using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Interaction;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Data;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Linq;
using LabFusion.Extensions;
using LabFusion.SDK.Gamemodes;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using PowerTools;
using PowerTools.Tools;
using Steamworks;
using Steamworks.Data;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Adds a few quality of life features")]
[assembly: AssemblyDescription("Adds a few quality of life features")]
[assembly: AssemblyCompany("cheesydev")]
[assembly: AssemblyProduct("Powertools")]
[assembly: AssemblyCopyright("Developed by freakycheesy/Breadsoup")]
[assembly: AssemblyTrademark("cheesydev")]
[assembly: AssemblyFileVersion("0.6.5")]
[assembly: MelonInfo(typeof(Main), "Powertools", "0.6.5", "freakycheesy/Breadsoup", "https://thunderstore.io/c/bonelab/p/team_cheesy/PowerTools")]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.5.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 PowerTools
{
public class Main : MelonMod
{
internal const string Name = "Powertools";
public const string ModName = "<color=#00FF72>P</color><color=#00FF80>o</color><color=#00FF8D>w</color><color=#00FF99>e</color><color=#00FFA5>r</color><color=#00FFB0> </color><color=#00FFBA>T</color><color=#00FFC3>o</color><color=#00FFCC>o</color><color=#00FFD4>l</color><color=#00FFD4>s</color>";
internal const string Description = "Adds a few quality of life features";
internal const string Author = "freakycheesy/Breadsoup";
internal const string Company = "cheesydev";
internal const string Version = "0.6.5";
internal const string DownloadLink = "https://thunderstore.io/c/bonelab/p/team_cheesy/PowerTools";
public static Page MainPage;
public static Action OnUpdateEvent;
public static Action OnFixedUpdateEvent;
public static Action OnGUIEvent;
public static bool CanUseSteamworks { get; internal set; }
public static MelonPreferences_Category Preferences { get; private set; }
public override void OnInitializeMelon()
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
CanUseSteamworks = !Application.isMobilePlatform;
if (!CanUseSteamworks)
{
MelonLogger.Error("BONELAB FUSION NEEDED FOR STEAMWORKS SINCE IM LAZY AF TO PORT IT ");
}
if (GameSafe())
{
Preferences = MelonPreferences.CreateCategory("PowerTools", "Power Tools");
MainPage = Page.Root.CreatePage("<color=#00FF72>P</color><color=#00FF80>o</color><color=#00FF8D>w</color><color=#00FF99>e</color><color=#00FFA5>r</color><color=#00FFB0> </color><color=#00FFBA>T</color><color=#00FFC3>o</color><color=#00FFCC>o</color><color=#00FFD4>l</color><color=#00FFD4>s</color>", Color.white, 0, true);
Hooking.OnLevelLoaded += delegate
{
OnSceneAwake();
};
Hooking.OnLevelUnloaded += Save;
ToolLoader.LoadTools();
}
}
private bool GameSafe()
{
foreach (KeyValuePair<KeyValuePair<string, string>, string> item in new Dictionary<KeyValuePair<string, string>, string> {
{
new KeyValuePair<string, string>("Fusion Protector", "James Reborn"),
"Fusion Protector is a Fusion Backdoor made by a controversial/non trustworthy figure in the bonelab community who caused tons of drama by making a cheat client"
} })
{
if (MelonBase.FindMelon(item.Key.Key, item.Key.Value) != null)
{
MelonLogger.Error($"BAD MOD FOUND,\n UNINSTALL IT FAST IN YOUR MODS FOLDER ON PC\nMELONLOADER-STRESSLEVELZERO-BONELAB-MODS ON QUEST!!!\n[Mod:{item.Key.ToString()}] [Reason:{item.Value}]");
Environment.Exit(0);
Application.Quit();
return false;
}
}
return true;
}
public override void OnUpdate()
{
((MelonBase)this).OnUpdate();
OnUpdateEvent?.Invoke();
}
public override void OnFixedUpdate()
{
((MelonBase)this).OnFixedUpdate();
OnFixedUpdateEvent?.Invoke();
}
public override void OnGUI()
{
((MelonBase)this).OnGUI();
if (CanUseSteamworks)
{
OnGUIEvent?.Invoke();
}
}
private static void OnSceneAwake()
{
ToolLoader.ResetTools();
Save();
}
public override void OnApplicationQuit()
{
Save();
((MelonBase)this).OnApplicationQuit();
}
public static void Save()
{
MelonPreferences.Save();
}
}
public static class ToolLoader
{
public static List<BaseTool> LoadedTools { get; set; } = new List<BaseTool>();
public static void LoadTool(BaseTool tool)
{
LoadedTools.Add(tool);
tool.Start();
}
public static void LoadTools()
{
LoadedTools.Clear();
MelonLogger.Msg("Loading Tools from Melons");
foreach (MelonBase registeredMelon in MelonBase.RegisteredMelons)
{
Utils.LoadAllValid<BaseTool>(registeredMelon.MelonAssembly.Assembly, LoadToolFromType);
}
LoadedTools.ToList().ForEach(LoadTool);
}
private static void LoadToolFromType(Type type)
{
if (Activator.CreateInstance(type) is BaseTool item)
{
LoadedTools.Add(item);
}
}
public static void ResetTools()
{
ResetTools(LoadedTools);
}
public static void ResetTools(IEnumerable<BaseTool> tools)
{
foreach (BaseTool tool in tools)
{
tool.Reset();
}
}
public static BaseTool GetToolInLoadedToolsFromType(Type type)
{
return GetToolInLoadedToolsFromType(type.FullName);
}
public static BaseTool GetToolInLoadedToolsFromType(string fullname)
{
foreach (BaseTool loadedTool in LoadedTools)
{
if (loadedTool.GetType().FullName == fullname)
{
MelonLogger.Msg("Found tool: (" + fullname + ")");
return loadedTool;
}
}
MelonLogger.Error("Could not find Tool with type: (" + fullname + ")");
return null;
}
}
public static class Utils
{
public static void LoadAllValid<T>(Assembly assembly, Action<Type> runOnValid)
{
string fullName = assembly.FullName;
if (fullName != null && fullName.Contains("System"))
{
return;
}
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
if ((!type.Name.Contains("Mono") || !type.Name.Contains("Security")) && typeof(T).IsAssignableFrom(type) && !type.IsAbstract && !type.IsInterface)
{
try
{
runOnValid(type);
}
catch (Exception ex)
{
MelonLogger.Error(ex.Message);
}
}
}
}
public static byte[] LoadBytesFromAssembly(Assembly assembly, string name)
{
if (!((ReadOnlySpan<string>)assembly.GetManifestResourceNames()).Contains(name))
{
return null;
}
using Stream stream = assembly.GetManifestResourceStream(name);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
public static Assembly LoadAssemblyFromAssembly(Assembly assembly, string name)
{
byte[] array = LoadBytesFromAssembly(assembly, name);
if (array == null)
{
return null;
}
return Assembly.Load(array);
}
}
}
namespace PowerTools.Tools
{
public abstract class ToolTemplate : BaseTool
{
public override string ToolName => "";
public override Color ToolTheme => Color.green;
public override void Start()
{
base.Start();
}
public override void MelonCreator()
{
base.MelonCreator();
}
public override void BoneMenuCreator()
{
base.BoneMenuCreator();
}
public override void OnSetEnabled(bool value)
{
base.OnSetEnabled(value);
}
public override void Reset()
{
base.Reset();
}
}
public class AchievementTool : BaseTool
{
public static Page AchievementsPage;
public static Action InitiatedSteam;
public override string ToolName => "Achievement Tool";
public override Color ToolTheme => Color.red + Color.yellow;
public override bool HaveEnableToggle => false;
public override void Start()
{
base.Start();
if (Main.CanUseSteamworks)
{
InitiatedSteam = (Action)Delegate.Combine(InitiatedSteam, new Action(AddAchievements));
}
}
private void AddAchievements()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
foreach (Achievement achievement2 in SteamUserStats.Achievements)
{
Achievement achievement = achievement2;
Page obj = AchievementsPage.CreatePage(((Achievement)(ref achievement)).Name + "\n(" + ((Achievement)(ref achievement)).Identifier + ")", Color.green, 0, true);
obj.CreateFunction("Unlock", Color.green, (Action)delegate
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
UnlockAchievement(achievement);
});
obj.CreateFunction("Lock", Color.green, (Action)delegate
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
LockAchievement(achievement);
});
}
}
private void LockAchievement(Achievement achievement)
{
((Achievement)(ref achievement)).Clear();
SteamUserStats.StoreStats();
SteamUserStats.RequestCurrentStats();
}
private void UnlockAchievement(Achievement achievement)
{
((Achievement)(ref achievement)).Trigger(true);
SteamUserStats.StoreStats();
SteamUserStats.RequestCurrentStats();
}
public override void MelonCreator()
{
base.MelonCreator();
_ = Main.CanUseSteamworks;
}
public override void BoneMenuCreator()
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
base.BoneMenuCreator();
if (!Main.CanUseSteamworks)
{
Page.CreateFunction("Steam Only", ToolTheme, (Action)delegate
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
new Notification
{
ShowTitleOnPopup = true,
PopupLength = 0.1f,
Title = NotificationText.op_Implicit("guess what"),
Message = NotificationText.op_Implicit("impossible on oculus")
};
});
}
else
{
Page.CreateFunction("Initiate Steam", ToolTheme, (Action)InitPlatform);
Page.CreateFunction("Unlock All Achievements", ToolTheme, (Action)UnlockAchievements);
Page.CreateFunction("Lock All Achievements", ToolTheme, (Action)LockAchievements);
AchievementsPage = Page.CreatePage("Achievements", Color.green, 12, true);
}
}
private void InitPlatform()
{
SteamClient.Init(1592190u, true);
InitiatedSteam?.Invoke();
}
private void LockAchievements()
{
UnlockSteamAchievements();
}
private void UnlockAchievements()
{
LockSteamAchievements();
}
private void UnlockSteamAchievements()
{
IEnumerableExtensions.ForEach<Achievement>(SteamUserStats.Achievements, (Action<Achievement>)UnlockAchievement);
}
private void LockSteamAchievements()
{
IEnumerableExtensions.ForEach<Achievement>(SteamUserStats.Achievements, (Action<Achievement>)LockAchievement);
}
public override void OnSetEnabled(bool value)
{
base.OnSetEnabled(value);
}
public override void Reset()
{
base.Reset();
}
}
public abstract class BaseTool
{
public Page Page;
public MelonPreferences_Entry<bool> ToolEnabled;
public bool started;
public abstract bool HaveEnableToggle { get; }
public abstract string ToolName { get; }
public abstract Color ToolTheme { get; }
public virtual void Start()
{
if (!started)
{
MelonCreator();
BoneMenuCreator();
MelonLogger.Msg("Loaded tool: (" + ToolName + ")");
started = true;
}
}
public virtual void MelonCreator()
{
ToolEnabled = Main.Preferences.CreateEntry<bool>(ToolName + " Enabled", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
}
public virtual void BoneMenuCreator()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
Page = Main.MainPage.CreatePage(ToolName, ToolTheme, 0, true);
if (HaveEnableToggle)
{
Page.CreateBool("Enabled", ToolTheme, ToolEnabled.Value, (Action<bool>)delegate(bool a)
{
ToolEnabled.Value = a;
});
}
}
public virtual void OnSetEnabled(bool value)
{
ToolEnabled.Value = value;
}
public virtual void Reset()
{
_ = ToolEnabled;
}
}
public class ButtonDisabler : BaseTool
{
public static MelonPreferences_Entry<bool> EndOfLevelButton { get; set; }
public override string ToolName => "Button Disabler";
public override Color ToolTheme => Color.red + Color.yellow / 2f;
public override bool HaveEnableToggle => false;
public override void Start()
{
base.Start();
}
public override void MelonCreator()
{
base.MelonCreator();
EndOfLevelButton = Main.Preferences.CreateEntry<bool>("Disableendoflevelbutton", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
}
public override void BoneMenuCreator()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
base.BoneMenuCreator();
Page.CreateBool("Disable Next Level Button", ToolTheme, EndOfLevelButton.Value, (Action<bool>)OnEndOfLevelButtonEnabled);
}
public override void OnSetEnabled(bool value)
{
base.OnSetEnabled(value);
DisableButtons();
}
public override void Reset()
{
base.Reset();
DisableButtons();
}
public void DisableButtons()
{
foreach (Transform item in Object.FindObjectsOfType<Transform>(true))
{
if (!((Object)item).name.Contains("FLOORS") && !((Object)item).name.Contains("LoadButtons") && !((Object)item).name.Contains("prop_bigButton") && !((Object)item).name.Contains("INTERACTION"))
{
continue;
}
for (int i = 0; i < item.childCount; i++)
{
Transform child = item.GetChild(i);
ButtonToggle component = ((Component)child).GetComponent<ButtonToggle>();
if ((Object)(object)component != (Object)null && ToolEnabled.Value)
{
if (EndOfLevelButton.Value)
{
((Behaviour)component).enabled = false;
}
else if (!EndOfLevelButton.Value)
{
if (!((Object)child).name.Contains("prop_bigButton_NEXTLEVEL"))
{
((Behaviour)component).enabled = false;
}
if (((Object)child).name.Contains("prop_bigButton_NEXTLEVEL"))
{
((Behaviour)component).enabled = true;
}
}
}
else if ((Object)(object)component != (Object)null && !ToolEnabled.Value)
{
((Behaviour)component).enabled = true;
}
}
}
}
private void OnEndOfLevelButtonEnabled(bool value)
{
EndOfLevelButton.Value = value;
Main.Save();
DisableButtons();
}
}
public enum Bool : byte
{
Default,
True,
False
}
public class HealthSettings : BaseTool
{
[HarmonyPatch(typeof(Player_Health))]
public static class PlayerHealthPatch
{
[HarmonyPatch("SetFullHealth")]
[HarmonyPrefix]
public static void Respawn()
{
MelonLogger.Msg("Respawn");
Hooking_OnPlayerDamageRecieved(0f);
Unragdoll();
}
[HarmonyPatch("Death")]
[HarmonyPrefix]
public static void Death()
{
Hooking_OnPlayerDamageRecieved(0f);
MelonLogger.Msg("Death");
if (RagdollOnDeath.Value)
{
Ragdoll();
}
}
[HarmonyPatch("TAKEDAMAGE")]
[HarmonyPrefix]
public static void TAKEDAMAGE(Player_Health __instance, float damage)
{
Hooking_OnPlayerDamageRecieved(damage);
MelonLogger.Msg(((Object)((Health)__instance)._rigManager).name + " was damaged");
}
}
public static MelonPreferences_Entry<bool> GodMode;
public static MelonPreferences_Entry<bool> RagdollOnDeath;
public static MelonPreferences_Entry<Bool> ReloadLevel;
public static MelonPreferences_Entry<float> DeathTime;
public static Player_Health PlayerHealth
{
get
{
RigManager rigManager = Player.RigManager;
if ((Object)(object)((rigManager != null) ? rigManager.health : null) != (Object)null)
{
return ((Il2CppObjectBase)Player.RigManager.health).TryCast<Player_Health>();
}
return null;
}
}
public override string ToolName => "Health Settings";
public override Color ToolTheme => Color.red;
public override bool HaveEnableToggle => false;
public override void Start()
{
base.Start();
Hooking.OnLevelLoaded += delegate
{
EditReloadOnDeath(ReloadLevel.Value);
};
}
private static void Hooking_OnPlayerDamageRecieved(float obj)
{
MelonLogger.Msg("Damage Recieved");
EditReloadOnDeath(ReloadLevel.Value);
if (GodMode.Value)
{
SetFullHealth();
}
else if (RagdollOnDeath.Value && ((Health)PlayerHealth).curr_Health <= 0f)
{
Ragdoll();
}
}
private static void Ragdoll()
{
Player.PhysicsRig.ShutdownRig();
Player.PhysicsRig.RagdollRig();
}
private static void Unragdoll()
{
Player.PhysicsRig.TurnOnRig();
Player.PhysicsRig.UnRagdollRig();
}
public override void MelonCreator()
{
base.MelonCreator();
GodMode = Main.Preferences.CreateEntry<bool>("God Mode", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
RagdollOnDeath = Main.Preferences.CreateEntry<bool>("Ragdoll On Death", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
ReloadLevel = Main.Preferences.CreateEntry<Bool>("ReloadLevel", Bool.Default, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
DeathTime = Main.Preferences.CreateEntry<float>("Damage Threshold", 3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
}
public override void BoneMenuCreator()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: 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)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
base.BoneMenuCreator();
Page.CreateBool("God Mode", ToolTheme, GodMode.Value, (Action<bool>)delegate(bool a)
{
GodMode.Value = a;
Main.Save();
});
Page.CreateBool("Ragdoll On Death", ToolTheme, RagdollOnDeath.Value, (Action<bool>)delegate(bool a)
{
RagdollOnDeath.Value = a;
((Health)PlayerHealth)._testRagdollOnDeath = RagdollOnDeath.Value;
Main.Save();
});
Page.CreateEnum("Reload Level On Death", ToolTheme, (Enum)ReloadLevel.Value, (Action<Enum>)delegate(Enum a)
{
ReloadLevel.Value = (Bool)(object)a;
EditReloadOnDeath(a);
Main.Save();
});
Page.CreateFloat("Death Time", ToolTheme, DeathTime.Value, 1f, 0f, 30f, (Action<float>)delegate(float dt)
{
DeathTime.Value = dt;
PlayerHealth.deathTimeAmount = DeathTime.Value;
Main.Save();
});
Page.CreateFunction("Die", ToolTheme, (Action)OnDie);
Page.CreateFunction("Refill Health", ToolTheme, (Action)SetFullHealth);
}
public static void EditReloadOnDeath(Enum a)
{
if (!Object.op_Implicit((Object)(object)PlayerHealth) || !(a is Bool))
{
return;
}
switch ((Bool)(object)a)
{
case Bool.True:
PlayerHealth.reloadLevelOnDeath = true;
break;
case Bool.False:
PlayerHealth.reloadLevelOnDeath = false;
break;
case Bool.Default:
{
PlayerHealthDecorator val = Object.FindObjectOfType<PlayerHealthDecorator>();
if (Object.op_Implicit((Object)(object)val))
{
PlayerHealth.reloadLevelOnDeath = val._reloadLevelOnDeath;
}
break;
}
}
}
public static void SetFullHealth()
{
if (!GamemodeManager.IsGamemodeStarted)
{
Player_Health playerHealth = PlayerHealth;
if (playerHealth != null)
{
((Health)playerHealth).SetFullHealth();
}
}
}
private static void OnDie()
{
EditReloadOnDeath(ReloadLevel.Value);
Player_Health playerHealth = PlayerHealth;
if (playerHealth != null)
{
((Health)playerHealth).Dying(100f);
}
Player_Health playerHealth2 = PlayerHealth;
if (playerHealth2 != null)
{
((Health)playerHealth2).Death();
}
Player_Health playerHealth3 = PlayerHealth;
if (playerHealth3 != null)
{
((Health)playerHealth3).Respawn();
}
}
public override void Reset()
{
base.Reset();
EditReloadOnDeath(ReloadLevel.Value);
PlayerHealth.deathTimeAmount = DeathTime.Value;
}
}
public class InfiniteAmmo : BaseTool
{
public static class GunPatches
{
[HarmonyPatch(typeof(AmmoInventory), "RemoveCartridge")]
public static class TaxReturn
{
[HarmonyPrefix]
public static void Prefix(AmmoInventory __instance, CartridgeData cartridge, int count)
{
if (Enabled)
{
__instance.AddCartridge(cartridge, count);
}
}
}
[HarmonyPatch(typeof(InventoryAmmoReceiver), "OnHandGrab")]
public static class AmmoCheckPatch
{
[HarmonyPrefix]
public static void Prefix()
{
if (Enabled && InfiniteAmmoEnabled.Value)
{
if (AmmoInventory.Instance.GetCartridgeCount("light") <= 0)
{
Bankruptcy(AmmoInventory.Instance.lightAmmoGroup);
}
if (AmmoInventory.Instance.GetCartridgeCount("medium") <= 0)
{
Bankruptcy(AmmoInventory.Instance.mediumAmmoGroup);
}
if (AmmoInventory.Instance.GetCartridgeCount("heavy") <= 25)
{
Bankruptcy(AmmoInventory.Instance.heavyAmmoGroup);
}
}
}
private static void Bankruptcy(AmmoGroup group)
{
AmmoInventory.Instance.AddCartridge(group, 1);
}
}
[HarmonyPatch(typeof(Magazine), "OnGrab")]
public static class CashBack
{
[HarmonyPostfix]
public static void Postfix()
{
if (Enabled)
{
Magazine componentInHand = Player.GetComponentInHand<Magazine>(Player.LeftHand);
Magazine componentInHand2 = Player.GetComponentInHand<Magazine>(Player.RightHand);
if ((Object)(object)componentInHand != (Object)null)
{
MagMax(componentInHand);
}
if ((Object)(object)componentInHand2 != (Object)null)
{
MagMax(componentInHand2);
}
}
}
private static void MagMax(Magazine mag)
{
if (InfiniteAmmoEnabled.Value)
{
int rounds = mag.magazineState.magazineData.rounds;
int cartridgeCount = AmmoInventory.Instance.GetCartridgeCount(mag.magazineState.cartridgeData);
if (cartridgeCount < rounds)
{
BankStatement(mag, rounds, cartridgeCount);
}
}
if (InfiniteAmmo.MidasTouch.Value)
{
MidasTouch(mag);
}
}
private static void MidasTouch(Magazine mag)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
foreach (Renderer componentsInChild in ((Component)mag).GetComponentsInChildren<Renderer>())
{
foreach (Material item in (Il2CppArrayBase<Material>)(object)componentsInChild.materials)
{
item.mainTexture = null;
item.color = Color.yellow;
item.SetFloat("_Metallic", 1f);
item.SetFloat("_Smoothness", 1f);
}
}
}
private static void BankStatement(Magazine mag, int magMax, int cartridgeCount)
{
if (AmmoInventory.Instance.GetCartridgeCount("light") == cartridgeCount)
{
Loan(mag, AmmoInventory.Instance.lightAmmoGroup, magMax);
}
else if (AmmoInventory.Instance.GetCartridgeCount("medium") == cartridgeCount)
{
Loan(mag, AmmoInventory.Instance.mediumAmmoGroup, magMax);
}
else if (AmmoInventory.Instance.GetCartridgeCount("heavy") == cartridgeCount)
{
Loan(mag, AmmoInventory.Instance.heavyAmmoGroup, magMax);
}
}
private static void Loan(Magazine mag, AmmoGroup group, int amount)
{
if (AmmoInventory.Instance.GetCartridgeCount(group.KeyName) == 1)
{
AmmoInventory.Instance.AddCartridge(group, -1);
}
AmmoInventory.Instance.AddCartridge(group, amount);
mag.magazineState.Refill();
}
}
[HarmonyPatch(typeof(Gun), "OnFire")]
public static class CreditCard
{
[HarmonyPostfix]
public static void Postfix(Gun __instance)
{
if (Enabled && InfMags.Value && (Object)(object)((Component)__instance).gameObject.GetComponentInChildren<Magazine>() != (Object)null)
{
((Component)__instance).gameObject.GetComponentInChildren<Magazine>().magazineState.Refill();
}
}
}
[HarmonyPatch(typeof(Magazine), "OnEject")]
public static class Withdraw
{
[HarmonyPostfix]
public static void Postfix(Magazine __instance)
{
if (Enabled && EjectRefill.Value)
{
__instance.magazineState.Refill();
}
}
}
[HarmonyPatch(typeof(Gun), "AmmoCount")]
public static class ShotgunCreditCard
{
[HarmonyPrefix]
public static bool Prefix(Gun __instance, ref int __result)
{
if (Enabled && InfMags.Value)
{
__result = 1;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Gun), "CheckGunRequirements")]
public static class Paycheck
{
[HarmonyPrefix]
public static void Prefix(Gun __instance)
{
if (Enabled && AutoChamber.Value)
{
__instance.Charge();
}
if (Enabled && AutoLoad.Value && !__instance._hasMagState)
{
__instance.InstantLoadAsync();
}
}
}
[HarmonyPatch(typeof(Gun), "OnTriggerGripAttached")]
public static class DirectDeposit
{
[HarmonyPrefix]
public static void Prefix(Gun __instance)
{
if (Enabled && AutoLoad.Value && !__instance._hasMagState)
{
__instance.InstantLoadAsync();
}
}
}
public static bool Enabled
{
get
{
if (Instance == null)
{
return false;
}
if (Instance != null && Instance.ToolEnabled == null)
{
return false;
}
return Instance.ToolEnabled.Value;
}
}
}
public static InfiniteAmmo Instance { get; private set; }
public static MelonPreferences_Entry<bool> InfiniteAmmoEnabled { get; set; }
public static MelonPreferences_Entry<bool> InfMags { get; set; }
public static MelonPreferences_Entry<bool> AutoChamber { get; set; }
public static MelonPreferences_Entry<bool> AutoLoad { get; set; }
public static MelonPreferences_Entry<bool> EjectRefill { get; set; }
public static MelonPreferences_Entry<bool> MidasTouch { get; set; }
public override string ToolName => "Infinite Ammo";
public override Color ToolTheme => Color.yellow;
public override bool HaveEnableToggle => true;
public override void Start()
{
base.Start();
Instance = this;
}
public override void MelonCreator()
{
base.MelonCreator();
InfiniteAmmoEnabled = Main.Preferences.CreateEntry<bool>("Infinite Ammo", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
AutoChamber = Main.Preferences.CreateEntry<bool>("AutoChamber", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
AutoLoad = Main.Preferences.CreateEntry<bool>("AutoLoad", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
InfMags = Main.Preferences.CreateEntry<bool>("AutoRefill", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
EjectRefill = Main.Preferences.CreateEntry<bool>("EjectRefill", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
MidasTouch = Main.Preferences.CreateEntry<bool>("MidasTouch", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
}
public override void BoneMenuCreator()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
base.BoneMenuCreator();
Page.CreateBool("Infinte Ammo", ToolTheme, InfiniteAmmoEnabled.Value, (Action<bool>)OnGiveAmmoWhenEmpty);
Page.CreateBool("Auto Chamber", ToolTheme, AutoChamber.Value, (Action<bool>)OnAutoChamber);
Page.CreateBool("Auto Load Guns", ToolTheme, InfiniteAmmoEnabled.Value, (Action<bool>)OnAutoLoad);
Page.CreateBool("Auto Refill", ToolTheme, InfMags.Value, (Action<bool>)OnInfiniteMags);
Page.CreateBool("Eject Refill", ToolTheme, EjectRefill.Value, (Action<bool>)OnEjectRefill);
Page.CreateBool("Midas Touch", ToolTheme, MidasTouch.Value, (Action<bool>)OnGoldMags);
}
private static void OnGoldMags(bool obj)
{
MidasTouch.Value = obj;
Main.Save();
}
private static void OnEjectRefill(bool obj)
{
EjectRefill.Value = obj;
Main.Save();
}
public override void OnSetEnabled(bool value)
{
base.OnSetEnabled(value);
Main.Save();
}
private static void OnGiveAmmoWhenEmpty(bool value)
{
InfiniteAmmoEnabled.Value = value;
Main.Save();
}
private static void OnInfiniteMags(bool value)
{
InfMags.Value = value;
Main.Save();
}
private static void OnAutoChamber(bool value)
{
AutoChamber.Value = value;
Main.Save();
}
private static void OnAutoLoad(bool value)
{
AutoLoad.Value = value;
Main.Save();
}
}
public class PhysicsTool : BaseTool
{
[HarmonyPatch(typeof(Grip))]
private static class GripPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void Awake(Grip __instance)
{
AddForcePull(__instance);
}
public static void AddForcePull(Grip __instance)
{
if (ForcePullAnything.Value)
{
ForcePullGrip val = default(ForcePullGrip);
if (!((Component)__instance).gameObject.TryGetComponent<ForcePullGrip>(ref val))
{
val = ((Component)__instance).gameObject.AddComponent<ForcePullGrip>();
}
((Component)val).gameObject.layer = LayerMask.NameToLayer("Interactable");
val._grip = __instance;
val.maxForce = maxForce;
val.maxSpeed = maxSpeed;
}
}
}
public static MelonPreferences_Entry<bool> ForcePullAnything;
public static float maxForce = 1000f;
public static float maxSpeed = 1E+10f;
public override string ToolName => "Physics Tool";
public override Color ToolTheme => Color.green;
public override bool HaveEnableToggle => false;
public override void MelonCreator()
{
base.MelonCreator();
ForcePullAnything = Main.Preferences.CreateEntry<bool>("ForcePullAnything", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
}
public override void BoneMenuCreator()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
base.BoneMenuCreator();
Page.CreateBool("Force Pull Anything (Cannot Reverse)", ToolTheme, ForcePullAnything.Value, (Action<bool>)delegate(bool a)
{
ForcePullAnything.Value = a;
foreach (Grip item in Resources.FindObjectsOfTypeAll<Grip>())
{
GripPatch.AddForcePull(item);
}
Main.Save();
});
}
}
public class RagdollLegs : BaseTool
{
public override string ToolName => "Ragdoll Legs";
public override Color ToolTheme => Color.cyan;
public override bool HaveEnableToggle => true;
public override void OnSetEnabled(bool value)
{
if (value)
{
Player.PhysicsRig.PhysicalLegs();
}
else
{
Player.PhysicsRig.UnRagdollRig();
}
}
}
public class VaultingToggle : BaseTool
{
[HarmonyPatch(typeof(PhysicsRig))]
public static class VaultPatch
{
[HarmonyPatch("CheckDangle")]
[HarmonyPrefix]
public static bool CheckDangle(PhysicsRig __instance, ref bool __result)
{
if (!instance.ToolEnabled.Value)
{
__result = false;
return false;
}
return true;
}
}
public static VaultingToggle instance;
public override string ToolName => "Vaulting Toggle";
public override Color ToolTheme => Color.magenta;
public override bool HaveEnableToggle => true;
public override void Start()
{
base.Start();
}
public override void BoneMenuCreator()
{
base.BoneMenuCreator();
instance = this;
}
}
}
namespace PowerTools.src
{
public static class Extensions
{
public static List<T> ToList<T>(this IEnumerable<T> dirtyList)
{
return ((IEnumerable<T>)Enumerable.ToArray<T>(dirtyList)).ToList();
}
}
}