Decompiled source of Balance Changes For Greedy Men v0.1.4

BepInEx/Plugins/Mod for GWYF.dll

Decompiled 19 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Extensions;
using FMOD.Studio;
using FMODUnity;
using HarmonyLib;
using Mirror;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[HarmonyPatch(typeof(CosmeticWardrobe), "TryEquipCosmetic")]
internal class Patch_EquipLockedCosmetics
{
	private static bool Prefix(CosmeticWardrobe __instance, int spawnIndex)
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)NetworkClient.localPlayer == (Object)null)
		{
			return false;
		}
		Traverse val = Traverse.Create((object)__instance);
		Transform[] value = val.Field("spawnTransforms").GetValue<Transform[]>();
		int value2 = val.Field("currentPage").GetValue<int>();
		List<CosmeticData> value3 = val.Field("currentCategoryCosmetics").GetValue<List<CosmeticData>>();
		if (value == null || spawnIndex < 0 || spawnIndex >= value.Length)
		{
			return false;
		}
		if (spawnIndex == 0)
		{
			PlayerCustomization component = ((Component)NetworkClient.localPlayer).GetComponent<PlayerCustomization>();
			if (component != null)
			{
				component.ClearCategory(val.Field("currentCategory").GetValue<CosmeticType>());
			}
			return false;
		}
		int value4 = val.Method("GetUsableSlotsPerPage", Array.Empty<object>()).GetValue<int>();
		int num = value2 * value4 + (spawnIndex - 1);
		if (value3 == null || num < 0 || num >= value3.Count)
		{
			return false;
		}
		CosmeticData val2 = value3[num];
		if ((Object)(object)val2 == (Object)null)
		{
			return false;
		}
		PlayerCustomization component2 = ((Component)NetworkClient.localPlayer).GetComponent<PlayerCustomization>();
		if ((Object)(object)component2 == (Object)null)
		{
			return false;
		}
		component2.CmdChangeCustomization(val2.cosmeticId, true);
		FixingPlguin.Log.LogInfo((object)$"Forced equip: {val2.cosmeticName} ({val2.cosmeticId})");
		return false;
	}
}
[HarmonyPatch]
public static class SpawnWakeFixPatch
{
	[CompilerGenerated]
	private sealed class <FinalWakeRoutine>d__1 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public PlayerController pc;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <FinalWakeRoutine>d__1(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(0.5f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)pc == (Object)null)
				{
					return false;
				}
				SafeInvoke(pc, "ServerLock", false);
				pc.LocalLock(false);
				SafeInvoke(pc, "ServerWakeUp");
				<>2__current = (object)new WaitForSeconds(0.5f);
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				SafeInvoke(pc, "ServerLock", false);
				pc.LocalLock(false);
				Debug.Log((object)"[WakeFix] Wake applied");
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[HarmonyPatch(typeof(SpawnBoxPlayerRagdollTrigger), "AssignPlayer")]
	[HarmonyPostfix]
	private static void AssignPlayerPatch(PlayerController player)
	{
		if (!((Object)(object)player == (Object)null) && NetworkServer.active)
		{
			((MonoBehaviour)player).StartCoroutine(FinalWakeRoutine(player));
		}
	}

	[IteratorStateMachine(typeof(<FinalWakeRoutine>d__1))]
	private static IEnumerator FinalWakeRoutine(PlayerController pc)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <FinalWakeRoutine>d__1(0)
		{
			pc = pc
		};
	}

	private static void SafeInvoke(object obj, string methodName, params object[] args)
	{
		obj.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(obj, args);
	}
}
[HarmonyPatch(typeof(GameManager), "OnAwake")]
public class Patch_GameManager_OnAwake
{
	private static void Postfix(GameManager __instance)
	{
		FieldInfo fieldInfo = AccessTools.Field(typeof(GameManager), "_gs");
		object? value = fieldInfo.GetValue(__instance);
		GameSettings val = (GameSettings)((value is GameSettings) ? value : null);
		if (val != null)
		{
			val.dayDuration = FixingPlguin.timerSetting.Value;
		}
	}
}
[HarmonyPatch(typeof(GameManager), "OnTimerChanged")]
public class Patch_OnTimerChanged
{
	private static bool Prefix(float oldValue, float newValue)
	{
		NetworkSingleton<GameUI>.Instance.SetTimerText((float)FixingPlguin.timerSetting.Value - newValue);
		return false;
	}
}
[HarmonyPatch(typeof(GameSettings), "GetQuota")]
public class Patch_GetQuota
{
	private static bool Prefix(int index, long previousQuota, long currentMoney, ref long __result)
	{
		if (!FixingPlguin.quotaSetting.Value)
		{
			return true;
		}
		if (index == 0)
		{
			__result = 1200L;
			return false;
		}
		if (previousQuota <= 0)
		{
			__result = 1200L;
			return false;
		}
		GameManager instance = NetworkSingleton<GameManager>.Instance;
		int num = (((Object)(object)instance != (Object)null) ? instance.daysPassed : 0);
		float num2 = Mathf.Clamp(2.5f + 0.5f * (float)num, 2f, 7.5f);
		__result = (long)((float)previousQuota * num2 * FixingPlguin.scaler.Value);
		return false;
	}
}
[HarmonyPatch(typeof(GameManager), "ProgressNextQuota")]
internal class Patch_ProgressNextQuota
{
	private static long cachedQuota;

	private static void Prefix(GameManager __instance)
	{
		cachedQuota = __instance.currentQuota;
	}

	private static void Postfix()
	{
		MoneyManager instance = NetworkSingleton<MoneyManager>.Instance;
		instance.TryChangeBalance(-cachedQuota, (PlayerProfile)null, (ChangeType)4);
	}
}
[BepInPlugin("fixes.gamble", "Gamble Fixer", "0.1.3")]
public class FixingPlguin : BaseUnityPlugin
{
	public static ManualLogSource Log;

	internal static ConfigEntry<float> scaler;

	internal static ConfigEntry<bool> maxPlayers;

	internal static ConfigEntry<bool> ticketSetting;

	internal static ConfigEntry<bool> shareUpgrades;

	internal static ConfigEntry<bool> empoweredUpgrades;

	internal static ConfigEntry<int> timerSetting;

	internal static ConfigEntry<bool> rerollSetting;

	internal static ConfigEntry<bool> quotaSetting;

	internal static ConfigEntry<bool> payQuotaSetting;

	private void Awake()
	{
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Expected O, but got Unknown
		quotaSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("Quota Settings", "Custom Quota", true, "Enables custom quota calculation");
		scaler = ((BaseUnityPlugin)this).Config.Bind<float>("Quota Settings", "Quota Mult", 1f, "Multiplies quota for each day by this amount (only custom)");
		payQuotaSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("Quota Settings", "Pay Quota", true, "Makes you pay quota at the end of each day");
		timerSetting = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Game Timer", 450, "Changes how long the game timer is (Seconds)");
		maxPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Max Players", true, "Make max lobby size 40 instead of 8");
		ticketSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Custom Tickets", true, "Enable custom ticket calculation, allowing 50 tickets each day from over quota");
		shareUpgrades = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Share Upgrades", true, "Enable sharing of upgrades (Divides them out)");
		empoweredUpgrades = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Empowered Upgrades", true, "Enables a 1/250 chance for upgrades to give 10x value");
		rerollSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Reroll Logic", true, "Changes the shop to also reroll empty slots");
		Log = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("fixes.gamble");
		val.PatchAll();
		Log.LogInfo((object)"Fixer loaded");
	}

	private void DumpAllEvents()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		System studioSystem = RuntimeManager.StudioSystem;
		Bank[] array = default(Bank[]);
		((System)(ref studioSystem)).getBankList(ref array);
		Bank[] array2 = array;
		EventDescription[] array3 = default(EventDescription[]);
		string text = default(string);
		for (int i = 0; i < array2.Length; i++)
		{
			Bank val = array2[i];
			((Bank)(ref val)).getEventList(ref array3);
			EventDescription[] array4 = array3;
			for (int j = 0; j < array4.Length; j++)
			{
				EventDescription val2 = array4[j];
				((EventDescription)(ref val2)).getPath(ref text);
				Log.LogInfo((object)("EVENT: " + text));
			}
		}
	}
}
[HarmonyPatch(typeof(UpgradeManager), "ChangeUpgradeData")]
internal class Patch_ShareUpgrades
{
	private static bool isProcessing;

	private static EventReference wheelWinEvent;

	private static bool Prefix(UpgradeManager __instance, ulong steamId, PlayerUpgradeType type, float amount)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		if (!FixingPlguin.shareUpgrades.Value)
		{
			return true;
		}
		if (isProcessing)
		{
			return false;
		}
		try
		{
			isProcessing = true;
			PlayerProfile[] array = Object.FindObjectsByType<PlayerProfile>((FindObjectsSortMode)0);
			float upgradeData = __instance.GetUpgradeData(steamId, type);
			float num = upgradeData + amount;
			bool flag = false;
			if (NetworkServer.active && Random.Range(0f, 1f) < 0.004f && FixingPlguin.empoweredUpgrades.Value)
			{
				num = upgradeData + amount * 10f;
				PlayerController val = Object.FindObjectsByType<PlayerController>((FindObjectsSortMode)0).FirstOrDefault();
				if ((Object)(object)val != (Object)null)
				{
					if (((EventReference)(ref wheelWinEvent)).IsNull)
					{
						wheelWinEvent = RuntimeManager.PathToEventReference("event:/Games/WheelOfFortune/WheelFortuneWin");
					}
					SFXManager.SFXOneShot(wheelWinEvent, ((Component)val).transform.position);
					FixingPlguin.Log.LogInfo((object)"Wheel jackpot played.");
				}
			}
			PlayerProfile[] array2 = array;
			foreach (PlayerProfile val2 in array2)
			{
				__instance.SetUpgradeData(val2.steamId, type, num);
			}
			return false;
		}
		finally
		{
			isProcessing = false;
		}
	}
}
internal static class StampRuntimeState
{
	public static bool IsRerolling;
}
[HarmonyPatch(typeof(ItemStampManager), "RerollAllItemStamps")]
internal class Patch_RerollAllItemStamps
{
	private static void Prefix(ItemStampManager __instance)
	{
		if (FixingPlguin.rerollSetting.Value)
		{
			StampRuntimeState.IsRerolling = true;
			if (AccessTools.Field(typeof(ItemStampManager), "_preAssignedItems").GetValue(__instance) is Dictionary<string, GameObject> dictionary)
			{
				dictionary.Clear();
			}
		}
	}

	private static void Postfix()
	{
		StampRuntimeState.IsRerolling = false;
	}
}
[HarmonyPatch(typeof(ItemStampManager), "DestroyAllSpawnedInstances")]
internal class Patch_DestroyAllSpawnedInstances
{
	private static void Postfix(ItemStampManager __instance)
	{
		if (FixingPlguin.rerollSetting.Value && StampRuntimeState.IsRerolling && AccessTools.Field(typeof(ItemStampManager), "_purchasedStamps").GetValue(__instance) is HashSet<ItemStamp> hashSet)
		{
			hashSet.Clear();
		}
	}
}
[HarmonyPatch(typeof(ItemStampManager), "RetrieveAndRespawnAllItemStamps")]
internal class Patch_RetrieveAndRespawnAllItemStamps
{
	private static void Prefix(ItemStampManager __instance)
	{
		if (FixingPlguin.rerollSetting.Value && AccessTools.Field(typeof(ItemStampManager), "_preAssignedItems").GetValue(__instance) is Dictionary<string, GameObject> dictionary)
		{
			dictionary.Clear();
		}
	}
}
[HarmonyPatch(typeof(GameSettings), "GetQuotaExcessReward")]
internal class Patch_QuotaReward
{
	private static bool Prefix(int floor, long quota, long money, ref int __result)
	{
		if (!FixingPlguin.ticketSetting.Value)
		{
			return true;
		}
		if (quota <= 0 || money <= quota)
		{
			__result = 0;
			return false;
		}
		long num = money * 100 / quota;
		int num2 = 0;
		num2 = (int)((num <= 200) ? ((num - 100) / 20) : ((num <= 300) ? (5 + (int)((num - 200) / 20)) : ((num <= 450) ? (10 + (int)((num - 300) / 30)) : ((num <= 600) ? (15 + (int)((num - 450) / 30)) : ((num <= 750) ? (20 + (int)((num - 600) / 30)) : ((num <= 850) ? (25 + (int)((num - 750) / 30)) : ((num <= 1000) ? (30 + (int)((num - 850) / 30)) : ((num <= 1250) ? (35 + (int)((num - 1000) / 50)) : ((num > 1500) ? (45 + (int)((num - 1500) / 100)) : (40 + (int)((num - 1250) / 50)))))))))));
		if (num2 > 50)
		{
			num2 = 50;
		}
		__result = num2;
		return false;
	}
}
[HarmonyPatch(typeof(Upgrade), "Start")]
internal class Patch_UpgradeValues
{
	private static void Prefix(Upgrade __instance)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Expected I4, but got Unknown
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Expected O, but got Unknown
		if (FixingPlguin.shareUpgrades.Value)
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(Upgrade), "upgradeType");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(Upgrade), "value");
			FieldInfo fieldInfo3 = AccessTools.Field(typeof(Upgrade), "valueText");
			PlayerUpgradeType val = (PlayerUpgradeType)fieldInfo.GetValue(__instance);
			float num = 0.1f;
			float num2 = 0.05f;
			PlayerUpgradeType val2 = val;
			PlayerUpgradeType val3 = val2;
			switch ((int)val3)
			{
			case 0:
				num = 0.5f;
				num2 = 0.125f;
				break;
			case 1:
				num = 0.25f;
				num2 = 0.1f;
				break;
			case 3:
				num = 0.15f;
				num2 = 0.075f;
				break;
			case 2:
				num = 0.5f;
				num2 = 0.5f;
				break;
			}
			PlayerProfile[] array = Object.FindObjectsByType<PlayerProfile>((FindObjectsSortMode)0);
			int num3 = Mathf.Max(array.Length, 1);
			float num4 = num / (float)num3;
			num4 = Mathf.Clamp(num4, num2, num);
			num4 = (float)Math.Round(num4, 3);
			fieldInfo2.SetValue(__instance, num4);
			TextMeshPro val4 = (TextMeshPro)fieldInfo3.GetValue(__instance);
			((TMP_Text)val4).text = (num4 * 100f).ToString("0.#") + "%";
		}
	}
}
namespace GambleMaxPlayers;

[HarmonyPatch(typeof(GoOnlineClient), "CreateLobby")]
internal static class Patch_CreateLobby
{
	private static void Prefix(GoOnlineClient __instance)
	{
		FieldInfo fieldInfo = AccessTools.Field(typeof(GoOnlineClient), "lobbySettings");
		object? value = fieldInfo.GetValue(__instance);
		LobbySettings val = (LobbySettings)((value is LobbySettings) ? value : null);
		if ((Object)(object)val != (Object)null && FixingPlguin.maxPlayers.Value)
		{
			val.maxPlayers = 40;
		}
	}
}
[HarmonyPatch(typeof(NetworkServer), "Listen")]
internal static class NetworkServerListenPatch
{
	private static void Prefix(ref int maxConns)
	{
		maxConns = 40;
	}
}