Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Husky v1.1.1
Husky.dll
Decompiled 2 months ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.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.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Husky.Functions; using JetBrains.Annotations; using LocalizationManager; 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.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.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("blacks7ar")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.1.1")] [assembly: AssemblyInformationalVersion("1.0.0+f3154c4984230a173ddd08088b1cf18d72c5f8d9")] [assembly: AssemblyProduct("Husky")] [assembly: AssemblyTitle("Husky")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Husky { [BepInPlugin("blacks7ar.Husky", "Husky", "1.1.1")] public class Plugin : BaseUnityPlugin { private const string modGUID = "blacks7ar.Husky"; public const string modName = "Husky"; public const string modAuthor = "blacks7ar"; public const string modVersion = "1.1.1"; public const string modLink = "https://valheim.thunderstore.io/package/blacks7ar/Husky/"; private static readonly Harmony _harmony = new Harmony("blacks7ar.Husky"); private static readonly ConfigSync _configSync = new ConfigSync("blacks7ar.Husky") { DisplayName = "Husky", CurrentVersion = "1.1.1", MinimumRequiredVersion = "1.1.1", ModRequired = true }; private static ConfigEntry<Toggle> _serverConfigLocked; public static ConfigEntry<bool> _boneToyEnable; public static ConfigEntry<string> _boneToyMat; public static ConfigEntry<bool> _pillEnable; public static ConfigEntry<string> _pillMat1; public static ConfigEntry<string> _pillMat2; public static ConfigEntry<string> _pillMat3; public static ConfigEntry<bool> _giftEnable; public static ConfigEntry<string> _giftMat1; public static ConfigEntry<string> _giftMat2; public static ConfigEntry<string> _giftMat3; public static ConfigEntry<string> _giftMat4; public static ConfigEntry<bool> _hornEnable; public static ConfigEntry<string> _hornMat1; public static ConfigEntry<string> _hornMat2; public static ConfigEntry<string> _hornMat3; public static AssetBundle _huskyBundle; public static GameObject _husky; public static GameObject _boneToy; public static GameObject _odinsGift; public static GameObject _healingPill; public static GameObject _horn; public static GameObject _vfxHit; public static GameObject _vfxDeath; public static GameObject _vfxWaterSurface; public static GameObject _fxFootstepWater; private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description, bool synchronizedConfig = true) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown ConfigDescription val = new ConfigDescription(description.Description + (synchronizedConfig ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags); ConfigEntry<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val); _configSync.AddConfigEntry<T>(val2).SynchronizedConfig = synchronizedConfig; return val2; } public void Awake() { //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Expected O, but got Unknown //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Expected O, but got Unknown //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Expected O, but got Unknown //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Expected O, but got Unknown //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Expected O, but got Unknown //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Expected O, but got Unknown //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Expected O, but got Unknown //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Expected O, but got Unknown //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Expected O, but got Unknown //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Expected O, but got Unknown //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Expected O, but got Unknown ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; Localizer.Load(); _huskyBundle = GetAssetBundleFromResources("huskybundle"); _husky = _huskyBundle.LoadAsset<GameObject>("BHP_Husky"); ShaderReplacer.Replace(_husky); _boneToy = _huskyBundle.LoadAsset<GameObject>("BHP_BoneToy"); _odinsGift = _huskyBundle.LoadAsset<GameObject>("BHP_OdinsGift"); _healingPill = _huskyBundle.LoadAsset<GameObject>("BHP_HealingPill"); _horn = _huskyBundle.LoadAsset<GameObject>("BHP_Horn"); _vfxHit = _huskyBundle.LoadAsset<GameObject>("bhp_vfx_wolf_hit"); ShaderReplacer.Replace(_vfxHit); _vfxDeath = _huskyBundle.LoadAsset<GameObject>("bhp_vfx_wolf_death"); ShaderReplacer.Replace(_vfxDeath); _vfxWaterSurface = _huskyBundle.LoadAsset<GameObject>("bhp_vfx_water_surface"); ShaderReplacer.Replace(_vfxWaterSurface); _fxFootstepWater = _huskyBundle.LoadAsset<GameObject>("bhp_fx_footstep_water"); ShaderReplacer.Replace(_fxFootstepWater); _serverConfigLocked = config("1- ServerSync", "Lock Configuration", Toggle.On, new ConfigDescription("If On, the configuration is locked and can be changed by server admins only.", (AcceptableValueBase)null, Array.Empty<object>())); _configSync.AddLockingConfigEntry<Toggle>(_serverConfigLocked); string group = "BoneToy"; _boneToyEnable = config(group, "Recipe", value: true, new ConfigDescription("Enable/Disables recipe. (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); _boneToyMat = config(group, "Required Material", "BoneFragments:4:2", new ConfigDescription("Item name : amount : amount per level (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); string group2 = "OdinsGift"; _giftEnable = config(group2, "Recipe", value: true, new ConfigDescription("Enable/Disables recipe. (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); _giftMat1 = config(group2, "Required Material 1", "Coins:100", new ConfigDescription("Item name : amount (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); _giftMat2 = config(group2, "Required Material 2", "Amber:2", new ConfigDescription("Item name : amount (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); _giftMat3 = config(group2, "Required Material 3", "AmberPearl:2", new ConfigDescription("Item name : amount (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); _giftMat4 = config(group2, "Required Material 4", "Ruby:2", new ConfigDescription("Item name : amount (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); string group3 = "GoldenHorn"; _hornEnable = config(group3, "Recipe", value: true, new ConfigDescription("Enable/Disables recipe. (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); _hornMat1 = config(group3, "Required Material 1", "Bronze:4:1", new ConfigDescription("Item name : amount : amount per level (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); _hornMat2 = config(group3, "Required Material 2", "Flint:3:1", new ConfigDescription("Item name : amount : amount per level (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); _hornMat3 = config(group3, "Required Material 3", "SurtlingCore:1:0", new ConfigDescription("Item name : amount : amount per level (Needs Logout)", (AcceptableValueBase)null, Array.Empty<object>())); Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony.PatchAll(executingAssembly); ((BaseUnityPlugin)this).Config.SaveOnConfigSet = true; ((BaseUnityPlugin)this).Config.Save(); } private void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } private static AssetBundle GetAssetBundleFromResources(string filename) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string name = Enumerable.Single(executingAssembly.GetManifestResourceNames(), (string x) => x.EndsWith(filename)); using Stream stream = executingAssembly.GetManifestResourceStream(name); return AssetBundle.LoadFromStream(stream); } public static void NewTame(GameObject pet) { if (!Object.op_Implicit((Object)(object)pet.GetComponent<FetchAI>())) { ((Behaviour)pet.GetComponent<MonsterAI>()).enabled = false; pet.AddComponent<FetchAI>(); } if (!Object.op_Implicit((Object)(object)pet.GetComponent<AlertedFixed>())) { pet.AddComponent<AlertedFixed>(); } } } } namespace Husky.Patches { [HarmonyPatch(typeof(Humanoid), "UseItem")] public class HumanoidPatch { public static bool Prefix(Humanoid __instance, Inventory inventory, ItemData item, bool fromInventoryGui) { //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: 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_00c0: Invalid comparison between Unknown and I4 //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) if (inventory == null) { inventory = __instance.m_inventory; } if (!inventory.ContainsItem(item)) { return true; } GameObject hoverObject = __instance.GetHoverObject(); if ((Object.op_Implicit((Object)(object)hoverObject) ? hoverObject.GetComponentInParent<Hoverable>() : null) != null && !fromInventoryGui) { MonsterAI component = hoverObject.GetComponent<MonsterAI>(); if ((Object)(object)component != (Object)null && ((Object)((Component)component).gameObject).name.Replace("(Clone)", "") == "BHP_Husky" && component.CanConsume(item)) { Tameable component2 = hoverObject.GetComponent<Tameable>(); string text = ((((component2 != null) ? component2.GetText() : null) == "") ? component2.m_character.m_name : component2.GetText()); if ((int)item.m_shared.m_itemType == 2) { if ((Object)(object)component2 != (Object)null && component2.IsHungry()) { __instance.DoInteractAnimation(hoverObject); component.m_onConsumedItem(item.m_dropPrefab.GetComponent<ItemDrop>()); Humanoid component3 = hoverObject.GetComponent<Humanoid>(); component3.m_consumeItemEffects.Create(((Component)component3).transform.position, Quaternion.identity, (Transform)null, 1f, -1); hoverObject.GetComponentInChildren<Animator>().SetTrigger("consume"); inventory.RemoveOneItem(item); ((Character)__instance).Message((MessageType)2, text + " is very happy.", 0, (Sprite)null); return false; } if (!component2.IsHungry()) { ((Character)__instance).Message((MessageType)2, text + " is not yet hungry.", 0, (Sprite)null); return false; } return false; } } } if (!fromInventoryGui) { return true; } if (!item.m_shared.m_name.ToLower().Contains("odinsgift")) { return true; } Object.Instantiate<GameObject>(Plugin._husky, ((Component)__instance).transform.position + ((Component)__instance).transform.forward + ((Component)__instance).transform.forward, Quaternion.identity); Object.Instantiate<GameObject>(ZNetScene.instance.GetPrefab("bhp_fx_wolf_pet"), ((Component)__instance).transform.position, Quaternion.identity); inventory.RemoveOneItem(item); ((Character)__instance).Message((MessageType)2, "You unwrapped the gift and a big healthy dog jumps out.", 0, (Sprite)null); return false; } } [HarmonyPatch] public class ObjectDBPatch { [HarmonyPriority(700)] [HarmonyPostfix] [HarmonyPatch(typeof(ObjectDB), "Awake")] public static void Awake_Postfix(ObjectDB __instance) { RegisterPrefab.ToObjectDB(); RegisterPrefab.Recipes(); __instance.UpdateRegisters(); } [HarmonyPriority(700)] [HarmonyPostfix] [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] public static void CopyOtherDB_Postfix(ObjectDB __instance) { RegisterPrefab.ToObjectDB(); RegisterPrefab.Recipes(); __instance.UpdateRegisters(); } } [HarmonyPatch(typeof(ZNetScene), "Awake")] public class ZNetScenePatch { public static void Postfix(ZNetScene __instance) { RegisterPrefab.ToZNetScene(); } } } namespace Husky.Functions { public class AlertedFixed : MonoBehaviour { private MonsterAI m_monsterAI; public void OnEnable() { m_monsterAI = ((Component)this).GetComponent<MonsterAI>(); } public void FixedUpdate() { Character val = ((BaseAI)m_monsterAI).FindEnemy(); if (Object.op_Implicit((Object)(object)val) && ((BaseAI)m_monsterAI).CanSenseTarget(val)) { ((BaseAI)m_monsterAI).Alert(); } } } public class FetchAI : MonoBehaviour { public enum AIStates { BaseAI, Idle, GettingToy, ReturningToy, Wait, DropToy } [CompilerGenerated] private sealed class <PickupToy>d__26 : IEnumerator<object>, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public FetchAI <>4__this; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <PickupToy>d__26(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Expected O, but got Unknown //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0139: 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_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Expected O, but got Unknown int num = <>1__state; FetchAI fetchAI = <>4__this; switch (num) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForSeconds(0.48f); <>1__state = 1; return true; case 1: { <>1__state = -1; if (!fetchAI.ValidToyToGet || ((BaseAI)fetchAI.m_monsterAI).IsAlerted()) { fetchAI.m_animator.CrossFadeInFixedTime("New State 0", 0.4f, 0); fetchAI.m_AiState = AIStates.Idle; fetchAI.m_stateTime = 0f; return false; } Traverse.Create((object)((Component)fetchAI.m_targetToy).GetComponent<ZSyncTransform>()).Field("m_useGravity").SetValue((object)false); fetchAI.m_targetToy.collisionDetectionMode = (CollisionDetectionMode)3; fetchAI.m_targetToy.isKinematic = true; ((Component)fetchAI.m_targetToy).GetComponent<ItemDrop>().m_autoPickup = false; Transform val = Utils.FindChild(((Component)fetchAI).transform, "Bip01 Head", (IterativeSearchType)0); Vector3 val2 = ((Component)fetchAI.m_targetToy).transform.rotation * fetchAI.m_ToyOffset; ((Component)fetchAI.m_targetToy).transform.SetParent(val, true); ((Component)fetchAI.m_targetToy).transform.position = val.position + val2 + val.rotation * fetchAI.m_mouthOffset; fetchAI.m_hasToy = true; ((Renderer)((Component)fetchAI.m_targetToy).gameObject.GetComponentInChildren<MeshRenderer>()).enabled = false; <>2__current = (object)new WaitForSeconds(0.22f); <>1__state = 2; return true; } case 2: <>1__state = -1; fetchAI.m_animator.CrossFadeInFixedTime("New State 7", 0.6f, 0); <>2__current = (object)new WaitForSeconds(Random.Range(0.2f, 1.5f)); <>1__state = 3; return true; case 3: <>1__state = -1; fetchAI.m_AiState = AIStates.ReturningToy; fetchAI.m_stateTime = 10f; return false; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static readonly List<FetchAI> _fetchAiList = new List<FetchAI>(); public AIStates m_AiState; public Animator m_animator; public MonsterAI m_monsterAI; public float m_updateTimer; public float m_distanceFromPlayer = 2.25f; public float m_distanceFromToy = 1f; public bool m_pausing; public Rigidbody m_targetToy; public float m_stateTime; public bool m_hasToy; private readonly Vector3 m_ToyOffset = new Vector3(0f, 0f, 0f); private readonly Vector3 m_mouthOffset = new Vector3(0.18f, 0.56f, 0f); private bool ValidToyToGet { get { if ((Object)(object)m_targetToy != (Object)null) { return m_targetToy.useGravity; } return false; } } private bool ValidToy { get { if ((Object)(object)m_targetToy != (Object)null) { return !m_targetToy.useGravity; } return false; } } public void Awake() { m_monsterAI = ((Component)this).GetComponent<MonsterAI>(); _fetchAiList.Add(this); m_animator = ((Component)this).GetComponentInChildren<Animator>(); } public void Start() { m_monsterAI.Start(); } private void OnDestroy() { _fetchAiList.Remove(this); } private Rigidbody GetToy(float range) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) m_targetToy = FetchSystem.FindToy(((Component)this).transform.position, range); if (Object.op_Implicit((Object)(object)m_targetToy)) { return m_targetToy; } return null; } public void GetToy(ItemDrop toy) { m_targetToy = ((Component)toy).GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)m_targetToy)) { m_AiState = AIStates.GettingToy; m_stateTime = 10f; } } public void FixedUpdate() { try { if (((BaseAI)m_monsterAI).m_nview.IsValid()) { m_updateTimer += Time.fixedDeltaTime; if (!(m_updateTimer < 0.05f)) { UpdateAI(0.05f); m_updateTimer -= 0.05f; } } } catch { } } public void UpdateAI(float dt) { //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_013f: 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) m_stateTime -= dt; if (((BaseAI)m_monsterAI).IsAlerted()) { m_stateTime = 3f; m_AiState = AIStates.BaseAI; DropToy(); } if (m_stateTime <= 0f && m_pausing) { m_pausing = false; } else if (m_stateTime <= 0f && m_AiState != 0) { NewAction(); } else if (m_pausing) { return; } switch (m_AiState) { case AIStates.BaseAI: ((BaseAI)m_monsterAI).UpdateAI(dt); if (m_stateTime <= 0f) { if (((BaseAI)m_monsterAI).m_randomMoveUpdateTimer <= 0f) { NewAction(); } else { m_stateTime = 3f; } } break; case AIStates.GettingToy: { if (!ValidToyToGet) { m_stateTime = 0f; break; } Vector3 position = ((Component)m_targetToy).transform.position; if (((BaseAI)m_monsterAI).MoveTo(dt, position, m_distanceFromToy, true) && Utils.DistanceXZ(((Component)this).transform.position, position) <= m_distanceFromToy) { ((BaseAI)m_monsterAI).LookAt(position); if (((BaseAI)m_monsterAI).IsLookingAt(position, 20f, false) && ValidToyToGet) { m_animator.Play("consume"); ((MonoBehaviour)this).StartCoroutine(PickupToy()); m_AiState = AIStates.Wait; m_stateTime = 5f; } } break; } case AIStates.ReturningToy: { if (!ValidToy) { m_hasToy = false; m_stateTime = 0f; break; } Transform transform = ((Component)Player.m_localPlayer).transform; if (((BaseAI)m_monsterAI).MoveTo(dt, transform.position + transform.forward * m_distanceFromPlayer, 0f, true)) { ((BaseAI)m_monsterAI).LookAt(transform.position); if (((BaseAI)m_monsterAI).IsLookingAt(transform.position, 15f, false)) { m_pausing = true; m_AiState = AIStates.DropToy; m_stateTime = Random.Range(0.4f, 1.3f); } } break; } case AIStates.DropToy: DropToy(); m_AiState = AIStates.Wait; m_stateTime = Random.Range(2f, 4f); break; case AIStates.Idle: case AIStates.Wait: ((BaseAI)m_monsterAI).UpdateAI(dt); break; } } private void DropToy() { if (m_hasToy) { m_hasToy = false; if (ValidToy) { ((Renderer)((Component)m_targetToy).gameObject.GetComponentInChildren<MeshRenderer>()).enabled = true; m_targetToy.isKinematic = false; m_targetToy.collisionDetectionMode = (CollisionDetectionMode)1; Traverse.Create((object)((Component)m_targetToy).GetComponent<ZSyncTransform>()).Field("m_useGravity").SetValue((object)true); ((Component)m_targetToy).transform.SetParent((Transform)null, true); } } } [IteratorStateMachine(typeof(<PickupToy>d__26))] private IEnumerator PickupToy() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <PickupToy>d__26(0) { <>4__this = this }; } private void NewAction() { //IL_0017: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) if (Random.Range(0, 3) == 0) { if (!m_hasToy) { Vector3 val = ((Component)this).transform.position - ((Component)Player.m_localPlayer).transform.position; if (((Vector3)(ref val)).sqrMagnitude <= 64f && !((Object)(object)GetToy(64f) == (Object)null)) { m_AiState = AIStates.GettingToy; m_stateTime = 10f; } } } else { m_AiState = AIStates.BaseAI; m_stateTime = Random.Range(2f, 4f); } } } [HarmonyPatch] public class FetchSystem { private static readonly Collider[] _sphereResults = (Collider[])(object)new Collider[32]; private static ItemDrop _lastDroppedItem; [HarmonyPostfix] [HarmonyPatch(typeof(ItemDrop), "OnPlayerDrop")] public static void OnPlayerDrop_Postfix(ItemDrop __instance) { _lastDroppedItem = __instance; } [HarmonyPostfix] [HarmonyPatch(typeof(ItemDrop), "DropItem")] public static void DropItem_Postfix(ItemDrop __result) { _lastDroppedItem = __result; } [HarmonyPostfix] [HarmonyPatch(typeof(Projectile), "SpawnOnHit")] public static void SpawnOnHit_Postfix(Projectile __instance, ref ItemData ___m_spawnItem) { if (__instance.m_spawnItem == null || !__instance.m_respawnItemOnHit || !Object.op_Implicit((Object)(object)_lastDroppedItem) || ___m_spawnItem.m_shared.m_name != "$bhp_bonetoy") { return; } foreach (FetchAI item in Enumerable.Select(Enumerable.Where(Enumerable.Select(Enumerable.Where(FetchAI._fetchAiList, delegate(FetchAI pet) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)pet).gameObject.transform.position - ((Component)Player.m_localPlayer).transform.position; return !(((Vector3)(ref val)).sqrMagnitude > 100f); }), (FetchAI pet) => new { pet = pet, component = ((Component)pet).GetComponent<Character>() }), <>h__TransparentIdentifier0 => Object.op_Implicit((Object)(object)<>h__TransparentIdentifier0.component) && <>h__TransparentIdentifier0.component.IsTamed() && !Object.op_Implicit((Object)(object)((Component)<>h__TransparentIdentifier0.pet).GetComponent<Growup>()) && !((BaseAI)<>h__TransparentIdentifier0.pet.m_monsterAI).IsAlerted() && <>h__TransparentIdentifier0.pet.m_AiState == FetchAI.AIStates.BaseAI), <>h__TransparentIdentifier0 => <>h__TransparentIdentifier0.pet)) { item.GetToy(_lastDroppedItem); } } [HarmonyPostfix] [HarmonyPatch(typeof(Humanoid), "DropItem")] public static void DropItem_Postfix(Inventory inventory, ItemData item, int amount, Humanoid __instance, bool __result) { if (!__result || !((Character)__instance).IsPlayer() || !Object.op_Implicit((Object)(object)_lastDroppedItem) || item.m_shared.m_name != "$bhp_bonetoy") { return; } foreach (FetchAI item2 in Enumerable.Select(Enumerable.Where(Enumerable.Select(Enumerable.Where(FetchAI._fetchAiList, delegate(FetchAI pet) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)pet).gameObject.transform.position - ((Component)Player.m_localPlayer).transform.position; return !(((Vector3)(ref val)).sqrMagnitude > 100f); }), (FetchAI pet) => new { pet = pet, component = ((Component)pet).GetComponent<Character>() }), <>h__TransparentIdentifier0 => Object.op_Implicit((Object)(object)<>h__TransparentIdentifier0.component) && <>h__TransparentIdentifier0.component.IsTamed() && !Object.op_Implicit((Object)(object)((Component)<>h__TransparentIdentifier0.pet).GetComponent<Growup>()) && !((BaseAI)<>h__TransparentIdentifier0.pet.m_monsterAI).IsAlerted() && <>h__TransparentIdentifier0.pet.m_AiState == FetchAI.AIStates.BaseAI), <>h__TransparentIdentifier0 => <>h__TransparentIdentifier0.pet)) { item2.GetToy(_lastDroppedItem); } } [HarmonyPostfix] [HarmonyPatch(typeof(MonsterAI), "MakeTame")] public static void MakeTame_Postfix(MonsterAI __instance) { if (!(((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "") != "BHP_Husky")) { Character component = ((Component)__instance).GetComponent<Character>(); if (component != null && component.IsTamed()) { Plugin.NewTame(((Component)__instance).gameObject); } } } [HarmonyPostfix] [HarmonyPatch(typeof(Procreation), "Awake")] public static void Awake_Postfix(Procreation __instance) { if (!(((Object)((Component)__instance).gameObject).name.Replace("(Clone)", "") != "BHP_Husky")) { Character component = ((Component)__instance).GetComponent<Character>(); if (component != null && component.IsTamed()) { Plugin.NewTame(((Component)__instance).gameObject); } } } [HarmonyPostfix] [HarmonyPatch(typeof(Character), "Awake")] public static void Awake_Prefix(Character __instance) { if (!((Object)(object)__instance == (Object)null) && !__instance.IsPlayer() && !__instance.IsBoss() && __instance.m_nview.IsValid() && __instance.IsTamed() && !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<Growup>()) && !(((Object)__instance).name.Replace("(Clone)", "") != "BHP_Husky")) { Plugin.NewTame(((Component)__instance).gameObject); } } public static Rigidbody FindToy(Vector3 pos, float range) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) int num = Physics.OverlapSphereNonAlloc(pos, range, _sphereResults, LayerMask.GetMask(new string[1] { "item" })); Rigidbody result = null; float num2 = 999999f; for (int i = 0; i < num; i++) { Collider val = _sphereResults[i]; if (!Object.op_Implicit((Object)(object)val.attachedRigidbody)) { continue; } ItemDrop component = ((Component)val.attachedRigidbody).GetComponent<ItemDrop>(); if ((Object)(object)component == (Object)null || !((Component)component).GetComponent<ZNetView>().IsValid() || component.m_itemData.m_shared.m_name != "$bhp_bonetoy") { continue; } Rigidbody component2 = ((Component)component).GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)component2) && component2.useGravity) { Vector3 val2 = ((Component)component).transform.position - pos; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; if (sqrMagnitude < num2) { result = component2; num2 = sqrMagnitude; } } } return result; } } public static class Helper { public static void AddClonedObject(this ZNetScene zNetScene, GameObject gameObject, bool overWrite = true) { GameObject prefab; if ((Object)(object)(prefab = zNetScene.GetPrefab(((Object)gameObject).name)) != (Object)null) { if (!overWrite) { return; } zNetScene.m_prefabs.Remove(prefab); zNetScene.m_namedPrefabs.Remove(StringExtensionMethods.GetStableHashCode(((Object)gameObject).name)); } zNetScene.m_prefabs.Add(gameObject); zNetScene.m_namedPrefabs.Add(StringExtensionMethods.GetStableHashCode(((Object)gameObject).name), gameObject); } public static void AddClonedObject(this ObjectDB objectDB, GameObject gameObject, bool overWrite = true) { GameObject itemPrefab; if ((Object)(object)(itemPrefab = objectDB.GetItemPrefab(((Object)gameObject).name)) != (Object)null) { if (!overWrite) { return; } objectDB.m_items.Remove(itemPrefab); objectDB.m_itemByHash.Remove(StringExtensionMethods.GetStableHashCode(((Object)gameObject).name)); } objectDB.m_items.Add(gameObject); objectDB.m_itemByHash.Add(StringExtensionMethods.GetStableHashCode(((Object)gameObject).name), gameObject); } public static void AddRecipe(this ObjectDB objectDB, Recipe recipe, bool overWrite = true) { if (objectDB.m_recipes.Contains(recipe)) { if (!overWrite) { return; } objectDB.m_recipes.Remove(recipe); } objectDB.m_recipes.Add(recipe); } public static bool ObjectDBAwake() { if ((Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_items.Count != 0) { return (Object)(object)ObjectDB.instance.GetItemPrefab("Wood") != (Object)null; } return false; } public static bool ZNetSceneAwake() { if ((Object)(object)ZNetScene.instance != (Object)null && ZNetScene.instance.m_prefabs.Count != 0) { return (Object)(object)ZNetScene.instance.GetPrefab("piece_workbench") != (Object)null; } return false; } } public class Recall : StatusEffect { public float m_maxDistance = 100f; public List<Character> m_companions = new List<Character>(); private readonly float[] _offSets = new float[6] { -80f, 80f, -60f, 60f, -30f, 30f }; public override void Setup(Character character) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) ((StatusEffect)this).Setup(character); m_companions.Clear(); List<Character> list = new List<Character>(); Character.GetCharactersInRange(((Component)character).transform.position, m_maxDistance, list); int num = 0; foreach (Character item in Enumerable.Where(list, (Character pet) => pet.IsTamed() && ((Object)pet).name.Replace("(Clone)", "") == "BHP_Husky")) { num++; MonsterAI component = ((Component)item).GetComponent<MonsterAI>(); if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.GetFollowTarget()) && (Object)(object)component.GetFollowTarget() == (Object)(object)((Component)character).gameObject) { m_companions.Add(item); } } } public override void UpdateStatusEffect(float dt) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) ((StatusEffect)this).UpdateStatusEffect(dt); int num = 0; foreach (Character companion in m_companions) { Vector3 val = Quaternion.AngleAxis(_offSets[num], Vector3.up) * ((Component)companion).transform.forward * 0.75f; Vector3 val2 = ((Component)base.m_character).transform.rotation * Vector3.forward; ((Component)companion).transform.position = ((Component)base.m_character).transform.position + val; ((Component)companion).transform.rotation = ((Component)base.m_character).transform.rotation; companion.SetLookDir(val2, 0f); num++; } } } public static class RegisterPrefab { private static ZNetScene _zNetScene => ZNetScene.instance; private static ObjectDB _objectDB => ObjectDB.instance; public static void ToZNetScene() { if (Helper.ZNetSceneAwake()) { _zNetScene.AddClonedObject(Plugin._husky); Plugin.NewTame(Plugin._husky); Plugin._husky.GetComponent<MonsterAI>().m_consumeItems = new List<ItemDrop>(7) { _zNetScene.GetPrefab("CookedDeerMeat").GetComponent<ItemDrop>(), _zNetScene.GetPrefab("CookedMeat").GetComponent<ItemDrop>(), _zNetScene.GetPrefab("CookedBugMeat").GetComponent<ItemDrop>(), _zNetScene.GetPrefab("CookedChickenMeat").GetComponent<ItemDrop>(), _zNetScene.GetPrefab("CookedHareMeat").GetComponent<ItemDrop>(), _zNetScene.GetPrefab("CookedLoxMeat").GetComponent<ItemDrop>(), _zNetScene.GetPrefab("CookedWolfMeat").GetComponent<ItemDrop>() }; _zNetScene.AddClonedObject(Plugin._boneToy); _zNetScene.AddClonedObject(Plugin._horn); _zNetScene.AddClonedObject(Plugin._odinsGift); _zNetScene.AddClonedObject(Plugin._vfxHit); _zNetScene.AddClonedObject(Plugin._vfxDeath); _zNetScene.AddClonedObject(Plugin._vfxWaterSurface); _zNetScene.AddClonedObject(Plugin._fxFootstepWater); GameObject gameObject = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_bone_projectile"); _zNetScene.AddClonedObject(gameObject); GameObject gameObject2 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_fx_backstab"); _zNetScene.AddClonedObject(gameObject2); GameObject gameObject3 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_fx_creature_tamed"); _zNetScene.AddClonedObject(gameObject3); GameObject gameObject4 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_fx_crit"); _zNetScene.AddClonedObject(gameObject4); GameObject gameObject5 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_fx_footstep_jog"); _zNetScene.AddClonedObject(gameObject5); GameObject gameObject6 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_fx_wolf_pet"); _zNetScene.AddClonedObject(gameObject6); GameObject gameObject7 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_sfx_creature_consume"); _zNetScene.AddClonedObject(gameObject7); GameObject gameObject8 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_sfx_footstep_swim"); _zNetScene.AddClonedObject(gameObject8); GameObject gameObject9 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_sfx_wolf_alerted"); _zNetScene.AddClonedObject(gameObject9); GameObject gameObject10 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_sfx_wolf_hit"); _zNetScene.AddClonedObject(gameObject10); GameObject gameObject11 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_vfx_corpse_destruction_small"); _zNetScene.AddClonedObject(gameObject11); GameObject gameObject12 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_vfx_creature_soothed"); _zNetScene.AddClonedObject(gameObject12); GameObject gameObject13 = Plugin._huskyBundle.LoadAsset<GameObject>("BHP_HuskyRagdoll"); _zNetScene.AddClonedObject(gameObject13); GameObject gameObject14 = Plugin._huskyBundle.LoadAsset<GameObject>("bhp_sfx_warhorn"); _zNetScene.AddClonedObject(gameObject14); } } public static void ToObjectDB() { if (Helper.ObjectDBAwake()) { _objectDB.AddClonedObject(Plugin._boneToy); _objectDB.AddClonedObject(Plugin._odinsGift); _objectDB.AddClonedObject(Plugin._horn); SharedData shared = Plugin._horn.GetComponent<ItemDrop>().m_itemData.m_shared; Recall recall = ScriptableObject.CreateInstance<Recall>(); ((StatusEffect)recall).m_ttl = 0.25f; shared.m_consumeStatusEffect = (StatusEffect)(object)recall; RegisterStatusEffects(shared.m_consumeStatusEffect); } } public static void Recipes() { if (Helper.ObjectDBAwake() && Helper.ZNetSceneAwake()) { BoneToy(); OdinsGift(); VikingHorn(); } } private static void BoneToy() { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Expected O, but got Unknown Recipe val = ScriptableObject.CreateInstance<Recipe>(); ((Object)val).name = "Recipe_BoneToy"; val.m_item = Plugin._boneToy.GetComponent<ItemDrop>(); val.m_amount = 1; val.m_enabled = Plugin._boneToyEnable.Value; val.m_qualityResultAmountMultiplier = 1f; val.m_craftingStation = _zNetScene.GetPrefab("piece_workbench").GetComponent<CraftingStation>(); val.m_repairStation = val.m_craftingStation; val.m_minStationLevel = 1; val.m_requireOnlyOneIngredient = false; string[] array = Plugin._boneToyMat.Value.Split(':', ' '); val.m_resources = (Requirement[])(object)new Requirement[1] { new Requirement { m_resItem = _objectDB.GetItemPrefab(array[0]).GetComponent<ItemDrop>(), m_amount = int.Parse(array[1]), m_extraAmountOnlyOneIngredient = 0, m_amountPerLevel = int.Parse(array[2]), m_recover = true } }; _objectDB.AddRecipe(val); } private static void OdinsGift() { //IL_0101: 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) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Expected O, but got Unknown //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Expected O, but got Unknown //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Expected O, but got Unknown //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Expected O, but got Unknown Recipe val = ScriptableObject.CreateInstance<Recipe>(); ((Object)val).name = "Recipe_OdinsGift"; val.m_item = Plugin._odinsGift.GetComponent<ItemDrop>(); val.m_amount = 1; val.m_enabled = Plugin._giftEnable.Value; val.m_qualityResultAmountMultiplier = 1f; val.m_craftingStation = _zNetScene.GetPrefab("piece_workbench").GetComponent<CraftingStation>(); val.m_repairStation = val.m_craftingStation; val.m_minStationLevel = 1; val.m_requireOnlyOneIngredient = false; string[] array = Plugin._giftMat1.Value.Split(':', ' '); string[] array2 = Plugin._giftMat2.Value.Split(':', ' '); string[] array3 = Plugin._giftMat3.Value.Split(':', ' '); string[] array4 = Plugin._giftMat4.Value.Split(':', ' '); val.m_resources = (Requirement[])(object)new Requirement[4] { new Requirement { m_resItem = _objectDB.GetItemPrefab(array[0]).GetComponent<ItemDrop>(), m_amount = int.Parse(array[1]), m_extraAmountOnlyOneIngredient = 0, m_amountPerLevel = 0, m_recover = true }, new Requirement { m_resItem = _objectDB.GetItemPrefab(array2[0]).GetComponent<ItemDrop>(), m_amount = int.Parse(array2[1]), m_extraAmountOnlyOneIngredient = 0, m_amountPerLevel = 0, m_recover = true }, new Requirement { m_resItem = _objectDB.GetItemPrefab(array3[0]).GetComponent<ItemDrop>(), m_amount = int.Parse(array3[1]), m_extraAmountOnlyOneIngredient = 0, m_amountPerLevel = 0, m_recover = true }, new Requirement { m_resItem = _objectDB.GetItemPrefab(array4[0]).GetComponent<ItemDrop>(), m_amount = int.Parse(array4[1]), m_extraAmountOnlyOneIngredient = 0, m_amountPerLevel = 0, m_recover = true } }; _objectDB.AddRecipe(val); } private static void VikingHorn() { //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown //IL_012a: 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_0147: 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_015c: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Expected O, but got Unknown Recipe val = ScriptableObject.CreateInstance<Recipe>(); ((Object)val).name = "Recipe_BHP_GoldenHorn"; val.m_item = Plugin._horn.GetComponent<ItemDrop>(); val.m_amount = 1; val.m_enabled = Plugin._hornEnable.Value; val.m_qualityResultAmountMultiplier = 1f; val.m_craftingStation = _zNetScene.GetPrefab("piece_workbench").GetComponent<CraftingStation>(); val.m_repairStation = val.m_craftingStation; val.m_minStationLevel = 1; val.m_requireOnlyOneIngredient = false; string[] array = Plugin._hornMat1.Value.Split(':', ' '); string[] array2 = Plugin._hornMat2.Value.Split(':', ' '); string[] array3 = Plugin._hornMat3.Value.Split(':', ' '); val.m_resources = (Requirement[])(object)new Requirement[3] { new Requirement { m_resItem = _objectDB.GetItemPrefab(array[0]).GetComponent<ItemDrop>(), m_amount = int.Parse(array[1]), m_extraAmountOnlyOneIngredient = 0, m_amountPerLevel = int.Parse(array[2]), m_recover = true }, new Requirement { m_resItem = _objectDB.GetItemPrefab(array2[0]).GetComponent<ItemDrop>(), m_amount = int.Parse(array2[1]), m_extraAmountOnlyOneIngredient = 0, m_amountPerLevel = int.Parse(array2[2]), m_recover = true }, new Requirement { m_resItem = _objectDB.GetItemPrefab(array3[0]).GetComponent<ItemDrop>(), m_amount = int.Parse(array3[1]), m_extraAmountOnlyOneIngredient = 0, m_amountPerLevel = int.Parse(array3[2]), m_recover = true } }; _objectDB.AddRecipe(val); } private static void RegisterStatusEffects(StatusEffect statusEffect) { if (statusEffect != null && !Object.op_Implicit((Object)(object)_objectDB.GetStatusEffect(StringExtensionMethods.GetStableHashCode(((Object)statusEffect).name)))) { _objectDB.m_StatusEffects.Add(statusEffect); } } } public static class ShaderReplacer { private static readonly List<GameObject> GOToSwap; static ShaderReplacer() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown GOToSwap = new List<GameObject>(); new Harmony("blacks7ar.utilities.ShaderReplacer").Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(ShaderReplacer), "ReplaceShaderPatch", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } public static void Replace(GameObject gameObject) { GOToSwap.Add(gameObject); } [HarmonyPriority(700)] private static void ReplaceShaderPatch() { foreach (Material item in Enumerable.Select(Enumerable.Where(Enumerable.SelectMany(Enumerable.Where(Enumerable.SelectMany(Enumerable.Select(GOToSwap, (GameObject gameObject) => gameObject.GetComponentsInChildren<Renderer>(true)), (Renderer[] renderers) => renderers, (Renderer[] renderers, Renderer renderer) => new { renderers, renderer }), <>h__TransparentIdentifier0 => (Object)(object)<>h__TransparentIdentifier0.renderer != (Object)null), <>h__TransparentIdentifier0 => <>h__TransparentIdentifier0.renderer.sharedMaterials, (<>h__TransparentIdentifier0, Material material) => new { <>h__TransparentIdentifier0, material }), <>h__TransparentIdentifier1 => (Object)(object)<>h__TransparentIdentifier1.material != (Object)null), <>h__TransparentIdentifier1 => <>h__TransparentIdentifier1.material)) { Shader[] array = Resources.FindObjectsOfTypeAll<Shader>(); foreach (Shader val in array) { if (((Object)item.shader).name == ((Object)val).name) { item.shader = val; } } } } } public enum Toggle { On = 1, Off = 0 } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace ServerSync { [PublicAPI] internal abstract class OwnConfigEntryBase { public object? LocalBaseValue; public bool SynchronizedConfig = true; public abstract ConfigEntryBase BaseConfig { get; } } [PublicAPI] internal class SyncedConfigEntry<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; base..ctor(); } public void AssignLocalValue(T value) { if (LocalBaseValue == null) { Value = value; } else { LocalBaseValue = value; } } } internal abstract class CustomSyncedValueBase { public object? LocalBaseValue; public readonly string Identifier; 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; 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; }; } } [PublicAPI] internal sealed class CustomSyncedValue<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] internal class ConfigSync { [HarmonyPatch(typeof(ZRpc), "HandlePackage")] private static class SnatchCurrentlyHandlingRPC { public static ZRpc? currentRpc; [HarmonyPrefix] private static void Prefix(ZRpc __instance) { currentRpc = __instance; } } [HarmonyPatch(typeof(ZNet), "Awake")] internal static class RegisterRPCPatch { [HarmonyPostfix] 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()); } 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 = Enumerable.First(configSyncs); if (configSync != null) { ((MonoBehaviour)ZNet.instance).StartCoroutine(configSync.sendZPackage(peers, package)); } } 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 (!Enumerable.SequenceEqual(adminList.GetList(), CurrentList)) { CurrentList = new List<string>(adminList.GetList()); List<ZNetPeer> adminPeer = Enumerable.ToList(Enumerable.Where(ZNet.instance.GetPeers(), 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 })); })); List<ZNetPeer> nonAdminPeer = Enumerable.ToList(Enumerable.Except(ZNet.instance.GetPeers(), adminPeer)); SendAdmin(nonAdminPeer, isAdmin: false); SendAdmin(adminPeer, isAdmin: true); } } } } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] private static class RegisterClientRPCPatch { [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); } } } private class ParsedConfigs { public readonly Dictionary<OwnConfigEntryBase, object?> configValues = new Dictionary<OwnConfigEntryBase, object>(); public readonly Dictionary<CustomSyncedValueBase, object?> customValues = new Dictionary<CustomSyncedValueBase, object>(); } [HarmonyPatch(typeof(ZNet), "Shutdown")] 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")] private class SendConfigsAfterLogin { private class BufferingSocket : ZPlayFabSocket, 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; ((ZPlayFabSocket)this)..ctor(); } 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); } } } [HarmonyPriority(800)] [HarmonyPrefix] private static void Prefix(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()) { return; } BufferingSocket bufferingSocket = new BufferingSocket(rpc.GetSocket()); AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, bufferingSocket); 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) { FieldInfo fieldInfo = AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket"); object? value = fieldInfo.GetValue(val); ZPlayFabSocket val2 = (ZPlayFabSocket)((value is ZPlayFabSocket) ? value : null); if (val2 != null) { typeof(ZPlayFabSocket).GetField("m_remotePlayerId").SetValue(bufferingSocket, val2.m_remotePlayerId); } fieldInfo.SetValue(val, bufferingSocket); } if (__state == null) { __state = new Dictionary<Assembly, BufferingSocket>(); } __state[Assembly.GetExecutingAssembly()] = bufferingSocket; } [HarmonyPostfix] private static void Postfix(Dictionary<Assembly, BufferingSocket> __state, ZNet __instance, ZRpc rpc) { ZRpc rpc2 = rpc; ZNet __instance2 = __instance; Dictionary<Assembly, BufferingSocket> __state2 = __state; ZNetPeer peer; if (__instance2.IsServer()) { object obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance2, new object[1] { rpc2 }); peer = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (peer == null) { SendBufferedData(); } else { ((MonoBehaviour)__instance2).StartCoroutine(sendAsync()); } } void SendBufferedData() { if (rpc2.GetSocket() is BufferingSocket bufferingSocket) { AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc2, bufferingSocket.Original); object? obj2 = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance2, new object[1] { rpc2 }); ZNetPeer val = (ZNetPeer)((obj2 is ZNetPeer) ? obj2 : null); if (val != null) { AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val, bufferingSocket.Original); } } BufferingSocket bufferingSocket2 = __state2[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(rpc2.GetSocket().GetHostName())) : listContainsId.Invoke(ZNet.instance, new object[2] { adminList, rpc2.GetSocket().GetHostName() })) }); ZPackage package = ConfigsToPackage(Enumerable.Select(configSync.allConfigs, (OwnConfigEntryBase c) => c.BaseConfig), configSync.allCustomValues, entries, partial: false); yield return ((MonoBehaviour)__instance2).StartCoroutine(configSync.sendZPackage(new List<ZNetPeer> { peer }, package)); } SendBufferedData(); } } } private class PackageEntry { public string section = null; public string key = null; public Type type = null; public object? value; } [HarmonyPatch(typeof(ConfigEntryBase), "GetSerializedValue")] private static class PreventSavingServerInfo { [HarmonyPrefix] 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; } } [HarmonyPatch(typeof(ConfigEntryBase), "SetSerializedValue")] private static class PreventConfigRereadChangingValues { [HarmonyPrefix] 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; } } private class InvalidDeserializationTypeException : Exception { public string expected = null; public string received = null; public string field = ""; } public static bool ProcessingServerUpdate; public readonly string Name; public string? DisplayName; public string? CurrentVersion; 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; 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[]>>(); 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; public event Action<bool>? SourceOfTruthChanged; 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<T>(ConfigEntry<T> configEntry) { ConfigEntry<T> configEntry2 = configEntry; OwnConfigEntryBase ownConfigEntryBase = configData((ConfigEntryBase)(object)configEntry2); SyncedConfigEntry<T> syncedEntry = ownConfigEntryBase as SyncedConfigEntry<T>; if (syncedEntry == null) { syncedEntry = new SyncedConfigEntry<T>(configEntry2); AccessTools.DeclaredField(typeof(ConfigDescription), "<Tags>k__BackingField").SetValue(((ConfigEntryBase)configEntry2).Description, Enumerable.ToArray(Enumerable.Concat(Enumerable.Concat(new object[1] { new ConfigurationManagerAttributes() }, ((ConfigEntryBase)configEntry2).Description.Tags ?? Array.Empty<object>()), new SyncedConfigEntry<T>[1] { syncedEntry }))); configEntry2.SettingChanged += delegate { if (!ProcessingServerUpdate && syncedEntry.SynchronizedConfig) { Broadcast(ZRoutedRpc.Everybody, (ConfigEntryBase)configEntry2); } }; allConfigs.Add(syncedEntry); } return syncedEntry; } public SyncedConfigEntry<T> AddLockingConfigEntry<T>(ConfigEntry<T> lockingConfig) where T : IConvertible { if (lockedConfig != null) { throw new Exception("Cannot initialize locking ConfigEntry twice"); } lockedConfig = AddConfigEntry<T>(lockingConfig); lockingConfig.SettingChanged += delegate { this.lockedConfigChanged?.Invoke(); }; return (SyncedConfigEntry<T>)lockedConfig; } internal void AddCustomValue(CustomSyncedValueBase customValue) { CustomSyncedValueBase customValue2 = customValue; if (Enumerable.Contains(Enumerable.Concat(Enumerable.Select(allCustomValues, (CustomSyncedValueBase v) => v.Identifier), new string[1] { "serverversion" }), customValue2.Identifier)) { throw new Exception("Cannot have multiple settings with the same name or with a reserved name (serverversion)"); } allCustomValues.Add(customValue2); allCustomValues = new HashSet<CustomSyncedValueBase>(Enumerable.OrderByDescending(allCustomValues, (CustomSyncedValueBase v) => v.Priority)); customValue2.ValueChanged += delegate { if (!ProcessingServerUpdate) { Broadcast(ZRoutedRpc.Everybody, customValue2); } }; } 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(delegate(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 SortedDictionary<int, byte[]> 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(Enumerable.ToArray(Enumerable.SelectMany(value.Values, (byte[] a) => a))); 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; val2.Save(); } 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 = Enumerable.ToDictionary(Enumerable.Where(allConfigs, (OwnConfigEntryBase c) => c.SynchronizedConfig), (OwnConfigEntryBase c) => c.BaseConfig.Definition.Section + "_" + c.BaseConfig.Definition.Key, (OwnConfigEntryBase c) => c); Dictionary<string, CustomSyncedValueBase> dictionary2 = Enumerable.ToDictionary(allCustomValues, (CustomSyncedValueBase c) => c.Identifier, (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) { OwnConfigEntryBase config2 = config; ConfigSync configSync = Enumerable.FirstOrDefault(configSyncs, (ConfigSync cs) => cs.allConfigs.Contains(config2)); if (configSync == null) { return true; } return configSync.IsSourceOfTruth || !config2.SynchronizedConfig || config2.LocalBaseValue == null || (!configSync.IsLocked && (config2 != 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 Enumerable.Where(allConfigs, (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 Enumerable.Where(allCustomValues, (CustomSyncedValueBase config) => config.LocalBaseValue != null)) { item2.BoxedValue = item2.LocalBaseValue; item2.LocalBaseValue = null; } lockedConfigChanged -= serverLockedSettingChanged; serverLockedSettingChanged(); } private IEnumerator<bool> distributeConfigToPeers(ZNetPeer peer, ZPackage package) { ZNetPeer peer2 = peer; 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 (peer2.m_socket.IsConnected()) { ZPackage fragmentedPackage = new ZPackage(); fragmentedPackage.Write((byte)2); fragmentedPackage.Write(packageIdentifier); fragmentedPackage.Write(fragment); fragmentedPackage.Write(fragments); fragmentedPackage.Write(Enumerable.ToArray(Enumerable.Take(Enumerable.Skip(data, 250000 * fragment), 250000))); 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) { peer2.m_rpc.Invoke(text, new object[1] { pkg }); } else { rpc.InvokeRoutedRPC(peer2.m_server ? 0 : peer2.m_uid, text, new object[1] { pkg }); } } IEnumerable<bool> waitForQueue() { float timeout = Time.time + 30f; while (peer2.m_socket.GetSendQueueSize() > 20000) { if (Time.time > timeout) { Debug.Log((object)$"Disconnecting {peer2.m_uid} after 30 seconds config sending timeout"); peer2.m_rpc.Invoke("Error", new object[1] { (object)(ConnectionStatus)5 }); ZNet.instance.Disconnect(peer2); 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 = Enumerable.ToList(Enumerable.Where(list, (ZNetPeer p) => p.m_uid == target)); } return sendZPackage(list, package); } private IEnumerator sendZPackage(List<ZNetPeer> peers, ZPackage package) { ZPackage package2 = package; if (!Object.op_Implicit((Object)(object)ZNet.instance)) { yield break; } byte[] rawData = package2.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()); package2 = compressedPackage; } List<IEnumerator<bool>> writers = Enumerable.ToList(Enumerable.Select(Enumerable.Where(peers, (ZNetPeer peer) => peer.IsReady()), (ZNetPeer p) => distributeConfigToPeers(p, package2))); 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)); } } } private static OwnConfigEntryBase? configData(ConfigEntryBase config) { object[] tags = config.Description.Tags; return (tags != null) ? Enumerable.SingleOrDefault(Enumerable.OfType<OwnConfigEntryBase>(tags)) : null; } public static SyncedConfigEntry<T>? ConfigData<T>(ConfigEntry<T> config) { object[] tags = ((ConfigEntryBase)config).Description.Tags; return (tags != null) ? Enumerable.SingleOrDefault(Enumerable.OfType<SyncedConfigEntry<T>>(tags)) : null; } private static T configAttribute<T>(ConfigEntryBase config) { return Enumerable.First(Enumerable.OfType<T>(config.Description.Tags)); } 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(IEnumerable<ConfigEntryBase>? configs = null, IEnumerable<CustomSyncedValueBase>? customValues = null, 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 != null) ? Enumerable.ToList(Enumerable.Where(configs, (ConfigEntryBase config) => configData(config).SynchronizedConfig)) : null) ?? new List<ConfigEntryBase>(); List<CustomSyncedValueBase> list2 = ((customValues != null) ? Enumerable.ToList(customValues) : null) ?? new List<CustomSyncedValueBase>(); ZPackage val = new ZPackage(); val.Write((byte)(partial ? 1 : 0)); val.Write(list.Count + list2.Count + ((packageEntries != null) ? Enumerable.Count(packageEntries) : 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, 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 Enumerable.First(source); } } [PublicAPI] [HarmonyPatch] internal class VersionCheck { private static readonly HashSet<VersionCheck> versionChecks; private static readonly Dictionary<string, string> notProcessedNames; public string Name; private string? displayName; private string? currentVersion; private string? minimumRequiredVersion; public bool ModRequired = true; private string? ReceivedCurrentVersion; private string? ReceivedMinimumRequiredVersion; private readonly List<ZRpc> ValidatedClients = new List<ZRpc>(); 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 && Enumerable.Count(patchInfo.Postfixes, (Patch p) => p.PatchMethod.DeclaringType == typeof(ConfigSync.RegisterRPCPatch)) > 0) { return; } Harmony val = new Harmony("org.bepinex.helpers.ServerSync"); foreach (Type item in Enumerable.Where(Enumerable.Concat(typeof(ConfigSync).GetNestedTypes(BindingFlags.NonPublic), new Type[1] { typeof(VersionCheck) }), (Type t) => t.IsClass)) { 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; ModRequired = true; versionChecks.Add(this); } public VersionCheck(ConfigSync configSync) { ConfigSync = configSync; Name = ConfigSync.Name; versionChecks.Add(this); } public void Initialize() { ReceivedCurrentVersion = null; ReceivedMinimumRequiredVersion = null; if (ConfigSync != null) { Name = ConfigSync.Name; DisplayName = ConfigSync.DisplayName; CurrentVersion = ConfigSync.CurrentVersion; MinimumRequiredVersion = ConfigSync.MinimumRequiredVersion; ModRequired = ConfigSync.ModRequired; } } private bool IsVersionOk() { if (ReceivedMinimumRequiredVersion == null || ReceivedCurrentVersion == null) { return !ModRequired; } bool flag = new System.Version(CurrentVersion) >= new System.Version(ReceivedMinimumRequiredVersion); bool flag2 = new System.Version(ReceivedCurrentVersion) >= new System.Version(MinimumRequiredVersion); return flag && flag2; } private string ErrorClient() { if (ReceivedMinimumRequiredVersion == null) { return DisplayName + " is not installed on the server."; } return (new System.Version(CurrentVersion) >= new System.Version(ReceivedMinimumRequiredVersion)) ? (DisplayName + " may not be higher than version " + ReceivedCurrentVersion + ". You have version " + CurrentVersion + ".") : (DisplayName + " needs to be at least version " + ReceivedMinimumRequiredVersion + ". You have version " + CurrentVersion + "."); } private string ErrorServer(ZRpc rpc) { return "Disconnect: The client (" + rpc.GetSocket().GetHostName() + ") doesn't have the correct " + DisplayName + " version " + MinimumRequiredVersion; } private string Error(ZRpc? rpc = null) { return (rpc == null) ? ErrorClient() : ErrorServer(rpc); } private static VersionCheck[] GetFailedClient() { return Enumerable.ToArray(Enumerable.Where(versionChecks, (VersionCheck check) => !check.IsVersionOk())); } private static VersionCheck[] GetFailedServer(ZRpc rpc) { ZRpc rpc2 = rpc; return Enumerable.ToArray(Enumerable.Where(versionChecks, (VersionCheck check) => check.ModRequired && !check.ValidatedClients.Contains(rpc2))); } private static void Logout() { Game.instance.Logout(true, true); AccessTools.DeclaredField(typeof(ZNet), "m_connectionStatus").SetValue(null, (object)(ConnectionStatus)3); } private static void DisconnectClient(ZRpc rpc) { rpc.Invoke("Error", new object[1] { 3 }); } private static void CheckVersion(ZRpc rpc, ZPackage pkg) { CheckVersion(rpc, pkg, null); } private static void CheckVersion(ZRpc rpc, ZPackage pkg, Action<ZRpc, ZPackage>? original) { string text = pkg.ReadString(); string text2 = pkg.ReadString(); string text3 = pkg.ReadString(); bool flag = false; foreach (VersionCheck versionCheck in versionChecks) { if (!(text != versionCheck.Name)) { Debug.Log((object)("Received " + versionCheck.DisplayName + " version " + text3 + " and minimum version " + text2 + " from the " + (ZNet.instance.IsServer() ? "client" : "server") + ".")); versionCheck.ReceivedMinimumRequiredVersion = text2; versionCheck.ReceivedCurrentVersion = text3; if (ZNet.instance.IsServer() && versionCheck.IsVersionOk()) { versionCheck.ValidatedClients.Add(rpc); } flag = true; } } if (flag) { return; } pkg.SetPos(0); if (original != null) { original(rpc, pkg); if (pkg.GetPos() == 0) { notProcessedNames.Add(text, text3); } } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [HarmonyPrefix] private static bool RPC_PeerInfo(ZRpc rpc, ZNet __instance) { VersionCheck[] array = (__instance.IsServer() ? GetFailedServer(rpc) : GetFailedClient()); if (array.Length == 0) { return true; } VersionCheck[] array2 = array; foreach (VersionCheck versionCheck in array2) { Debug.LogWarning((object)versionCheck.Error(rpc)); } if (__instance.IsServer()) { DisconnectClient(rpc); } else { Logout(); } return false; } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] [HarmonyPrefix] private static void RegisterAndCheckVersion(ZNetPeer peer, ZNet __instance) { //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Expected O, but got Unknown notProcessedNames.Clear(); IDictionary dictionary = (IDictionary)typeof(ZRpc).GetField("m_functions", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(peer.m_rpc); if (dictionary.Contains(StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck"))) { object obj = dictionary[StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck")]; Action<ZRpc, ZPackage> action = (Action<ZRpc, ZPackage>)obj.GetType().GetField("m_action", BindingFlags.Instance | BindingFlags.NonPublic).GetVal