Decompiled source of ChaosLogs v0.9.1

MegabonkChaosMods.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Assets.Scripts.Actors.Player;
using Assets.Scripts.Inventory__Items__Pickups;
using Assets.Scripts.Inventory__Items__Pickups.Stats;
using Assets.Scripts.Menu.Shop;
using Assets.Scripts.Saves___Serialization.Progression.Achievements;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyCompany("MegabonkChaosMods")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MegabonkChaosMods")]
[assembly: AssemblyTitle("MegabonkChaosMods")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace MegabonkChaosMod;

[BepInPlugin("com.Wohou.chaoslogsmod", "Chaos Logs Mod", "1.0.0")]
public class ChaosLog : BasePlugin
{
	public static Dictionary<int, float> statsBefore = new Dictionary<int, float>();

	public static bool isMonitoring = false;

	public override void Load()
	{
		((BasePlugin)this).Log.LogInfo((object)"Chaos Logs mod loaded successfully!");
		((BasePlugin)this).Log.LogInfo((object)"Chaos Logs mod By Wohou");
		Harmony.CreateAndPatchAll(typeof(ChaosLog), (string)null);
	}

	public static float GetTotalStatValue(StatInventory inventory, int statIndex)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		float num = 0f;
		EStat val = (EStat)statIndex;
		if (inventory.permanentChanges != null && inventory.permanentChanges.ContainsKey(val))
		{
			List<StatModifier> val2 = inventory.permanentChanges[val];
			if (val2 != null)
			{
				for (int i = 0; i < val2.Count; i++)
				{
					num += val2[i].modification;
				}
			}
		}
		return num;
	}

	public static void AppendChaosSignature(ShrineLogs ui)
	{
		try
		{
			ScrollRect componentInChildren = ((Component)ui).gameObject.GetComponentInChildren<ScrollRect>();
			Transform val = (Transform)(((Object)(object)componentInChildren != (Object)null) ? ((object)componentInChildren.content) : ((object)((Component)ui).transform));
			if (val.childCount <= 0)
			{
				return;
			}
			Transform child = val.GetChild(val.childCount - 1);
			Il2CppArrayBase<MonoBehaviour> componentsInChildren = ((Component)child).GetComponentsInChildren<MonoBehaviour>();
			global::System.Collections.Generic.IEnumerator<MonoBehaviour> enumerator = componentsInChildren.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					MonoBehaviour current = enumerator.Current;
					string name = ((MemberInfo)((Object)current).GetIl2CppType()).Name;
					if (!name.Contains("Text") && !name.Contains("TMP"))
					{
						continue;
					}
					PropertyInfo property = ((object)current).GetType().GetProperty("text");
					if (property != (PropertyInfo)null)
					{
						string text = property.GetValue((object)current) as string;
						if (!string.IsNullOrEmpty(text) && !text.Contains("Chaos"))
						{
							string text2 = text + " <color=#A020F0> (Chaos)</color>";
							property.SetValue((object)current, (object)text2);
							break;
						}
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}
		catch
		{
		}
	}

	[HarmonyPatch(typeof(TomeInventory), "AddTome")]
	[HarmonyPrefix]
	public static void Prefix(TomeData tomeData)
	{
		if ((Object)(object)tomeData == (Object)null)
		{
			return;
		}
		string internalName = ((UnlockableBase)tomeData).GetInternalName();
		if (!string.IsNullOrEmpty(internalName) && internalName.Contains("Chaos") && (Object)(object)MyPlayer.Instance != (Object)null && MyPlayer.Instance.inventory != null)
		{
			StatInventory statInventory = MyPlayer.Instance.inventory.statInventory;
			statsBefore.Clear();
			for (int i = 0; i < 60; i++)
			{
				statsBefore[i] = GetTotalStatValue(statInventory, i);
			}
			isMonitoring = true;
		}
	}

	[HarmonyPatch(typeof(TomeInventory), "AddTome")]
	[HarmonyPostfix]
	public static void Postfix()
	{
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Expected O, but got Unknown
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		if (!isMonitoring)
		{
			return;
		}
		isMonitoring = false;
		if ((Object)(object)MyPlayer.Instance == (Object)null || MyPlayer.Instance.inventory == null)
		{
			return;
		}
		StatInventory statInventory = MyPlayer.Instance.inventory.statInventory;
		Il2CppArrayBase<ShrineLogs> val = Resources.FindObjectsOfTypeAll<ShrineLogs>();
		ShrineLogs val2 = ((val != null && val.Count > 0) ? val[0] : null);
		for (int i = 0; i < 60; i++)
		{
			float num = (statsBefore.ContainsKey(i) ? statsBefore[i] : 0f);
			float totalStatValue = GetTotalStatValue(statInventory, i);
			float num2 = totalStatValue - num;
			if (!(Mathf.Abs(num2) > 0.001f))
			{
				continue;
			}
			EStat stat = (EStat)i;
			if ((Object)(object)val2 != (Object)null)
			{
				StatModifier val3 = new StatModifier();
				val3.stat = stat;
				val3.modification = num2;
				int num3 = i;
				if (num3 == 0 || num3 == 1 || num3 == 2 || num3 == 3 || num3 == 16 || num3 == 45 || num3 == 46 || num3 == 47)
				{
					val3.modifyType = (EStatModifyType)2;
				}
				else
				{
					val3.modifyType = (EStatModifyType)0;
				}
				val2.AddLog(val3, true);
				AppendChaosSignature(val2);
			}
		}
	}
}