using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CWAPI;
using CWAPI.Extensions;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MyceliumNetworking;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using Tweaks.Enums;
using Tweaks.Features.BetterConsole;
using Tweaks.Features.Commands.Patches;
using UnityEngine;
using UnityEngine.UIElements;
using Zorro.Core;
using Zorro.Core.CLI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HungryMuttis.Tweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("3.0.2.0")]
[assembly: AssemblyInformationalVersion("3.0.2+99a15519c9e2cdd99069751ff2944f4c9333d44f")]
[assembly: AssemblyProduct("Tweaks")]
[assembly: AssemblyTitle("HungryMuttis.Tweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.0.2.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 Tweaks
{
[ContentWarningPlugin("HungryMuttis.Tweaks", "3.0.2", false)]
[BepInPlugin("HungryMuttis.Tweaks", "Tweaks", "3.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Tweaks : BaseUnityPlugin
{
public const uint MOD_ID = 2389670781u;
private FeatureManager Manager;
public static Tweaks Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static HarmonyPatcher Patcher { get; private set; }
private void Awake()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Patcher = new HarmonyPatcher("HungryMuttis.Tweaks", Logger);
Instance = this;
Manager = new FeatureManager(Logger, ((BaseUnityPlugin)this).Config);
Logger.LogDebug((object)"Hooking...");
Manager.InitializeFeatures(false);
Logger.LogDebug((object)"Finished Hooking!");
Logger.LogInfo((object)"Tweaks v3.0.2 has loaded!");
}
internal static void UnhookAll()
{
Logger.LogDebug((object)"Unhooking...");
Patcher.UnpatchAll();
Logger.LogDebug((object)"Finished Unhooking!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "HungryMuttis.Tweaks";
public const string PLUGIN_NAME = "Tweaks";
public const string PLUGIN_VERSION = "3.0.2";
}
}
namespace Tweaks.Features.ReturnItems
{
public static class ItemInstancePatch
{
private static readonly FieldInfo isHeldField = AccessTools.Field(typeof(ItemInstance), "isHeld") ?? throw new MemberNotFoundException("ItemInstance does not contain a field named 'isHeld'");
private static readonly FieldInfo rigField = AccessTools.Field(typeof(ItemInstance), "rig") ?? throw new MemberNotFoundException("ItemInstance does not contain a field named 'rig'");
private static readonly FieldInfo m_BoughtItemPositionField = AccessTools.Field(typeof(ShopHandler), "m_BoughtItemPosition") ?? throw new MemberNotFoundException("ShopHandler does not contain a field named 'm_BoughtItemPosition'");
private static Transform? m_BoughtItemPosition;
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Assembly-CSharp", "", true, 1);
Tweaks.Patcher.Patch("Update", (System.Type[])null, (string)null, "Update_Postfix", (string)null);
}
public static void Update_Postfix(ItemInstance __instance)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: 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_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Expected O, but got Unknown
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: 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 (!PhotonNetwork.IsMasterClient)
{
return;
}
Rigidbody val = (Rigidbody)rigField.GetValue(__instance);
if (!(bool)isHeldField.GetValue(__instance) && !((Object)(object)val == (Object)null) && !__instance.m_guid.IsNone && (!(val.position.y >= -150f) || !(val.position.y <= 100f)) && PhotonGameLobbyHandler.IsSurface && !((Object)(object)Hospital.instance == (Object)null))
{
if ((Object)(object)m_BoughtItemPosition == (Object)null)
{
m_BoughtItemPosition = (Transform)m_BoughtItemPositionField.GetValue(ShopHandler.Instance);
}
Vector3 position = m_BoughtItemPosition.position;
position.y = 100f;
if (val.position.y > 100f)
{
val.velocity *= -1f;
}
val.position = position;
}
}
}
[Feature(false)]
internal class ReturnItemsFeature : Feature<ReturnItemsFeature>
{
public override ManualLogSource LogSource => Tweaks.Logger;
public override string FeatureName => "ReturnFallenItems";
public override string FeatureDescription => "Returns any items that may have fallen out of the island";
public override void Initialize()
{
ItemInstancePatch.Init();
}
}
}
namespace Tweaks.Features.OxygenSettings
{
[Feature(false)]
internal class OxygenSettingsFeature : Feature<OxygenSettingsFeature>
{
public override ManualLogSource LogSource => Tweaks.Logger;
public override string FeatureName => "OxygenSettings";
public override string FeatureDescription => "Variuos settings related to oxygen";
public ConfigEntry<float> MaxOxygen { get; private set; }
public override void CreateConfig(ConfigSection section)
{
MaxOxygen = section.Bind<float>("MaxOxygen", 500f, "Maximum seconds of oxygen player can have");
}
public override void Initialize()
{
PlayerPatch.Init();
}
}
public static class PlayerPatch
{
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Assembly-CSharp", "", true, 1);
Tweaks.Patcher.Patch("Start", (System.Type[])null, "Start_Prefix", (string)null, (string)null);
}
public static void Start_Prefix(Player __instance)
{
__instance.data.remainingOxygen = Feature<OxygenSettingsFeature>.Instance.MaxOxygen.Value;
}
}
}
namespace Tweaks.Features.DivingBellOxygenRefill
{
[Feature(false)]
internal class DivingBellOxygenRefillFeature : Feature<DivingBellOxygenRefillFeature>
{
public override ManualLogSource LogSource => Tweaks.Logger;
public override string FeatureName => "DivingBellOxygenRefilling";
public override string FeatureDescription => "Refills oxygen when player is in diving bell";
public ConfigEntry<float> RefillRate { get; private set; }
public override void CreateConfig(ConfigSection section)
{
RefillRate = section.Bind<float>("RefillRate", 4f, "How much oxygen is refilled per second while in diving bell");
}
public override void Initialize()
{
PlayerDataPatch.Init();
}
}
public static class PlayerDataPatch
{
internal static void Init()
{
Tweaks.Patcher.SaveInfo(typeof(PlayerData), 1);
Tweaks.Patcher.Patch("UpdateValues", (System.Type[])null, (string)null, "UpdateValues_Postfix", (string)null);
}
public static void UpdateValues_Postfix(PlayerData __instance)
{
if (__instance.isInDiveBell)
{
__instance.remainingOxygen = Mathf.Clamp(__instance.remainingOxygen + Feature<DivingBellOxygenRefillFeature>.Instance.RefillRate.Value * Time.deltaTime, 0f, __instance.maxOxygen);
}
}
}
}
namespace Tweaks.Features.Defib
{
[Feature(false)]
internal class DefibFeature : Feature<DefibFeature>
{
public override ManualLogSource LogSource => Tweaks.Logger;
public override string FeatureName => "Defib";
public override string FeatureDescription => "Restores a configurable amount of oxygen upon revival.";
public ConfigEntry<Setting> Setting { get; private set; }
public ConfigEntry<float> Amount { get; private set; }
public ConfigEntry<global::Tweaks.Enums.Type> Type { get; private set; }
public override void CreateConfig(ConfigSection section)
{
Setting = section.Bind<Setting>("Setting", global::Tweaks.Enums.Setting.cset, "cset: After reviving, if oxygen is less than <Amount> set it to <Amount>\r\nset: After reviving, set the oxygen to <Amount> (no matter if the remaining oxygen was more or less than <Amount>)\r\nadd: After reviving, add <Amount> oxygen (won't give more than 100% of oxygen)");
Amount = section.Bind<float>("Amount", 180f, "Amount of oxygen");
Type = section.Bind<global::Tweaks.Enums.Type>("Type", global::Tweaks.Enums.Type.seconds, "seconds: <Amount> of seconds\r\npercent: <Amount> of percent");
}
public override void Initialize()
{
PlayerPatch.Init();
}
}
public static class PlayerPatch
{
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Assembly-CSharp", "", true, 1);
Tweaks.Patcher.Patch("RPCA_PlayerRevive", (System.Type[])null, "RPCA_PlayerRevive_Prefix", (string)null, (string)null);
}
public static void RPCA_PlayerRevive_Prefix(Player __instance)
{
__instance.data.remainingOxygen = CalculateOxygen(__instance.data.remainingOxygen, __instance.data.maxOxygen);
}
private static float CalculateOxygen(float remainingOxygen, float maxOxygen)
{
DefibFeature instance = Feature<DefibFeature>.Instance;
remainingOxygen = ((remainingOxygen < 0f) ? 0f : remainingOxygen);
float num = ((instance.Type.Value == global::Tweaks.Enums.Type.seconds) ? instance.Amount.Value : (maxOxygen * instance.Amount.Value / 100f));
float num2;
switch (instance.Setting.Value)
{
case Setting.add:
num2 = remainingOxygen + num;
break;
case Setting.cset:
num2 = Mathf.Max(remainingOxygen, num);
break;
case Setting.set:
num2 = num;
break;
default:
Feature<DefibFeature>.Error((object)"Invalid setting: 'Oxygen.Setting'. Review config file.");
num2 = remainingOxygen;
break;
}
return Mathf.Clamp(num2, 0f, maxOxygen);
}
}
}
namespace Tweaks.Features.DeathOxygen
{
[Feature(false)]
internal class DeathOxygenFeature : Feature<DeathOxygenFeature>
{
public override ManualLogSource LogSource => Tweaks.Logger;
public override string FeatureName => "DeathOxygen";
public override string FeatureDescription => "Changes how much oxygen is consumed when the Player is dead.";
public ConfigEntry<float> Consumption { get; private set; }
public override void CreateConfig(ConfigSection section)
{
Consumption = section.Bind<float>("Consumption", 0f, "Changes how much oxygen is consumed when the player is dead\r\nSet this to 0 to turn off oxygen consumption when player is dead");
}
public override void Initialize()
{
PlayerDataPatch.Init();
}
}
public static class PlayerDataPatch
{
internal static void Init()
{
Tweaks.Patcher.SaveInfo(typeof(PlayerData), 1);
Tweaks.Patcher.Patch("UpdateValues", (System.Type[])null, "UpdateValues_Prefix", "UpdateValues_Postfix", (string)null);
}
public static bool UpdateValues_Prefix(PlayerData __instance, out bool __state)
{
__state = __instance.usingOxygen;
if (!__instance.dead)
{
return true;
}
__instance.usingOxygen = false;
return true;
}
public static void UpdateValues_Postfix(PlayerData __instance, bool __state)
{
if (__instance.dead)
{
__instance.usingOxygen = __state;
__instance.remainingOxygen -= Feature<DeathOxygenFeature>.Instance.Consumption.Value * Time.deltaTime;
}
}
}
}
namespace Tweaks.Features.Commands
{
internal class ClientNetworkHandler : SingletonNetworkComponent<ClientNetworkHandler>
{
protected override ManualLogSource LogSource => Tweaks.Logger;
protected override uint MOD_ID => 2389670781u;
[CustomRPC]
private void RPC_SetHealth(float health)
{
All(delegate(Player? p)
{
PlayerManager.SetHealth(p, health);
});
}
public static void SendHealth(float health)
{
SingletonNetworkComponent<ClientNetworkHandler>.Send("RPC_SetHealth", (ReliableType)1, new object[1] { health });
}
[CustomRPC]
private void RPC_SetGravityDirection(Vector3 direction)
{
//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)
All(delegate(Player? p)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
PlayerManager.SetGravityDirection(p, direction);
});
}
public static void SendGravityDirection(Vector3 direction)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
SingletonNetworkComponent<ClientNetworkHandler>.Send("RPC_SetGravityDirection", (ReliableType)1, new object[1] { direction });
}
[CustomRPC]
private void RPC_SetMaxOxygen(float maxOxygen)
{
All(delegate(Player? p)
{
PlayerManager.SetMaxOxygen(p, maxOxygen);
});
}
public static void SendMaxOxygen(float maxOxygen)
{
SingletonNetworkComponent<ClientNetworkHandler>.Send("RPC_SetMaxOxygen", (ReliableType)1, new object[1] { maxOxygen });
}
[CustomRPC]
private void RPC_SetRemainingOxygen(float remainingOxygen, bool percent)
{
All(delegate(Player? p)
{
PlayerManager.SetRemainingOxygen(p, remainingOxygen, percent);
});
}
public static void SendRemainingOxygen(float remainingOxygen, bool percent)
{
SingletonNetworkComponent<ClientNetworkHandler>.Send("RPC_SetRemainingOxygen", (ReliableType)1, new object[2] { remainingOxygen, percent });
}
[CustomRPC]
private void RPC_PlayerConsole(bool enabled)
{
DebugUIHandlerPatch.AllowConsole = enabled;
}
public static void SendConsoleEnabled(Player player, bool enabled)
{
Send("RPC_PlayerConsole", player, (ReliableType)1, enabled);
}
[CustomRPC]
private void RPC_SetGravity(float gravity)
{
PlayerManager.SetGravity(gravity);
}
public static void SendGravity(Player player, float gravity)
{
Send("RPC_SetGravity", player, (ReliableType)1, gravity);
}
public static void SendGravity(float gravity)
{
SingletonNetworkComponent<ClientNetworkHandler>.Send("RPC_SetGravity", (ReliableType)1, new object[1] { gravity });
}
[CustomRPC]
private void RPC_SetPlayerThrowStrengthMultiplier(float multiplier)
{
PlayerPatch.ThrowStrengthMultiplier = multiplier;
}
public static void SendThrowStrengthMultiplier(Player player, float multiplier)
{
Send("RPC_SetPlayerThrowStrengthMultiplier", player, (ReliableType)1, multiplier);
}
public static void SendThrowStrengthMultiplier(float multiplier)
{
SingletonNetworkComponent<ClientNetworkHandler>.Send("RPC_SetPlayerThrowStrengthMultiplier", (ReliableType)1, new object[1] { multiplier });
}
[CustomRPC]
private void RPC_CanRagdoll(bool ragdoll)
{
PlayerRagdoll.RagdollIfFellForLongerThan = (ragdoll ? 1.5f : float.MaxValue);
}
public static void SendCanRagdoll(bool ragdoll)
{
SingletonNetworkComponent<ClientNetworkHandler>.Send("RPC_CanRagdoll", (ReliableType)1, new object[1] { ragdoll });
}
[CustomRPC]
private void RPC_SetMaxHealth(float maxHealth, bool addHealth)
{
PlayerManager.SetMaxHealth(maxHealth, addHealth);
}
public static void SendMaxHealth(float maxHealth, bool addHealth)
{
SingletonNetworkComponent<ClientNetworkHandler>.Send("RPC_SetMaxHealth", (ReliableType)1, new object[2] { maxHealth, addHealth });
}
private static void All(Action<Player?> action)
{
if (PlayerHandler.instance?.players == null)
{
return;
}
foreach (Player player in PlayerHandler.instance.players)
{
action(player);
}
}
private static void Send(string methodName, Player? plr, ReliableType reliable, params object[] parameters)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
CSteamID val = default(CSteamID);
if (plr == null || !PlayerExtensions.TryGetSteamID(plr, ref val))
{
Debug.LogError((object)"Failed to get CSteamID from Player");
}
else
{
SingletonNetworkComponent<ClientNetworkHandler>.Send(methodName, val, reliable, parameters);
}
}
}
[Feature(false)]
internal class CommandsFeature : Feature<CommandsFeature>
{
public override ManualLogSource LogSource => Tweaks.Logger;
public override string FeatureName => "Commands";
public override string FeatureDescription => "Adds various console commands.";
public ConfigEntry<KeyCode> OpenConsoleKey { get; private set; }
public override void CreateConfig(ConfigSection section)
{
OpenConsoleKey = section.Bind<KeyCode>("OpenConsoleKey", (KeyCode)96, "Sets the button to open the console\r\nONLY WORKS WHEN TipeMod IS NOT INSTALLED");
}
public override void Initialize()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
new GameObject("PlayersNetworkHandler", new System.Type[1] { typeof(ClientNetworkHandler) });
BotPatch.Init();
CD_ItemPatch.Init();
PlayerPatch.Init();
UI_HealthPatch.Init();
if (!Chainloader.PluginInfos.ContainsKey("Tipe.TipeMod"))
{
DebugUIHandlerPatch.Init();
}
}
}
public static class DebugUIHandlerPatch
{
internal static bool AllowConsole;
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Zorro.Core.Runtime", "Zorro.Core.CLI", true, 1);
Tweaks.Patcher.Patch("Update", (System.Type[])null, (string)null, "Update_Postfix", (string)null);
}
public static void Update_Postfix(DebugUIHandler __instance)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
if (!Input.GetKeyDown(Feature<CommandsFeature>.Instance.OpenConsoleKey.Value))
{
return;
}
if (__instance.IsOpen)
{
__instance.Hide();
}
else if (PhotonNetwork.InRoom && (PhotonNetwork.IsMasterClient || AllowConsole))
{
if (PhotonNetwork.CurrentRoom.IsOpen)
{
Debug.LogError((object)"Using commands before starting the game can lead to desyncs and weird issues");
}
__instance.Show();
}
}
}
public static class PlayerManager
{
public static void SetGravity(float gravity)
{
if (!((Object)(object)Player.localPlayer?.refs?.controller == (Object)null))
{
Player.localPlayer.refs.controller.gravity = gravity;
}
}
public static void SetHealth(Player? player, float health)
{
if (player?.data != null)
{
player.data.health = health;
}
}
public static void SetGravityDirection(Player? player, Vector3 direction)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
if (player?.data != null)
{
player.data.gravityDirection = direction;
}
}
public static void SetMaxOxygen(Player? player, float maxOxygen)
{
if (player?.data != null)
{
player.data.maxOxygen = maxOxygen;
}
}
public static void SetRemainingOxygen(Player? player, float remainingOxygen, bool percent)
{
if (player?.data != null)
{
player.data.remainingOxygen = (percent ? (player.data.maxOxygen * remainingOxygen / 100f) : remainingOxygen);
}
}
public static void SetMaxHealth(float maxHealth, bool addHealth)
{
float healthAdded = maxHealth - PlayerData.maxHealth;
healthAdded = ((healthAdded < 0f) ? 0f : healthAdded);
PlayerData.maxHealth = maxHealth;
All(delegate(Player? p)
{
if (p?.data != null)
{
p.data.health = Mathf.Clamp(addHealth ? (healthAdded + p.data.health) : p.data.health, 0f, maxHealth);
}
});
}
private static void All(Action<Player?> action)
{
if (PlayerHandler.instance?.players == null)
{
return;
}
foreach (Player player in PlayerHandler.instance.players)
{
action(player);
}
}
}
internal class PlayerNetworkHandler : NetworkComponent<PlayerNetworkHandler, Player>
{
protected override ManualLogSource LogSource => Tweaks.Logger;
protected override uint MOD_ID => 2389670781u;
[CustomRPC]
private void RPC_SetPlayerHealth(float health)
{
PlayerManager.SetHealth(base.ParentComponent, health);
}
public static void SendHealth(Player targetPlayer, float health)
{
NetworkComponent<PlayerNetworkHandler, Player>.Send(targetPlayer, "RPC_SetPlayerHealth", (ReliableType)1, new object[1] { health });
}
[CustomRPC]
private void RPC_SetPlayerGravityDirection(Vector3 direction)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
PlayerManager.SetGravityDirection(base.ParentComponent, direction);
}
public static void SendGravityDirection(Player targetPlayer, Vector3 direction)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
NetworkComponent<PlayerNetworkHandler, Player>.Send(targetPlayer, "RPC_SetPlayerGravityDirection", (ReliableType)1, new object[1] { direction });
}
[CustomRPC]
private void RPC_SetPlayerMaxOxygen(float maxOxygen)
{
PlayerManager.SetMaxOxygen(base.ParentComponent, maxOxygen);
}
public static void SendMaxOxygen(Player targetPlayer, float maxOxygen)
{
NetworkComponent<PlayerNetworkHandler, Player>.Send(targetPlayer, "RPC_SetPlayerMaxOxygen", (ReliableType)1, new object[1] { maxOxygen });
}
[CustomRPC]
private void RPC_SetPlayerRemainingOxygen(float remainingOxygen)
{
PlayerManager.SetRemainingOxygen(base.ParentComponent, remainingOxygen, percent: false);
}
public static void SendRemainingOxygen(Player targetPlayer, float remainingOxygen)
{
NetworkComponent<PlayerNetworkHandler, Player>.Send(targetPlayer, "RPC_SetPlayerRemainingOxygen", (ReliableType)1, new object[1] { remainingOxygen });
}
}
[TypeParser(typeof(Vector3))]
public class TypeParsers : CLITypeParser
{
private const NumberStyles Style = NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent;
private static readonly SortedDictionary<string, Vector3> Constants = new SortedDictionary<string, Vector3>
{
{
"Back",
Vector3.back
},
{
"Down",
Vector3.down
},
{
"Forward",
Vector3.forward
},
{
"Left",
Vector3.left
},
{
"One",
Vector3.one
},
{
"Right",
Vector3.right
},
{
"Up",
Vector3.up
},
{
"Zero",
Vector3.zero
}
};
public override List<ParameterAutocomplete> FindAutocomplete(string parameterText)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Expected O, but got Unknown
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Expected O, but got Unknown
List<ParameterAutocomplete> list = ((parameterText == "") ? new List<ParameterAutocomplete>(1)
{
new ParameterAutocomplete("0")
} : new List<ParameterAutocomplete>());
foreach (KeyValuePair<string, Vector3> constant in Constants)
{
if (constant.Key.StartsWith(parameterText))
{
list.Add(new ParameterAutocomplete(constant.Key));
}
else if (string.Compare(constant.Key, parameterText) > 0)
{
break;
}
}
if (list.Count > 0)
{
return list;
}
parameterText = parameterText.Replace(',', '.');
string autocomplete = GetAutocomplete(parameterText);
if (autocomplete == null)
{
return new List<ParameterAutocomplete>();
}
return new List<ParameterAutocomplete>(1)
{
new ParameterAutocomplete(autocomplete)
};
}
public override object Parse(string str)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
if (Constants.TryGetValue(str, out var value))
{
return value;
}
str = str.Replace(",", ".");
string[] array = str.Split(';');
if (array.Length != 3)
{
throw new ArgumentException("Wrong number of axies", "str");
}
float[] array2 = new float[3];
for (int i = 0; i < 3; i++)
{
if (!float.TryParse(array[i], NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out array2[i]))
{
throw new ArgumentException("Cannot parse floats", "str");
}
}
return (object)new Vector3(array2[0], array2[1], array2[2]);
}
private static string? GetAutocomplete(string parameterText)
{
string[] array = parameterText.Split(';');
bool prevb = false;
if (array.Length > 3 || array.Any(delegate(string s)
{
if (prevb)
{
return true;
}
if (s == "" || s == "-")
{
prevb = true;
return false;
}
float result;
return !float.TryParse(s, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out result);
}))
{
return null;
}
if (array.Last().Length == 0 || array.Last() == "-")
{
return new string(parameterText + "0");
}
if (array.Length != 3)
{
return new string(parameterText + ";");
}
return new string(parameterText);
}
}
}
namespace Tweaks.Features.Commands.Patches
{
public static class BotPatch
{
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Assembly-CSharp", "", true, 1);
Tweaks.Patcher.Patch("Patrol", new System.Type[6]
{
typeof(bool),
typeof(bool),
typeof(float),
typeof(bool),
typeof(Vector3),
typeof(bool)
}, "Patrol_Prefix", (string)null, (string)null);
Tweaks.Patcher.Patch("WalkAway", new System.Type[1] { typeof(Vector3) }, "Walk_Prefix", (string)null, (string)null);
}
public static bool Patrol_Prefix(Bot __instance, ref bool __result)
{
if ((Object)(object)Level.currentLevel != (Object)null)
{
return true;
}
__result = false;
__instance.patrolPoint = null;
return false;
}
public static bool Walk_Prefix(Bot __instance)
{
if ((Object)(object)Level.currentLevel != (Object)null)
{
return true;
}
__instance.patrolPoint = null;
return false;
}
}
public static class CD_ItemPatch
{
private static readonly FieldInfo machineField = AccessTools.Field(typeof(CD_Item), "machine");
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Assembly-CSharp", "", true, 1);
Tweaks.Patcher.Patch("Update", (System.Type[])null, "Update_Prefix", (string)null, (string)null);
}
public static bool Update_Prefix(CD_Item __instance)
{
if (machineField.GetValue(__instance) != null)
{
return true;
}
return false;
}
}
public static class PlayerPatch
{
public static float ThrowStrengthMultiplier = 1f;
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Assembly-CSharp", "", true, 1);
Tweaks.Patcher.Patch("RequestCreatePickup", new System.Type[6]
{
typeof(byte),
typeof(ItemInstanceData),
typeof(Vector3),
typeof(Quaternion),
typeof(Vector3),
typeof(Vector3)
}, "RequestCreatePickup_Prefix", (string)null, (string)null);
Tweaks.Patcher.Patch("Start", (System.Type[])null, (string)null, "Start_Postfix", (string)null);
}
public static void RequestCreatePickup_Prefix(ref Vector3 vel)
{
//IL_0002: 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_0011: Unknown result type (might be due to invalid IL or missing references)
vel *= ThrowStrengthMultiplier;
}
public static void Start_Postfix(Player __instance)
{
if (!__instance.ai && (Object)(object)((Component)__instance).gameObject.GetComponent<PlayerNetworkHandler>() == (Object)null)
{
((Component)__instance).gameObject.AddComponent<PlayerNetworkHandler>();
}
}
}
public static class UI_HealthPatch
{
[CompilerGenerated]
private sealed class <Update_Transpiler>d__1 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable
{
private int <>1__state;
private CodeInstruction <>2__current;
private int <>l__initialThreadId;
private IEnumerable<CodeInstruction> instructions;
public IEnumerable<CodeInstruction> <>3__instructions;
private IEnumerator<CodeInstruction> <>7__wrap1;
CodeInstruction IEnumerator<CodeInstruction>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Update_Transpiler>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || (uint)(num - 1) <= 1u)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<>7__wrap1 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Expected O, but got Unknown
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>7__wrap1 = instructions.GetEnumerator();
<>1__state = -3;
break;
case 1:
<>1__state = -3;
break;
case 2:
<>1__state = -3;
break;
}
if (<>7__wrap1.MoveNext())
{
CodeInstruction current = <>7__wrap1.Current;
if (current.opcode == OpCodes.Ldc_R4 && (float)current.operand == 100f)
{
<>2__current = new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(PlayerData), "maxHealth"));
<>1__state = 1;
return true;
}
<>2__current = current;
<>1__state = 2;
return true;
}
<>m__Finally1();
<>7__wrap1 = null;
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap1 != null)
{
<>7__wrap1.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
{
<Update_Transpiler>d__1 <Update_Transpiler>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<Update_Transpiler>d__ = this;
}
else
{
<Update_Transpiler>d__ = new <Update_Transpiler>d__1(0);
}
<Update_Transpiler>d__.instructions = <>3__instructions;
return <Update_Transpiler>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
}
}
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Assembly-CSharp", "", true, 1);
Tweaks.Patcher.Patch("Update", (System.Type[])null, (string)null, (string)null, "Update_Transpiler");
}
[IteratorStateMachine(typeof(<Update_Transpiler>d__1))]
public static IEnumerable<CodeInstruction> Update_Transpiler(IEnumerable<CodeInstruction> instructions)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <Update_Transpiler>d__1(-2)
{
<>3__instructions = instructions
};
}
}
}
namespace Tweaks.Features.Commands.Classes
{
internal class Console : ICommandsClass
{
public static bool Enabled => ((Feature<CommandsFeature>)(object)Feature<CommandsFeature>.Instance).Enabled;
[ConsoleCommand("Disables console for the specified player", new string[] { })]
public static void Disable(Player Player)
{
ClientNetworkHandler.SendConsoleEnabled(Player, enabled: false);
}
[ConsoleCommand("Enables console for the specified player", new string[] { })]
public static void Enable(Player Player)
{
ClientNetworkHandler.SendConsoleEnabled(Player, enabled: true);
}
}
public class Player : ICommandsClass
{
public static bool Enabled => ((Feature<CommandsFeature>)(object)Feature<CommandsFeature>.Instance).Enabled;
[ConsoleCommand("Heals the specified player specified amount", new string[] { "", "Amount to heal", "Is amount percent" })]
public static void Heal(Player Player, float Value, bool Percent = false)
{
if (!((Object)(object)Player.refs?.view == (Object)null))
{
Player.refs.view.RPC("RPCA_Heal", (RpcTarget)0, new object[1] { Percent ? (PlayerData.maxHealth * Value / 100f) : Value });
}
}
[ConsoleCommand("Sets the gravity for the specified player", new string[] { "", "Amount of gravity" })]
public static void SetGravity(Player Player, float Value)
{
ClientNetworkHandler.SendGravity(Player, Value);
}
public static void SetGravityDirection(Player Player, Vector3 Direction)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
PlayerNetworkHandler.SendGravityDirection(Player, Direction);
}
[ConsoleCommand("Sets the health for the specified player", new string[] { "", "Amount of health", "Is amount percent" })]
public static void SetHealth(Player Player, float Value, bool Percent = false)
{
PlayerNetworkHandler.SendHealth(Player, Percent ? (PlayerData.maxHealth * Value / 100f) : Value);
}
[ConsoleCommand("Sets the max oxygen for the specified player", new string[] { "", "Amount of oxygen" })]
public static void SetMaxOxygen(Player Player, float Value)
{
PlayerNetworkHandler.SendMaxOxygen(Player, Value);
}
[ConsoleCommand("Sets the remaining oxygen for the specified player", new string[] { "", "Amount of oxygen", "Is amount percent" })]
public static void SetRemainingOxygen(Player Player, float Value, bool Percent = false)
{
PlayerNetworkHandler.SendRemainingOxygen(Player, Percent ? (Player.data.maxOxygen * Value / 100f) : Value);
}
[ConsoleCommand("Sets the throw strength multiplier for the specified player", new string[] { "", "Times to multiply the throw strength" })]
public static void SetThrowStrengthMultiplier(Player Player, float Multiplier)
{
ClientNetworkHandler.SendThrowStrengthMultiplier(Player, Multiplier);
}
}
public class Players : ICommandsClass
{
public static bool Enabled => ((Feature<CommandsFeature>)(object)Feature<CommandsFeature>.Instance).Enabled;
public static void CanRagdoll(bool Ragdoll)
{
ClientNetworkHandler.SendCanRagdoll(Ragdoll);
}
[ConsoleCommand("Heals all of the players the specified amount", new string[] { "Amount to heal", "Is amount percent" })]
public static void Heal(float Value, bool Percent = false)
{
if (PlayerHandler.instance?.players == null)
{
return;
}
foreach (Player player in PlayerHandler.instance.players)
{
if (!((Object)(object)player?.refs?.view == (Object)null))
{
player.refs.view.RPC("RPCA_Heal", (RpcTarget)0, new object[1] { Percent ? (PlayerData.maxHealth * Value / 100f) : Value });
}
}
}
[ConsoleCommand("Sets the gravity for all players", new string[] { "Amount of gravity" })]
public static void SetGravity(float Value)
{
ClientNetworkHandler.SendGravity(Value);
}
public static void SetGravityDirection(Vector3 Direction)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
ClientNetworkHandler.SendGravityDirection(Direction);
}
[ConsoleCommand("Sets the health for all players", new string[] { "Amount of health", "Is amount percent" })]
public static void SetHealth(float Value, bool Percent = false)
{
ClientNetworkHandler.SendHealth(Percent ? (PlayerData.maxHealth * Value / 100f) : Value);
}
[ConsoleCommand("Sets the max oxygen for all of the players", new string[] { "Amount of oxygen" })]
public static void SetMaxOxygen(float Value)
{
ClientNetworkHandler.SendMaxOxygen(Value);
}
[ConsoleCommand("Sets the remaining oxygen for all of the players", new string[] { "Amount of oxygen", "Is amount percent (calculated individually)" })]
public static void SetRemainingOxygen(float Value, bool Percent = false)
{
ClientNetworkHandler.SendRemainingOxygen(Value, Percent);
}
[ConsoleCommand("Sets the throw strength multiplier for the specified player", new string[] { "Times to multiply the throw strength" })]
public static void SetThrowStrengthMultiplier(float Multiplier)
{
ClientNetworkHandler.SendThrowStrengthMultiplier(Multiplier);
}
[ConsoleCommand("Sets max health for all players to the specified value", new string[] { "Max health", "Heal the player" })]
public static void SetMaxHealth(float Value, bool AddHealth = false)
{
ClientNetworkHandler.SendMaxHealth(Value, AddHealth);
}
}
}
namespace Tweaks.Features.BetterConsole
{
[Feature(true)]
internal class BetterConsoleFeature : Feature<BetterConsoleFeature>
{
public override ManualLogSource LogSource => Tweaks.Logger;
public override bool Required => true;
public override string FeatureName => "BetterConsole";
public override string FeatureDescription => "Enables the console and makes it better (for the devs mostly)";
public override void Initialize()
{
ConsoleHandlerPatch.Init();
CommandSuggestionPatch.Init();
ConsolePagePatch.Init();
}
}
public static class CommandSuggestionPatch
{
private static ConsoleCommand[]? ConsoleCommands;
private static readonly FieldInfo SelectedParameterIndexField = AccessTools.Field(typeof(CommandSuggestion), "selectedParameterIndex");
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Zorro.Core.Runtime", "Zorro.Core.CLI", true, 1);
Tweaks.Patcher.Patch("GetDisplayTextWithMaxParameter", (System.Type[])null, "GetDisplayTextWithMaxParameter_Prefix", (string)null, (string)null);
}
public static bool GetDisplayTextWithMaxParameter_Prefix(CommandSuggestion __instance, int maxParameterIndex, bool color, ref string __result)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
CommandSuggestion __instance2 = __instance;
if (ConsoleCommands == null)
{
ConsoleCommands = (ConsoleCommand[])AccessTools.Field(typeof(ConsoleHandler), "m_consoleCommands").GetValue(null);
}
if (ConsoleCommands == null)
{
return true;
}
ConsoleCommand val = ((IEnumerable<ConsoleCommand>)ConsoleCommands).FirstOrDefault((Func<ConsoleCommand, bool>)((ConsoleCommand c) => c.DomainName == __instance2.Domain && c.Command == __instance2.Command));
if (val.MethodInfo == null)
{
return true;
}
ConsoleCommandAttribute consoleCommandAttribute = val.MethodInfo?.GetCustomAttribute<ConsoleCommandAttribute>();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < __instance2.ParameterInfos.Length && i < maxParameterIndex; i++)
{
ParameterInfo parameterInfo = __instance2.ParameterInfos[i];
bool flag = i == (int)SelectedParameterIndexField.GetValue(__instance2);
string text = ((flag && consoleCommandAttribute?.Arguments != null && i < consoleCommandAttribute.Arguments.Length && !string.IsNullOrEmpty(consoleCommandAttribute.Arguments[i])) ? consoleCommandAttribute.Arguments[i] : parameterInfo.Name);
if (color)
{
stringBuilder.Append(flag ? "<color=#ffffff>" : "<color=#cccaca>");
}
string text2 = text + " (" + parameterInfo.ParameterType.Name + (parameterInfo.IsOptional ? $" = {parameterInfo.DefaultValue}" : "") + ")";
stringBuilder.Append(parameterInfo.IsOptional ? (" [" + text2 + "]") : (" <" + text2 + ">"));
}
string text3 = __instance2.FullCommand;
if (color)
{
text3 = "<color=#cccaca>" + text3;
}
__result = text3 + stringBuilder.ToString();
return false;
}
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class ConsoleCommandAttribute : Attribute
{
public string Description { get; }
public string[] Arguments { get; }
public ConsoleCommandAttribute(string description, params string[] arguments)
{
Description = description;
Arguments = arguments;
base..ctor();
}
}
public static class ConsoleHandlerPatch
{
private class AmbiguityContext
{
public readonly List<ConsoleCommand> Overloads;
public readonly List<string> Arguments;
public AmbiguityContext(List<ConsoleCommand> overloads, List<string> arguments)
{
Overloads = overloads;
Arguments = arguments;
base..ctor();
}
}
private static AmbiguityContext? _ambiguityContext;
private static Dictionary<System.Type, CLITypeParser> Parsers = new Dictionary<System.Type, CLITypeParser>();
private static readonly MethodInfo ConvertMethod = AccessTools.Method(typeof(ConsoleHandler), "ConvertParameter", (System.Type[])null, (System.Type[])null);
private static ConsoleCommand[] ConsoleCommands = null;
private static readonly Dictionary<MethodInfo, ConsoleCommandAttribute?> Attributes = new Dictionary<MethodInfo, ConsoleCommandAttribute>();
private const string HelpCommand = "Help";
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Zorro.Core.Runtime", "Zorro.Core.CLI", true, 1);
Tweaks.Patcher.Patch("Initialize", (System.Type[])null, (string)null, "Initialize_Postfix", (string)null);
Tweaks.Patcher.Patch("ProcessCommand", (System.Type[])null, "ProcessCommand_Override", (string)null, (string)null);
Tweaks.Patcher.Patch("FindSuggestions", (System.Type[])null, "FindSuggestions_Override", (string)null, (string)null);
}
public static void Initialize_Postfix()
{
//IL_0060: 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_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
FieldInfo fieldInfo = AccessTools.Field(typeof(ConsoleHandler), "m_consoleCommands");
Feature<BetterConsoleFeature>.Debug((object)"Searching for custom commands...");
List<MethodInfo> list = FindCustomCommands();
if (list.Count == 0)
{
Feature<BetterConsoleFeature>.Debug((object)"No custom commands found.");
return;
}
List<ConsoleCommand> list2 = ((ConsoleCommand[])fieldInfo.GetValue(null)).ToList();
Attributes.Clear();
foreach (ConsoleCommand item in list2)
{
Attributes[item.MethodInfo] = null;
}
int num = 0;
foreach (MethodInfo item2 in list)
{
System.Type declaringType = item2.DeclaringType;
if (declaringType == null)
{
continue;
}
bool flag = false;
if (!typeof(ICommandsClass).IsAssignableFrom(declaringType))
{
flag = true;
}
else
{
PropertyInfo property = declaringType.GetProperty("Enabled", BindingFlags.Static | BindingFlags.Public);
if (property != null && (bool)property.GetValue(null))
{
flag = true;
}
}
if (flag)
{
list2.Add(new ConsoleCommand(item2));
Attributes[item2] = item2.GetCustomAttribute<ConsoleCommandAttribute>();
num++;
}
}
fieldInfo.SetValue(null, list2.ToArray());
ConsoleCommands = (ConsoleCommand[])fieldInfo.GetValue(null);
Feature<BetterConsoleFeature>.Debug((object)$"Added {num} new commands. Total commands: {list2.Count}");
Parsers = (Dictionary<System.Type, CLITypeParser>)AccessTools.Field(typeof(ConsoleHandler), "m_typeParsers").GetValue(null);
}
public static bool ProcessCommand_Override(string command, ref bool __result)
{
if (HandleAmbiguity(command, ref __result))
{
return false;
}
if (command.Equals("Help", StringComparison.OrdinalIgnoreCase) || command.TrimEnd().Equals("Help.Help", StringComparison.OrdinalIgnoreCase))
{
return HandleHelpCommand(ref __result);
}
_ambiguityContext = null;
string[] array = StringUtility.SplitOnFirstOfChar(command, '.');
if (array == null)
{
__result = false;
return false;
}
string domain = array[0];
string text = array[1].TrimEnd();
string commandName = text.Split(' ').First();
object obj;
int lastStart;
if (!text.Contains(' '))
{
obj = "";
}
else
{
string text2 = text;
lastStart = commandName.Length;
obj = text2.Substring(lastStart, text2.Length - lastStart).Trim();
}
string argumentString = (string)obj;
bool next;
List<string> providedArgs = ParseArguments(argumentString, out next, out lastStart);
if (commandName.Equals("Help", StringComparison.OrdinalIgnoreCase))
{
return HandleHelpCommand(ref __result, domain);
}
List<ConsoleCommand> list = ConsoleCommands.Where((ConsoleCommand c) => c.DomainName == domain && c.Command == commandName).ToList();
if (list.Count == 0)
{
__result = false;
return false;
}
return HandleCommandExecution(FindValidCmds(list, providedArgs), providedArgs, commandName, ref __result);
}
public static bool FindSuggestions_Override(string input, ref List<Suggestion> __result)
{
if (__result == null)
{
__result = new List<Suggestion>();
}
if (string.IsNullOrEmpty(input))
{
return false;
}
string[] array = StringUtility.SplitOnFirstOfChar(input, ' ');
bool next = false;
int lastStart = -1;
string domain;
string command;
int level;
List<string> args;
if (array == null)
{
GetCommand(input, out domain, out command);
level = ((command != null) ? 1 : 0);
args = new List<string>();
}
else
{
GetCommand(array[0], out domain, out command);
level = 2;
args = ParseArguments(array[1], out next, out lastStart);
}
FindCommandSuggestions(domain, command, args, next, level, ref __result);
AddParameterSuggestions(input, command, args, next, lastStart, level, ref __result);
return false;
}
private static void FindCommandSuggestions(string domain, string? command, List<string>? args, bool next, int level, ref List<Suggestion> __result)
{
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Expected O, but got Unknown
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Expected O, but got Unknown
//IL_0227: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
//IL_02ee: Expected O, but got Unknown
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
string domain2 = domain;
string command2 = command;
if (level == 0)
{
__result = ((IEnumerable<Suggestion>)(from d in ConsoleCommands.Select((ConsoleCommand c) => c.DomainName).Distinct()
where d.Contains(domain2, StringComparison.OrdinalIgnoreCase)
select d).Select((Func<string, DomainSuggestion>)((string d) => new DomainSuggestion(d)))).ToList();
if ("Help".Contains(domain2, StringComparison.OrdinalIgnoreCase) && !__result.Any((Suggestion s) => ((DomainSuggestion)(((s is DomainSuggestion) ? s : null)?)).Domain.Equals("Help", StringComparison.OrdinalIgnoreCase) ?? false))
{
__result.Add((Suggestion)new DomainSuggestion("Help"));
}
return;
}
HashSet<ConsoleCommand> hashSet = new HashSet<ConsoleCommand>();
foreach (ConsoleCommand item in ConsoleCommands.Where((ConsoleCommand c) => c.DomainName == domain2))
{
hashSet.Add(item);
}
HashSet<ConsoleCommand> hashSet2 = hashSet;
if (hashSet2.Count == 0)
{
return;
}
if (level == 1)
{
__result = ((IEnumerable<Suggestion>)hashSet2.Where((ConsoleCommand c) => c.Command.StartsWith(command2)).Select((Func<ConsoleCommand, CommandSuggestion>)((ConsoleCommand c) => new CommandSuggestion(c.DomainName, c.Command, c.ParameterInfo)))).ToList();
if ("Help".Contains(command2, StringComparison.OrdinalIgnoreCase) && !__result.Any((Suggestion s) => ((CommandSuggestion)(((s is CommandSuggestion) ? s : null)?)).Command.Equals("Help", StringComparison.OrdinalIgnoreCase) ?? false))
{
__result.Add((Suggestion)new CommandSuggestion(domain2, "Help", Array.Empty<ParameterInfo>()));
}
return;
}
HashSet<ConsoleCommand> hashSet3 = new HashSet<ConsoleCommand>();
foreach (ConsoleCommand item2 in hashSet2.Where((ConsoleCommand c) => c.MethodInfo.Name == command2 && c.ParameterInfo.Length != 0))
{
hashSet3.Add(item2);
}
hashSet2 = hashSet3;
foreach (ConsoleCommand item3 in hashSet2)
{
if ((next && item3.ParameterInfo.Length <= args.Count) || item3.ParameterInfo.Length < args.Count)
{
continue;
}
bool flag = true;
for (int i = 0; i < args.Count; i++)
{
object value;
if (i == args.Count - 1 && !next)
{
if (!PossibleArgument(args[i], item3.ParameterInfo[i].ParameterType))
{
flag = false;
break;
}
}
else if (!TryConvertParameter(args[i], item3.ParameterInfo[i].ParameterType, out value))
{
flag = false;
break;
}
}
if (flag)
{
__result.Add((Suggestion)new CommandSuggestion(item3.DomainName, item3.Command, item3.ParameterInfo));
}
}
}
private static void AddParameterSuggestions(string input, string? command, List<string>? args, bool next, int lastStart, int level, ref List<Suggestion> __result)
{
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Expected O, but got Unknown
switch (level)
{
case 0:
return;
case 1:
if (!next)
{
return;
}
break;
}
if (args == null)
{
args = new List<string>();
}
string carg = "";
int num;
if (next)
{
num = args.Count;
}
else if (args.Count > 0)
{
num = args.Count - 1;
carg = args[num];
}
else
{
num = 0;
}
string text = (next ? input : input.Substring(0, StringUtility.SplitOnFirstOfChar(input, ' ')[0].Length + 1 + lastStart));
HashSet<string> hashSet = new HashSet<string>();
for (int num2 = __result.Count - 1; num2 >= 0; num2--)
{
Suggestion obj = __result[num2];
CommandSuggestion val = (CommandSuggestion)(object)((obj is CommandSuggestion) ? obj : null);
if (val == null || !val.Command.Equals(command, StringComparison.OrdinalIgnoreCase) || val.ParameterInfos.Length <= num)
{
continue;
}
val.HighlightParameter(num);
ParameterInfo parameterInfo = val.ParameterInfos[num];
List<ParameterAutocomplete> list;
if (Parsers.TryGetValue(parameterInfo.ParameterType, out CLITypeParser value))
{
list = value.FindAutocomplete(carg);
}
else
{
if (!parameterInfo.ParameterType.IsEnum)
{
continue;
}
list = (from s in Enum.GetNames(parameterInfo.ParameterType)
where s.StartsWith(carg)
select s).Select((Func<string, ParameterAutocomplete>)((string s) => new ParameterAutocomplete(s))).ToList();
}
string displayTextWithMaxParameter = val.GetDisplayTextWithMaxParameter(num, false);
foreach (ParameterAutocomplete item in list)
{
if (hashSet.Add(item.Value))
{
__result.Add((Suggestion)new ParameterSuggestion(displayTextWithMaxParameter, text, item.Value));
}
}
}
}
private static bool HandleAmbiguity(string command, ref bool result)
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
if (!int.TryParse(command, out var result2) || result2 <= 0)
{
return false;
}
result = true;
if (_ambiguityContext == null)
{
ConsoleError("No ambiguous command to resolve. Enter a full command.");
return true;
}
int num = result2 - 1;
if (num >= _ambiguityContext.Overloads.Count)
{
ConsoleError($"Invalid selection. Enter a number between 1 and {_ambiguityContext.Overloads.Count}");
return true;
}
ExecuteCommand(_ambiguityContext.Overloads[num], _ambiguityContext.Arguments);
_ambiguityContext = null;
return true;
}
private static bool HandleCommandExecution(List<ConsoleCommand> validCmds, List<string> providedArgs, string commandName, ref bool result)
{
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: 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_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
if (validCmds.Count == 0)
{
ConsoleError("Error: No overload for '" + commandName + "' matches the provided argument types.");
result = true;
return false;
}
if (validCmds.Count > 1)
{
_ambiguityContext = new AmbiguityContext(validCmds, providedArgs);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine($"Ambiguous command. {validCmds.Count} overloads match the arguments.");
stringBuilder.Append("Enter the number of the command you want to execute:");
for (int i = 0; i < validCmds.Count; i++)
{
ConsoleCommand val = validCmds[i];
stringBuilder.AppendLine();
stringBuilder.Append($" {i + 1}: {val.Command}(");
stringBuilder.Append(string.Join(", ", val.ParameterInfo.Select((ParameterInfo p) => p.ParameterType.Name + " " + p.Name)));
stringBuilder.Append(")");
}
ConsoleError(stringBuilder.ToString());
result = true;
return false;
}
ExecuteCommand(validCmds[0], providedArgs);
result = true;
return false;
}
private static bool PossibleArgument(string arg, System.Type paramType)
{
string arg2 = arg;
if (string.IsNullOrEmpty(arg2))
{
return true;
}
if (paramType == typeof(string))
{
return true;
}
float result;
if (paramType == typeof(float))
{
return float.TryParse(arg2, NumberStyles.Any, CultureInfo.InvariantCulture, out result);
}
int result2;
if (paramType == typeof(int))
{
return int.TryParse(arg2, out result2);
}
if (Parsers.TryGetValue(paramType, out CLITypeParser value))
{
return value.FindAutocomplete(arg2).Any();
}
if (paramType.IsEnum)
{
return Enum.GetNames(paramType).Any((string n) => n.StartsWith(arg2));
}
return true;
}
private static List<ConsoleCommand> FindValidCmds(List<ConsoleCommand> candidates, List<string> providedArgs)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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)
List<string> providedArgs2 = providedArgs;
List<ConsoleCommand> list = new List<ConsoleCommand>();
foreach (ConsoleCommand candidate in candidates)
{
if (providedArgs2.Count >= candidate.ParameterInfo.Count((ParameterInfo p) => !p.IsOptional) && providedArgs2.Count <= candidate.ParameterInfo.Length && Enumerable.Range(0, providedArgs2.Count).All((int i) => TryConvertParameter(providedArgs2[i], candidate.ParameterInfo[i].ParameterType, out object _)))
{
list.Add(candidate);
}
}
return list;
}
private static void ExecuteCommand(ConsoleCommand command, List<string> providedArgs)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
ParameterInfo[] parameterInfo = command.ParameterInfo;
object[] array = new object[parameterInfo.Length];
for (int i = 0; i < parameterInfo.Length; i++)
{
if (i < providedArgs.Count)
{
if (!TryConvertParameter(providedArgs[i], parameterInfo[i].ParameterType, out object value))
{
ConsoleError("Failed to convert argument '" + providedArgs[i] + "' to type " + parameterInfo[i].ParameterType.Name + ".");
return;
}
array[i] = value;
}
else
{
array[i] = parameterInfo[i].DefaultValue;
}
}
try
{
command.MethodInfo.Invoke(null, array);
}
catch (Exception ex)
{
ConsoleError("Failed to execute command: " + (ex.InnerException ?? ex).ToString());
}
}
private static bool TryConvertParameter(string arg, System.Type type, [NotNullWhen(true)] out object? value)
{
if (type.IsEnum && !Parsers.ContainsKey(type))
{
if (Enum.TryParse(type, arg, ignoreCase: false, out value))
{
return true;
}
value = null;
return false;
}
try
{
value = ConvertMethod.Invoke(null, new object[2] { arg, type });
if (value is Exception)
{
value = null;
return false;
}
return true;
}
catch
{
value = null;
return false;
}
}
private static List<string> ParseArguments(string argumentString, out bool next, out int lastStart)
{
next = false;
lastStart = 0;
List<string> list = new List<string>();
if (string.IsNullOrWhiteSpace(argumentString))
{
return list;
}
StringBuilder stringBuilder = new StringBuilder();
bool flag = false;
int num = 0;
for (int i = 0; i < argumentString.Length; i++)
{
char c = argumentString[i];
switch (c)
{
case '\\':
next = false;
if (i + 1 < argumentString.Length)
{
stringBuilder.Append(argumentString[i + 1]);
i++;
}
else
{
stringBuilder.Append(c);
}
continue;
case '"':
flag = !flag;
if (!flag && stringBuilder.Length == 0 && i > num)
{
list.Add("");
num = i + 1;
}
next = false;
continue;
case ' ':
if (!flag)
{
lastStart = num;
num = i + 1;
list.Add(stringBuilder.ToString());
stringBuilder.Clear();
next = true;
continue;
}
break;
}
if (next)
{
lastStart = num;
}
next = false;
stringBuilder.Append(c);
}
if (stringBuilder.Length > 0)
{
list.Add(stringBuilder.ToString());
}
return list;
}
private static void GetCommand(string info, out string domain, out string? command)
{
string[] array = StringUtility.SplitOnFirstOfChar(info, '.');
if (array == null)
{
domain = info;
command = null;
}
else
{
domain = array[0];
command = array[1];
}
}
private static List<MethodInfo> FindCustomCommands()
{
List<MethodInfo> list = new List<MethodInfo>();
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
try
{
list.AddRange(from m in ((IEnumerable<System.Type>)assembly.GetTypes()).SelectMany((Func<System.Type, IEnumerable<MethodInfo>>)AccessTools.GetDeclaredMethods)
where m.GetCustomAttribute<ConsoleCommandAttribute>() != null
select m);
}
catch (ReflectionTypeLoadException ex)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Could not load types from assembly " + assembly.FullName + ": " + ex.Message);
if (ex.LoaderExceptions != null)
{
Exception[] loaderExceptions = ex.LoaderExceptions;
foreach (Exception ex2 in loaderExceptions)
{
stringBuilder.AppendLine(" - LoaderException: " + ex2.Message);
}
}
Feature<BetterConsoleFeature>.Error((object)stringBuilder);
}
catch (Exception ex3)
{
Feature<BetterConsoleFeature>.Error((object)("An unexpected error occurred while scanning assembly " + assembly.FullName + ": " + ex3.Message));
}
}
return list;
}
private static bool HandleHelpCommand(ref bool __result, string? domain = null)
{
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
string domain2 = domain;
StringBuilder stringBuilder = new StringBuilder();
if (domain2 == null)
{
IEnumerable<string> enumerable = from d in ConsoleCommands.Select((ConsoleCommand c) => c.DomainName).Distinct()
orderby d
select d;
foreach (string item in enumerable)
{
stringBuilder.AppendLine(item);
}
stringBuilder.Append("Type '<Domain>.Help' for help with a specific domain");
}
else
{
List<ConsoleCommand> list = ConsoleCommands.Where((ConsoleCommand c) => c.DomainName.Equals(domain2, StringComparison.OrdinalIgnoreCase)).ToList();
if (!list.Any())
{
ConsoleError("No domain named '" + domain2 + "' found");
__result = true;
return false;
}
bool flag = true;
foreach (ConsoleCommand cmd in list)
{
Attributes.TryGetValue(cmd.MethodInfo, out ConsoleCommandAttribute attr);
if (!flag)
{
stringBuilder.AppendLine();
}
else
{
flag = false;
}
stringBuilder.Append(cmd.Command);
stringBuilder.Append(' ');
stringBuilder.Append(string.Join(" ", Enumerable.Range(0, cmd.ParameterInfo.Length).Select(delegate(int i)
{
string text = ((attr?.Arguments != null && i < attr.Arguments.Length && !string.IsNullOrEmpty(attr.Arguments[i])) ? attr.Arguments[i] : cmd.ParameterInfo[i].Name) + " (" + cmd.ParameterInfo[i].ParameterType.Name + ")";
return (!cmd.ParameterInfo[i].IsOptional) ? ("<" + text + ">") : ("[" + text + "]");
})));
if (attr?.Description != null)
{
stringBuilder.AppendLine();
stringBuilder.Append(" - ");
stringBuilder.Append(attr?.Description);
}
}
}
ConsoleLog(stringBuilder.ToString());
__result = true;
return false;
}
private static void ConsoleError(string text)
{
Debug.LogError((object)text);
}
private static void ConsoleLog(string text)
{
Debug.Log((object)text);
}
}
public static class ConsolePagePatch
{
private static readonly MethodInfo FindSuggestions = AccessTools.Method(typeof(ConsolePage), "FindSuggestions", (System.Type[])null, (System.Type[])null);
private static readonly FieldInfo ListViewField = AccessTools.Field(typeof(ConsolePage), "m_listView");
private static readonly FieldInfo LogEntriesField = AccessTools.Field(typeof(ConsolePage), "m_logEntries");
internal static void Init()
{
Tweaks.Patcher.SaveInfo("Zorro.Core.Runtime", "Zorro.Core.CLI", true, 1);
Tweaks.Patcher.Patch("Update", (System.Type[])null, (string)null, "Update_Postfix", (string)null);
Tweaks.Patcher.Patch("LogRecieved", (System.Type[])null, (string)null, "Scrollfix_Postfix", (string)null);
Tweaks.Patcher.Patch("AttemptParseCommand", (System.Type[])null, (string)null, "Scrollfix_Postfix", (string)null);
Tweaks.Patcher.Patch("ConstructConsole", (System.Type[])null, (string)null, "Scrollfix_Postfix", (string)null);
}
public static void Update_Postfix(ConsolePage __instance, ref Optionable<byte> ___m_selectedSuggestion, string ___m_currentInput)
{
//IL_000a: 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)
if (Input.GetKeyDown((KeyCode)9))
{
___m_selectedSuggestion = Optionable<byte>.None;
FindSuggestions.Invoke(__instance, new object[1] { ___m_currentInput });
}
}
public static void Scrollfix_Postfix(object __instance)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
ListView listView = (ListView)ListViewField.GetValue(__instance);
if (listView == null)
{
return;
}
List<ConsoleLogEntry> logEntries = (List<ConsoleLogEntry>)LogEntriesField.GetValue(__instance);
if (logEntries == null)
{
return;
}
((VisualElement)listView).schedule.Execute((Action)delegate
{
((VisualElement)listView).schedule.Execute((Action)delegate
{
if (logEntries.Count > 0)
{
((BaseVerticalCollectionView)listView).ScrollToItem(logEntries.Count - 1);
}
});
});
}
}
public interface ICommandsClass
{
static bool Enabled { get; }
}
[TypeParser(typeof(bool))]
public class BoolParser : CLITypeParser
{
private readonly HashSet<string> tVals = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "true", "on", "1", "yes", "enable", "accept" };
private readonly HashSet<string> fVals = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "false", "off", "0", "no", "disable", "deny" };
public override object Parse(string str)
{
if (tVals.Contains(str))
{
return true;
}
if (fVals.Contains(str))
{
return false;
}
throw new ArgumentException("Could not parse '" + str + "' as a Boolean value. Expected true/false, on/off, etc.");
}
public override List<ParameterAutocomplete> FindAutocomplete(string parameterText)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
List<ParameterAutocomplete> list = new List<ParameterAutocomplete>();
if ("true".StartsWith(parameterText, StringComparison.OrdinalIgnoreCase))
{
list.Add(new ParameterAutocomplete("true"));
}
if ("false".StartsWith(parameterText, StringComparison.OrdinalIgnoreCase))
{
list.Add(new ParameterAutocomplete("false"));
}
return list;
}
}
[TypeParser(typeof(Player))]
public class PlayerParser : CLITypeParser
{
public override List<ParameterAutocomplete> FindAutocomplete(string parameterText)
{
string parameterText2 = parameterText;
return PlayerHandler.instance.players.Where(delegate(Player p)
{
PlayerRefs refs = p.refs;
object obj;
if (refs == null)
{
obj = null;
}
else
{
PhotonView view = refs.view;
if (view == null)
{
obj = null;
}
else
{
Player owner = view.Owner;
obj = ((owner != null) ? owner.NickName : null);
}
}
return obj != null && p.refs.view.Owner.NickName.StartsWith(parameterText2, StringComparison.OrdinalIgnoreCase);
}).Select((Func<Player, ParameterAutocomplete>)((Player p) => new ParameterAutocomplete(p.refs.view.Owner.NickName))).ToList();
}
public override object Parse(string str)
{
string str2 = str;
return ((IEnumerable<Player>)PlayerHandler.instance.players).FirstOrDefault((Func<Player, bool>)delegate(Player p)
{
PlayerRefs refs = p.refs;
bool? obj;
if (refs == null)
{
obj = null;
}
else
{
PhotonView view = refs.view;
if (view == null)
{
obj = null;
}
else
{
Player owner = view.Owner;
obj = ((owner != null) ? new bool?(owner.NickName.Equals(str2, StringComparison.OrdinalIgnoreCase)) : null);
}
}
bool? flag = obj;
return flag.GetValueOrDefault();
}) ?? throw new ArgumentException("No player with username '" + str2 + "' exists");
}
}
}
namespace Tweaks.Enums
{
internal enum Setting
{
add,
cset,
set
}
internal enum Type
{
seconds,
percent
}
}