From 51932c15f1200a49659df454c5a0ae1278cdfeb9 Mon Sep 17 00:00:00 2001 From: SabreML <57483089+SabreML@users.noreply.github.com> Date: Sun, 12 Feb 2023 16:42:15 +0000 Subject: [PATCH] Pointing! (Also a full rename) --- Properties/AssemblyInfo.cs | 4 +- SingleplayerCoopEmotes.cs | 82 ++++++++++++++++++ ...te.csproj => SingleplayerCoopEmotes.csproj | 10 ++- ...eepEmote.sln => SingleplayerCoopEmotes.sln | 4 +- SingleplayerCoopEmotes/modinfo.json | 8 ++ .../thumbnail.png | Bin SingleplayerSleepEmote.cs | 29 ------- SingleplayerSleepEmote/modinfo.json | 8 -- 8 files changed, 101 insertions(+), 44 deletions(-) create mode 100644 SingleplayerCoopEmotes.cs rename SingleplayerSleepEmote.csproj => SingleplayerCoopEmotes.csproj (88%) rename SingleplayerSleepEmote.sln => SingleplayerCoopEmotes.sln (90%) create mode 100644 SingleplayerCoopEmotes/modinfo.json rename {SingleplayerSleepEmote => SingleplayerCoopEmotes}/thumbnail.png (100%) delete mode 100644 SingleplayerSleepEmote.cs delete mode 100644 SingleplayerSleepEmote/modinfo.json diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 69ddc3d..326cd41 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("SingleplayerSleepEmote")] +[assembly: AssemblyTitle("SingleplayerCoopEmotes")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SingleplayerSleepEmote")] +[assembly: AssemblyProduct("SingleplayerCoopEmotes")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/SingleplayerCoopEmotes.cs b/SingleplayerCoopEmotes.cs new file mode 100644 index 0000000..c0abf8f --- /dev/null +++ b/SingleplayerCoopEmotes.cs @@ -0,0 +1,82 @@ +using BepInEx; +using System.Reflection; +using System.Security.Permissions; +using MonoMod.RuntimeDetour; +using UnityEngine; +using System; + +#pragma warning disable CS0618 +[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] +#pragma warning restore CS0618 + +namespace SingleplayerCoopEmotes +{ + [BepInPlugin("sabreml.singleplayercoopemotes", "SingleplayerCoopEmotes", "1.1.0")] + public class SingleplayerCoopEmotes : BaseUnityPlugin + { + public void OnEnable() + { + On.RainWorld.OnModsInit += Init; + } + + private void Init(On.RainWorld.orig_OnModsInit orig, RainWorld self) + { + orig(self); + // If the DLC is installed on Steam, and Jolly Co-op isn't currently loaded. (No reason to change anything otherwise) + if (RWCustom.Custom.rainWorld.dlcVersion > 0 && !ModManager.JollyCoop) + { + On.Player.JollyUpdate += JollyUpdateHK; + On.Player.checkInput += checkInputHK; + + // Manual hook to override the `Player.RevealMap` property getter. + new Hook( + typeof(Player).GetProperty("RevealMap", BindingFlags.Public | BindingFlags.Instance).GetGetMethod(), + typeof(SingleplayerCoopEmotes).GetMethod(nameof(get_RevealMapHK), BindingFlags.NonPublic | BindingFlags.Static) + ); + } + } + + private static void JollyUpdateHK(On.Player.orig_JollyUpdate orig, Player self, bool eu) + { + // If this is hooked then the check above must have passed, so we don't need to worry about conflicts. + orig(self, eu); + + // Sleeping emote things. + self.JollyEmoteUpdate(); + + // Update the jolly button. (Taken from `JollyInputUpdate()`) + if (!self.input[0].mp) // If the button isn't being held down at all. + { + self.jollyButtonDown = false; + } + else if (!self.input[1].mp) // If the button was down this frame, but not last frame. + { + self.jollyButtonDown = false; + for (int i = 2; i < self.input.Length - 1; i++) + { + if (self.input[i].mp && !self.input[i + 1].mp) // Look for a double tap. + { + self.jollyButtonDown = true; + } + } + } + // Pointing emote things. + self.JollyPointUpdate(); + } + + private static void checkInputHK(On.Player.orig_checkInput orig, Player self) + { + // Temporarily make it think that Jolly Co-op is loaded so that it checks for `jollyButtonDown`. + // (Doing it this way is a lot easier than trying to edit the method.) + ModManager.CoopAvailable = true; + orig(self); + ModManager.CoopAvailable = false; + } + + // Same as the original getter except without a `ModManager.CoopAvailable` check. + private static bool get_RevealMapHK(Func orig, Player self) + { + return !self.jollyButtonDown && self.input[0].mp && !self.inVoidSea; + } + } +} diff --git a/SingleplayerSleepEmote.csproj b/SingleplayerCoopEmotes.csproj similarity index 88% rename from SingleplayerSleepEmote.csproj rename to SingleplayerCoopEmotes.csproj index 50bbdc1..603b682 100644 --- a/SingleplayerSleepEmote.csproj +++ b/SingleplayerCoopEmotes.csproj @@ -7,8 +7,8 @@ {32FB7380-F5F5-498D-B802-78E17EFB66BB} Library Properties - SingleplayerSleepEmote - SingleplayerSleepEmote + SingleplayerCoopEmotes + SingleplayerCoopEmotes v4.8 512 true @@ -34,7 +34,7 @@ Always - + @@ -50,6 +50,10 @@ ..\..\DLLs\HOOKS-Assembly-CSharp.dll False + + ..\..\DLLs\Additional\MonoMod.RuntimeDetour.dll + False + ..\..\DLLs\UnityEngine.dll False diff --git a/SingleplayerSleepEmote.sln b/SingleplayerCoopEmotes.sln similarity index 90% rename from SingleplayerSleepEmote.sln rename to SingleplayerCoopEmotes.sln index 1c826de..f0faba5 100644 --- a/SingleplayerSleepEmote.sln +++ b/SingleplayerCoopEmotes.sln @@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33213.308 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleplayerSleepEmote", "SingleplayerSleepEmote.csproj", "{32FB7380-F5F5-498D-B802-78E17EFB66BB}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingleplayerCoopEmotes", "SingleplayerCoopEmotes.csproj", "{32FB7380-F5F5-498D-B802-78E17EFB66BB}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ED14B559-DB0C-4B19-9A63-1F374E0DFD2A}" ProjectSection(SolutionItems) = preProject - SingleplayerSleepEmote\modinfo.json = SingleplayerSleepEmote\modinfo.json + SingleplayerCoopEmotes\modinfo.json = SingleplayerCoopEmotes\modinfo.json EndProjectSection EndProject Global diff --git a/SingleplayerCoopEmotes/modinfo.json b/SingleplayerCoopEmotes/modinfo.json new file mode 100644 index 0000000..333f28b --- /dev/null +++ b/SingleplayerCoopEmotes/modinfo.json @@ -0,0 +1,8 @@ +{ + "id": "sabreml.singleplayercoopemotes", + "name": "Singleplayer Co-op Emotes", + "version": "1.1.0", + "target_game_version": "v1.9.05", + "authors": "SabreML", + "description": "Makes the Jolly Co-op emotes work in singleplayer!" +} \ No newline at end of file diff --git a/SingleplayerSleepEmote/thumbnail.png b/SingleplayerCoopEmotes/thumbnail.png similarity index 100% rename from SingleplayerSleepEmote/thumbnail.png rename to SingleplayerCoopEmotes/thumbnail.png diff --git a/SingleplayerSleepEmote.cs b/SingleplayerSleepEmote.cs deleted file mode 100644 index fc5033a..0000000 --- a/SingleplayerSleepEmote.cs +++ /dev/null @@ -1,29 +0,0 @@ -using BepInEx; -using System.Security.Permissions; - -#pragma warning disable CS0618 -[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] -#pragma warning restore CS0618 - -namespace SingleplayerSleepEmote -{ - [BepInPlugin("sabreml.singleplayersleepemote", "SingleplayerSleepEmote", "1.0.0")] - public class SingleplayerSleepEmote : BaseUnityPlugin - { - public void OnEnable() - { - On.Player.JollyUpdate += JollyUpdateHK; - } - - private void JollyUpdateHK(On.Player.orig_JollyUpdate orig, Player self, bool eu) - { - orig(self, eu); - - // If the DLC is installed on Steam, and Jolly Co-op isn't currently loaded. (No point in this mod otherwise) - if (RWCustom.Custom.rainWorld.dlcVersion > 0 && !ModManager.CoopAvailable) - { - self.JollyEmoteUpdate(); - } - } - } -} diff --git a/SingleplayerSleepEmote/modinfo.json b/SingleplayerSleepEmote/modinfo.json deleted file mode 100644 index 585eaf4..0000000 --- a/SingleplayerSleepEmote/modinfo.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "id": "sabreml.singleplayersleepemote", - "name": "Singleplayer Sleep Emote", - "version": "1.0.0", - "target_game_version": "v1.9.04", - "authors": "SabreML", - "description": "Makes the Jolly Co-op sleep emote work in singleplayer!" -} \ No newline at end of file