Skip to content

Commit

Permalink
Added compat for Ancient mining industry (#437)
Browse files Browse the repository at this point in the history
As a side note - Ancient hydroponic farm facilities mod should already be fine, only needing Vanilla Expanded Framework Compat.

A friend was planning on playing MP soon and asked me if those two mods were safe, so as any sensible modder would do - I didn't answer and instead patched the mod.
  • Loading branch information
SokyranTheDragon authored Apr 9, 2024
1 parent dd62f75 commit 533f281
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Source/Mods/AncientMiningIndustry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using HarmonyLib;
using Multiplayer.API;
using Verse;

namespace Multiplayer.Compat;

/// <summary>Ancient mining industry by MO</summary>
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=3141472661"/>
[MpCompatFor("XMB.AncientMiningIndustry.MO")]
public class AncientMiningIndustry
{
private static SyncType questScriptPairType;

public AncientMiningIndustry(ModContentPack mod)
{
// Turn on/off (0), build walls on/off (1)
MpCompat.RegisterLambdaMethod("AncientMining.Building_BoringMachine", nameof(Thing.GetGizmos), 0, 1);

// Dev produce portion (0), shutdown (1)
MpCompat.RegisterLambdaMethod("AncientMining.CompDeepDrillAutomated", nameof(ThingComp.CompGetGizmosExtra), 0, 1).SetDebugOnly();

// No quest (1), specific quest (3)
MpCompat.RegisterLambdaDelegate("AncientMining.CompQuestScanner", nameof(ThingComp.CompGetGizmosExtra), 1, 3).SetContext(SyncContext.MapSelected);

// A bit of a "hacky" solution. It'll sync the field by exposing it, instead of setting it
// to a specific reference from the comp's props. However, due to the way it's handled, it
// should work completely fine - the reference itself doesn't matter, only its contents.
// An alternative would be to make a sync worker that searches all `ThingDef`s for quest
// scanner props, checks if it contains that specific item in its list of possible quests,
// and then syncs the def and position of that object on the list.
// Side note: this could be done using ISyncDelegate.ExposeFields - however,
// seems I may have left a bug behind in that code, so it'll need to be fixed first.
questScriptPairType = AccessTools.TypeByName("AncientMining.QuestScriptTexPathPair");
questScriptPairType.expose = true;

MP.RegisterSyncWorker<object>(SyncQuestScriptTexPathPair, questScriptPairType.type);
}

private static void SyncQuestScriptTexPathPair(SyncWorker sync, ref object obj) => sync.Bind(ref obj, questScriptPairType);
}

0 comments on commit 533f281

Please sign in to comment.