Skip to content

Commit

Permalink
Updated Alpha Genes (#480)
Browse files Browse the repository at this point in the history
Changes:
- Removed RNG patches
  - RNG code was dropped from the mod itself
- Added patch for clearing one of the caches used by the mod
  - This also fixes a bug in the mod. Going to report the bug to the dev, the patch may need to be removed (depending on how it's fixed)
- Added comments to the gizmo syncing to explain which functionality is being synced
  • Loading branch information
SokyranTheDragon authored Oct 12, 2024
1 parent 6462b0c commit e5edff6
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions Source/Mods/AlphaGenes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using System.Collections.Generic;
using HarmonyLib;
using Multiplayer.API;
using RimWorld;
using Verse;
Expand All @@ -11,23 +12,22 @@ namespace Multiplayer.Compat
[MpCompatFor("sarg.alphagenes")]
internal class AlphaGenes
{
private static AccessTools.FieldRef<HashSet<Pawn>> pawnsToRiseField;

public AlphaGenes(ModContentPack mod)
{
// RNG
{
PatchingUtilities.PatchSystemRandCtor("AlphaGenes.CompAbilityOcularConversion", false);
PatchingUtilities.PatchSystemRand("AlphaGenes.CompInsanityBlast:Apply", false);
PatchingUtilities.PatchSystemRand("AlphaGenes.HediffComp_Parasites:Hatch", false);
// The following method is seeded, so it should be fine
// If not, then patching it as well should fix it
//"AlphaGenes.GameComponent_RandomMood:GameComponentTick",
}
LongEventHandler.ExecuteWhenFinished(LatePatch);

// Abilities
{
// Toggle off (0) or on (1)
MpCompat.RegisterLambdaMethod("AlphaGenes.Ability_MineralOverdrive", "GetGizmos", 0, 2);
// Toggle off (0) or on (1)
MpCompat.RegisterLambdaMethod("AlphaGenes.Ability_ReactiveArmour", "GetGizmos", 0, 2);
// Dev: reset scorpion counter to 0 (if it bugs out)
MpCompat.RegisterLambdaDelegate("AlphaGenes.CompScorpionCounter", "CompGetGizmosExtra", 0).SetDebugOnly();
// Dev: force mutation
MpCompat.RegisterLambdaMethod("AlphaGenes.HediffComp_RandomMutation", "CompGetGizmos", 0).SetDebugOnly();
}

// Randomizer gene
Expand All @@ -37,6 +37,22 @@ public AlphaGenes(ModContentPack mod)
}
}

private static void LatePatch()
{
// Clear cache
{
// List of pawns to rise as shamblers.
// The collection, if not cleared, will
// cause bugs in the game. Remove if
// fixed in the mod itself (and make
// sure it's safe to remove as well).
var field = AccessTools.DeclaredField("AlphaGenes.StaticCollectionsClass:pawnsToRise");
pawnsToRiseField = AccessTools.StaticFieldRefAccess<HashSet<Pawn>>(field);
MpCompat.harmony.Patch(AccessTools.DeclaredMethod(typeof(GameComponentUtility), nameof(GameComponentUtility.FinalizeInit)),
postfix: new HarmonyMethod(ClearCache));
}
}

private static bool PrePostAddRandomizerGene(Gene __instance)
{
if (!MP.IsInMultiplayer)
Expand All @@ -53,5 +69,7 @@ private static bool PrePostAddRandomizerGene(Gene __instance)

return false;
}

private static void ClearCache() => pawnsToRiseField().Clear();
}
}

0 comments on commit e5edff6

Please sign in to comment.