-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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?
- Loading branch information
1 parent
2a7594e
commit 8b31be3
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using HarmonyLib; | ||
using Multiplayer.API; | ||
using RimWorld; | ||
using Verse; | ||
|
||
namespace Multiplayer.Compat; | ||
|
||
/// <summary>Vanilla Factions Expanded - Insectoids 2 by Oskar Potocki, xrushha, Taranchuk, Sarg Bjornson</summary> | ||
/// GitHub page not up yet. | ||
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=3309003431"/> | ||
[MpCompatFor("OskarPotocki.VFE.Insectoid2")] | ||
public class VanillaFactionsInsectoid2 | ||
{ | ||
#region Fields | ||
|
||
private static Type hiveGizmoType; | ||
private static AccessTools.FieldRef<Gizmo, CompSpawnerPawn> 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<CompSpawnerPawn>(hiveGizmoType, "compHive"); | ||
MP.RegisterSyncWorker<Gizmo>(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<CompSpawnerPawn>(); | ||
} | ||
|
||
#endregion | ||
} |