Skip to content

Commit

Permalink
fix: add patch to get random map seed for randomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantanrk committed Jun 13, 2024
1 parent 2168c9f commit 4b99bf2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Behaviours/KeyboardPhysicsProp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ internal class KeyboardPhysicsProp : PhysicsProp

float _lastTriggeredTime;

private System.Random? randomizer;
private static System.Random? randomizer;

public static void OnSeedUpdate()
{
randomizer = new System.Random(DingusThings.GetRandomMapSeed());
}

public override void Start()
{
base.Start();
int seed = StartOfRound.Instance.randomMapSeed + StartOfRound.Instance.currentLevelID + itemProperties.itemId;
int seed = itemProperties.itemId;
randomizer = new System.Random(seed);
}

Expand Down
23 changes: 19 additions & 4 deletions DingusThings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BepInEx;
using BepInEx.Logging;
using DingusThings.Behaviours;
using DingusThings.CustomScriptableObject;
using DingusThings.Patches;
using HarmonyLib;
Expand All @@ -23,10 +24,7 @@ public class DingusThings : BaseUnityPlugin

private static Terminal? terminalInstance;

public static void SetTerminalInstance(Terminal terminal)
{
terminalInstance = terminal;
}
private static int randomMapSeed = 0;

public static Terminal? GetTerminalInstance()
{
Expand All @@ -40,6 +38,23 @@ public static void SetTerminalInstance(Terminal terminal)
}
}

public static void SetTerminalInstance(Terminal terminal)
{
terminalInstance = terminal;
}

public static int GetRandomMapSeed()
{
return randomMapSeed;
}

public static void SetRandomMapSeed(int s)
{
randomMapSeed = s;
// update keyboard physics prop seed
KeyboardPhysicsProp.OnSeedUpdate();
}

private void Awake()
{
Logger = base.Logger;
Expand Down
16 changes: 16 additions & 0 deletions Patches/SeedPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using DingusThings.Behaviours;
using HarmonyLib;

namespace DingusThings.Patches
{
internal class SeedPatch
{
[HarmonyPatch(typeof(StartOfRound), nameof(StartOfRound.ChooseNewRandomMapSeed))]
[HarmonyPostfix]
public static void StartOfRound_ChooseNewRandomMapSeed(StartOfRound __instance)
{
// save random map seed to our instance
DingusThings.SetRandomMapSeed(__instance.randomMapSeed);
}
}
}

0 comments on commit 4b99bf2

Please sign in to comment.