using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Cryptography; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using Microsoft.CodeAnalysis; using ServerSync; using SkillControl.Managers; using SkillControl.Professions; using SkillControl.UI; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Core.Tokens; using YamlDotNet.Helpers; using YamlDotNet.Serialization; using YamlDotNet.Serialization.BufferedDeserialization; using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators; using YamlDotNet.Serialization.Converters; using YamlDotNet.Serialization.EventEmitters; using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization.NodeDeserializers; using YamlDotNet.Serialization.NodeTypeResolvers; using YamlDotNet.Serialization.ObjectFactories; using YamlDotNet.Serialization.ObjectGraphTraversalStrategies; using YamlDotNet.Serialization.ObjectGraphVisitors; using YamlDotNet.Serialization.Schemas; using YamlDotNet.Serialization.TypeInspectors; using YamlDotNet.Serialization.TypeResolvers; using YamlDotNet.Serialization.Utilities; using YamlDotNet.Serialization.ValueDeserializers; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("SkillControl")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyProduct("SkillControl")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")] [assembly: AssemblyFileVersion("1.0.5")] [assembly: AssemblyCompany("RustyMods")] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.5.0")] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<92279cac-f02a-492f-8688-a3b9c598b742>Embedded] internal sealed class <92279cac-f02a-492f-8688-a3b9c598b742>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [<92279cac-f02a-492f-8688-a3b9c598b742>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [CompilerGenerated] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [<92279cac-f02a-492f-8688-a3b9c598b742>Embedded] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace SkillControl { [NullableContext(1)] [BepInPlugin("RustyMods.SkillControl", "SkillControl", "1.0.5")] [Nullable(0)] public class SkillControlPlugin : BaseUnityPlugin { [NullableContext(0)] public enum Toggle { On = 1, Off = 0 } [NullableContext(0)] private class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order; [UsedImplicitly] public bool? Browsable; [Nullable(2)] [UsedImplicitly] public string Category; [UsedImplicitly] [Nullable(new byte[] { 2, 1 })] public Action CustomDrawer; } internal const string ModName = "SkillControl"; internal const string ModVersion = "1.0.5"; internal const string Author = "RustyMods"; private const string ModGUID = "RustyMods.SkillControl"; private static string ConfigFileName = "RustyMods.SkillControl.cfg"; private static string ConfigFileFullPath; internal static string ConnectionError; private readonly Harmony _harmony = new Harmony("RustyMods.SkillControl"); public static readonly ManualLogSource SkillControlLogger; public static readonly ConfigSync ConfigSync; public static readonly AssetBundle _AssetBundle; private static ConfigEntry _serverConfigLocked; public static ConfigEntry _UIKey; public static ConfigEntry _JobLimit; public static ConfigEntry _Currency; public static ConfigEntry _CostToRemove; public static ConfigEntry _ForceJob; public static ConfigEntry _UIPosition; public static ConfigEntry _RemoveSkillExperience; public static ConfigEntry _OverrideDefaults; public void Awake() { Localizer.Load(); PluginPaths.CreateDirectories(); FileWaterManager.InitFileWatcher(); SpriteManager.GetIcons(); JobManager.InitJobs(); InitConfigs(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony.PatchAll(executingAssembly); SetupWatcher(); } private void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } private void Update() { LoadUI.UpdateUI(); } private static AssetBundle GetAssetBundle(string fileName) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string name = executingAssembly.GetManifestResourceNames().Single([NullableContext(0)] (string str) => str.EndsWith(fileName)); using Stream stream = executingAssembly.GetManifestResourceStream(name); return AssetBundle.LoadFromStream(stream); } private void SetupWatcher() { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName); fileSystemWatcher.Changed += ReadConfigValues; fileSystemWatcher.Created += ReadConfigValues; fileSystemWatcher.Renamed += ReadConfigValues; fileSystemWatcher.IncludeSubdirectories = true; fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; fileSystemWatcher.EnableRaisingEvents = true; } private void ReadConfigValues(object sender, FileSystemEventArgs e) { if (!File.Exists(ConfigFileFullPath)) { return; } try { SkillControlLogger.LogDebug((object)"ReadConfigValues called"); ((BaseUnityPlugin)this).Config.Reload(); } catch { SkillControlLogger.LogError((object)("There was an issue loading your " + ConfigFileName)); SkillControlLogger.LogError((object)"Please check your config entries for spelling and format!"); } } private void InitConfigs() { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Expected O, but got Unknown //IL_00f7: Unknown result type (might be due to invalid IL or missing references) _serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only."); ConfigSync.AddLockingConfigEntry(_serverConfigLocked); _UIKey = config("2 - Settings", "Key", (KeyCode)288, "Set key code to open job menu", synchronizedSetting: false); _JobLimit = config("2 - Settings", "Limit", 2, new ConfigDescription("Set the amount of jobs a player can have", (AcceptableValueBase)(object)new AcceptableValueRange(1, 10), Array.Empty())); _Currency = config("2 - Settings", "Currency", "Coins", "Set the currency used for skill controller, if invalid, defaults to coins"); _CostToRemove = config("2 - Settings", "Cost To Remove", 999, new ConfigDescription("Set the cost to remove job", (AcceptableValueBase)(object)new AcceptableValueRange(0, 999), Array.Empty())); _ForceJob = config("2 - Settings", "Force Employment", Toggle.Off, "If on, job menu will stay open until player chooses at least one job"); _UIPosition = config("2 - Settings", "Position", Vector2.zero, "Set the position of the UI", synchronizedSetting: false); _UIPosition.SettingChanged += LoadUI.OnPositionChange; _RemoveSkillExperience = config("2 - Settings", "Lose Skills", Toggle.Off, "If on, removing jobs, also removes skill experiences"); _OverrideDefaults = config("2 - Settings", "Override Defaults", Toggle.On, "If on, plugin overrides default skill gain"); } private ConfigEntry config<[Nullable(2)] T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags); ConfigEntry val2 = ((BaseUnityPlugin)this).Config.Bind(group, name, value, val); SyncedConfigEntry syncedConfigEntry = ConfigSync.AddConfigEntry(val2); syncedConfigEntry.SynchronizedConfig = synchronizedSetting; return val2; } private ConfigEntry config<[Nullable(2)] T>(string group, string name, T value, string description, bool synchronizedSetting = true) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty()), synchronizedSetting); } static SkillControlPlugin() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; ConnectionError = ""; SkillControlLogger = Logger.CreateLogSource("SkillControl"); ConfigSync = new ConfigSync("RustyMods.SkillControl") { DisplayName = "SkillControl", CurrentVersion = "1.0.5", MinimumRequiredVersion = "1.0.5" }; _AssetBundle = GetAssetBundle("jobsbundle"); _serverConfigLocked = null; _UIKey = null; _JobLimit = null; _Currency = null; _CostToRemove = null; _ForceJob = null; _UIPosition = null; _RemoveSkillExperience = null; _OverrideDefaults = null; } } public static class KeyboardExtensions { public static bool IsKeyDown(this KeyboardShortcut shortcut) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return (int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey) && ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func)Input.GetKey); } public static bool IsKeyHeld(this KeyboardShortcut shortcut) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return (int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKey(((KeyboardShortcut)(ref shortcut)).MainKey) && ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func)Input.GetKey); } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] public static class RegisterAndCheckVersion { [NullableContext(1)] private static void Prefix(ZNetPeer peer, ref ZNet __instance) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown SkillControlPlugin.SkillControlLogger.LogDebug((object)"Registering version RPC handler"); peer.m_rpc.Register("SkillControl_VersionCheck", (Action)RpcHandlers.RPC_SkillControl_Version); SkillControlPlugin.SkillControlLogger.LogInfo((object)"Invoking version check"); ZPackage val = new ZPackage(); val.Write("1.0.5"); peer.m_rpc.Invoke("SkillControl_VersionCheck", new object[1] { val }); } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [Nullable(0)] [NullableContext(1)] public static class VerifyClient { private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance) { if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc)) { return true; } SkillControlPlugin.SkillControlLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") never sent version or couldn't due to previous disconnect, disconnecting")); rpc.Invoke("Error", new object[1] { 3 }); return false; } private static void Postfix(ZNet __instance) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "SkillControlRequestAdminSync", new object[1] { (object)new ZPackage() }); } } [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] public class ShowConnectionError { [NullableContext(1)] private static void Postfix(FejdStartup __instance) { if (__instance.m_connectionFailedPanel.activeSelf) { __instance.m_connectionFailedError.fontSizeMax = 25f; __instance.m_connectionFailedError.fontSizeMin = 15f; TMP_Text connectionFailedError = __instance.m_connectionFailedError; connectionFailedError.text = connectionFailedError.text + "\n" + SkillControlPlugin.ConnectionError; } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] public static class RemoveDisconnectedPeerFromVerified { [NullableContext(1)] private static void Prefix(ZNetPeer peer, ref ZNet __instance) { if (__instance.IsServer()) { SkillControlPlugin.SkillControlLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list")); RpcHandlers.ValidatedPeers.Remove(peer.m_rpc); } } } [Nullable(0)] [NullableContext(1)] public static class RpcHandlers { public static readonly List ValidatedPeers = new List(); public static void RPC_SkillControl_Version(ZRpc rpc, ZPackage pkg) { string text = pkg.ReadString(); SkillControlPlugin.SkillControlLogger.LogInfo((object)("Version check, local: 1.0.5, remote: " + text)); if (text != "1.0.5") { SkillControlPlugin.ConnectionError = "SkillControl Installed: 1.0.5\n Needed: " + text; if (ZNet.instance.IsServer()) { SkillControlPlugin.SkillControlLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting...")); rpc.Invoke("Error", new object[1] { 3 }); } } else if (!ZNet.instance.IsServer()) { SkillControlPlugin.SkillControlLogger.LogInfo((object)"Received same version from server!"); } else { SkillControlPlugin.SkillControlLogger.LogInfo((object)("Adding peer (" + rpc.m_socket.GetHostName() + ") to validated list")); ValidatedPeers.Add(rpc); } } public static string ComputeHashForMod() { using SHA256 sHA = SHA256.Create(); byte[] array = sHA.ComputeHash(File.ReadAllBytes(Assembly.GetExecutingAssembly().Location)); StringBuilder stringBuilder = new StringBuilder(); byte[] array2 = array; foreach (byte b in array2) { stringBuilder.Append(b.ToString("X2")); } return stringBuilder.ToString(); } } } namespace SkillControl.UI { [Nullable(0)] [NullableContext(1)] public static class LoadUI { [HarmonyPatch(typeof(InventoryGui), "Awake")] [NullableContext(0)] private static class Load_Jobs_UI { [NullableContext(1)] private static void Postfix(InventoryGui __instance) { if (Object.op_Implicit((Object)(object)__instance)) { InitUI(__instance); } } } [HarmonyPatch(typeof(InventoryGui), "Show")] [NullableContext(0)] private static class Override_ForceEmployment { private static void Postfix() { OverrideUI(); } } private static Text m_title = null; private static Image m_icon = null; private static Text m_description = null; private static Text m_availableSkills = null; private static Text m_lockedSkills = null; private static Text m_selectedTitle = null; private static Text m_selectButtonText = null; private static Button m_selectButton = null; private static Button m_closeButton = null; private static Transform m_partAvailable = null; private static Transform m_partLocked = null; private static Transform m_partTabs = null; private static Transform m_selected = null; private static GameObject m_selectedContainer = null; private static GameObject m_UI = null; private static GameObject m_skillElement = null; private static GameObject m_tabElement = null; private static RectTransform m_position = null; private static Sprite m_defaultBackground = null; private static ItemDrop m_defaultCurrency = null; private static JobData m_selectedJob = new JobData { Name = "$msg_select_job", Description = "" }; private static void GetGameAssets(InventoryGui instance, out ButtonSfx sfx, out Button button) { Transform val = instance.m_trophiesPanel.transform.Find("TrophiesFrame/Closebutton"); sfx = ((Component)val).GetComponent(); button = ((Component)val).GetComponent