Last active
May 7, 2019 18:22
-
-
Save sanasol/afa227721c39f53387e3a1eb13af3708 to your computer and use it in GitHub Desktop.
Rise of Industry mod hook world ready event
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
namespace CustomMod | |
{ | |
public class CustomMod : Mod, IWorldReadyListener | |
{ | |
public void OnWorldBecameReady(bool isLoadedFromSavegame) | |
{ | |
Debug.Log("CustomMod OnWorldBecameReady dispatched"); | |
} | |
public static void OnWorldBecameReadyHook(ScenarioManager __instance, bool isLoadedFromSavegame) | |
{ | |
Debug.Log("Loading OnWorldBecameReadyHook"); | |
ModLoader.instance.loadedMods[0].mods.OfType<IWorldReadyListener>() | |
.ForEach<IWorldReadyListener>( | |
(Action<IWorldReadyListener>) (o => o.OnWorldBecameReady(isLoadedFromSavegame))); | |
Debug.Log("Done OnWorldBecameReadyHook"); | |
} | |
public override void OnModWasLoaded() | |
{ | |
HarmonyInstance.Create(nameof(CustomMod)).Patch( | |
(MethodBase) typeof(ScenarioManager).GetMethod("OnWorldBecameReady"), | |
(HarmonyMethod) null, | |
new HarmonyMethod(typeof(CustomMod).GetMethod("OnWorldBecameReadyHook")), | |
(HarmonyMethod) null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment