using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComputerysModdingUtilities;
using FishNet;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using Unrandomizer.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: StraftatMod(false)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ChoccyMewks-Unrandomizer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+40f372bb5f4c86088b1ff1ba8348d58d78b08c90")]
[assembly: AssemblyProduct("Choccy Mewk's Unrandomizer")]
[assembly: AssemblyTitle("ChoccyMewks-Unrandomizer")]
[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;
}
}
}
internal sealed class ConfigurationManagerAttributes
{
public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);
public bool? ShowRangeAsPercent;
public Action<ConfigEntryBase> CustomDrawer;
public CustomHotkeyDrawerFunc CustomHotkeyDrawer;
public bool? Browsable;
public string Category;
public object DefaultValue;
public bool? HideDefaultButton;
public bool? HideSettingName;
public string Description;
public string DispName;
public int? Order;
public bool? ReadOnly;
public bool? IsAdvanced;
public Func<object, string> ObjToStr;
public Func<string, object> StrToObj;
}
namespace Unrandomizer
{
[HarmonyPatch(typeof(Weapon))]
[BepInPlugin("ChoccyMewks-Unrandomizer", "Choccy Mewk's Unrandomizer", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static ConfigFile ConfigFileRef;
internal static ManualLogSource Logger;
private static Plugin Instance;
private readonly Harmony harmony = new Harmony("ChoccyMewks-Unrandomizer");
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
Logger = ((BaseUnityPlugin)this).Logger;
ConfigFileRef = ((BaseUnityPlugin)this).Config;
harmony.PatchAll(typeof(Plugin));
harmony.PatchAll(typeof(ItemSpawnerPatch));
ItemSpawnerPatch.Setup(ConfigFileRef);
Logger.LogInfo((object)"Plugin ChoccyMewks-Unrandomizer is loaded!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ChoccyMewks-Unrandomizer";
public const string PLUGIN_NAME = "Choccy Mewk's Unrandomizer";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace Unrandomizer.Patches
{
[HarmonyPatch(typeof(ItemSpawner))]
internal static class ItemSpawnerPatch
{
private static Dictionary<string, ConfigEntry<bool>> WeaponToggles = new Dictionary<string, ConfigEntry<bool>>();
private static ConfigEntry<bool> EnableAllWeaponsToggle;
private static ConfigEntry<bool> DisableAllWeaponsToggle;
private static ConfigEntry<bool> ToggleRandomWeaponRespawnTime;
private static ConfigEntry<float> RandomWeaponRespawnTimerMin;
private static ConfigEntry<float> RandomWeaponRespawnTimerMax;
private static ConfigEntry<float> WeaponRespawnTimer;
private static ConfigFile Config;
private static List<GameObject> _completeWeaponList;
private static string weaponsPath = "RandomWeapons";
private static float countdown = 2f;
private static List<string> randomWeaponList => (from kv in WeaponToggles
where kv.Value.Value
select kv.Key).ToList();
[HarmonyPostfix]
[HarmonyPatch("LoadAllWeapons")]
private static void GetRandomWeapons(ref GameObject[] ___randomWeapons)
{
SetWeaponList(ref ___randomWeapons);
}
[HarmonyPrefix]
[HarmonyPatch("PickRandomWeapon")]
private static void GetRandomWeapon(ref GameObject[] ___randomWeapons)
{
SetWeaponList(ref ___randomWeapons);
}
[HarmonyPrefix]
[HarmonyPatch("Awake")]
private static void Awake(ref string ___weaponsPath, ref float ___blankStateProbability, ref float ___countdown)
{
if (InstanceFinder.NetworkManager.IsServer)
{
ValidateRange();
RandomWeaponRespawnTimerMin.SettingChanged += delegate
{
ValidateRange();
};
RandomWeaponRespawnTimerMax.SettingChanged += delegate
{
ValidateRange();
};
weaponsPath = ___weaponsPath;
___countdown = WeaponRespawnTimer.Value;
___blankStateProbability = -1f;
}
}
[HarmonyPrefix]
[HarmonyPatch("Update")]
private static void Update(ref float ___countdown)
{
if (InstanceFinder.NetworkManager.IsServer)
{
if (ToggleRandomWeaponRespawnTime.Value)
{
___countdown = Random.Range(RandomWeaponRespawnTimerMin.Value, RandomWeaponRespawnTimerMax.Value);
}
else
{
___countdown = WeaponRespawnTimer.Value;
}
}
}
private static void SetWeaponList(ref GameObject[] ___randomWeapons)
{
if (InstanceFinder.NetworkManager.IsServer)
{
if (_completeWeaponList == null)
{
_completeWeaponList = Resources.LoadAll<GameObject>(weaponsPath).ToList();
}
___randomWeapons = _completeWeaponList.Where((GameObject weapon) => randomWeaponList.Contains(((Object)weapon).name)).ToArray();
}
}
private static void ValidateRange()
{
RandomWeaponRespawnTimerMin.Value = (float)Math.Round(RandomWeaponRespawnTimerMin.Value, 2);
RandomWeaponRespawnTimerMax.Value = (float)Math.Round(RandomWeaponRespawnTimerMax.Value, 2);
if (RandomWeaponRespawnTimerMin.Value > RandomWeaponRespawnTimerMax.Value)
{
RandomWeaponRespawnTimerMin.Value = RandomWeaponRespawnTimerMax.Value;
}
}
public static void Setup(ConfigFile config)
{
Config = config;
SetupConfigOptions();
SetupWeaponList();
SetupWeaponResetButton();
SetupDisableAllWeaponsToggleButton();
}
private static void SetupWeaponList()
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Expected O, but got Unknown
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Expected O, but got Unknown
EnableAllWeaponsToggle = Config.Bind<bool>("Weapons Options", "Enable all weapons", false, new ConfigDescription("Enables all weapons to become spawnable.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
Category = "Weapons Options",
Order = 2,
HideDefaultButton = true
}
}));
DisableAllWeaponsToggle = Config.Bind<bool>("Weapons Options", "Disable all weapons", false, new ConfigDescription("Disables all weapons from being spawnable.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
Category = "Weapons Options",
Order = 1,
HideDefaultButton = true
}
}));
if (_completeWeaponList == null)
{
_completeWeaponList = Resources.LoadAll<GameObject>(weaponsPath).ToList();
}
foreach (GameObject completeWeapon in _completeWeaponList)
{
ConfigEntry<bool> value = Config.Bind<bool>("Weapons", "Toggle " + ((Object)completeWeapon).name, true, new ConfigDescription("Enable or disable the " + ((Object)completeWeapon).name + " appearing in-game.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
Category = "Weapons"
}
}));
WeaponToggles[((Object)completeWeapon).name] = value;
}
Plugin.Logger.LogInfo((object)$"Registered {WeaponToggles.Count} weapon toggles.");
}
private static void SetupConfigOptions()
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Expected O, but got Unknown
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Expected O, but got Unknown
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Expected O, but got Unknown
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Expected O, but got Unknown
WeaponRespawnTimer = Config.Bind<float>("General", "Weapon respawn timer (seconds)", 2f, new ConfigDescription("Controls the amount of time it takes a weapon to respawn.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 180f), new object[1]
{
new ConfigurationManagerAttributes
{
Category = "General",
Order = 0
}
}));
ToggleRandomWeaponRespawnTime = Config.Bind<bool>("Random Respawn", "Toggle random respawn time", false, new ConfigDescription("Toggles if weapons should have differing respawn times.", (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
Category = "Random Respawn",
Order = 2
}
}));
RandomWeaponRespawnTimerMin = Config.Bind<float>("Random Respawn", "Minimum time in seconds", 2f, new ConfigDescription("The minimum amount of time it should take for a weapon to respawn.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 180f), new object[1]
{
new ConfigurationManagerAttributes
{
Category = "Random Respawn",
Order = 1
}
}));
RandomWeaponRespawnTimerMax = Config.Bind<float>("Random Respawn", "Maximum time in seconds", 2f, new ConfigDescription("The maximum amount of time it should take for a weapon to respawn.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 180f), new object[1]
{
new ConfigurationManagerAttributes
{
Category = "Random Respawn",
Order = 0
}
}));
}
private static void SetupWeaponResetButton()
{
EnableAllWeaponsToggle.SettingChanged += delegate
{
if (EnableAllWeaponsToggle.Value && WeaponToggles != null)
{
foreach (ConfigEntry<bool> value in WeaponToggles.Values)
{
value.Value = true;
}
EnableAllWeaponsToggle.Value = false;
Plugin.Logger.LogInfo((object)"Enabled all weapons.");
}
};
}
private static void SetupDisableAllWeaponsToggleButton()
{
DisableAllWeaponsToggle.SettingChanged += delegate
{
if (DisableAllWeaponsToggle.Value && WeaponToggles != null)
{
foreach (ConfigEntry<bool> value in WeaponToggles.Values)
{
value.Value = false;
}
DisableAllWeaponsToggle.Value = false;
Plugin.Logger.LogInfo((object)"Disabled all weapons.");
}
};
}
}
}