Decompiled source of DevToolsUnlocked v1.0.0
plugins/DevToolsUnlocked/DevToolsUnlocked.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; 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.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using FishNet.Connection; using FishNet.Object; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.Samples.RebindUI; using UnityEngine.Localization; using UnityEngine.Localization.Components; using UnityEngine.Localization.Settings; using UnityEngine.SceneManagement; using UnityEngine.UI; [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("DevToolsUnlocked")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+868c594518b00323d12c50172f78129572a2db61")] [assembly: AssemblyProduct("DevToolsUnlocked")] [assembly: AssemblyTitle("DevToolsUnlocked")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 DevToolsUnlocked { public static class ChatHistory { private const int Max = 50; private static readonly List<string> Lines = new List<string>(); private static readonly FieldInfo InstanceField = AccessTools.Field(typeof(ChatManager), "_instance"); private static readonly FieldInfo InputField = AccessTools.Field(typeof(ChatManager), "_chatInputField"); private static int _index = -1; private static TMP_InputField _moveCaret; public static IReadOnlyList<string> All => Lines; public static string Last { get { if (Lines.Count <= 0) { return null; } return Lines[Lines.Count - 1]; } } public static string Step(ref int index, int step) { if (Lines.Count == 0) { return null; } if (index < 0) { if (step > 0) { return null; } index = Lines.Count - 1; } else { index = Math.Max(0, index + step); if (index >= Lines.Count) { index = -1; } } if (index < 0) { return ""; } return Lines[index]; } public static void Add(string line) { if (!string.IsNullOrWhiteSpace(line) && line.TrimStart().StartsWith("/")) { line = line.Trim(); Lines.Remove(line); Lines.Add(line); if (Lines.Count > 50) { Lines.RemoveAt(0); } _index = -1; } } public static void Update() { if ((Object)(object)_moveCaret != (Object)null) { TMP_InputField moveCaret = _moveCaret; int caretPosition = (_moveCaret.stringPosition = _moveCaret.text.Length); moveCaret.caretPosition = caretPosition; _moveCaret = null; } if (!ChatManager.IsTyping) { _index = -1; return; } Keyboard current = Keyboard.current; if (current == null || Lines.Count == 0) { return; } int num = (((ButtonControl)current.upArrowKey).wasPressedThisFrame ? (-1) : (((ButtonControl)current.downArrowKey).wasPressedThisFrame ? 1 : 0)); if (num == 0) { return; } object? obj = InputField?.GetValue(InstanceField?.GetValue(null)); TMP_InputField val = (TMP_InputField)((obj is TMP_InputField) ? obj : null); if (!((Object)(object)val == (Object)null)) { string text = Step(ref _index, num); if (text != null) { val.text = text; _moveCaret = val; } } } } [HarmonyPatch(typeof(ChatManager), "SendTypedMessage")] internal static class SendTypedMessagePatch { private static readonly FieldInfo InputField = AccessTools.Field(typeof(ChatManager), "_chatInputField"); private static void Prefix(ChatManager __instance) { object? obj = InputField?.GetValue(__instance); TMP_InputField val = (TMP_InputField)((obj is TMP_InputField) ? obj : null); if (val != null) { ChatHistory.Add(val.text); } } } public sealed class CommandInfo { public string Name; public string Args; public string Help; public bool HostOnly; public bool Destructive; public Action<string[]> Run; public string Usage { get { if (!string.IsNullOrEmpty(Args)) { return "/" + Name + " " + Args; } return "/" + Name; } } } public static class Commands { public const string ConfirmWord = "confirm"; private static readonly FieldInfo NameToSpawnableField = AccessTools.Field(typeof(GameInfo), "_nameToSpawnable"); private static readonly FieldInfo SlotMachineInstanceField = AccessTools.Field(typeof(SlotMachine), "_instance"); public static readonly CommandInfo[] Game = new CommandInfo[24] { G("spawn", "<item>", "Spawns an item or creature in front of you", destructive: false, delegate(string[] a) { Spawn(a, dead: false, drip: false); }), G("spawndead", "<creature>", "Spawns a dead creature", destructive: false, delegate(string[] a) { Spawn(a, dead: true, drip: false); }), G("spawndrip", "<creature>", "Spawns a drip creature", destructive: false, delegate(string[] a) { Spawn(a, dead: false, drip: true); }), G("spawndripdead", "<creature>", "Spawns a dead drip creature (feeds the slot machine)", destructive: false, delegate(string[] a) { Spawn(a, dead: true, drip: true); }), G("godmode", "", "Toggles god mode for everyone (the game's own)"), G("oneshot", "", "Toggles one-shot kills"), G("killboss", "", "Kills the current boss"), G("addmoney", "", "Adds 9999 money"), G("removemoney", "", "Removes 9999 money"), G("grill", "", "Unlocks the grill", destructive: true), G("boat", "", "Unlocks the boat", destructive: true), G("nextisland", "", "Teleports everyone to the next island"), G("previsland", "", "Teleports everyone to the previous island"), G("island", "<scene>|mini", "Teleports everyone to an island (see /islands); \"mini\" picks a random mini island", destructive: false, WorldTools.Island), M("showkillscores", "", "Shows every kill score bonus (on your screen)", hostOnly: false, delegate { ShowKillScores(); }), G("allskins", "", "Unlocks every skin (replaces your skin save)", destructive: true), G("noskins", "", "Locks every skin (wipes your skin save)", destructive: true), G("killallcreatures", "", "Marks every creature as caught in the journal", destructive: true), G("killalldripcreatures", "", "Marks every drip creature as caught", destructive: true), G("resetallcreatures", "", "Clears every creature from the journal", destructive: true), G("resetalldripcreatures", "", "Clears every drip creature from the journal", destructive: true), G("finishgame", "", "Plays the ending", destructive: true), G("unlockachievements", "", "Unlocks your real Steam achievements", destructive: true), G("lockachievements", "", "Locks your real Steam achievements", destructive: true) }; public static readonly CommandInfo[] Mod = new CommandInfo[18] { M("help", "", "Lists every command", hostOnly: false, delegate { Help(); }), M("items", "[filter]", "Lists spawnable names (full list saved to a file)", hostOnly: false, Items), M("islands", "", "Lists island scene names for /island", hostOnly: false, delegate { Islands(); }), M("god", "[player|all]", "Toggles god mode for you, a player or everyone", hostOnly: true, WorldTools.God), M("heal", "[player|all]", "Fills health and hunger", hostOnly: true, WorldTools.Heal), M("hurt", "[amount] [player|all]", "Damages (25 by default); players in god mode are spared", hostOnly: true, WorldTools.Hurt), M("kill", "[player|all]", "Kills; players in god mode are spared", hostOnly: true, WorldTools.Kill), M("bring", "<player|all>", "Teleports players in front of you", hostOnly: true, WorldTools.Bring), M("goto", "<player>", "Teleports you next to a player", hostOnly: true, WorldTools.GoTo), M("money", "<amount> [euro]", "Adds money (negative removes it), dollars or euro", hostOnly: true, WorldTools.Money), M("skins", "<item|boat>", "Lists an item's skins with index, rarity and owned state", hostOnly: false, Skins), M("unlockskin", "<item|boat> <index|all>", "Unlocks skins in your save", hostOnly: false, delegate(string[] a) { SkinTools.SetSkins(a, unlock: true); }), M("lockskin", "<item|boat> <index|all>", "Locks skins in your save (backs up first)", hostOnly: false, delegate(string[] a) { SkinTools.SetSkins(a, unlock: false); }), M("backupskins", "", "Saves a copy of your unlocked skins", hostOnly: false, delegate { SkinTools.Backup("manual", announce: true); }), M("restoreskins", "[number]", "Lists skin backups, or restores one", hostOnly: false, SkinTools.Restore), M("slots", "<item|boat> <index> | off", "The next slot machine rolls win this skin, until /slots off", hostOnly: true, Slots), M("roll", "", "Rolls the slot machine on this island without feeding it", hostOnly: true, delegate { Roll(); }), M("slotpool", "", "Shows the slot machine's prize pool and odds", hostOnly: false, delegate { SlotPool(); }) }; private static readonly Dictionary<string, CommandInfo> ByName = (from c in Game.Concat(Mod) group c by c.Name).ToDictionary((IGrouping<string, CommandInfo> g) => g.Key, (IGrouping<string, CommandInfo> g) => g.Last()); private static readonly FieldInfo CheatItemField = AccessTools.Field(typeof(SlotMachineManager), "_cheatItem"); private static readonly FieldInfo CheatIndexField = AccessTools.Field(typeof(SlotMachineManager), "_cheatSkinIndex"); public static bool IsHost { get { if ((Object)(object)Server.Instance != (Object)null) { return ((NetworkBehaviour)Server.Instance).IsServerInitialized; } return false; } } public static string DataFolder { get { string text = Path.Combine(Paths.ConfigPath, "DevToolsUnlocked"); Directory.CreateDirectory(text); return text; } } private static CommandInfo G(string name, string args, string help, bool destructive = false, Action<string[]> run = null) { return new CommandInfo { Name = name, Args = args, Help = help, HostOnly = true, Destructive = destructive, Run = run }; } private static CommandInfo M(string name, string args, string help, bool hostOnly, Action<string[]> run) { return new CommandInfo { Name = name, Args = args, Help = help, HostOnly = hostOnly, Run = run }; } public static void Execute(string line) { if (!string.IsNullOrWhiteSpace(line)) { DazedCommands.IsServerCommand(line.Trim()); } } public static void Reply(string message) { Plugin.Log.LogInfo((object)message); if ((Object)(object)Remote.Requester != (Object)null) { Remote.Announce(message); } else if (ChatManagerReady()) { ChatManager.ChatMessage(message); } else { DevPanel.AddLog(message); } } private static bool ChatManagerReady() { object? obj = AccessTools.Field(typeof(ChatManager), "_instance")?.GetValue(null); return (Object)((obj is Object) ? obj : null) != (Object)null; } public static bool TryHandle(string line) { string[] array = line.Substring(1).Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length == 0) { return false; } string text = array[0].ToLowerInvariant(); string[] source = array.Skip(1).ToArray(); if (!ByName.TryGetValue(text, out var value)) { return false; } if (value.HostOnly && !IsHost) { if (!Remote.TrySend(text, "/" + string.Join(" ", array))) { Reply("Only the host can use /" + text + "."); } return true; } bool flag = source.Any((string a) => a.Equals("confirm", StringComparison.OrdinalIgnoreCase)); if (value.Name.EndsWith("achievements") && !Plugin.AllowAchievements.Value) { Reply("/" + text + " changes your real Steam achievements and is off. Turn on AllowAchievementCommands in the config to use it."); return true; } if (value.Destructive && Plugin.RequireConfirm.Value && !flag) { Reply("/" + text + ": " + value.Help + ". Type <b>/" + text + " confirm</b> to run it."); return true; } if (text == "allskins" || text == "noskins") { SkinTools.Backup("before-" + text, announce: false); } if (value.Run == null) { return false; } value.Run(source.Where((string a) => !a.Equals("confirm", StringComparison.OrdinalIgnoreCase)).ToArray()); return true; } private static void Help() { Reply("<b>Game:</b> " + string.Join(", ", Game.Select((CommandInfo c) => c.Usage))); Reply("<b>DevToolsUnlocked:</b> " + string.Join(", ", Mod.Select((CommandInfo c) => c.Usage))); Reply("Commands that change the save need \"confirm\". The panel (" + Plugin.PanelKeyName() + ") lists them all."); } private static void Spawn(string[] args, bool dead, bool drip) { //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) string text = string.Join("", args).ToLowerInvariant(); Item val = ((text.Length > 0) ? GameInfo.GetSpawnable(text) : null); if ((Object)(object)val == (Object)null) { Reply("No item called \"" + text + "\". /items lists the names."); return; } if ((dead || drip) && (Object)(object)((Component)val).GetComponent<Creature>() == (Object)null) { Reply(text + " isn't a creature: only /spawn works for it."); return; } Transform val2 = (((Object)(object)Remote.Requester != (Object)null) ? Remote.Requester.CamObject : (((Object)(object)GameInfo.CurCamera != (Object)null) ? ((Component)GameInfo.CurCamera).transform : null)); if (!((Object)(object)val2 == (Object)null)) { Item val3 = Object.Instantiate<Item>(val, val2.position + val2.forward * 2f, Quaternion.identity); if (drip) { ((Component)val3).GetComponent<Creature>().SetDrip(); } if (dead) { ((Component)val3).GetComponent<Creature>().ServerKillOnSpawn(); } ((NetworkBehaviour)Server.Instance).Spawn(((Component)val3).gameObject, (NetworkConnection)null, default(Scene)); } } private static void ShowKillScores() { if (!((Object)(object)Player.LocalPlayer == (Object)null)) { for (int i = 0; i < 3; i++) { Player.LocalPlayer.KillScore.AddKillScore($"All killscores {i}", 100, KillScoreCalculator.GetAllBonuses(i)); } } } public static List<string> SpawnableNames() { if (NameToSpawnableField?.GetValue(null) is Dictionary<string, Item> dictionary) { return dictionary.Keys.OrderBy((string k) => k).ToList(); } return new List<string>(); } private static void Items(string[] args) { List<string> list = SpawnableNames(); if (list.Count == 0) { Reply("The item list isn't loaded yet."); return; } string filter = string.Join("", args).ToLowerInvariant(); List<string> list2 = list.Where((string n) => n.Contains(filter)).ToList(); Reply($"{list2.Count} of {list.Count} items: " + string.Join(", ", list2.Take(40)) + ((list2.Count > 40) ? ", ..." : "")); string text = WriteItemList(); if (text != null) { Reply("Full list: " + text); } } public static string WriteItemList() { if (!(NameToSpawnableField?.GetValue(null) is Dictionary<string, Item> { Count: not 0 } dictionary)) { return null; } try { List<string> list = new List<string> { "# name (for /spawn, /slots ...) | ID | display name | kind | skins | class | components | cost | worth" }; foreach (KeyValuePair<string, Item> item in dictionary.OrderBy((KeyValuePair<string, Item> p) => p.Key)) { Item value = item.Value; string text; try { text = value.GetName(); } catch (Exception) { text = ""; } string text2 = (((Object)(object)((Component)value).GetComponent<Creature>() != (Object)null) ? "creature" : (value.IsQuestItem ? "quest item" : "item")); int num = (((Object)(object)value.SkinPreset != (Object)null) ? value.SkinPreset.Skins.Count : 0); IEnumerable<string> values = (from m in ((Component)value).GetComponents<MonoBehaviour>() where (Object)(object)m != (Object)null && ((object)m).GetType().Assembly == typeof(Item).Assembly select ((object)m).GetType().Name).Distinct(); string text3 = Field(value, "_cost"); string text4 = Field(value, "_worth"); string text5 = Field(value, "_currency"); list.Add(string.Format("{0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} {8} | {9}", item.Key, value.ID, text, text2, num, ((object)value).GetType().Name, string.Join(",", values), text3, text5, text4)); } string text6 = Path.Combine(DataFolder, "spawnables.txt"); File.WriteAllLines(text6, list); return text6; } catch (Exception ex2) { Plugin.Log.LogWarning((object)("Could not write the item list: " + ex2.Message)); return null; } } private static string Field(object o, string name) { try { return AccessTools.Field(o.GetType(), name)?.GetValue(o)?.ToString() ?? ""; } catch (Exception) { return ""; } } public static List<string> IslandNames() { List<string> list = new List<string>(); for (int i = 1; i < SceneManager.sceneCountInBuildSettings; i++) { list.Add(Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i)).Replace(" ", "")); } return list; } private static void Islands() { Reply("Islands: " + string.Join(", ", IslandNames()) + ". Use /island <name>."); } private static void Skins(string[] args) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_00a5: Unknown result type (might be due to invalid IL or missing references) if (SkinTools.Resolve(string.Join("", args), out var target)) { HashSet<byte> hashSet = SkinTools.Owned(target.ID); List<string> list = new List<string>(); for (int i = 0; i < target.Preset.Skins.Count; i++) { ItemSkin val = target.Preset.Skins[i]; string text = ((i == 0) ? "default" : (((int)((ItemSkin)(ref val)).Rarity == 0) ? "unobtainable" : (hashSet.Contains((byte)i) ? "owned" : "locked"))); list.Add($"{i} {((ItemSkin)(ref val)).Name} <color=#{RarityColor(((ItemSkin)(ref val)).Rarity)}>{((ItemSkin)(ref val)).Rarity}</color> ({text})"); } Reply("<b>" + target.Label + "</b> skins: " + string.Join(", ", list)); } } public static string RarityColor(Rarity rarity) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected I4, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) try { switch (rarity - 1) { case 0: return ColorUtility.ToHtmlStringRGB(GameInfo.CommonColor); case 1: return ColorUtility.ToHtmlStringRGB(GameInfo.RareColor); case 2: return ColorUtility.ToHtmlStringRGB(GameInfo.LegendaryColor); } } catch (Exception) { } return "AAAAAA"; } private static void Slots(string[] args) { byte result; if (args.Length == 1 && args[0].Equals("off", StringComparison.OrdinalIgnoreCase)) { SlotMachineManager.SetCheatSkin((Item)null, byte.MaxValue); Reply("Slot machine rolls are random again."); } else if (args.Length < 2 || !byte.TryParse(args[^1], out result)) { Reply("Usage: /slots <item|boat> <index>, or /slots off. /skins <item> shows the indexes."); } else { SetSlotsSkin(string.Join("", args.Take(args.Length - 1)), result); } } public static void SetSlotsSkin(string itemName, byte index) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) if (!SkinTools.Resolve(itemName, out var target)) { return; } if (index >= target.Preset.Skins.Count) { Reply($"{target.Label} has skins 0 to {target.Preset.Skins.Count - 1}."); return; } ItemSkin val = target.Preset.Skins[index]; if ((int)((ItemSkin)(ref val)).Rarity == 0) { Reply(((ItemSkin)(ref val)).Name + " is a default/unobtainable skin: the slot machine can't roll it."); return; } SlotMachineManager.SetCheatSkin(target.IsBoat ? null : target.Item, index); Reply($"Every slot machine roll now wins <b>{target.Label} {((ItemSkin)(ref val)).Name}</b> ({((ItemSkin)(ref val)).Rarity}) until /slots off."); } private static void Roll() { object? obj = SlotMachineInstanceField?.GetValue(null); if ((Object)((obj is Object) ? obj : null) == (Object)null || SlotMachine.AvailableItems == null) { Reply("There's no slot machine on this island."); return; } if (SlotMachine.IsRolling) { Reply("The slot machine is already rolling."); return; } Player val = (((Object)(object)Remote.Requester != (Object)null) ? Remote.Requester : Player.LocalPlayer); if (!((Object)(object)val == (Object)null)) { SlotMachineManager.RollRandom(val); } } private static void SlotPool() { string[] array = SlotPoolText().Split('\n'); for (int i = 0; i < array.Length; i++) { Reply(array[i]); } } public static string SlotPoolText() { Item[] availableItems = SlotMachine.AvailableItems; if (availableItems == null) { return "No slot machine has been loaded yet: visit an island with one."; } List<string> list = new List<string>(); Item[] array = availableItems; foreach (Item val in array) { if ((Object)(object)val != (Object)null && (Object)(object)val.SkinPreset != (Object)null) { list.Add(PoolEntry(SafeName(val), val.SkinPreset)); } } if (!SlotMachine.ExcludeBoat && (Object)(object)BoatManager.Boat != (Object)null) { list.Add(PoolEntry("Boat", BoatManager.Boat.SkinPreset)); } string text = $"Slot pool ({list.Count} collections, common/rare/legendary skins): " + string.Join(", ", list) + "\nEach roll: 7 common, 2 rare and 1 legendary slot, one wins at random (70/20/10%), then an even pick of collection and skin."; string text2 = ForcedPrize(); if (text2 != null) { text = text + "\nForced prize (/slots): " + text2; } return text; } public static string ForcedPrize() { //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) if (CheatIndexField == null || !(CheatIndexField.GetValue(null) is byte b) || b == byte.MaxValue) { return null; } object? obj = CheatItemField?.GetValue(null); Item val = (Item)((obj is Item) ? obj : null); SkinPreset val2 = (((Object)(object)val != (Object)null) ? val.SkinPreset : (((Object)(object)BoatManager.Boat != (Object)null) ? BoatManager.Boat.SkinPreset : null)); if ((Object)(object)val2 == (Object)null || b >= val2.Skins.Count) { return null; } string arg = (((Object)(object)val != (Object)null) ? SafeName(val) : "Boat"); ItemSkin val3 = val2.Skins[b]; string name = ((ItemSkin)(ref val3)).Name; val3 = val2.Skins[b]; return $"{arg} {name} ({((ItemSkin)(ref val3)).Rarity})"; } private static string PoolEntry(string name, SkinPreset preset) { return $"{name} {Count((Rarity)1)}/{Count((Rarity)2)}/{Count((Rarity)3)}"; int Count(Rarity r) { //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) return preset.Skins.Count((ItemSkin s) => ((ItemSkin)(ref s)).Rarity == r); } } public static string SafeName(Item item) { try { string name = item.GetName(); if (!string.IsNullOrEmpty(name)) { return name; } } catch (Exception) { } return ((Object)item).name; } } [HarmonyPatch(typeof(DazedCommands), "IsServerCommand")] internal static class IsServerCommandPatch { private static bool Prefix(string fullCommand, ref bool __result, out bool __state) { __state = false; if (string.IsNullOrEmpty(fullCommand) || !fullCommand.StartsWith("/")) { return true; } __result = true; if (Commands.TryHandle(fullCommand)) { return false; } if (!ClientSettings.CheatsEnabled) { ClientSettings.ToggleCheats(true); __state = true; } return true; } private static Exception Finalizer(Exception __exception, string fullCommand, ref bool __result, bool __state) { if (__state) { ClientSettings.ToggleCheats(false); } if (__exception == null) { return null; } __result = true; Plugin.Log.LogError((object)$"{fullCommand} failed: {__exception}"); Commands.Reply(fullCommand + " failed: " + __exception.GetType().Name + ". Check the name with /items or /skins."); return null; } } [HarmonyPatch(typeof(ChatManager), "ChatMessage", new Type[] { typeof(string) })] internal static class ChatMessagePatch { private static void Postfix(string message) { DevPanel.AddLog(message); Remote.OnChatLine(message); } } public class DevToolsRow : MonoBehaviour { public Transform Source; } public static class ControlsMenu { private const string TemplateAction = "ChangeBait"; private static readonly FieldInfo ActionField = AccessTools.Field(typeof(RebindActionUI), "m_Action"); private static readonly FieldInfo BindingIdField = AccessTools.Field(typeof(RebindActionUI), "m_BindingId"); private static readonly HashSet<RebindActionUI> Pending = new HashSet<RebindActionUI>(); private static readonly List<TextMeshProUGUI> Labels = new List<TextMeshProUGUI>(); private static ModInput _input; public static void Init(ModInput input) { _input = input; Strings.LanguageChanged += OnLanguageChanged; } public static void Notice(RebindActionUI ui) { if (_input != null && ActionName(ui) == "ChangeBait") { Pending.Add(ui); } } public static void ProcessPending() { if (Pending.Count == 0) { return; } List<RebindActionUI> list = Pending.ToList(); Pending.Clear(); foreach (RebindActionUI item in list) { try { if ((Object)(object)item == (Object)null || ActionName(item) != "ChangeBait" || (Object)(object)((Component)item).GetComponentInParent<DevToolsRow>(true) != (Object)null) { continue; } Transform val = FindRow(((Component)item).transform); if (!((Object)(object)val.parent == (Object)null)) { Transform column = FindTargetColumn(val); if (!AlreadyInjected(column, val)) { Inject(val, column); } } } catch (Exception arg) { Plugin.Log.LogError((object)$"Could not add the DevToolsUnlocked row to the Controls menu: {arg}"); } } } private static Transform FindRow(Transform t) { Transform val = t; while ((Object)(object)val.parent != (Object)null && !((Component)val.parent).GetComponentsInChildren<RebindActionUI>(true).Any((RebindActionUI u) => ActionName(u) != "ChangeBait")) { val = val.parent; } return val; } private static Transform FindTargetColumn(Transform row) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown Transform parent = row.parent; if ((Object)(object)parent.parent == (Object)null) { return parent; } Transform result = parent; int num = RowCount(parent); foreach (Transform item in parent.parent) { Transform val = item; if (!((Object)(object)val == (Object)(object)parent) && !((Object)(object)((Component)val).GetComponent<LayoutGroup>() == (Object)null)) { int num2 = RowCount(val); if (num2 > 0 && num2 < num) { result = val; num = num2; } } } return result; } private static int RowCount(Transform column) { return ((IEnumerable)column).Cast<Transform>().Count((Transform c) => (Object)(object)((Component)c).GetComponentInChildren<RebindActionUI>(true) != (Object)null); } private static bool AlreadyInjected(Transform column, Transform row) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) foreach (Transform item in column) { DevToolsRow component = ((Component)item).GetComponent<DevToolsRow>(); if ((Object)(object)component != (Object)null && (Object)(object)component.Source == (Object)(object)row) { return true; } } return false; } private static void Inject(Transform row, Transform column) { Transform val = ((IEnumerable)column).Cast<Transform>().LastOrDefault((Func<Transform, bool>)((Transform c) => (Object)(object)((Component)c).GetComponentInChildren<RebindActionUI>(true) != (Object)null)) ?? row; int num = (((Object)(object)val.parent == (Object)(object)column) ? val.GetSiblingIndex() : (column.childCount - 1)); GameObject val2 = Object.Instantiate<GameObject>(((Component)row).gameObject, column, false); ((Object)val2).name = "DevTools_" + _input.OpenPanel.name; val2.transform.SetSiblingIndex(num + 1); val2.AddComponent<DevToolsRow>().Source = row; Retarget(val2.transform); ChainNavigation(val, val2.transform); Plugin.Log.LogInfo((object)("Added the DevToolsUnlocked row to the Controls menu under '" + ((Object)column).name + "'")); } private static void Retarget(Transform clone) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) HashSet<TextMeshProUGUI> excluded = new HashSet<TextMeshProUGUI>(); List<Transform> overlays = new List<Transform>(); TextMeshProUGUI val = null; RebindActionUI[] componentsInChildren = ((Component)clone).GetComponentsInChildren<RebindActionUI>(true); InputAction val3 = default(InputAction); int num = default(int); foreach (RebindActionUI val2 in componentsInChildren) { int num2; if (val2.ResolveActionAndBinding(ref val3, ref num)) { InputBinding val4 = InputBinding.MaskByGroup("Controller"); num2 = (((InputBinding)(ref val4)).Matches(val3.bindings[num]) ? 1 : 0); } else { num2 = 0; } bool flag = (byte)num2 != 0; ActionField.SetValue(val2, InputActionReference.Create(_input.OpenPanel)); BindingIdField.SetValue(val2, (flag ? ModInput.OpenPanelControllerId : ModInput.OpenPanelKeyboardId).ToString()); val2.UpdateBindingDisplay(); TextMeshProUGUI[] array = (TextMeshProUGUI[])(object)new TextMeshProUGUI[3] { val2.bindingText, val2.rebindPrompt, val2.rebindInfo }; foreach (TextMeshProUGUI val5 in array) { if ((Object)(object)val5 != (Object)null) { excluded.Add(val5); } } if ((Object)(object)val2.rebindOverlay != (Object)null) { overlays.Add(val2.rebindOverlay.transform); } if ((Object)(object)val == (Object)null && (Object)(object)val2.actionLabel != (Object)null && ((TMP_Text)val2.actionLabel).transform.IsChildOf(clone)) { val = val2.actionLabel; } } if ((Object)(object)val == (Object)null) { val = ((IEnumerable<TextMeshProUGUI>)((Component)clone).GetComponentsInChildren<TextMeshProUGUI>(true)).FirstOrDefault((Func<TextMeshProUGUI, bool>)((TextMeshProUGUI t) => !excluded.Contains(t) && !overlays.Any((Transform o) => ((TMP_Text)t).transform.IsChildOf(o)))); } if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)"No label found in the cloned Controls row"); return; } LocalizeStringEvent component = ((Component)val).GetComponent<LocalizeStringEvent>(); if ((Object)(object)component != (Object)null) { ((Behaviour)component).enabled = false; } ((TMP_Text)val).text = LabelText(); Labels.Add(val); } private static void ChainNavigation(Transform anchor, Transform clone) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Invalid comparison between Unknown and I4 //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Invalid comparison between Unknown and I4 //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: 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) Selectable[] componentsInChildren = ((Component)anchor).GetComponentsInChildren<Selectable>(true); Selectable[] componentsInChildren2 = ((Component)clone).GetComponentsInChildren<Selectable>(true); if (componentsInChildren2.Length != componentsInChildren.Length) { return; } for (int i = 0; i < componentsInChildren.Length; i++) { Selectable val = componentsInChildren[i]; Navigation navigation = val.navigation; if ((int)((Navigation)(ref navigation)).mode != 4) { continue; } navigation = val.navigation; Selectable selectOnDown = ((Navigation)(ref navigation)).selectOnDown; Selectable val2 = componentsInChildren2[i]; Navigation navigation2 = val2.navigation; ((Navigation)(ref navigation2)).mode = (Mode)4; ((Navigation)(ref navigation2)).selectOnUp = val; ((Navigation)(ref navigation2)).selectOnDown = selectOnDown; navigation = val.navigation; ((Navigation)(ref navigation2)).selectOnLeft = MapWithinRow(((Navigation)(ref navigation)).selectOnLeft, componentsInChildren, componentsInChildren2); navigation = val.navigation; ((Navigation)(ref navigation2)).selectOnRight = MapWithinRow(((Navigation)(ref navigation)).selectOnRight, componentsInChildren, componentsInChildren2); val2.navigation = navigation2; Navigation navigation3 = val.navigation; ((Navigation)(ref navigation3)).selectOnDown = val2; val.navigation = navigation3; if (!((Object)(object)selectOnDown != (Object)null)) { continue; } navigation = selectOnDown.navigation; if ((int)((Navigation)(ref navigation)).mode == 4) { navigation = selectOnDown.navigation; if ((Object)(object)((Navigation)(ref navigation)).selectOnUp == (Object)(object)val) { Navigation navigation4 = selectOnDown.navigation; ((Navigation)(ref navigation4)).selectOnUp = val2; selectOnDown.navigation = navigation4; } } } } private static Selectable MapWithinRow(Selectable target, Selectable[] original, Selectable[] clone) { int num = Array.IndexOf(original, target); if (num < 0) { return target; } return clone[num]; } private static string LabelText() { return Strings.Get("PanelRow"); } private static void OnLanguageChanged() { Labels.RemoveAll((TextMeshProUGUI l) => (Object)(object)l == (Object)null); foreach (TextMeshProUGUI label in Labels) { ((TMP_Text)label).text = LabelText(); } } private static string ActionName(RebindActionUI ui) { object? value = ActionField.GetValue(ui); InputActionReference val = (InputActionReference)((value is InputActionReference) ? value : null); if (!((Object)(object)val != (Object)null) || val.action == null) { return null; } return val.action.name; } } [HarmonyPatch(typeof(RebindActionUI), "OnEnable")] internal static class RebindActionUIOnEnablePatch { private static void Postfix(RebindActionUI __instance) { ControlsMenu.Notice(__instance); } } public static class DevPanel { private enum Tab { Favorites, Player, Commands, Creatures, Items, Skins, SlotMachine, Islands, Log } private sealed class SpawnInfo { public string Key; public string Display; public string Category; public bool IsCreature; } private static readonly string[] TabNames = new string[9] { "Favorites", "Player", "Commands", "Creatures", "Items", "Skins", "Slot machine", "Islands", "Log" }; private static readonly string[] TabHints = new string[9] { "Your starred commands and the latest ones you ran", "God mode, one-shot, health, hunger and money", "Every command, with a description. Red ones change the save for good and ask twice", "Spawn fish and other creatures in front of you: alive, dead, drip or dead drip", "Spawn weapons, tools, explosives, quest items and everything else", "Unlock or lock skins one by one, force the slot machine prize, back up and restore your skins", "Roll the slot machine, see its prize pool and the forced prize", "Teleport everyone to an island", "Every chat and command message" }; private static readonly List<string> LogLines = new List<string>(); private const int MaxLog = 200; private const int MaxRows = 120; private static GameObject _root; private static Canvas _canvas; private static RectTransform _window; private static RectTransform _content; private static ScrollRect _scroll; private static TextMeshProUGUI _status; private static TextMeshProUGUI _hostState; private static TextMeshProUGUI _title; private static TMP_InputField _search; private static TMP_InputField _command; private static TMP_InputField _count; private static readonly List<Button> TabButtons = new List<Button>(); private static Tab _tab = Tab.Commands; private static string _hint; private static string _armed; private static float _armedUntil; private static float _rebuildAt = -1f; private static int _historyIndex = -1; private static int _skinTarget; private static bool _wasHost; private static List<SpawnInfo> _spawnables; private static readonly string[] ItemCategories = new string[6] { "All", "Weapons", "Tools", "Explosives", "Quest", "Other" }; private static string _itemCategory = "All"; private static string _moneyAmount = "1000"; private static TextMeshProUGUI _playerState; private static float _nextStateUpdate; private static bool _builtWithGameStyle; private static readonly List<KeyValuePair<Player, TextMeshProUGUI>> PlayerStats = new List<KeyValuePair<Player, TextMeshProUGUI>>(); private static int _playerCount; public static bool IsOpen { get; private set; } public static void Toggle() { if (IsOpen) { Close(); } else if (!ChatManager.IsTyping) { Open(); } } private static void Open() { UiKit.Resolve(); if ((Object)(object)_root == (Object)null || (!_builtWithGameStyle && UiKit.FoundGameStyle)) { Build(); } _spawnables = null; IsOpen = true; _root.SetActive(true); ApplyScale(); Rebuild(); } public static void Close() { if (IsOpen) { IsOpen = false; _armed = null; if ((Object)(object)_root != (Object)null) { _root.SetActive(false); } if ((Object)(object)EventSystem.current != (Object)null) { EventSystem.current.SetSelectedGameObject((GameObject)null); } if ((Object)(object)Player.LocalPlayer != (Object)null) { PlayerCamera.ToggleMouse(false); } } } public static void KeepCursorFree() { if (IsOpen) { Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; } } public static void Update() { if (!IsOpen) { return; } if (_rebuildAt > 0f && Time.unscaledTime >= _rebuildAt) { _rebuildAt = -1f; Rebuild(keepScroll: true); } if (_tab == Tab.Player && Time.unscaledTime >= _nextStateUpdate) { _nextStateUpdate = Time.unscaledTime + 0.5f; UpdatePlayerState(); } if (Commands.IsHost != _wasHost) { RefreshHostState(); } if (_armed != null && Time.unscaledTime > _armedUntil) { _armed = null; RebuildSoon(0f); } Keyboard current = Keyboard.current; if (!((Object)(object)_command != (Object)null) || !_command.isFocused || current == null) { return; } int num = (((ButtonControl)current.upArrowKey).wasPressedThisFrame ? (-1) : (((ButtonControl)current.downArrowKey).wasPressedThisFrame ? 1 : 0)); if (num != 0) { string text = ChatHistory.Step(ref _historyIndex, num); if (text != null) { _command.text = text; TMP_InputField command = _command; int caretPosition = (_command.stringPosition = text.Length); command.caretPosition = caretPosition; } } } public static void AddLog(string message) { if (string.IsNullOrEmpty(message)) { return; } message = message.Replace("</color></b></i></u></size></material>", "").Replace("<noparse>", "").Replace("</noparse>", ""); LogLines.Add(message); if (LogLines.Count > 200) { LogLines.RemoveRange(0, LogLines.Count - 200); } if (IsOpen) { UpdateStatus(); if (_tab == Tab.Log || _tab == Tab.Skins || _tab == Tab.SlotMachine || _tab == Tab.Favorites) { RebuildSoon(0.2f); } } } public static void SetHint(string hint) { _hint = hint; UpdateStatus(); } private static void UpdateStatus() { //IL_005b: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_status == (Object)null)) { ((TMP_Text)_status).text = ((!string.IsNullOrEmpty(_hint)) ? ("<color=#" + ColorUtility.ToHtmlStringRGB(UiKit.Accent) + ">" + _hint + "</color>") : ((LogLines.Count > 0) ? LogLines[LogLines.Count - 1] : "Hover anything for a description.")); } } private static void RebuildSoon(float delay) { float num = Time.unscaledTime + delay; if (_rebuildAt < 0f || num < _rebuildAt) { _rebuildAt = num; } } private static void Run(string line) { line = line.Trim(); if (line.Length != 0) { if (!line.StartsWith("/")) { line = "/" + line; } ChatHistory.Add(line.Replace(" confirm", "")); Commands.Execute(line); if (_tab == Tab.Skins || _tab == Tab.Favorites || _tab == Tab.SlotMachine || _tab == Tab.Log) { RebuildSoon(0.3f); } } } private static void RunDangerous(string line, Button button) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.RequireConfirm.Value || (_armed == line && Time.unscaledTime < _armedUntil)) { _armed = null; Run(line + " confirm"); } else { _armed = line; _armedUntil = Time.unscaledTime + 3f; UiKit.SetButtonText(button, "Sure? Click again", UiKit.Danger); } } private static Button DangerButton(Transform parent, string label, string line, float width = -1f, string hint = null) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) Button button = null; button = UiKit.Button(parent, label, delegate { RunDangerous(line, button); }, width, UiKit.Danger, hint); return button; } private static int Count() { if (!((Object)(object)_count != (Object)null) || !int.TryParse(_count.text, out var result)) { return 1; } return Mathf.Clamp(result, 1, 20); } private static List<string> Favorites() { return (from f in (Plugin.Favorites.Value ?? "").Split('|') where f.Length > 0 select f).ToList(); } private static bool IsFavorite(string line) { return Favorites().Contains(line); } private static void ToggleFavorite(string line) { List<string> list = Favorites(); if (!list.Remove(line)) { list.Add(line); } Plugin.Favorites.Value = string.Join("|", list); RebuildSoon(0f); } private static void Star(Transform parent, Func<string> line) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) bool flag = IsFavorite(line()); UiKit.Button(parent, flag ? "*" : "+", delegate { ToggleFavorite(line()); }, 44f, flag ? UiKit.Accent : UiKit.TextDim, flag ? "Remove from Favorites" : "Add to Favorites (with the text typed in the box)"); } private static void Build() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Expected O, but got Unknown //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Unknown result type (might be due to invalid IL or missing references) //IL_05db: Unknown result type (might be due to invalid IL or missing references) //IL_060f: Unknown result type (might be due to invalid IL or missing references) //IL_0676: Unknown result type (might be due to invalid IL or missing references) //IL_06ab: Unknown result type (might be due to invalid IL or missing references) //IL_06b2: Unknown result type (might be due to invalid IL or missing references) //IL_06b4: Unknown result type (might be due to invalid IL or missing references) //IL_06b5: Unknown result type (might be due to invalid IL or missing references) //IL_06bc: Unknown result type (might be due to invalid IL or missing references) //IL_06ce: Unknown result type (might be due to invalid IL or missing references) //IL_06d8: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_root != (Object)null) { Object.Destroy((Object)(object)_root); } _builtWithGameStyle = UiKit.FoundGameStyle; TabButtons.Clear(); _root = new GameObject("DevToolsUnlockedCanvas"); Object.DontDestroyOnLoad((Object)(object)_root); _canvas = _root.AddComponent<Canvas>(); _canvas.renderMode = (RenderMode)0; _canvas.sortingOrder = 32000; CanvasScaler obj = _root.AddComponent<CanvasScaler>(); obj.uiScaleMode = (ScaleMode)1; obj.matchWidthOrHeight = 1f; _root.AddComponent<GraphicRaycaster>(); Image val = UiKit.Panel(_root.transform, "Window", UiKit.PanelColor); _window = ((Graphic)val).rectTransform; RectTransform window = _window; RectTransform window2 = _window; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); window2.anchorMax = val2; window.anchorMin = val2; _window.pivot = new Vector2(0f, 1f); _window.sizeDelta = new Vector2(1180f, 760f); _window.anchoredPosition = new Vector2(-590f, 380f); VerticalLayoutGroup obj2 = ((Component)val).gameObject.AddComponent<VerticalLayoutGroup>(); ((LayoutGroup)obj2).padding = new RectOffset(14, 14, 10, 14); ((HorizontalOrVerticalLayoutGroup)obj2).spacing = 8f; bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true); ((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = childControlWidth; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = true; ((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false; HorizontalLayoutGroup obj3 = UiKit.Row(((Component)val).transform, 46f, 10f); DragMove dragMove = ((Component)obj3).gameObject.AddComponent<DragMove>(); dragMove.Target = _window; dragMove.Canvas = _canvas; ((Graphic)((Component)obj3).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.001f); _title = UiKit.Label(((Component)obj3).transform, "<b>Dev Tools</b>", 30f, UiKit.Accent, (TextAlignmentOptions)4097); UiKit.Size((Component)(object)_title, ((TMP_Text)_title).preferredWidth + 10f); _hostState = UiKit.Label(((Component)obj3).transform, "", 17f, UiKit.TextDim, (TextAlignmentOptions)4097); UiKit.Size((Component)(object)_hostState, -1f, -1f, 1f); ((Component)UiKit.Label(((Component)obj3).transform, "v1.0.0", 17f, UiKit.TextDim, (TextAlignmentOptions)4097)).gameObject.AddComponent<LayoutElement>().preferredWidth = 70f; UiKit.Button(((Component)obj3).transform, "X", Close, 46f, null, "Close (" + Plugin.PanelKeyName() + " or Esc)"); HorizontalLayoutGroup obj4 = UiKit.Row(((Component)val).transform); _search = UiKit.Input(((Component)obj4).transform, "Search this tab..."); ((UnityEvent<string>)(object)_search.onValueChanged).AddListener((UnityAction<string>)delegate { RebuildSoon(0.15f); }); UiKit.Hint((Component)(object)_search, "Filters the list below by name or description"); TextMeshProUGUI val3 = UiKit.Label(((Component)obj4).transform, "Spawn count", 17f, UiKit.TextDim, (TextAlignmentOptions)4097); UiKit.Size((Component)(object)val3, ((TMP_Text)val3).preferredWidth + 4f); _count = UiKit.Input(((Component)obj4).transform, "1", 70f); _count.characterValidation = (CharacterValidation)2; _count.characterLimit = 2; UiKit.Hint((Component)(object)_count, "How many to spawn per click (1 to 20)"); HorizontalLayoutGroup val4 = UiKit.Row(((Component)val).transform, -1f, 10f); UiKit.Size((Component)(object)val4, -1f, -1f, -1f, 1f); ((HorizontalOrVerticalLayoutGroup)val4).childForceExpandHeight = true; VerticalLayoutGroup val5 = UiKit.Column(((Component)val4).transform, 4f); UiKit.Size((Component)(object)val5, 200f, -1f, 0f); for (int num = 0; num < TabNames.Length; num++) { Tab tab = (Tab)num; Button val6 = UiKit.Button(((Component)val5).transform, TabNames[num], delegate { SelectTab(tab); }, 200f, null, TabHints[num]); UiKit.Size((Component)(object)val6, -1f, 40f); TabButtons.Add(val6); } _content = UiKit.Scroll(((Component)val4).transform, out _scroll); HorizontalLayoutGroup obj5 = UiKit.Row(((Component)val).transform); _command = UiKit.Input(((Component)obj5).transform, "Type a command, e.g. /spawn knife (Enter runs, Up/Down: history)"); ((UnityEvent<string>)(object)_command.onSubmit).AddListener((UnityAction<string>)delegate(string text) { Run(text); _command.text = ""; _historyIndex = -1; _command.ActivateInputField(); }); UiKit.Button(((Component)obj5).transform, "Run", delegate { Run(_command.text); _command.text = ""; }, 90f, null, "Runs the typed command"); UiKit.Button(((Component)obj5).transform, "Repeat last", delegate { if (ChatHistory.Last != null) { Run(ChatHistory.Last); } }, -1f, null, "Runs the last command again"); Image obj6 = UiKit.Panel(((Component)val).transform, "Status", UiKit.SectionColor); UiKit.Size((Component)(object)obj6, -1f, 56f, -1f, 0f); _status = UiKit.Label(((Component)obj6).transform, "", 17f, UiKit.Text, (TextAlignmentOptions)4097, wrap: true); ((TMP_Text)_status).overflowMode = (TextOverflowModes)1; UiKit.Stretch(((TMP_Text)_status).rectTransform, 10f, 4f, 10f, 4f); Image obj7 = UiKit.Panel(((Component)val).transform, "Resize", new Color(1f, 1f, 1f, 0.25f)); ((Component)obj7).gameObject.AddComponent<LayoutElement>().ignoreLayout = true; RectTransform rectTransform = ((Graphic)obj7).rectTransform; Vector2 val7 = default(Vector2); ((Vector2)(ref val7))..ctor(1f, 0f); rectTransform.pivot = val7; val2 = (rectTransform.anchorMin = (rectTransform.anchorMax = val7)); rectTransform.sizeDelta = new Vector2(18f, 18f); rectTransform.anchoredPosition = Vector2.zero; DragResize dragResize = ((Component)obj7).gameObject.AddComponent<DragResize>(); dragResize.Target = _window; dragResize.Canvas = _canvas; UiKit.Hint((Component)(object)obj7, "Drag to resize"); _root.SetActive(false); } private static void ApplyScale() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) _root.GetComponent<CanvasScaler>().referenceResolution = new Vector2(1920f, 1080f) / Mathf.Max(0.3f, Plugin.PanelScale.Value); } private static void SelectTab(Tab tab) { _tab = tab; _armed = null; if ((Object)(object)_search != (Object)null) { _search.SetTextWithoutNotify(""); } Rebuild(); } private static void RefreshHostState() { _wasHost = Commands.IsHost; if (!((Object)(object)_hostState == (Object)null)) { ((TMP_Text)_hostState).text = (Commands.IsHost ? "You are the host: everything works." : (((Object)(object)Player.LocalPlayer == (Object)null) ? "Join or host a world to use the commands." : "Client: the safe commands are sent to the host (it needs this mod). Red ones are host only.")); } } private static void Rebuild(bool keepScroll = false) { //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_content == (Object)null) { return; } float num = (((Object)(object)_scroll != (Object)null) ? _scroll.verticalNormalizedPosition : 1f); UiKit.Clear((Transform)(object)_content); RefreshHostState(); UpdateStatus(); for (int i = 0; i < TabButtons.Count; i++) { UiKit.SetButtonText(TabButtons[i], TabNames[i], (i == (int)_tab) ? new Color?(UiKit.Accent) : new Color?(UiKit.Text)); } string filter = (((Object)(object)_search != (Object)null) ? _search.text : "").Trim().ToLowerInvariant(); try { switch (_tab) { case Tab.Favorites: BuildFavorites(filter); break; case Tab.Commands: BuildCommands(filter); break; case Tab.Player: BuildPlayer(); break; case Tab.Creatures: BuildSpawn(filter, creatures: true); break; case Tab.Items: BuildSpawn(filter, creatures: false); break; case Tab.Skins: BuildSkins(filter); break; case Tab.SlotMachine: BuildSlotMachine(); break; case Tab.Islands: BuildIslands(filter); break; default: BuildLog(filter); break; } } catch (Exception arg) { Plugin.Log.LogError((object)$"Panel tab {_tab} failed: {arg}"); UiKit.Label((Transform)(object)_content, "This tab failed to load: see the BepInEx log.", 22f, UiKit.Danger, (TextAlignmentOptions)4097); } Canvas.ForceUpdateCanvases(); if ((Object)(object)_scroll != (Object)null) { _scroll.verticalNormalizedPosition = ((_tab == Tab.Log) ? 0f : (keepScroll ? num : 1f)); } } private static void Section(string title) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) UiKit.Size((Component)(object)UiKit.Label((Transform)(object)_content, "<b>" + title + "</b>", 22f, UiKit.Accent, (TextAlignmentOptions)4097), -1f, 34f); } private static void Note(string text) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) UiKit.Label((Transform)(object)_content, text, 17f, UiKit.TextDim, (TextAlignmentOptions)257, wrap: true); } private static bool Matches(string filter, params string[] texts) { if (filter.Length != 0) { return texts.Any((string t) => t?.ToLowerInvariant().Contains(filter) ?? false); } return true; } private static void LineRow(string line) { HorizontalLayoutGroup obj = UiKit.Row((Transform)(object)_content); Star(((Component)obj).transform, () => line); UiKit.Size((Component)(object)UiKit.Label(((Component)obj).transform, line, 22f, null, (TextAlignmentOptions)4097), -1f, -1f, 1f); UiKit.Button(((Component)obj).transform, "Run", delegate { Run(line); }, 90f); } private static void BuildFavorites(string filter) { Section("Favorites"); List<string> list = (from f in Favorites() where Matches(filter, f) select f).ToList(); if (list.Count == 0) { Note("Click + next to any command, item or line to keep it here."); } foreach (string item in list) { LineRow(item); } Section("Recent"); List<string> list2 = (from l in ChatHistory.All.Reverse() where Matches(filter, l) select l).Take(15).ToList(); if (list2.Count == 0) { Note("The commands you run (here or in the chat) show up here."); } foreach (string item2 in list2) { LineRow(item2); } } private static void BuildCommands(string filter) { Section("Game commands"); foreach (CommandInfo item in Commands.Game.Where((CommandInfo c) => Matches(filter, c.Name, c.Help))) { CommandRow(item); } Section("DevToolsUnlocked commands"); foreach (CommandInfo item2 in Commands.Mod.Where((CommandInfo c) => Matches(filter, c.Name, c.Help))) { CommandRow(item2); } } private static void CommandRow(CommandInfo cmd) { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) bool flag = !cmd.HostOnly || Commands.IsHost || Remote.Allowed.Contains(cmd.Name); VerticalLayoutGroup obj = UiKit.Column((Transform)(object)_content, 2f); HorizontalLayoutGroup val = UiKit.Row(((Component)obj).transform); TMP_InputField args = null; Func<string> line = () => (!((Object)(object)args != (Object)null) || args.text.Trim().Length <= 0) ? ("/" + cmd.Name) : ("/" + cmd.Name + " " + args.text.Trim()); Star(((Component)val).transform, line); UiKit.Size((Component)(object)UiKit.Label(color: (!flag) ? UiKit.TextDim : (cmd.Destructive ? UiKit.Danger : UiKit.Text), parent: ((Component)val).transform, text: "<b>/" + cmd.Name + "</b>", size: 22f, align: (TextAlignmentOptions)4097), 260f); if (!string.IsNullOrEmpty(cmd.Args)) { args = UiKit.Input(((Component)val).transform, cmd.Args); } else { UiKit.Size((Component)(object)((Component)UiKit.Rect("Spacer", ((Component)val).transform)).gameObject.AddComponent<LayoutElement>(), -1f, -1f, 1f); } Button run; if (!flag) { run = UiKit.Button(((Component)val).transform, "Host only", null, 130f, UiKit.TextDim, "Only the host can use this one"); ((Selectable)run).interactable = false; } else if (cmd.Destructive) { run = DangerButton(((Component)val).transform, "Run", "/" + cmd.Name, 130f, cmd.Help); } else { run = UiKit.Button(((Component)val).transform, "Run", delegate { Run(line()); }, 130f, null, cmd.Help); } if ((Object)(object)args != (Object)null) { ((UnityEvent<string>)(object)args.onSubmit).AddListener((UnityAction<string>)delegate { ((UnityEvent)run.onClick).Invoke(); }); } string text = cmd.Help; if (cmd.HostOnly && !Commands.IsHost && flag) { text += " <i>(asks the host)</i>"; } TextMeshProUGUI obj2 = UiKit.Label(((Component)obj).transform, text, 17f, UiKit.TextDim, (TextAlignmentOptions)4097); ((TMP_Text)obj2).margin = new Vector4(52f, 0f, 0f, 0f); UiKit.Size((Component)(object)obj2, -1f, 22f); } private static List<SpawnInfo> Spawnables() { if (_spawnables != null && _spawnables.Count > 0) { return _spawnables; } _spawnables = new List<SpawnInfo>(); foreach (string item in Commands.SpawnableNames()) { Item spawnable = GameInfo.GetSpawnable(item); if (!((Object)(object)spawnable == (Object)null)) { string text = Commands.SafeName(spawnable); _spawnables.Add(new SpawnInfo { Key = item, Display = ((text == ((Object)spawnable).name) ? "" : text), IsCreature = ((Object)(object)((Component)spawnable).GetComponent<Creature>() != (Object)null), Category = CategoryOf(spawnable) }); } } if (_spawnables.Count > 0) { Commands.WriteItemList(); } return _spawnables; } private static string CategoryOf(Item item) { if ((Object)(object)((Component)item).GetComponent<Creature>() != (Object)null) { return "Creatures"; } if (item.IsQuestItem) { return "Quest"; } if (item is Explosive) { return "Explosives"; } if (item is Weapon || item is Melee) { return "Weapons"; } if (item is Tool || item is Map || item is Radio || item is GroundBait) { return "Tools"; } return "Other"; } private static void BuildSpawn(string filter, bool creatures) { //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) List<SpawnInfo> list = (from s in Spawnables() where s.IsCreature == creatures select s).ToList(); if (list.Count == 0) { Note("The item list loads with the game. Join a world and open the panel again."); return; } if (!creatures) { HorizontalLayoutGroup val = UiKit.Row((Transform)(object)_content); string[] itemCategories = ItemCategories; foreach (string text in itemCategories) { string c = text; int num2 = ((c == "All") ? list.Count : list.Count((SpawnInfo s) => s.Category == c)); UiKit.Button(((Component)val).transform, $"{c} ({num2})", delegate { _itemCategory = c; Rebuild(); }, -1f, (_itemCategory == c) ? new Color?(UiKit.Accent) : ((Color?)null)); } if (_itemCategory != "All") { list = list.Where((SpawnInfo s) => s.Category == _itemCategory).ToList(); } } List<SpawnInfo> list2 = list.Where((SpawnInfo s) => Matches(filter.Replace(" ", ""), s.Key) || Matches(filter, s.Display)).ToList(); Note(creatures ? $"{list2.Count} creatures. Spawn count sets how many per click. A dead drip creature feeds the slot machine." : $"{list2.Count} items. Spawn count sets how many per click. Full list: BepInEx/config/DevToolsUnlocked/spawnables.txt (/items)."); foreach (SpawnInfo item in list2.Take(120)) { HorizontalLayoutGroup val2 = UiKit.Row((Transform)(object)_content); string key = item.Key; Star(((Component)val2).transform, () => "/spawn " + key); UiKit.Size((Component)(object)UiKit.Label(((Component)val2).transform, (item.Display.Length > 0) ? (item.Key + " <color=#" + Hex(UiKit.TextDim) + ">" + item.Display + "</color>") : item.Key, 22f, null, (TextAlignmentOptions)4097), -1f, -1f, 1f); if (creatures) { SpawnButton(((Component)val2).transform, "Spawn", "spawn", key, enabled: true); SpawnButton(((Component)val2).transform, "Dead", "spawndead", key, enabled: true); SpawnButton(((Component)val2).transform, "Drip", "spawndrip", key, enabled: true); SpawnButton(((Component)val2).transform, "Drip dead", "spawndripdead", key, enabled: true); } else { ((Component)UiKit.Label(((Component)val2).transform, item.Category, 17f, UiKit.TextDim, (TextAlignmentOptions)4097)).gameObject.AddComponent<LayoutElement>().preferredWidth = 110f; SpawnButton(((Component)val2).transform, "Spawn", "spawn", key, enabled: true); } } if (list2.Count > 120) { Note($"{list2.Count - 120} more: type in the search box to narrow it down."); } } private static void BuildPlayer() { //IL_000f: 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) _playerState = UiKit.Label((Transform)(object)_content, "", 22f, UiKit.Text, (TextAlignmentOptions)257, wrap: true); PlayerStats.Clear(); _playerCount = PlayerManager.Players.Count((Player p) => (Object)(object)p != (Object)null); Section("Players"); foreach (Player item in (from p in PlayerManager.Players where (Object)(object)p != (Object)null orderby (Object)(object)p == (Object)(object)Player.LocalPlayer descending, p.SteamName select p).ToList()) { PlayerRow(item); } EveryoneRow(); Section("World"); HorizontalLayoutGroup obj = UiKit.Row((Transform)(object)_content); UiKit.Button(((Component)obj).transform, "God mode for all (game)", delegate { Run("/godmode"); }, -1f, null, "The game's own god mode: nobody takes damage (/godmode)"); UiKit.Button(((Component)obj).transform, "Toggle one-shot", delegate { Run("/oneshot"); }, -1f, null, "Every hit kills (/oneshot)"); UiKit.Button(((Component)obj).transform, "Kill the boss", delegate { Run("/killboss"); }, -1f, null, "/killboss"); UpdatePlayerState(); Section("Money (shared by the team)"); HorizontalLayoutGroup obj2 = UiKit.Row((Transform)(object)_content); TextMeshProUGUI val = UiKit.Label(((Component)obj2).transform, "Amount", 17f, UiKit.TextDim, (TextAlignmentOptions)4097); UiKit.Size((Component)(object)val, ((TMP_Text)val).preferredWidth + 4f); TMP_InputField obj3 = UiKit.Input(((Component)obj2).transform, "1000", 140f); obj3.text = _moneyAmount; obj3.characterValidation = (CharacterValidation)2; ((UnityEvent<string>)(object)obj3.onValueChanged).AddListener((UnityAction<string>)delegate(string moneyAmount) { _moneyAmount = moneyAmount; }); UiKit.Button(((Component)obj2).transform, "+ $", delegate { Run($"/money {Amount()}"); }, 80f, null, "Adds that many dollars"); UiKit.Button(((Component)obj2).transform, "- $", delegate { Run($"/money -{Amount()}"); }, 80f, null, "Removes that many dollars"); UiKit.Button(((Component)obj2).transform, "+ €", delegate { Run($"/money {Amount()} euro"); }, 80f, null, "Adds that many euro"); UiKit.Button(((Component)obj2).transform, "- €", delegate { Run($"/money -{Amount()} euro"); }, 80f, null, "Removes that many euro"); HorizontalLayoutGroup val2 = UiKit.Row((Transform)(object)_content); int[] array = new int[4] { 100, 1000, 10000, 100000 }; foreach (int num2 in array) { int v = num2; UiKit.Button(((Component)val2).transform, $"+{v} $", delegate { Run($"/money {v}"); }, -1f, null, $"/money {v}"); } if (!Commands.IsHost) { Note("As a client these are sent to the host, which needs DevToolsUnlocked. God mode's state is only known by the host."); } } private static int Amount() { if (!int.TryParse(_moneyAmount, out var result)) { return 1000; } return Mathf.Clamp(Math.Abs(result), 1, 9999999); } private static string TargetArg(Player player) { if (!((Object)(object)player == (Object)(object)Player.LocalPlayer)) { return player.SteamName; } return "me"; } private static void PlayerRow(Player player) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0075: 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) bool flag = (Object)(object)player == (Object)(object)Player.LocalPlayer; string who = TargetArg(player); VerticalLayoutGroup obj = UiKit.Column((Transform)(object)_content, 2f); HorizontalLayoutGroup obj2 = UiKit.Row(((Component)obj).transform); UiKit.Size((Component)(object)UiKit.Label(((Component)obj2).transform, "<b>" + WorldTools.Name(player) + "</b>" + (flag ? " (you)" : ""), 22f, flag ? UiKit.Accent : UiKit.Text, (TextAlignmentOptions)4097), -1f, -1f, 1f); TextMeshProUGUI val = UiKit.Label(((Component)obj2).transform, "", 17f, UiKit.TextDim, (TextAlignmentOptions)4100); UiKit.Size((Component)(object)val, 330f); PlayerStats.Add(new KeyValuePair<Player, TextMeshProUGUI>(player, val)); HorizontalLayoutGroup val2 = UiKit.Row(((Component)obj).transform); UiKit.Button(((Component)val2).transform, "God mode", delegate { Run("/god " + who); }, -1f, null, "Turns god mode on or off for " + WorldTools.Name(player) + " (/god)"); UiKit.Button(((Component)val2).transform, "Heal", delegate { Run("/heal " + who); }, -1f, null, "Fills health and hunger (/heal)"); UiKit.Button(((Component)val2).transform, "Hurt 25", delegate { Run("/hurt 25 " + who); }, -1f, null, "25 damage, unless in god mode (/hurt)"); DangerButton(((Component)val2).transform, "Kill", "/kill " + who, -1f, "Kills, unless in god mode (/kill)"); if (!flag) { UiKit.Button(((Component)val2).transform, "Bring here", delegate { Run("/bring " + who); }, -1f, null, "Teleports them in front of you (/bring)"); UiKit.Button(((Component)val2).transform, "Go to", delegate { Run("/goto " + who); }, -1f, null, "Teleports you next to them (/goto)"); } } private static void EveryoneRow() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) VerticalLayoutGroup obj = UiKit.Column((Transform)(object)_content, 2f); ((Component)UiKit.Label(((Component)obj).transform, "<b>Everyone</b>", 22f, UiKit.Text, (TextAlignmentOptions)4097)).gameObject.AddComponent<LayoutElement>().preferredHeight = 40f; HorizontalLayoutGroup obj2 = UiKit.Row(((Component)obj).transform); UiKit.Button(((Component)obj2).transform, "God mode", delegate { Run("/god all"); }, -1f, null, "God mode on for everyone (off if they all have it)"); UiKit.Button(((Component)obj2).transform, "Heal", delegate { Run("/heal all"); }, -1f, null, "/heal all"); UiKit.Button(((Component)obj2).transform, "Hurt 25", delegate { Run("/hurt 25 all"); }, -1f, null, "/hurt 25 all"); DangerButton(((Component)obj2).transform, "Kill", "/kill all", -1f, "/kill all"); UiKit.Button(((Component)obj2).transform, "Bring everyone here", delegate { Run("/bring all"); }, -1f, null, "/bring all"); } private static void UpdatePlayerState() { //IL_0189: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_playerState == (Object)null) { return; } if ((Object)(object)Player.LocalPlayer == (Object)null) { ((TMP_Text)_playerState).text = "Join a world to see the players."; return; } if (PlayerManager.Players.Count((Player p) => (Object)(object)p != (Object)null) != _playerCount) { RebuildSoon(0f); return; } string text = (Commands.IsHost ? (" God mode for all (game) " + On(PlayerManager.InGodMode)) : ""); string text2 = (((Object)(object)ServerSettings.Instance != (Object)null) ? (" One-shot " + On(ServerSettings.OneShotEnabled)) : ""); ((TMP_Text)_playerState).text = $"Money ${MoneyManager.Money} €{MoneyManager.Euro}{text}{text2}"; foreach (KeyValuePair<Player, TextMeshProUGUI> playerStat in PlayerStats) { if (!((Object)(object)playerStat.Key == (Object)null) && !((Object)(object)playerStat.Value == (Object)null)) { PlayerVitals vitals = playerStat.Key.Vitals; string text3 = (((Object)(object)vitals != (Object)null) ? $"Health {vitals.Health} Hunger {vitals.Fullness}" : ""); if (Commands.IsHost && WorldTools.IsGod(playerStat.Key)) { text3 = text3 + " <color=#" + Hex(UiKit.Accent) + ">GOD</color>"; } ((TMP_Text)playerStat.Value).text = text3; } } static string On(bool on) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (!on) { return "off"; } return "<color=#" + Hex(UiKit.Accent) + ">ON</color>"; } } private static void SpawnButton(Transform parent, string label, string cmd, string key, bool enabled) { ((Selectable)UiKit.Button(parent, label, delegate { int num = Count(); for (int i = 0; i < num; i++) { Run("/" + cmd + " " + key); } }, (label.Length > 5) ? 130 : 90, null, "/" + cmd + " " + key)).interactable = enabled; } private static void BuildSkins(string filter) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_0560: Unknown result type (might be due to invalid IL or missing references) //IL_0351: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_03cc: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Unknown result type (might be due to invalid IL or missing references) //IL_04d2: Unknown result type (might be due to invalid IL or missing references) //IL_04d8: Invalid comparison between Unknown and I4 List<SkinTools.Target> list = SkinTools.AllTargets(); if (list.Count == 0) { Note("Skins load with a world."); return; } _skinTarget = Mathf.Clamp(_skinTarget, 0, list.Count - 1); SkinTools.Target target = list[_skinTarget]; string arg = (target.IsBoat ? "boat" : target.ID.ToString()); GridLayoutGroup val = UiKit.Grid((Transform)(object)_content, 190f, 5); for (int i = 0; i < list.Count; i++) { int index = i; UiKit.Button(((Component)val).transform, list[i].Label, delegate { _skinTarget = index; Rebuild(); }, -1f, (i == _skinTarget) ? new Color?(UiKit.Accent) : ((Color?)null)); } HashSet<byte> hashSet = SkinTools.Owned(target.ID); int num = ((target.Preset.Skins.Count((ItemSkin s) => (int)((ItemSkin)(ref s)).Rarity > 0) != 0) ? hashSet.Count : 0); Section($"{target.Label}: {num} of {target.Preset.Skins.Count((ItemSkin s) => (int)((ItemSkin)(ref s)).Rarity > 0)} unlocked"); string text = Commands.ForcedPrize(); if (text != null) { Note("Forced slot machine prize: " + text + " (Slot machine tab to clear it)."); } HorizontalLayoutGroup obj = UiKit.Row((Transform)(object)_content); UiKit.Button(((Component)obj).transform, "Unlock all", delegate { Run("/unlockskin " + arg + " all"); }, -1f, null, "Unlocks every skin of this item in your save"); DangerButton(((Component)obj).transform, "Lock all", "/lockskin " + arg + " all", -1f, "Locks every skin of this item (backs up first)"); UiKit.Button(((Component)obj).transform, "Back up skins", delegate { Run("/backupskins"); }, -1f, null, "Saves a copy of all your unlocked skins"); for (int num2 = 0; num2 < target.Preset.Skins.Count; num2++) { ItemSkin val2 = target.Preset.Skins[num2]; if (!Matches(filter, ((ItemSkin)(ref val2)).Name, ((object)((ItemSkin)(ref val2)).Rarity/*cast due to .constrained prefix*/).ToString())) { continue; } int index2 = num2; bool has = num2 == 0 || hashSet.Contains((byte)num2); HorizontalLayoutGroup val3 = UiKit.Row((Transform)(object)_content); ((Component)UiKit.Label(((Component)val3).transform, num2.ToString(), 22f, UiKit.TextDim, (TextAlignmentOptions)4097)).gameObject.AddComponent<LayoutElement>().preferredWidth = 40f; UiKit.Size((Component)(object)UiKit.Label(((Component)val3).transform, ((ItemSkin)(ref val2)).Name, 22f, has ? UiKit.Text : UiKit.TextDim, (TextAlignmentOptions)4097), -1f, -1f, 1f); string text2 = ((num2 == 0) ? "Default" : (((int)((ItemSkin)(ref val2)).Rarity == 0) ? "Unobtainable" : ((object)((ItemSkin)(ref val2)).Rarity/*cast due to .constrained prefix*/).ToString())); ((Component)UiKit.Label(((Component)val3).transform, "<color=#" + Commands.RarityColor(((ItemSkin)(ref val2)).Rarity) + ">" + text2 + "</color>", 17f, null, (TextAlignmentOptions)4097)).gameObject.AddComponent<LayoutElement>().preferredWidth = 130f; if (num2 == 0) { ((Component)UiKit.Label(((Component)val3).transform, "default skin", 17f, UiKit.TextDim, (TextAlignmentOptions)4097)).gameObject.AddComponent<LayoutElement>().preferredWidth = 120f; } else { UiKit.Button(((Component)val3).transform, has ? "Lock" : "Unlock", delegate { Run(string.Format("/{0} {1} {2}", has ? "lockskin" : "unlockskin", arg, index2)); }, 120f); } ((Selectable)UiKit.Button(((Component)val3).transform, "Win next rolls", delegate { Run($"/slots {arg} {index2}"); }, 190f, null, "Every slot machine roll gives this skin until you turn it off (/slots off)")).interactable = (int)((ItemSkin)(ref val2)).Rarity > 0; } List<string> list2 = SkinTools.Backups().Take(5).ToList(); if (list2.Count > 0) { Section("Restore a skin backup"); for (int num3 = 0; num3 < list2.Count; num3++) { HorizontalLayoutGroup obj2 = UiKit.Row((Transform)(object)_content); UiKit.Size((Component)(object)UiKit.Label(((Component)obj2).transform, Path.GetFileNameWithoutExtension(list2[num3]).Substring(6), 17f, UiKit.TextDim, (TextAlignmentOptions)4097), -1f, -1f, 1f); DangerButton(((Component)obj2).transform, "Restore", "/restoreskins " + (num3 + 1), 160f, "Replaces your skins with this backup (the current ones are backed up first)"); } } } private static void BuildSlotMachine() { HorizontalLayoutGroup obj = UiKit.Row((Transform)(object)_content); UiKit.Button(((Component)obj).transform, "Roll now", delegate { Run("/roll"); }, -1f, null, "Rolls the slot machine on this island for you, without feeding it"); UiKit.Button(((Component)obj).transform, "Random rolls again", delegate { Run("/slots off"); }, -1f, null, "Clears the forced prize (/slots off)"); UiKit.Button(((Component)obj).transform, "Spawn a dead drip fish", delegate { SelectTab(Tab.Creatures); }, -1f, null, "Opens the Creatures tab: Drip dead on a creature makes something you can drop in the machine"); Section("Prize pool"); Note(Commands.SlotPoolText()); Note("To force a prize, use \"Win next rolls\" on a skin in the Skins tab. The skin is unlocked on the game of whoever rolled."); } private static void BuildIslands(string filter) { bool flag = Commands.IsHost || Remote.Allowed.Contains("island"); HorizontalLayoutGroup obj = UiKit.Row((Transform)(object)_content); ((Selectable)UiKit.Button(((Component)obj).transform, "< Previous island", delegate { Run("/previsland"); }, -1f, null, "/previsland")).interactable = flag; ((Selectable)UiKit.Button(((Component)obj).transform, "Next island >", delegate { Run("/nextisland"); }, -1f, null, "/nextisland")).interactable = flag; ((Selectable)UiKit.Button(((Component)obj).transform, "Random mini island", delegate { Run("/island mini"); }, -1f, null, "/island mini: a random mini island in open sea near you")).interactable = flag; List<string> source = (from n in Commands.IslandNames() where Matches(filter, n) select n).ToList(); IslandGrid("Main islands", source.Where((string n) => !WorldTools.IsMini(n)).ToList(), flag); IslandGrid("Mini islands", source.Where(WorldTools.IsMini).ToList(), flag); Note("Teleports everyone in the lobby. Mini islands appear in open sea near you; if you're too close to a main island, sail away a bit."); } private static void IslandGrid(string title, List<string> names, bool available) { if (names.Count == 0) { return; } Section(title); GridLayoutGroup val = UiKit.Grid((Transform)(object)_content, 220f, 4); foreach (string name2 in names) { string name = name2; ((Selectable)UiKit.Button(((Component)val).transform, name, delegate { Run("/island " + name); }, -1f, null, "/island " + name)).interactable = available; } } private static void BuildLog(string filter) { //IL_00ac: Unknown result type (might be due to invalid IL or missing references) UiKit.Button(((Component)UiKit.Row((Transform)(object)_content)).transform, "Clear", delegate { LogLines.Clear(); Rebuild(); }); List<string> list = LogLines.Where((string l) => Matches(filter, l)).ToList(); foreach (string item in list.Skip(Math.Max(0, list.Count - 120))) { UiKit.Label((Transform)(object)_content, item, 17f, UiKit.Text, (TextAlignmentOptions)257, wrap: true); } } private static string Hex(Color c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return ColorUtility.ToHtmlStringRGBA(c); } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class BlockInputsPatch { private static void Postfix(ref bool __result) { if (DevPanel.IsOpen) { __result = true; } } } [HarmonyPatch(typeof(ChatManager), "ToggleChat")] internal static class ToggleChatPatch { private static bool Prefix(bool to) { if (to) { return !DevPanel.IsOpen; } return true; } } [HarmonyPatch(typeof(PauseManager), "PauseInput")] internal static class PauseInputPatch { private static bool Prefix() { if (!DevPanel.IsOpen) { return true; } DevPanel.Close(); return false; } } public sealed class ModInput { public const string KeyboardGroup = "Keyboard"; public const string ControllerGroup = "Controller"; public static readonly Guid OpenPanelKeyboardId = new Guid("8c41d2e7-5b39-4a6f-a0d8-71e9f3b2c501"); public static readonly Guid OpenPanelControllerId = new Guid("8c41d2e7-5b39-4a6f-a0d8-71e9f3b2c502"); private readonly InputActionAsset _asset; private readonly InputActionMap _map; private readonly ConfigEntry<string> _overrides; public InputAction OpenPanel { get; } public ModInput(ConfigEntry<string> overrides) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown _overrides = overrides; _asset = ScriptableObject.CreateInstance<InputActionAsset>(); ((Object)_asset).name = "DevToolsUnlockedInput"; Object.DontDestroyOnLoad((Object)(object)_asset); _map = new InputActionMap("DevToolsUnlocked"); InputActionSetupExtensions.AddActionMap(_asset, _map); OpenPanel = InputActionSetupExtensions.AddAction(_map, "OpenDevToolsPanel", (InputActionType)1, (string)null, (string)null, (string)null, (string)null, (string)null); AddBinding(OpenPanel, OpenPanelKeyboardId, "<Keyboard>/f8", "Keyboard"); AddBinding(OpenPanel, OpenPanelControllerId, "", "Controller"); Load(); InputSystem.onActionChange += OnActionChange; _map.Enable(); } private void AddBinding(InputAction action, Guid id, string path, string group) { //IL_0008: 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_0035: Unknown result type (might be due to invalid IL or missing references) InputActionMap map = _map; InputBinding val = default(InputBinding); ((InputBinding)(ref val)).id = id; ((InputBinding)(ref val)).path = path; ((InputBinding)(ref val)).groups = group; ((InputBinding)(ref val)).action = action.name; InputActionSetupExtensions.AddBinding(map, val); } private void Load() { if (string.IsNullOrEmpty(_overrides.Value)) { return; } try { InputActionRebindingExtensions.LoadBindingOverridesFromJson((IInputActionCollection2)(object)_asset, _overrides.Value, true); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Ignoring invalid saved bindings: " + ex.Message)); } } private void OnActionChange(object obj, InputActionChange change) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 if ((int)change != 8) { return; } object obj2 = ((obj is InputAction) ? obj : null); if ((((obj2 != null) ? ((InputAction)obj2).actionMap : null) ?? ((obj is InputActionMap) ? obj : null)) == _map || obj == _asset) { string text = InputActionRebindingExtensions.SaveBindingOverridesAsJson((IInputActionCollection2)(object)_asset); if (text != _overrides.Value) { _overrides.Value = text; } } } } [BepInPlugin("avidkaos.howtofish.devtoolsunlocked", "DevToolsUnlocked", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "avidkaos.howtofish.devtoolsunlocked"; public const string PluginName = "DevToolsUnlocked"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; internal static ConfigEntry<bool> RequireConfirm; internal static ConfigEntry<bool> AllowAchievements; internal static ConfigEntry<float> PanelScale; internal static ConfigEntry<bool> ClientCommands; internal static ConfigEntry<string> Favorites; private static ModInput _input; private ConfigEntry<string> _bindings; private void Awake() { //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown //IL_00f6: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; RequireConfirm = ((BaseUnityPlugin)this).Config.Bind<bool>("Safety", "RequireConfirm", true, "Commands that change the save for good (/allskins, /noskins, /finishgame, journal resets...) need \"confirm\" typed after them, or a second click in the panel."); AllowAchievements = ((BaseUnityPlugin)this).Config.Bind<bool>("Safety", "AllowAchievementCommands", false, "Allow /unlockachievements and /lockachievements, which change your real Steam achievements."); ClientCommands = ((BaseUnityPlugin)this).Config.Bind<bool>("Multiplayer", "ClientCommands", true, "When you host: run the safe commands (spawn, godmode, islands, slot machine... not the ones that change the save) that players with this mod send. Everyone sees in the chat who used what."); PanelScale = ((BaseUnityPlugin)this).Config.Bind<float>("Panel", "Scale", 1f, new ConfigDescription("Size of the dev tools panel (on top of the automatic scaling for the screen height).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>())); Favorites = ((BaseUnityPlugin)this).Config.Bind<string>("Panel", "Favorites", "", "Command lines starred in the panel, separated by |."); _bindings = ((BaseUnityPlugin)this).Config.Bind<string>("Controls", "BindingOverrides", "", "Rebinds made in the game's Controls menu (Dev Tools Panel row). Clear to restore the default (F8)."); new Harmony("avidkaos.howtofish.devtoolsunlocked").PatchAll(typeof(Plugin).Assembly); Log.LogInfo((object)"DevToolsUnlocked 1.0.0 loaded"); } private void Start() { try { _input = new ModInput(_bindings); ControlsMenu.Init(_input); } catch (Exception arg) { Log.LogError((object)$"Could not create the panel key: {arg}"); } } private void Update() { ControlsMenu.ProcessPending(); ChatHistory.Update(); Remote.Update(); if (_input != null && _input.OpenPanel.WasPressedThisFrame()) { DevPanel.Toggle(); } DevPanel.Update(); DevPanel.KeepCursorFree(); } private void LateUpdate() { DevPanel.KeepCursorFree(); } public static string PanelKeyName() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) try { if (_input != null) { int bindingIndex = InputActionRebindingExtensions.GetBindingIndex(_input.OpenPanel, InputBinding.MaskByGroup("Keyboard")); if (bindingIndex >= 0) { string bindingDisplayString = InputActionRebindingExtensions.GetBindingDisplayString(_input.OpenPanel, bindingIndex, (DisplayStringOptions)0); if (!string.IsNullOrEmpty(bindingDisplayString)) { return bindingDisplayString; } } } } catch (Exception) { } return "F8"; } } public static class Remote { public const string Tag = "[DevTools]"; public static readonly HashSet<string> Allowed = new HashSet<string> { "spawn", "spawndead", "spawndrip", "spawndripdead", "godmode", "oneshot", "killboss", "addmoney", "removemoney", "nextisland", "previsland", "island", "slots", "roll", "heal", "hurt", "money", "god", "kill", "bring", "goto" }; private static string _waiting; private static float _waitUntil; public static Player Requester { get; private set; } public static bool TrySend(string name, string line) { if (!Allowed.Contains(name)) { return false; } if ((Object)(object)Server.Instance == (Object)null || !((NetworkBehaviour)Server.Instance).IsClientInitialized) { Commands.Reply("Join a world first."); return true; } Server.Instance.SendChatMessage(line, (NetworkConnection)null); _waiting = line; _waitUntil = Time.unscaledTime + 5f; return true; } public static void Update() { if (_waiting != null && Time.unscaledTime > _waitUntil) { Commands.Reply("No answer from the host for " + _waiting + ": the host needs DevToolsUnlocked with ClientCommands on."); _waiting = null; } } public static void OnChatLine(string message) { if (_waiting != null && message != null && message.Contains("[DevTools]")) { _waiting = null; } } public static bool HandleOnHost(string message, NetworkConnection conn) { if (string.IsNullOrEmpty(message) || !message.StartsWith("/") || !Commands.IsHost || conn == (NetworkConnection)null || conn.IsLocalClient) { return false; } Player val = ((IEnumerable<Player>)PlayerManager.Players).FirstOrDefault((Func<Player, bool>)((Player p) => (Object)(object)p != (Object)null && ((NetworkBehaviour)p).Owner == conn)); if ((Object)(object)val == (Object)null) { return true; } string text = (string.IsNullOrEmpty(val.SteamName) ? "A player" : val.SteamName); if (!Plugin.ClientCommands.Value) { Announce(text + " asked for " + message + ", but the host turned client commands off."); return true; } string[] array = message.Substring(1).Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string text2 = ((array.Length != 0) ? array[0].ToLowerInvariant() : ""); if (!Allowed.Contains(text2)) { Announce(text + ": /" + text2 + " only works for the host."); return true; } Announce(text + ": " + message); Requester = val; try { Commands.Execute(message); } finally { Requester = null; } return true; } public static void Announce(string text) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) text = "[DevTools] " + Regex.Replace(text, "<.*?>", ""); OnlineChatManager instance = OnlineChatManager.Instance; if ((Object)(object)instance != (Object)null && ((NetworkBehaviour)instance).IsServerInitialized) { instance.SendChatMessage(SteamManager.CurrentLobbyID.m_SteamID, text); } else { ChatManager.ChatMessage(text); } } } [HarmonyPatch] internal static class ServerChatRpcPatch { private static MethodBase TargetMethod() { return AccessTools.GetDeclaredMethods(typeof(Server)).FirstOrDefault((MethodInfo m) => m.Name.StartsWith("RpcLogic___SendChatMessage") && m.GetParameters().Length == 2 && m.GetParameters()[0].ParameterType == typeof(string) && m.GetParameters()[1].ParameterType == typeof(NetworkConnection)); } private static bool Prepare() { bool num = TargetMethod() != null; if (!num) { Plugin.Log.LogWarning((object)"Server chat RPC not found: clients can't send commands to this host."); } return num; } private static bool Prefix(string __0, NetworkConnection __1) { try { return !Remote.HandleOnHost(__0, __1); } catch (Exception arg) { Plugin.Log.LogError((object)$"Client command {__0} failed: {arg}"); return false; } } } public static class SkinTools { public sealed class Target { public byte ID; public Item Item; public SkinPreset Preset; public string Label; public bool IsBoat => ID == byte.MaxValue; } [Serializable] private class SkinBackup { public List<SavedItemSkin> UnlockedItemSkins = new List<SavedItemSkin>(); public List<byte> UnlockedBoatSkins = new List<byte>(); } private static readonly FieldInfo LocalSaveField = AccessTools.Field(typeof(SaveManager), "_curLocalSave"); private const string BackupPrefix = "skins-"; private static LocalSaveObject LocalSave { get { object? obj = LocalSaveField?.GetValue(null); return (LocalSaveObject)((obj is LocalSaveObject) ? obj : null); } } private static string BackupFolder { get { string text = Path.Combine(Commands.DataFolder, "skin-backups"); Directory.CreateDirectory(text); return text; } } public static List<Target> AllTargets() { List<Target> list = new List<Target>(); try { Item[] array = (Item[])(((object)GameInfo.ItemWithSkinsforCommands) ?? ((object)new Item[0])); foreach (Item val in array) { if ((Object)(object)val != (Object)null && (Object)(object)val.SkinPreset != (Object)null) { list.Add(new Target { ID = val.ID, Item = val, Preset = val.SkinPreset, Label = Commands.SafeName(val) }); } } } catch (Exception) { } if ((Object)(object)BoatManager.Boat != (Object)null && (Object)(object)BoatManager.Boat.SkinPreset != (Object)null) { list.Add(new Target { ID = byte.MaxValue, Preset = BoatManager.Boat.SkinPreset, Label = "Boat" }); } return list; } public static bool Resolve(string name, out Target target) { target = null; name = (name ?? "").Replace(" ", "").ToLowerInvariant(); if (name.Length == 0) { Commands.Reply("Name an item (/items lists them) or \"boat\"."); return false; } if (name == "boat" || name == "255") { if ((Object)(object)BoatManager.Boat == (Object)null) { Commands.Reply("The boat isn't loaded: join a world first."); return false; } target = new Target { ID = byte.MaxValue, Preset = BoatManager.Boat.SkinPreset, Label = "Boat" }; return true; } byte result; Item val = (byte.TryParse(name, out result) ? GameInfo.IDToItem(result) : GameInfo.GetSpawnable(name)); if ((Object)(object)val == (Object)null) { Commands.Reply("No item called \"" + name + "\". /items lists the names."); return false; } if ((Object)(object)val.SkinPreset == (Object)null) { Commands.Reply(Commands.SafeName(val) + " has no skins."); return false; } target = new Target { ID = val.ID, Item = val, Preset = val.SkinPreset, Label = Commands.SafeName(val) }; return true; } public static HashSet<byte> Owned(byte id) { LocalSaveObject localSave = LocalSave; if (localSave == null) { return new HashSet<byte>(); } if (id == byte.MaxValue) { return new HashSet<byte>(localSave.UnlockedBoatSkins); } SavedItemSkin val = ((IEnumerable<SavedItemSkin>)localSave.UnlockedItemSkins).FirstOrDefault((Func<SavedItemSkin, bool>)((SavedItemSkin s) => s.ID == id)); if (val != null) { return new HashSet<byte>(val.SkinsUnlocked); } return new HashSet<byte>(); } public static void SetSkins(string[] args, bool unlock) { string text = (unlock ? "unlockskin" : "lockskin"); if (args.Length < 2) { Commands.Reply("Usage: /" + text + " <item|boat> <index|all>"); } else { if (!Resolve(string.Join("", args.Take(args.Length - 1)), out var target)) { return; } string text2 = args[^1].ToLowerInvariant(); List<byte> indexes; if (text2 == "all") { indexes = (from i in Enumerable.Range(1, target.Preset.Skins.Count - 1) select (byte)i).ToList(); } else { if (!byte.TryParse(text2, out var result) || result <= 0 || result >= target.Preset.Skins.Count) { Commands.Reply($"{target.Label}: give an index from 1 to {target.Preset.Skins.Count - 1} (0 is the default skin), or \"all\"."); return; } indexes = new List<byte> { result }; } SetSkins(target, indexes, unlock); } } public static void SetSkins(Target target, IList<byte> indexes, bool unlock) { //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) LocalSaveObject localSave = LocalSave; if (localSave == null) { Commands.Reply("The skin save isn't loaded yet."); return; } if (!unlock && indexes.Count > 1) { Backup("before-lockskin", announce: false); } foreach (byte index in indexes) { if (unlock) { SaveManager.UnlockSkin(target.ID, index); continue; } if (target.IsBoat) { localSave.UnlockedBoatSkins.Remove(index); continue; } SavedItemSkin val =