Decompiled source of SprayPaintTzpReshMod v2.0.4

SprayPaintTzpReshMod.dll

Decompiled 10 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using SprayPaintTzpReshMod.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SprayPaintTzpReshMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("SprayPaintTzpReshMod")]
[assembly: AssemblyCopyright("Copyright © HP 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3fec7b08-f094-4da4-81c7-b273443948cc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SprayPaintTzpReshMod
{
	[BepInPlugin("Resh.SprayPaintTzpReshMod", "Spray Paint Tzp Resh Mod", "2.0.4")]
	public class SprayPaintTzpReshModBase : BaseUnityPlugin
	{
		private const string modGUID = "Resh.SprayPaintTzpReshMod";

		private const string modName = "Spray Paint Tzp Resh Mod";

		private const string modVersion = "2.0.4";

		private readonly Harmony harmony = new Harmony("Resh.SprayPaintTzpReshMod");

		private static SprayPaintTzpReshModBase Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Resh.SprayPaintTzpReshMod");
			mls.LogInfo((object)"SprayPaintTzp mod is live");
			harmony.PatchAll(typeof(SprayPaintTzpReshModBase));
			harmony.PatchAll(typeof(SprayPaintItemPatch));
			harmony.PatchAll(typeof(TetraChemicalItemPatch));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
		}
	}
}
namespace SprayPaintTzpReshMod.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static Dictionary<PlayerControllerB, PlayerControllerData> playerDataMap = new Dictionary<PlayerControllerB, PlayerControllerData>();

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void Update(PlayerControllerB __instance)
		{
			if (!playerDataMap.TryGetValue(__instance, out var value))
			{
				value = new PlayerControllerData();
				playerDataMap[__instance] = value;
			}
			FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerControllerB), "drunkness");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(PlayerControllerB), "drunknessInertia");
			FieldInfo fieldInfo3 = AccessTools.Field(typeof(PlayerControllerB), "drunknessSpeed");
			float num = (float)fieldInfo3.GetValue(__instance);
			float num2 = (float)fieldInfo2.GetValue(__instance);
			float num3 = (float)fieldInfo.GetValue(__instance);
			if (value.drunknessDup < 0.2f)
			{
				value.drunknessStage = 1f;
			}
			if (value.drunknessDup > 0.3f && value.drunknessDup < 0.85f)
			{
				value.drunknessStage = 2f;
			}
			if (value.drunknessDup > 0.99f)
			{
				value.drunknessStage = 3f;
			}
			if (num3 > 0f)
			{
				value.drunknessInertiaDup = Mathf.Clamp(num2 * 20f, -0.07f, 100f);
			}
			else if (num3 == 0f && value.drunknessDup > 0f)
			{
				value.drunknessInertiaDup = -0.07f;
			}
			else if (num3 == 0f && value.drunknessDup == 0f)
			{
				value.drunknessInertiaDup = 0f;
			}
			value.drunknessDup = Mathf.Clamp(value.drunknessDup + Time.deltaTime / 12f * num * value.drunknessInertiaDup, 0f, 1f);
			FieldInfo fieldInfo4 = AccessTools.Field(typeof(PlayerControllerB), "sprintMultiplier");
			FieldInfo fieldInfo5 = AccessTools.Field(typeof(PlayerControllerB), "isSprinting");
			FieldInfo fieldInfo6 = AccessTools.Field(typeof(PlayerControllerB), "sprintMeter");
			bool flag = (bool)fieldInfo5.GetValue(__instance);
			float num4 = (float)fieldInfo6.GetValue(__instance);
			if (value.drunknessStage == 2f && !flag)
			{
				fieldInfo4.SetValue(__instance, 1.08f);
				fieldInfo6.SetValue(__instance, Mathf.Clamp(num4 + 0.0022f, 0f, 1f));
			}
			if (value.drunknessStage == 3f && !flag)
			{
				fieldInfo4.SetValue(__instance, 1.08f);
				fieldInfo6.SetValue(__instance, 1f);
			}
			if (value.drunknessStage == 2f && flag)
			{
				fieldInfo4.SetValue(__instance, 2.43f);
			}
			if (value.drunknessStage == 3f && flag)
			{
				fieldInfo4.SetValue(__instance, 2.43f);
				fieldInfo6.SetValue(__instance, 1f);
			}
		}
	}
	internal class PlayerControllerData
	{
		public float drunknessDup = 0f;

		public float drunknessInertiaDup = 0f;

		public float drunknessStage = 1f;
	}
	[HarmonyPatch(typeof(SprayPaintItem))]
	internal class SprayPaintItemPatch
	{
		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		private static void LateUpdate(SprayPaintItem __instance)
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(SprayPaintItem), "sprayCanTank");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(SprayPaintItem), "sprayCanShakeMeter");
			if (fieldInfo != null)
			{
				fieldInfo.SetValue(__instance, 100f);
			}
			if (fieldInfo2 != null)
			{
				fieldInfo2.SetValue(__instance, 100f);
			}
		}

		[HarmonyPatch("ItemInteractLeftRight")]
		[HarmonyPostfix]
		private static void ItemInteractLeftRight(bool right, SprayPaintItem __instance, ref Material[] ___sprayCanMats)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			FieldInfo fieldInfo = AccessTools.Field(typeof(GrabbableObject), "playerHeldBy");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(SprayPaintItem), "isSpraying");
			FieldInfo fieldInfo3 = AccessTools.Field(typeof(SprayPaintItem), "sprayCanMatsIndex");
			int num = (int)fieldInfo3.GetValue(__instance);
			PlayerControllerB val = (PlayerControllerB)fieldInfo.GetValue(__instance);
			if (fieldInfo != null && (Object)(object)val != (Object)null && fieldInfo2 != null)
			{
				bool flag = (bool)fieldInfo2.GetValue(__instance);
				if (!right && !((Object)(object)val == (Object)null) && !flag && fieldInfo3 != null)
				{
					num = ((num != ___sprayCanMats.Length - 1) ? (num + 1) : 0);
					fieldInfo3.SetValue(__instance, num);
				}
			}
		}
	}
	[HarmonyPatch(typeof(TetraChemicalItem))]
	internal class TetraChemicalItemPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void Update(TetraChemicalItem __instance)
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(TetraChemicalItem), "fuel");
			if (fieldInfo != null)
			{
				fieldInfo.SetValue(__instance, 10f);
			}
		}
	}
}