using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AnyMagazine;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTrademark(null)]
[assembly: MelonInfo(typeof(global::AnyMagazine.AnyMagazine), "AnyMagazine", "1.0.1", "Rexmeck", "https://thunderstore.io/c/bonelab/p/Rexmeck/AnyMagazine/")]
[assembly: MelonColor]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "BoneLib" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace AnyMagazine;
public static class BuildInfo
{
public const string Name = "AnyMagazine";
public const string Description = "Insert any magazines into many guns!";
public const string Author = "Rexmeck";
public const string Company = null;
public const string Version = "1.0.1";
public const string DownloadLink = "https://thunderstore.io/c/bonelab/p/Rexmeck/AnyMagazine/";
}
public class AnyMagazine : MelonMod
{
public override void OnInitializeMelon()
{
Prefs.Initialize();
}
}
[HarmonyPatch(typeof(AmmoPlug), "OnPlugInsertComplete")]
public static class AmmoPlugOnPlugInsertCompletePatch
{
private static Hand FindLocalHand(InteractableHost host)
{
for (int i = 0; i < host.HandCount(); i++)
{
Hand hand = host.GetHand(i);
if (((Object)hand.manager).name == "RigManager(bonelab) [0]")
{
return hand;
}
}
return null;
}
private static void Prefix(AmmoPlug __instance)
{
if (!Prefs.Enabled || (!Prefs.ApplyMagazine && !Prefs.ApplyCartridge))
{
return;
}
Hand lastHand = ((Plug)__instance).host.GetLastHand();
if (!((Object)(object)lastHand != (Object)null) || (!lastHand.Controller.GetThumbStick() && Prefs.HoldThumbstick))
{
return;
}
AmmoSocket component = ((Component)((AlignPlug)__instance)._lastSocket).GetComponent<AmmoSocket>();
if ((Object)(object)component != (Object)null && (Object)(object)__instance.magazine != (Object)null && __instance.magazine.magazineState != null && (Object)(object)component.gun != (Object)null && (Object)(object)((Socket)component).host != (Object)null)
{
Hand val = FindLocalHand(((Socket)component).host);
Gun gun = component.gun;
InventoryAmmoReceiver lastAmmoInventoryReceiver = __instance.magazine._lastAmmoInventoryReceiver;
if ((Object)(object)val != (Object)null && (Object)(object)val.slot != (Object)null)
{
lastAmmoInventoryReceiver.OnHandItemSlotRemoved(val.slot);
}
if (Prefs.ApplyMagazine)
{
gun.defaultMagazine = __instance.magazine.magazineState.magazineData;
}
if (Prefs.ApplyCartridge)
{
gun.defaultCartridge = __instance.magazine.magazineState.cartridgeData;
}
if ((Object)(object)val != (Object)null && (Object)(object)val.slot != (Object)null)
{
lastAmmoInventoryReceiver.OnHandItemSlot(val.slot);
}
}
}
}
[HarmonyPatch(typeof(AlignPlug), "Awake")]
public static class AmmoPlugProxyGripFix
{
private static void Prefix(AlignPlug __instance)
{
AmmoPlug component = ((Component)__instance).GetComponent<AmmoPlug>();
if ((Object)(object)component != (Object)null && (Object)(object)__instance.proxyGrip == (Object)null && (Object)(object)component.magazine.grip != (Object)null)
{
__instance.proxyGrip = component.magazine.grip;
}
}
}
[HarmonyPatch(typeof(AmmoSocket), "OnPlugEnter")]
public static class AmmoSocketOnPlugEnterPatch
{
private static string _prevplatform = "";
private static void Prefix(AmmoSocket __instance, Plug plug)
{
if (Prefs.Enabled)
{
AmmoPlug component = ((Component)plug).GetComponent<AmmoPlug>();
if ((Object)(object)component != (Object)null && (Object)(object)component.magazine != (Object)null && component.magazine.magazineState != null)
{
_prevplatform = __instance.platform;
__instance.platform = component.magazine.magazineState.magazineData.platform;
}
}
}
private static void Postfix(AmmoSocket __instance, Plug plug)
{
if (Prefs.Enabled)
{
__instance.platform = _prevplatform;
}
}
}
public static class Prefs
{
public static MelonPreferences_Category instance;
private static MelonPreferences_Entry<bool> _Enabled;
private static MelonPreferences_Entry<bool> _HoldThumbstick;
private static MelonPreferences_Entry<bool> _ApplyMagazine;
private static MelonPreferences_Entry<bool> _ApplyCartridge;
public static bool Enabled
{
get
{
return _Enabled.Value;
}
set
{
_Enabled.Value = value;
instance.SaveToFile(false);
}
}
public static bool HoldThumbstick
{
get
{
return _HoldThumbstick.Value;
}
set
{
_HoldThumbstick.Value = value;
instance.SaveToFile(false);
}
}
public static bool ApplyMagazine
{
get
{
return _ApplyMagazine.Value;
}
set
{
_ApplyMagazine.Value = value;
instance.SaveToFile(false);
}
}
public static bool ApplyCartridge
{
get
{
return _ApplyCartridge.Value;
}
set
{
_ApplyCartridge.Value = value;
instance.SaveToFile(false);
}
}
public static void Initialize()
{
instance = MelonPreferences.CreateCategory("AnyMagazine");
_Enabled = instance.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
_HoldThumbstick = instance.CreateEntry<bool>("HoldThumbstick", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
_ApplyMagazine = instance.CreateEntry<bool>("ApplyMagazine", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
_ApplyCartridge = instance.CreateEntry<bool>("ApplyCartridge", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
instance.SaveToFile(false);
try
{
CreateBoneMenu();
}
catch (Exception)
{
MelonLogger.Msg("BoneMenu Not Detected!");
}
}
public static void CreateBoneMenu()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
Page obj = Page.Root.CreatePage("AnyMagazine", Color.white, 0, true);
obj.CreateBool("Mod Enabled", Color.white, Enabled, (Action<bool>)delegate(bool v)
{
Enabled = v;
});
obj.CreateBool("Hold Thumbstick To Apply", Color.white, HoldThumbstick, (Action<bool>)delegate(bool v)
{
HoldThumbstick = v;
});
obj.CreateBool("Apply Magazine", Color.white, ApplyMagazine, (Action<bool>)delegate(bool v)
{
ApplyMagazine = v;
});
obj.CreateBool("Apply Cartridge", Color.white, ApplyCartridge, (Action<bool>)delegate(bool v)
{
ApplyCartridge = v;
});
}
}