Decompiled source of GlueEfficiency v1.1.1

catrice.GlueEfficiency.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("catrice.GlueEfficiency")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyProduct("catrice.GlueEfficiency")]
[assembly: AssemblyTitle("catrice.GlueEfficiency")]
[assembly: AssemblyVersion("0.1.1.0")]
namespace catrice.GlueEfficiency;

[BepInPlugin("com.catrice.GlueEfficiency", "GlueEfficiency", "1.1.1")]
[BepInProcess("GTFO.exe")]
public class EntryPoint : BasePlugin
{
	public const string GUID = "com.catrice.GlueEfficiency";

	private bool once;

	public override void Load()
	{
		//IL_0010: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		Logger.LogInstance = ((BasePlugin)this).Log;
		Harmony val = new Harmony("com.catrice.GlueEfficiency");
		MethodInfo method = typeof(GlueGun).GetMethod("FireBurst");
		MethodInfo method2 = typeof(GlueEfficiencyHooks).GetMethod("Postfix_FireBurst");
		val.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.PatchAll();
	}
}
public static class GlueEfficiencyHooks
{
	public static void Postfix_FireBurst(GlueGun __instance, float pressure)
	{
		int num = __instance.GetShotCount(pressure);
		if (num == 0)
		{
			num = 1;
		}
		Logger.Log($"ShotCount: {num}");
		float num2 = Mathf.Max(AgentModifierManager.ApplyModifier((Agent)(object)((Item)__instance).Owner, (AgentModifier)101, 1f), 1E-05f);
		int num3 = Mathf.Max(Mathf.RoundToInt((float)num / num2), 1);
		float num4 = (float)num / num2;
		Mathf.FloorToInt(num4);
		float num5 = 0f;
		num5 = (float)num3 - num4;
		if (num5 != 0f)
		{
			PlayerAmmoStorage ammoStorage = PlayerBackpackManager.GetBackpack(((Item)__instance).Owner.Owner).AmmoStorage;
			InventorySlotAmmo val = ((Il2CppArrayBase<InventorySlotAmmo>)(object)ammoStorage.m_ammoStorage)[2];
			float num6 = num5 * val.CostOfBullet;
			float ammoInPack = Mathf.Clamp(val.AmmoInPack + num6, 0f, val.AmmoMaxCap);
			Logger.Log($"Num {num6}  Ammo {val.AmmoInPack} Num3 {num3} Delta {num5}");
			val.AmmoInPack = ammoInPack;
			Logger.Log($"New Ammo {val.AmmoInPack}");
			val.OnBulletsUpdateCallback?.Invoke(val.BulletsInPack);
			ammoStorage.NeedsSync = true;
			ammoStorage.UpdateSlotAmmoUI(val, 0);
		}
	}
}
public static class Logger
{
	public static ManualLogSource LogInstance;

	public static void Log(string format, params object[] args)
	{
		Log(string.Format(format, args));
	}

	public static void Log(string str)
	{
		ManualLogSource logInstance = LogInstance;
		if (logInstance != null)
		{
			logInstance.Log((LogLevel)8, (object)str);
		}
	}

	public static void Warning(string format, params object[] args)
	{
		Warning(string.Format(format, args));
	}

	public static void Warning(string str)
	{
		ManualLogSource logInstance = LogInstance;
		if (logInstance != null)
		{
			logInstance.Log((LogLevel)4, (object)str);
		}
	}

	public static void Error(string format, params object[] args)
	{
		Error(string.Format(format, args));
	}

	public static void Error(string str)
	{
		ManualLogSource logInstance = LogInstance;
		if (logInstance != null)
		{
			logInstance.Log((LogLevel)2, (object)str);
		}
	}
}