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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MoreCommands.Accessors;
using MoreCommands.Commands;
using MoreCommands.Common;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MoreCommands")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Console commands factory for White Knuckle. You can use this for your commands.")]
[assembly: AssemblyFileVersion("0.5.1.0")]
[assembly: AssemblyInformationalVersion("0.5.1+904eecf48006200ef1091fb416a8d596efe00815")]
[assembly: AssemblyProduct("MoreCommands")]
[assembly: AssemblyTitle("MoreCommands")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.5.1.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;
}
}
}
public static class ArgParse
{
public static int GetMult(string[] args, int fallback = 1)
{
if (args.Length != 0)
{
int.TryParse(args[0], out fallback);
}
return fallback;
}
public static bool ParseEnabled(bool enabled, string[] args)
{
if (args.Length == 0 || !bool.TryParse(args[0], out var result))
{
return !enabled;
}
return result;
}
}
namespace MoreCommands
{
[BepInPlugin("shishyando.WK.MoreCommands", "MoreCommands", "0.5.1")]
public class MoreCommandsPlugin : BaseUnityPlugin
{
public static ManualLogSource Beep;
private readonly Harmony Harmony = new Harmony("shishyando.WK.MoreCommands");
private void Awake()
{
Beep = ((BaseUnityPlugin)this).Logger;
CommandRegistry.InitializeCommands();
Harmony.PatchAll();
Beep.LogInfo((object)"shishyando.WK.MoreCommands is loaded");
SceneManager.sceneUnloaded += OnSceneUnloaded;
}
public static void OnSceneUnloaded(Scene s)
{
if (((Scene)(ref s)).name == "Game-Main")
{
CommandRegistry.DisableAllTogglableCommands();
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "shishyando.WK.MoreCommands";
public const string PLUGIN_NAME = "MoreCommands";
public const string PLUGIN_VERSION = "0.5.1";
}
}
namespace MoreCommands.Patches
{
[HarmonyPatch(typeof(CommandConsole), "Awake")]
public static class CommandConsole_Patcher
{
[HarmonyPostfix]
public static void AddMorePlayerCommands(CommandConsole __instance)
{
foreach (ICommand item in CommandRegistry.GetCommandsByTag(CommandTag.Console))
{
string[] aliases = item.Aliases;
foreach (string text in aliases)
{
CommandConsole.AddCommand(text, item.GetCallback(), false);
}
}
}
}
[HarmonyPatch(typeof(ENT_Player), "CreateCommands")]
public static class ENT_Player_Patcher
{
[HarmonyPostfix]
public static void AddMorePlayerCommands(ENT_Player __instance)
{
foreach (ICommand item in CommandRegistry.GetCommandsByTag(CommandTag.Player))
{
string[] aliases = item.Aliases;
foreach (string text in aliases)
{
CommandConsole.AddCommand(text, item.GetCallback(), false);
}
}
}
}
}
namespace MoreCommands.Common
{
public interface ICommand
{
string[] Aliases { get; }
CommandTag Tag { get; }
string Description { get; }
bool CheatsOnly { get; }
Action<string[]> GetCallback();
}
public interface ITogglableCommand : ICommand
{
bool Enabled { get; set; }
void UpdateEnabled(string[] args);
}
public abstract class CommandBase : ICommand
{
public abstract string[] Aliases { get; }
public abstract CommandTag Tag { get; }
public abstract string Description { get; }
public abstract bool CheatsOnly { get; }
protected abstract Action<string[]> GetLogicCallback();
public void EnsureCheats(string[] args)
{
if (CheatsOnly)
{
CommandConsoleAccessor.EnsureCheatsAreEnabled();
}
}
public virtual Action<string[]> GetCallback()
{
return (Action<string[]>)Delegate.Combine(new Action<string[]>(EnsureCheats), GetLogicCallback());
}
}
public abstract class TogglableCommandBase : CommandBase, ITogglableCommand, ICommand
{
public bool Enabled { get; set; }
public void UpdateEnabled(string[] args)
{
Enabled = ArgParse.ParseEnabled(Enabled, args);
}
public sealed override Action<string[]> GetCallback()
{
return (Action<string[]>)Delegate.Combine((Action<string[]>)Delegate.Combine(new Action<string[]>(UpdateEnabled), new Action<string[]>(base.EnsureCheats)), GetLogicCallback());
}
public static string[] WhenEnabled(bool enabled)
{
return new string[1] { enabled.ToString().ToLower() };
}
public static string[] WhenDisabled(bool enabled)
{
return new string[1] { (!enabled).ToString().ToLower() };
}
}
public enum CommandTag
{
Player,
World,
Console
}
public static class PerkChanger
{
public static void MaxOutPerk(string perkId)
{
ENT_Player playerObject = ENT_Player.playerObject;
if ((Object)(object)playerObject == (Object)null)
{
return;
}
Perk perk = playerObject.GetPerk(perkId);
if ((Object)(object)perk != (Object)null)
{
int num = perk.stackMax - perk.stackAmount;
if (num > 0)
{
perk.AddStack(num);
}
return;
}
Perk perkAsset = CL_AssetManager.GetPerkAsset(perkId, "");
if ((Object)(object)perkAsset != (Object)null)
{
Perk val = Object.Instantiate<Perk>(perkAsset);
int stackMax = val.stackMax;
if (stackMax > 0)
{
playerObject.AddPerk(val, stackMax);
}
}
else
{
MoreCommandsPlugin.Beep.LogWarning((object)("Perk " + perkId + " not found!"));
}
}
}
public static class CommandRegistry
{
public static List<ICommand> RegisteredCommands = new List<ICommand>();
public static bool Initialized = false;
private static void RegisterAll()
{
Register(new BetterListPerksCommand());
Register(new CargoCommand());
Register(new ExploreCommand());
Register(new FlashCommand());
Register(new FreerunCommand());
Register(new GravityCommand());
Register(new ManCommand());
Register(new SpeedyCommand());
}
public static void InitializeCommands()
{
if (!Initialized)
{
RegisterAll();
Initialized = true;
}
}
public static void Register(ICommand command)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
string[] aliases = command.Aliases;
foreach (string alias in aliases)
{
ICommand command2 = RegisteredCommands.Find((ICommand c) => c.Aliases.Contains(alias));
if (command2 != null)
{
dictionary.Add(alias, command2.GetType().ToString());
}
}
if (dictionary.Count > 0)
{
MoreCommandsPlugin.Beep.LogWarning((object)string.Format("Failed to register command {0}:\n{1}", command.GetType(), GeneralExtensions.Join<KeyValuePair<string, string>>((IEnumerable<KeyValuePair<string, string>>)dictionary, (Func<KeyValuePair<string, string>, string>)((KeyValuePair<string, string> x) => "\t" + x.Key + " taken by " + x.Value), "\n")));
}
else
{
RegisteredCommands.Add(command);
}
}
public static List<ICommand> GetAllCommands()
{
return RegisteredCommands.OrderBy((ICommand c) => c.Aliases[0]).ToList();
}
public static List<ICommand> GetCommandsByTag(CommandTag tag)
{
return RegisteredCommands.Where((ICommand c) => c.Tag == tag).ToList();
}
public static ICommand GetCommand<T>() where T : ICommand
{
return RegisteredCommands.FirstOrDefault((ICommand c) => c.GetType() == typeof(T));
}
public static Action<string[]> GetCallback<T>() where T : ICommand
{
return RegisteredCommands.FirstOrDefault((ICommand c) => c.GetType() == typeof(T))?.GetCallback() ?? ((Action<string[]>)delegate
{
MoreCommandsPlugin.Beep.LogWarning((object)$"Command {typeof(T)} not found");
});
}
public static void DisableAllTogglableCommands()
{
foreach (ICommand registeredCommand in RegisteredCommands)
{
if (registeredCommand is ITogglableCommand togglableCommand)
{
togglableCommand.Enabled = false;
}
}
}
}
}
namespace MoreCommands.Commands
{
public sealed class BetterListPerksCommand : CommandBase
{
public override string[] Aliases => new string[1] { "lp" };
public override CommandTag Tag => CommandTag.Console;
public override string Description => "List perks info, filtered by `arg`";
public override bool CheatsOnly => false;
protected override Action<string[]> GetLogicCallback()
{
return delegate(string[] args)
{
foreach (Perk perkAsset in CL_AssetManager.GetFullCombinedAssetDatabase().perkAssets)
{
if (args.Length == 0 || Has(((Object)perkAsset).name, args[0]) || Has(perkAsset.description, args[0]) || Has(perkAsset.id, args[0]))
{
CommandConsoleAccessor.EchoToConsole("- " + perkAsset.GetTitle(false) + " (<color=grey>" + perkAsset.id + "</color>)\n" + perkAsset.GetDescription(false, false, false) + "</color></color></color>\n");
}
}
};
}
private bool Has(string text, string check)
{
return text != null && text.IndexOf(check, StringComparison.OrdinalIgnoreCase) >= 0;
}
}
public sealed class CargoCommand : CommandBase
{
public override string[] Aliases => new string[1] { "cargo" };
public override CommandTag Tag => CommandTag.Player;
public override string Description => "max backstrength";
public override bool CheatsOnly => true;
protected override Action<string[]> GetLogicCallback()
{
return delegate
{
CommandConsoleAccessor.EnsureCheatsAreEnabled();
PerkChanger.MaxOutPerk("Perk_BackStrengtheners");
};
}
}
public sealed class ExploreCommand : TogglableCommandBase
{
public override string[] Aliases => new string[1] { "explore" };
public override CommandTag Tag => CommandTag.Player;
public override string Description => "freerun + noclip";
public override bool CheatsOnly => true;
protected override Action<string[]> GetLogicCallback()
{
return (Action<string[]>)Delegate.Combine(CommandRegistry.GetCallback<FreerunCommand>(), (Action<string[]>)delegate
{
ENT_Player playerObject = ENT_Player.playerObject;
if (playerObject != null)
{
playerObject.Noclip(TogglableCommandBase.WhenEnabled(base.Enabled));
}
});
}
}
public sealed class FlashCommand : CommandBase
{
public override string[] Aliases => new string[1] { "flash" };
public override CommandTag Tag => CommandTag.Player;
public override string Description => "freerun + speedy + cargo";
public override bool CheatsOnly => true;
protected override Action<string[]> GetLogicCallback()
{
return (Action<string[]>)Delegate.Combine((Action<string[]>)Delegate.Combine(CommandRegistry.GetCallback<FreerunCommand>(), CommandRegistry.GetCallback<SpeedyCommand>()), CommandRegistry.GetCallback<CargoCommand>());
}
}
public sealed class FreerunCommand : TogglableCommandBase
{
public override string[] Aliases => new string[1] { "freerun" };
public override CommandTag Tag => CommandTag.Player;
public override string Description => "godmode + deathgoo-stop + fullbright + infinitestamina + notarget";
public override bool CheatsOnly => true;
protected override Action<string[]> GetLogicCallback()
{
return delegate
{
ENT_Player playerObject = ENT_Player.playerObject;
if (playerObject != null)
{
playerObject.SetGodMode(base.Enabled);
}
if (playerObject != null)
{
playerObject.InfiniteStaminaCommand(TogglableCommandBase.WhenEnabled(base.Enabled));
}
FXManager.Fullbright(TogglableCommandBase.WhenEnabled(base.Enabled));
DEN_DeathFloor instance = DEN_DeathFloor.instance;
if (instance != null)
{
instance.DeathGooToggle(TogglableCommandBase.WhenDisabled(base.Enabled));
}
CL_GameManager gMan = CL_GameManager.gMan;
if (gMan != null)
{
gMan.NoTarget(TogglableCommandBase.WhenEnabled(base.Enabled));
}
};
}
}
public sealed class GravityCommand : CommandBase
{
public override string[] Aliases => new string[2] { "sv_gravity", "grav" };
public override CommandTag Tag => CommandTag.Player;
public override string Description => "set player gravity multiplier (1 is default)";
public override bool CheatsOnly => true;
protected override Action<string[]> GetLogicCallback()
{
return delegate(string[] args)
{
CommandConsoleAccessor.EnsureCheatsAreEnabled();
ENT_Player playerObject = ENT_Player.playerObject;
float result;
if (args.Length == 0)
{
playerObject.SetGravityMult(1f);
}
else if (float.TryParse(args[0], out result))
{
playerObject.SetGravityMult(result);
}
else
{
CommandConsoleAccessor.EchoToConsole("Invalid arguments for gravity command: " + GeneralExtensions.Join<string>((IEnumerable<string>)args, (Func<string, string>)null, " "));
}
};
}
}
public sealed class ManCommand : CommandBase
{
private const string CHEAT_SIGN = "<color=orange>+</color>";
public override string[] Aliases => new string[3] { "man", "mhelp", "morecommandshelp" };
public override CommandTag Tag => CommandTag.Console;
public override string Description => "prints MoreCommands with their descriptions ('+' = enables cheats)";
public override bool CheatsOnly => false;
protected override Action<string[]> GetLogicCallback()
{
return delegate(string[] args)
{
foreach (ICommand allCommand in CommandRegistry.GetAllCommands())
{
if (args.Length == 0 || allCommand.Aliases.Contains(args[0]))
{
CommandConsoleAccessor.EchoToConsole(Colored((allCommand.CheatsOnly ? "<color=orange>+</color>" : "-") + " " + GeneralExtensions.Join<string>((IEnumerable<string>)allCommand.Aliases, (Func<string, string>)null, ", ") + ":\n" + allCommand.Description, ColorByTag(allCommand.Tag)));
}
}
};
}
private static string Colored(string m, string color)
{
return "<color=" + color + ">" + m + "</color>";
}
private static string ColorByTag(CommandTag tag)
{
if (1 == 0)
{
}
string result = tag switch
{
CommandTag.Player => "#dafeffff",
CommandTag.World => "#cfffe9ff",
CommandTag.Console => "#f4e2ffff",
_ => "white",
};
if (1 == 0)
{
}
return result;
}
}
public sealed class SpeedyCommand : CommandBase
{
private static List<string> MovementPerks = new List<string>(17)
{
"Perk_ArmoredPlating", "Perk_ElasticLimbs", "Perk_MetabolicStasis", "Perk_PulseOrgan", "Perk_RabbitDNA", "Perk_SomaticPainkillers", "Perk_SystemReorganization", "Perk_AutotomousSkeleton", "Perk_AdrenalinePumps", "Perk_HeavyStrike",
"Perk_VelocityAugments", "Perk_LatissimusOptimization", "Perk_SteadiedStance", "Perk_Rho_Blessing_Protection", "Perk_Rho_Blessing_Regeneration", "Perk_Rho_Blessing_Swift", "Perk_Rho_Blessing_Overwhelm"
};
public override string[] Aliases => new string[1] { "speedy" };
public override CommandTag Tag => CommandTag.Player;
public override string Description => "get some movement perks";
public override bool CheatsOnly => true;
protected override Action<string[]> GetLogicCallback()
{
return delegate
{
CommandConsoleAccessor.EnsureCheatsAreEnabled();
foreach (string movementPerk in MovementPerks)
{
PerkChanger.MaxOutPerk(movementPerk);
}
};
}
}
}
namespace MoreCommands.Accessors
{
public static class CommandConsoleAccessor
{
private static readonly Action<CommandConsole, string[]> EnableCheatsRaw = AccessTools.MethodDelegate<Action<CommandConsole, string[]>>(AccessTools.Method(typeof(CommandConsole), "EnableCheatsCommand", new Type[1] { typeof(string[]) }, (Type[])null), (object)null, true);
private static readonly Action<CommandConsole, string> AddMessageToHistory = AccessTools.MethodDelegate<Action<CommandConsole, string>>(AccessTools.Method(typeof(CommandConsole), "AddMessageToHistory", new Type[1] { typeof(string) }, (Type[])null), (object)null, true);
private static readonly Action<CommandConsole> CheatsEnabler = delegate(CommandConsole inst)
{
EnableCheatsRaw(inst, new string[1] { "true" });
};
public static void EnsureCheatsAreEnabled()
{
if (!CommandConsole.hasCheated)
{
CommandConsole instance = CommandConsole.instance;
if ((Object)(object)instance == (Object)null)
{
MoreCommandsPlugin.Beep.LogWarning((object)"CommandConsoleAccessor::EnableCheats instance is null");
}
else
{
CheatsEnabler(CommandConsole.instance);
}
}
}
public static void EchoToConsole(string msg)
{
CommandConsole instance = CommandConsole.instance;
if ((Object)(object)instance == (Object)null)
{
MoreCommandsPlugin.Beep.LogWarning((object)"CommandConsoleAccessor::EnableCheats instance is null");
}
else
{
AddMessageToHistory(instance, msg);
}
}
}
}