Decompiled source of True1 5x v0.0.1

True1.5x.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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("True1.5x")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("True1.5x")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("eb436ce9-d958-4a81-9280-daa924c7176e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace True1._5x;

[BepInPlugin("mtsukn.true1.5x", "True1.5x", "0.0.1")]
public class Main : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Game))]
	[HarmonyPatch("ScaleDrops", new Type[]
	{
		typeof(int),
		typeof(int)
	})]
	public static class ScaleDrops1_Patch
	{
		private static bool Prefix(int randomMin, ref int randomMax)
		{
			if (!doRangePatch.Value)
			{
				return true;
			}
			if (randomMax - 1 > randomMin)
			{
				randomMax--;
			}
			else
			{
				randomMax = randomMin;
			}
			return true;
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			if (doTrueRoundPatch.Value)
			{
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				for (int i = 0; i < list.Count; i++)
				{
					if (list[i].opcode == OpCodes.Call && list[i].operand.ToString() == "Single Round(Single)")
					{
						list[i] = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Main), "trueRound", new Type[1] { typeof(float) }, (Type[])null));
					}
				}
				return list.AsEnumerable();
			}
			return instructions;
		}
	}

	[HarmonyPatch(typeof(Game))]
	[HarmonyPatch("ScaleDrops", new Type[]
	{
		typeof(ItemData),
		typeof(int)
	})]
	public static class ScaleDrops2_Patch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			if (doTrueRoundPatch.Value)
			{
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				for (int i = 0; i < list.Count; i++)
				{
					if (list[i].opcode == OpCodes.Call && list[i].operand.ToString() == "Single Round(Single)")
					{
						list[i] = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Main), "trueRound", new Type[1] { typeof(float) }, (Type[])null));
					}
				}
				return list.AsEnumerable();
			}
			return instructions;
		}
	}

	[HarmonyPatch(typeof(DropTable))]
	[HarmonyPatch("GetDropList", new Type[] { typeof(int) })]
	public static class GetDropList_Patch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			if (doTrueRoundPatch.Value)
			{
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				bool flag = false;
				bool flag2 = false;
				for (int i = 0; i < list.Count; i++)
				{
					if (list[i].opcode == OpCodes.Ldfld && (list[i].operand.ToString() == "System.Int32 m_stackMin" || list[i].operand.ToString() == "System.Int32 m_stackMax") && list[i + 4].opcode == OpCodes.Call && list[i + 4].operand.ToString() == "Single Round(Single)")
					{
						flag = true;
						list.RemoveAt(i + 4);
					}
					if (flag && list[i].opcode == OpCodes.Call && list[i].operand.ToString() == "Single Round(Single)")
					{
						flag = false;
						flag2 = true;
						list[i] = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Main), "trueRound", new Type[1] { typeof(float) }, (Type[])null));
					}
					if (flag2 && list[i].opcode == OpCodes.Call && list[i].operand.ToString() == "Single Max(Single, Single)")
					{
						flag2 = false;
						list.RemoveAt(i);
					}
					if (list[i].opcode == OpCodes.Call)
					{
						logger.LogInfo((object)list[i].operand.ToString());
					}
				}
				return list.AsEnumerable();
			}
			return instructions;
		}
	}

	private const string pluginGUID = "mtsukn.true1.5x";

	private const string pluginName = "True1.5x";

	private const string pluginVersion = "0.0.1";

	private readonly Harmony HarmonyInstance = new Harmony("mtsukn.true1.5x");

	public static ManualLogSource logger = Logger.CreateLogSource("True1.5x");

	public static ConfigEntry<bool> enableDebugMessages { get; private set; }

	public static ConfigEntry<bool> doTrueRoundPatch { get; private set; }

	public static ConfigEntry<bool> doRangePatch { get; private set; }

	public void Awake()
	{
		enableDebugMessages = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Debug logs", false, "Enables debug messages in the console");
		doTrueRoundPatch = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "True Round", true, "(Requires Restart) Patches ScaleDrops and GetDropList to roll for the remainder instead of rounding up. For example if the drop amount comes to 1.5, instead of rounding up to 2, it will drop one and have a 50% chance to drop another.");
		doRangePatch = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Range Patch", true, "Fixes a discrepancy in the code where different Random.Range methods are used for default and modified resource rates, causing things to drop up to 3x more than they should. Explanation in README.");
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		HarmonyInstance.PatchAll(executingAssembly);
	}

	public static float trueRound(float num)
	{
		float num2 = (float)Math.Truncate(num);
		float num3 = num - num2;
		if (num3 == 0f)
		{
			if (enableDebugMessages.Value)
			{
				logger.LogInfo((object)("total drops: " + num2 + ". no remainder"));
			}
			return num2;
		}
		float value = Random.value;
		if (enableDebugMessages.Value)
		{
			logger.LogInfo((object)("total drops: " + num2 + ". testing " + num3 + " against " + value));
		}
		if (num3 > 0f && num3 > value)
		{
			if (enableDebugMessages.Value)
			{
				logger.LogInfo((object)"success, adding 1");
			}
			num2 += 1f;
		}
		return num2;
	}

	public static void repairStackSize(int min, ref int max)
	{
		if (max - 1 > min)
		{
			max--;
		}
		else
		{
			max = min;
		}
	}

	public static void logFloat(float v)
	{
		logger.LogInfo((object)v);
	}
}