From 93645f532f7244184fa139e60a4262e1c75df4ce Mon Sep 17 00:00:00 2001 From: "B. Willemstein" Date: Sun, 23 Nov 2025 22:39:56 +0100 Subject: [PATCH 1/3] WIP fix for #235. Needs robust testing. Current method might be a bit heavy due to using sphereSearch and searching again from the object. --- ShareSuite/MoneySharingHooks.cs | 72 ++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/ShareSuite/MoneySharingHooks.cs b/ShareSuite/MoneySharingHooks.cs index c1b153e..24edde9 100644 --- a/ShareSuite/MoneySharingHooks.cs +++ b/ShareSuite/MoneySharingHooks.cs @@ -1,9 +1,14 @@ -using System; -using System.Linq; +using EntityStates.AffixVoid; using EntityStates.GoldGat; using MonoMod.Cil; using R2API.Utils; using RoR2; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel.Design; +using System.Linq; +using System.Reflection; using UnityEngine; using UnityEngine.Networking; @@ -28,6 +33,7 @@ internal static void UnHook() On.RoR2.Networking.NetworkManagerSystem.OnClientConnect -= GoldGatConnect; On.RoR2.Networking.NetworkManagerSystem.OnClientDisconnect -= GoldGatDisconnect; On.RoR2.HealthComponent.TakeDamage -= RollOfPenniesDamageHook; + On.RoR2.GoldSiphonNearbyBodyController.DrainGold -= SiphonGold; IL.EntityStates.GoldGat.GoldGatFire.FireBullet -= RemoveGoldGatMoneyLine; } @@ -46,6 +52,7 @@ internal static void Hook() On.RoR2.Networking.NetworkManagerSystem.OnClientConnect += GoldGatConnect; On.RoR2.Networking.NetworkManagerSystem.OnClientDisconnect += GoldGatDisconnect; On.RoR2.HealthComponent.TakeDamage += RollOfPenniesDamageHook; + On.RoR2.GoldSiphonNearbyBodyController.DrainGold += SiphonGold; if (ShareSuite.MoneyIsShared.Value && GeneralHooks.IsMultiplayer()) IL.EntityStates.GoldGat.GoldGatFire.FireBullet += RemoveGoldGatMoneyLine; @@ -106,6 +113,67 @@ public static bool SharedMoneyEnabled() return ShareSuite.MoneyIsShared.Value; } + private static void SiphonGold(On.RoR2.GoldSiphonNearbyBodyController.orig_DrainGold orig, + GoldSiphonNearbyBodyController self) + { + if (!GeneralHooks.IsMultiplayer() || !ShareSuite.MoneyIsShared.Value) + { + orig(self); + return; + } + //var bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic + // | BindingFlags.Static | BindingFlags.GetField; + //var amountOfPlayerField = typeof(GoldSiphonNearbyBodyController).GetField("tetheredPlayers", bindFlags); + //int amountOfPlayers = (int) amountOfPlayerField.GetValue(self); + Debug.Log("Siphoning gold"); + Debug.Log($"Shrine: {self.shrineGameObject.name}"); + Debug.Log($"Amount of Player: {self.GetFieldValue("tetheredPlayers")}"); + Debug.Log($"tierTracker: {self.GetFieldValue("tierTracker")}"); + Debug.Log($"goldDrainValue: {self.GetFieldValue("goldDrainValue")}"); + Debug.Log($"appliedDrain: {self.GetFieldValue("appliedDrain")}"); + + SphereSearch sphereSearch = self.GetFieldValue("sphereSearch"); + List candidates = new List(); + List hurtBoxes = new List(); + TeamMask mask = default(TeamMask); + mask.AddTeam(TeamIndex.Player); + sphereSearch.mask = LayerIndex.entityPrecise.mask; + sphereSearch.origin = self.gameObject.transform.position; + sphereSearch.radius = self.GetFieldValue("parentShrineReference").radius; + sphereSearch.queryTriggerInteraction = QueryTriggerInteraction.UseGlobal; + sphereSearch.RefreshCandidates(); + sphereSearch.FilterCandidatesByHurtBoxTeam(mask); + sphereSearch.OrderCandidatesByDistance(); + sphereSearch.FilterCandidatesByDistinctHurtBoxEntities(); + sphereSearch.GetHurtBoxes(hurtBoxes); + sphereSearch.GetCandidates(candidates); + sphereSearch.ClearCandidates(); + Debug.Log($"candidates: {candidates.Count}"); + Debug.Log($"hurtboxes {hurtBoxes.Count}"); + int players = 0; + if ((candidates.Count > 0) || (hurtBoxes.Count > 0)) + { + foreach (GameObject obj in candidates) + { + Debug.Log($"candidates: {(obj.name ?? "null")}"); + } + foreach (HurtBox obj in hurtBoxes) + { + if (obj == null) + Debug.Log("hurtBox: null hurtbox"); + else + //Debug.Log($"hurtBox: {(obj.name ?? "null")}"); + if (obj.healthComponent.body.isPlayerControlled) players++; + Debug.Log($"Players in range: {players}"); + } + } + + SharedMoneyValue -= (int) (players * self.GetFieldValue("appliedDrain")); + Debug.Log("-------"); + + orig(self); + } + private static void OnShopPurchase(On.RoR2.PurchaseInteraction.orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator) { From b2a9a1bb951f9b92ec7f051af46e203049bc9bc9 Mon Sep 17 00:00:00 2001 From: "B. Willemstein" Date: Mon, 24 Nov 2025 23:00:24 +0100 Subject: [PATCH 2/3] Fix for negative money draining. --- ShareSuite/MoneySharingHooks.cs | 36 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/ShareSuite/MoneySharingHooks.cs b/ShareSuite/MoneySharingHooks.cs index 24edde9..4d91ffb 100644 --- a/ShareSuite/MoneySharingHooks.cs +++ b/ShareSuite/MoneySharingHooks.cs @@ -121,16 +121,19 @@ private static void SiphonGold(On.RoR2.GoldSiphonNearbyBodyController.orig_Drain orig(self); return; } + + uint currentDrain = self.GetFieldValue("appliedDrain"); + //var bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic // | BindingFlags.Static | BindingFlags.GetField; //var amountOfPlayerField = typeof(GoldSiphonNearbyBodyController).GetField("tetheredPlayers", bindFlags); //int amountOfPlayers = (int) amountOfPlayerField.GetValue(self); + Debug.Log("-------"); Debug.Log("Siphoning gold"); - Debug.Log($"Shrine: {self.shrineGameObject.name}"); Debug.Log($"Amount of Player: {self.GetFieldValue("tetheredPlayers")}"); Debug.Log($"tierTracker: {self.GetFieldValue("tierTracker")}"); Debug.Log($"goldDrainValue: {self.GetFieldValue("goldDrainValue")}"); - Debug.Log($"appliedDrain: {self.GetFieldValue("appliedDrain")}"); + Debug.Log($"appliedDrain: {currentDrain}"); SphereSearch sphereSearch = self.GetFieldValue("sphereSearch"); List candidates = new List(); @@ -148,30 +151,35 @@ private static void SiphonGold(On.RoR2.GoldSiphonNearbyBodyController.orig_Drain sphereSearch.GetHurtBoxes(hurtBoxes); sphereSearch.GetCandidates(candidates); sphereSearch.ClearCandidates(); - Debug.Log($"candidates: {candidates.Count}"); - Debug.Log($"hurtboxes {hurtBoxes.Count}"); int players = 0; - if ((candidates.Count > 0) || (hurtBoxes.Count > 0)) + if (hurtBoxes.Count > 0) { - foreach (GameObject obj in candidates) - { - Debug.Log($"candidates: {(obj.name ?? "null")}"); - } foreach (HurtBox obj in hurtBoxes) { if (obj == null) Debug.Log("hurtBox: null hurtbox"); else - //Debug.Log($"hurtBox: {(obj.name ?? "null")}"); if (obj.healthComponent.body.isPlayerControlled) players++; Debug.Log($"Players in range: {players}"); } } - SharedMoneyValue -= (int) (players * self.GetFieldValue("appliedDrain")); - Debug.Log("-------"); - - orig(self); + Debug.Log($"currentDrain {currentDrain}"); + Debug.Log($"SharedMoneyValue {SharedMoneyValue}"); + if (currentDrain == 4294967295) { + Debug.Log("We're at the stupid value again, are we not initialized?... Calling orig."); + orig(self); + return; + } + if (SharedMoneyValue >= (int) currentDrain) { + SharedMoneyValue -= (int) (players * self.GetFieldValue("appliedDrain")); + orig(self); + return; + } + else { + Debug.Log("Not Draining due to too little money"); + return; + } } private static void OnShopPurchase(On.RoR2.PurchaseInteraction.orig_OnInteractionBegin orig, From 5df32a33a866cb27f1c7092931726bcbaab3ae78 Mon Sep 17 00:00:00 2001 From: "B. Willemstein" Date: Sat, 29 Nov 2025 21:01:30 +0100 Subject: [PATCH 3/3] Remove some redundant logging. --- ShareSuite/MoneySharingHooks.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ShareSuite/MoneySharingHooks.cs b/ShareSuite/MoneySharingHooks.cs index 4d91ffb..71377c6 100644 --- a/ShareSuite/MoneySharingHooks.cs +++ b/ShareSuite/MoneySharingHooks.cs @@ -128,13 +128,14 @@ private static void SiphonGold(On.RoR2.GoldSiphonNearbyBodyController.orig_Drain // | BindingFlags.Static | BindingFlags.GetField; //var amountOfPlayerField = typeof(GoldSiphonNearbyBodyController).GetField("tetheredPlayers", bindFlags); //int amountOfPlayers = (int) amountOfPlayerField.GetValue(self); +#if DEBUG Debug.Log("-------"); Debug.Log("Siphoning gold"); Debug.Log($"Amount of Player: {self.GetFieldValue("tetheredPlayers")}"); Debug.Log($"tierTracker: {self.GetFieldValue("tierTracker")}"); Debug.Log($"goldDrainValue: {self.GetFieldValue("goldDrainValue")}"); Debug.Log($"appliedDrain: {currentDrain}"); - +#endif SphereSearch sphereSearch = self.GetFieldValue("sphereSearch"); List candidates = new List(); List hurtBoxes = new List(); @@ -157,27 +158,36 @@ private static void SiphonGold(On.RoR2.GoldSiphonNearbyBodyController.orig_Drain foreach (HurtBox obj in hurtBoxes) { if (obj == null) + { Debug.Log("hurtBox: null hurtbox"); - else + } + else { if (obj.healthComponent.body.isPlayerControlled) players++; +#if DEBUG Debug.Log($"Players in range: {players}"); +#endif + } } } - +#if DEBUG Debug.Log($"currentDrain {currentDrain}"); Debug.Log($"SharedMoneyValue {SharedMoneyValue}"); +#endif if (currentDrain == 4294967295) { Debug.Log("We're at the stupid value again, are we not initialized?... Calling orig."); orig(self); return; } - if (SharedMoneyValue >= (int) currentDrain) { + if (SharedMoneyValue >= (int) currentDrain) + { SharedMoneyValue -= (int) (players * self.GetFieldValue("appliedDrain")); orig(self); return; } else { +#if DEBUG Debug.Log("Not Draining due to too little money"); +#endif return; } }