using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using AntiMagPocket;
using AntiMagPocket.MagReplacement;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Data;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSystem;
using Il2CppUltEvents;
using MelonLoader;
using MelonLoader.Preferences;
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: MelonInfo(typeof(Core), "AntiMagPocket", "1.0.0", "notnotnotswipez", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AntiMagPocket")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AntiMagPocket")]
[assembly: AssemblyTitle("AntiMagPocket")]
[assembly: NeutralResourcesLanguage("en-US")]
[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 AntiMagPocket
{
public class Core : MelonMod
{
[HarmonyPatch(typeof(Magazine), "OnGrab")]
public class MagHolsterAddPatch
{
public static void Prefix(Magazine __instance)
{
if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInChildren<WeaponSlot>()))
{
WeaponSlot val = ((Component)__instance).gameObject.AddComponent<WeaponSlot>();
val.interactableHost = ((Component)__instance).GetComponentInChildren<InteractableHost>();
val.grip = ((Component)__instance).GetComponentInChildren<Grip>();
val.slotType = (SlotType)1;
}
}
}
[HarmonyPatch(typeof(InventoryAmmoReceiver), "RegisterMagazine")]
public class InventoryAmmoReceiverRegisterPatch
{
public static bool Prefix(InventoryAmmoReceiver __instance)
{
return false;
}
}
public static MelonPreferences_Category mainCategory = MelonPreferences.CreateCategory("AntiMagPocket", "Anti Mag Pocket");
public static MelonPreferences_Entry<ReplacerType> replacerTypePreference = mainCategory.CreateEntry<ReplacerType>("ReplacerType", ReplacerType.ALL, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
public static MelonPreferences_Entry<float> radiusPreference = mainCategory.CreateEntry<float>("Radius", 2f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
public override void OnInitializeMelon()
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
Hooking.OnUIRigCreated += delegate
{
((Component)((Component)Player.RigManager).transform.Find("PhysicsRig/Pelvis/BeltLf1")).gameObject.SetActive(false);
Transform transform = ((Component)UIRig.Instance).transform;
((Component)transform.Find("PLAYERUI/HUD/scaleOffset/hud_Ammo/grid_Ammo")).gameObject.SetActive(false);
((Component)transform.Find("PLAYERUI/INVENTORYSLOTS/scaleOffset/slot_target 04")).gameObject.SetActive(false);
((Component)transform.Find("PLAYERUI/INVENTORYSLOTS/scaleOffset/slot_target 02")).gameObject.SetActive(false);
((Component)transform.Find("../AmmoInventory")).gameObject.SetActive(false);
MagReplacerManager.RunReplacement();
};
MagReplacerManager.activeReplacerType = replacerTypePreference.Value;
MagReplacerManager.radius = radiusPreference.Value;
Page val = Page.Root.CreatePage("AntiMagPocket", Color.yellow, 0, true);
val.CreateEnum("Replacement Type", Color.green, (Enum)MagReplacerManager.activeReplacerType, (Action<Enum>)delegate(Enum type)
{
MagReplacerManager.activeReplacerType = (ReplacerType)(object)type;
replacerTypePreference.Value = (ReplacerType)(object)type;
mainCategory.SaveToFile(false);
});
val.CreateFloat("Radius", Color.yellow, MagReplacerManager.radius, 0.1f, 0.1f, 100f, (Action<float>)delegate(float f)
{
MagReplacerManager.radius = f;
radiusPreference.Value = f;
mainCategory.SaveToFile(false);
});
}
}
}
namespace AntiMagPocket.MagReplacement
{
[HarmonyPatch(typeof(CrateSpawner), "Awake")]
public class CrateSpawnPatch
{
public static void Prefix(CrateSpawner __instance)
{
if (__instance.spawnableCrateReference != null && MagReplacerManager.IsReplacableAmmo(((ScannableReference)__instance.spawnableCrateReference)._barcode._id))
{
Action<CrateSpawner, GameObject> action = delegate(CrateSpawner spawner, GameObject obj)
{
MagReplacerManager.AddReplacableAmmoObject(obj);
};
((UltEvent<CrateSpawner, GameObject>)(object)__instance.onSpawnEvent).DynamicCalls += Action<CrateSpawner, GameObject>.op_Implicit(action);
}
}
}
[HarmonyPatch(typeof(Gun), "Awake")]
public class GunSpawnPatch
{
public static void Prefix(Gun __instance)
{
if (MagReplacerManager.IsSafeToHandle())
{
MagReplacerManager.AddGunBeacon(__instance);
}
}
}
[HarmonyPatch(typeof(LoadingScene), "Start")]
public class LoadingSceneStartPatch
{
public static void Prefix(LoadingScene __instance)
{
MagReplacerManager.ClearData();
}
}
public enum ReplacerType
{
SPHERE,
ALL
}
public static class MagReplacerManager
{
public static ReplacerType activeReplacerType = ReplacerType.ALL;
public static float radius = 2f;
private static bool sceneActive = false;
private static List<string> replacableAmmoBarcodes = new List<string> { "c1534c5a-57d4-4468-b5f0-c795416d6d6f", "c1534c5a-97a9-43f7-be30-6095416d6d6f", "c1534c5a-683b-4c01-b378-6795416d6d6f", "SLZ.BONELAB.Content.Spawnable.DestAmmoBoxHeavyVariant", "SLZ.BONELAB.Content.Spawnable.DestAmmoBoxLightVariant", "SLZ.BONELAB.Content.Spawnable.DestAmmoBoxMediumVariant" };
private static Dictionary<string, string> remappedBarcodes = new Dictionary<string, string>();
private static List<Gun> activeGunBeacons = new List<Gun>();
private static List<GameObject> replacableAmmoObjects = new List<GameObject>();
public static void ClearData()
{
activeGunBeacons.Clear();
replacableAmmoObjects.Clear();
sceneActive = false;
}
public static void AddGunBeacon(Gun gun)
{
if (Regex.IsMatch(((Object)gun).name, "\\[\\d+\\]$"))
{
activeGunBeacons.Add(gun);
}
}
public static void AddReplacableAmmoObject(GameObject gameObject)
{
replacableAmmoObjects.Add(gameObject);
}
public static bool IsReplacableAmmo(string barcode)
{
return replacableAmmoBarcodes.Contains(barcode);
}
public static bool IsSafeToHandle()
{
return !sceneActive;
}
public static void RunReplacement()
{
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
sceneActive = true;
switch (activeReplacerType)
{
case ReplacerType.ALL:
{
foreach (GameObject replacableAmmoObject in replacableAmmoObjects)
{
Gun val = null;
float num2 = float.MaxValue;
foreach (Gun activeGunBeacon in activeGunBeacons)
{
float num3 = Vector3.Distance(replacableAmmoObject.transform.position, ((Component)activeGunBeacon).transform.position);
if (num3 < num2)
{
num2 = num3;
val = activeGunBeacon;
}
}
if ((Object)(object)val != (Object)null)
{
SpawnMagazine(val, replacableAmmoObject.transform.position, replacableAmmoObject.transform.rotation);
Object.Destroy((Object)(object)replacableAmmoObject);
}
}
break;
}
case ReplacerType.SPHERE:
{
foreach (Gun activeGunBeacon2 in activeGunBeacons)
{
foreach (GameObject replacableAmmoObject2 in replacableAmmoObjects)
{
float num = Vector3.Distance(replacableAmmoObject2.transform.position, ((Component)activeGunBeacon2).transform.position);
if (num < radius)
{
SpawnMagazine(activeGunBeacon2, replacableAmmoObject2.transform.position, replacableAmmoObject2.transform.rotation);
Object.Destroy((Object)(object)replacableAmmoObject2);
}
}
}
break;
}
}
}
private static void SpawnMagazine(Gun gun, Vector3 position, Quaternion rotation)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Expected O, but got Unknown
if ((Object)(object)gun.defaultMagazine == (Object)null || (Object)(object)gun.defaultCartridge == (Object)null)
{
return;
}
Barcode val = ((ScannableReference)gun.defaultMagazine.spawnable.crateRef)._barcode;
if (remappedBarcodes.ContainsKey(val._id))
{
val = new Barcode(remappedBarcodes[val._id]);
}
int rounds = gun.defaultMagazine.rounds;
CartridgeData projectile = gun.defaultCartridge;
SpawnableCrate val2 = ((Il2CppObjectBase)AssetWarehouse.Instance._crateRegistry[val]).TryCast<SpawnableCrate>();
Action<GameObject> action = delegate(GameObject o)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
Vector3 val3 = position;
Quaternion val4 = rotation;
GameObject val5 = Object.Instantiate<GameObject>(o, val3, val4);
Magazine componentInChildren = val5.GetComponentInChildren<Magazine>();
if (Object.op_Implicit((Object)(object)componentInChildren))
{
componentInChildren.Initialize(projectile, rounds);
componentInChildren.Claim();
}
};
((CrateT<GameObject>)(object)val2).LoadAsset(Action<GameObject>.op_Implicit(action));
}
}
}