Decompiled source of AllOneScrap v1.0.0

AllOneScrap.dll

Decompiled a month ago
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 AllOneScrap.Patches;
using BepInEx;
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("AllOneScrap")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AllOneScrap")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("45a5792d-3c44-40b4-9119-58c6ee8d4b75")]
[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 AllOneScrap
{
	[BepInPlugin("kennetek.AllOneScrap", "All One Scrap", "1.0.0.0")]
	public class AllOneScrapBase : BaseUnityPlugin
	{
		private const string modGUID = "kennetek.AllOneScrap";

		private const string modName = "All One Scrap";

		private const string modVersion = "1.0.0.0";

		private readonly Harmony harmony = new Harmony("kennetek.AllOneScrap");

		private static AllOneScrapBase Instance;

		internal static ManualLogSource Log;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"AllOneScrap started!");
			harmony.PatchAll(typeof(AllOneScrapBase));
			harmony.PatchAll(typeof(RoundManagerPatch));
		}
	}
}
namespace AllOneScrap.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	public static class RoundManagerPatch
	{
		internal static ManualLogSource Log = AllOneScrapBase.Log;

		[HarmonyPatch("SpawnScrapInLevel")]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
		{
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Expected O, but got Unknown
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			LocalBuilder localBuilder = il.DeclareLocal(typeof(int));
			int num = -1;
			int num2 = -1;
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].operand != null)
				{
					if (CodeInstructionExtensions.IsStloc(list[i], (LocalBuilder)null) && list[i].operand.ToString().Equals("System.Int32[] (5)"))
					{
						Log.LogInfo((object)list[i]);
						Log.LogInfo((object)list[i].operand.GetType());
						Log.LogInfo((object)i);
						num = i;
					}
					if (list[i].operand.ToString().Equals("Int32 GetRandomWeightedIndex(Int32[], System.Random)"))
					{
						Log.LogInfo((object)list[i]);
						Log.LogInfo((object)list[i].operand.GetType());
						Log.LogInfo((object)i);
						num2 = i;
					}
					if (num > 0 && num2 > 0)
					{
						break;
					}
				}
			}
			if (num < 0 || num2 < 0)
			{
				return list.AsEnumerable();
			}
			CodeInstruction item = list[num2 - 3];
			CodeInstruction item2 = list[num2 - 2];
			CodeInstruction item3 = list[num2 - 1];
			CodeInstruction item4 = list[num2];
			CodeInstruction item5 = new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder);
			CodeInstruction item6 = new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder);
			list.RemoveAt(num2);
			list.RemoveAt(num2 - 1);
			list.RemoveAt(num2 - 2);
			list.RemoveAt(num2 - 3);
			list.Insert(num2 - 3, item6);
			list.Insert(num + 1, item5);
			list.Insert(num + 1, item4);
			list.Insert(num + 1, item3);
			list.Insert(num + 1, item2);
			list.Insert(num + 1, item);
			for (int j = num - 5; j < num2 + 5; j++)
			{
				Log.LogInfo((object)list[j]);
			}
			return list.AsEnumerable();
		}
	}
}