From 8b31be3f63f5a8e16d759306d6492101651dd2e7 Mon Sep 17 00:00:00 2001 From: SokyranTheDragon <36712560+SokyranTheDragon@users.noreply.github.com> Date: Fri, 16 Aug 2024 04:47:56 +0200 Subject: [PATCH] Compat for Vanilla Factions Expanded - Insectoids 2 (#458) This should handle everything the mod has to offer, although I may have missed something. Let me know if something doesn't work. I've included this as a separate compat since it's a separate mod (sequel), with a separate ID and mod page. The original is still left where it was. Considering it's unlikely that it will be updated, should we delete the old compat? --- Source/Mods/VanillaFactionsInsectoid2.cs | 85 ++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Source/Mods/VanillaFactionsInsectoid2.cs diff --git a/Source/Mods/VanillaFactionsInsectoid2.cs b/Source/Mods/VanillaFactionsInsectoid2.cs new file mode 100644 index 0000000..f52d5f0 --- /dev/null +++ b/Source/Mods/VanillaFactionsInsectoid2.cs @@ -0,0 +1,85 @@ +using System; +using HarmonyLib; +using Multiplayer.API; +using RimWorld; +using Verse; + +namespace Multiplayer.Compat; + +/// Vanilla Factions Expanded - Insectoids 2 by Oskar Potocki, xrushha, Taranchuk, Sarg Bjornson +/// GitHub page not up yet. +/// +[MpCompatFor("OskarPotocki.VFE.Insectoid2")] +public class VanillaFactionsInsectoid2 +{ + #region Fields + + private static Type hiveGizmoType; + private static AccessTools.FieldRef hiveGizmoCompField; + + #endregion + + #region Main patch + + public VanillaFactionsInsectoid2(ModContentPack mod) + { + LongEventHandler.ExecuteWhenFinished(LatePatch); + + #region Gizmos + + { + var type = AccessTools.TypeByName("VFEInsectoids.CompHive"); + // Change pawn kind to spawn, called from Gizmo_Hive + MP.RegisterSyncMethod(type, "ChangePawnKind"); + // Dev mode spawn pawn, called from gizmo lambda + MP.RegisterSyncMethod(type, "DoSpawn").SetDebugOnly(); + + type = AccessTools.TypeByName("VFEInsectoids.HediffComp_Spawn"); + // Advance severity + MP.RegisterSyncMethodLambda(type, nameof(HediffComp.CompGetGizmos), 0).SetDebugOnly(); + } + + #endregion + + #region RNG + + { + PatchingUtilities.PatchSystemRandCtor("VFEInsectoids.Tunneler"); + } + + #endregion + } + + #endregion + + #region Late patch + + private static void LatePatch() + { + #region Gizmos + + { + hiveGizmoType = AccessTools.TypeByName("VFEInsectoids.Gizmo_Hive"); + hiveGizmoCompField = AccessTools.FieldRefAccess(hiveGizmoType, "compHive"); + MP.RegisterSyncWorker(SyncGizmoHive, hiveGizmoType, shouldConstruct: true); + // Change color + MP.RegisterSyncMethodLambda(hiveGizmoType, "GizmoOnGUI", 1); + } + + #endregion + } + + #endregion + + #region SyncWorkers + + private static void SyncGizmoHive(SyncWorker sync, ref Gizmo gizmo) + { + if (sync.isWriting) + sync.Write(hiveGizmoCompField(gizmo)); + else + hiveGizmoCompField(gizmo) = sync.Read(); + } + + #endregion +} \ No newline at end of file