using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Gunfiguration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("ConfigurableRatChests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("N/A")]
[assembly: AssemblyProduct("ConfigurableRatChests")]
[assembly: AssemblyCopyright("Copyright © N/A 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("22bdf3ac-ff30-4bd3-a936-e606662bc3d6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ConfigurableRatChests
{
[BepInPlugin("spapi.etg.configurableratchests", "Configurable Rat Chests", "1.0.2")]
[HarmonyPatch]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "spapi.etg.configurableratchests";
public const string NAME = "Configurable Rat Chests";
public const string VERSION = "1.0.2";
public static Gunfig gunfig;
public static float RatChest_D_Weight;
public static float RatChest_C_Weight;
public static float RatChest_B_Weight;
public static float RatChest_A_Weight;
public static float RatChest_S_Weight;
public const string USE_RAT_ITEMS = "Use rat items?";
public const string POOL_MODE = "Loot pool mode";
public const string POOL_MODE_RANDOM = "Random";
public const string POOL_MODE_ALLGUNS = "Always guns";
public const string POOL_MODE_ALLITEMS = "Always items";
public const string D_WEIGHT = "D tier item weight";
public const string C_WEIGHT = "C tier item weight";
public const string B_WEIGHT = "B tier item weight";
public const string A_WEIGHT = "A tier item weight";
public const string S_WEIGHT = "S tier item weight";
public void Awake()
{
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
gunfig = Gunfig.Get("Configurable Rat Chests");
List<string> list = new List<string>
{
"0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9",
"1"
};
List<string> list2 = new List<string>
{
"1", "0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8",
"0.9"
};
gunfig.AddToggle("Use rat items?", true, GunfigHelpers.Yellow("Use rat items?"), (Action<string, string>)null, (Update)1);
gunfig.AddScrollBox("Loot pool mode", new List<string>(3) { "Random", "Always guns", "Always items" }, GunfigHelpers.Cyan("Loot pool mode"), (Action<string, string>)null, (List<string>)null, (Update)1);
gunfig.AddScrollBox("D tier item weight", list, GunfigHelpers.WithColor("D tier item weight", new Color(1f, 0.5f, 0f)), (Action<string, string>)WeightSetCallback, (List<string>)null, (Update)1);
gunfig.AddScrollBox("C tier item weight", list, GunfigHelpers.Blue("C tier item weight"), (Action<string, string>)WeightSetCallback, (List<string>)null, (Update)1);
gunfig.AddScrollBox("B tier item weight", list, GunfigHelpers.Green("B tier item weight"), (Action<string, string>)WeightSetCallback, (List<string>)null, (Update)1);
gunfig.AddScrollBox("A tier item weight", list2, GunfigHelpers.Red("A tier item weight"), (Action<string, string>)WeightSetCallback, (List<string>)null, (Update)1);
gunfig.AddScrollBox("S tier item weight", list, "S tier item weight", (Action<string, string>)WeightSetCallback, (List<string>)null, (Update)1);
SetWeightsAndUpdateRatChestChances();
new Harmony("spapi.etg.configurableratchests").PatchAll();
}
public static void WeightSetCallback(string key, string value)
{
if (float.TryParse(value, out var result))
{
switch (key)
{
case "D tier item weight":
RatChest_D_Weight = result;
break;
case "C tier item weight":
RatChest_C_Weight = result;
break;
case "B tier item weight":
RatChest_B_Weight = result;
break;
case "A tier item weight":
RatChest_A_Weight = result;
break;
case "S tier item weight":
RatChest_S_Weight = result;
break;
}
UpdateRatChestChances();
}
}
public static void SetWeightsAndUpdateRatChestChances(Chest ratChest = null)
{
if (float.TryParse(gunfig.Value("D tier item weight"), out var result))
{
RatChest_D_Weight = result;
}
if (float.TryParse(gunfig.Value("C tier item weight"), out var result2))
{
RatChest_C_Weight = result2;
}
if (float.TryParse(gunfig.Value("B tier item weight"), out var result3))
{
RatChest_B_Weight = result3;
}
if (float.TryParse(gunfig.Value("A tier item weight"), out var result4))
{
RatChest_A_Weight = result4;
}
if (float.TryParse(gunfig.Value("S tier item weight"), out var result5))
{
RatChest_S_Weight = result5;
}
UpdateRatChestChances(ratChest);
}
public static void UpdateRatChestChances(Chest ratChest = null)
{
if ((Object)(object)ratChest == (Object)null)
{
ratChest = LoadHelper.LoadAssetFromAnywhere<GameObject>("chest_rat").GetComponent<Chest>();
}
if (!((Object)(object)ratChest == (Object)null) && ratChest.lootTable != null)
{
LootData lootTable = ratChest.lootTable;
float num = RatChest_D_Weight + RatChest_C_Weight + RatChest_B_Weight + RatChest_A_Weight + RatChest_S_Weight;
lootTable.Common_Chance = 0f;
if (num <= 0f)
{
lootTable.D_Chance = 0f;
lootTable.C_Chance = 0f;
lootTable.B_Chance = 0f;
lootTable.A_Chance = 0f;
lootTable.S_Chance = 0f;
}
else
{
lootTable.D_Chance = RatChest_D_Weight / num;
lootTable.C_Chance = RatChest_C_Weight / num;
lootTable.B_Chance = RatChest_B_Weight / num;
lootTable.A_Chance = RatChest_A_Weight / num;
lootTable.S_Chance = RatChest_S_Weight / num;
}
}
}
[HarmonyPatch(typeof(ResourcefulRatRewardRoomController), "Start")]
[HarmonyPostfix]
public static void DisableForcedDrops(ResourcefulRatRewardRoomController __instance)
{
if ((Object)(object)__instance == (Object)null || __instance.m_ratChests == null)
{
return;
}
Chest[] ratChests = __instance.m_ratChests;
foreach (Chest val in ratChests)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
SetWeightsAndUpdateRatChestChances(val);
string text = gunfig.Value("Loot pool mode");
if (text == "Always guns")
{
val.lootTable.lootTable = GameManager.Instance.RewardManager.GunsLootTable;
}
if (text == "Always items")
{
val.lootTable.lootTable = GameManager.Instance.RewardManager.ItemsLootTable;
}
else
{
val.lootTable.lootTable = (BraveUtility.RandomBool() ? GameManager.Instance.RewardManager.GunsLootTable : GameManager.Instance.RewardManager.ItemsLootTable);
}
if (!gunfig.Enabled("Use rat items?"))
{
Chest val2 = val;
if (val2.forceContentIds == null)
{
val2.forceContentIds = new List<int>();
}
val.forceContentIds.Clear();
}
}
}
}
}