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 BoneLib;
using BoneLib.BoneMenu;
using Bonelab_RandomWeapon;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSystem.Collections.Generic;
using Jevil;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Bonelab-RandomWeapon", "1.0.0", "Stoney", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Bonelab_RandomWeapon")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+805995ce1cb9785557189744979430a30d4e2633")]
[assembly: AssemblyProduct("Bonelab_RandomWeapon")]
[assembly: AssemblyTitle("Bonelab_RandomWeapon")]
[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 Bonelab_RandomWeapon
{
public class Core : MelonMod
{
public enum BindType
{
THUMBSTICK_PRESS,
DOUBLE_TAP_B
}
private MelonPreferences_Category randomWeaponCategory;
private MelonPreferences_Entry<bool> mod_EnabledPref;
private MelonPreferences_Entry<BindType> bind_ModePref;
private MelonPreferences_Entry<bool> debug_EnabledPref;
private MelonPreferences_Entry<bool> firearm_Pistol;
private MelonPreferences_Entry<bool> firearm_SMG;
private MelonPreferences_Entry<bool> firearm_Rifle;
private MelonPreferences_Entry<bool> firearm_Shotgun;
private MelonPreferences_Entry<bool> firearm_Other;
private MelonPreferences_Entry<bool> melee_Blade;
private MelonPreferences_Entry<bool> melee_Blunt;
private MelonPreferences_Entry<bool> melee_Other;
private Page mainPage;
private BoolElement enabledElement;
private EnumElement bindElement;
private BoolElement debugElement;
private static List<SpawnableCrate> cached_Weapons = new List<SpawnableCrate>();
private static float last_Spawn_Time = 0f;
private static float spawn_Cooldown = 0.5f;
private static float last_Tap_Time = 0f;
private static bool waiting_Second_Tap = false;
private const float doubleTap_Delay = 0.32f;
private static bool mod_Enabled = true;
private static BindType bind_Mode = BindType.THUMBSTICK_PRESS;
public override void OnInitializeMelon()
{
((MelonBase)this).LoggerInstance.Msg("[Bonelab_RandomWeapon] Initialized");
Setup_Prefs();
Hooking.OnLevelLoaded += delegate
{
Cache_All_Weapons();
};
Create_Bone_Menu();
}
private void Setup_Prefs()
{
randomWeaponCategory = MelonPreferences.CreateCategory("RandomWeapon");
mod_EnabledPref = randomWeaponCategory.CreateEntry<bool>("mod_Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
bind_ModePref = randomWeaponCategory.CreateEntry<BindType>("bind_Mode", BindType.THUMBSTICK_PRESS, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
debug_EnabledPref = randomWeaponCategory.CreateEntry<bool>("debug_Enabled", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
firearm_Pistol = randomWeaponCategory.CreateEntry<bool>("firearm_Pistol", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
firearm_SMG = randomWeaponCategory.CreateEntry<bool>("firearm_SMG", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
firearm_Rifle = randomWeaponCategory.CreateEntry<bool>("firearm_Rifle", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
firearm_Shotgun = randomWeaponCategory.CreateEntry<bool>("firearm_Shotgun", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
firearm_Other = randomWeaponCategory.CreateEntry<bool>("firearm_Other", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
melee_Blade = randomWeaponCategory.CreateEntry<bool>("melee_Blade", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
melee_Blunt = randomWeaponCategory.CreateEntry<bool>("melee_Blunt", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
melee_Other = randomWeaponCategory.CreateEntry<bool>("melee_Other", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
mod_Enabled = mod_EnabledPref.Value;
bind_Mode = bind_ModePref.Value;
}
private void Create_Bone_Menu()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_0277: Unknown result type (might be due to invalid IL or missing references)
//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
mainPage = Page.Root.CreatePage("Random Weapon", Color.white, 0, true);
enabledElement = mainPage.CreateBool("Enabled", Color.yellow, mod_Enabled, (Action<bool>)delegate(bool v)
{
mod_Enabled = v;
mod_EnabledPref.Value = v;
randomWeaponCategory.SaveToFile(true);
});
bindElement = mainPage.CreateEnum("Binding", Color.cyan, (Enum)bind_Mode, (Action<Enum>)delegate(Enum val)
{
bind_Mode = (BindType)(object)val;
bind_ModePref.Value = bind_Mode;
randomWeaponCategory.SaveToFile(true);
});
debugElement = mainPage.CreateBool("Debug Logs", Color.grey, debug_EnabledPref.Value, (Action<bool>)delegate(bool v)
{
debug_EnabledPref.Value = v;
randomWeaponCategory.SaveToFile(true);
});
mainPage.CreateFunction("Re-cache Weapons", Color.yellow, (Action)delegate
{
Cache_All_Weapons();
((MelonBase)this).LoggerInstance.Msg("[Bonelab_RandomWeapon] Weapons re-cached!");
});
Page obj = mainPage.CreatePage("Firearms", Color.red, 0, true);
obj.CreateFunction("!!! Re-cache after selecting !!!", Color.red, (Action)delegate
{
});
obj.CreateBool("Pistol", Color.red, firearm_Pistol.Value, (Action<bool>)delegate(bool v)
{
firearm_Pistol.Value = v;
randomWeaponCategory.SaveToFile(true);
});
obj.CreateBool("SMG", Color.red, firearm_SMG.Value, (Action<bool>)delegate(bool v)
{
firearm_SMG.Value = v;
randomWeaponCategory.SaveToFile(true);
});
obj.CreateBool("Rifle", Color.red, firearm_Rifle.Value, (Action<bool>)delegate(bool v)
{
firearm_Rifle.Value = v;
randomWeaponCategory.SaveToFile(true);
});
obj.CreateBool("Shotgun", Color.red, firearm_Shotgun.Value, (Action<bool>)delegate(bool v)
{
firearm_Shotgun.Value = v;
randomWeaponCategory.SaveToFile(true);
});
obj.CreateBool("Other", Color.red, firearm_Other.Value, (Action<bool>)delegate(bool v)
{
firearm_Other.Value = v;
randomWeaponCategory.SaveToFile(true);
});
Page obj2 = mainPage.CreatePage("Melee", Color.green, 0, true);
obj2.CreateFunction("!!! Re-cache after selecting !!!", Color.red, (Action)delegate
{
});
obj2.CreateBool("Blade", Color.green, melee_Blade.Value, (Action<bool>)delegate(bool v)
{
melee_Blade.Value = v;
randomWeaponCategory.SaveToFile(true);
});
obj2.CreateBool("Blunt", Color.green, melee_Blunt.Value, (Action<bool>)delegate(bool v)
{
melee_Blunt.Value = v;
randomWeaponCategory.SaveToFile(true);
});
obj2.CreateBool("Other", Color.green, melee_Other.Value, (Action<bool>)delegate(bool v)
{
melee_Other.Value = v;
randomWeaponCategory.SaveToFile(true);
});
mainPage.CreateFunction("Spawn Random Weapon", Color.white, (Action)delegate
{
Spawn_Random_Weapon();
});
}
private void Cache_All_Weapons()
{
cached_Weapons.Clear();
AssetWarehouse instance = AssetWarehouse.Instance;
if (instance == null || !AssetWarehouse.ready)
{
((MelonBase)this).LoggerInstance.Warning("[Bonelab_RandomWeapon] AssetWarehouse not ready.");
return;
}
((MelonBase)this).LoggerInstance.Msg("[Bonelab_RandomWeapon] Caching spawnable crates...");
Enumerator<SpawnableCrate> enumerator = instance.GetCrates<SpawnableCrate>((ICrateFilter<SpawnableCrate>)null).GetEnumerator();
while (enumerator.MoveNext())
{
SpawnableCrate current = enumerator.Current;
if ((Object)(object)current == (Object)null)
{
continue;
}
List<string> tags = ((Crate)current).Tags;
bool flag = false;
Enumerator<string> enumerator2 = tags.GetEnumerator();
while (enumerator2.MoveNext())
{
string current2 = enumerator2.Current;
if ((current2 == "Pistol" && firearm_Pistol.Value) || (current2 == "SMG" && firearm_SMG.Value) || (current2 == "Rifle" && firearm_Rifle.Value) || (current2 == "Shotgun" && firearm_Shotgun.Value) || (current2 == "Other" && firearm_Other.Value))
{
flag = true;
break;
}
}
bool flag2 = false;
enumerator2 = tags.GetEnumerator();
while (enumerator2.MoveNext())
{
string current3 = enumerator2.Current;
if ((current3 == "Blade" && melee_Blade.Value) || (current3 == "Blunt" && melee_Blunt.Value) || (current3 == "Other" && melee_Other.Value))
{
flag2 = true;
break;
}
}
if (flag || flag2)
{
cached_Weapons.Add(current);
}
}
((MelonBase)this).LoggerInstance.Msg($"[Bonelab_RandomWeapon] Cached {cached_Weapons.Count} crates.");
}
private void Spawn_Random_Weapon()
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: 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)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: 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)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
if (cached_Weapons.Count == 0 || Time.time - last_Spawn_Time < spawn_Cooldown)
{
return;
}
last_Spawn_Time = Time.time;
if ((Object)(object)Player.Head == (Object)null)
{
if (debug_EnabledPref.Value)
{
((MelonBase)this).LoggerInstance.Warning("[Bonelab_RandomWeapon] Player.Head is null!");
}
return;
}
SpawnableCrate val = cached_Weapons[Random.Range(0, cached_Weapons.Count)];
if ((Object)(object)val == (Object)null)
{
if (debug_EnabledPref.Value)
{
((MelonBase)this).LoggerInstance.Warning("[Bonelab_RandomWeapon] Selected crate is null!");
}
return;
}
Vector3 val2 = Player.Head.position + Player.Head.forward * 1.5f + Vector3.up * 0.2f;
Quaternion identity = Quaternion.identity;
Extensions.Spawn(val, val2, identity);
if (debug_EnabledPref.Value)
{
((MelonBase)this).LoggerInstance.Msg("[Bonelab_RandomWeapon] Spawned crate: " + ((Scannable)val).Barcode.ID);
}
}
public override void OnUpdate()
{
if (mod_Enabled)
{
BaseController rightController = Player.RightController;
if (!((Object)(object)rightController == (Object)null) && Get_Input(rightController))
{
Spawn_Random_Weapon();
}
}
}
private static bool Get_Input(BaseController controller)
{
BindType bindType = bind_Mode;
if (bindType == BindType.THUMBSTICK_PRESS || bindType != BindType.DOUBLE_TAP_B)
{
waiting_Second_Tap = false;
last_Tap_Time = 0f;
return controller.GetThumbStickDown();
}
bool bButtonDown = controller.GetBButtonDown();
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (bButtonDown && waiting_Second_Tap)
{
if (realtimeSinceStartup - last_Tap_Time <= 0.32f)
{
return true;
}
waiting_Second_Tap = false;
last_Tap_Time = 0f;
}
else if (bButtonDown)
{
last_Tap_Time = realtimeSinceStartup;
waiting_Second_Tap = true;
}
else if (realtimeSinceStartup - last_Tap_Time > 0.32f)
{
waiting_Second_Tap = false;
last_Tap_Time = 0f;
}
return false;
}
public override void OnApplicationQuit()
{
MelonPreferences.Save();
}
}
}