diff --git a/SingleplayerCoopEmotes.cs b/SingleplayerCoopEmotes.cs index 3f9ea5e..ee5f987 100644 --- a/SingleplayerCoopEmotes.cs +++ b/SingleplayerCoopEmotes.cs @@ -1,8 +1,9 @@ using BepInEx; -using System.Reflection; -using System.Security.Permissions; +using MonoMod.Cil; using MonoMod.RuntimeDetour; using System; +using System.Reflection; +using System.Security.Permissions; using UnityEngine; #pragma warning disable CS0618 @@ -11,7 +12,7 @@ namespace SingleplayerCoopEmotes { - [BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.1.3")] + [BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.1.4")] public class SingleplayerCoopEmotes : BaseUnityPlugin { public void OnEnable() @@ -39,9 +40,11 @@ private static void Init(On.RainWorld.orig_OnModsInit orig, RainWorld self) On.Player.JollyUpdate += JollyUpdateHK; On.Player.JollyPointUpdate += JollyPointUpdateHK; On.Player.GraphicsModuleUpdated += GraphicsModuleUpdatedHK; - On.Player.checkInput += checkInputHK; On.PlayerGraphics.PlayerBlink += PlayerBlinkHK; + // IL hook to remove all `ModManager.CoopAvailable` checks. + IL.Player.checkInput += checkInputHK_IL; + // Manual hook to override the `Player.RevealMap` property getter. new Hook( typeof(Player).GetProperty("RevealMap", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), @@ -125,17 +128,24 @@ private static void GraphicsModuleUpdatedHK(On.Player.orig_GraphicsModuleUpdated // When Jolly Co-op is active and the jolly button is held, the `checkInput()` method skips opening the map // and sets the player's movement input as the pointing direction. - private static void checkInputHK(On.Player.orig_checkInput orig, Player self) + private static void checkInputHK_IL(ILContext il) { - // Temporarily make the method think that Jolly Co-op is loaded so that it checks for `jollyButtonDown`. - if (!self.isNPC) + ILCursor cursor = new ILCursor(il); + + // Go to each `ModManager.CoopAvailable` check, and set its label target to the next instruction. + // + // (This results in the same behaviour as just removing the check, but after multiple days of trying I couldn't get that to work.) + ILLabel label = null; + while (cursor.TryGotoNext(MoveType.After, + i => i.MatchLdsfld("CoopAvailable"), + i => i.MatchBrfalse(out label) + )) { - ModManager.CoopAvailable = true; // Don't do this for NPCs because it can break their AI. + cursor.MarkLabel(label); } - orig(self); - ModManager.CoopAvailable = false; } + // Called by `PlayerGraphics.Update()` when the player has fully curled up to sleep. // // This override is the same as the original except without the Spearmaster check, as it made them inconsistent with diff --git a/SingleplayerCoopEmotes.csproj b/SingleplayerCoopEmotes.csproj index 603b682..8e9dd6f 100644 --- a/SingleplayerCoopEmotes.csproj +++ b/SingleplayerCoopEmotes.csproj @@ -50,10 +50,18 @@ ..\..\DLLs\HOOKS-Assembly-CSharp.dll False + + ..\..\DLLs\Additional\Mono.Cecil.dll + False + ..\..\DLLs\Additional\MonoMod.RuntimeDetour.dll False + + ..\..\DLLs\Additional\MonoMod.Utils.dll + False + ..\..\DLLs\UnityEngine.dll False diff --git a/SingleplayerCoopEmotes/modinfo.json b/SingleplayerCoopEmotes/modinfo.json index 00efdfc..a8aaf66 100644 --- a/SingleplayerCoopEmotes/modinfo.json +++ b/SingleplayerCoopEmotes/modinfo.json @@ -1,7 +1,7 @@ { "id": "sabreml.singleplayercoopemotes", "name": "Singleplayer Co-op Emotes", - "version": "1.1.3", + "version": "1.1.4", "target_game_version": "v1.9.05", "authors": "SabreML", "description": "Makes the Jolly Co-op emotes work in singleplayer!"