Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of AdvancedAdminPanel v2.3.0
BepInEx/plugins/AdminPanel.dll
Decompiled 2 months 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.Globalization; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.EventSystems; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("AdminPanel")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("AdminPanel")] [assembly: AssemblyTitle("AdminPanel")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [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 AdminPanel { [BepInPlugin("com.halitb.adminpanel", "AdminPanel", "2.3.0")] public class AdminPanelPlugin : BaseUnityPlugin { private class ItemEntry { public ItemDrop Drop; public string Prefab; public string Display; public string Info; public string Cat; public string Sub; public Sprite Icon; public bool IconTried; } private class SeEntry { public StatusEffect Se; public string Display; public string Tooltip; public int Hash; public int Bucket; } private class CreatureEntry { public GameObject Prefab; public string Name; public string Display; public string Faction; public bool Boss; public bool Tamable; } private enum SideMode { None, WhatsNew, BugReport } [HarmonyPatch] private static class CheatPatches { [HarmonyPatch(typeof(Player), "UseStamina")] [HarmonyPrefix] private static bool NoStaminaPrefix(Player __instance) { if (NoStaminaFlag) { return !((Object)(object)__instance == (Object)(object)Player.m_localPlayer); } return true; } [HarmonyPatch(typeof(Character), "Damage")] [HarmonyPrefix] private static void OneHitPrefix(Character __instance, HitData hit) { if (!OneHitKillFlag || hit == null || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)__instance == (Object)null || (Object)(object)__instance == (Object)(object)Player.m_localPlayer) { return; } try { if (!((Object)(object)hit.GetAttacker() != (Object)(object)Player.m_localPlayer)) { hit.m_damage.m_damage = 1E+09f; } } catch { } } } [HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")] private static class CursorPatch { [HarmonyPrefix] private static bool Prefix() { if ((Object)(object)Instance == (Object)null || !Instance._visible) { return true; } Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; return false; } } [HarmonyPatch(typeof(Player), "TakeInput")] private static class InputBlockPatch { [HarmonyPostfix] private static void Postfix(ref bool __result) { if ((Object)(object)Instance != (Object)null && Instance._visible) { __result = false; } } } [HarmonyPatch(typeof(Humanoid), "StartAttack")] private static class BlockAttackPatch { [HarmonyPrefix] private static bool Prefix(Humanoid __instance) { if ((Object)(object)Instance != (Object)null && Instance._visible) { return !((Object)(object)__instance == (Object)(object)Player.m_localPlayer); } return true; } } [HarmonyPatch] private static class CameraLockPatch { private static MethodBase TargetMethod() { Type type = AccessTools.TypeByName("ZInput"); if (!(type == null)) { return AccessTools.Method(type, "GetMouseDelta", Type.EmptyTypes, (Type[])null); } return null; } [HarmonyPostfix] private static void Postfix(ref Vector2 __result) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Instance != (Object)null && Instance._visible && (Instance._cameraLockCfg == null || Instance._cameraLockCfg.Value)) { __result = Vector2.zero; } } } [HarmonyPatch(typeof(Player), "OnDeath")] private static class DeathPointPatch { [HarmonyPrefix] private static void Prefix(Player __instance) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Instance == (Object)null) && !((Object)(object)__instance == (Object)null) && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { Vector3 position = ((Component)__instance).transform.position; Instance._lastDeathCfg.Value = string.Format(CultureInfo.InvariantCulture, "{0:0.#},{1:0.#},{2:0.#}", position.x, position.y, position.z); ((BaseUnityPlugin)Instance).Config.Save(); } } } private static class ZoomWheelMute { internal static float SafeScrollWheel() { if (!((Object)(object)Instance != (Object)null) || !Instance._visible) { return ZInput.GetMouseScrollWheel(); } return 0f; } internal static float SafeGetAxis(string name) { if (!((Object)(object)Instance != (Object)null) || !Instance._visible || !(name == "Mouse ScrollWheel")) { return Input.GetAxis(name); } return 0f; } internal static IEnumerable<CodeInstruction> ReplaceAxisReads(IEnumerable<CodeInstruction> instructions, string owner) { MethodInfo original = AccessTools.Method(typeof(Input), "GetAxis", new Type[1] { typeof(string) }, (Type[])null); MethodInfo safe = AccessTools.Method(typeof(ZoomWheelMute), "SafeGetAxis", (Type[])null, (Type[])null); int replaced = 0; foreach (CodeInstruction instruction in instructions) { if (original != null && CodeInstructionExtensions.Calls(instruction, original)) { instruction.opcode = OpCodes.Call; instruction.operand = safe; replaced++; } yield return instruction; } if (replaced == 0) { AdminPanelPlugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogWarning((object)("Cross-mod zoom mute (" + owner + "): no Input.GetAxis calls found — mod code changed, mute inactive there.")); } } else { AdminPanelPlugin instance2 = Instance; if (instance2 != null) { ((BaseUnityPlugin)instance2).Logger.LogInfo((object)$"Cross-mod zoom mute ({owner}): {replaced} axis read(s) muted while panel open."); } } } internal static IEnumerable<CodeInstruction> VPlusAxisTranspiler(IEnumerable<CodeInstruction> instructions) { return ReplaceAxisReads(instructions, "ValheimPlus FirstPerson.Postfix"); } internal static IEnumerable<CodeInstruction> ReplaceWheelReads(IEnumerable<CodeInstruction> instructions, string owner) { MethodInfo original = AccessTools.Method(typeof(ZInput), "GetMouseScrollWheel", Type.EmptyTypes, (Type[])null); MethodInfo safe = AccessTools.Method(typeof(ZoomWheelMute), "SafeScrollWheel", (Type[])null, (Type[])null); int replaced = 0; foreach (CodeInstruction instruction in instructions) { if (original != null && CodeInstructionExtensions.Calls(instruction, original)) { instruction.opcode = OpCodes.Call; instruction.operand = safe; replaced++; } yield return instruction; } if (replaced == 0) { AdminPanelPlugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogWarning((object)("Zoom-freeze transpiler (" + owner + "): no GetMouseScrollWheel calls found — game code changed, zoom freeze inactive.")); } } else { AdminPanelPlugin instance2 = Instance; if (instance2 != null) { ((BaseUnityPlugin)instance2).Logger.LogInfo((object)$"Zoom-freeze transpiler ({owner}): {replaced} wheel read(s) muted while panel open."); } } } } [HarmonyPatch(typeof(GameCamera), "UpdateCamera")] private static class ZoomFreezeCameraTranspiler { [HarmonyTranspiler] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { return ZoomWheelMute.ReplaceWheelReads(instructions, "UpdateCamera"); } } [HarmonyPatch(typeof(GameCamera), "UpdateFreeFly")] private static class ZoomFreezeFreeFlyTranspiler { [HarmonyTranspiler] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { return ZoomWheelMute.ReplaceWheelReads(instructions, "UpdateFreeFly"); } } [HarmonyPatch(typeof(FejdStartup), "SetupGui")] private static class MenuVersionPatch { [HarmonyPostfix] private static void Postfix(FejdStartup __instance) { try { object obj = AccessTools.Field(typeof(FejdStartup), "m_versionLabel")?.GetValue(__instance); PropertyInfo propertyInfo = obj?.GetType().GetProperty("text"); if (propertyInfo?.GetValue(obj) is string text && !text.Contains("Advanced Admin Panel")) { propertyInfo.SetValue(obj, text + "\n<color=#FAC759>Advanced Admin Panel 2.3.0</color>"); } } catch (Exception ex) { AdminPanelPlugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogWarning((object)("Menu version line failed (cosmetic only): " + ex.Message)); } } } } [HarmonyPatch] private static class RpcRegistration { [HarmonyPatch(typeof(ZNet), "Awake")] [HarmonyPostfix] private static void ZNetAwakePostfix() { if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.Register<ZPackage>("AP_InvData", (Action<long, ZPackage>)OnInventoryData); ZRoutedRpc.instance.Register<string>("AP_VersionData", (Action<long, string>)OnVersionData); } } } public const string PluginGuid = "com.halitb.adminpanel"; public const string PluginName = "AdminPanel"; public const string PluginVersion = "2.3.0"; internal static AdminPanelPlugin Instance; private ConfigEntry<KeyCode> _toggleKey; private ConfigEntry<KeyCode> _mapTpKey; private ConfigEntry<string> _fontChoiceCfg; private ConfigEntry<int> _fontSizeCfg; private ConfigEntry<string> _languageCfg; private ConfigEntry<int> _panelAlphaCfg; private ConfigEntry<bool> _cameraLockCfg; private int _fontSizeLive; private int _panelAlphaLive; private int _rebindTarget; private int _rebindTargetLayout; private Vector2 _settingsScroll; private static readonly string[] FontChoices = new string[5] { "Norse (auto)", "Norse Bold", "Norse", "Averia Serif", "Default" }; private bool _visible; private Rect _windowRect = new Rect(60f, 60f, 740f, 680f); private Rect _lastSavedRect; private int _tab; private static readonly string[] TabKeys = new string[8] { "tab.items", "tab.creatures", "tab.bosses", "tab.player", "tab.world", "tab.players", "tab.server", "tab.settings" }; private string _itemSearch = ""; private Vector2 _itemScroll; private int _itemAmount = 1; private int _itemQuality = 1; private long _giveTargetId; private List<PlayerInfo> _othersSnapshot; private List<string> _globalKeysLayout; private int _itemSort; private List<ItemEntry> _itemWindowList; private int _itemWindowFirst; private int _itemWindowVisible; private int _itemWindowTotal; private static readonly string[] ItemSortModes = new string[3] { "A → Z", "Z → A", "Category" }; private static readonly string[] CreatureSortModes = new string[3] { "A → Z", "Z → A", "Faction" }; private int _creatureSort; private string _openDropdown; private string _openDropdownLayout; private List<ItemEntry> _filteredItemsCache; private string _itemFilterKey = ""; private int _favVersion; private int _recentVersion; private List<CreatureEntry> _filteredCreaturesCache; private string _creatureFilterKey = ""; private List<string> _creatureCats; private List<string> _subCatsCache; private string _subCatsKey; private List<ItemEntry> _itemIndex; private List<SeEntry> _seIndex; private List<SeEntry> _seFilteredCache; private string _seFilterKey; private string _mainCat = "All"; private string _subCat = "All"; private ConfigEntry<string> _favoritesCfg; private ConfigEntry<string> _crafterNameCfg; private ConfigEntry<string> _bulkPackCfg; private HashSet<string> _favorites; private readonly List<ItemEntry> _recentItems = new List<ItemEntry>(); private static readonly string[] MainCats = new string[14] { "All", "★ Fav", "Recent", "Kits", "Weapons", "Shields", "Armor", "Accessories", "Ammo", "Tools", "Food & Potions", "Materials", "Trophies", "Misc" }; private static readonly Dictionary<string, string> MaterialBiome = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { { "Wood", "Meadows" }, { "Stone", "Meadows" }, { "Resin", "Meadows" }, { "Feathers", "Meadows" }, { "LeatherScraps", "Meadows" }, { "DeerHide", "Meadows" }, { "Flint", "Meadows" }, { "RawMeat", "Meadows" }, { "NeckTail", "Meadows" }, { "BoarMeat", "Meadows" }, { "DeerMeat", "Meadows" }, { "Honey", "Meadows" }, { "Dandelion", "Meadows" }, { "BeechSeeds", "Meadows" }, { "QueenBee", "Meadows" }, { "FineWood", "Black Forest" }, { "RoundLog", "Black Forest" }, { "Coal", "Black Forest" }, { "Tin", "Black Forest" }, { "TinOre", "Black Forest" }, { "Copper", "Black Forest" }, { "CopperOre", "Black Forest" }, { "CopperScrap", "Black Forest" }, { "Bronze", "Black Forest" }, { "BronzeNails", "Black Forest" }, { "TrollHide", "Black Forest" }, { "BoneFragments", "Black Forest" }, { "SurtlingCore", "Black Forest" }, { "GreydwarfEye", "Black Forest" }, { "Thistle", "Black Forest" }, { "AncientSeed", "Black Forest" }, { "Amber", "Black Forest" }, { "AmberPearl", "Black Forest" }, { "Ruby", "Black Forest" }, { "Coins", "Black Forest" }, { "CarrotSeeds", "Black Forest" }, { "FirCone", "Black Forest" }, { "PineCone", "Black Forest" }, { "Iron", "Swamp" }, { "IronScrap", "Swamp" }, { "WitheredBone", "Swamp" }, { "Chain", "Swamp" }, { "ElderBark", "Swamp" }, { "Guck", "Swamp" }, { "Ooze", "Swamp" }, { "Entrails", "Swamp" }, { "Bloodbag", "Swamp" }, { "TurnipSeeds", "Swamp" }, { "IronNails", "Swamp" }, { "Root", "Swamp" }, { "SerpentScale", "Swamp" }, { "Chitin", "Swamp" }, { "Silver", "Mountain" }, { "SilverOre", "Mountain" }, { "Obsidian", "Mountain" }, { "WolfPelt", "Mountain" }, { "WolfFang", "Mountain" }, { "FreezeGland", "Mountain" }, { "Crystal", "Mountain" }, { "WolfClaw", "Mountain" }, { "WolfHairBundle", "Mountain" }, { "JuteRed", "Mountain" }, { "DragonEgg", "Mountain" }, { "OnionSeeds", "Mountain" }, { "BlackMetal", "Plains" }, { "BlackMetalScrap", "Plains" }, { "Barley", "Plains" }, { "Flax", "Plains" }, { "LoxPelt", "Plains" }, { "Needle", "Plains" }, { "LinenThread", "Plains" }, { "Tar", "Plains" }, { "BarleyFlour", "Plains" }, { "LoxMeat", "Plains" }, { "Cloudberry", "Plains" }, { "BlackMarble", "Mistlands" }, { "Sap", "Mistlands" }, { "Eitr", "Mistlands" }, { "RefinedEitr", "Mistlands" }, { "YggdrasilWood", "Mistlands" }, { "Carapace", "Mistlands" }, { "Softtissue", "Mistlands" }, { "ScaleHide", "Mistlands" }, { "BlackCore", "Mistlands" }, { "Wisp", "Mistlands" }, { "Mandible", "Mistlands" }, { "RoyalJelly", "Mistlands" }, { "SeekerBrain", "Mistlands" }, { "JuteBlue", "Mistlands" }, { "FlametalNew", "Ashlands" }, { "FlametalOreNew", "Ashlands" }, { "Grausten", "Ashlands" }, { "CharredBone", "Ashlands" }, { "ProustitePowder", "Ashlands" }, { "CelestialFeather", "Ashlands" }, { "AskHide", "Ashlands" }, { "Blackwood", "Ashlands" }, { "SulfurStone", "Ashlands" }, { "MoltenCore", "Ashlands" }, { "CharcoalResin", "Ashlands" }, { "GemstoneRed", "Ashlands" }, { "GemstoneGreen", "Ashlands" }, { "GemstoneBlue", "Ashlands" }, { "BonemawSerpentMeat", "Ashlands" } }; private static readonly (string Name, (string Prefab, int Count)[] Items)[] GearKits = new(string, (string, int)[])[8] { ("Bronze Kit", new(string, int)[6] { ("ArmorBronzeChest", 1), ("ArmorBronzeLegs", 1), ("HelmetBronze", 1), ("CapeDeerHide", 1), ("SwordBronze", 1), ("ShieldBronzeBuckler", 1) }), ("Iron Kit", new(string, int)[6] { ("ArmorIronChest", 1), ("ArmorIronLegs", 1), ("HelmetIron", 1), ("CapeTrollHide", 1), ("SwordIron", 1), ("ShieldBanded", 1) }), ("Wolf Kit", new(string, int)[6] { ("ArmorWolfChest", 1), ("ArmorWolfLegs", 1), ("HelmetDrake", 1), ("CapeWolf", 1), ("SwordSilver", 1), ("ShieldSilver", 1) }), ("Padded Kit", new(string, int)[6] { ("ArmorPaddedCuirass", 1), ("ArmorPaddedGreaves", 1), ("HelmetPadded", 1), ("CapeLox", 1), ("SwordBlackmetal", 1), ("ShieldBlackmetal", 1) }), ("Carapace Kit", new(string, int)[6] { ("ArmorCarapaceChest", 1), ("ArmorCarapaceLegs", 1), ("HelmetCarapace", 1), ("CapeFeather", 1), ("SwordMistwalker", 1), ("ShieldCarapace", 1) }), ("Ashlands Kit", new(string, int)[6] { ("ArmorAshlandsMediumChest", 1), ("ArmorAshlandsMediumlegs", 1), ("HelmetAshlandsMediumHood", 1), ("CapeAsksvin", 1), ("SwordNiedhogg", 1), ("ShieldFlametal", 1) }), ("Food Pack", new(string, int)[5] { ("FishAndBread", 10), ("MeatPlatter", 10), ("YggdrasilPorridge", 10), ("MeadHealthMajor", 5), ("MeadStaminaLingering", 5) }), ("Builder Pack", new(string, int)[7] { ("Hammer", 1), ("Hoe", 1), ("Cultivator", 1), ("Wood", 50), ("Stone", 50), ("IronNails", 100), ("FineWood", 50) }) }; private string _creatureSearch = ""; private Vector2 _creatureScroll; private List<CreatureEntry> _creWindowList; private int _creWindowFirst; private int _creWindowVisible; private int _creWindowTotal; private int _creatureCount = 1; private int _creatureLevel = 1; private List<CreatureEntry> _creatureIndex; private string _creatureCat = "All"; private bool _spawnAtCrosshair; private string _petName = ""; private string _arenaA; private string _arenaB; private int _arenaCountA = 5; private int _arenaCountB = 5; private ConfigEntry<string> _spawnPresetsCfg; private string _presetName = ""; private string _weather = ""; private float _timeSlider = 0.5f; private bool _timeLocked; private float _windAngle; private float _windIntensity = 0.5f; private bool _windLocked; private ConfigEntry<string> _bookmarksCfg; private string _bookmarkName = ""; private string _tpX = "0"; private string _tpY = "0"; private string _tpZ = "0"; private string _newGlobalKey = ""; private bool _peaceful; private Vector2 _worldScroll; private static readonly (string Label, string Location)[] QuickJumps = new(string, string)[8] { ("Spawn", "StartTemple"), ("Eikthyr", "Eikthyrnir"), ("The Elder", "GDKing"), ("Bonemass", "Bonemass"), ("Moder", "Dragonqueen"), ("Yagluth", "GoblinKing"), ("The Queen", "Mistlands_DvergrBossEntrance1"), ("Fader", "FaderLocation") }; private bool _god; private bool _ghost; private bool _fly; private bool _noCost; private float _speedMult = 1f; private float _jumpMult = 1f; private bool _infiniteWeight; private bool _noStamina; private bool _oneHitKill; private float _pickupRange = 2f; private float _baseWalk = -1f; private float _baseRun; private float _baseSwim; private float _baseJump; private float _baseWeight; private float _basePickup; private Player _appliedTo; private string _seSearch = ""; private Vector2 _seScroll; private bool _showStatusEffects; private Vector2 _playerScroll; private bool _showSkills; private Vector2 _skillScroll; private string _skillCustom = "25"; private long _skillTargetId; private long _seTargetId; private string _skillMsg = ""; private static readonly SkillType[] AllSkillTypes = (from SkillType t in Enum.GetValues(typeof(SkillType)) where (int)t != 0 && (int)t != 999 select t).ToArray(); private Vector2 _playersScroll; private string _broadcastText = ""; private ConfigEntry<string> _playerNotesCfg; private ConfigEntry<string> _windowRectCfg; private bool _resizing; private bool _notesDirty; private Dictionary<string, string> _playerNotes; private string _inspectPlayerName; private long _inspectTargetId; private List<(string name, int stack, int quality)> _inspectInventory; private bool _inspectPending; private float _inspectRequestTime; private Vector2 _inspectScroll; private readonly List<string> _joinLog = new List<string>(); private HashSet<string> _lastSeenPlayers = new HashSet<string>(); private bool _seenPlayersInit; private float _nextPlayerPoll; private float _nextInvClean; private Vector2 _serverScroll; private static readonly string[] RaidEvents = new string[14] { "army_eikthyr", "army_theelder", "army_bonemass", "army_moder", "army_goblin", "army_seekers", "army_gjall", "foresttrolls", "skeletons", "blobs", "surtlings", "wolves", "bats", "army_charred" }; private SideMode _sideMode; private SideMode _sideModeLayout; private Vector2 _sideScroll; private ConfigEntry<bool> _autoWhatsNewCfg; private ConfigEntry<string> _seenVersionCfg; private ConfigEntry<string> _bugWebhookCfg; private ConfigEntry<string> _lastDeathCfg; private string _bugText = ""; private bool _bugAttachShot = true; private volatile string _bugStatus; private string _bugStatusLayout; private bool _bugCoolLayout; private bool _bugSending; private float _nextBugSend; private const string DiscordInvite = "https://discord.gg/2RVn78hNrz"; private const string DonateUrl = "https://www.paypal.com/donate/?business=HRKGKS3G5JD94&no_recurring=0&item_name=Your+Friendly+Neighborhood+Dev%2C+Halit.%0AMay+the+Lord+bless+you+with+even+more%21¤cy_code=USD"; private volatile string _updateAvailable; private string _updateBannerLayout; private volatile string _srvCompVersion; private string _versionWarnLayout; private float _nextVersionReq; private float _versionReqFirst; private const string ReleasesApi = "https://api.github.com/repos/hldblc/ValheimAdminPanel/releases/latest"; private const string ReleasesPage = "https://github.com/hldblc/ValheimAdminPanel/releases/latest"; private const string DefaultBugWebhook = "https://discord.com/api/webhooks/1527589135672672266/vqCLH1pZV8mRtKauUCcRxExWGwTazxkSJ6gz75Ey6yQoSfriVnuc4b07e3DYNvCaUPK3"; private const string WhatsNewText = "• The panel speaks your language: German, French, Spanish, Italian, Portuguese (BR), Polish, Dutch and Swedish. It follows Valheim's own language setting by default — change it under Settings → Language.\n\n• Smarter search: results are ranked by relevance, so typing \"iron\" puts Iron first instead of burying it alphabetically. Typing no longer re-sorts the whole list on every keystroke.\n\n• Multi-step undo: Undo spawn now steps back through your last 20 spawns instead of just one, and each admin has their own history — your undo can't delete someone else's work.\n\n• Destructive actions ask first: Kill ALL loaded, Ground items, Clear trees and Ban now need a second click to confirm.\n\n• Status effects for anyone: the status-effect browser now has the same Me/any-player target picker as the skill browser (needs companion 2.3.0 on the target).\n\n• Undo actually works on dedicated servers now — the destroy silently did nothing server-side unless the server owned the object.\n\n• Scrolling panel lists no longer zooms the vanilla camera (muted at the IL level, with startup verification in the log). ValheimPlus's separate FirstPerson zoom gets a best-effort mute too.\n\n• Layout survives big font sizes: labels never wrap mid-word and buttons no longer stretch across the row.\n\n• Server tab: added ZDOs loaded, zones loaded and session uptime.\n\n• Smoother: the panel does far less work per frame across every tab, and switches to a readable font automatically if the game's Norse font can't draw your language.\n\n• If the mod has been useful, there's now a \"Buy the developer a coffee\" button in Settings. Entirely optional — the mod is free and always will be."; private Vector2 _bossScroll; private static readonly (string Prefab, string Label, string OfferPrefab, int OfferCount)[] BossList = new(string, string, string, int)[7] { ("Eikthyr", "Eikthyr", "TrophyDeer", 2), ("gd_king", "The Elder", "AncientSeed", 3), ("Bonemass", "Bonemass", "WitheredBone", 10), ("Dragon", "Moder", "DragonEgg", 3), ("GoblinKing", "Yagluth", "GoblinTotem", 5), ("SeekerQueen", "The Queen", "DvergrKeyFragment", 9), ("Fader", "Fader", "BellFragment", 3) }; private GUIStyle _windowStyle; private GUIStyle _buttonStyle; private GUIStyle _labelStyle; private GUIStyle _headerStyle; private GUIStyle _textFieldStyle; private GUIStyle _toggleStyle; private GUIStyle _tabStyle; private GUIStyle _catStyle; private GUIStyle _rowEven; private GUIStyle _rowOdd; private GUIStyle _dimLabelStyle; private GUIStyle _textAreaStyle; private GUIStyle _cellStyle; private GUIStyle _dimCellStyle; private GUIStyle _hintStyle; private GUIStyle _proseStyle; private Texture2D _texWood; private Texture2D _texRule; private Texture2D _logoTex; private bool _logoTried; private float _logoAspect = 3.63f; private ConfigEntry<bool> _showLogoCfg; private bool _skinReady; private bool _fontApplied; private Font _appliedFont; private bool _wasInWorld; private float _nextFontTry; private int _fontTries; internal static bool NoStaminaFlag; internal static bool OneHitKillFlag; private string _presetsKvRaw; private string _bookmarksKvRaw; private Dictionary<string, string> _presetsKv; private Dictionary<string, string> _bookmarksKv; private List<KeyValuePair<string, string>> _presetRowsLayout; private List<KeyValuePair<string, string>> _bookmarkRowsLayout; private static MethodInfo _screenToWorld; private static readonly string[] SeBucketKeys = new string[6] { "se.boss_powers", "se.set_bonuses", "se.potions", "se.debuffs", "se.comfort", "se.other" }; private static readonly string[] SeDebuffKeys = new string[19] { "Burning", "Cold", "Freezing", "Frost", "Wet", "Poison", "Smoked", "Tared", "Harpooned", "Stagger", "Encumbered", "Slime", "Lightning", "Immobilized", "Barnacle", "Puke", "Debuff", "Curse", "Bleeding" }; private static readonly string[] SeComfortKeys = new string[11] { "Rested", "Resting", "Shelter", "Comfort", "Campfire", "Warm", "Fire", "Sated", "SoftDeath", "Sitting", "Bed" }; private string _seSearchApplied = ""; private string _seSearchLastSeen = ""; private float _seSearchDirtyAt = -1f; private Texture2D _coffeeTex; private bool _coffeeTried; private static bool? _companionLoadedHost; private static readonly string[] MainCatKeys = new string[14] { "cat.all", "cat.fav", "cat.recent", "cat.kits", "cat.weapons", "cat.shields", "cat.armor", "cat.accessories", "cat.ammo", "cat.tools", "cat.food", "cat.materials", "cat.trophies", "cat.misc" }; private string[] _mainCatLabels; private string[] _itemSortLabels; private string[] _creatureSortLabels; private string _labelsLang; private const float ConfirmWindowSeconds = 3f; private string _confirmAction; private float _confirmExpiresAt; private const float SearchDebounceSeconds = 0.15f; private string _itemSearchApplied = ""; private string _itemSearchLastSeen = ""; private float _itemSearchDirtyAt = -1f; private string _creatureSearchApplied = ""; private string _creatureSearchLastSeen = ""; private float _creatureSearchDirtyAt = -1f; private float _nextStatsRefresh; private string _statsMain = ""; private string _statsLoad = ""; private string _statsHost = ""; private string _unbanId = ""; private static Player LocalPlayer => Player.m_localPlayer; private void Awake() { //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Expected O, but got Unknown //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Expected O, but got Unknown //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Expected O, but got Unknown //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Expected O, but got Unknown //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Unknown result type (might be due to invalid IL or missing references) //IL_05dd: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_0381: Unknown result type (might be due to invalid IL or missing references) Instance = this; _toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)288, "Key that opens/closes the admin panel"); _mapTpKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "MapTeleportKey", (KeyCode)116, "With the full map open, hover a spot and press this key to teleport there"); _favoritesCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Items", "Favorites", "", "Comma-separated favorite item prefabs"); _crafterNameCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Items", "CrafterName", "", "Crafter signature on given items (empty = none)"); _bulkPackCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Items", "BulkPack", "Wood:50,Stone:50,FineWood:30,Iron:30,BronzeNails:100", "Items granted by the Bulk Pack button (prefab:count, comma-separated)"); _spawnPresetsCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Creatures", "SpawnPresets", "", "Saved creature spawn presets"); _bookmarksCfg = ((BaseUnityPlugin)this).Config.Bind<string>("World", "Bookmarks", "", "Saved teleport bookmarks"); _playerNotesCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Players", "Notes", "", "Per-player admin notes"); _windowRectCfg = ((BaseUnityPlugin)this).Config.Bind<string>("General", "WindowRect", "60,60,740,680", "Admin panel window position+size x,y,width,height (auto-saved)"); _fontChoiceCfg = ((BaseUnityPlugin)this).Config.Bind<string>("UI", "Font", FontChoices[0], new ConfigDescription("Panel font. 'Norse (auto)' picks the best available game font; 'Default' is Unity's built-in font.", (AcceptableValueBase)(object)new AcceptableValueList<string>(FontChoices), Array.Empty<object>())); _fontSizeCfg = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "FontSize", 13, new ConfigDescription("Base font size for panel text; headers, tabs and the title scale with it.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 20), Array.Empty<object>())); _languageCfg = ((BaseUnityPlugin)this).Config.Bind<string>("UI", "Language", Loc.MenuNames[0], new ConfigDescription("Panel language. 'Auto' follows Valheim's own language setting. Item and creature names always follow the game regardless of this setting.", (AcceptableValueBase)(object)new AcceptableValueList<string>(Loc.MenuNames), Array.Empty<object>())); _panelAlphaCfg = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "PanelOpacity", 96, new ConfigDescription("Panel background opacity in percent.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(55, 100), Array.Empty<object>())); _cameraLockCfg = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "CameraLockWhilePanelOpen", true, "Lock mouse-look while the panel is open (like the inventory). Turn off to keep the camera live."); _showLogoCfg = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "ShowLogoHeader", true, "Show the Advanced Admin Panel logo at the top of the panel."); _autoWhatsNewCfg = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "ShowWhatsNewOnUpdate", true, "Open the What's New side panel once after the mod updates."); _seenVersionCfg = ((BaseUnityPlugin)this).Config.Bind<string>("UI", "WhatsNewSeenVersion", "", "Last version whose What's New was shown (internal bookkeeping)."); _bugWebhookCfg = ((BaseUnityPlugin)this).Config.Bind<string>("BugReport", "WebhookUrl", "https://discord.com/api/webhooks/1527589135672672266/vqCLH1pZV8mRtKauUCcRxExWGwTazxkSJ6gz75Ey6yQoSfriVnuc4b07e3DYNvCaUPK3", "Discord webhook that receives in-panel bug reports. Empty disables the Send button."); _lastDeathCfg = ((BaseUnityPlugin)this).Config.Bind<string>("Player", "LastDeathPos", "", "Your last death position, auto-recorded for the 'TP to last death' button (x,y,z)."); _fontSizeLive = _fontSizeCfg.Value; _panelAlphaLive = _panelAlphaCfg.Value; try { string[] array = _windowRectCfg.Value.Split(new char[1] { ',' }); if (array.Length == 4 && float.TryParse(array[0], out var result) && float.TryParse(array[1], out var result2) && float.TryParse(array[2], out var result3) && float.TryParse(array[3], out var result4)) { _windowRect = new Rect(result, result2, result3, result4); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Bad WindowRect config, using default: " + ex.Message)); } _lastSavedRect = _windowRect; _favorites = new HashSet<string>(_favoritesCfg.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries), StringComparer.OrdinalIgnoreCase); _playerNotes = ParseKv(_playerNotesCfg.Value); Harmony.CreateAndPatchAll(typeof(RpcRegistration), (string)null); Harmony.CreateAndPatchAll(typeof(CheatPatches), (string)null); try { Harmony.CreateAndPatchAll(typeof(CursorPatch), (string)null); } catch (Exception ex2) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Cursor patch failed (panel still works): " + ex2.Message)); } try { Harmony.CreateAndPatchAll(typeof(InputBlockPatch), (string)null); } catch (Exception ex3) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Input-block patch failed (panel still works): " + ex3.Message)); } try { Harmony.CreateAndPatchAll(typeof(BlockAttackPatch), (string)null); } catch (Exception ex4) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Attack-block patch failed (panel still works): " + ex4.Message)); } try { Harmony.CreateAndPatchAll(typeof(CameraLockPatch), (string)null); } catch (Exception ex5) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Camera-lock patch failed (panel still works): " + ex5.Message)); } try { Harmony.CreateAndPatchAll(typeof(DeathPointPatch), (string)null); } catch (Exception ex6) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Death-point patch failed (panel still works): " + ex6.Message)); } try { Harmony.CreateAndPatchAll(typeof(ZoomFreezeCameraTranspiler), (string)null); } catch (Exception ex7) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Zoom-freeze camera transpiler failed (panel still works): " + ex7.Message)); } try { Harmony.CreateAndPatchAll(typeof(ZoomFreezeFreeFlyTranspiler), (string)null); } catch (Exception ex8) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Zoom-freeze free-fly transpiler failed (panel still works): " + ex8.Message)); } PatchValheimPlusZoomIfPresent(); VerifyCameraPatches(); try { Harmony.CreateAndPatchAll(typeof(MenuVersionPatch), (string)null); } catch (Exception ex9) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Menu version-line patch failed (panel still works): " + ex9.Message)); } ((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} {1} loaded. Press {2} in-game.", "AdminPanel", "2.3.0", _toggleKey.Value)); StartUpdateCheck(); } private void PatchValheimPlusZoomIfPresent() { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown try { Type type = AccessTools.TypeByName("ValheimPlus.FirstPerson.VPlusFirstPerson+GameCamera_Update_Patch"); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "Postfix", (Type[])null, (Type[])null) : null); if (methodInfo == null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"ValheimPlus FirstPerson patch not found — cross-mod zoom mute not needed."); } else { new Harmony("com.halitb.adminpanel.crossmod").Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ZoomWheelMute), "VPlusAxisTranspiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Cross-mod zoom mute failed (panel still works): " + ex.Message)); } } private void VerifyCameraPatches() { try { List<(string, MethodBase)> list = new List<(string, MethodBase)> { ("UpdateCamera", AccessTools.Method(typeof(GameCamera), "UpdateCamera", (Type[])null, (Type[])null)), ("UpdateFreeFly", AccessTools.Method(typeof(GameCamera), "UpdateFreeFly", (Type[])null, (Type[])null)) }; Type type = AccessTools.TypeByName("ValheimPlus.FirstPerson.VPlusFirstPerson+GameCamera_Update_Patch"); if (type != null) { list.Add(("V+ FP.Postfix", AccessTools.Method(type, "Postfix", (Type[])null, (Type[])null))); } foreach (var item3 in list) { string item = item3.Item1; MethodBase item2 = item3.Item2; Patches val = ((item2 != null) ? Harmony.GetPatchInfo(item2) : null); if (val == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("patch-verify " + item + ": NO patches bound")); continue; } ((BaseUnityPlugin)this).Logger.LogInfo((object)("patch-verify " + item + ": " + $"{val.Prefixes.Count} prefix, {val.Postfixes.Count} postfix, {val.Transpilers.Count} transpiler " + "[" + string.Join(", ", val.Transpilers.Select((Patch p) => p.PatchMethod.DeclaringType?.Name)) + "]")); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("patch-verify failed: " + ex.Message)); } } private void StartUpdateCheck() { Task.Run(delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown try { ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; HttpClient val = new HttpClient(); try { val.Timeout = TimeSpan.FromSeconds(10.0); val.DefaultRequestHeaders.UserAgent.ParseAdd("AdvancedAdminPanel/2.3.0"); Match match = Regex.Match(val.GetStringAsync("https://api.github.com/repos/hldblc/ValheimAdminPanel/releases/latest").GetAwaiter().GetResult(), "\"tag_name\"\\s*:\\s*\"v?([0-9.]+)\""); if (match.Success && new Version(match.Groups[1].Value) > new Version("2.3.0")) { _updateAvailable = match.Groups[1].Value; } } finally { ((IDisposable)val)?.Dispose(); } } catch { } }); } private static string EncKv(string s) { if (!string.IsNullOrEmpty(s)) { return s.Replace("%", "%25").Replace("|", "%7C").Replace("=", "%3D"); } return s; } private static string DecKv(string s) { if (!string.IsNullOrEmpty(s)) { return s.Replace("%3D", "=").Replace("%7C", "|").Replace("%25", "%"); } return s; } private Dictionary<string, string> PresetsKv() { string text = _spawnPresetsCfg.Value ?? ""; if (_presetsKv == null || _presetsKvRaw != text) { _presetsKv = ParseKv(text); _presetsKvRaw = text; } return _presetsKv; } private Dictionary<string, string> BookmarksKv() { string text = _bookmarksCfg.Value ?? ""; if (_bookmarksKv == null || _bookmarksKvRaw != text) { _bookmarksKv = ParseKv(text); _bookmarksKvRaw = text; } return _bookmarksKv; } private List<KeyValuePair<string, string>> PresetRows() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 if ((Event.current != null && (int)Event.current.type == 8) || _presetRowsLayout == null) { _presetRowsLayout = new List<KeyValuePair<string, string>>(PresetsKv()); } return _presetRowsLayout; } private List<KeyValuePair<string, string>> BookmarkRows() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 if ((Event.current != null && (int)Event.current.type == 8) || _bookmarkRowsLayout == null) { _bookmarkRowsLayout = new List<KeyValuePair<string, string>>(BookmarksKv()); } return _bookmarkRowsLayout; } private static Dictionary<string, string> ParseKv(string raw) { Dictionary<string, string> dictionary = new Dictionary<string, string>(); string[] array = raw.Split(new char[1] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { int num = text.IndexOf('='); if (num > 0) { dictionary[DecKv(text.Substring(0, num))] = DecKv(text.Substring(num + 1)); } } return dictionary; } private static string JoinKv(Dictionary<string, string> dict) { return string.Join("|", dict.Select((KeyValuePair<string, string> kv) => EncKv(kv.Key) + "=" + EncKv(kv.Value))); } private static void OnVersionData(long sender, string version) { if ((Object)(object)Instance != (Object)null) { Instance._srvCompVersion = version; } } private static void OnInventoryData(long sender, ZPackage pkg) { AdminPanelPlugin instance = Instance; if ((Object)(object)instance == (Object)null) { return; } try { string inspectPlayerName = pkg.ReadString(); int num = pkg.ReadInt(); if (num >= 0 && num <= 512) { List<(string, int, int)> list = new List<(string, int, int)>(); for (int i = 0; i < num; i++) { string item = pkg.ReadString(); int item2 = pkg.ReadInt(); int item3 = pkg.ReadInt(); list.Add((item, item2, item3)); } instance._inspectPlayerName = inspectPlayerName; instance._inspectInventory = list; instance._inspectPending = false; } } catch (Exception) { } } private static long PeerIdOf(PlayerInfo info) { return ((ZDOID)(ref info.m_characterID)).UserID; } private static long ServerUid() { return (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetServerPeer() : null)?.m_uid ?? 0; } private long SelfUid() { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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) //IL_0050: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ZNet.instance == (Object)null || (Object)(object)LocalPlayer == (Object)null) { return 0L; } string playerName = LocalPlayer.GetPlayerName(); foreach (PlayerInfo player in ZNet.instance.GetPlayerList()) { if (player.m_name == playerName) { return PeerIdOf(player); } } return 0L; } private void Update() { //IL_0011: 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_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Invalid comparison between Unknown and I4 if (_rebindTarget == 0 && Input.GetKeyDown(_toggleKey.Value)) { _visible = !_visible; if (_visible) { Loc.Refresh(_languageCfg.Value); RefreshCaches(); if (_autoWhatsNewCfg.Value && _seenVersionCfg.Value != "2.3.0") { _sideMode = SideMode.WhatsNew; _seenVersionCfg.Value = "2.3.0"; ((BaseUnityPlugin)this).Config.Save(); } } else { FlushNotes(); CommitUiSettings(); _openDropdown = null; } } if (_visible && (((_itemIndex == null || _seIndex == null) && (Object)(object)ObjectDB.instance != (Object)null) || (_creatureIndex == null && (Object)(object)ZNetScene.instance != (Object)null))) { RefreshCaches(); } if (_rebindTarget == 0 && Input.GetKeyDown(_mapTpKey.Value) && (Object)(object)LocalPlayer != (Object)null && (Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode == 2) { TeleportToMapCursor(); } if (_visible && Input.GetMouseButtonUp(0)) { CommitUiSettings(); } EventSystem current = EventSystem.current; if ((Object)(object)current != (Object)null && !((Behaviour)current).enabled) { ((Behaviour)current).enabled = true; } if (_visible && _srvCompVersion == null && (Object)(object)ZNet.instance != (Object)null && Time.time >= _nextVersionReq) { _nextVersionReq = Time.time + 30f; if (_versionReqFirst == 0f) { _versionReqFirst = Time.time; } SrvRpc("AP_SrvVersion"); } if ((Object)(object)ZNet.instance != (Object)null) { _wasInWorld = true; } else if (_wasInWorld) { _wasInWorld = false; ResetSessionState(); } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && (Object)(object)localPlayer != (Object)(object)_appliedTo) { ReapplyPlayerState(localPlayer); _appliedTo = localPlayer; } if ((Object)(object)localPlayer != (Object)null && Time.time >= _nextInvClean) { _nextInvClean = Time.time + 2f; Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (inventory != null) { List<ItemData> list = (from i in inventory.GetAllItems() where i.m_shared == null || i.m_shared.m_icons == null || i.m_shared.m_icons.Length == 0 select i).ToList(); if (list.Count > 0) { foreach (ItemData item in list) { inventory.RemoveItem(item); } ((BaseUnityPlugin)this).Logger.LogWarning((object)$"Auto-removed {list.Count} icon-less item(s) that would freeze the inventory."); ((Character)localPlayer).Message((MessageType)1, $"[Admin] Removed {list.Count} broken item(s) from your bag", 0, (Sprite)null); } } } if (!((Object)(object)ZNet.instance != (Object)null) || !(Time.time >= _nextPlayerPoll)) { return; } _nextPlayerPoll = Time.time + 3f; HashSet<string> hashSet = new HashSet<string>(from p in ZNet.instance.GetPlayerList() select p.m_name); if (_seenPlayersInit) { foreach (string item2 in hashSet.Except(_lastSeenPlayers)) { _joinLog.Insert(0, $"{DateTime.Now:HH:mm} + {item2} joined"); } foreach (string item3 in _lastSeenPlayers.Except(hashSet)) { _joinLog.Insert(0, $"{DateTime.Now:HH:mm} - {item3} left"); } } else { _seenPlayersInit = true; } if (_joinLog.Count > 100) { _joinLog.RemoveRange(100, _joinLog.Count - 100); } _lastSeenPlayers = hashSet; } private void OnDisable() { FlushNotes(); } private void ResetSessionState() { FlushNotes(); _visible = false; _itemIndex = null; _seIndex = null; _creatureIndex = null; _creatureCats = null; _filteredItemsCache = null; _itemFilterKey = ""; _filteredCreaturesCache = null; _creatureFilterKey = ""; _seFilteredCache = null; _seFilterKey = null; _subCatsCache = null; _subCatsKey = null; _itemWindowList = null; _creWindowList = null; _othersSnapshot = null; _recentItems.Clear(); _recentVersion++; _giveTargetId = 0L; _openDropdown = null; _openDropdownLayout = null; _sideMode = SideMode.None; _inspectPlayerName = null; _inspectInventory = null; _inspectPending = false; _inspectTargetId = 0L; _joinLog.Clear(); _lastSeenPlayers.Clear(); _seenPlayersInit = false; _skillTargetId = 0L; _skillMsg = ""; _srvCompVersion = null; _versionReqFirst = 0f; _nextVersionReq = 0f; _appliedTo = null; _baseWalk = -1f; } private void FlushNotes() { if (_notesDirty) { _playerNotesCfg.Value = JoinKv(_playerNotes); ((BaseUnityPlugin)this).Config.Save(); _notesDirty = false; } } private void ReapplyPlayerState(Player p) { _baseWalk = ((Character)p).m_walkSpeed; _baseRun = ((Character)p).m_runSpeed; _baseSwim = ((Character)p).m_swimSpeed; _baseJump = ((Character)p).m_jumpForce; _baseWeight = p.m_maxCarryWeight; _basePickup = p.m_autoPickupRange; if (_god) { p.SetGodMode(true); } if (_ghost) { p.SetGhostMode(true); } if (_noCost) { p.SetNoPlacementCost(true); } if (_infiniteWeight) { p.m_maxCarryWeight = 100000f; } if (_speedMult > 1.001f) { ((Character)p).m_walkSpeed = _baseWalk * _speedMult; ((Character)p).m_runSpeed = _baseRun * _speedMult; ((Character)p).m_swimSpeed = _baseSwim * _speedMult; } if (_jumpMult > 1.001f) { ((Character)p).m_jumpForce = _baseJump * _jumpMult; } if (_pickupRange > 2.001f) { p.m_autoPickupRange = _pickupRange; } _fly = false; } private void TeleportToMapCursor() { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) if (_screenToWorld == null) { _screenToWorld = AccessTools.Method(typeof(Minimap), "ScreenToWorldPoint", new Type[1] { typeof(Vector3) }, (Type[])null); } if (_screenToWorld == null) { Message(Loc.T("world.msg_map_tp_unavailable")); return; } Vector3 val = (Vector3)_screenToWorld.Invoke(Minimap.instance, new object[1] { Input.mousePosition }); TeleportToWorld(val, $"map point ({val.x:0}, {val.z:0})"); } private void TeleportToWorld(Vector3 world, string label) { //IL_0000: 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) float num = world.y; float num2 = default(float); if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(world, ref num2)) { num = num2; } ((Character)LocalPlayer).TeleportTo(new Vector3(world.x, num + 1.5f, world.z), ((Component)LocalPlayer).transform.rotation, true); Message(Loc.T("world.msg_tp_to", label)); } private static (string cat, string sub) Categorize(ItemDrop drop) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected I4, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Invalid comparison between Unknown and I4 SharedData shared = drop.m_itemData.m_shared; ItemType itemType = shared.m_itemType; switch (itemType - 1) { case 2: case 3: case 13: case 21: if ((int)shared.m_skillType == 12) { return (cat: "Tools", sub: "Pickaxes"); } return (cat: "Weapons", sub: ((object)Unsafe.As<SkillType, SkillType>(ref shared.m_skillType)/*cast due to .constrained prefix*/).ToString()); case 4: return (cat: "Shields", sub: "All"); case 5: return (cat: "Armor", sub: "Helmets"); case 6: return (cat: "Armor", sub: "Chest"); case 10: return (cat: "Armor", sub: "Legs"); case 16: return (cat: "Armor", sub: "Capes"); case 9: case 17: return (cat: "Accessories", sub: "All"); case 8: case 22: return (cat: "Ammo", sub: "All"); case 1: return (cat: "Food & Potions", sub: (shared.m_food > 0f) ? "Food" : "Potions & Other"); case 14: case 18: return (cat: "Tools", sub: "All"); case 12: return (cat: "Trophies", sub: "All"); case 0: { string value; return (cat: "Materials", sub: MaterialBiome.TryGetValue(((Object)drop).name, out value) ? value : "Other"); } default: return (cat: "Misc", sub: "All"); } } private static string LocalizeSafe(string token, string fallback) { string text = ((Localization.instance != null) ? Localization.instance.Localize(token) : fallback); if (string.IsNullOrEmpty(text) || text.StartsWith("[")) { text = fallback; } return text; } private static string ShortDesc(string token, int max) { string text = LocalizeSafe(token, ""); if (string.IsNullOrEmpty(text)) { return ""; } text = text.Replace('\n', ' ').Replace('\r', ' ').Trim(); if (text.Length > max) { text = text.Substring(0, max).TrimEnd(Array.Empty<char>()) + "…"; } return text; } private static string BuildDamageLine(DamageTypes d) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_011f: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) List<string> list = new List<string>(4); if (d.m_damage > 0f) { list.Add($"Dmg {d.m_damage:0}"); } if (d.m_blunt > 0f) { list.Add($"Blunt {d.m_blunt:0}"); } if (d.m_slash > 0f) { list.Add($"Slash {d.m_slash:0}"); } if (d.m_pierce > 0f) { list.Add($"Pierce {d.m_pierce:0}"); } if (d.m_chop > 0f) { list.Add($"Chop {d.m_chop:0}"); } if (d.m_pickaxe > 0f) { list.Add($"Pickaxe {d.m_pickaxe:0}"); } if (d.m_fire > 0f) { list.Add($"Fire {d.m_fire:0}"); } if (d.m_frost > 0f) { list.Add($"Frost {d.m_frost:0}"); } if (d.m_lightning > 0f) { list.Add($"Lightning {d.m_lightning:0}"); } if (d.m_poison > 0f) { list.Add($"Poison {d.m_poison:0}"); } if (d.m_spirit > 0f) { list.Add($"Spirit {d.m_spirit:0}"); } return string.Join(" · ", list); } private static string BuildStatLine(SharedData s) { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Expected I4, but got Unknown //IL_0118: Unknown result type (might be due to invalid IL or missing references) if (s == null) { return ""; } if (s.m_food > 0f) { List<string> list = new List<string>(4); list.Add($"+{s.m_food:0} HP"); if (s.m_foodStamina > 0f) { list.Add($"+{s.m_foodStamina:0} ST"); } if (s.m_foodEitr > 0f) { list.Add($"+{s.m_foodEitr:0} Eitr"); } list.Add($"{s.m_foodBurnTime:0}s"); return string.Join(" · ", list); } ItemType itemType = s.m_itemType; switch (itemType - 3) { case 0: case 1: case 6: case 11: case 12: case 17: case 19: case 20: { string text2 = BuildDamageLine(s.m_damages); if (text2.Length <= 0) { return ShortDesc(s.m_description, 60); } return text2; } case 3: case 4: case 8: case 14: { string text = $"Armor {s.m_armor:0}"; if (s.m_armorPerLevel > 0f) { text += $" (+{s.m_armorPerLevel:0}/lv)"; } return text; } case 2: return $"Block {s.m_blockPower:0}"; default: return ShortDesc(s.m_description, 60); } } private static int ClassifySe(string name) { if (string.IsNullOrEmpty(name)) { return 5; } if (name.StartsWith("GP_", StringComparison.OrdinalIgnoreCase)) { return 0; } if (name.StartsWith("SetEffect_", StringComparison.OrdinalIgnoreCase)) { return 1; } if (name.StartsWith("Potion_", StringComparison.OrdinalIgnoreCase)) { return 2; } string[] seDebuffKeys = SeDebuffKeys; foreach (string value in seDebuffKeys) { if (name.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0) { return 3; } } seDebuffKeys = SeComfortKeys; foreach (string value2 in seDebuffKeys) { if (name.IndexOf(value2, StringComparison.OrdinalIgnoreCase) >= 0) { return 4; } } return 5; } private List<SeEntry> FilteredStatusEffects() { string q = DebounceSearch(_seSearch, ref _seSearchApplied, ref _seSearchLastSeen, ref _seSearchDirtyAt); if (_seFilteredCache != null && q == _seFilterKey) { return _seFilteredCache; } if (_seIndex == null) { _seFilteredCache = new List<SeEntry>(); _seFilterKey = q; return _seFilteredCache; } IEnumerable<SeEntry> source = _seIndex; if (!string.IsNullOrEmpty(q)) { source = _seIndex.Where((SeEntry e) => e.Display.IndexOf(q, StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)e.Se).name.IndexOf(q, StringComparison.OrdinalIgnoreCase) >= 0); } _seFilteredCache = source.ToList(); _seFilterKey = q; return _seFilteredCache; } private void RefreshCaches() { _itemIndex = null; _seIndex = null; _seFilteredCache = null; _seFilterKey = null; _creatureIndex = null; _creatureCats = null; _subCatsCache = null; _subCatsKey = null; if ((Object)(object)ObjectDB.instance != (Object)null) { _itemIndex = (from e in (from go in ObjectDB.instance.m_items select go.GetComponent<ItemDrop>() into id where (Object)(object)id != (Object)null select id).Select(delegate(ItemDrop id) { var (cat, sub) = Categorize(id); return new ItemEntry { Drop = id, Prefab = ((Object)id).name, Display = LocalizeSafe(id.m_itemData.m_shared.m_name, ((Object)id).name), Info = BuildStatLine(id.m_itemData.m_shared), Cat = cat, Sub = sub }; }) orderby e.Cat, e.Sub, e.Display select e).ToList(); _seIndex = (from se in ObjectDB.instance.m_StatusEffects where (Object)(object)se != (Object)null select new SeEntry { Se = se, Display = LocalizeSafe(se.m_name, ((Object)se).name), Tooltip = ShortDesc(se.m_tooltip, 90), Hash = se.NameHash(), Bucket = ClassifySe(((Object)se).name) } into e orderby e.Bucket select e).ThenBy<SeEntry, string>((SeEntry e) => e.Display, StringComparer.OrdinalIgnoreCase).ToList(); } if ((Object)(object)ZNetScene.instance != (Object)null) { _creatureIndex = (from e in ZNetScene.instance.m_prefabs.Where((GameObject p) => (Object)(object)p != (Object)null && (Object)(object)p.GetComponent<Character>() != (Object)null && (Object)(object)p.GetComponent<Player>() == (Object)null).Select(delegate(GameObject p) { Character component = p.GetComponent<Character>(); return new CreatureEntry { Prefab = p, Name = ((Object)p).name, Display = LocalizeSafe(component.m_name, ((Object)p).name), Faction = ((object)Unsafe.As<Faction, Faction>(ref component.m_faction)/*cast due to .constrained prefix*/).ToString(), Boss = component.IsBoss(), Tamable = ((Object)(object)p.GetComponent<Tameable>() != (Object)null) }; }) orderby e.Faction, e.Display select e).ToList(); _creatureCats = new List<string> { "All", "Bosses", "Tamable" }; _creatureCats.AddRange(from f in _creatureIndex.Select((CreatureEntry e) => e.Faction).Distinct() orderby f select f); } } private static Texture2D SolidTex(Color c) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false) { hideFlags = (HideFlags)61 }; val.SetPixel(0, 0, c); val.Apply(); return val; } private void EnsureSkin() { //IL_001e: 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) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: 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_010e: Expected O, but got Unknown //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Expected O, but got Unknown //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Expected O, but got Unknown //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Expected O, but got Unknown //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Expected O, but got Unknown //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_0333: Expected O, but got Unknown //IL_033e: Unknown result type (might be due to invalid IL or missing references) //IL_0343: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) //IL_0357: Expected O, but got Unknown //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_0374: 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_0398: Unknown result type (might be due to invalid IL or missing references) //IL_03ab: Unknown result type (might be due to invalid IL or missing references) //IL_03b5: Expected O, but got Unknown //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03c9: Expected O, but got Unknown //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_03ee: Unknown result type (might be due to invalid IL or missing references) //IL_03f6: Unknown result type (might be due to invalid IL or missing references) //IL_0402: Expected O, but got Unknown //IL_040e: Unknown result type (might be due to invalid IL or missing references) //IL_0418: Expected O, but got Unknown //IL_0422: Unknown result type (might be due to invalid IL or missing references) //IL_042c: Expected O, but got Unknown //IL_0440: Unknown result type (might be due to invalid IL or missing references) //IL_0477: Unknown result type (might be due to invalid IL or missing references) //IL_047c: Unknown result type (might be due to invalid IL or missing references) //IL_0484: Unknown result type (might be due to invalid IL or missing references) //IL_0490: Expected O, but got Unknown //IL_049c: Unknown result type (might be due to invalid IL or missing references) //IL_04a6: Expected O, but got Unknown //IL_04b0: Unknown result type (might be due to invalid IL or missing references) //IL_04ba: Expected O, but got Unknown //IL_04df: Unknown result type (might be due to invalid IL or missing references) //IL_04e9: Expected O, but got Unknown //IL_04f3: Unknown result type (might be due to invalid IL or missing references) //IL_04fd: Expected O, but got Unknown //IL_0504: Unknown result type (might be due to invalid IL or missing references) //IL_050e: Expected O, but got Unknown //IL_052d: Unknown result type (might be due to invalid IL or missing references) //IL_0543: Unknown result type (might be due to invalid IL or missing references) //IL_0548: Unknown result type (might be due to invalid IL or missing references) //IL_0555: Expected O, but got Unknown //IL_056f: Unknown result type (might be due to invalid IL or missing references) //IL_0580: Unknown result type (might be due to invalid IL or missing references) //IL_0585: Unknown result type (might be due to invalid IL or missing references) //IL_058c: Unknown result type (might be due to invalid IL or missing references) //IL_0598: Expected O, but got Unknown //IL_059f: Unknown result type (might be due to invalid IL or missing references) //IL_05a4: Unknown result type (might be due to invalid IL or missing references) //IL_05ab: Unknown result type (might be due to invalid IL or missing references) //IL_05b7: Expected O, but got Unknown //IL_05be: Unknown result type (might be due to invalid IL or missing references) //IL_05c3: Unknown result type (might be due to invalid IL or missing references) //IL_05ca: Unknown result type (might be due to invalid IL or missing references) //IL_05d6: Expected O, but got Unknown //IL_05dd: Unknown result type (might be due to invalid IL or missing references) //IL_05e2: Unknown result type (might be due to invalid IL or missing references) //IL_05e9: Unknown result type (might be due to invalid IL or missing references) //IL_05f5: Expected O, but got Unknown if (!_skinReady || !((Object)(object)_texWood != (Object)null)) { _texWood = SolidTex(WoodColor(_panelAlphaLive)); _texRule = SolidTex(new Color(0.62f, 0.46f, 0.22f, 0.45f)); Texture2D background = SolidTex(new Color(0.22f, 0.16f, 0.1f, 1f)); Texture2D background2 = SolidTex(new Color(0.31f, 0.23f, 0.13f, 1f)); Texture2D background3 = SolidTex(new Color(0.16f, 0.115f, 0.07f, 1f)); Texture2D background4 = SolidTex(new Color(0.07f, 0.05f, 0.035f, 1f)); Color textColor = default(Color); ((Color)(ref textColor))..ctor(0.87f, 0.79f, 0.62f); Color textColor2 = default(Color); ((Color)(ref textColor2))..ctor(0.98f, 0.78f, 0.35f); _windowStyle = new GUIStyle(GUI.skin.window); _windowStyle.normal.background = _texWood; _windowStyle.onNormal.background = _texWood; _windowStyle.normal.textColor = textColor2; _windowStyle.onNormal.textColor = textColor2; _windowStyle.fontStyle = (FontStyle)1; _windowStyle.fontSize = 15; _buttonStyle = new GUIStyle(GUI.skin.button); _buttonStyle.normal.background = background; _buttonStyle.hover.background = background2; _buttonStyle.active.background = background3; _buttonStyle.onNormal.background = background2; _buttonStyle.normal.textColor = textColor; _buttonStyle.hover.textColor = textColor2; _buttonStyle.active.textColor = textColor2; _buttonStyle.onNormal.textColor = textColor2; _buttonStyle.fontStyle = (FontStyle)1; _labelStyle = new GUIStyle(GUI.skin.label) { fontSize = 13 }; _labelStyle.normal.textColor = textColor; _labelStyle.stretchWidth = false; _labelStyle.wordWrap = false; _headerStyle = new GUIStyle(_labelStyle) { fontStyle = (FontStyle)1, fontSize = 14 }; _headerStyle.normal.textColor = textColor2; _textFieldStyle = new GUIStyle(GUI.skin.textField); _textFieldStyle.normal.background = background4; _textFieldStyle.focused.background = background4; _textFieldStyle.hover.background = background4; _textFieldStyle.normal.textColor = textColor; _textFieldStyle.focused.textColor = textColor2; _textFieldStyle.hover.textColor = textColor; _textAreaStyle = new GUIStyle(_textFieldStyle) { wordWrap = true }; _toggleStyle = new GUIStyle(GUI.skin.toggle) { fontSize = 13, stretchWidth = false }; _toggleStyle.normal.textColor = textColor; _toggleStyle.onNormal.textColor = textColor2; _toggleStyle.hover.textColor = textColor; _toggleStyle.onHover.textColor = textColor2; _buttonStyle.padding = new RectOffset(10, 10, 5, 5); _buttonStyle.margin = new RectOffset(3, 3, 3, 3); _buttonStyle.fontSize = 13; _buttonStyle.stretchWidth = false; _tabStyle = new GUIStyle(_buttonStyle) { fontSize = 14, stretchWidth = true }; _tabStyle.padding = new RectOffset(12, 12, 8, 8); _tabStyle.margin = new RectOffset(3, 3, 4, 4); Texture2D background5 = SolidTex(new Color(0.42f, 0.3f, 0.12f, 1f)); _tabStyle.onNormal.background = background5; _tabStyle.onHover.background = background5; _catStyle = new GUIStyle(_buttonStyle) { fontSize = 12, stretchWidth = true }; _catStyle.padding = new RectOffset(10, 10, 6, 6); _catStyle.margin = new RectOffset(3, 3, 4, 4); _catStyle.onNormal.background = background5; _catStyle.onHover.background = background5; _rowEven = new GUIStyle(); _rowEven.padding = new RectOffset(4, 4, 3, 3); _rowOdd = new GUIStyle(_rowEven); _rowOdd.normal.background = SolidTex(new Color(1f, 1f, 1f, 0.035f)); _dimLabelStyle = new GUIStyle(_labelStyle) { fontSize = 12 }; _dimLabelStyle.normal.textColor = new Color(0.62f, 0.55f, 0.44f); _cellStyle = new GUIStyle(_labelStyle) { wordWrap = false, clipping = (TextClipping)1 }; _dimCellStyle = new GUIStyle(_dimLabelStyle) { wordWrap = false, clipping = (TextClipping)1 }; _hintStyle = new GUIStyle(_dimLabelStyle) { wordWrap = true, stretchWidth = true }; _proseStyle = new GUIStyle(_labelStyle) { wordWrap = true, stretchWidth = true }; ApplyFontSizes(); _skinReady = true; } } private static Font FindValheimFont() { Font[] source = Resources.FindObjectsOfTypeAll<Font>(); return ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("Norsebold", StringComparison.OrdinalIgnoreCase) >= 0)) ?? ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("AveriaSerifLibre", StringComparison.OrdinalIgnoreCase) >= 0)) ?? ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("Norse", StringComparison.OrdinalIgnoreCase) >= 0)); } private static Font FindFontFor(string choice) { Font[] source = Resources.FindObjectsOfTypeAll<Font>(); return (Font)(choice switch { "Norse Bold" => ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("Norsebold", StringComparison.OrdinalIgnoreCase) >= 0)), "Norse" => ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("Norse", StringComparison.OrdinalIgnoreCase) >= 0 && ((Object)f).name.IndexOf("bold", StringComparison.OrdinalIgnoreCase) < 0)), "Averia Serif" => ((IEnumerable<Font>)source).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("AveriaSerifLibre", StringComparison.OrdinalIgnoreCase) >= 0)), _ => FindValheimFont(), }); } private IEnumerable<string> ContentFontSamples() { int n = 0; if (_itemIndex != null) { foreach (ItemEntry item in _itemIndex) { if (n++ >= 200) { break; } yield return item.Display; } } n = 0; if (_creatureIndex == null) { yield break; } foreach (CreatureEntry item2 in _creatureIndex) { if (n++ >= 200) { break; } yield return item2.Display; } } private void ApplyFont() { if (_fontApplied && (Object)(object)_appliedFont == (Object)null && _fontChoiceCfg.Value != "Default") { _fontApplied = false; _fontTries = 0; _appliedFont = null; } if (_fontApplied) { return; } Font val = null; if (_fontChoiceCfg.Value != "Default") { if (Time.time < _nextFontTry) { return; } _nextFontTry = Time.time + 1f; val = FindFontFor(_fontChoiceCfg.Value); if ((Object)(object)val == (Object)null && ++_fontTries < 10) { return; } if ((Object)(object)val != (Object)null && Loc.ResolveFontSafety(val, ContentFontSamples())) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Font '" + ((Object)val).name + "' lacks glyphs for the current language; using the default font instead.")); val = null; } } GUIStyle[] array = (GUIStyle[])(object)new GUIStyle[16] { _windowStyle, _buttonStyle, _labelStyle, _headerStyle, _textFieldStyle, _toggleStyle, _tabStyle, _catStyle, _rowEven, _rowOdd, _dimLabelStyle, _textAreaStyle, _cellStyle, _dimCellStyle, _hintStyle, _proseStyle }; foreach (GUIStyle val2 in array) { if (val2 != null) { val2.font = val; } } _appliedFont = val; _fontApplied = true; } private static Texture2D LoadEmbeddedPng(string fileSuffix) { //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Expected O, but got Unknown try { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string n) => n.EndsWith(fileSuffix, StringComparison.OrdinalIgnoreCase)); if (text == null) { return null; } byte[] array; using (Stream stream = executingAssembly.GetManifestResourceStream(text)) { if (stream == null) { return null; } array = new byte[stream.Length]; int num2; for (int num = 0; num < array.Length; num += num2) { num2 = stream.Read(array, num, array.Length - num); if (num2 <= 0) { break; } } } MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("UnityEngine.ImageConversion"), "LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }, (Type[])null); if (methodInfo == null) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true) { filterMode = (FilterMode)2, hideFlags = (HideFlags)61 }; return ((bool)methodInfo.Invoke(null, new object[2] { val, array })) ? val : null; } catch { return null; } } private Texture2D CoffeeTex() { if (_coffeeTried && (Object)(object)_coffeeTex != (Object)null) { return _coffeeTex; } _coffeeTried = true; _coffeeTex = LoadEmbeddedPng("coffee.png"); return _coffeeTex; } private void DrawCoffeeButton(float minWidth) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown Texture2D val = CoffeeTex(); string text = Loc.T("set.buy_coffee"); if (GUILayout.Button(((Object)(object)val != (Object)null) ? new GUIContent(" " + text, (Texture)(object)val) : new GUIContent(text), _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.MinWidth(minWidth), GUILayout.Height(28f) })) { Application.OpenURL("https://www.paypal.com/donate/?business=HRKGKS3G5JD94&no_recurring=0&item_name=Your+Friendly+Neighborhood+Dev%2C+Halit.%0AMay+the+Lord+bless+you+with+even+more%21¤cy_code=USD"); } } private Texture2D LogoTex() { //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: 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_010e: Expected O, but got Unknown if (_logoTried) { return _logoTex; } _logoTried = true; try { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string n) => n.EndsWith("logo.png", StringComparison.OrdinalIgnoreCase)); if (text == null) { return null; } byte[] array; using (Stream stream = executingAssembly.GetManifestResourceStream(text)) { if (stream == null) { return null; } array = new byte[stream.Length]; int num2; for (int num = 0; num < array.Length; num += num2) { num2 = stream.Read(array, num, array.Length - num); if (num2 <= 0) { break; } } } MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("UnityEngine.ImageConversion"), "LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }, (Type[])null); if (methodInfo == null) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true) { filterMode = (FilterMode)2, hideFlags = (HideFlags)61 }; if (!(bool)methodInfo.Invoke(null, new object[2] { val, array })) { return null; } _logoAspect = (float)((Texture)val).width / (float)((Texture)val).height; _logoTex = val; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Logo header failed to load (panel still works): " + ex.Message)); } return _logoTex; } private Vector2 LogoSize() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Min(((Rect)(ref _windowRect)).width * 0.55f, 430f); return new Vector2(num, num / _logoAspect); } private float LogoHeaderHeight() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_logoTex == (Object)null || _showLogoCfg == null || !_showLogoCfg.Value) { return 0f; } return LogoSize().y + 6f; } private void DrawLogoHeader() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Invalid comparison between Unknown and I4 //IL_0073: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)LogoTex() == (Object)null) && _showLogoCfg.Value) { Vector2 val = LogoSize(); GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); GUILayout.FlexibleSpace(); Rect rect = GUILayoutUtility.GetRect(val.x, val.y, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(val.x), GUILayout.Height(val.y) }); if ((int)Event.current.type == 7) { GUI.DrawTexture(rect, (Texture)(object)_logoTex, (ScaleMode)2, true); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(6f); } } private static bool CompanionLoadedInProcess() { _companionLoadedHost = _companionLoadedHost ?? (AccessTools.TypeByName("AdminPanelCompanion.CompanionPlugin") != null); return _companionLoadedHost.Value; } private string CompanionWarning() { if ((Object)(object)ZNet.instance == (Object)null) { return null; } if (ZNet.instance.IsServer() && !CompanionLoadedInProcess()) { return Loc.T("chrome.companion_missing_host"); } if (_srvCompVersion != null) { if (!(_srvCompVersion == "2.3.0")) { return Loc.T("chrome.version_mismatch", "2.3.0", _srvCompVersion); } return null; } if (!ZNet.instance.IsServer() && _versionReqFirst > 0f && Time.time - _versionReqFirst > 15f) { return Loc.T("chrome.companion_silent"); } return null; } private void DrawSection(string title) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Invalid comparison between Unknown and I4 //IL_0064: Unknown result type (might be due to invalid IL or missing references) GUILayout.Space(10f); Rect rect = GUILayoutUtility.GetRect(1f, 2f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); if ((int)Event.current.type == 7 && (Object)(object)_texRule != (Object)null) { GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 14f, 2f), (Texture)(object)_texRule); } GUILayout.Space(4f); if (!string.IsNullOrEmpty(title)) { GUILayout.Label(title, _headerStyle, Array.Empty<GUILayoutOption>()); } } private void OnGUI() { //IL_00fd: 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_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Expected O, but got Unknown //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Invalid comparison between Unknown and I4 //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Expected O, but got Unknown //IL_022f: Unknown result type (might be due to invalid IL or missing references) if (_visible) { EnsureSkin(); ApplyFont(); ((Rect)(ref _windowRect)).width = Mathf.Clamp(((Rect)(ref _windowRect)).width, 660f, (float)Screen.width); ((Rect)(ref _windowRect)).height = Mathf.Clamp(((Rect)(ref _windowRect)).height, 300f, (float)Screen.height); ((Rect)(ref _windowRect)).x = Mathf.Clamp(((Rect)(ref _windowRect)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref _windowRect)).width)); ((Rect)(ref _windowRect)).y = Mathf.Clamp(((Rect)(ref _windowRect)).y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref _windowRect)).height)); bool flag = (Object)(object)_logoTex != (Object)null && _showLogoCfg.Value; _windowRect = GUI.Window(918273, _windowRect, new WindowFunction(DrawWindow), flag ? Loc.T("chrome.title_hint", _toggleKey.Value) : Loc.T("chrome.title_full", _toggleKey.Value), _windowStyle); if ((int)Event.current.type == 1) { SaveWindowRect(); } if (_sideMode != SideMode.None) { float num = Mathf.Clamp(((Rect)(ref _windowRect)).height, 380f, 560f); float num2 = ((((Rect)(ref _windowRect)).xMax + 6f + 340f <= (float)Screen.width) ? (((Rect)(ref _windowRect)).xMax + 6f) : (((Rect)(ref _windowRect)).x - 340f - 6f)); GUI.Window(918274, new Rect(num2, ((Rect)(ref _windowRect)).y, 340f, num), new WindowFunction(DrawSideWindow), (_sideMode == SideMode.WhatsNew) ? "What's New" : "Bug Report", _windowStyle); } } } private void SaveWindowRect() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (!(_windowRect == _lastSavedRect)) { _lastSavedRect = _windowRect; _windowRectCfg.Value = $"{((Rect)(ref _windowRect)).x:0},{((Rect)(ref _windowRect)).y:0},{((Rect)(ref _windowRect)).width:0},{((Rect)(ref _windowRect)).height:0}"; ((BaseUnityPlugin)this).Config.Save(); } } private float ListView(float reserve) { return Mathf.Clamp(((Rect)(ref _windowRect)).height - reserve - LogoHeaderHeight() - (float)Mathf.Max(0, _fontSizeLive - 13) * 3f, 160f, 4000f); } private void DrawWindow(int id) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Invalid comparison between Unknown and I4 //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Invalid comparison between Unknown and I4 //IL_03e4: 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_0350: Invalid comparison between Unknown and I4 //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0361: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing references) if (GUI.Button(new Rect(((Rect)(ref _windowRect)).width - 34f, 4f, 28f, 22f), "✕", _buttonStyle)) { _visible = false; FlushNotes(); CommitUiSettings(); _openDropdown = null; } if ((Object)(object)LocalPlayer == (Object)null) { GUILayout.Label(Loc.T("chrome.not_in_game"), _labelStyle, Array.Empty<GUILayoutOption>()); GUI.DragWindow(); return; } if ((int)Event.current.type == 8) { _openDropdownLayout = _openDropdown; _rebindTargetLayout = _rebindTarget; _updateBannerLayout = _updateAvailable; _versionWarnLayout = CompanionWarning(); _othersSnapshot = OtherPlayers(); _globalKeysLayout = (((Object)(object)ZoneSystem.instance != (Object)null) ? new List<string>(ZoneSystem.instance.GetGlobalKeys()) : null); } DrawLogoHeader(); if (_updateBannerLayout != null) { GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); GUILayout.Label(Loc.T("chrome.update_available", _updateBannerLayout, "2.3.0"), _proseStyle, Array.Empty<GUILayoutOption>()); if (GUILayout.Button(Loc.T("chrome.get_update"), _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MinWidth(110f) })) { Application.OpenURL("https://github.com/hldblc/ValheimAdminPanel/releases/latest"); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } if (_versionWarnLayout != null) { GUILayout.Label(_versionWarnLayout, _proseStyle, Array.Empty<GUILayoutOption>()); } GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); for (int i = 0; i < TabKeys.Length; i++) { if (GUILayout.Toggle(_tab == i, Loc.T(TabKeys[i]), _tabStyle, Array.Empty<GUILayoutOption>()) && _tab != i) { _tab = i; _openDropdown = null; _rebindTarget = 0; } } GUILayout.EndHorizontal(); GUILayout.Space(14f); try { switch (_tab) { case 0: DrawItemsTab(); break; case 1: DrawCreaturesTab(); break; case 2: DrawBossesTab(); break; case 3: DrawPlayerTab(); break; case 4: DrawWorldTab(); break; case 5: DrawPlayersTab(); break; case 6: DrawServerTab(); break; case 7: DrawSettingsTab(); break; } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)$"AdminPanel tab {_tab} draw error: {ex.Message}"); } Rect val = default(Rect); ((Rect)(ref val))..ctor(((Rect)(ref _windowRect)).width - 22f, ((Rect)(ref _windowRect)).height - 22f, 22f, 22f); GUI.Label(val, "◢", _dimLabelStyle); Event current = Event.current; if (_resizing && ((int)current.rawType == 1 || !Input.GetMouseButton(0))) { _resizing = false; SaveWindowRect(); } if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val)).Contains(current.mousePosition)) { _resizing = true; current.Use(); } else if (_resizing && (int)current.type == 3 && current.button == 0) { ((Rect)(ref _windowRect)).width = Mathf.Clamp(current.mousePosition.x + 11f, 660f, (float)Screen.width - ((Rect)(ref _windowRect)).x); ((Rect)(ref _windowRect)).height = Mathf.Clamp(current.mousePosition.y + 11f, 300f, (float)Screen.height - ((Rect)(ref _windowRect)).y); current.Use(); } GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f)); } private List<PlayerInfo> OtherPlayers() { if ((Object)(object)ZNet.instance == (Object)null) { return new List<PlayerInfo>(); } string myName = (((Object)(object)LocalPlayer != (Object)null) ? LocalPlayer.GetPlayerName() : ""); return (from p in ZNet.instance.GetPlayerList() where p.m_name != myName select p).ToList(); } private int GiveTargetIndex(List<PlayerInfo> others) { if (_giveTargetId == 0L) { return -1; } return others.FindIndex((PlayerInfo p) => PeerIdOf(p) == _giveTargetId); } private string GiveTargetName(List<PlayerInfo> others) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) int num = GiveTargetIndex(others); if (num >= 0) { return others[num].m_name; } return Loc.T("common.nobody"); } private void CycleGiveTarget(List<PlayerInfo> others) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) if (others.Count == 0) { _giveTargetId = 0L; return; } int index = (GiveTargetIndex(others) + 1) % others.Count; _giveTargetId = PeerIdOf(others[index]); } private Vector3 SpawnPos(float distance = 3f) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0050: Unknown result type (might be due to invalid IL or missing references) if (_spawnAtCrosshair && (Object)(object)GameCamera.instance != (Object)null) { Transform transform = ((Component)GameCamera.instance).transform; RaycastHit val = default(RaycastHit); if (Physics.Raycast(transform.position, transform.forward, ref val, 200f)) { return ((RaycastHit)(ref val)).point + Vector3.up * 0.3f; } } return ((Component)LocalPlayer).transform.position + ((Component)LocalPlayer).transform.forward * distance + Vector3.up * 0.5f; } private void SrvRpc(string method, params object[] parameters) { long num = ServerUid(); if (num == 0L && (!((Object)(object)ZNet.instance != (Object)null) || !ZNet.instance.IsServer())) { Message(Loc.T("common.not_connected_srv")); } else if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.InvokeRoutedRPC(num, method, parameters); } } private void SendServerSpawn(int kind, string prefabName, Vector3 pos, int count, int levelOrQuality, bool tamed, string petName = "") { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0015: Unknown result type (might be due to invalid IL or missing references) ZPackage val = new ZPackage(); val.Write(kind); val.Write(prefabName); val.Write(pos); val.Write(count); val.Write(levelOrQuality); val.Write(tamed); val.Write(petName ?? ""); SrvRpc("AP_SrvSpawn", val); } private void SendServerGive(long targetUid, string prefabName, int amount, int quality) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown ZPackage val = new ZPackage(); val.Write(targetUid); val.Write(prefabName); val.Write(amount); val.Write(quality); val.Write(_crafterNameCfg.Value ?? ""); SrvRpc("AP_SrvGive", val); } private void Message(string text) { Player localPlayer = LocalPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, "[Admin] " + text, 0, (Sprite)null); } ((BaseUnityPlugin)this).Logger.LogInfo((object)text); } private static bool HasIcon(ItemDrop drop) { Sprite[] icons = drop.m_itemData.m_shared.m_icons; if (icons != null) { return icons.Length != 0; } return false; } private void DrawIcon(ItemEntry e) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) Rect rect = GUILayoutUtility.GetRect(26f, 26f, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width(26f), GUILayout.Height(26f) }); if (!e.IconTried) { e.IconTried = true; try { e.Icon = e.Drop.m_itemData.GetIcon(); } catch { } } Sprite icon = e.Icon; if (!((Object)(object)icon == (Object)null) && !((Object)(object)icon.texture == (Object)null)) { Rect textureRect = icon.textureRect; Texture2D texture = icon.texture; Rect val = default(Rect); ((Rect)(ref val))..ctor(((Rect)(ref textureRect)).x / (float)((Texture)texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)texture).height); GUI.DrawTextureWithTexCoords(rect, (Texture)(object)texture, val); } } private void ToggleFavorite(string prefab) { if (!_favorites.Remove(prefab)) { _favorites.Add(prefab); } _favoritesCfg.Value = string.Join(",", _favorites); _favVersion++; ((BaseUnityPlugin)this).Config.Save(); } private void MarkRecent(ItemEntry e) { _recentItems.RemoveAll((ItemEntry r) => r.Prefab == e.Prefab); _recentItems.Insert(0, e); if (_recentItems.Count > 25) { _recentItems.RemoveAt(_recentItems.Count - 1); } _recentVersion++; } private void EnsureLocalizedLabels() { if (!(_labelsLang == Loc.ActiveCode) || _mainCatLabels == null) { _labelsLang = Loc.ActiveCode; _mainCatLabels = new string[MainCatKeys.Length]; for (int i = 0; i < MainCatKeys.Length; i++) { _mainCatLabels[i] = Loc.T(MainCatKeys[i]); } _itemSortLabels = new string[3] { Loc.T("sort.az"), Loc.T("sort.za"), Loc.T("sort.category") }; _creatureSortLabels = new string[3] { Loc.T("sort.az"), Loc.T("sort.za"), Loc.T("sort.faction") }; } } private bool ConfirmButton(string id, string label, param
BepInEx/plugins/AdminPanelCompanion.dll
Decompiled 2 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("AdminPanelCompanion")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("AdminPanelCompanion")] [assembly: AssemblyTitle("AdminPanelCompanion")] [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 AdminPanelCompanion { [BepInPlugin("com.halitb.adminpanelcompanion", "AdminPanelCompanion", "2.3.0")] public class CompanionPlugin : BaseUnityPlugin { [HarmonyPatch] private static class RpcRegistration { [HarmonyPatch(typeof(ZNet), "Awake")] [HarmonyPostfix] private static void ZNetAwakePostfix() { if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.Register<ZPackage>("AP_SrvGive", (Action<long, ZPackage>)OnServerGive); ZRoutedRpc.instance.Register<ZPackage>("AP_SrvSpawn", (Action<long, ZPackage>)OnServerSpawn); ZRoutedRpc.instance.Register<long>("AP_SrvReqInv", (Action<long, long>)OnServerRequestInventory); ZRoutedRpc.instance.Register("AP_SrvUndo", (Action<long>)OnServerUndo); ZRoutedRpc.instance.Register<ZPackage>("AP_SrvTeleport", (Action<long, ZPackage>)OnServerTeleport); ZRoutedRpc.instance.Register<long>("AP_SrvHeal", (Action<long, long>)OnServerHeal); ZRoutedRpc.instance.Register<long>("AP_SrvKick", (Action<long, long>)OnServerKick); ZRoutedRpc.instance.Register<long>("AP_SrvBan", (Action<long, long>)OnServerBan); ZRoutedRpc.instance.Register<string>("AP_SrvUnban", (Action<long, string>)OnServerUnban); ZRoutedRpc.instance.Register<string>("AP_SrvBroadcast", (Action<long, string>)OnServerBroadcast); ZRoutedRpc.instance.Register<long, string>("AP_SrvMsg", (Action<long, long, string>)OnServerMessage); ZRoutedRpc.instance.Register<string, Vector3>("AP_SrvEvent", (Action<long, string, Vector3>)OnServerEvent); ZRoutedRpc.instance.Register<bool>("AP_SrvPeaceful", (Action<long, bool>)OnServerPeaceful); ZRoutedRpc.instance.Register<ZPackage>("AP_SrvInvRemove", (Action<long, ZPackage>)OnServerInvRemove); ZRoutedRpc.instance.Register<ZPackage>("AP_SrvSkillRaise", (Action<long, ZPackage>)OnServerSkillRaise); ZRoutedRpc.instance.Register<long, int>("AP_SrvApplySE", (Action<long, long, int>)OnServerApplyStatusEffect); ZRoutedRpc.instance.Register("AP_SrvVersion", (Action<long>)OnServerVersionReq); ZRoutedRpc.instance.Register("AP_SrvSkipNight", (Action<long>)OnServerSkipNight); ZRoutedRpc.instance.Register<string, int, int, string>("AP_GiveItem", (Method<string, int, int, string>)OnGiveItem); ZRoutedRpc.instance.Register<ZPackage>("AP_RemoveItem", (Action<long, ZPackage>)OnRemoveItem); ZRoutedRpc.instance.Register<ZPackage>("AP_SkillRaise", (Action<long, ZPackage>)OnSkillRaise); ZRoutedRpc.instance.Register<long>("AP_InvRequest", (Action<long, long>)OnInventoryRequest); ZRoutedRpc.instance.Register<Vector3>("AP_Teleport", (Action<long, Vector3>)OnTeleport); ZRoutedRpc.instance.Register("AP_HealSelf", (Action<long>)OnHealSelf); ZRoutedRpc.instance.Register<int>("AP_ApplySE", (Action<long, int>)OnApplyStatusEffect); ZRoutedRpc.instance.Register<string>("AP_Msg", (Action<long, string>)OnMessage); } } } [HarmonyPatch(typeof(ZRoutedRpc), "RPC_RoutedRPC")] private static class RouteRpcSanitizer { private static void Prefix(ZRpc rpc, ZPackage pkg) { if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer() || pkg == null) { return; } long num = 0L; foreach (ZNetPeer peer in ZNet.instance.GetPeers()) { if (peer != null && peer.m_rpc == rpc) { num = peer.m_uid; break; } } if (num == 0L) { return; } int pos = pkg.GetPos(); try { pkg.SetPos(8); if (pkg.ReadLong() != num) { pkg.SetPos(8); pkg.Write(num); } } catch { } finally { pkg.SetPos(pos); } } } public const string PluginGuid = "com.halitb.adminpanelcompanion"; public const string PluginName = "AdminPanelCompanion"; public const string PluginVersion = "2.3.0"; internal static CompanionPlugin Instance; private const int UndoDepth = 20; private static readonly Dictionary<long, List<List<ZDOID>>> UndoHistory = new Dictionary<long, List<List<ZDOID>>>(); private static bool SenderSanitizerActive; private static bool IsDedicatedServer { get { if ((Object)(object)ZNet.instance != (Object)null) { return ZNet.instance.IsServer(); } return false; } } private void Awake() { Instance = this; Harmony.CreateAndPatchAll(typeof(RpcRegistration), (string)null); try { Harmony.CreateAndPatchAll(typeof(RouteRpcSanitizer), (string)null); SenderSanitizerActive = true; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("RoutedRPC sender-sanitizer patch failed (server security reduced): " + ex.Message)); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"AdminPanelCompanion 2.3.0 loaded."); } private static void Log(string msg) { CompanionPlugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)msg); } } private static long ServerUid() { return (((Object)(object)ZNet.instance != (Object)null) ? ZNet.instance.GetServerPeer() : null)?.m_uid ?? 0; } private static bool IsLocalHostSender(long sender) { if (SenderSanitizerActive && (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer() && ZDOMan.instance != null) { return sender == ZDOMan.GetSessionID(); } return false; } private static bool SenderIsServer(long sender) { long num = ServerUid(); if (num != 0L && sender == num) { return true; } return IsLocalHostSender(sender); } private static string BareId(string host) { if (string.IsNullOrEmpty(host) || !host.Contains("_")) { return host; } return host.Substring(host.IndexOf('_') + 1); } private static SyncedList GetList(string field) { object? obj = AccessTools.Field(typeof(ZNet), field)?.GetValue(ZNet.instance); return (SyncedList)((obj is SyncedList) ? obj : null); } private static bool SenderIsAdmin(long sender) { if ((Object)(object)ZNet.instance == (Object)null) { return false; } if (IsLocalHostSender(sender)) { return true; } ZNetPeer peer = ZNet.instance.GetPeer(sender); string text = ((peer != null && peer.m_socket != null) ? peer.m_socket.GetHostName() : null); if (string.IsNullOrEmpty(text)) { Log($"DENIED admin action from unresolvable peer {sender}"); return false; } SyncedList list = GetList("m_adminList"); int num; if (list != null) { if (!list.Contains(text)) { num = (list.Contains(BareId(text)) ? 1 : 0); if (num == 0) { goto IL_008a; } } else { num = 1; } goto IL_00a0; } num = 0; goto IL_008a; IL_00a0: return (byte)num != 0; IL_008a: Log($"DENIED admin action from non-admin {text} (peer {sender})"); goto IL_00a0; } private static void OnServerGive(long sender, ZPackage pkg) { if (IsDedicatedServer && SenderIsAdmin(sender)) { long num; string text; int num3; string text2; int num2; try { num = pkg.ReadLong(); text = pkg.ReadString(); num2 = pkg.ReadInt(); num3 = pkg.ReadInt(); text2 = pkg.ReadString(); } catch (Exception ex) { Log("AP_SrvGive: malformed packet dropped (" + ex.Message + ")"); return; } if (!string.IsNullOrEmpty(text) && num2 > 0) { num2 = Mathf.Min(num2, 100000); Log($"Admin {sender} gives {num2}x {text} (q{num3}) to peer {num}"); ZRoutedRpc.instance.InvokeRoutedRPC(num, "AP_GiveItem", new object[4] { text, num2, num3, text2 }); } } } private static void OnServerSpawn(long sender, ZPackage pkg) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0225: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) if (!IsDedicatedServer || !SenderIsAdmin(sender)) { return; } int num; string text; Vector3 val; int num3; bool flag; string text2; int num2; try { num = pkg.ReadInt(); text = pkg.ReadString(); val = pkg.ReadVector3(); num2 = pkg.ReadInt(); num3 = pkg.ReadInt(); flag = pkg.ReadBool(); text2 = pkg.ReadString(); } catch (Exception ex) { Log("AP_SrvSpawn: malformed packet dropped (" + ex.Message + ")"); return; } if (string.IsNullOrEmpty(text)) { return; } num2 = Mathf.Clamp(num2, 0, 100); GameObject val2 = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(text) : null); if ((Object)(object)val2 == (Object)null && (Object)(object)ObjectDB.instance != (Object)null) { val2 = ObjectDB.instance.GetItemPrefab(text); } if ((Object)(object)val2 == (Object)null) { Log("AP_SrvSpawn: prefab '" + text + "' not found"); return; } Log($"Admin {sender} spawns {num2}x {text} (kind {num}) at {val}"); List<ZDOID> batch = new List<ZDOID>(); if (num == 0) { ItemDrop component = val2.GetComponent<ItemDrop>(); int num4 = ((!((Object)(object)component != (Object)null)) ? 1 : component.m_itemData.m_shared.m_maxStackSize); if (num4 < 1) { num4 = 1; } int num5 = num2; while (num5 > 0) { int num6 = Mathf.Min(num5, num4); num5 -= num6; GameObject obj = Object.Instantiate<GameObject>(val2, val, Quaternion.identity); RememberSpawn(obj, batch); ItemDrop component2 = obj.GetComponent<ItemDrop>(); if ((Object)(object)component2 != (Object)null) { component2.m_itemData.m_stack = num6; component2.m_itemData.m_quality = Mathf.Clamp(num3, 1, component2.m_itemData.m_shared.m_maxQuality); component2.m_itemData.m_durability = component2.m_itemData.GetMaxDurability(); } } } else { Vector3 val3 = default(Vector3); for (int i = 0; i < num2; i++) { ((Vector3)(ref val3))..ctor(Random.Range(-1.5f, 1.5f), 0.5f, Random.Range(-1.5f, 1.5f)); GameObject val4 = Object.Instantiate<GameObject>(val2, val + val3, Quaternion.identity); RememberSpawn(val4, batch); Character component3 = val4.GetComponent<Character>(); if (!((Object)(object)component3 != (Object)null)) { continue; } if (num3 > 1) { component3.SetLevel(Mathf.Clamp(num3, 1, 10)); } if (flag) { component3.SetTamed(true); } if (!flag || string.IsNullOrEmpty(text2)) { continue; } ZNetView component4 = val4.GetComponent<ZNetView>(); if (component4 != null) { ZDO zDO = component4.GetZDO(); if (zDO != null) { zDO.Set("TamedName", text2); } } } } PushUndo(sender, batch); } private static void RememberSpawn(GameObject go, List<ZDOID> batch) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) ZNetView component = go.GetComponent<ZNetView>(); ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null); if (val != null) { batch.Add(val.m_uid); } } private static void PushUndo(long sender, List<ZDOID> batch) { if (batch != null && batch.Count != 0) { PruneUndoHistory(); if (!UndoHistory.TryGetValue(sender, out var value)) { value = new List<List<ZDOID>>(); UndoHistory[sender] = value; } value.Add(batch); if (value.Count > 20) { value.RemoveAt(0); } } } private static void PruneUndoHistory() { if (UndoHistory.Count == 0 || (Object)(object)ZNet.instance == (Object)null) { return; } List<long> list = null; foreach (KeyValuePair<long, List<List<ZDOID>>> item in UndoHistory) { if (!IsLocalHostSender(item.Key) && ZNet.instance.GetPeer(item.Key) == null) { (list ?? (list = new List<long>())).Add(item.Key); } } if (list == null) { return; } foreach (long item2 in list) { UndoHistory.Remove(item2); } } private static void OnServerUndo(long sender) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) if (!IsDedicatedServer || !SenderIsAdmin(sender)) { return; } if (!UndoHistory.TryGetValue(sender, out var value) || value.Count == 0) { Log($"Admin {sender} undo: nothing left to undo"); ZRoutedRpc.instance.InvokeRoutedRPC(sender, "AP_Msg", new object[1] { "Nothing left to undo" }); return; } List<ZDOID> list = value[value.Count - 1]; value.RemoveAt(value.Count - 1); if (value.Count == 0) { UndoHistory.Remove(sender); } int num = 0; foreach (ZDOID item in list) { ZDO zDO = ZDOMan.instance.GetZDO(item); if (zDO != null) { ZNetView val = ZNetScene.instance.FindInstance(zDO); ZNetView val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<ZNetView>() : null); if ((Object)(object)val2 != (Object)null) { val2.ClaimOwnership(); val2.Destroy(); num++; } else { zDO.SetOwner(ZDOMan.GetSessionID()); ZDOMan.instance.DestroyZDO(zDO); num++; } } } int count = value.Count; Log($"Admin {sender} undo: removed {num} spawned objects ({count} step(s) left)"); ZRoutedRpc.instance.InvokeRoutedRPC(sender, "AP_Msg", new object[1] { $"Undo: removed {num} object(s) — {count} step(s) left" }); } private static void OnServerRequestInventory(long sender, long targetUid) { if (IsDedicatedServer && SenderIsAdmin(sender)) { ZRoutedRpc.instance.InvokeRoutedRPC(targetUid, "AP_InvRequest", new object[1] { sender }); } } private static void OnServerTeleport(long sender, ZPackage pkg) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) if (IsDedicatedServer && SenderIsAdmin(sender)) { long num; Vector3 val; try { num = pkg.ReadLong(); val = pkg.ReadVector3(); } catch (Exception ex) { Log("AP_SrvTeleport: malformed packet dropped (" + ex.Message + ")"); return; } Log($"Admin {sender} teleports peer {num} to {val}"); ZRoutedRpc.instance.InvokeRoutedRPC(num, "AP_Teleport", new object[1] { val }); } } private static void OnServerHeal(long sender, long targetUid) { if (IsDedicatedServer && SenderIsAdmin(sender)) { ZRoutedRpc.instance.InvokeRoutedRPC(targetUid, "AP_HealSelf", Array.Empty<object>()); } } private static string HostOfPeer(long uid) { if ((Object)(object)ZNet.instance == (Object)null) { return null; } foreach (ZNetPeer peer in ZNet.instance.GetPeers()) { if (peer.m_uid == uid) { return (peer.m_socket != null) ? peer.m_socket.GetHostName() : null; } } return null; } private static bool KickByUid(long uid) { if ((Object)(object)ZNet.instance == (Object)null) { return false; } foreach (ZNetPeer peer in ZNet.instance.GetPeers()) { if (peer.m_uid != uid) { continue; } MethodInfo methodInfo = AccessTools.Method(typeof(ZNet), "InternalKick", new Type[1] { typeof(ZNetPeer) }, (Type[])null) ?? AccessTools.Method(typeof(ZNet), "Kick", new Type[1] { typeof(ZNetPeer) }, (Type[])null); if (methodInfo != null) { methodInfo.Invoke(ZNet.instance, new object[1] { peer }); } else { ZRpc rpc = peer.m_rpc; if (rpc != null) { ISocket socket = rpc.GetSocket(); if (socket != null) { socket.Close(); } } } return true; } return false; } private static void OnServerKick(long sender, long uid) { if (IsDedicatedServer && SenderIsAdmin(sender)) { bool flag = KickByUid(uid); Log(string.Format("Admin {0} kick peer {1}: {2}", sender, uid, flag ? "kicked" : "peer not found")); } } private static void OnServerBan(long sender, long uid) { if (!IsDedicatedServer || !SenderIsAdmin(sender)) { return; } string text = BareId(HostOfPeer(uid)); if (!string.IsNullOrEmpty(text)) { SyncedList list = GetList("m_bannedList"); if (list != null && !list.Contains(text)) { list.Add(text); } } bool flag = KickByUid(uid); Log(string.Format("Admin {0} ban peer {1} ({2}): {3}", sender, uid, text ?? "unknown", flag ? "kicked" : "peer not found")); } private static void OnServerUnban(long sender, string host) { if (IsDedicatedServer && SenderIsAdmin(sender)) { SyncedList list = GetList("m_bannedList"); string text = BareId(host); if (list != null) { list.Remove(text); list.Remove(host); } Log($"Admin {sender} unbans {text}"); } } private static void OnServerBroadcast(long sender, string text) { if (IsDedicatedServer && SenderIsAdmin(sender)) { Log("Admin broadcast: " + text); ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "AP_Msg", new object[1] { text }); } } private static void OnServerMessage(long sender, long targetUid, string text) { if (IsDedicatedServer && SenderIsAdmin(sender)) { ZRoutedRpc.instance.InvokeRoutedRPC(targetUid, "AP_Msg", new object[1] { text }); } } private static void OnServerEvent(long sender, string eventName, Vector3 pos) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) if (IsDedicatedServer && SenderIsAdmin(sender) && !((Object)(object)RandEventSystem.instance == (Object)null)) { Log($"Admin {sender} starts event '{eventName}' at {pos}"); RandEventSystem.instance.SetRandomEventByName(eventName, pos); } } private static void OnServerPeaceful(long sender, bool peaceful) { if (!IsDedicatedServer || !SenderIsAdmin(sender)) { return; } if (!((AccessTools.Field(typeof(RandEventSystem), "m_events") ?? AccessTools.Field(typeof(RandEventSystem), "m_randomEvents"))?.GetValue(RandEventSystem.instance) is IList list)) { Log("Peaceful toggle: event list not found"); return; } int num = 0; foreach (object item in list) { FieldInfo fieldInfo = AccessTools.Field(item.GetType(), "m_enabled"); if (!(fieldInfo == null)) { fieldInfo.SetValue(item, !peaceful); num++; } } if (peaceful && (Object)(object)RandEventSystem.instance != (Object)null) { RandEventSystem.instance.ResetRandomEvent(); } Log(string.Format("Peaceful mode {0} ({1} events toggled)", peaceful ? "ON" : "OFF", num)); } private static void OnGiveItem(long sender, string prefabName, int amount, int quality, string crafter) { //IL_011d: 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_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !SenderIsServer(sender)) { return; } GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(prefabName) : null); if ((Object)(object)val == (Object)null) { return; } ItemDrop component = val.GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null || component.m_itemData.m_shared.m_icons == null || component.m_itemData.m_shared.m_icons.Length == 0) { return; } int num = component.m_itemData.m_shared.m_maxStackSize; if (num < 1) { num = 1; } int num2 = amount; while (num2 > 0) { int num3 = Mathf.Min(num2, num); num2 -= num3; ItemData val2 = component.m_itemData.Clone(); val2.m_dropPrefab = val; val2.m_stack = num3; val2.m_quality = Mathf.Clamp(quality, 1, val2.m_shared.m_maxQuality); val2.m_durability = val2.GetMaxDurability(); if (!string.IsNullOrEmpty(crafter)) { val2.m_crafterID = 1L; val2.m_crafterName = crafter; } if (!((Humanoid)localPlayer).GetInventory().AddItem(val2)) { ItemDrop component2 = Object.Instantiate<GameObject>(val, ((Component)localPlayer).transform.position + Vector3.up, Quaternion.identity).GetComponent<ItemDrop>(); if ((Object)(object)component2 != (Object)null) { component2.m_itemData.m_stack = num3; component2.m_itemData.m_quality = Mathf.Clamp(quality, 1, component2.m_itemData.m_shared.m_maxQuality); } } } ((Character)localPlayer).Message((MessageType)2, $"An admin granted you {amount}x {prefabName}!", 0, (Sprite)null); } private static void OnServerInvRemove(long sender, ZPackage pkg) { //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown if (IsDedicatedServer && SenderIsAdmin(sender)) { long num; string text; int num2; try { num = pkg.ReadLong(); text = pkg.ReadString(); num2 = pkg.ReadInt(); } catch (Exception ex) { Log("AP_SrvInvRemove: malformed packet dropped (" + ex.Message + ")"); return; } if (!string.IsNullOrEmpty(text) && num2 > 0) { Log($"Admin {sender} removes {num2}x {text} from peer {num}"); ZPackage val = new ZPackage(); val.Write(text); val.Write(num2); val.Write(sender); ZRoutedRpc.instance.InvokeRoutedRPC(num, "AP_RemoveItem", new object[1] { val }); } } } private static void OnRemoveItem(long sender, ZPackage pkg) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !SenderIsServer(sender)) { return; } string text; int num; long replyTo; try { text = pkg.ReadString(); num = pkg.ReadInt(); replyTo = pkg.ReadLong(); } catch { return; } if (string.IsNullOrEmpty(text) || num <= 0) { return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); int num2 = 0; foreach (ItemData item in new List<ItemData>(inventory.GetAllItems())) { if (num2 >= num) { break; } if (!((((Object)(object)item.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name : item.m_shared.m_name) != text)) { if (item.m_equipped) { ((Humanoid)localPlayer).UnequipItem(item, false); } int num3 = Mathf.Min(item.m_stack, num - num2); inventory.RemoveItem(item, num3); num2 += num3; } } if (num2 > 0) { ((Character)localPlayer).Message((MessageType)2, $"An admin removed {num2}x {text} from your inventory", 0, (Sprite)null); } OnInventoryRequest(sender, replyTo); } private static void OnServerVersionReq(long sender) { if (IsDedicatedServer) { ZRoutedRpc.instance.InvokeRoutedRPC(sender, "AP_VersionData", new object[1] { "2.3.0" }); } } private static void OnServerSkipNight(long sender) { if (IsDedicatedServer && SenderIsAdmin(sender) && !((Object)(object)EnvMan.instance == (Object)null)) { Log($"Admin {sender} skips to morning"); EnvMan.instance.SkipToMorning(); } } private static void OnServerSkillRaise(long sender, ZPackage pkg) { //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Expected O, but got Unknown if (IsDedicatedServer && SenderIsAdmin(sender)) { long num; string text; string text2; float num2; try { num = pkg.ReadLong(); text = pkg.ReadString(); num2 = pkg.ReadSingle(); text2 = pkg.ReadString(); } catch (Exception ex) { Log("AP_SrvSkillRaise: malformed packet dropped (" + ex.Message + ")"); return; } if (!string.IsNullOrEmpty(text)) { num2 = Mathf.Clamp(num2, -100f, 100f); Log($"Admin {sender} raises {text} by {num2} for peer {num}"); ZPackage val = new ZPackage(); val.Write(text); val.Write(num2); val.Write(text2 ?? ""); ZRoutedRpc.instance.InvokeRoutedRPC(num, "AP_SkillRaise", new object[1] { val }); } } } private static void OnServerApplyStatusEffect(long sender, long targetUid, int seHash) { if (IsDedicatedServer && SenderIsAdmin(sender)) { Log($"Admin {sender} applies status effect {seHash} to peer {targetUid}"); ZRoutedRpc.instance.InvokeRoutedRPC(targetUid, "AP_ApplySE", new object[1] { seHash }); } } private static void OnApplyStatusEffect(long sender, int seHash) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !SenderIsServer(sender)) { return; } ((Character)localPlayer).GetSEMan().AddStatusEffect(seHash, true, 0, 0f); if (!((Object)(object)ObjectDB.instance != (Object)null)) { return; } foreach (StatusEffect statusEffect in ObjectDB.instance.m_StatusEffects) { if ((Object)(object)statusEffect != (Object)null && statusEffect.NameHash() == seHash) { string text = ((!string.IsNullOrEmpty(statusEffect.m_name) && !statusEffect.m_name.StartsWith("$")) ? statusEffect.m_name : ((Object)statusEffect).name); if (!string.IsNullOrEmpty(text)) { ((Character)localPlayer).Message((MessageType)1, "[Admin] " + text, 0, (Sprite)null); } break; } } } private static void OnSkillRaise(long sender, ZPackage pkg) { //IL_007e: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !SenderIsServer(sender)) { return; } string text; float num; string text2; try { text = pkg.ReadString(); num = pkg.ReadSingle(); text2 = pkg.ReadString(); } catch { return; } if (string.IsNullOrEmpty(text)) { return; } ((Character)localPlayer).GetSkills().CheatRaiseSkill(text, Mathf.Clamp(num, -100f, 100f), false); if (!string.IsNullOrEmpty(text2)) { string text3 = ""; if (Enum.TryParse<SkillType>(text, out SkillType result)) { text3 = $"\n{text}: {((Character)localPlayer).GetSkills().GetSkillLevel(result):0.#}"; } ((Character)localPlayer).Message((MessageType)2, text2 + text3, 0, (Sprite)null); } } private static void OnInventoryRequest(long sender, long replyTo) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || !SenderIsServer(sender)) { return; } ZPackage val = new ZPackage(); val.Write(localPlayer.GetPlayerName()); List<ItemData> allItems = ((Humanoid)localPlayer).GetInventory().GetAllItems(); val.Write(allItems.Count); foreach (ItemData item in allItems) { val.Write(((Object)(object)item.m_dropPrefab != (Object)null) ? ((Object)item.m_dropPrefab).name : item.m_shared.m_name); val.Write(item.m_stack); val.Write(item.m_quality); } ZRoutedRpc.instance.InvokeRoutedRPC(replyTo, "AP_InvData", new object[1] { val }); } private static void OnTeleport(long sender, Vector3 pos) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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) Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && SenderIsServer(sender)) { ((Character)localPlayer).TeleportTo(pos + Vector3.up, ((Component)localPlayer).transform.rotation, true); ((Character)localPlayer).Message((MessageType)2, "An admin teleported you!", 0, (Sprite)null); } } private static void OnHealSelf(long sender) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && SenderIsServer(sender)) { ((Character)localPlayer).Heal(((Character)localPlayer).GetMaxHealth(), true); ((Character)localPlayer).Message((MessageType)2, "An admin healed you!", 0, (Sprite)null); } } private static void OnMessage(long sender, string text) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && SenderIsServer(sender)) { ((Character)localPlayer).Message((MessageType)2, "[Server] " + text, 0, (Sprite)null); } } } }