Decompiled source of MaxwellRealism Mod v0.0.4

NGA.MaxwellRealismMod.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("NGA")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Persistent player progression! Raid, stash loot, and deploy with seemless scene/loadout saving.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("NGA.MaxwellRealismMod")]
[assembly: AssemblyTitle("BepInEx Plugin Title")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace NGA
{
	[BepInPlugin("NGA.MaxwellRealismMod", "MaxwellRealismMod", "0.0.1")]
	[BepInDependency("nrgill28.Sodalite", "1.4.1")]
	[BepInDependency("NGA.JsonFileIO", "0.0.0")]
	[BepInProcess("h3vr.exe")]
	public class MaxwellRealismMod : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(FVRPhysicalObject))]
		[HarmonyPatch("FVRFixedUpdate")]
		public class FVRPhysicalObjectFVRFixedUpdate : MonoBehaviour
		{
			private static void Postfix(FVRPhysicalObject __instance)
			{
				//IL_006e: 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_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				if (CheckTomigotchiSkip() || ((Object)((Component)__instance).gameObject).name != "Dingus(Clone)")
				{
					return;
				}
				ScaleObj(__instance);
				Transform val = ((Component)__instance).transform.Find("_Patty-Nose");
				if ((Object)(object)val == (Object)null)
				{
					Logger.LogWarning((object)"No _Patty-Nose child object found.");
					return;
				}
				Vector3 position = val.position;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(0.01f, 0.01f, 0.01f);
				Collider[] array = Physics.OverlapBox(position, val2);
				Collider[] array2 = array;
				foreach (Collider val3 in array2)
				{
					if (((Object)((Component)val3).gameObject).name == "BeefCan(Clone)")
					{
						Logger.LogMessage((object)("You just ate: " + ((Object)((Component)val3).gameObject).name));
						UpdateJustAte(__instance);
						RefreshSaveFile();
						Logger.LogMessage((object)"Vars saved.");
						Object.Destroy((Object)(object)((Component)val3).gameObject);
					}
				}
			}
		}

		[HarmonyPatch(typeof(TNH_Manager))]
		[HarmonyPatch("SetPhase_Completed")]
		public class TNH_ManagerSetPhase_Completed : MonoBehaviour
		{
			private static void Postfix(TNH_Manager __instance)
			{
				if (!CheckCancerSkip())
				{
					payment_balance += __instance.m_numTokens;
					RefreshSaveFile();
					Logger.LogMessage((object)("Payment balanced added: " + __instance.m_numTokens + " new total: " + payment_balance));
				}
			}
		}

		private static ConfigEntry<bool> _Feeding;

		private static ConfigEntry<int> _Feeding_Cycle_h;

		private static ConfigEntry<bool> _Cancer;

		private static ConfigEntry<int> _Insurance_Copay;

		private static ExtensibleDictionary myDic;

		private static string mod_folder_name = "AGN-MaxwellRealism_Mod";

		private static string save_file_name = "agn_maxwell_realism_mod.json";

		private static DateTime date_installed;

		private static int payment_balance;

		private static DateTime last_time_ate;

		private static float overall_size_scale;

		private static float wide_mult;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("AGN.MaxwellRealismMod");
			Logger.LogMessage((object)"New harmony");
			SetUpConfigFields();
			Logger.LogMessage((object)"Setted the fields");
			val.PatchAll();
			Logger.LogMessage((object)"Hello, world! Sent from AGN.MaxwellRealismMod 0.0.1");
			InitializeSaveFile();
			ReadVarsFromSaveFile();
			Logger.LogMessage((object)"Save file ready and read");
			if (_Cancer.Value)
			{
				DateTime dateTime = date_installed.AddMonths(9);
				DateTime now = DateTime.Now;
				int num = (int)(dateTime - now).TotalDays;
				Logger.LogMessage((object)("Days until Maxwell's bills are due (9 months after install): " + num));
			}
		}

		private void InitializeSaveFile()
		{
			string text = FileIO.ReadFile(mod_folder_name, save_file_name);
			if (text == null)
			{
				text = CreateDefaultSaveFile();
				FileIO.WriteToFile(mod_folder_name, save_file_name, text);
			}
			else
			{
				myDic = ExtensibleDictionary.FromJson(text);
			}
		}

		private static string CreateDefaultSaveFile()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			myDic = new ExtensibleDictionary();
			myDic.AddEntry("overall_size_scale", 0.3f.ToString());
			myDic.AddEntry("wide_mult", 1f.ToString());
			ExtensibleDictionary obj = myDic;
			DateTime minValue = DateTime.MinValue;
			obj.AddEntry("last_time_ate", minValue.ToString("o"));
			myDic.AddEntry("date_installed", DateTime.Now.ToString("o"));
			myDic.AddEntry("payment_balance", 0.ToString());
			return myDic.ToJson();
		}

		private static void ReadVarsFromSaveFile()
		{
			overall_size_scale = float.Parse(myDic.GetValue("overall_size_scale"));
			wide_mult = float.Parse(myDic.GetValue("wide_mult"));
			last_time_ate = DateTime.Parse(myDic.GetValue("last_time_ate"));
			date_installed = DateTime.Parse(myDic.GetValue("date_installed"));
			payment_balance = int.Parse(myDic.GetValue("payment_balance"));
		}

		private static void WriteVarsToMyDic()
		{
			if (myDic == null)
			{
				Logger.LogError((object)"myDic is not initialized.");
				return;
			}
			myDic.InsertOrUpdateEntry("overall_size_scale", overall_size_scale.ToString());
			myDic.InsertOrUpdateEntry("wide_mult", wide_mult.ToString());
			myDic.InsertOrUpdateEntry("last_time_ate", last_time_ate.ToString("o"));
			myDic.InsertOrUpdateEntry("date_installed", date_installed.ToString("o"));
			myDic.InsertOrUpdateEntry("payment_balance", payment_balance.ToString());
		}

		private static void RefreshSaveFile()
		{
			WriteVarsToMyDic();
			FileIO.WriteToFile(mod_folder_name, save_file_name, myDic.ToJson());
			myDic = ExtensibleDictionary.FromJson(FileIO.ReadFile(mod_folder_name, save_file_name));
			ReadVarsFromSaveFile();
		}

		private void SetUpConfigFields()
		{
			_Feeding = ((BaseUnityPlugin)this).Config.Bind<bool>("Tomigotchi", "Feeding", true, "Jess is just a kitten, you gotta feed her so she grows into a strong Maxwell :)");
			_Feeding_Cycle_h = ((BaseUnityPlugin)this).Config.Bind<int>("Tomigotchi", "Feed every X hours", 48, "The number of hours before Jess needs to be fed again. Overfeeding is not recommended.");
			_Cancer = ((BaseUnityPlugin)this).Config.Bind<bool>("Hardcore", "Cancer", false, "[NOT YET IMPLEMENTED] Maxwell has cancer (like irl) and due to insufficient health insurance needs help with her bills.");
			_Insurance_Copay = ((BaseUnityPlugin)this).Config.Bind<int>("Hardcore", "Insurance CoPay", 500, "The amount in TnH tokens needed to pay for Maxwells cancer treatment. Collected on TnH completion.");
		}

		private static bool CheckTomigotchiSkip()
		{
			return !_Feeding.Value;
		}

		private static void UpdateJustAte(FVRPhysicalObject __instance)
		{
			TimeSpan timeSpan = DateTime.Now - last_time_ate;
			if (timeSpan.TotalHours <= (double)_Feeding_Cycle_h.Value && wide_mult < 5f)
			{
				Logger.LogMessage((object)"Maxwell got a bit wider");
				wide_mult += 1f;
			}
			else if (timeSpan.TotalHours <= (double)(2 * _Feeding_Cycle_h.Value))
			{
				if (overall_size_scale < 1f)
				{
					Logger.LogMessage((object)"Maxwell grew by 0.1 :)");
					overall_size_scale += 0.1f;
					wide_mult = 1f;
				}
			}
			else
			{
				Logger.LogWarning((object)("You haven't feed Max in a while! Make sure to feed him after " + _Feeding_Cycle_h.Value + " hours but before " + 2 * _Feeding_Cycle_h.Value));
			}
			last_time_ate = DateTime.Now;
			ScaleObj(__instance);
		}

		private static void ScaleObj(FVRPhysicalObject __instance)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			float num = overall_size_scale * wide_mult;
			float num2 = overall_size_scale;
			float num3 = overall_size_scale;
			((Component)__instance).transform.localScale = new Vector3(num, num2, num3);
		}

		private static bool CheckCancerSkip()
		{
			return !_Cancer.Value;
		}
	}
}