From 0a68f14422195e3525cbd8a41df3b8517e28a634 Mon Sep 17 00:00:00 2001 From: Flourek Date: Sat, 24 Aug 2024 19:16:23 +0200 Subject: [PATCH 1/6] Assigning chatters to guards, command to opt in --- asset_patches/assets/data/Papers.xml | 95 +++++++++++++++++++ psp-papers-mod/src/Patches/ChatterGuards.cs | 55 +++++++++++ psp-papers-mod/src/Patches/TextPatch.cs | 25 +++-- .../src/Twitch/Commands/Commands.cs | 13 +++ .../src/Twitch/TwitchIntegration.cs | 1 + 5 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 psp-papers-mod/src/Patches/ChatterGuards.cs diff --git a/asset_patches/assets/data/Papers.xml b/asset_patches/assets/data/Papers.xml index 3d913e5..dd68773 100644 --- a/asset_patches/assets/data/Papers.xml +++ b/asset_patches/assets/data/Papers.xml @@ -47,6 +47,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/psp-papers-mod/src/Patches/ChatterGuards.cs b/psp-papers-mod/src/Patches/ChatterGuards.cs new file mode 100644 index 0000000..6879e2a --- /dev/null +++ b/psp-papers-mod/src/Patches/ChatterGuards.cs @@ -0,0 +1,55 @@ +using data; +using HarmonyLib; +using Il2CppSystem; +using play.day.border; +using psp_papers_mod.Twitch; +using System.Collections.Generic; +using System.Linq; + +namespace psp_papers_mod.Patches; + +public class ChatterGuards { + public static ChatterCollection WantGuardChatters = new (); + public static Chatter[] Guards = new Chatter[5]; + // 0-1: left guards, 2-4: right guards + + public static bool SetGuards() { + if (WantGuardChatters.Count < 1) return false; + + int[] order = { 2, 3, 4, 0, 1 }; // Prioritize setting the right ones first + + foreach (int i in order) { + for (int j = 0; j < WantGuardChatters.Count; j++) { + Chatter chatter = WantGuardChatters.GetRandomChatter(); + + if (!Guards.Contains(chatter)) { + Guards[i] = chatter; + break; + } + } + } + + return true; + } + + public static string GuardNames(bool right) { + Chatter[] guards = right ? Guards[2..] : Guards[..2]; + return string.Join(", ", guards.Distinct().Select(c => c?.Username)); + } +} + + +[HarmonyPatch(typeof(Person))] +public class GuardPersonPatch { + + [HarmonyPrefix] + [HarmonyPatch("setAnim", typeof(Anim), typeof(Object))] + private static void PersonSetAnim(Anim anim, Object movingHorizontal, Person __instance) { + if (!anim.death) return; + // left guards can't die as of rn + if(__instance.id == "guard2") ChatterGuards.Guards[2]?.Shot(); + if(__instance.id == "guard3") ChatterGuards.Guards[3]?.Shot(); + if(__instance.id == "guard4") ChatterGuards.Guards[4]?.Shot(); + + } +} \ No newline at end of file diff --git a/psp-papers-mod/src/Patches/TextPatch.cs b/psp-papers-mod/src/Patches/TextPatch.cs index 8ec8a40..47acd88 100644 --- a/psp-papers-mod/src/Patches/TextPatch.cs +++ b/psp-papers-mod/src/Patches/TextPatch.cs @@ -13,12 +13,25 @@ public static string Process(string text) { } public static void SetMenuTextPrefix(ref string v) { - if (v is not "The day was cut short by a terrorist attack.") return; - - Chatter attacker = TwitchIntegration.ActiveAttacker; - if (attacker == null) return; - - v = v.Replace(".", " by " + attacker.Username + "."); + if (v == null) return; + + if (v is "The day was cut short by a terrorist attack.") { + Chatter attacker = TwitchIntegration.ActiveAttacker; + if (attacker == null) return; + + v = v.Replace(".", " by " + attacker.Username + "."); + return; + } + + if (v.Contains("_GUARDS__")) { + if (!ChatterGuards.SetGuards()) { + v = ""; + return; + } + v = v.Replace("__LEFT_GUARDS__", ChatterGuards.GuardNames(false)); + v = v.Replace("__RIGHT_GUARDS__", ChatterGuards.GuardNames(true)); + return; + } } } diff --git a/psp-papers-mod/src/Twitch/Commands/Commands.cs b/psp-papers-mod/src/Twitch/Commands/Commands.cs index d40c54c..2577209 100644 --- a/psp-papers-mod/src/Twitch/Commands/Commands.cs +++ b/psp-papers-mod/src/Twitch/Commands/Commands.cs @@ -48,6 +48,19 @@ public static void NoBomb(Chatter sender, ChatMessage chatMessage, string[] args sender.WantsBomb = false; } + [ChatCommand("guard")] + public static void WantsGuard(Chatter sender, ChatMessage chatMessage, string[] args) { + string username = sender.Username; + if (!ChatterGuards.WantGuardChatters.ContainsKey(username)) { + ChatterGuards.WantGuardChatters.Add(username, new Chatter(chatMessage)); + + chatMessage.Reply("Thank you for enlisting in the border patrol o7"); + } else { + ChatterGuards.WantGuardChatters.Remove(username); + chatMessage.Reply("Opted out of being a guard."); + } + } + [ChatCommand("give")] public static void GiveEmote(Chatter sender, ChatMessage chatMessage, string[] args) { if (!sender.IsActiveChatter) return; diff --git a/psp-papers-mod/src/Twitch/TwitchIntegration.cs b/psp-papers-mod/src/Twitch/TwitchIntegration.cs index a938f09..6a471e9 100644 --- a/psp-papers-mod/src/Twitch/TwitchIntegration.cs +++ b/psp-papers-mod/src/Twitch/TwitchIntegration.cs @@ -31,6 +31,7 @@ public class TwitchIntegration { public const float DENIED_WEIGHT_MODIFIER = 0.8f; public ChatterCollection FrequentChatters { get; } + public static Chatter NextChatter { get; set; } From f2ea436fb8cd717c8485d91fc35c0b5f2727f08a Mon Sep 17 00:00:00 2001 From: Flourek Date: Sat, 24 Aug 2024 23:34:50 +0200 Subject: [PATCH 2/6] A bunch of refactoring --- asset_patches/assets/data/Papers.xml | 86 +++---------------- psp-papers-mod/src/Patches/ChatterGuards.cs | 16 ++-- psp-papers-mod/src/Patches/TextPatch.cs | 17 ++-- .../src/Twitch/Commands/Commands.cs | 6 +- .../src/Twitch/TwitchIntegration.cs | 1 + psp-papers-mod/src/Utils/SplitUsername.cs | 2 - 6 files changed, 30 insertions(+), 98 deletions(-) diff --git a/asset_patches/assets/data/Papers.xml b/asset_patches/assets/data/Papers.xml index dd68773..899de1c 100644 --- a/asset_patches/assets/data/Papers.xml +++ b/asset_patches/assets/data/Papers.xml @@ -50,34 +50,23 @@ - + - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - + @@ -86,59 +75,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/psp-papers-mod/src/Patches/ChatterGuards.cs b/psp-papers-mod/src/Patches/ChatterGuards.cs index 6879e2a..78e75e6 100644 --- a/psp-papers-mod/src/Patches/ChatterGuards.cs +++ b/psp-papers-mod/src/Patches/ChatterGuards.cs @@ -9,18 +9,18 @@ namespace psp_papers_mod.Patches; public class ChatterGuards { - public static ChatterCollection WantGuardChatters = new (); + public static ChatterCollection WantToGuardChatters = new (); public static Chatter[] Guards = new Chatter[5]; // 0-1: left guards, 2-4: right guards - + public static bool SetGuards() { if (WantGuardChatters.Count < 1) return false; int[] order = { 2, 3, 4, 0, 1 }; // Prioritize setting the right ones first foreach (int i in order) { - for (int j = 0; j < WantGuardChatters.Count; j++) { - Chatter chatter = WantGuardChatters.GetRandomChatter(); + for (int j = 0; j < WantToGuardChatters.Count; j++) { + Chatter chatter = WantToGuardChatters.GetRandomChatter(); if (!Guards.Contains(chatter)) { Guards[i] = chatter; @@ -31,21 +31,17 @@ public static bool SetGuards() { return true; } - - public static string GuardNames(bool right) { - Chatter[] guards = right ? Guards[2..] : Guards[..2]; - return string.Join(", ", guards.Distinct().Select(c => c?.Username)); - } } [HarmonyPatch(typeof(Person))] -public class GuardPersonPatch { +internal class GuardPersonPatch { [HarmonyPrefix] [HarmonyPatch("setAnim", typeof(Anim), typeof(Object))] private static void PersonSetAnim(Anim anim, Object movingHorizontal, Person __instance) { if (!anim.death) return; + // left guards can't die as of rn if(__instance.id == "guard2") ChatterGuards.Guards[2]?.Shot(); if(__instance.id == "guard3") ChatterGuards.Guards[3]?.Shot(); diff --git a/psp-papers-mod/src/Patches/TextPatch.cs b/psp-papers-mod/src/Patches/TextPatch.cs index 47acd88..490e86c 100644 --- a/psp-papers-mod/src/Patches/TextPatch.cs +++ b/psp-papers-mod/src/Patches/TextPatch.cs @@ -23,14 +23,15 @@ public static void SetMenuTextPrefix(ref string v) { return; } - if (v.Contains("_GUARDS__")) { - if (!ChatterGuards.SetGuards()) { - v = ""; - return; - } - v = v.Replace("__LEFT_GUARDS__", ChatterGuards.GuardNames(false)); - v = v.Replace("__RIGHT_GUARDS__", ChatterGuards.GuardNames(true)); - return; + if (ChatterGuards.WantToGuardChatters.Count < 1) { + if (v is "Assigned guards:" || v.Contains("__GUARD")) v = ""; + } else { + ChatterGuards.SetGuards(); + if (v is "__GUARD0__") v = ChatterGuards.Guards[0]?.Username; + if (v is "__GUARD1__") v = ChatterGuards.Guards[1]?.Username; + if (v is "__GUARD2__") v = ChatterGuards.Guards[2]?.Username; + if (v is "__GUARD3__") v = ChatterGuards.Guards[3]?.Username; + if (v is "__GUARD4__") v = ChatterGuards.Guards[4]?.Username; } } diff --git a/psp-papers-mod/src/Twitch/Commands/Commands.cs b/psp-papers-mod/src/Twitch/Commands/Commands.cs index 2577209..8cd77b4 100644 --- a/psp-papers-mod/src/Twitch/Commands/Commands.cs +++ b/psp-papers-mod/src/Twitch/Commands/Commands.cs @@ -51,12 +51,12 @@ public static void NoBomb(Chatter sender, ChatMessage chatMessage, string[] args [ChatCommand("guard")] public static void WantsGuard(Chatter sender, ChatMessage chatMessage, string[] args) { string username = sender.Username; - if (!ChatterGuards.WantGuardChatters.ContainsKey(username)) { - ChatterGuards.WantGuardChatters.Add(username, new Chatter(chatMessage)); + if (!ChatterGuards.WantToGuardChatters.ContainsKey(username)) { + ChatterGuards.WantToGuardChatters.Add(username, new Chatter(chatMessage)); chatMessage.Reply("Thank you for enlisting in the border patrol o7"); } else { - ChatterGuards.WantGuardChatters.Remove(username); + ChatterGuards.WantToGuardChatters.Remove(username); chatMessage.Reply("Opted out of being a guard."); } } diff --git a/psp-papers-mod/src/Twitch/TwitchIntegration.cs b/psp-papers-mod/src/Twitch/TwitchIntegration.cs index 6a471e9..2b3d475 100644 --- a/psp-papers-mod/src/Twitch/TwitchIntegration.cs +++ b/psp-papers-mod/src/Twitch/TwitchIntegration.cs @@ -58,6 +58,7 @@ public class TwitchIntegration { public TwitchIntegration() { this.FrequentChatters = new ChatterCollection(); + Task authTask = LocalAuthResponse.Fetch(); authTask.Wait(); diff --git a/psp-papers-mod/src/Utils/SplitUsername.cs b/psp-papers-mod/src/Utils/SplitUsername.cs index dd4a582..18fedd2 100644 --- a/psp-papers-mod/src/Utils/SplitUsername.cs +++ b/psp-papers-mod/src/Utils/SplitUsername.cs @@ -72,8 +72,6 @@ public static (string, string) Process(string username) { // uni1g -> 1g, uni if (username.EndsWith("1g")) { - Console.WriteLine("1g"); - splitIndex = username.LastIndexOf("1g", StringComparison.Ordinal); } From 3f2eace2c93924579508d2d7d1b2fa4530282173 Mon Sep 17 00:00:00 2001 From: Flourek Date: Mon, 26 Aug 2024 15:12:25 +0200 Subject: [PATCH 3/6] Asset adjustments --- asset_patches/assets/data/Papers.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/asset_patches/assets/data/Papers.xml b/asset_patches/assets/data/Papers.xml index 899de1c..738f25e 100644 --- a/asset_patches/assets/data/Papers.xml +++ b/asset_patches/assets/data/Papers.xml @@ -54,14 +54,14 @@ - - - - - - - - + + + + + + + + From f82051e10f803d9c15fc7eb41a8cc7399d2168f3 Mon Sep 17 00:00:00 2001 From: Flourek Date: Mon, 26 Aug 2024 16:10:33 +0200 Subject: [PATCH 4/6] Guards can't be active chatter --- psp-papers-mod/src/Twitch/Chatter.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/psp-papers-mod/src/Twitch/Chatter.cs b/psp-papers-mod/src/Twitch/Chatter.cs index 0f40146..69ee106 100644 --- a/psp-papers-mod/src/Twitch/Chatter.cs +++ b/psp-papers-mod/src/Twitch/Chatter.cs @@ -172,7 +172,10 @@ public int GetWeight(bool attacker = false) { // The active chatter can't be the attacker and vice versa (attacker && TwitchIntegration.ActiveChatter == this) || - (!attacker && TwitchIntegration.ActiveAttacker == this) + (!attacker && TwitchIntegration.ActiveAttacker == this) || + + // Guards can't be active chatters + (ChatterGuards.Guards.Contains(this)) ) return 0; From c327f42cdc337d06c1748c9e431c14822a61c9ff Mon Sep 17 00:00:00 2001 From: Flourek Date: Mon, 26 Aug 2024 16:24:00 +0200 Subject: [PATCH 5/6] bugfix for assigning guards --- psp-papers-mod/src/Patches/TextPatch.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/psp-papers-mod/src/Patches/TextPatch.cs b/psp-papers-mod/src/Patches/TextPatch.cs index 490e86c..adacab9 100644 --- a/psp-papers-mod/src/Patches/TextPatch.cs +++ b/psp-papers-mod/src/Patches/TextPatch.cs @@ -24,9 +24,11 @@ public static void SetMenuTextPrefix(ref string v) { } if (ChatterGuards.WantToGuardChatters.Count < 1) { - if (v is "Assigned guards:" || v.Contains("__GUARD")) v = ""; + if (v.Contains("__GUARD")) v = ""; } else { - ChatterGuards.SetGuards(); + // hacky, but executes once per day right when it's needed + if (v is "Assigned guards:") ChatterGuards.SetGuards(); + if (v is "__GUARD0__") v = ChatterGuards.Guards[0]?.Username; if (v is "__GUARD1__") v = ChatterGuards.Guards[1]?.Username; if (v is "__GUARD2__") v = ChatterGuards.Guards[2]?.Username; From 1736f6d57b4879b5722c8563e915f7958590b240 Mon Sep 17 00:00:00 2001 From: ByteZ1337 <0xbytez@gmail.com> Date: Tue, 22 Oct 2024 16:36:13 +0200 Subject: [PATCH 6/6] Update ChatterGuards.cs --- psp-papers-mod/src/Patches/ChatterGuards.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psp-papers-mod/src/Patches/ChatterGuards.cs b/psp-papers-mod/src/Patches/ChatterGuards.cs index 78e75e6..7a057d3 100644 --- a/psp-papers-mod/src/Patches/ChatterGuards.cs +++ b/psp-papers-mod/src/Patches/ChatterGuards.cs @@ -14,7 +14,7 @@ public class ChatterGuards { // 0-1: left guards, 2-4: right guards public static bool SetGuards() { - if (WantGuardChatters.Count < 1) return false; + if (WantToGuardChatters.Count < 1) return false; int[] order = { 2, 3, 4, 0, 1 }; // Prioritize setting the right ones first