From 533f281e360f56bf8c9bda2bdb7d41b83a1cf01b Mon Sep 17 00:00:00 2001 From: SokyranTheDragon <36712560+SokyranTheDragon@users.noreply.github.com> Date: Tue, 9 Apr 2024 03:36:58 +0200 Subject: [PATCH] Added compat for Ancient mining industry (#437) 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. --- Source/Mods/AncientMiningIndustry.cs | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Source/Mods/AncientMiningIndustry.cs diff --git a/Source/Mods/AncientMiningIndustry.cs b/Source/Mods/AncientMiningIndustry.cs new file mode 100644 index 0000000..24332c3 --- /dev/null +++ b/Source/Mods/AncientMiningIndustry.cs @@ -0,0 +1,40 @@ +using HarmonyLib; +using Multiplayer.API; +using Verse; + +namespace Multiplayer.Compat; + +/// Ancient mining industry by MO +/// +[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(SyncQuestScriptTexPathPair, questScriptPairType.type); + } + + private static void SyncQuestScriptTexPathPair(SyncWorker sync, ref object obj) => sync.Bind(ref obj, questScriptPairType); +} \ No newline at end of file