Decompiled source of Trapped Luggage v1.2.0

Trapped Luggage.dll

Decompiled 2 hours ago
using System;
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.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("Trapped Luggage")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Trapped Luggage")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("116b48d9-8079-4ed0-9ea8-d6b2b553b8c6")]
[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")]
[BepInPlugin("tony4twentys.Trapped_Luggage", "Trapped Luggage", "1.1.0")]
public class TrappedLuggagePlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(LootData), "PopulateLootData")]
	public static class LootDataPatch
	{
		public static void Postfix()
		{
			Instance.ParseIgnoredPools();
			ApplyDynamiteOdds();
		}
	}

	[HarmonyPatch(typeof(RunManager), "StartRun")]
	public static class RunStartPatch
	{
		public static void Postfix()
		{
			Log.LogInfo((object)"[TrappedLuggage] Run started. Reapplying loot odds.");
			LootData.PopulateLootData();
			ApplyDynamiteOdds();
		}
	}

	internal static ManualLogSource Log;

	internal static ConfigEntry<float> DynamiteSpawnChancePercent;

	internal static Dictionary<SpawnPool, ConfigEntry<bool>> LuggageIgnoreSettings = new Dictionary<SpawnPool, ConfigEntry<bool>>();

	internal static HashSet<SpawnPool> IgnoredPools = new HashSet<SpawnPool>();

	public static TrappedLuggagePlugin Instance { get; private set; }

	private void Awake()
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		DynamiteSpawnChancePercent = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DynamiteChancePercent", 5f, "Chance for dynamite to spawn in luggage (as a percent). Example: 5 = 5% chance.");
		SetupLuggagePoolToggles();
		ParseIgnoredPools();
		Harmony val = new Harmony("tony4twentys.Trapped_Luggage");
		val.PatchAll();
		Log.LogInfo((object)$"Trapped Luggage loaded! Default chance: {DynamiteSpawnChancePercent.Value}%");
	}

	private void SetupLuggagePoolToggles()
	{
		AddLuggageConfig((SpawnPool)1024, "LuggageBeach", "Ignore Beach luggage for dynamite spawning.");
		AddLuggageConfig((SpawnPool)2048, "LuggageJungle", "Ignore Jungle luggage for dynamite spawning.");
		AddLuggageConfig((SpawnPool)4096, "LuggageTundra", "Ignore Tundra luggage for dynamite spawning.");
		AddLuggageConfig((SpawnPool)8192, "LuggageCaldera", "Ignore Caldera luggage for dynamite spawning.");
		AddLuggageConfig((SpawnPool)16384, "LuggageClimber", "Ignore Climber luggage for dynamite spawning.");
		AddLuggageConfig((SpawnPool)32768, "LuggageAncient", "Ignore Ancient luggage for dynamite spawning.");
		AddLuggageConfig((SpawnPool)65536, "LuggageCursed", "Ignore Cursed luggage for dynamite spawning.");
	}

	private void AddLuggageConfig(SpawnPool pool, string name, string description)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		ConfigEntry<bool> value = ((BaseUnityPlugin)this).Config.Bind<bool>("IgnoreLuggage", name, false, description);
		LuggageIgnoreSettings[pool] = value;
	}

	public void ParseIgnoredPools()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		IgnoredPools.Clear();
		foreach (KeyValuePair<SpawnPool, ConfigEntry<bool>> luggageIgnoreSetting in LuggageIgnoreSettings)
		{
			if (luggageIgnoreSetting.Value.Value)
			{
				IgnoredPools.Add(luggageIgnoreSetting.Key);
			}
		}
	}

	public static void ApplyDynamiteOdds()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		ushort key = 106;
		float num = Mathf.Clamp(DynamiteSpawnChancePercent.Value, 0f, 100f);
		foreach (SpawnPool value in Enum.GetValues(typeof(SpawnPool)))
		{
			if (!IsLuggagePool(value) || IgnoredPools.Contains(value) || !LootData.AllSpawnWeightData.ContainsKey(value))
			{
				continue;
			}
			Dictionary<ushort, int> dictionary = LootData.AllSpawnWeightData[value];
			int num2 = 0;
			foreach (int value2 in dictionary.Values)
			{
				num2 += value2;
			}
			if (Mathf.Approximately(num, 100f))
			{
				if (dictionary.ContainsKey(key))
				{
					dictionary[key] = 999999;
				}
				else
				{
					dictionary.Add(key, 999999);
				}
				Log.LogInfo((object)$"[TrappedLuggage] Guaranteed spawn of dynamite in {(object)value} with weight {999999} (100%)");
				continue;
			}
			int num3 = Mathf.RoundToInt(num / 100f * (float)num2);
			if (num3 > 0)
			{
				dictionary[key] = num3;
				Log.LogInfo((object)$"[TrappedLuggage] Added dynamite to {(object)value} with weight {num3} ({num}%)");
			}
			else
			{
				Log.LogInfo((object)$"[TrappedLuggage] Skipped dynamite in {(object)value} (chance too low)");
			}
		}
	}

	private static bool IsLuggagePool(SpawnPool pool)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Invalid comparison between Unknown and I4
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Invalid comparison between Unknown and I4
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Invalid comparison between Unknown and I4
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Invalid comparison between Unknown and I4
		return (int)pool == 1024 || (int)pool == 2048 || (int)pool == 4096 || (int)pool == 8192 || (int)pool == 16384 || (int)pool == 32768 || (int)pool == 65536;
	}
}