Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 88 additions & 2 deletions ShareSuite/MoneySharingHooks.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -106,6 +113,85 @@ 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;
}

uint currentDrain = self.GetFieldValue<uint>("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);
#if DEBUG
Debug.Log("-------");
Debug.Log("Siphoning gold");
Debug.Log($"Amount of Player: {self.GetFieldValue<int>("tetheredPlayers")}");
Debug.Log($"tierTracker: {self.GetFieldValue<int>("tierTracker")}");
Debug.Log($"goldDrainValue: {self.GetFieldValue<int>("goldDrainValue")}");
Debug.Log($"appliedDrain: {currentDrain}");
#endif
SphereSearch sphereSearch = self.GetFieldValue<SphereSearch>("sphereSearch");
List<GameObject> candidates = new List<GameObject>();
List<HurtBox> hurtBoxes = new List<HurtBox>();
TeamMask mask = default(TeamMask);
mask.AddTeam(TeamIndex.Player);
sphereSearch.mask = LayerIndex.entityPrecise.mask;
sphereSearch.origin = self.gameObject.transform.position;
sphereSearch.radius = self.GetFieldValue<HalcyoniteShrineInteractable>("parentShrineReference").radius;
sphereSearch.queryTriggerInteraction = QueryTriggerInteraction.UseGlobal;
sphereSearch.RefreshCandidates();
sphereSearch.FilterCandidatesByHurtBoxTeam(mask);
sphereSearch.OrderCandidatesByDistance();
sphereSearch.FilterCandidatesByDistinctHurtBoxEntities();
sphereSearch.GetHurtBoxes(hurtBoxes);
sphereSearch.GetCandidates(candidates);
sphereSearch.ClearCandidates();
int players = 0;
if (hurtBoxes.Count > 0)
{
foreach (HurtBox obj in hurtBoxes)
{
if (obj == null)
{
Debug.Log("hurtBox: null hurtbox");
}
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)
{
SharedMoneyValue -= (int) (players * self.GetFieldValue<uint>("appliedDrain"));
orig(self);
return;
}
else {
#if DEBUG
Debug.Log("Not Draining due to too little money");
#endif
return;
}
}

private static void OnShopPurchase(On.RoR2.PurchaseInteraction.orig_OnInteractionBegin orig,
PurchaseInteraction self, Interactor activator)
{
Expand Down