Decompiled source of AlesModded v1.9.2
LootCrates.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.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 LootCrates.Behaviors; using LootCrates.Managers; using Microsoft.CodeAnalysis; using ServerSync; using TMPro; using UnityEngine; 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: AssemblyFileVersion("1.0.0")] [assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")] [assembly: ComVisible(false)] [assembly: AssemblyTrademark("")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyProduct("LootCrates")] [assembly: AssemblyCompany("RustyMods")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyDescription("")] [assembly: AssemblyTitle("LootCrates")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<44bcb520-52e4-4fb4-aaa1-4a2a3c219cde>Embedded] internal sealed class <44bcb520-52e4-4fb4-aaa1-4a2a3c219cde>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [<44bcb520-52e4-4fb4-aaa1-4a2a3c219cde>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [CompilerGenerated] internal sealed class <e42e9aab-c10f-4d92-8699-eca8bdf50386>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <e42e9aab-c10f-4d92-8699-eca8bdf50386>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <e42e9aab-c10f-4d92-8699-eca8bdf50386>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [<44bcb520-52e4-4fb4-aaa1-4a2a3c219cde>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class <31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContextAttribute : Attribute { public readonly byte Flag; public <31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace LootCrates { [BepInPlugin("RustyMods.LootCrates", "LootCrates", "1.0.0")] [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(0)] public class LootCratesPlugin : BaseUnityPlugin { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] public enum Toggle { On = 1, Off = 0 } [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] private class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order; [UsedImplicitly] public bool? Browsable; [UsedImplicitly] [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(2)] public string Category; [UsedImplicitly] [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(new byte[] { 2, 1 })] public Action<ConfigEntryBase> CustomDrawer; } internal const string ModName = "LootCrates"; internal const string ModVersion = "1.0.0"; internal const string Author = "RustyMods"; private const string ModGUID = "RustyMods.LootCrates"; private static readonly string ConfigFileName = "RustyMods.LootCrates.cfg"; private static readonly string ConfigFileFullPath; internal static string ConnectionError; private readonly Harmony _harmony = new Harmony("RustyMods.LootCrates"); public static readonly ManualLogSource LootCratesLogger; public static readonly ConfigSync ConfigSync; public static LootCratesPlugin _Plugin; public static GameObject _Root; private static ConfigEntry<Toggle> _serverConfigLocked; public static ConfigEntry<Toggle> _checkPlayerCodes; private void LoadConfigs() { _serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only."); ConfigSync.AddLockingConfigEntry<Toggle>(_serverConfigLocked); _checkPlayerCodes = config("2 - Settings", "Check Used Codes", Toggle.On, "If on, crates will check if player already used code"); } public void Awake() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown Localizer.Load(); _Plugin = this; _Root = new GameObject("root"); Object.DontDestroyOnLoad((Object)(object)_Root); _Root.SetActive(false); LoadConfigs(); LootManager.ReadFile(); LootManager.InitServerSync(); LootManager.InitFileWatch(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony.PatchAll(executingAssembly); SetupWatcher(); } private void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } 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 { LootCratesLogger.LogDebug((object)"ReadConfigValues called"); ((BaseUnityPlugin)this).Config.Reload(); } catch { LootCratesLogger.LogError((object)("There was an issue loading your " + ConfigFileName)); LootCratesLogger.LogError((object)"Please check your config entries for spelling and format!"); } } public ConfigEntry<T> config<[<e42e9aab-c10f-4d92-8699-eca8bdf50386>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<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val); SyncedConfigEntry<T> syncedConfigEntry = ConfigSync.AddConfigEntry<T>(val2); syncedConfigEntry.SynchronizedConfig = synchronizedSetting; return val2; } public ConfigEntry<T> config<[<e42e9aab-c10f-4d92-8699-eca8bdf50386>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<object>()), synchronizedSetting); } static LootCratesPlugin() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; ConnectionError = ""; LootCratesLogger = Logger.CreateLogSource("LootCrates"); ConfigSync = new ConfigSync("RustyMods.LootCrates") { DisplayName = "LootCrates", CurrentVersion = "1.0.0", MinimumRequiredVersion = "1.0.0" }; _Plugin = null; _Root = null; _serverConfigLocked = null; _checkPlayerCodes = null; } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] public static class RegisterAndCheckVersion { [<31d73ba5-17ac-416a-8de0-05113198bfbd>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 LootCratesPlugin.LootCratesLogger.LogDebug((object)"Registering version RPC handler"); peer.m_rpc.Register<ZPackage>("LootCrates_VersionCheck", (Action<ZRpc, ZPackage>)RpcHandlers.RPC_LootCrates_Version); LootCratesPlugin.LootCratesLogger.LogInfo((object)"Invoking version check"); ZPackage val = new ZPackage(); val.Write("1.0.0"); peer.m_rpc.Invoke("LootCrates_VersionCheck", new object[1] { val }); } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(0)] public static class VerifyClient { private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance) { if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc)) { return true; } LootCratesPlugin.LootCratesLogger.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(), "LootCratesRequestAdminSync", new object[1] { (object)new ZPackage() }); } } [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] public class ShowConnectionError { [<31d73ba5-17ac-416a-8de0-05113198bfbd>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" + LootCratesPlugin.ConnectionError; } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] public static class RemoveDisconnectedPeerFromVerified { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] private static void Prefix(ZNetPeer peer, ref ZNet __instance) { if (__instance.IsServer()) { LootCratesPlugin.LootCratesLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list")); RpcHandlers.ValidatedPeers.Remove(peer.m_rpc); } } } [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(0)] [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] public static class RpcHandlers { public static readonly List<ZRpc> ValidatedPeers = new List<ZRpc>(); public static void RPC_LootCrates_Version(ZRpc rpc, ZPackage pkg) { string text = pkg.ReadString(); LootCratesPlugin.LootCratesLogger.LogInfo((object)("Version check, local: 1.0.0, remote: " + text)); if (text != "1.0.0") { LootCratesPlugin.ConnectionError = "LootCrates Installed: 1.0.0\n Needed: " + text; if (ZNet.instance.IsServer()) { LootCratesPlugin.LootCratesLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting...")); rpc.Invoke("Error", new object[1] { 3 }); } } else if (!ZNet.instance.IsServer()) { LootCratesPlugin.LootCratesLogger.LogInfo((object)"Received same version from server!"); } else { LootCratesPlugin.LootCratesLogger.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 LootCrates.Managers { [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(0)] [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] [PublicAPI] public class Localizer { private static readonly Dictionary<string, Dictionary<string, Func<string>>> PlaceholderProcessors; private static readonly Dictionary<string, Dictionary<string, string>> loadedTexts; private static readonly ConditionalWeakTable<Localization, string> localizationLanguage; private static readonly List<WeakReference<Localization>> localizationObjects; [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(2)] private static BaseUnityPlugin _plugin; private static readonly List<string> fileExtensions; private static BaseUnityPlugin plugin { get { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown if (_plugin == null) { IEnumerable<TypeInfo> source; try { source = Assembly.GetExecutingAssembly().DefinedTypes.ToList(); } catch (ReflectionTypeLoadException ex) { source = from t in ex.Types where t != null select t.GetTypeInfo(); } _plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First([<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t))); } return _plugin; } } private static void UpdatePlaceholderText(Localization localization, string key) { localizationLanguage.TryGetValue(localization, out var value); string text = loadedTexts[value][key]; if (PlaceholderProcessors.TryGetValue(key, out var value2)) { text = value2.Aggregate(text, [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value())); } localization.AddWord(key, text); } public static void AddPlaceholder<T>(string key, string placeholder, ConfigEntry<T> config, [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(new byte[] { 2, 1, 1 })] Func<T, string> convertConfigValue = null) { if (convertConfigValue == null) { convertConfigValue = [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] [return: <e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(1)] (T val) => val.ToString(); } if (!PlaceholderProcessors.ContainsKey(key)) { PlaceholderProcessors[key] = new Dictionary<string, Func<string>>(); } config.SettingChanged += [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] (object _, EventArgs _) => { UpdatePlaceholder(); }; if (loadedTexts.ContainsKey(Localization.instance.GetSelectedLanguage())) { UpdatePlaceholder(); } void UpdatePlaceholder() { PlaceholderProcessors[key][placeholder] = () => convertConfigValue(config.Value); UpdatePlaceholderText(Localization.instance, key); } } public static void AddText(string key, string text) { List<WeakReference<Localization>> list = new List<WeakReference<Localization>>(); foreach (WeakReference<Localization> localizationObject in localizationObjects) { if (localizationObject.TryGetTarget(out var target)) { Dictionary<string, string> dictionary = loadedTexts[localizationLanguage.GetOrCreateValue(target)]; if (!target.m_translations.ContainsKey(key)) { dictionary[key] = text; target.AddWord(key, text); } } else { list.Add(localizationObject); } } foreach (WeakReference<Localization> item in list) { localizationObjects.Remove(item); } } public static void Load() { LoadLocalization(Localization.instance, Localization.instance.GetSelectedLanguage()); } private static void LoadLocalization(Localization __instance, string language) { if (!localizationLanguage.Remove(__instance)) { localizationObjects.Add(new WeakReference<Localization>(__instance)); } localizationLanguage.Add(__instance, language); Dictionary<string, string> dictionary = new Dictionary<string, string>(); foreach (string item in from f in Directory.GetFiles(Path.GetDirectoryName(Paths.PluginPath), plugin.Info.Metadata.Name + ".*", SearchOption.AllDirectories) where fileExtensions.IndexOf(Path.GetExtension(f)) >= 0 select f) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item); if (dictionary.ContainsKey(fileNameWithoutExtension)) { Debug.LogWarning((object)("Duplicate key " + fileNameWithoutExtension + " found for " + plugin.Info.Metadata.Name + ". The duplicate file found at " + item + " will be skipped.")); } else { dictionary[fileNameWithoutExtension] = item; } } byte[] array = LoadTranslationFromAssembly("English"); if (array == null) { throw new Exception("Found no English localizations in mod " + plugin.Info.Metadata.Name + ". Expected an embedded resource translations/English.json or translations/English.yml."); } Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(Encoding.UTF8.GetString(array)); if (dictionary2 == null) { throw new Exception("Localization for mod " + plugin.Info.Metadata.Name + " failed: Localization file was empty."); } string text = null; if (language != "English") { if (dictionary.ContainsKey(language)) { text = File.ReadAllText(dictionary[language]); } else { byte[] array2 = LoadTranslationFromAssembly(language); if (array2 != null) { text = Encoding.UTF8.GetString(array2); } } } if (text == null && dictionary.ContainsKey("English")) { text = File.ReadAllText(dictionary["English"]); } if (text != null) { foreach (KeyValuePair<string, string> item2 in new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(text) ?? new Dictionary<string, string>()) { dictionary2[item2.Key] = item2.Value; } } loadedTexts[language] = dictionary2; foreach (KeyValuePair<string, string> item3 in dictionary2) { UpdatePlaceholderText(__instance, item3.Key); } } static Localizer() { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown PlaceholderProcessors = new Dictionary<string, Dictionary<string, Func<string>>>(); loadedTexts = new Dictionary<string, Dictionary<string, string>>(); localizationLanguage = new ConditionalWeakTable<Localization, string>(); localizationObjects = new List<WeakReference<Localization>>(); fileExtensions = new List<string> { ".json", ".yml" }; Harmony val = new Harmony("org.bepinex.helpers.LocalizationManager"); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "LoadCSV", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } [return: <e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(2)] private static byte[] LoadTranslationFromAssembly(string language) { foreach (string fileExtension in fileExtensions) { byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension); if (array != null) { return array; } } return null; } [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(2)] public static byte[] ReadEmbeddedFileBytes([<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(1)] string resourceFileName, Assembly containingAssembly = null) { using MemoryStream memoryStream = new MemoryStream(); if ((object)containingAssembly == null) { containingAssembly = Assembly.GetCallingAssembly(); } string text = containingAssembly.GetManifestResourceNames().FirstOrDefault([<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] (string str) => str.EndsWith(resourceFileName, StringComparison.Ordinal)); if (text != null) { containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream); } return (memoryStream.Length == 0L) ? null : memoryStream.ToArray(); } } [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(0)] [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] public static class LootManager { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] [HarmonyPatch(typeof(ZNet), "Awake")] private static class ZNet_Awake_Patch { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] private static void Postfix(ZNet __instance) { if (Object.op_Implicit((Object)(object)__instance) && __instance.IsServer()) { UpdateServerFile(); } } } [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class RegisterCrate { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] private static void Postfix(ZNetScene __instance) { if (Object.op_Implicit((Object)(object)__instance)) { CreateCrates(__instance); } } } [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class RegisterForgettingOrb { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] private static void Postfix(ObjectDB __instance) { if (Object.op_Implicit((Object)(object)ZNetScene.instance)) { CreateForgettingItem(__instance); } } } [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] [HarmonyPatch(typeof(Player), "ConsumeItem")] private static class Player_ConsumeItem_Patch { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] private static void Prefix(ItemData item) { if (item.m_shared.m_name == "$item_lootcrate_codebreaker") { TerminalCommands.ClearCodes(); } } } [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] public class FileData { [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(1)] public List<CrateData> Crates = new List<CrateData>(); } [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(0)] public class CrateData { public string Code = null; public List<LootData> Loot = new List<LootData>(); } [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] public class LootData { [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(1)] public string ItemName = null; public int Stack; public int Quality; } [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(0)] public class PlayerCustomData { public string m_playerName; public int m_playerID; public List<string> m_usedCodes = new List<string>(); } private static readonly CustomSyncedValue<string> m_serverSynced = new CustomSyncedValue<string>(LootCratesPlugin.ConfigSync, "LootCrateServerSyncData", ""); private static readonly string m_filePath; private static FileData m_data; private static bool m_serverSyncInitialized; public static bool CodeExists(string code) { return m_data.Crates.Exists((CrateData data) => data.Code == code); } [return: <e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(2)] public static CrateData GetCrate(string code) { return m_data.Crates.Find((CrateData data) => data.Code == code); } public static void ReadFile() { if (!File.Exists(m_filePath)) { m_data.Crates = CreateDefaultCrate(); ISerializer serializer = new SerializerBuilder().Build(); string contents = serializer.Serialize(m_data); File.WriteAllText(m_filePath, contents); } else { string input = File.ReadAllText(m_filePath); IDeserializer deserializer = new DeserializerBuilder().Build(); m_data = deserializer.Deserialize<FileData>(input); } } public static void InitFileWatch() { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, "LootCrates.yml") { IncludeSubdirectories = false, SynchronizingObject = ThreadingHelper.SynchronizingObject, EnableRaisingEvents = true }; fileSystemWatcher.Changed += OnFileChange; } public static void OnFileChange(object sender, FileSystemEventArgs e) { LootCratesPlugin.LootCratesLogger.LogInfo((object)"LootCrate file changed"); string input = File.ReadAllText(m_filePath); IDeserializer deserializer = new DeserializerBuilder().Build(); if (Object.op_Implicit((Object)(object)ZNet.instance)) { if (!ZNet.instance.IsServer()) { LootCratesPlugin.LootCratesLogger.LogInfo((object)"Not server, loot crates will not be updated"); return; } m_data = deserializer.Deserialize<FileData>(input); UpdateServerFile(); } else { m_data = deserializer.Deserialize<FileData>(input); } } public static void InitServerSync() { if (m_serverSyncInitialized) { return; } m_serverSynced.ValueChanged += delegate { if (!Utility.IsNullOrWhiteSpace(m_serverSynced.Value)) { IDeserializer deserializer = new DeserializerBuilder().Build(); m_data = deserializer.Deserialize<FileData>(m_serverSynced.Value); LootCratesPlugin.LootCratesLogger.LogInfo((object)"Received loot crate data from server"); } }; m_serverSyncInitialized = true; } public static void UpdateServerFile() { ISerializer serializer = new SerializerBuilder().Build(); m_serverSynced.Value = serializer.Serialize(m_data); } private static List<CrateData> CreateDefaultCrate() { return new List<CrateData> { new CrateData { Code = "1234", Loot = new List<LootData> { new LootData { ItemName = "Resin", Stack = 10, Quality = 1 }, new LootData { ItemName = "Wood", Stack = 10, Quality = 1 } } } }; } public static void CreateCrates(ZNetScene __instance) { Clone(__instance, "piece_chest", "piece_iron_lootcrate", "Loot Crate"); Clone(__instance, "piece_chest_blackmetal", "piece_blackmetal_lootcrate", "Loot Crate"); Clone(__instance, "piece_chest_wood", "piece_wood_lootcrate", "Loot Crate"); Clone(__instance, "piece_gift1", "piece_gift1_lootcrate", "Loot Crate"); Clone(__instance, "piece_gift2", "piece_gift2_lootcrate", "Loot Crate"); Clone(__instance, "piece_gift3", "piece_gift3_lootcrate", "Loot Crate"); Clone(__instance, "piece_pot1", "piece_pot1_lootcrate", "Loot Crate"); Clone(__instance, "piece_pot1_cracked", "piece_pot1_cracked_lootcrate", "Loot Crate"); Clone(__instance, "piece_pot1_red", "piece_pot1_red_lootcrate", "Loot Crate"); Clone(__instance, "piece_pot2", "piece_pot2_lootcrate", "Loot Crate"); Clone(__instance, "piece_pot2_cracked", "piece_pot2_cracked_lootcrate", "Loot Crate"); Clone(__instance, "piece_pot2_red", "piece_pot2_red_lootcrate", "Loot Crate"); Clone(__instance, "piece_pot3", "piece_pot3_lootcrate", "Loot Crate"); Clone(__instance, "piece_pot3_cracked", "piece_pot3_cracked_lootcrate", "Loot Crate"); Clone(__instance, "piece_pot3_red", "piece_pot3_red_lootcrate", "Loot Crate"); Clone(__instance, "piece_chest_private", "piece_private_lootcrate", "Loot Crate"); } private static void Clone(ZNetScene __instance, string prefabName, string name, string displayName) { //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) GameObject prefab = __instance.GetPrefab(prefabName); if (!Object.op_Implicit((Object)(object)prefab)) { return; } GameObject val = Object.Instantiate<GameObject>(prefab, LootCratesPlugin._Root.transform, false); ((Object)val).name = name; LootCrate lootCrate = val.AddComponent<LootCrate>(); Container val2 = default(Container); if (val.TryGetComponent<Container>(ref val2)) { lootCrate.m_bkg = val2.m_bkg; lootCrate.m_open = val2.m_open; lootCrate.m_closed = val2.m_closed; lootCrate.m_openEffects = val2.m_openEffects; lootCrate.m_closedEffects = val2.m_closeEffects; Object.Destroy((Object)(object)val2); } Piece piece = default(Piece); if (val.TryGetComponent<Piece>(ref piece)) { ConfigEntry<string> nameConfig = LootCratesPlugin._Plugin.config(name, "Display Name", displayName, "Set display name"); piece.m_name = nameConfig.Value; nameConfig.SettingChanged += [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] (object sender, EventArgs args) => { piece.m_name = nameConfig.Value; }; ConfigEntry<PieceCategory> category = LootCratesPlugin._Plugin.config<PieceCategory>(name, "Category", (PieceCategory)0, "Set category"); piece.m_category = GetCategory(category); category.SettingChanged += [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] (object sender, EventArgs args) => { //IL_0011: 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) piece.m_category = GetCategory(category); }; ConfigEntry<string> recipe = LootCratesPlugin._Plugin.config(name, "Recipe", "SwordCheat:1", "[prefab]:[amount],[prefab]:[amount]"); piece.m_resources = GetRequirements(recipe).ToArray(); recipe.SettingChanged += [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] (object sender, EventArgs args) => { piece.m_resources = GetRequirements(recipe).ToArray(); }; } WearNTear wearNTear = default(WearNTear); if (val.TryGetComponent<WearNTear>(ref wearNTear)) { ConfigEntry<float> health = LootCratesPlugin._Plugin.config(name, "Health", wearNTear.m_health, "Set health"); wearNTear.m_health = health.Value; health.SettingChanged += [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] (object sender, EventArgs args) => { wearNTear.m_health = health.Value; }; } RegisterToScene(val); RegisterToHammer(val); } private static void CreateForgettingItem(ObjectDB __instance) { GameObject itemPrefab = __instance.GetItemPrefab("StaminaUpgrade_Greydwarf"); if (!Object.op_Implicit((Object)(object)itemPrefab)) { return; } GameObject val = Object.Instantiate<GameObject>(itemPrefab, LootCratesPlugin._Root.transform, false); ((Object)val).name = "LootCrateCodeBreaker"; ItemDrop val2 = default(ItemDrop); if (val.TryGetComponent<ItemDrop>(ref val2)) { val2.m_itemData.m_shared.m_name = "$item_lootcrate_codebreaker"; val2.m_itemData.m_shared.m_description = "$item_lootcrate_codebreaker_desc"; val2.m_itemData.m_shared.m_questItem = false; if (!__instance.m_items.Contains(val)) { __instance.m_items.Add(val); } __instance.m_itemByHash[StringExtensionMethods.GetStableHashCode(((Object)val).name)] = val; RegisterToScene(val); } } private static List<Requirement> GetRequirements(ConfigEntry<string> config) { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Expected O, but got Unknown List<Requirement> list = new List<Requirement>(); string[] array = config.Value.Split(new char[1] { ',' }); ItemDrop resItem = default(ItemDrop); foreach (string text in array) { string[] array2 = text.Split(new char[1] { ':' }); if (array2.Length == 2) { GameObject prefab = ZNetScene.instance.GetPrefab(array2[0]); if (Object.op_Implicit((Object)(object)prefab) && prefab.TryGetComponent<ItemDrop>(ref resItem)) { list.Add(new Requirement { m_resItem = resItem, m_amount = ((!int.TryParse(array2[1], out var result)) ? 1 : result), m_extraAmountOnlyOneIngredient = 1, m_amountPerLevel = 1, m_recover = true }); } } } return list; } private static PieceCategory GetCategory(ConfigEntry<PieceCategory> config) { //IL_000c: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) return (PieceCategory)(Enum.IsDefined(typeof(PieceCategory), config.Value) ? ((int)config.Value) : 0); } private static void RegisterToScene(GameObject prefab) { if (!ZNetScene.instance.m_prefabs.Contains(prefab)) { ZNetScene.instance.m_prefabs.Add(prefab); } ZNetScene.instance.m_namedPrefabs[StringExtensionMethods.GetStableHashCode(((Object)prefab).name)] = prefab; } private static void RegisterToHammer(GameObject prefab) { GameObject prefab2 = ZNetScene.instance.GetPrefab("Hammer"); ItemDrop val = default(ItemDrop); if (Object.op_Implicit((Object)(object)prefab2) && prefab2.TryGetComponent<ItemDrop>(ref val) && !val.m_itemData.m_shared.m_buildPieces.m_pieces.Contains(prefab)) { val.m_itemData.m_shared.m_buildPieces.m_pieces.Add(prefab); } } static LootManager() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; m_filePath = configPath + directorySeparatorChar + "LootCrates.yml"; m_data = new FileData(); } } public static class TerminalCommands { [HarmonyPatch(typeof(Terminal), "Awake")] private static class RegisterLootCrateCommands { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEventFailable <>9__0_0; public static ConsoleOptionsFetcher <>9__0_1; internal object <Postfix>b__0_0(ConsoleEventArgs args) { if (args.Length < 2) { return false; } switch (args[1]) { case "help": ListCommandOptions(); break; case "reset": ClearCodes(); break; case "used": PrintUsedCodes(); break; } return true; } internal List<string> <Postfix>b__0_1() { return new List<string> { "help", "reset", "used" }; } } private static void Postfix() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown object obj = <>c.<>9__0_0; if (obj == null) { ConsoleEventFailable val = delegate(ConsoleEventArgs args) { if (args.Length < 2) { return false; } switch (args[1]) { case "help": ListCommandOptions(); break; case "reset": ClearCodes(); break; case "used": PrintUsedCodes(); break; } return true; }; <>c.<>9__0_0 = val; obj = (object)val; } object obj2 = <>c.<>9__0_1; if (obj2 == null) { ConsoleOptionsFetcher val2 = () => new List<string> { "help", "reset", "used" }; <>c.<>9__0_1 = val2; obj2 = (object)val2; } ConsoleCommand val3 = new ConsoleCommand("lootcrate", "Commands for LootCrate, use help to find commands", (ConsoleEventFailable)obj, false, false, false, false, false, (ConsoleOptionsFetcher)obj2, false, false, true); } } private static void ListCommandOptions() { foreach (string item in new List<string> { "reset - clears player data of all loot crate codes", "used - list used codes" }) { LootCratesPlugin.LootCratesLogger.LogInfo((object)item); } } public static void ClearCodes() { Player.m_localPlayer.m_customData[LootCrate.m_customDataKey] = ""; LootCratesPlugin.LootCratesLogger.LogInfo((object)"Cleared loot crate codes from player save"); } private static void PrintUsedCodes() { if (Player.m_localPlayer.m_customData.TryGetValue(LootCrate.m_customDataKey, out var value)) { if (!Utility.IsNullOrWhiteSpace(value)) { IDeserializer deserializer = new DeserializerBuilder().Build(); LootManager.PlayerCustomData playerCustomData = deserializer.Deserialize<LootManager.PlayerCustomData>(value); { foreach (string usedCode in playerCustomData.m_usedCodes) { LootCratesPlugin.LootCratesLogger.LogInfo((object)usedCode); } return; } } LootCratesPlugin.LootCratesLogger.LogInfo((object)"No codes found on player save"); } else { LootCratesPlugin.LootCratesLogger.LogInfo((object)"No codes found on player save"); } } } } namespace LootCrates.Behaviors { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(0)] public class LootCrate : MonoBehaviour, Hoverable, Interactable, TextReceiver { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] [HarmonyPatch(typeof(InventoryGui), "UpdateContainer")] private static class LootCrate_ContainerOverride { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] private static bool Prefix(InventoryGui __instance, Player player) { //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) if (!__instance.m_animator.GetBool(Visible)) { return false; } if (Object.op_Implicit((Object)(object)__instance.m_currentContainer)) { m_currentLootCrate = null; return true; } if ((Object)(object)m_currentLootCrate != (Object)null && m_currentLootCrate.IsOwner()) { m_currentLootCrate.SetInUse(inUse: true); ((Component)__instance.m_container).gameObject.SetActive(true); __instance.m_containerGrid.UpdateInventory(m_currentLootCrate.GetInventory(), (Player)null, __instance.m_dragItem); __instance.m_containerName.text = Localization.instance.Localize(m_currentLootCrate.GetInventory().GetName()); if (__instance.m_firstContainerUpdate) { __instance.m_containerGrid.ResetView(); __instance.m_firstContainerUpdate = false; __instance.m_containerHoldTime = 0f; __instance.m_containerHoldState = 0; } if (Vector3.Distance(((Component)m_currentLootCrate).transform.position, ((Component)player).transform.position) > __instance.m_autoCloseDistance) { CloseLootCrate(__instance); } if (ZInput.GetButton("Use") || ZInput.GetButton("JoyUse")) { __instance.m_containerHoldTime += Time.deltaTime; if (__instance.m_containerHoldTime > __instance.m_containerHoldPlaceStackDelay && __instance.m_containerHoldState == 0) { m_currentLootCrate.StackAll(); __instance.m_containerHoldState = 1; } else { if (__instance.m_containerHoldTime <= __instance.m_containerHoldPlaceStackDelay + __instance.m_containerHoldExitDelay || __instance.m_containerHoldState != 1) { return false; } __instance.Hide(); } } else { if (__instance.m_containerHoldState < 0) { return false; } __instance.m_containerHoldState = -1; } } else { ((Component)__instance.m_container).gameObject.SetActive(false); if (__instance.m_dragInventory == null || __instance.m_dragInventory == ((Humanoid)Player.m_localPlayer).GetInventory()) { return false; } __instance.SetupDragItem((ItemData)null, (Inventory)null, 1); } return false; } } [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] [HarmonyPatch(typeof(InventoryGui), "Hide")] private static class InventoryGUI_Hide_Patch { private static void Postfix() { HideLootCrate(); } } [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] [HarmonyPatch(typeof(InventoryGui), "IsContainerOpen")] private static class InventoryGUI_IsContainerOpen_Patch { private static void Postfix(ref bool __result) { if (IsLootCrateOpen()) { __result = true; } } } [HarmonyPatch(typeof(InventoryGui), "OnTakeAll")] [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(0)] private static class InventoryGUI_OnTakeAll_Patch { [<31d73ba5-17ac-416a-8de0-05113198bfbd>NullableContext(1)] private static void Postfix(InventoryGui __instance) { if (!((Object)(object)m_currentLootCrate == (Object)null)) { __instance.SetupDragItem((ItemData)null, (Inventory)null, 1); ((Humanoid)Player.m_localPlayer).GetInventory().MoveAll(m_currentLootCrate.GetInventory()); } } } [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(2)] private static LootCrate m_currentLootCrate; public static readonly string m_customDataKey = "LootCrateData"; private readonly int m_key = StringExtensionMethods.GetStableHashCode("lootCode"); public string m_name = "$piece_lootcrate"; [<e42e9aab-c10f-4d92-8699-eca8bdf50386>Nullable(2)] public Sprite m_bkg; public int m_width = 7; public int m_height = 4; public GameObject m_open = null; public GameObject m_closed = null; public EffectList m_openEffects = new EffectList(); public EffectList m_closedEffects = new EffectList(); public ZNetView m_nview = null; private Inventory m_inventory = null; public bool m_inUse; private static readonly int Visible = Animator.StringToHash("visible"); public void Awake() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown m_nview = ((Component)this).GetComponent<ZNetView>(); m_inventory = new Inventory(m_name, m_bkg, m_width, m_height); if (Object.op_Implicit((Object)(object)m_nview)) { m_nview.Register<long>("RPC_RequestOpen", (Action<long, long>)RPC_RequestOpen); m_nview.Register<bool>("RPC_OpenResponse", (Action<long, bool>)RPC_OpenResponse); m_nview.Register<long>("RPC_RequestStack", (Action<long, long>)RPC_RequestStack); m_nview.Register<bool>("RPC_StackResponse", (Action<long, bool>)RPC_StackResponse); m_nview.Register<long>("RPC_RequestTakeAll", (Action<long, long>)RPC_RequestTakeAll); m_nview.Register<bool>("RPC_TakeAllResponse", (Action<long, bool>)RPC_TakeAllResponse); m_nview.Register<string>("RPC_SetCode", (Action<long, string>)RPC_SetCode); } } public void AddItems() { if (Utility.IsNullOrWhiteSpace(GetText())) { return; } LootManager.CrateData crate = LootManager.GetCrate(GetText()); if (crate == null) { return; } m_inventory.RemoveAll(); ItemDrop val = default(ItemDrop); foreach (LootManager.LootData item in crate.Loot) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item.ItemName); if (Object.op_Implicit((Object)(object)itemPrefab) && itemPrefab.TryGetComponent<ItemDrop>(ref val)) { ItemData val2 = val.m_itemData.Clone(); val2.m_stack = item.Stack; val2.m_quality = item.Quality; val2.m_dropPrefab = itemPrefab; m_inventory.AddItem(val2); } } } public void RPC_RequestOpen(long uid, long playerID) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) if (IsInUse()) { m_nview.InvokeRPC(uid, "RPC_OpenResponse", new object[1] { false }); return; } if (!m_nview.IsOwner()) { m_nview.ClaimOwnership(); } ZDOMan.instance.ForceSendZDO(uid, m_nview.GetZDO().m_uid); m_nview.GetZDO().SetOwner(uid); m_nview.InvokeRPC(uid, "RPC_OpenResponse", new object[1] { true }); } public void RPC_OpenResponse(long uid, bool granted) { if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { if (granted) { Hud.HidePieceSelection(); InventoryGui.instance.m_animator.SetBool(Visible, true); InventoryGui.instance.SetActiveGroup(1, false); InventoryGui.instance.SetupCrafting(); m_currentLootCrate = this; } else { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_inuse", 0, (Sprite)null); } } } public void SaveCodeToPlayer() { ISerializer serializer = new SerializerBuilder().Build(); LootManager.PlayerCustomData codesFromPlayer = GetCodesFromPlayer(); if (!codesFromPlayer.m_usedCodes.Contains(GetText())) { codesFromPlayer.m_usedCodes.Add(GetText()); Player.m_localPlayer.m_customData[m_customDataKey] = serializer.Serialize(codesFromPlayer); } } public LootManager.PlayerCustomData GetCodesFromPlayer() { if (!Object.op_Implicit((Object)(object)Player.m_localPlayer)) { return new LootManager.PlayerCustomData(); } if (!Player.m_localPlayer.m_customData.TryGetValue(m_customDataKey, out var value)) { return new LootManager.PlayerCustomData(); } if (Utility.IsNullOrWhiteSpace(value)) { return new LootManager.PlayerCustomData(); } IDeserializer deserializer = new DeserializerBuilder().Build(); return deserializer.Deserialize<LootManager.PlayerCustomData>(value); } public void StackAll() { m_nview.InvokeRPC("RPC_RequestStack", new object[1] { Game.instance.GetPlayerProfile().GetPlayerID() }); } public void RPC_RequestStack(long uid, long playerID) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) if (IsOwner()) { if (IsInUse()) { m_nview.InvokeRPC(uid, "RPC_StackResponse", Array.Empty<object>()); return; } ZDOMan.instance.ForceSendZDO(uid, m_nview.GetZDO().m_uid); m_nview.GetZDO().SetOwner(uid); m_nview.InvokeRPC(uid, "RPC_StackResponse", new object[1] { true }); } } public void RPC_StackResponse(long uid, bool granted) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)Player.m_localPlayer)) { return; } if (granted) { if (m_inventory.StackAll(((Humanoid)Player.m_localPlayer).GetInventory(), true) > 0) { InventoryGui.instance.m_moveItemEffects.Create(((Component)this).transform.position, Quaternion.identity, (Transform)null, 1f, -1); } } else { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_inuse", 0, (Sprite)null); } } public void TakeAll(Humanoid character) { m_nview.InvokeRPC("RPC_RequestTakeAll", Array.Empty<object>()); } public void RPC_RequestTakeAll(long uid, long playerID) { if (IsOwner()) { m_nview.InvokeRPC(uid, "RPC_TakeAllResponse", new object[1] { !IsInUse() }); } } public void RPC_TakeAllResponse(long uid, bool granted) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { if (granted) { m_nview.ClaimOwnership(); ZDOMan.instance.ForceSendZDO(uid, m_nview.GetZDO().m_uid); ((Humanoid)Player.m_localPlayer).GetInventory().MoveAll(m_inventory); } else { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_inuse", 0, (Sprite)null); } } } public bool IsInUse() { return m_inUse; } public void SetInUse(bool inUse) { //IL_0076: 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_0049: 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) if (!IsOwner()) { m_nview.ClaimOwnership(); } if (m_inUse != inUse) { m_inUse = inUse; UpdateUseVisual(); if (inUse) { m_openEffects.Create(((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null, 1f, -1); } else { m_closedEffects.Create(((Component)this).transform.position, ((Component)this).transform.rotation, (Transform)null, 1f, -1); } } } public void UpdateUseVisual() { bool flag; if (m_nview.IsOwner()) { flag = m_inUse; m_nview.GetZDO().Set(ZDOVars.s_inUse, m_inUse ? 1 : 0, false); } else { flag = m_nview.GetZDO().GetInt(ZDOVars.s_inUse, 0) == 1; } if (Object.op_Implicit((Object)(object)m_open)) { m_open.SetActive(flag); } if (Object.op_Implicit((Object)(object)m_closed)) { m_closed.SetActive(!flag); } } public bool IsOwner() { return m_nview.IsOwner(); } public Inventory GetInventory() { return m_inventory; } public string GetHoverText() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(m_name + "\n"); stringBuilder.AppendFormat("[<color=yellow>{0}</color>] {1}\n", "$KEY_Use", "$piece_container_open"); stringBuilder.AppendFormat("[<color=yellow>{0}</color>] {1}", "L.Shift + $KEY_Use", "$piece_input_code"); return Localization.instance.Localize(stringBuilder.ToString()); } public string GetHoverName() { return m_name; } public bool Interact(Humanoid user, bool hold, bool alt) { if (hold) { return false; } if (alt) { TextInput.instance.RequestText((TextReceiver)(object)this, "$text_code", 40); return true; } if (!CheckCode() || IsInUse()) { ((Character)user).Message((MessageType)2, "$msg_cantopen", 0, (Sprite)null); return true; } AddItems(); SaveCodeToPlayer(); SetText(""); m_nview.InvokeRPC("RPC_RequestOpen", new object[1] { Game.instance.GetPlayerProfile().GetPlayerID() }); return true; } private bool CheckCode() { string text = GetText(); if (Utility.IsNullOrWhiteSpace(text)) { return false; } if (!CheckPlayerCodes(text)) { return false; } return LootManager.CodeExists(text); } public bool CheckPlayerCodes(string code) { if (LootCratesPlugin._checkPlayerCodes.Value == LootCratesPlugin.Toggle.Off) { return true; } if (!Player.m_localPlayer.m_customData.TryGetValue(m_customDataKey, out var value)) { return true; } if (Utility.IsNullOrWhiteSpace(value)) { return true; } IDeserializer deserializer = new DeserializerBuilder().Build(); LootManager.PlayerCustomData playerCustomData = deserializer.Deserialize<LootManager.PlayerCustomData>(value); return !playerCustomData.m_usedCodes.Contains(code); } public bool UseItem(Humanoid user, ItemData item) { return false; } public string GetText() { return m_nview.GetZDO().GetString(m_key, ""); } public void SetText(string text) { if (!CheckPlayerCodes(text)) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_codeused", 0, (Sprite)null); return; } m_nview.InvokeRPC("RPC_SetCode", new object[1] { text }); } public void RPC_SetCode(long sender, string value) { m_nview.GetZDO().Set(m_key, value); } public static bool IsLootCrateOpen() { return (Object)(object)m_currentLootCrate != (Object)null; } private static void CloseLootCrate(InventoryGui __instance) { if (__instance.m_dragInventory != null && __instance.m_dragInventory != ((Humanoid)Player.m_localPlayer).GetInventory()) { __instance.SetupDragItem((ItemData)null, (Inventory)null, 1); } HideLootCrate(); ((Component)__instance.m_splitPanel).gameObject.SetActive(false); __instance.m_firstContainerUpdate = true; ((Component)__instance.m_container).gameObject.SetActive(false); } private static void HideLootCrate() { if (!((Object)(object)m_currentLootCrate == (Object)null)) { m_currentLootCrate.SetInUse(inUse: false); m_currentLootCrate = null; } } } } namespace Microsoft.CodeAnalysis { [<d2a6910b-d303-4301-a421-0949245c6745>Embedded] [CompilerGenerated] internal sealed class <d2a6910b-d303-4301-a421-0949245c6745>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [<d2a6910b-d303-4301-a421-0949245c6745>Embedded] [CompilerGenerated] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class <b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [<d2a6910b-d303-4301-a421-0949245c6745>Embedded] [CompilerGenerated] internal sealed class <818c8758-3b28-4b50-b865-a5450963aeb0>NullableContextAttribute : Attribute { public readonly byte Flag; public <818c8758-3b28-4b50-b865-a5450963aeb0>NullableContextAttribute(byte P_0) { Flag = P_0; } } [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] [<d2a6910b-d303-4301-a421-0949245c6745>Embedded] [CompilerGenerated] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ServerSync { [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] [PublicAPI] internal abstract class OwnConfigEntryBase { [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] public object LocalBaseValue; public bool SynchronizedConfig = true; public abstract ConfigEntryBase BaseConfig { get; } } [PublicAPI] [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] internal class SyncedConfigEntry<[<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] T> : OwnConfigEntryBase { public readonly ConfigEntry<T> SourceConfig; public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig; public T Value { get { return SourceConfig.Value; } set { SourceConfig.Value = value; } } public SyncedConfigEntry(ConfigEntry<T> sourceConfig) { SourceConfig = sourceConfig; } public void AssignLocalValue(T value) { if (LocalBaseValue == null) { Value = value; } else { LocalBaseValue = value; } } } [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(2)] internal abstract class CustomSyncedValueBase { public object LocalBaseValue; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(1)] public readonly string Identifier; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(1)] public readonly Type Type; private object boxedValue; protected bool localIsOwner; public readonly int Priority; public object BoxedValue { get { return boxedValue; } set { boxedValue = value; this.ValueChanged?.Invoke(); } } public event Action ValueChanged; [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority) { Priority = priority; Identifier = identifier; Type = type; configSync.AddCustomValue(this); localIsOwner = configSync.IsSourceOfTruth; configSync.SourceOfTruthChanged += delegate(bool truth) { localIsOwner = truth; }; } } [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] [PublicAPI] internal sealed class CustomSyncedValue<[<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] T> : CustomSyncedValueBase { public T Value { get { return (T)base.BoxedValue; } set { base.BoxedValue = value; } } public CustomSyncedValue(ConfigSync configSync, string identifier, T value = default(T), int priority = 0) : base(configSync, identifier, typeof(T), priority) { Value = value; } public void AssignLocalValue(T value) { if (localIsOwner) { Value = value; } else { LocalBaseValue = value; } } } internal class ConfigurationManagerAttributes { [UsedImplicitly] public bool? ReadOnly = false; } [PublicAPI] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] internal class ConfigSync { [HarmonyPatch(typeof(ZRpc), "HandlePackage")] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] private static class SnatchCurrentlyHandlingRPC { [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] public static ZRpc currentRpc; [HarmonyPrefix] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] private static void Prefix(ZRpc __instance) { currentRpc = __instance; } } [HarmonyPatch(typeof(ZNet), "Awake")] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] internal static class RegisterRPCPatch { [HarmonyPostfix] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] private static void Postfix(ZNet __instance) { isServer = __instance.IsServer(); foreach (ConfigSync configSync2 in configSyncs) { ZRoutedRpc.instance.Register<ZPackage>(configSync2.Name + " ConfigSync", (Action<long, ZPackage>)configSync2.RPC_FromOtherClientConfigSync); if (isServer) { configSync2.InitialSyncDone = true; Debug.Log((object)("Registered '" + configSync2.Name + " ConfigSync' RPC - waiting for incoming connections")); } } if (isServer) { ((MonoBehaviour)__instance).StartCoroutine(WatchAdminListChanges()); } [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] static void SendAdmin(List<ZNetPeer> peers, bool isAdmin) { ZPackage package = ConfigsToPackage(null, null, new PackageEntry[1] { new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = isAdmin } }); ConfigSync configSync = configSyncs.First(); if (configSync != null) { ((MonoBehaviour)ZNet.instance).StartCoroutine(configSync.sendZPackage(peers, package)); } } [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] static IEnumerator WatchAdminListChanges() { MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); List<string> CurrentList = new List<string>(adminList.GetList()); while (true) { yield return (object)new WaitForSeconds(30f); if (!adminList.GetList().SequenceEqual(CurrentList)) { CurrentList = new List<string>(adminList.GetList()); List<ZNetPeer> adminPeer = ZNet.instance.GetPeers().Where(delegate(ZNetPeer p) { string hostName = p.m_rpc.GetSocket().GetHostName(); return ((object)listContainsId == null) ? adminList.Contains(hostName) : ((bool)listContainsId.Invoke(ZNet.instance, new object[2] { adminList, hostName })); }).ToList(); List<ZNetPeer> nonAdminPeer = ZNet.instance.GetPeers().Except(adminPeer).ToList(); SendAdmin(nonAdminPeer, isAdmin: false); SendAdmin(adminPeer, isAdmin: true); } } } } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] private static class RegisterClientRPCPatch { [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] [HarmonyPostfix] private static void Postfix(ZNet __instance, ZNetPeer peer) { if (__instance.IsServer()) { return; } foreach (ConfigSync configSync in configSyncs) { peer.m_rpc.Register<ZPackage>(configSync.Name + " ConfigSync", (Action<ZRpc, ZPackage>)configSync.RPC_FromServerConfigSync); } } } [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] private class ParsedConfigs { [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(new byte[] { 1, 1, 2 })] public readonly Dictionary<OwnConfigEntryBase, object> configValues = new Dictionary<OwnConfigEntryBase, object>(); [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(new byte[] { 1, 1, 2 })] public readonly Dictionary<CustomSyncedValueBase, object> customValues = new Dictionary<CustomSyncedValueBase, object>(); } [HarmonyPatch(typeof(ZNet), "Shutdown")] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] private class ResetConfigsOnShutdown { [HarmonyPostfix] private static void Postfix() { ProcessingServerUpdate = true; foreach (ConfigSync configSync in configSyncs) { configSync.resetConfigsFromServer(); configSync.IsSourceOfTruth = true; configSync.InitialSyncDone = false; } ProcessingServerUpdate = false; } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] private class SendConfigsAfterLogin { [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] private class BufferingSocket : ISocket { public volatile bool finished = false; public volatile int versionMatchQueued = -1; public readonly List<ZPackage> Package = new List<ZPackage>(); public readonly ISocket Original; public BufferingSocket(ISocket original) { Original = original; } public bool IsConnected() { return Original.IsConnected(); } public ZPackage Recv() { return Original.Recv(); } public int GetSendQueueSize() { return Original.GetSendQueueSize(); } public int GetCurrentSendRate() { return Original.GetCurrentSendRate(); } public bool IsHost() { return Original.IsHost(); } public void Dispose() { Original.Dispose(); } public bool GotNewData() { return Original.GotNewData(); } public void Close() { Original.Close(); } public string GetEndPointString() { return Original.GetEndPointString(); } public void GetAndResetStats(out int totalSent, out int totalRecv) { Original.GetAndResetStats(ref totalSent, ref totalRecv); } public void GetConnectionQuality(out float localQuality, out float remoteQuality, out int ping, out float outByteSec, out float inByteSec) { Original.GetConnectionQuality(ref localQuality, ref remoteQuality, ref ping, ref outByteSec, ref inByteSec); } public ISocket Accept() { return Original.Accept(); } public int GetHostPort() { return Original.GetHostPort(); } public bool Flush() { return Original.Flush(); } public string GetHostName() { return Original.GetHostName(); } public void VersionMatch() { if (finished) { Original.VersionMatch(); } else { versionMatchQueued = Package.Count; } } public void Send(ZPackage pkg) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown int pos = pkg.GetPos(); pkg.SetPos(0); int num = pkg.ReadInt(); if ((num == StringExtensionMethods.GetStableHashCode("PeerInfo") || num == StringExtensionMethods.GetStableHashCode("RoutedRPC") || num == StringExtensionMethods.GetStableHashCode("ZDOData")) && !finished) { ZPackage val = new ZPackage(pkg.GetArray()); val.SetPos(pos); Package.Add(val); } else { pkg.SetPos(pos); Original.Send(pkg); } } } [HarmonyPrefix] [HarmonyPriority(800)] private static void Prefix([<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(new byte[] { 2, 1, 1 })] ref Dictionary<Assembly, BufferingSocket> __state, ZNet __instance, ZRpc rpc) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Invalid comparison between Unknown and I4 if (__instance.IsServer()) { BufferingSocket value = new BufferingSocket(rpc.GetSocket()); AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, value); object? obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); ZNetPeer val = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (val != null && (int)ZNet.m_onlineBackend > 0) { AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val, value); } if (__state == null) { __state = new Dictionary<Assembly, BufferingSocket>(); } __state[Assembly.GetExecutingAssembly()] = value; } } [HarmonyPostfix] private static void Postfix(Dictionary<Assembly, BufferingSocket> __state, ZNet __instance, ZRpc rpc) { ZNetPeer peer; if (__instance.IsServer()) { object obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); peer = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (peer == null) { SendBufferedData(); } else { ((MonoBehaviour)__instance).StartCoroutine(sendAsync()); } } void SendBufferedData() { if (rpc.GetSocket() is BufferingSocket bufferingSocket) { AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, bufferingSocket.Original); object? obj2 = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); ZNetPeer val = (ZNetPeer)((obj2 is ZNetPeer) ? obj2 : null); if (val != null) { AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val, bufferingSocket.Original); } } BufferingSocket bufferingSocket2 = __state[Assembly.GetExecutingAssembly()]; bufferingSocket2.finished = true; for (int i = 0; i < bufferingSocket2.Package.Count; i++) { if (i == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } bufferingSocket2.Original.Send(bufferingSocket2.Package[i]); } if (bufferingSocket2.Package.Count == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } } IEnumerator sendAsync() { foreach (ConfigSync configSync in configSyncs) { List<PackageEntry> entries = new List<PackageEntry>(); if (configSync.CurrentVersion != null) { entries.Add(new PackageEntry { section = "Internal", key = "serverversion", type = typeof(string), value = configSync.CurrentVersion }); } MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); entries.Add(new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = (((object)listContainsId == null) ? ((object)adminList.Contains(rpc.GetSocket().GetHostName())) : listContainsId.Invoke(ZNet.instance, new object[2] { adminList, rpc.GetSocket().GetHostName() })) }); ZPackage package = ConfigsToPackage(configSync.allConfigs.Select([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (OwnConfigEntryBase c) => c.BaseConfig), configSync.allCustomValues, entries, partial: false); yield return ((MonoBehaviour)__instance).StartCoroutine(configSync.sendZPackage(new List<ZNetPeer> { peer }, package)); } SendBufferedData(); } } } [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] private class PackageEntry { public string section = null; public string key = null; public Type type = null; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] public object value; } [HarmonyPatch(typeof(ConfigEntryBase), "GetSerializedValue")] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] private static class PreventSavingServerInfo { [HarmonyPrefix] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] private static bool Prefix(ConfigEntryBase __instance, ref string __result) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || isWritableConfig(ownConfigEntryBase)) { return true; } __result = TomlTypeConverter.ConvertToString(ownConfigEntryBase.LocalBaseValue, __instance.SettingType); return false; } } [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] [HarmonyPatch(typeof(ConfigEntryBase), "SetSerializedValue")] private static class PreventConfigRereadChangingValues { [HarmonyPrefix] [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] private static bool Prefix(ConfigEntryBase __instance, string value) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || ownConfigEntryBase.LocalBaseValue == null) { return true; } try { ownConfigEntryBase.LocalBaseValue = TomlTypeConverter.ConvertToValue(value, __instance.SettingType); } catch (Exception ex) { Debug.LogWarning((object)$"Config value of setting \"{__instance.Definition}\" could not be parsed and will be ignored. Reason: {ex.Message}; Value: {value}"); } return false; } } [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] private class InvalidDeserializationTypeException : Exception { public string expected = null; public string received = null; public string field = ""; } public static bool ProcessingServerUpdate; public readonly string Name; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] public string DisplayName; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] public string CurrentVersion; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] public string MinimumRequiredVersion; public bool ModRequired = false; private bool? forceConfigLocking; private bool isSourceOfTruth = true; private static readonly HashSet<ConfigSync> configSyncs; private readonly HashSet<OwnConfigEntryBase> allConfigs = new HashSet<OwnConfigEntryBase>(); private HashSet<CustomSyncedValueBase> allCustomValues = new HashSet<CustomSyncedValueBase>(); private static bool isServer; private static bool lockExempt; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] private OwnConfigEntryBase lockedConfig = null; private const byte PARTIAL_CONFIGS = 1; private const byte FRAGMENTED_CONFIG = 2; private const byte COMPRESSED_CONFIG = 4; private readonly Dictionary<string, SortedDictionary<int, byte[]>> configValueCache = new Dictionary<string, SortedDictionary<int, byte[]>>(); [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(new byte[] { 1, 0, 1 })] private readonly List<KeyValuePair<long, string>> cacheExpirations = new List<KeyValuePair<long, string>>(); private static long packageCounter; public bool IsLocked { get { bool? flag = forceConfigLocking; bool num; if (!flag.HasValue) { if (lockedConfig == null) { goto IL_0052; } num = ((IConvertible)lockedConfig.BaseConfig.BoxedValue).ToInt32(CultureInfo.InvariantCulture) != 0; } else { num = flag.GetValueOrDefault(); } if (!num) { goto IL_0052; } int result = ((!lockExempt) ? 1 : 0); goto IL_0053; IL_0053: return (byte)result != 0; IL_0052: result = 0; goto IL_0053; } set { forceConfigLocking = value; } } public bool IsAdmin => lockExempt || isSourceOfTruth; public bool IsSourceOfTruth { get { return isSourceOfTruth; } private set { if (value != isSourceOfTruth) { isSourceOfTruth = value; this.SourceOfTruthChanged?.Invoke(value); } } } public bool InitialSyncDone { get; private set; } = false; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] [method: <818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(2)] [field: <b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] public event Action<bool> SourceOfTruthChanged; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] [method: <818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(2)] [field: <b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] private event Action lockedConfigChanged; static ConfigSync() { ProcessingServerUpdate = false; configSyncs = new HashSet<ConfigSync>(); lockExempt = false; packageCounter = 0L; RuntimeHelpers.RunClassConstructor(typeof(VersionCheck).TypeHandle); } public ConfigSync(string name) { Name = name; configSyncs.Add(this); new VersionCheck(this); } public SyncedConfigEntry<T> AddConfigEntry<[<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] T>(ConfigEntry<T> configEntry) { OwnConfigEntryBase ownConfigEntryBase = configData((ConfigEntryBase)(object)configEntry); SyncedConfigEntry<T> syncedEntry = ownConfigEntryBase as SyncedConfigEntry<T>; if (syncedEntry == null) { syncedEntry = new SyncedConfigEntry<T>(configEntry); AccessTools.DeclaredField(typeof(ConfigDescription), "<Tags>k__BackingField").SetValue(((ConfigEntryBase)configEntry).Description, new object[1] { new ConfigurationManagerAttributes() }.Concat(((ConfigEntryBase)configEntry).Description.Tags ?? Array.Empty<object>()).Concat(new SyncedConfigEntry<T>[1] { syncedEntry }).ToArray()); configEntry.SettingChanged += [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (object _, EventArgs _) => { if (!ProcessingServerUpdate && syncedEntry.SynchronizedConfig) { Broadcast(ZRoutedRpc.Everybody, (ConfigEntryBase)configEntry); } }; allConfigs.Add(syncedEntry); } return syncedEntry; } public SyncedConfigEntry<T> AddLockingConfigEntry<[<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] T>(ConfigEntry<T> lockingConfig) where T : IConvertible { if (lockedConfig != null) { throw new Exception("Cannot initialize locking ConfigEntry twice"); } lockedConfig = AddConfigEntry<T>(lockingConfig); lockingConfig.SettingChanged += [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (object _, EventArgs _) => { this.lockedConfigChanged?.Invoke(); }; return (SyncedConfigEntry<T>)lockedConfig; } internal void AddCustomValue(CustomSyncedValueBase customValue) { if (allCustomValues.Select([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (CustomSyncedValueBase v) => v.Identifier).Concat(new string[1] { "serverversion" }).Contains(customValue.Identifier)) { throw new Exception("Cannot have multiple settings with the same name or with a reserved name (serverversion)"); } allCustomValues.Add(customValue); allCustomValues = new HashSet<CustomSyncedValueBase>(allCustomValues.OrderByDescending([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (CustomSyncedValueBase v) => v.Priority)); customValue.ValueChanged += delegate { if (!ProcessingServerUpdate) { Broadcast(ZRoutedRpc.Everybody, customValue); } }; } private void RPC_FromServerConfigSync(ZRpc rpc, ZPackage package) { lockedConfigChanged += serverLockedSettingChanged; IsSourceOfTruth = false; if (HandleConfigSyncRPC(0L, package, clientUpdate: false)) { InitialSyncDone = true; } } private void RPC_FromOtherClientConfigSync(long sender, ZPackage package) { HandleConfigSyncRPC(sender, package, clientUpdate: true); } private bool HandleConfigSyncRPC(long sender, ZPackage package, bool clientUpdate) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Expected O, but got Unknown //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Expected O, but got Unknown try { if (isServer && IsLocked) { ZRpc currentRpc = SnatchCurrentlyHandlingRPC.currentRpc; object obj; if (currentRpc == null) { obj = null; } else { ISocket socket = currentRpc.GetSocket(); obj = ((socket != null) ? socket.GetHostName() : null); } string text = (string)obj; if (text != null) { MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList val = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); if (!(((object)methodInfo == null) ? val.Contains(text) : ((bool)methodInfo.Invoke(ZNet.instance, new object[2] { val, text })))) { return false; } } } cacheExpirations.RemoveAll(([<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(new byte[] { 0, 1 })] KeyValuePair<long, string> kv) => { if (kv.Key < DateTimeOffset.Now.Ticks) { configValueCache.Remove(kv.Value); return true; } return false; }); byte b = package.ReadByte(); if ((b & 2u) != 0) { long num = package.ReadLong(); string text2 = sender.ToString() + num; if (!configValueCache.TryGetValue(text2, out var value)) { value = new SortedDictionary<int, byte[]>(); configValueCache[text2] = value; cacheExpirations.Add(new KeyValuePair<long, string>(DateTimeOffset.Now.AddSeconds(60.0).Ticks, text2)); } int key = package.ReadInt(); int num2 = package.ReadInt(); value.Add(key, package.ReadByteArray()); if (value.Count < num2) { return false; } configValueCache.Remove(text2); package = new ZPackage(value.Values.SelectMany([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (byte[] a) => a).ToArray()); b = package.ReadByte(); } ProcessingServerUpdate = true; if ((b & 4u) != 0) { byte[] buffer = package.ReadByteArray(); MemoryStream stream = new MemoryStream(buffer); MemoryStream memoryStream = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress)) { deflateStream.CopyTo(memoryStream); } package = new ZPackage(memoryStream.ToArray()); b = package.ReadByte(); } if ((b & 1) == 0) { resetConfigsFromServer(); } ParsedConfigs parsedConfigs = ReadConfigsFromPackage(package); ConfigFile val2 = null; bool saveOnConfigSet = false; foreach (KeyValuePair<OwnConfigEntryBase, object> configValue in parsedConfigs.configValues) { if (!isServer && configValue.Key.LocalBaseValue == null) { configValue.Key.LocalBaseValue = configValue.Key.BaseConfig.BoxedValue; } if (val2 == null) { val2 = configValue.Key.BaseConfig.ConfigFile; saveOnConfigSet = val2.SaveOnConfigSet; val2.SaveOnConfigSet = false; } configValue.Key.BaseConfig.BoxedValue = configValue.Value; } if (val2 != null) { val2.SaveOnConfigSet = saveOnConfigSet; } foreach (KeyValuePair<CustomSyncedValueBase, object> customValue in parsedConfigs.customValues) { if (!isServer) { CustomSyncedValueBase key2 = customValue.Key; if (key2.LocalBaseValue == null) { key2.LocalBaseValue = customValue.Key.BoxedValue; } } customValue.Key.BoxedValue = customValue.Value; } Debug.Log((object)string.Format("Received {0} configs and {1} custom values from {2} for mod {3}", parsedConfigs.configValues.Count, parsedConfigs.customValues.Count, (isServer || clientUpdate) ? $"client {sender}" : "the server", DisplayName ?? Name)); if (!isServer) { serverLockedSettingChanged(); } return true; } finally { ProcessingServerUpdate = false; } } private ParsedConfigs ReadConfigsFromPackage(ZPackage package) { ParsedConfigs parsedConfigs = new ParsedConfigs(); Dictionary<string, OwnConfigEntryBase> dictionary = allConfigs.Where([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (OwnConfigEntryBase c) => c.SynchronizedConfig).ToDictionary([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (OwnConfigEntryBase c) => c.BaseConfig.Definition.Section + "_" + c.BaseConfig.Definition.Key, [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (OwnConfigEntryBase c) => c); Dictionary<string, CustomSyncedValueBase> dictionary2 = allCustomValues.ToDictionary([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (CustomSyncedValueBase c) => c.Identifier, [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (CustomSyncedValueBase c) => c); int num = package.ReadInt(); for (int i = 0; i < num; i++) { string text = package.ReadString(); string text2 = package.ReadString(); string text3 = package.ReadString(); Type type = Type.GetType(text3); if (text3 == "" || type != null) { object obj; try { obj = ((text3 == "") ? null : ReadValueWithTypeFromZPackage(package, type)); } catch (InvalidDeserializationTypeException ex) { Debug.LogWarning((object)("Got unexpected struct internal type " + ex.received + " for field " + ex.field + " struct " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + ex.expected)); continue; } OwnConfigEntryBase value2; if (text == "Internal") { CustomSyncedValueBase value; if (text2 == "serverversion") { if (obj?.ToString() != CurrentVersion) { Debug.LogWarning((object)("Received server version is not equal: server version = " + (obj?.ToString() ?? "null") + "; local version = " + (CurrentVersion ?? "unknown"))); } } else if (text2 == "lockexempt") { if (obj is bool flag) { lockExempt = flag; } } else if (dictionary2.TryGetValue(text2, out value)) { if ((text3 == "" && (!value.Type.IsValueType || Nullable.GetUnderlyingType(value.Type) != null)) || GetZPackageTypeString(value.Type) == text3) { parsedConfigs.customValues[value] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for internal value " + text2 + " for mod " + (DisplayName ?? Name) + ", expecting " + value.Type.AssemblyQualifiedName)); } } else if (dictionary.TryGetValue(text + "_" + text2, out value2)) { Type type2 = configType(value2.BaseConfig); if ((text3 == "" && (!type2.IsValueType || Nullable.GetUnderlyingType(type2) != null)) || GetZPackageTypeString(type2) == text3) { parsedConfigs.configValues[value2] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + type2.AssemblyQualifiedName)); } else { Debug.LogWarning((object)("Received unknown config entry " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ". This may happen if client and server versions of the mod do not match.")); } continue; } Debug.LogWarning((object)("Got invalid type " + text3 + ", abort reading of received configs")); return new ParsedConfigs(); } return parsedConfigs; } private static bool isWritableConfig(OwnConfigEntryBase config) { ConfigSync configSync = configSyncs.FirstOrDefault([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (ConfigSync cs) => cs.allConfigs.Contains(config)); if (configSync == null) { return true; } return configSync.IsSourceOfTruth || !config.SynchronizedConfig || config.LocalBaseValue == null || (!configSync.IsLocked && (config != configSync.lockedConfig || lockExempt)); } private void serverLockedSettingChanged() { foreach (OwnConfigEntryBase allConfig in allConfigs) { configAttribute<ConfigurationManagerAttributes>(allConfig.BaseConfig).ReadOnly = !isWritableConfig(allConfig); } } private void resetConfigsFromServer() { ConfigFile val = null; bool saveOnConfigSet = false; foreach (OwnConfigEntryBase item in allConfigs.Where([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (OwnConfigEntryBase config) => config.LocalBaseValue != null)) { if (val == null) { val = item.BaseConfig.ConfigFile; saveOnConfigSet = val.SaveOnConfigSet; val.SaveOnConfigSet = false; } item.BaseConfig.BoxedValue = item.LocalBaseValue; item.LocalBaseValue = null; } if (val != null) { val.SaveOnConfigSet = saveOnConfigSet; } foreach (CustomSyncedValueBase item2 in allCustomValues.Where([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (CustomSyncedValueBase config) => config.LocalBaseValue != null)) { item2.BoxedValue = item2.LocalBaseValue; item2.LocalBaseValue = null; } lockedConfigChanged -= serverLockedSettingChanged; serverLockedSettingChanged(); } private IEnumerator<bool> distributeConfigToPeers(ZNetPeer peer, ZPackage package) { ZRoutedRpc rpc = ZRoutedRpc.instance; if (rpc == null) { yield break; } byte[] data = package.GetArray(); if (data != null && data.LongLength > 250000) { int fragments = (int)(1 + (data.LongLength - 1) / 250000); long packageIdentifier = ++packageCounter; int fragment = 0; while (fragment < fragments) { foreach (bool item in waitForQueue()) { yield return item; } if (peer.m_socket.IsConnected()) { ZPackage fragmentedPackage = new ZPackage(); fragmentedPackage.Write((byte)2); fragmentedPackage.Write(packageIdentifier); fragmentedPackage.Write(fragment); fragmentedPackage.Write(fragments); fragmentedPackage.Write(data.Skip(250000 * fragment).Take(250000).ToArray()); SendPackage(fragmentedPackage); if (fragment != fragments - 1) { yield return true; } int num = fragment + 1; fragment = num; continue; } break; } yield break; } foreach (bool item2 in waitForQueue()) { yield return item2; } SendPackage(package); void SendPackage(ZPackage pkg) { string text = Name + " ConfigSync"; if (isServer) { peer.m_rpc.Invoke(text, new object[1] { pkg }); } else { rpc.InvokeRoutedRPC(peer.m_server ? 0 : peer.m_uid, text, new object[1] { pkg }); } } IEnumerable<bool> waitForQueue() { float timeout = Time.time + 30f; while (peer.m_socket.GetSendQueueSize() > 20000) { if (Time.time > timeout) { Debug.Log((object)$"Disconnecting {peer.m_uid} after 30 seconds config sending timeout"); peer.m_rpc.Invoke("Error", new object[1] { (object)(ConnectionStatus)5 }); ZNet.instance.Disconnect(peer); break; } yield return false; } } } private IEnumerator sendZPackage(long target, ZPackage package) { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { return Enumerable.Empty<object>().GetEnumerator(); } List<ZNetPeer> list = (List<ZNetPeer>)AccessTools.DeclaredField(typeof(ZRoutedRpc), "m_peers").GetValue(ZRoutedRpc.instance); if (target != ZRoutedRpc.Everybody) { list = list.Where([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (ZNetPeer p) => p.m_uid == target).ToList(); } return sendZPackage(list, package); } private IEnumerator sendZPackage(List<ZNetPeer> peers, ZPackage package) { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { yield break; } byte[] rawData = package.GetArray(); if (rawData != null && rawData.LongLength > 10000) { ZPackage compressedPackage = new ZPackage(); compressedPackage.Write((byte)4); MemoryStream output = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(output, CompressionLevel.Optimal)) { deflateStream.Write(rawData, 0, rawData.Length); } compressedPackage.Write(output.ToArray()); package = compressedPackage; } List<IEnumerator<bool>> writers = (from peer in peers where peer.IsReady() select peer into p select distributeConfigToPeers(p, package)).ToList(); writers.RemoveAll((IEnumerator<bool> writer) => !writer.MoveNext()); while (writers.Count > 0) { yield return null; writers.RemoveAll((IEnumerator<bool> writer) => !writer.MoveNext()); } } private void Broadcast(long target, params ConfigEntryBase[] configs) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(configs); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } private void Broadcast(long target, params CustomSyncedValueBase[] customValues) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(null, customValues); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } [return: <b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] private static OwnConfigEntryBase configData(ConfigEntryBase config) { return config.Description.Tags?.OfType<OwnConfigEntryBase>().SingleOrDefault(); } [return: <b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(new byte[] { 2, 1 })] public static SyncedConfigEntry<T> ConfigData<[<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] T>(ConfigEntry<T> config) { return ((ConfigEntryBase)config).Description.Tags?.OfType<SyncedConfigEntry<T>>().SingleOrDefault(); } private static T configAttribute<[<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] T>(ConfigEntryBase config) { return config.Description.Tags.OfType<T>().First(); } private static Type configType(ConfigEntryBase config) { return configType(config.SettingType); } private static Type configType(Type type) { return type.IsEnum ? Enum.GetUnderlyingType(type) : type; } private static ZPackage ConfigsToPackage([<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(new byte[] { 2, 1 })] IEnumerable<ConfigEntryBase> configs = null, [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(new byte[] { 2, 1 })] IEnumerable<CustomSyncedValueBase> customValues = null, [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(new byte[] { 2, 1 })] IEnumerable<PackageEntry> packageEntries = null, bool partial = true) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown List<ConfigEntryBase> list = configs?.Where([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (ConfigEntryBase config) => configData(config).SynchronizedConfig).ToList() ?? new List<ConfigEntryBase>(); List<CustomSyncedValueBase> list2 = customValues?.ToList() ?? new List<CustomSyncedValueBase>(); ZPackage val = new ZPackage(); val.Write((byte)(partial ? 1 : 0)); val.Write(list.Count + list2.Count + (packageEntries?.Count() ?? 0)); foreach (PackageEntry item in packageEntries ?? Array.Empty<PackageEntry>()) { AddEntryToPackage(val, item); } foreach (CustomSyncedValueBase item2 in list2) { AddEntryToPackage(val, new PackageEntry { section = "Internal", key = item2.Identifier, type = item2.Type, value = item2.BoxedValue }); } foreach (ConfigEntryBase item3 in list) { AddEntryToPackage(val, new PackageEntry { section = item3.Definition.Section, key = item3.Definition.Key, type = configType(item3), value = item3.BoxedValue }); } return val; } private static void AddEntryToPackage(ZPackage package, PackageEntry entry) { package.Write(entry.section); package.Write(entry.key); package.Write((entry.value == null) ? "" : GetZPackageTypeString(entry.type)); AddValueToZPackage(package, entry.value); } private static string GetZPackageTypeString(Type type) { return type.AssemblyQualifiedName; } private static void AddValueToZPackage(ZPackage package, [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] object value) { Type type = value?.GetType(); if (value is Enum) { value = ((IConvertible)value).ToType(Enum.GetUnderlyingType(value.GetType()), CultureInfo.InvariantCulture); } else { if (value is ICollection collection) { package.Write(collection.Count); { foreach (object item in collection) { AddValueToZPackage(package, item); } return; } } if ((object)type != null && type.IsValueType && !type.IsPrimitive) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); package.Write(fields.Length); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { package.Write(GetZPackageTypeString(fieldInfo.FieldType)); AddValueToZPackage(package, fieldInfo.GetValue(value)); } return; } } ZRpc.Serialize(new object[1] { value }, ref package); } private static object ReadValueWithTypeFromZPackage(ZPackage package, Type type) { if ((object)type != null && type.IsValueType && !type.IsPrimitive && !type.IsEnum) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); int num = package.ReadInt(); if (num != fields.Length) { throw new InvalidDeserializationTypeException { received = $"(field count: {num})", expected = $"(field count: {fields.Length})" }; } object uninitializedObject = FormatterServices.GetUninitializedObject(type); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { string text = package.ReadString(); if (text != GetZPackageTypeString(fieldInfo.FieldType)) { throw new InvalidDeserializationTypeException { received = text, expected = GetZPackageTypeString(fieldInfo.FieldType), field = fieldInfo.Name }; } fieldInfo.SetValue(uninitializedObject, ReadValueWithTypeFromZPackage(package, fieldInfo.FieldType)); } return uninitializedObject; } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<, >)) { int num2 = package.ReadInt(); IDictionary dictionary = (IDictionary)Activator.CreateInstance(type); Type type2 = typeof(KeyValuePair<, >).MakeGenericType(type.GenericTypeArguments); FieldInfo field = type2.GetField("key", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = type2.GetField("value", BindingFlags.Instance | BindingFlags.NonPublic); for (int j = 0; j < num2; j++) { object obj = ReadValueWithTypeFromZPackage(package, type2); dictionary.Add(field.GetValue(obj), field2.GetValue(obj)); } return dictionary; } if (type != typeof(List<string>) && type.IsGenericType) { Type type3 = typeof(ICollection<>).MakeGenericType(type.GenericTypeArguments[0]); if ((object)type3 != null && type3.IsAssignableFrom(type)) { int num3 = package.ReadInt(); object obj2 = Activator.CreateInstance(type); MethodInfo method = type3.GetMethod("Add"); for (int k = 0; k < num3; k++) { method.Invoke(obj2, new object[1] { ReadValueWithTypeFromZPackage(package, type.GenericTypeArguments[0]) }); } return obj2; } } ParameterInfo parameterInfo = (ParameterInfo)FormatterServices.GetUninitializedObject(typeof(ParameterInfo)); AccessTools.DeclaredField(typeof(ParameterInfo), "ClassImpl").SetValue(parameterInfo, type); List<object> source = new List<object>(); ZRpc.Deserialize(new ParameterInfo[2] { null, parameterInfo }, package, ref source); return source.First(); } } [<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(1)] [HarmonyPatch] [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(0)] [PublicAPI] internal class VersionCheck { private static readonly HashSet<VersionCheck> versionChecks; private static readonly Dictionary<string, string> notProcessedNames; public string Name; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] private string displayName; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] private string currentVersion; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] private string minimumRequiredVersion; public bool ModRequired = true; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] private string ReceivedCurrentVersion; [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] private string ReceivedMinimumRequiredVersion; private readonly List<ZRpc> ValidatedClients = new List<ZRpc>(); [<b87fc8a6-92f5-4344-8bd8-3b0ab478d84d>Nullable(2)] private ConfigSync ConfigSync; public string DisplayName { get { return displayName ?? Name; } set { displayName = value; } } public string CurrentVersion { get { return currentVersion ?? "0.0.0"; } set { currentVersion = value; } } public string MinimumRequiredVersion { get { return minimumRequiredVersion ?? (ModRequired ? CurrentVersion : "0.0.0"); } set { minimumRequiredVersion = value; } } private static void PatchServerSync() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown Patches patchInfo = PatchProcessor.GetPatchInfo((MethodBase)AccessTools.DeclaredMethod(typeof(ZNet), "Awake", (Type[])null, (Type[])null)); if (patchInfo != null && patchInfo.Postfixes.Count([<818c8758-3b28-4b50-b865-a5450963aeb0>NullableContext(0)] (Patch p) => p.PatchMethod.DeclaringType == typeof(ConfigSync.RegisterRPCPatch)) > 0) { return; } Harmony val = new Harmony("org.bepinex.helpers.ServerSync"); foreach (Type item in from t in typeof(ConfigSync).GetNestedTypes(BindingFlags.NonPublic).Concat(new Type[1] { typeof(VersionCheck) }) where t.IsClass select t) { val.PatchAll(item); } } static VersionCheck() { versionChecks = new HashSet<VersionCheck>(); notProcessedNames = new Dictionary<string, string>(); typeof(ThreadingHelper).GetMethod("StartSyncInvoke").Invoke(ThreadingHelper.Instance, new object[1] { new Action(PatchServerSync) }); } public VersionCheck(string name) { Name = name
MonsterDB.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.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.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using Microsoft.CodeAnalysis; using MonsterDB.Behaviors; using MonsterDB.DataBase; using MonsterDB.FileWatcher; using ServerSync; using TMPro; using UnityEngine; 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("MonsterDB")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyProduct("MonsterDB")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")] [assembly: AssemblyFileVersion("1.0.0")] [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.0.0")] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<0ac34884-3b8f-45c1-b6d0-0d7737a7b275>Embedded] internal sealed class <0ac34884-3b8f-45c1-b6d0-0d7737a7b275>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [<0ac34884-3b8f-45c1-b6d0-0d7737a7b275>Embedded] [CompilerGenerated] internal sealed class <d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [<0ac34884-3b8f-45c1-b6d0-0d7737a7b275>Embedded] [CompilerGenerated] internal sealed class <00b16343-624e-4b9f-8261-3195a71905e6>NullableContextAttribute : Attribute { public readonly byte Flag; public <00b16343-624e-4b9f-8261-3195a71905e6>NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace MonsterDB { [BepInPlugin("RustyMods.MonsterDB", "MonsterDB", "1.0.0")] [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] public class MonsterDBPlugin : BaseUnityPlugin { [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(0)] public enum Toggle { On = 1, Off = 0 } [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(0)] private class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order; [UsedImplicitly] public bool? Browsable; [UsedImplicitly] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(2)] public string Category; [UsedImplicitly] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(new byte[] { 2, 1 })] public Action<ConfigEntryBase> CustomDrawer; } internal const string ModName = "MonsterDB"; internal const string ModVersion = "1.0.0"; internal const string Author = "RustyMods"; private const string ModGUID = "RustyMods.MonsterDB"; private static string ConfigFileName = "RustyMods.MonsterDB.cfg"; private static string ConfigFileFullPath; internal static string ConnectionError; private readonly Harmony _harmony = new Harmony("RustyMods.MonsterDB"); public static readonly ManualLogSource MonsterDBLogger; public static readonly ConfigSync ConfigSync; public static GameObject _Root; private static ConfigEntry<Toggle> _serverConfigLocked; public void Awake() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown Paths.CreateDirectories(); TextureManager.ReadLocalTextures(); _Root = new GameObject("root"); Object.DontDestroyOnLoad((Object)(object)_Root); _Root.SetActive(false); Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony.PatchAll(executingAssembly); SetupWatcher(); FileWatch.InitFileWatch(); SpawnData.InitSpawnSystem(); } private void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } 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 { MonsterDBLogger.LogDebug((object)"ReadConfigValues called"); ((BaseUnityPlugin)this).Config.Reload(); } catch { MonsterDBLogger.LogError((object)("There was an issue loading your " + ConfigFileName)); MonsterDBLogger.LogError((object)"Please check your config entries for spelling and format!"); } } private void InitConfigs() { _serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only."); ConfigSync.AddLockingConfigEntry<Toggle>(_serverConfigLocked); } private ConfigEntry<T> config<[<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>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<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val); SyncedConfigEntry<T> syncedConfigEntry = ConfigSync.AddConfigEntry<T>(val2); syncedConfigEntry.SynchronizedConfig = synchronizedSetting; return val2; } private ConfigEntry<T> config<[<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>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<object>()), synchronizedSetting); } static MonsterDBPlugin() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; ConnectionError = ""; MonsterDBLogger = Logger.CreateLogSource("MonsterDB"); ConfigSync = new ConfigSync("RustyMods.MonsterDB") { DisplayName = "MonsterDB", CurrentVersion = "1.0.0", MinimumRequiredVersion = "1.0.0" }; _Root = null; _serverConfigLocked = 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<KeyCode, bool>)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<KeyCode, bool>)Input.GetKey); } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] public static class RegisterAndCheckVersion { [<00b16343-624e-4b9f-8261-3195a71905e6>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 MonsterDBPlugin.MonsterDBLogger.LogDebug((object)"Registering version RPC handler"); peer.m_rpc.Register<ZPackage>("MonsterDB_VersionCheck", (Action<ZRpc, ZPackage>)RpcHandlers.RPC_MonsterDB_Version); MonsterDBPlugin.MonsterDBLogger.LogInfo((object)"Invoking version check"); ZPackage val = new ZPackage(); val.Write("1.0.0"); peer.m_rpc.Invoke("MonsterDB_VersionCheck", new object[1] { val }); } } [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] public static class VerifyClient { private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance) { if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc)) { return true; } MonsterDBPlugin.MonsterDBLogger.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(), "MonsterDBRequestAdminSync", new object[1] { (object)new ZPackage() }); } } [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] public class ShowConnectionError { [<00b16343-624e-4b9f-8261-3195a71905e6>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" + MonsterDBPlugin.ConnectionError; } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] public static class RemoveDisconnectedPeerFromVerified { [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] private static void Prefix(ZNetPeer peer, ref ZNet __instance) { if (__instance.IsServer()) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list")); RpcHandlers.ValidatedPeers.Remove(peer.m_rpc); } } } [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] public static class RpcHandlers { public static readonly List<ZRpc> ValidatedPeers = new List<ZRpc>(); public static void RPC_MonsterDB_Version(ZRpc rpc, ZPackage pkg) { string text = pkg.ReadString(); MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Version check, local: 1.0.0, remote: " + text)); if (text != "1.0.0") { MonsterDBPlugin.ConnectionError = "MonsterDB Installed: 1.0.0\n Needed: " + text; if (ZNet.instance.IsServer()) { MonsterDBPlugin.MonsterDBLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting...")); rpc.Invoke("Error", new object[1] { 3 }); } } else if (!ZNet.instance.IsServer()) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)"Received same version from server!"); } else { MonsterDBPlugin.MonsterDBLogger.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 MonsterDB.FileWatcher { [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] public static class FileWatch { public static void InitFileWatch() { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.MonsterPath, "*.yml") { Filter = "*.yml", EnableRaisingEvents = true, IncludeSubdirectories = true, SynchronizingObject = ThreadingHelper.SynchronizingObject, NotifyFilter = NotifyFilters.LastWrite }; fileSystemWatcher.Changed += OnCreatureChange; fileSystemWatcher.Deleted += OnCreatureDelete; FileSystemWatcher fileSystemWatcher2 = new FileSystemWatcher(Paths.SpawnPath, "*.yml") { Filter = "*.yml", EnableRaisingEvents = true, IncludeSubdirectories = true, SynchronizingObject = ThreadingHelper.SynchronizingObject, NotifyFilter = NotifyFilters.LastWrite }; fileSystemWatcher2.Changed += OnSpawnChange; fileSystemWatcher2.Created += OnSpawnChange; fileSystemWatcher2.Deleted += OnSpawnChange; } private static void OnSpawnChange(object sender, FileSystemEventArgs e) { if (!ZNet.instance.IsServer()) { return; } string fileName = Path.GetFileName(e.Name); if (!(fileName == "Example.yml")) { switch (e.ChangeType) { case WatcherChangeTypes.Changed: MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("File changed: " + fileName)); SpawnData.ReadFile(e.FullPath); break; case WatcherChangeTypes.Created: MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("File created: " + fileName)); SpawnData.ReadFile(e.FullPath); break; case WatcherChangeTypes.Deleted: MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("File deleted: " + fileName)); SpawnData.ClearSpawnData(); SpawnData.ReadSpawnFiles(); break; case WatcherChangeTypes.Created | WatcherChangeTypes.Deleted: break; } } } private static void OnCreatureDelete(object sender, FileSystemEventArgs e) { if (ZNet.instance.IsServer()) { string fileName = Path.GetFileName(e.Name); MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("File deleted: " + fileName)); if (MonsterManager.ResetMonster(fileName.Replace(".yml", string.Empty))) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)"Server: Successfully reset creature after deleting file"); MonsterDB.DataBase.ServerSync.UpdateServerMonsterDB(); } else { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)"Server: Failed to reset creature after deleting file"); } } } private static void OnCreatureChange(object sender, FileSystemEventArgs e) { if (ZNet.instance.IsServer()) { string fileName = Path.GetFileName(e.Name); MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("File changed: " + fileName)); if (MonsterManager.FileWatch_UpdateMonster(e.FullPath, fileName)) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Server: Successfully updated " + fileName)); MonsterDB.DataBase.ServerSync.UpdateServerMonsterDB(); } else { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Server: Failed to update " + fileName)); } } } } } namespace MonsterDB.DataBase { [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] public static class MonsterDB { [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(0)] [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class CacheResources_Patch { private static void Postfix() { CacheResources(); } } private static readonly Dictionary<string, GameObject> m_items = new Dictionary<string, GameObject>(); public static readonly Dictionary<string, Texture2D> m_textures = new Dictionary<string, Texture2D>(); public static List<GameObject> GetCachedItems() { return m_items.Values.Where([<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(0)] (GameObject x) => (Object)(object)x != (Object)null && Object.op_Implicit((Object)(object)x.GetComponent<ItemDrop>())).ToList(); } [return: <d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(2)] private static CreatureItem GetCreatureItem(string prefabName) { GameObject val = TryGetGameObject(prefabName); if ((Object)(object)val == (Object)null) { return null; } ItemDrop component = default(ItemDrop); if (!val.TryGetComponent<ItemDrop>(ref component)) { return null; } return MonsterManager.FormatAttack(component); } public static bool SaveCreatureItem(string prefabName) { CreatureItem creatureItem = GetCreatureItem(prefabName); if (creatureItem == null) { return false; } string dataPath = Paths.DataPath; char directorySeparatorChar = Path.DirectorySeparatorChar; string path = dataPath + directorySeparatorChar + prefabName + ".yml"; ISerializer serializer = new SerializerBuilder().Build(); string contents = serializer.Serialize(creatureItem); File.WriteAllText(path, contents); return true; } private static void CacheResources() { List<GameObject> list = Resources.FindObjectsOfTypeAll<GameObject>().ToList(); foreach (GameObject item in list) { m_items[((Object)item).name] = item; } List<Texture2D> source = Resources.FindObjectsOfTypeAll<Texture2D>().ToList(); foreach (Texture2D item2 in source.Where([<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(0)] (Texture2D texture) => !Utility.IsNullOrWhiteSpace(((Object)texture).name))) { m_textures[((Object)item2).name] = item2; } MonsterManager.CreateBaseHuman(); } [return: <d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(2)] public static GameObject TryGetGameObject(string prefabName) { if (!Object.op_Implicit((Object)(object)ZNetScene.instance) || !Object.op_Implicit((Object)(object)ObjectDB.instance)) { return null; } GameObject prefab = ZNetScene.instance.GetPrefab(prefabName); if ((Object)(object)prefab != (Object)null) { return prefab; } prefab = ObjectDB.instance.GetItemPrefab(prefabName); if ((Object)(object)prefab != (Object)null) { return prefab; } GameObject value; return (!m_items.TryGetValue(prefabName, out value)) ? null : value; } public static bool TryGetItemDrop(string itemName, [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(2)] out ItemDrop output) { output = TryGetItemDrop(itemName); return (Object)(object)output != (Object)null; } [return: <d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(2)] private static ItemDrop TryGetItemDrop(string itemName) { if (!Object.op_Implicit((Object)(object)ZNetScene.instance) || !Object.op_Implicit((Object)(object)ObjectDB.instance)) { return null; } GameObject val = TryGetGameObject(itemName); if ((Object)(object)val == (Object)null) { return null; } ItemDrop val2 = default(ItemDrop); return val.TryGetComponent<ItemDrop>(ref val2) ? val2 : null; } } [Serializable] [CanBeNull] [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] public class MonsterData { public bool ENABLED = false; public string OriginalMonster = ""; public bool isClone = false; public string PrefabName = null; public bool CHANGE_SCALE = false; public Scale Scale = new Scale(); public float ColliderHeight; public Scale ColliderCenter = new Scale(); public string DisplayName = null; public string Group = ""; public string Faction = ""; public bool Boss; public bool DoNotHideBossHUD; public string BossEvent = ""; public string DefeatSetGlobalKey = ""; public bool CHANGE_MOVEMENT = false; public float CrouchSpeed; public float WalkSpeed; public float Speed; public float TurnSpeed; public float RunSpeed; public float RunTurnSpeed; public float FlySlowSpeed; public float FlyFastSpeed; public float FlyTurnSpeed; public float Acceleration; public float JumpForce; public float JumpForceForward; public float JumpForceTiredFactor; public float AirControl; public bool CanSwim; public float SwimDepth; public float SwimSpeed; public float SwimTurnSpeed; public float SwimAcceleration; public string GroundTilt = "None"; public float GroundTiltSpeed; public bool Flying; public float JumpStaminaUsage; public bool DisableWhileSleeping; public bool CHANGE_CHARACTER_EFFECTS = false; public List<EffectPrefab> HitEffects = new List<EffectPrefab>(); public List<EffectPrefab> CriticalHitEffects = new List<EffectPrefab>(); public List<EffectPrefab> BackStabHitEffects = new List<EffectPrefab>(); public List<EffectPrefab> DeathEffects = new List<EffectPrefab>(); public List<EffectPrefab> WaterEffects = new List<EffectPrefab>(); public List<EffectPrefab> TarEffects = new List<EffectPrefab>(); public List<EffectPrefab> SlideEffects = new List<EffectPrefab>(); public List<EffectPrefab> JumpEffects = new List<EffectPrefab>(); public List<EffectPrefab> FlyingContinuousEffects = new List<EffectPrefab>(); public List<EffectPrefab> PickUpEffects = new List<EffectPrefab>(); public List<EffectPrefab> DropEffects = new List<EffectPrefab>(); public List<EffectPrefab> ConsumeItemEffects = new List<EffectPrefab>(); public List<EffectPrefab> EquipEffects = new List<EffectPrefab>(); public List<EffectPrefab> PerfectBlockEffect = new List<EffectPrefab>(); public bool CHANGE_HEALTH_DAMAGES = false; public bool TolerateWater; public bool TolerateFire; public bool TolerateSmoke; public bool TolerateTar; public float Health; public DamageModifiersData DamageModifiers = new DamageModifiersData(); public bool StaggerWhenBlocked; public float StaggerDamageFactor; public bool CHANGE_ATTACKS = false; public List<CreatureItem> DefaultItems = new List<CreatureItem>(); public List<CreatureItem> RandomWeapons = new List<CreatureItem>(); public List<CreatureItem> RandomArmors = new List<CreatureItem>(); public List<CreatureItem> RandomShields = new List<CreatureItem>(); public List<RandomSet> RandomSets = new List<RandomSet>(); public string UnarmedWeapon = ""; public string BeardItem = ""; public string HairItem = ""; public bool FemaleModel; public bool CHANGE_AI = false; public float ViewRange; public float ViewAngle; public float HearRange; public bool MistVision; public bool CHANGE_MONSTER_EFFECTS = false; public List<EffectPrefab> AlertedEffects = new List<EffectPrefab>(); public List<EffectPrefab> IdleSound = new List<EffectPrefab>(); public List<EffectPrefab> WakeUpEffects = new List<EffectPrefab>(); public float IdleSoundInterval; public float IdleSoundChance; public string PathAgentType = null; public float MoveMinimumAngle; public bool smoothMovement; public bool SerpentMovement; public float SerpentTurnRadius; public float JumpInterval; public float RandomCircleInterval; public float RandomMoveInterval; public float RandomMoveRange; public bool RandomFly; public float ChanceToTakeOff; public float ChanceToLand; public float GroundDuration; public float AirDuration; public float MaxLandAltitude; public float TakeOffTime; public float FlyAltitudeMinimum; public float FlyAltitudeMaximum; public float FlyAbsoluteMinimumAltitude; public bool AvoidFire; public bool AfraidOfFire; public bool AvoidWater; public bool Aggravatable; public bool PassiveAggressive; public string SpawnMessage = ""; public string DeathMessage = ""; public string AlertedMessage = ""; public float TimeToSafe; public float AlertRange; public bool FleeIfHurtWhenTargetCannotBeReached; public bool FleeIfNotAlerted; public float FleeIfLowHealth; public bool CirculateWhileCharging; public bool CirculateWhileChargingFlying; public bool EnableHuntPlayer; public bool AttackPlayerObjects; public int PrivateAreaTriggerThreshold; public float InterceptTimeMaximum; public float InterceptTimeMinimum; public float MaximumChaseDistance; public float MinimumAttackInterval; public float CircleTargetInterval; public float CircleTargetDuration; public float CircleTargetDistance; public bool Sleeping; public float WakeUpRange; public bool NoiseWakeUp; public float MaximumNoiseWakeUpRange; public float WakeUpDelayMinimum; public float WakeUpDelayMaximum; public bool AvoidLand; public bool CHANGE_MONSTER_CONSUME = false; public List<string> ConsumeItems = new List<string>(); public float ConsumeRange; public float ConsumeSearchRange; public float ConsumeSearchInterval; public bool CHANGE_DROP_TABLE = false; public List<DropData> Drops = new List<DropData>(); public bool CHANGE_PROCREATION; public float UpdateInterval; public float TotalCheckRange; public int MaxCreatures; public float PartnerCheckRange; public float PregnancyChance; public float PregnancyDuration; public int RequiredLovePoints; public bool ChangeOffSpring = false; public string OffSpring = null; public int MinimumOffspringLevel; public float SpawnOffset; public bool ChangeEffects = false; public List<EffectPrefab> BirthEffects = new List<EffectPrefab>(); public List<EffectPrefab> LoveEffects = new List<EffectPrefab>(); public bool CHANGE_TAMEABLE; public bool MAKE_TAMEABLE = false; public float FedDuration; public float TamingTime; public bool StartsTamed; public bool Commandable; public float UnSummonDistance; public float UnSummonOnOwnerLogoutSeconds; public string LevelUpOwnerSkill = "None"; public float LevelUpFactor; public string SaddleItem = ""; public bool DropSaddleOnDeath; public float DropItemVelocity; public bool CHANGE_TAME_EFFECTS = false; public List<EffectPrefab> TamedEffects = new List<EffectPrefab>(); public List<EffectPrefab> SootheEffects = new List<EffectPrefab>(); public List<EffectPrefab> PetEffects = new List<EffectPrefab>(); public List<EffectPrefab> UnSummonEffects = new List<EffectPrefab>(); public List<string> RandomStartingName = new List<string>(); public List<MaterialData> Materials = new List<MaterialData>(); } [Serializable] [CanBeNull] public class Scale { public float x; public float y; public float z; } [Serializable] [CanBeNull] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] public class MaterialData { public bool Enabled; public string Shader = ""; public string MaterialName = ""; public string MainTexture = ""; public ColorData MainColor = new ColorData(); public float Hue; public float Saturation; public float Value; public float AlphaCutoff; public float Smoothness; public bool UseGlossMap; public string GlossTexture = ""; public float Metallic; public float MetalGloss; public ColorData MetalColor = new ColorData(); public string EmissionTexture = ""; public ColorData EmissionColor = new ColorData(); public float BumpStrength; public string BumpTexture = ""; public bool TwoSidedNormals; public bool UseStyles; public float Style; public string StyleTexture = ""; public bool AddRain; } [Serializable] public class ColorData { public float Red; public float Green; public float Blue; public float Alpha; } [Serializable] [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] [CanBeNull] public class DamageModifiersData { public string Blunt = "Normal"; public string Slash = "Normal"; public string Pierce = "Normal"; public string Chop = "Normal"; public string Pickaxe = "Normal"; public string Fire = "Normal"; public string Frost = "Normal"; public string Lightning = "Normal"; public string Poison = "Normal"; public string Spirit = "Normal"; } [Serializable] [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] [CanBeNull] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] public class CreatureItem { public bool ENABLE_ITEM = true; public string Name = null; public string AnimationState = null; public string AttackAnimation = ""; public string AttackOrigin = ""; public bool CHANGE_ITEM_DATA = false; public bool HitTerrain; public bool HitFriendly; public float AttackAngle; public float AttackRange; public float AttackRangeMinimum; public float AttackInterval; public float AttackMaxAngle; public AttackDamages AttackDamages = new AttackDamages(); public int ToolTier; public float AttackForce; public bool Dodgeable; public bool Blockable; public string SpawnOnHit = ""; public string SpawnOnHitTerrain = ""; public string AttackStatusEffect = ""; public bool HitThroughWalls; public bool CHANGE_ITEM_EFFECTS = false; public List<EffectPrefab> HitEffects = new List<EffectPrefab>(); public List<EffectPrefab> HitTerrainEffects = new List<EffectPrefab>(); public List<EffectPrefab> StartEffects = new List<EffectPrefab>(); public List<EffectPrefab> TriggerEffects = new List<EffectPrefab>(); public List<EffectPrefab> TrailStartEffects = new List<EffectPrefab>(); public List<EffectPrefab> BurstEffects = new List<EffectPrefab>(); public bool CHANGE_PROJECTILE = false; public string Projectile_PrefabName = ""; public string Projectile_Clone_ID = ""; public bool CHANGE_PROJECTILE_DATA = false; public AttackDamages Projectile_Damages = new AttackDamages(); public float Projectile_AOE; public bool Projectile_Dodgeable; public bool Projectile_Blockable; public float Projectile_AttackForce; public string Projectile_StatusEffect = ""; public bool Projectile_CanHitWater; public string Projectile_SpawnOnHit = ""; public float Projectile_SpawnChance; public List<string> Projectile_RandomSpawnOnHit = new List<string>(); public bool Projectile_StaticHitOnly; public bool Projectile_GroundHitOnly; public bool PROJECTILE_CHANGE_EFFECTS = false; public List<EffectPrefab> Projectile_HitEffects = new List<EffectPrefab>(); public List<EffectPrefab> Projectile_HitWaterEffects = new List<EffectPrefab>(); public List<EffectPrefab> Projectile_SpawnOnHitEffects = new List<EffectPrefab>(); } public class AttackDamages { public float Damage; public float Blunt; public float Slash; public float Pierce; public float Chop; public float Pickaxe; public float Fire; public float Frost; public float Lightning; public float Poison; public float Spirit; } [Serializable] [CanBeNull] public class EffectPrefab { [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(1)] public string Prefab = null; public bool Enabled = true; public int Variant = -1; public bool Attach; public bool Follow; public bool InheritParentRotation; public bool InheritParentScale; public bool RandomRotation; public bool MultiplyParentVisualScale; public bool Scale; } [Serializable] [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] [CanBeNull] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] public class RandomSet { public string Name = null; public List<CreatureItem> Items = new List<CreatureItem>(); } [Serializable] [CanBeNull] public class DropData { [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(1)] public string Prefab = null; public int AmountMinimum; public int AmountMaximum; public float Chance; public bool OnePerPlayer; public bool LevelMultiplier; public bool DoNotScale; } [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(1)] [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(0)] public static class MonsterManager { [HarmonyPriority(0)] [HarmonyPatch(typeof(ObjectDB), "Awake")] [<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(0)] private static class Initiate_MonsterDB { private static void Postfix() { if (Object.op_Implicit((Object)(object)ZNetScene.instance)) { MonsterDBPlugin.MonsterDBLogger.LogDebug((object)"ObjectDB Awake: Initializing MONSTER DB Files"); RegisterMonsterTweaks(); } } } private static readonly Dictionary<string, MonsterData> m_defaultMonsterData = new Dictionary<string, MonsterData>(); private static readonly List<string> m_newTames = new List<string>(); private static readonly int Hue = Shader.PropertyToID("_Hue"); private static readonly int Saturation = Shader.PropertyToID("_Saturation"); private static readonly int Value = Shader.PropertyToID("_Value"); private static readonly int Cutoff = Shader.PropertyToID("_Cutoff"); private static readonly int Smoothness = Shader.PropertyToID("_Glossiness"); private static readonly int UseGlossMap = Shader.PropertyToID("_UseGlossmap"); private static readonly int Metallic = Shader.PropertyToID("_Metallic"); private static readonly int MetalGloss = Shader.PropertyToID("_MetalGloss"); private static readonly int MetalColor = Shader.PropertyToID("_MetalColor"); private static readonly int EmissionMap = Shader.PropertyToID("_EmissionMap"); private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor"); private static readonly int NormalStrength = Shader.PropertyToID("_BumpScale"); private static readonly int BumpMap = Shader.PropertyToID("_BumpMap"); private static readonly int TwoSidedNormals = Shader.PropertyToID("_TwoSidedNormals"); private static readonly int UseStyles = Shader.PropertyToID("_UseStyles"); private static readonly int Style = Shader.PropertyToID("_Style"); private static readonly int StyleTex = Shader.PropertyToID("_StyleTex"); private static readonly int AddRain = Shader.PropertyToID("_AddRain"); private static readonly int MetallicGlossMap = Shader.PropertyToID("_MetallicGlossMap"); private static void RegisterMonsterTweaks() { if (ZNet.instance.IsServer()) { Paths.CreateDirectories(); ServerSync.UpdateServerTextures(); List<MonsterData> list = DeserializeMonsterFiles(); RegisterClones(list); RegisterMonsterTweaks(list); ServerSync.UpdateServerMonsterDB(); } } private static void RegisterMonsterTweaks(List<MonsterData> list) { foreach (MonsterData item in list) { if (!GetMonsterData(item.PrefabName, out var _)) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to get default data for " + item.PrefabName)); continue; } if (UpdateMonsterData(item)) { MonsterDBPlugin.MonsterDBLogger.LogDebug((object)("Updated " + item.PrefabName)); } ServerSync.m_serverData[item.PrefabName] = item; } } private static void RegisterClones(List<MonsterData> list) { foreach (MonsterData item in list.Where([<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(0)] (MonsterData x) => x.isClone)) { if (CloneMonster(item)) { MonsterDBPlugin.MonsterDBLogger.LogDebug((object)("Successfully created " + item.PrefabName)); ServerSync.m_serverData[item.PrefabName] = item; } } } private static List<MonsterData> DeserializeMonsterFiles() { List<MonsterData> list = new List<MonsterData>(); Paths.CreateDirectories(); string[] files = Directory.GetFiles(Paths.MonsterPath); IDeserializer deserializer = new DeserializerBuilder().Build(); string[] array = files; foreach (string text in array) { try { string input = File.ReadAllText(text); MonsterData item = deserializer.Deserialize<MonsterData>(input); list.Add(item); } catch { MonsterDBPlugin.MonsterDBLogger.LogWarning((object)("Failed to deserialize " + text)); } } return list; } public static void CreateBaseHuman() { //IL_00d1: 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_019c: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Expected O, but got Unknown //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Expected O, but got Unknown //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Expected O, but got Unknown //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_0360: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Expected O, but got Unknown //IL_0413: Unknown result type (might be due to invalid IL or missing references) //IL_041a: Expected O, but got Unknown //IL_0518: Unknown result type (might be due to invalid IL or missing references) //IL_05f9: Unknown result type (might be due to invalid IL or missing references) //IL_05fe: Unknown result type (might be due to invalid IL or missing references) //IL_0613: Unknown result type (might be due to invalid IL or missing references) //IL_061a: Unknown result type (might be due to invalid IL or missing references) //IL_0622: Unknown result type (might be due to invalid IL or missing references) //IL_062d: Unknown result type (might be due to invalid IL or missing references) //IL_0639: Expected O, but got Unknown //IL_064f: Unknown result type (might be due to invalid IL or missing references) //IL_0654: Unknown result type (might be due to invalid IL or missing references) //IL_065f: Unknown result type (might be due to invalid IL or missing references) //IL_0666: Unknown result type (might be due to invalid IL or missing references) //IL_0671: Unknown result type (might be due to invalid IL or missing references) //IL_0681: Expected O, but got Unknown //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Expected O, but got Unknown //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Expected O, but got Unknown GameObject prefab = ZNetScene.instance.GetPrefab("Player"); Player val = default(Player); if (Object.op_Implicit((Object)(object)prefab) && prefab.TryGetComponent<Player>(ref val)) { GameObject val2 = Object.Instantiate<GameObject>(prefab, MonsterDBPlugin._Root.transform, false); ((Object)val2).name = "Human01"; Object.Destroy((Object)(object)val2.GetComponent<PlayerController>()); Object.Destroy((Object)(object)val2.GetComponent<Player>()); Object.Destroy((Object)(object)val2.GetComponent<Talker>()); Object.Destroy((Object)(object)val2.GetComponent<Skills>()); ZNetView val3 = default(ZNetView); if (val2.TryGetComponent<ZNetView>(ref val3)) { val3.m_persistent = true; } Humanoid val4 = val2.AddComponent<Humanoid>(); ((Object)val4).name = ((Object)val2).name; ((Character)val4).m_name = "Human"; ((Character)val4).m_group = "Humans"; ((Character)val4).m_faction = (Faction)0; ((Character)val4).m_crouchSpeed = ((Character)val).m_crouchSpeed; ((Character)val4).m_walkSpeed = ((Character)val).m_walkSpeed; ((Character)val4).m_speed = ((Character)val).m_speed; ((Character)val4).m_runSpeed = ((Character)val).m_runSpeed; ((Character)val4).m_runTurnSpeed = ((Character)val).m_runTurnSpeed; ((Character)val4).m_acceleration = ((Character)val).m_acceleration; ((Character)val4).m_jumpForce = ((Character)val).m_jumpForce; ((Character)val4).m_jumpForceForward = ((Character)val).m_jumpForceForward; ((Character)val4).m_jumpForceTiredFactor = ((Character)val).m_jumpForceForward; ((Character)val4).m_airControl = ((Character)val).m_airControl; ((Character)val4).m_canSwim = true; ((Character)val4).m_swimDepth = ((Character)val).m_swimDepth; ((Character)val4).m_swimSpeed = ((Character)val).m_swimSpeed; ((Character)val4).m_swimTurnSpeed = ((Character)val).m_swimTurnSpeed; ((Character)val4).m_swimAcceleration = ((Character)val).m_swimAcceleration; ((Character)val4).m_groundTilt = ((Character)val).m_groundTilt; ((Character)val4).m_groundTiltSpeed = ((Character)val).m_groundTiltSpeed; ((Character)val4).m_jumpStaminaUsage = ((Character)val).m_jumpStaminaUsage; ((Character)val4).m_eye = Utils.FindChild(val2.transform, "EyePos", (IterativeSearchType)0); ((Character)val4).m_hitEffects = ((Character)val).m_hitEffects; ((Character)val4).m_critHitEffects = ((Character)val).m_critHitEffects; ((Character)val4).m_backstabHitEffects = ((Character)val).m_backstabHitEffects; GameObject val5 = Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("Player_ragdoll"), MonsterDBPlugin._Root.transform, false); Ragdoll val6 = default(Ragdoll); EffectList val7; if (val5.TryGetComponent<Ragdoll>(ref val6)) { val6.m_ttl = 8f; Ragdoll obj = val6; val7 = new EffectList(); val7.m_effectPrefabs = (EffectData[])(object)new EffectData[1] { new EffectData { m_prefab = ZNetScene.instance.GetPrefab("vfx_corpse_destruction_small"), m_enabled = true } }; obj.m_removeEffect = val7; val6.m_float = true; val6.m_dropItems = true; } ((Object)val5).name = "human_ragdoll"; val5.AddComponent<RandomHuman>().m_isRagDoll = true; RegisterToZNetScene(val5); val7 = new EffectList(); val7.m_effectPrefabs = (EffectData[])(object)new EffectData[2] { new EffectData { m_prefab = ZNetScene.instance.GetPrefab("vfx_player_death"), m_enabled = true }, new EffectData { m_prefab = val5, m_enabled = true } }; ((Character)val4).m_deathEffects = val7; ((Character)val4).m_waterEffects = ((Character)val).m_waterEffects; ((Character)val4).m_tarEffects = ((Character)val).m_tarEffects; ((Character)val4).m_slideEffects = ((Character)val).m_slideEffects; ((Character)val4).m_jumpEffects = ((Character)val).m_jumpEffects; ((Character)val4).m_flyingContinuousEffect = ((Character)val).m_flyingContinuousEffect; ((Character)val4).m_tolerateWater = true; ((Character)val4).m_health = 100f; ((Character)val4).m_damageModifiers = ((Character)val).m_damageModifiers; ((Character)val4).m_staggerWhenBlocked = true; ((Character)val4).m_staggerDamageFactor = ((Character)val).m_staggerDamageFactor; val4.m_defaultItems = ((Humanoid)val).m_defaultItems; val4.m_randomWeapon = (GameObject[])(object)new GameObject[0]; val4.m_randomArmor = (GameObject[])(object)new GameObject[0]; val4.m_randomShield = (GameObject[])(object)new GameObject[0]; ItemSet[] array = new ItemSet[2]; ItemSet val8 = new ItemSet(); val8.m_name = "Leather"; val8.m_items = (GameObject[])(object)new GameObject[3] { ZNetScene.instance.GetPrefab("ArmorLeatherChest"), ZNetScene.instance.GetPrefab("ArmorLeatherLegs"), ZNetScene.instance.GetPrefab("Torch") }; array[0] = val8; val8 = new ItemSet(); val8.m_name = "Bronze"; val8.m_items = (GameObject[])(object)new GameObject[4] { ZNetScene.instance.GetPrefab("ArmorBronzeChest"), ZNetScene.instance.GetPrefab("ArmorBronzeLegs"), ZNetScene.instance.GetPrefab("ShieldBronzeBuckler"), ZNetScene.instance.GetPrefab("KnifeCopper") }; array[1] = val8; val4.m_randomSets = (ItemSet[])(object)array; val4.m_unarmedWeapon = ((Humanoid)val).m_unarmedWeapon; val4.m_pickupEffects = val.m_autopickupEffects; val4.m_dropEffects = ((Humanoid)val).m_dropEffects; val4.m_consumeItemEffects = ((Humanoid)val).m_consumeItemEffects; val4.m_equipEffects = val.m_equipStartEffects; val4.m_perfectBlockEffect = ((Humanoid)val).m_perfectBlockEffect; MonsterAI val9 = val2.AddComponent<MonsterAI>(); ((BaseAI)val9).m_viewRange = 30f; ((BaseAI)val9).m_viewAngle = 90f; ((BaseAI)val9).m_hearRange = 9999f; ((BaseAI)val9).m_idleSoundInterval = 10f; ((BaseAI)val9).m_idleSoundChance = 0f; ((BaseAI)val9).m_pathAgentType = (AgentType)1; ((BaseAI)val9).m_moveMinAngle = 90f; ((BaseAI)val9).m_smoothMovement = true; ((BaseAI)val9).m_jumpInterval = 10f; ((BaseAI)val9).m_randomCircleInterval = 2f; ((BaseAI)val9).m_randomMoveInterval = 30f; ((BaseAI)val9).m_randomMoveRange = 3f; val9.m_alertRange = 20f; val9.m_circulateWhileCharging = true; val9.m_privateAreaTriggerTreshold = 4; val9.m_interceptTimeMax = 2f; val9.m_maxChaseDistance = 300f; val9.m_circleTargetInterval = 8f; val9.m_circleTargetDuration = 6f; val9.m_circleTargetDistance = 8f; val9.m_consumeRange = 2f; val9.m_consumeSearchRange = 5f; val9.m_consumeSearchInterval = 10f; val9.m_consumeItems = new List<ItemDrop>(); CharacterDrop val10 = val2.AddComponent<CharacterDrop>(); val10.m_drops = new List<Drop> { new Drop { m_prefab = ZNetScene.instance.GetPrefab("Coins"), m_amountMin = 1, m_amountMax = 10, m_chance = 0.25f, m_levelMultiplier = true } }; RandomAnimation val11 = val2.AddComponent<RandomAnimation>(); val11.m_values = new List<RandomValue> { new RandomValue { m_name = "idle", m_value = 5, m_interval = 3f, m_floatTransition = 1f } }; GameObject prefab2 = ZNetScene.instance.GetPrefab("Boar"); Tameable val12 = default(Tameable); if (prefab2.TryGetComponent<Tameable>(ref val12)) { Tameable val13 = val2.AddComponent<Tameable>(); val13.m_fedDuration = 600f; val13.m_tamingTime = 1800f; val13.m_commandable = true; val13.m_tamedEffect = val12.m_tamedEffect; val13.m_sootheEffect = val12.m_sootheEffect; val13.m_petEffect = val12.m_petEffect; val13.m_commandable = true; val13.m_unsummonDistance = 0f; val13.m_randomStartingName = new List<string> { "Bjorn", "Harald", "Bo", "Frode", "Birger", "Arne", "Erik", "Kare", "Loki", "Thor", "Odin" }; } val2.AddComponent<RandomHuman>(); if (RegisterToZNetScene(val2)) { } } } [return: <d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(2)] private static GameObject CreateClone(string originalMonster, string name) { GameObject prefab = ZNetScene.instance.GetPrefab(originalMonster); if (!Object.op_Implicit((Object)(object)prefab)) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to find " + originalMonster)); return null; } GameObject val = Object.Instantiate<GameObject>(prefab, MonsterDBPlugin._Root.transform, false); ((Object)val).name = name; Humanoid val2 = default(Humanoid); Character val3 = default(Character); if (val.TryGetComponent<Humanoid>(ref val2)) { CloneRagDoll(((Character)val2).m_deathEffects.m_effectPrefabs, val); } else if (val.TryGetComponent<Character>(ref val3)) { CloneRagDoll(val3.m_deathEffects.m_effectPrefabs, val); } return val; } private static void CloneRagDoll(EffectData[] deathEffects, GameObject clone) { foreach (EffectData val in deathEffects) { if (Object.op_Implicit((Object)(object)val.m_prefab.GetComponent<Ragdoll>())) { GameObject val2 = Object.Instantiate<GameObject>(val.m_prefab, MonsterDBPlugin._Root.transform, false); ((Object)val2).name = ((Object)clone).name + "_ragdoll"; RegisterToZNetScene(val2); val.m_prefab = val2; } } } public static bool Server_CloneMonster(MonsterData data) { return CloneMonster(data); } private static bool CloneMonster(MonsterData data) { if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { return false; } GameObject prefab = ZNetScene.instance.GetPrefab(data.PrefabName); if (!Object.op_Implicit((Object)(object)prefab)) { GameObject val = CreateClone(data.OriginalMonster, data.PrefabName); if ((Object)(object)val == (Object)null) { return false; } if (!RegisterToZNetScene(val)) { MonsterDBPlugin.MonsterDBLogger.LogDebug((object)("Failed to register " + ((Object)val).name + " to ZNetScene")); return false; } } return true; } public static bool Command_CloneMonster(string creatureName, string cloneName, bool writeToDisk = true) { if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { return false; } bool flag = true; GameObject val = ZNetScene.instance.GetPrefab(cloneName); if (!Object.op_Implicit((Object)(object)val)) { val = CreateClone(creatureName, cloneName); flag = false; } if ((Object)(object)val == (Object)null) { return false; } if (!flag && !RegisterToZNetScene(val)) { MonsterDBPlugin.MonsterDBLogger.LogDebug((object)("Failed to register " + ((Object)val).name + " to ZNetScene")); return false; } if (!GetMonsterData(cloneName, out var data)) { return false; } data.OriginalMonster = creatureName; data.PrefabName = cloneName; data.DisplayName = cloneName; data.isClone = true; data.ENABLED = true; if (writeToDisk) { WriteDataToDisk(cloneName, data); } Command_UpdateMonster(cloneName); if (ZNet.instance.IsServer()) { ServerSync.m_serverData[cloneName] = data; } ServerSync.UpdateServerMonsterDB(); return true; } private static bool RegisterToZNetScene(GameObject prefab) { if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { return false; } if (ZNetScene.instance.m_prefabs.Contains(prefab)) { return false; } if (ZNetScene.instance.m_namedPrefabs.ContainsKey(StringExtensionMethods.GetStableHashCode(((Object)prefab).name))) { return false; } ZNetScene.instance.m_prefabs.Add(prefab); ZNetScene.instance.m_namedPrefabs[StringExtensionMethods.GetStableHashCode(((Object)prefab).name)] = prefab; return true; } public static bool Command_UpdateMonster(string creatureName) { string monsterPath = Paths.MonsterPath; char directorySeparatorChar = Path.DirectorySeparatorChar; string path = monsterPath + directorySeparatorChar + creatureName + ".yml"; if (!File.Exists(path)) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to find file: " + creatureName + ".yml")); return false; } try { IDeserializer deserializer = new DeserializerBuilder().Build(); string input = File.ReadAllText(path); MonsterData data = deserializer.Deserialize<MonsterData>(input); return UpdateMonsterData(data); } catch { MonsterDBPlugin.MonsterDBLogger.LogWarning((object)("Failed to deserialize " + creatureName + ".yml")); return false; } } public static bool Server_UpdateMonster(MonsterData data) { return UpdateMonsterData(data); } public static bool FileWatch_UpdateMonster(string filePath, string fileName) { if (!ZNet.instance.IsServer()) { MonsterDBPlugin.MonsterDBLogger.LogDebug((object)"Client: Must be server to update monster"); return false; } if (!File.Exists(filePath)) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to find file: " + fileName)); return false; } try { IDeserializer deserializer = new DeserializerBuilder().Build(); string input = File.ReadAllText(filePath); MonsterData monsterData = deserializer.Deserialize<MonsterData>(input); if (UpdateMonsterData(monsterData)) { ServerSync.m_serverData[monsterData.PrefabName] = monsterData; return true; } return false; } catch { MonsterDBPlugin.MonsterDBLogger.LogWarning((object)("Failed to deserialize " + fileName)); return false; } } public static bool ResetMonster(string creatureName) { MonsterData value; return m_defaultMonsterData.TryGetValue(creatureName, out value) && UpdateMonsterData(value, reset: true); } private static void UpdateMonsterScale(MonsterData data, GameObject critter, bool reset) { //IL_0040: 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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) if (!data.CHANGE_SCALE && !reset) { return; } critter.transform.localScale = new Vector3(data.Scale.x, data.Scale.y, data.Scale.z); CapsuleCollider val = default(CapsuleCollider); if (critter.TryGetComponent<CapsuleCollider>(ref val)) { val.height = data.ColliderHeight; val.center = new Vector3(data.ColliderCenter.x, data.ColliderCenter.y, data.ColliderCenter.z); } Humanoid val2 = default(Humanoid); if (critter.TryGetComponent<Humanoid>(ref val2)) { EffectData[] effectPrefabs = ((Character)val2).m_deathEffects.m_effectPrefabs; foreach (EffectData val3 in effectPrefabs) { if (Object.op_Implicit((Object)(object)val3.m_prefab.GetComponent<Ragdoll>())) { val3.m_prefab.transform.localScale = new Vector3(data.Scale.x, data.Scale.y, data.Scale.z); } } } else { Character val4 = default(Character); if (!critter.TryGetComponent<Character>(ref val4)) { return; } EffectData[] effectPrefabs2 = val4.m_deathEffects.m_effectPrefabs; foreach (EffectData val5 in effectPrefabs2) { if (Object.op_Implicit((Object)(object)val5.m_prefab.GetComponent<Ragdoll>())) { val5.m_prefab.transform.localScale = new Vector3(data.Scale.x, data.Scale.y, data.Scale.z); } } } } private static void UpdateMonsterHumanoid(MonsterData data, Humanoid humanoid, bool reset) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_03c6: Unknown result type (might be due to invalid IL or missing references) //IL_03c8: Unknown result type (might be due to invalid IL or missing references) ((Character)humanoid).m_name = data.DisplayName; ((Character)humanoid).m_group = data.Group; if (GetFaction(data.Faction, out var output)) { ((Character)humanoid).m_faction = output; } else { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to update faction for " + data.PrefabName)); } ((Character)humanoid).m_boss = data.Boss; ((Character)humanoid).m_dontHideBossHud = data.DoNotHideBossHUD; ((Character)humanoid).m_bossEvent = data.BossEvent; ((Character)humanoid).m_defeatSetGlobalKey = data.DefeatSetGlobalKey; if (data.CHANGE_MOVEMENT || reset) { ((Character)humanoid).m_crouchSpeed = data.CrouchSpeed; ((Character)humanoid).m_walkSpeed = data.WalkSpeed; ((Character)humanoid).m_speed = data.Speed; ((Character)humanoid).m_turnSpeed = data.TurnSpeed; ((Character)humanoid).m_runSpeed = data.RunSpeed; ((Character)humanoid).m_runTurnSpeed = data.RunTurnSpeed; ((Character)humanoid).m_flySlowSpeed = data.FlySlowSpeed; ((Character)humanoid).m_flyFastSpeed = data.FlyFastSpeed; ((Character)humanoid).m_flyTurnSpeed = data.FlyTurnSpeed; ((Character)humanoid).m_acceleration = data.Acceleration; ((Character)humanoid).m_jumpForce = data.JumpForce; ((Character)humanoid).m_jumpForceForward = data.JumpForceForward; ((Character)humanoid).m_jumpForceTiredFactor = data.JumpForceTiredFactor; ((Character)humanoid).m_airControl = data.AirControl; ((Character)humanoid).m_canSwim = data.CanSwim; ((Character)humanoid).m_swimDepth = data.SwimDepth; ((Character)humanoid).m_swimSpeed = data.SwimSpeed; ((Character)humanoid).m_swimTurnSpeed = data.SwimTurnSpeed; ((Character)humanoid).m_swimAcceleration = data.SwimAcceleration; if (GetGroundTilt(data.GroundTilt, out var output2)) { ((Character)humanoid).m_groundTilt = output2; } else { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to update ground tilt type for " + data.PrefabName)); } ((Character)humanoid).m_groundTiltSpeed = data.GroundTiltSpeed; ((Character)humanoid).m_flying = data.Flying; ((Character)humanoid).m_jumpStaminaUsage = data.JumpStaminaUsage; ((Character)humanoid).m_disableWhileSleeping = data.DisableWhileSleeping; } if (data.CHANGE_CHARACTER_EFFECTS || reset) { if (GetEffects(data.HitEffects, out var output3)) { ((Character)humanoid).m_hitEffects = output3; } if (GetEffects(data.CriticalHitEffects, out var output4)) { ((Character)humanoid).m_critHitEffects = output4; } if (GetEffects(data.BackStabHitEffects, out var output5)) { ((Character)humanoid).m_backstabHitEffects = output5; } if (GetEffects(data.DeathEffects, out var output6)) { ((Character)humanoid).m_deathEffects = output6; } if (GetEffects(data.WaterEffects, out var output7)) { ((Character)humanoid).m_waterEffects = output7; } if (GetEffects(data.TarEffects, out var output8)) { ((Character)humanoid).m_tarEffects = output8; } if (GetEffects(data.SlideEffects, out var output9)) { ((Character)humanoid).m_slideEffects = output9; } if (GetEffects(data.JumpEffects, out var output10)) { ((Character)humanoid).m_jumpEffects = output10; } if (GetEffects(data.FlyingContinuousEffects, out var output11)) { ((Character)humanoid).m_flyingContinuousEffect = output11; } if (GetEffects(data.PickUpEffects, out var output12)) { humanoid.m_pickupEffects = output12; } if (GetEffects(data.DropEffects, out var output13)) { humanoid.m_pickupEffects = output13; } if (GetEffects(data.ConsumeItemEffects, out var output14)) { humanoid.m_pickupEffects = output14; } if (GetEffects(data.EquipEffects, out var output15)) { humanoid.m_pickupEffects = output15; } if (GetEffects(data.PerfectBlockEffect, out var output16)) { humanoid.m_pickupEffects = output16; } } if (data.CHANGE_HEALTH_DAMAGES || reset) { ((Character)humanoid).m_tolerateWater = data.TolerateWater; ((Character)humanoid).m_tolerateFire = data.TolerateFire; ((Character)humanoid).m_tolerateSmoke = data.TolerateSmoke; ((Character)humanoid).m_tolerateTar = data.TolerateTar; ((Character)humanoid).m_health = data.Health; if (GetDamageMods(data.DamageModifiers, out var output17)) { ((Character)humanoid).m_damageModifiers = output17; } ((Character)humanoid).m_staggerWhenBlocked = data.StaggerWhenBlocked; ((Character)humanoid).m_staggerDamageFactor = data.StaggerDamageFactor; } if (data.CHANGE_ATTACKS || reset) { if (GetItems(data.DefaultItems, reset, out var output18)) { humanoid.m_defaultItems = output18.ToArray(); } if (GetItems(data.RandomWeapons, reset, out var output19)) { humanoid.m_randomWeapon = output19.ToArray(); } if (GetItems(data.RandomArmors, reset, out var output20)) { humanoid.m_randomArmor = output20.ToArray(); } if (GetItems(data.RandomShields, reset, out var output21)) { humanoid.m_randomShield = output21.ToArray(); } if (GetRandomSets(data.RandomSets, reset, out var output22)) { humanoid.m_randomSets = output22.ToArray(); } if (MonsterDB.TryGetItemDrop(data.UnarmedWeapon, out var output23)) { humanoid.m_unarmedWeapon = output23; } humanoid.m_beardItem = data.BeardItem; humanoid.m_hairItem = data.HairItem; } } private static void UpdateMonsterCharacter(MonsterData data, Character character, bool reset) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0187: 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_0324: Unknown result type (might be due to invalid IL or missing references) character.m_name = data.DisplayName; character.m_group = data.Group; if (GetFaction(data.Faction, out var output)) { character.m_faction = output; } else { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to update faction for " + data.PrefabName)); } character.m_boss = data.Boss; character.m_dontHideBossHud = data.DoNotHideBossHUD; character.m_bossEvent = data.BossEvent; character.m_defeatSetGlobalKey = data.DefeatSetGlobalKey; if (data.CHANGE_MOVEMENT || reset) { character.m_crouchSpeed = data.CrouchSpeed; character.m_walkSpeed = data.WalkSpeed; character.m_speed = data.Speed; character.m_turnSpeed = data.TurnSpeed; character.m_runSpeed = data.RunSpeed; character.m_runTurnSpeed = data.RunTurnSpeed; character.m_flySlowSpeed = data.FlySlowSpeed; character.m_flyFastSpeed = data.FlyFastSpeed; character.m_flyTurnSpeed = data.FlyTurnSpeed; character.m_acceleration = data.Acceleration; character.m_jumpForce = data.JumpForce; character.m_jumpForceForward = data.JumpForceForward; character.m_jumpForceTiredFactor = data.JumpForceTiredFactor; character.m_airControl = data.AirControl; character.m_canSwim = data.CanSwim; character.m_swimDepth = data.SwimDepth; character.m_swimSpeed = data.SwimSpeed; character.m_swimTurnSpeed = data.SwimTurnSpeed; character.m_swimAcceleration = data.SwimAcceleration; if (GetGroundTilt(data.GroundTilt, out var output2)) { character.m_groundTilt = output2; } character.m_groundTiltSpeed = data.GroundTiltSpeed; character.m_flying = data.Flying; character.m_jumpStaminaUsage = data.JumpStaminaUsage; character.m_disableWhileSleeping = data.DisableWhileSleeping; } if (data.CHANGE_CHARACTER_EFFECTS || reset) { if (GetEffects(data.HitEffects, out var output3)) { character.m_hitEffects = output3; } if (GetEffects(data.CriticalHitEffects, out var output4)) { character.m_hitEffects = output4; } if (GetEffects(data.BackStabHitEffects, out var output5)) { character.m_hitEffects = output5; } if (GetEffects(data.DeathEffects, out var output6)) { character.m_hitEffects = output6; } if (GetEffects(data.WaterEffects, out var output7)) { character.m_hitEffects = output7; } if (GetEffects(data.TarEffects, out var output8)) { character.m_hitEffects = output8; } if (GetEffects(data.SlideEffects, out var output9)) { character.m_hitEffects = output9; } if (GetEffects(data.JumpEffects, out var output10)) { character.m_hitEffects = output10; } if (GetEffects(data.FlyingContinuousEffects, out var output11)) { character.m_hitEffects = output11; } } if (data.CHANGE_HEALTH_DAMAGES || reset) { character.m_tolerateWater = data.TolerateWater; character.m_tolerateFire = data.TolerateFire; character.m_tolerateSmoke = data.TolerateSmoke; character.m_tolerateTar = data.TolerateTar; character.m_health = data.Health; if (GetDamageMods(data.DamageModifiers, out var output12)) { character.m_damageModifiers = output12; } character.m_staggerWhenBlocked = data.StaggerWhenBlocked; character.m_staggerDamageFactor = data.StaggerDamageFactor; } } private static void UpdateMonsterAI(MonsterData data, MonsterAI monsterAI, bool reset) { //IL_00ba: 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) ((BaseAI)monsterAI).m_viewRange = data.ViewRange; ((BaseAI)monsterAI).m_viewAngle = data.ViewAngle; ((BaseAI)monsterAI).m_hearRange = data.HearRange; ((BaseAI)monsterAI).m_mistVision = data.MistVision; if (data.CHANGE_MONSTER_EFFECTS || reset) { if (GetEffects(data.AlertedEffects, out var output)) { ((BaseAI)monsterAI).m_alertedEffects = output; } if (GetEffects(data.IdleSound, out var output2)) { ((BaseAI)monsterAI).m_idleSound = output2; } if (GetEffects(data.WakeUpEffects, out var output3)) { monsterAI.m_wakeupEffects = output3; } } ((BaseAI)monsterAI).m_idleSoundInterval = data.IdleSoundInterval; ((BaseAI)monsterAI).m_idleSoundChance = data.IdleSoundChance; if (GetPathType(data.PathAgentType, out var output4)) { ((BaseAI)monsterAI).m_pathAgentType = output4; } ((BaseAI)monsterAI).m_moveMinAngle = data.MoveMinimumAngle; ((BaseAI)monsterAI).m_smoothMovement = data.smoothMovement; ((BaseAI)monsterAI).m_serpentMovement = data.SerpentMovement; ((BaseAI)monsterAI).m_serpentTurnRadius = data.SerpentTurnRadius; ((BaseAI)monsterAI).m_jumpInterval = data.JumpInterval; ((BaseAI)monsterAI).m_randomCircleInterval = data.RandomCircleInterval; ((BaseAI)monsterAI).m_randomMoveInterval = data.RandomMoveInterval; ((BaseAI)monsterAI).m_randomMoveRange = data.RandomMoveRange; ((BaseAI)monsterAI).m_randomFly = data.RandomFly; ((BaseAI)monsterAI).m_chanceToTakeoff = data.ChanceToTakeOff; ((BaseAI)monsterAI).m_chanceToLand = data.ChanceToLand; ((BaseAI)monsterAI).m_groundDuration = data.GroundDuration; ((BaseAI)monsterAI).m_airDuration = data.AirDuration; ((BaseAI)monsterAI).m_maxLandAltitude = data.MaxLandAltitude; ((BaseAI)monsterAI).m_takeoffTime = data.TakeOffTime; ((BaseAI)monsterAI).m_flyAltitudeMin = data.FlyAltitudeMinimum; ((BaseAI)monsterAI).m_flyAltitudeMax = data.FlyAltitudeMaximum; ((BaseAI)monsterAI).m_flyAbsMinAltitude = data.FlyAbsoluteMinimumAltitude; ((BaseAI)monsterAI).m_avoidFire = data.AvoidFire; ((BaseAI)monsterAI).m_afraidOfFire = data.AfraidOfFire; ((BaseAI)monsterAI).m_avoidWater = data.AvoidWater; ((BaseAI)monsterAI).m_aggravatable = data.Aggravatable; ((BaseAI)monsterAI).m_passiveAggresive = data.PassiveAggressive; ((BaseAI)monsterAI).m_spawnMessage = data.SpawnMessage; ((BaseAI)monsterAI).m_deathMessage = data.DeathMessage; ((BaseAI)monsterAI).m_alertedMessage = data.AlertedMessage; monsterAI.m_alertRange = data.AlertRange; monsterAI.m_fleeIfHurtWhenTargetCantBeReached = data.FleeIfHurtWhenTargetCannotBeReached; monsterAI.m_fleeIfNotAlerted = data.FleeIfNotAlerted; monsterAI.m_fleeIfLowHealth = data.FleeIfLowHealth; monsterAI.m_circulateWhileCharging = data.CirculateWhileCharging; monsterAI.m_circulateWhileChargingFlying = data.CirculateWhileChargingFlying; monsterAI.m_enableHuntPlayer = data.EnableHuntPlayer; monsterAI.m_attackPlayerObjects = data.AttackPlayerObjects; monsterAI.m_privateAreaTriggerTreshold = data.PrivateAreaTriggerThreshold; monsterAI.m_interceptTimeMax = data.InterceptTimeMaximum; monsterAI.m_interceptTimeMin = data.InterceptTimeMinimum; monsterAI.m_maxChaseDistance = data.MaximumChaseDistance; monsterAI.m_minAttackInterval = data.MinimumAttackInterval; monsterAI.m_circleTargetInterval = data.CircleTargetInterval; monsterAI.m_circleTargetDuration = data.CircleTargetDuration; monsterAI.m_circleTargetDistance = data.CircleTargetDistance; monsterAI.m_sleeping = data.Sleeping; monsterAI.m_wakeupRange = data.WakeUpRange; monsterAI.m_noiseWakeup = data.NoiseWakeUp; monsterAI.m_maxNoiseWakeupRange = data.MaximumNoiseWakeUpRange; monsterAI.m_wakeUpDelayMin = data.WakeUpDelayMinimum; monsterAI.m_wakeUpDelayMax = data.WakeUpDelayMaximum; monsterAI.m_avoidLand = data.AvoidLand; if (data.CHANGE_MONSTER_CONSUME || reset) { if (GetItemDrops(data.ConsumeItems, out var output5)) { monsterAI.m_consumeItems = output5; } monsterAI.m_consumeRange = data.ConsumeRange; monsterAI.m_consumeSearchRange = data.ConsumeSearchRange; monsterAI.m_consumeSearchInterval = data.ConsumeSearchInterval; MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Updated " + data.PrefabName + " consume items")); } } private static void UpdateAnimalAI(MonsterData data, AnimalAI animalAI, bool reset) { //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) ((BaseAI)animalAI).m_viewRange = data.ViewRange; ((BaseAI)animalAI).m_viewAngle = data.ViewAngle; ((BaseAI)animalAI).m_hearRange = data.HearRange; ((BaseAI)animalAI).m_mistVision = data.MistVision; if (data.CHANGE_MONSTER_EFFECTS || reset) { if (GetEffects(data.AlertedEffects, out var output)) { ((BaseAI)animalAI).m_alertedEffects = output; } if (GetEffects(data.IdleSound, out var output2)) { ((BaseAI)animalAI).m_idleSound = output2; } } ((BaseAI)animalAI).m_idleSoundInterval = data.IdleSoundInterval; ((BaseAI)animalAI).m_idleSoundChance = data.IdleSoundChance; if (GetPathType(data.PathAgentType, out var output3)) { ((BaseAI)animalAI).m_pathAgentType = output3; } else { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to update path type of " + data.PrefabName)); } ((BaseAI)animalAI).m_moveMinAngle = data.MoveMinimumAngle; ((BaseAI)animalAI).m_smoothMovement = data.smoothMovement; ((BaseAI)animalAI).m_serpentMovement = data.SerpentMovement; ((BaseAI)animalAI).m_serpentTurnRadius = data.SerpentTurnRadius; ((BaseAI)animalAI).m_jumpInterval = data.JumpInterval; ((BaseAI)animalAI).m_randomCircleInterval = data.RandomCircleInterval; ((BaseAI)animalAI).m_randomMoveInterval = data.RandomMoveInterval; ((BaseAI)animalAI).m_randomMoveRange = data.RandomMoveRange; ((BaseAI)animalAI).m_randomFly = data.RandomFly; ((BaseAI)animalAI).m_chanceToTakeoff = data.ChanceToTakeOff; ((BaseAI)animalAI).m_chanceToLand = data.ChanceToLand; ((BaseAI)animalAI).m_groundDuration = data.GroundDuration; ((BaseAI)animalAI).m_airDuration = data.AirDuration; ((BaseAI)animalAI).m_maxLandAltitude = data.MaxLandAltitude; ((BaseAI)animalAI).m_takeoffTime = data.TakeOffTime; ((BaseAI)animalAI).m_flyAltitudeMin = data.FlyAltitudeMinimum; ((BaseAI)animalAI).m_flyAltitudeMax = data.FlyAltitudeMaximum; ((BaseAI)animalAI).m_flyAbsMinAltitude = data.FlyAbsoluteMinimumAltitude; ((BaseAI)animalAI).m_avoidFire = data.AvoidFire; ((BaseAI)animalAI).m_afraidOfFire = data.AfraidOfFire; ((BaseAI)animalAI).m_avoidWater = data.AvoidWater; ((BaseAI)animalAI).m_aggravatable = data.Aggravatable; ((BaseAI)animalAI).m_passiveAggresive = data.PassiveAggressive; ((BaseAI)animalAI).m_spawnMessage = data.SpawnMessage; ((BaseAI)animalAI).m_deathMessage = data.DeathMessage; ((BaseAI)animalAI).m_alertedMessage = data.AlertedMessage; animalAI.m_timeToSafe = data.TimeToSafe; } private static void UpdateMonsterProcreation(MonsterData data, GameObject critter, bool reset) { Procreation val = default(Procreation); if (!critter.TryGetComponent<Procreation>(ref val) || !(data.CHANGE_PROCREATION || reset)) { return; } val.m_updateInterval = data.UpdateInterval; val.m_totalCheckRange = data.TotalCheckRange; val.m_maxCreatures = data.MaxCreatures; val.m_partnerCheckRange = data.PartnerCheckRange; val.m_pregnancyChance = data.PregnancyChance; val.m_pregnancyDuration = data.PregnancyDuration; val.m_requiredLovePoints = data.RequiredLovePoints; if (data.ChangeOffSpring) { if (GetOffspring(data.OffSpring, out var output)) { val.m_offspring = output; } else { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to change offspring of " + ((Object)critter).name)); } } val.m_minOffspringLevel = data.MinimumOffspringLevel; val.m_spawnOffset = data.SpawnOffset; if (data.ChangeEffects) { if (GetEffects(data.BirthEffects, out var output2)) { val.m_birthEffects = output2; } if (GetEffects(data.LoveEffects, out var output3)) { val.m_loveEffects = output3; } } } private static void UpdateMonsterTame(MonsterData data, GameObject critter, bool reset) { //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) if (reset) { Tameable val = default(Tameable); if (m_newTames.Contains(data.PrefabName) && critter.TryGetComponent<Tameable>(ref val)) { Object.Destroy((Object)(object)val); m_newTames.Remove(data.PrefabName); } } else { if (!(data.CHANGE_TAMEABLE || reset)) { return; } Tameable val2 = default(Tameable); if (!critter.TryGetComponent<Tameable>(ref val2) && data.MAKE_TAMEABLE) { val2 = critter.AddComponent<Tameable>(); m_newTames.Add(data.PrefabName); } if (!((Object)(object)val2 != (Object)null)) { return; } val2.m_fedDuration = data.FedDuration; val2.m_tamingTime = data.TamingTime; val2.m_startsTamed = data.StartsTamed; if (data.CHANGE_TAME_EFFECTS) { if (GetEffects(data.TamedEffects, out var output)) { val2.m_tamedEffect = output; } if (GetEffects(data.SootheEffects, out var output2)) { val2.m_sootheEffect = output2; } if (GetEffects(data.PetEffects, out var output3)) { val2.m_petEffect = output3; } if (GetEffects(data.UnSummonEffects, out var output4)) { val2.m_unSummonEffect = output4; } } val2.m_commandable = data.Commandable; val2.m_unsummonDistance = data.UnSummonDistance; val2.m_unsummonOnOwnerLogoutSeconds = data.UnSummonOnOwnerLogoutSeconds; if (GetSkill(data.LevelUpOwnerSkill, out var output5)) { val2.m_levelUpOwnerSkill = output5; } val2.m_levelUpFactor = data.LevelUpFactor; if (GetSaddle(data.SaddleItem, out var output6)) { val2.m_saddleItem = output6; } val2.m_dropSaddleOnDeath = data.DropSaddleOnDeath; val2.m_dropItemVel = data.DropItemVelocity; val2.m_randomStartingName = data.RandomStartingName; } } private static Material CreateMaterial(MaterialData materialData, Material material) { //IL_0002: 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_0015: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) Material val = new Material(material) { name = ((Object)material).name }; if (GetTexture2D(materialData.MainTexture, out var output)) { val.mainTexture = (Texture)(object)output; } val.color = new Color(materialData.MainColor.Red, materialData.MainColor.Green, materialData.MainColor.Blue, materialData.MainColor.Alpha); if (val.HasFloat(Hue)) { val.SetFloat(Hue, materialData.Hue); } if (val.HasFloat(Saturation)) { val.SetFloat(Saturation, materialData.Saturation); } if (val.HasFloat(Value)) { val.SetFloat(Value, materialData.Value); } if (val.HasFloat(Cutoff)) { val.SetFloat(Cutoff, materialData.AlphaCutoff); } if (val.HasFloat(Smoothness)) { val.SetFloat(Smoothness, materialData.Smoothness); } if (val.HasFloat(UseGlossMap)) { val.SetFloat(UseGlossMap, materialData.UseGlossMap ? 1f : 0f); } if (val.HasFloat(Metallic)) { val.SetFloat(Metallic, materialData.Metallic); } if (val.HasTexture(MetallicGlossMap) && GetTexture2D(materialData.GlossTexture, out var output2)) { val.SetTexture(MetallicGlossMap, (Texture)(object)output2); } if (val.HasFloat(Metallic)) { val.SetFloat(Metallic, materialData.Metallic); } if (val.HasFloat(MetalGloss)) { val.SetFloat(MetalGloss, materialData.MetalGloss); } if (val.HasColor(MetalColor)) { val.SetColor(MetalColor, new Color(materialData.MetalColor.Red, materialData.MetalColor.Green, materialData.MetalColor.Blue, materialData.MetalColor.Alpha)); } if (val.HasTexture(EmissionMap) && GetTexture2D(materialData.EmissionTexture, out var output3)) { val.SetTexture(EmissionMap, (Texture)(object)output3); } if (val.HasColor(EmissionColor)) { val.SetColor(EmissionColor, new Color(materialData.EmissionColor.Red, materialData.EmissionColor.Green, materialData.EmissionColor.Blue, materialData.EmissionColor.Alpha)); } if (val.HasFloat(NormalStrength)) { val.SetFloat(NormalStrength, materialData.BumpStrength); } if (val.HasTexture(BumpMap) && GetTexture2D(materialData.BumpTexture, out var output4)) { val.SetTexture(BumpMap, (Texture)(object)output4); } if (val.HasFloat(TwoSidedNormals)) { val.SetFloat(TwoSidedNormals, materialData.TwoSidedNormals ? 1f : 0f); } if (val.HasFloat(UseStyles)) { val.SetFloat(UseStyles, materialData.UseStyles ? 1f : 0f); } if (val.HasFloat(Style)) { val.SetFloat(Style, materialData.Style); } if (val.HasTexture(StyleTex) && GetTexture2D(materialData.StyleTexture, out var output5)) { val.SetTexture(StyleTex, (Texture)(object)output5); } if (val.HasFloat(AddRain)) { val.SetFloat(AddRain, materialData.AddRain ? 1f : 0f); } return val; } private static void UpdateMonsterMaterial(MonsterData data, GameObject critter, bool reset) { if (data.Materials.TrueForAll((MaterialData x) => !x.Enabled) && !reset) { return; } SkinnedMeshRenderer componentInChildren = critter.GetComponentInChildren<SkinnedMeshRenderer>(); if ((Object)(object)componentInChildren == (Object)null) { return; } List<Material> list = new List<Material>(); foreach (MaterialData materialData in data.Materials) { Material val = ((Renderer)componentInChildren).materials.ToList().Find([<00b16343-624e-4b9f-8261-3195a71905e6>NullableContext(0)] (Material x) => ((Object)x).name.Replace("(Instance)", string.Empty).TrimEnd(Array.Empty<char>()) == materialData.MaterialName); if ((Object)(object)val == (Object)null) { return; } if (!materialData.Enabled && !reset) { list.Add(val); } else { list.Add(CreateMaterial(materialData, val)); } } if (list.Count != 0) { ((Renderer)componentInChildren).materials = list.ToArray(); ((Renderer)componentInChildren).sharedMaterials = list.ToArray(); Humanoid val2 = default(Humanoid); Character val3 = default(Character); if (critter.TryGetComponent<Humanoid>(ref val2)) { UpdateRagDollMaterials(((Character)val2).m_deathEffects.m_effectPrefabs, list); } else if (critter.TryGetComponent<Character>(ref val3)) { UpdateRagDollMaterials(val3.m_deathEffects.m_effectPrefabs, list); } } } private static void UpdateRagDollMaterials(EffectData[] deathEffects, List<Material> newMaterials) { Ragdoll val2 = default(Ragdoll); foreach (EffectData val in deathEffects) { if (val.m_prefab.TryGetComponent<Ragdoll>(ref val2)) { val2.m_mainModel.materials = newMaterials.ToArray(); val2.m_mainModel.sharedMaterials = newMaterials.ToArray(); } } } private static void UpdateMonsterModel(MonsterData data, GameObject critter, bool reset) { VisEquipment val = default(VisEquipment); if (critter.TryGetComponent<VisEquipment>(ref val)) { val.SetModel(data.FemaleModel ? 1 : 0); } } private static bool UpdateMonsterData(MonsterData data, bool reset = false) { if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { return false; } GameObject prefab = ZNetScene.instance.GetPrefab(data.PrefabName); if (!Object.op_Implicit((Object)(object)prefab)) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to find " + data.PrefabName)); return false; } UpdateMonsterScale(data, prefab, reset); Humanoid humanoid = default(Humanoid); Character character = default(Character); if (prefab.TryGetComponent<Humanoid>(ref humanoid) && (data.ENABLED || reset)) { UpdateMonsterHumanoid(data, humanoid, reset); } else if (prefab.TryGetComponent<Character>(ref character) && (data.ENABLED || reset)) { UpdateMonsterCharacter(data, character, reset); } MonsterAI monsterAI = default(MonsterAI); AnimalAI animalAI = default(AnimalAI); if (prefab.TryGetComponent<MonsterAI>(ref monsterAI) && (data.CHANGE_AI || reset)) { UpdateMonsterAI(data, monsterAI, reset); } else if (prefab.TryGetComponent<AnimalAI>(ref animalAI) && (data.CHANGE_AI || reset)) { UpdateAnimalAI(data, animalAI, reset); } CharacterDrop val = default(CharacterDrop); if (prefab.TryGetComponent<CharacterDrop>(ref val) && (data.CHANGE_DROP_TABLE || reset) && GetDrops(data.Drops, out var output)) { val.m_drops = output; } UpdateMonsterProcreation(data, prefab, reset); UpdateMonsterTame(data, prefab, reset); UpdateMonsterMaterial(data, prefab, reset); UpdateMonsterModel(data, prefab, reset); return true; } private static bool GetTexture2D(string input, [<d764d306-ce55-4ac8-bd0e-cb4b48ae77dc>Nullable(2)] out Texture2D output) { output = null; if (TextureManager.RegisteredTextures.TryGetValue(input, out var value)) { output = value; return true; } if (MonsterDB.m_textures.TryGetValue(input, out var value2)) { output = value2; return true; } return false; } private static bool GetSaddle(string input, out ItemDrop output) { output = null; GameObject val = MonsterDB.TryGetGameObject(input); if ((Object)(object)val == (Object)null) { return false; } ItemDrop val2 = default(ItemDrop); if (val.TryGetComponent<ItemDrop>(ref val2)) { output = val2; return true; } return false; } private static bool GetSkill(string input, out SkillType output) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected I4, but got Unknown output = (SkillType)0; if (Enum.TryParse<SkillType>(input, out SkillType result)) { output = (SkillType)(int)result; return true; } output = (SkillType)Math.Abs(StringExtensionMethods.GetStableHashCode(input)); return Object.op_Implicit((Object)(object)Player.m_localPlayer) && Player.m_localPlayer.m_skills.GetSkillDef(output) != null; } private static bool GetPathType(string input, out AgentType output) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected I4, but got Unknown output = (AgentType)1; if (!Enum.TryParse<AgentType>(input, out AgentType result)) { return false; } output = (AgentType)(int)result; return true; } private static bool GetDrops(List<DropData> input, out List<Drop> output) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_004e: 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) //IL_0066: 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) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Expected O, but got Unknown output = new List<Drop>(); foreach (DropData item in input) { GameObject val = MonsterDB.TryGetGameObject(item.Prefab); if (!((Object)(object)val == (Object)null)) { output.Add(new Drop { m_prefab = val, m_amountMin = item.AmountMinimum, m_amountMax = item.AmountMaximum, m_chance = item.Chance, m_onePerPlayer = item.OnePerPlayer, m_levelMultiplier = item.LevelMultiplier, m_dontScale = item.DoNotScale }); } } return output.Count > 0; } private static bool GetOffspring(string input, out GameObject output) { output = MonsterDB.TryGetGameObject(input); return (Object)(object)output != (Object)null; } private static bool GetRandomSets(List<RandomSet> input, bool reset, out List<ItemSet> output) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown output = new List<ItemSet>(); foreach (RandomSet item in input) { ItemSet val = new ItemSet { m_name = item.Name }; if (GetItems(item.Items, reset, out var output2)) { val.m_items = output2.ToArray(); } output.Add(val); } return true; } private static bool GetItemDrops(List<string> input, out List<ItemDrop> output) { output = new List<ItemDrop>(); ItemDrop item = default(ItemDrop); foreach (string item2 in input) { GameObject val = MonsterDB.TryGetGameObject(item2); if ((Object)(object)val == (Object)null) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to find item " + item2)); } else if (!val.TryGetComponent<ItemDrop>(ref item)) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to find item drop for " + item2)); } else { output.Add(item); } } return output.Count > 0; } private static bool GetItems(List<CreatureItem> input, bool reset, out List<GameObject> output) { //IL_0102: 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_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_04e9: Unknown result type (might be due to invalid IL or missing references) //IL_04ee: Unknown result type (might be due to invalid IL or missing references) output = new List<GameObject>(); ItemDrop val3 = default(ItemDrop); Projectile val6 = default(Projectile); foreach (CreatureItem item in input) { if (!item.ENABLE_ITEM) { continue; } GameObject val = MonsterDB.TryGetGameObject(item.Name); if ((Object)(object)val == (Object)null || !Object.op_Implicit((Object)(object)val.GetComponent<ItemDrop>())) { continue; } if (reset || !item.CHANGE_ITEM_DATA) { return Object.op_Implicit((Object)(object)val); } GameObject val2 = Object.Instantiate<GameObject>(val, MonsterDBPlugin._Root.transform, false); ((Object)val2).name = item.Name; if (!val2.TryGetComponent<ItemDrop>(ref val3)) { continue; } if (Enum.TryParse<AnimationState>(item.AnimationState, out AnimationState result)) { MonsterDBPlugin.MonsterDBLogger.LogWarning((object)("changed animation state to " + ((object)(AnimationState)(ref result)).ToString())); val3.m_itemData.m_shared.m_animationState = result; } if (!Utility.IsNullOrWhiteSpace(item.AttackAnimation)) { val3.m_itemData.m_shared.m_attack.m_attackAnimation = item.AttackAnimation; } val3.m_itemData.m_shared.m_attack.m_attackAngle = item.AttackAngle; val3.m_itemData.m_shared.m_attack.m_attackOriginJoint = item.AttackOrigin; val3.m_itemData.m_shared.m_attack.m_hitTerrain = item.HitTerrain; val3.m_itemData.m_shared.m_attack.m_hitFriendly = item.HitFriendly; val3.m_itemData.m_shared.m_aiAttackRange = item.AttackRange; val3.m_itemData.m_shared.m_aiAttackRangeMin = item.AttackRangeMinimum; val3.m_itemData.m_shared.m_aiAttackInterval = item.AttackInterval; val3.m_itemData.m_shared.m_aiAttackMaxAngle = item.AttackMaxAngle; val3.m_itemData.m_shared.m_damages = GetDamages(item.AttackDamages); val3.m_itemData.m_shared.m_toolTier = item.ToolTier; val3.m_itemData.m_shared.m_attackForce = item.AttackForce; val3.m_itemData.m_shared.m_dodgeable = item.Dodgeable; val3.m_itemData.m_shared.m_blockable = item.Blockable; val3.m_itemData.m_shared.m_spawnOnHit = MonsterDB.TryGetGameObject(item.SpawnOnHit); val3.m_itemData.m_shared.m_spawnOnHitTerrain = MonsterDB.TryGetGameObject(item.SpawnOnHitTerrain); if (!Utility.IsNullOrWhiteSpace(item.AttackStatusEffect)) { StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(StringExtensionMethods.GetStableHashCode(item.AttackStatusEffect)); if (Object.op_Implicit((Object)(object)statusEffect)) { val3.m_itemData.m_shared.m_attackStatusEffect = statusEffect; } } val3.m_itemData.m_shared.m_attack.m_hitThroughWalls = item.HitThroughWalls; if (item.CHANGE_ITEM_EFFECTS) { if (GetEffects(item.HitEffects, out var output2)) { val3.m_itemData.m_shared.m_attack.m_hitEffect = output2; } if (GetEffects(item.HitTerrainEffects, out var output3)) { val3.m_itemData.m_shared.m_attack.m_hitTerrainEffect = output3; } if (GetEffects(item.StartEffects, out var output4)) { val3.m_itemData.m_shared.m_attack.m_startEffect = output4; } if (GetEffects(item.TriggerEffects, out var output5)) { val3.m_itemData.m_shared.m_attack.m_triggerEffect = output5; } if (GetEffects(item.TrailStartEffects, out var output6)) { val3.m_itemData.m_shared.m_attack.m_trailStartEffect = output6; } if (GetEffects(item.BurstEffects, out var output7)) { val3.m_itemData.m_shared.m_attack.m_burstEffect = output7; } } if (item.CHANGE_PROJECTILE) { GameObject val4 = MonsterDB.TryGetGameObject(item.Projectile_PrefabName); if ((Object)(object)val4 != (Object)null && !Utility.IsNullOrWhiteSpace(item.Projectile_Clone_ID)) { GameObject val5 = MonsterDB.TryGetGameObject(item.Projectile_Clone_ID); if (!Object.op_Implicit((Object)(object)val5)) { val5 = Object.Instantiate<GameObject>(val4, MonsterDBPlugin._Root.transform, false); ((Object)val5).name = item.Projectile_Clone_ID; } if ((Object)(object)val5 != (Object)null && item.CHANGE_PROJECTILE_DATA && val5.TryGetComponent<Projectile>(ref val6)) { val6.m_damage = GetDamages(item.Projectile_Damages); val6.m_aoe = item.Projectile_AOE; val6.m_dodgeable = item.Projectile_Dodgeable; val6.m_blockable = item.Projectile_Blockable; val6.m_attackForce = item.Projectile_AttackForce; if (!Utility.IsNullOrWhiteSpace(item.Projectile_StatusEffect) && Object.op_Implicit((Object)(object)ObjectDB.instance.GetStatusEffect(StringExtensionMethods.GetStableHashCode(item.Projectile_StatusEffect)))) { val6.m_statusEffect = item.Projectile_StatusEffect; } val6.m_canHitWater = item.Projectile_CanHitWater; if (!Utility.IsNullOrWhiteSpace(item.Projectile_SpawnOnHit)) { GameObject val7 = MonsterDB.TryGetGameObject(item.Projectile_SpawnOnHit); if ((Object)(object)val7 != (Object)null) { val6.m_spawnOnHit = val7; } } val6.m_spawnOnHitChance = item.Projectile_SpawnChance; val6.m_randomSpawnOnHit = (from random in item.Projectile_RandomSpawnOnHit.Select(MonsterDB.TryGetGameObject) where (Object)(object)random != (Object)null select random).ToList(); val6.m_staticHitOnly = item.Projectile_StaticHitOnly; val6.m_groundHitOnly = item.Projectile_GroundHitOnly; if (item.PROJECTILE_CHANGE_EFFECTS) { if (GetEffects(item.Projectile_HitEffects, out var output8)) { val6.m_hitEffects = output8; } if (GetEffects(item.Projectile_HitWaterEffects, out var output9)) { val6.m_hitWaterEffects = output9; } if (GetEffects(item.Projectile_SpawnOnHitEffects, out var output10)) { val6.m_spawnOnHitEffects = output10; } } } if ((Object)(object)val5 != (Object)null) { RegisterToZNetScene(val5); val3.m_itemData.m_shared.m_attack.m_attackProjectile = val5; } } } output.Add(val2); } return true; } private static bool GetDamageMods(DamageModifiersData input, out DamageModifiers output) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0173: 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) output = default(DamageModifiers); if (!Enum.TryParse<DamageModifier>(input.Blunt, out DamageModifier result)) { return false; } if (!Enum.TryParse<DamageModifier>(input.Slash, out DamageModifier result2)) { return false; } if (!Enum.TryParse<DamageModifier>(input.Pierce, out DamageModifier result3)) { return false; } if (!Enum.TryParse<DamageModifier>(input.Chop, out DamageModifier result4)) { return false; } if (!Enum.TryParse<DamageModifier>(input.Pickaxe, out DamageModifier result5)) { return false; } if (!Enum.TryParse<DamageModifier>(input.Fire, out DamageModifier result6)) { return false; } if (!Enum.TryParse<DamageModifier>(input.Frost, out DamageModifier result7)) { return false; } if (!Enum.TryParse<DamageModifier>(input.Lightning, out DamageModifier result8)) { return false; } if (!Enum.TryParse<DamageModifier>(input.Poison, out DamageModifier result9)) { return false; } if (!Enum.TryParse<DamageModifier>(input.Spirit, out DamageModifier result10)) { return false; } output.m_blunt = result; output.m_slash = result2; output.m_pierce = result3; output.m_chop = result4; output.m_pickaxe = result5; output.m_fire = result6; output.m_frost = result7; output.m_lightning = result8; output.m_poison = result9; output.m_spirit = result10; return true; } private static bool GetEffects(List<EffectPrefab> input, out EffectList output) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_007c: 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_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: 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_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Expected O, but got Unknown output = new EffectList(); if (!Object.op_Implicit((Object)(object)ZNetScene.instance)) { return false; } List<EffectData> list = new List<EffectData>(); foreach (EffectPrefab item in input) { GameObject val = MonsterDB.TryGetGameObject(item.Prefab); if ((Object)(object)val == (Object)null) { MonsterDBPlugin.MonsterDBLogger.LogInfo((object)("Failed to find effect " + item.Prefab)); continue; } list.Add(new EffectData { m_prefab = val, m_enabled = item.Enabled, m_variant = item.Variant, m_attach = item.Attach, m_follow = item.Follow, m_inheritParentRotation = item.InheritParentRotation, m_inheritParentScale = item.InheritParentScale, m_randomRotation = item.RandomRotation, m_multiplyParentVisualScale = item.MultiplyParentVisualScale, m_scale = item.Scale }); } if (list.Count <= 0) { return false; } output.m_effectPrefabs = list.ToArray(); return true; } private static bool GetFaction(string input, out Faction output) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected I4, but got Unknown output = (Faction)8; if (!Enum.TryParse<Faction>(input, out Faction result)) { return false; } output = (Faction)(int)result; return true; } private static bool GetGroundTilt(string input, out Groun