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 Props Corpses v0.9.0
plugins/Props_Corpses.dll
Decompiled 2 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Unity.Collections; using UnityEngine; using UnityEngine.Rendering; [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("Props_Corpses")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.9.0.0")] [assembly: AssemblyInformationalVersion("0.9.0")] [assembly: AssemblyProduct("Props_Corpses")] [assembly: AssemblyTitle("Props_Corpses")] [assembly: AssemblyVersion("0.9.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } internal static class CorpseAdminBuild { private static Action<string> Warn; private static bool warnedMenu; private static readonly FieldInfo PiecesField = AccessTools.Field(typeof(PieceTable), "m_pieces"); private const BindingFlags Methods = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private static readonly FieldInfo GhostField = AccessTools.Field(typeof(Player), "m_placementGhost"); private static readonly FieldInfo StatusField = AccessTools.Field(typeof(Player), "m_placementStatus"); private static readonly object ValidStatus = ((StatusField != null && StatusField.FieldType.IsEnum && Enum.IsDefined(StatusField.FieldType, "Valid")) ? Enum.Parse(StatusField.FieldType, "Valid") : null); private static readonly FieldInfo HoverPiece = AccessTools.Field(typeof(Player), "m_hoveringPiece"); private static readonly MethodInfo GhostValid = AccessTools.Method(typeof(Player), "SetPlacementGhostValid", new Type[1] { typeof(bool) }, (Type[])null); private static readonly string[] RelaxedFlags = new string[7] { "m_groundOnly", "m_groundPiece", "m_noInWater", "m_notOnWood", "m_notOnTiltingSurface", "m_onlyInTeleportArea", "m_allowedInDungeons" }; private static bool warnedGhost; internal static void Install(Harmony harmony, Action<string> info, Action<string> warn) { Warn = warn; int num = 0; int num2 = 0; foreach (MethodInfo item in from m in typeof(PieceTable).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where m.Name == "UpdateAvailable" && !m.IsAbstract && !m.ContainsGenericParameters select m) { try { harmony.Patch((MethodBase)item, Hook("FilterMenu", 0), (HarmonyMethod)null, (HarmonyMethod)null, Hook("RestoreMenu", 0), (HarmonyMethod)null); num++; } catch (Exception ex) { warn("Corpse admin menu patch: " + ex); } } int num3 = 0; int num4 = 0; foreach (MethodInfo item2 in from m in typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where (m.Name == "TryPlacePiece" || m.Name == "PlacePiece") && !m.IsAbstract && !m.ContainsGenericParameters && (m.Name == "TryPlacePiece" || m.GetParameters().Any((ParameterInfo p) => p.ParameterType == typeof(Piece) || p.ParameterType == typeof(GameObject))) && (m.ReturnType == typeof(bool) || m.ReturnType == typeof(void)) select m) { try { string name = ((item2.ReturnType == typeof(bool)) ? "CheckPlacement" : "CheckPlacementVoid"); harmony.Patch((MethodBase)item2, Hook(name, 800), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num2++; if (item2.Name == "TryPlacePiece") { num3++; } else { num4++; } info("Corpse admin: patched " + item2); } catch (Exception ex2) { warn("Corpse admin placement patch: " + ex2); } } InstallPlacementAndRemoval(harmony, info, warn); info("Corpse admin-only construction: menu hooks=" + num + ", TryPlacePiece=" + num3 + ", PlacePiece=" + num4); if (num == 0 || num2 == 0) { warn("Corpse admin-only: missing game method hook; check compatibility before allowing non-admin clients."); } else if (num3 == 0) { warn("Corpse admin-only: TryPlacePiece hook unavailable; verify restrictions in multiplayer."); } } internal static void RelaxPiece(Piece piece) { string[] relaxedFlags = RelaxedFlags; foreach (string text in relaxedFlags) { FieldInfo fieldInfo = AccessTools.Field(typeof(Piece), text); if (fieldInfo != null && fieldInfo.FieldType == typeof(bool)) { fieldInfo.SetValue(piece, text == "m_allowedInDungeons"); } } WearNTear component = ((Component)piece).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component)) { FieldInfo fieldInfo2 = AccessTools.Field(typeof(WearNTear), "m_noSupportWear"); if (fieldInfo2 != null && fieldInfo2.FieldType == typeof(bool)) { fieldInfo2.SetValue(component, false); } } } private static void InstallPlacementAndRemoval(Harmony harmony, Action<string> info, Action<string> warn) { int num = 0; int num2 = 0; foreach (MethodInfo item in from m in typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where !m.IsAbstract && !m.ContainsGenericParameters select m) { try { if (item.Name == "UpdatePlacementGhost" && GhostField != null && ValidStatus != null) { harmony.Patch((MethodBase)item, (HarmonyMethod)null, Hook("FreeGhost", 0), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; } else if ((item.Name == "RemovePiece" || item.Name == "CheckCanRemovePiece") && (item.ReturnType == typeof(bool) || item.ReturnType == typeof(void))) { harmony.Patch((MethodBase)item, Hook((item.ReturnType == typeof(bool)) ? "BlockRemoval" : "BlockRemovalVoid", 800), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num2++; } } catch (Exception ex) { warn("Corpse free placement/removal hook " + item.Name + ": " + ex.Message); } } try { MethodInfo methodInfo = AccessTools.Method(typeof(WearNTear), "HaveSupport", Type.EmptyTypes, (Type[])null); if (methodInfo != null && methodInfo.ReturnType == typeof(bool)) { harmony.Patch((MethodBase)methodInfo, Hook("CorpseSupport", 800), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } catch (Exception ex2) { warn("Corpse support hook: " + ex2.Message); } info("Corpse free placement hooks=" + num + ", removal hooks=" + num2); if (num == 0 || num2 == 0) { warn("Corpse free placement/removal hook missing; verify current game compatibility."); } } private static bool CorpseSupport(WearNTear __instance, ref bool __result) { if (!IsCorpse(((Component)__instance).gameObject)) { return true; } __result = true; return false; } private static void FreeGhost(Player __instance) { //IL_005e: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || !CorpsePermissions.CanPlace) { return; } object? obj = GhostField?.GetValue(__instance); GameObject val = (GameObject)((obj is GameObject) ? obj : null); if (!IsCorpse(val)) { return; } try { if (!val.activeSelf) { Camera main = Camera.main; if (!Object.op_Implicit((Object)(object)main)) { return; } val.transform.position = ((Component)main).transform.position + ((Component)main).transform.forward * 3f; val.SetActive(true); } StatusField.SetValue(__instance, ValidStatus); GhostValid?.Invoke(__instance, new object[1] { true }); } catch (Exception ex) { if (!warnedGhost) { warnedGhost = true; Warn?.Invoke("Corpse free placement: " + ex.Message); } } } private static bool RemovalAllowed(Player player, object[] args) { if (CorpsePermissions.IsAdmin()) { return true; } bool flag = false; foreach (object obj in args) { Piece val = (Piece)((obj is Piece) ? obj : null); if (val != null && Object.op_Implicit((Object)(object)val)) { flag = true; if (IsCorpse(((Component)val).gameObject)) { return false; } } GameObject val2 = (GameObject)((obj is GameObject) ? obj : null); if (val2 != null && Object.op_Implicit((Object)(object)val2)) { flag = true; if (IsCorpse(val2) || CorpsePermissions.IsCorpse((Component)(object)val2.transform)) { return false; } } } if (flag) { return true; } object? obj2 = HoverPiece?.GetValue(player); Piece val3 = (Piece)((obj2 is Piece) ? obj2 : null); if (Object.op_Implicit((Object)(object)val3)) { return !IsCorpse(((Component)val3).gameObject); } return true; } private static bool BlockRemoval(Player __instance, object[] __args, ref bool __result) { if (RemovalAllowed(__instance, __args)) { return true; } __result = false; return false; } private static bool BlockRemovalVoid(Player __instance, object[] __args) { return RemovalAllowed(__instance, __args); } private static HarmonyMethod Hook(string name, int priority) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown return new HarmonyMethod(typeof(CorpseAdminBuild).GetMethod(name, BindingFlags.Static | BindingFlags.NonPublic)) { priority = priority }; } internal static bool IsCorpse(GameObject obj) { if (!Object.op_Implicit((Object)(object)obj)) { return false; } string text = ((Object)obj).name; if (text.EndsWith("(Clone)", StringComparison.Ordinal)) { text = text.Substring(0, text.Length - 7).TrimEnd(); } if (text.StartsWith("prop_boby_", StringComparison.Ordinal) && int.TryParse(text.Substring("prop_boby_".Length), out var result) && result >= 1) { return result <= 20; } return false; } private static void FilterMenu(PieceTable __instance, out List<GameObject> __state) { __state = null; if (CorpsePermissions.CanPlace) { return; } try { if (!(PiecesField?.GetValue(__instance) is List<GameObject> list)) { if (!warnedMenu) { warnedMenu = true; Warn?.Invoke("Corpse admin: unsupported PieceTable.m_pieces; placement guard remains active."); } } else if (list.Any(IsCorpse)) { List<GameObject> value = list.Where((GameObject p) => !IsCorpse(p)).ToList(); PiecesField.SetValue(__instance, value); __state = list; } } catch (Exception ex) { if (!warnedMenu) { warnedMenu = true; Warn?.Invoke("Corpse admin menu filter: " + ex.Message); } } } private static Exception RestoreMenu(PieceTable __instance, List<GameObject> __state, Exception __exception) { if (__state != null) { PiecesField.SetValue(__instance, __state); } return __exception; } private static bool Allowed(Player player, object[] args) { if (CorpsePermissions.CanPlace) { return true; } foreach (object obj in args) { Piece val = (Piece)((obj is Piece) ? obj : null); if (val != null && IsCorpse(((Component)val).gameObject)) { return false; } GameObject val2 = (GameObject)((obj is GameObject) ? obj : null); if (val2 != null && IsCorpse(val2)) { return false; } } if (Object.op_Implicit((Object)(object)player) && !args.Any((object a) => a is Piece || a is GameObject) && IsCorpse((GameObject)/*isinst with value type is only supported in some contexts*/)) { return false; } return true; } private static bool CheckPlacement(Player __instance, object[] __args, ref bool __result) { if (Allowed(__instance, __args)) { return true; } __result = false; return false; } private static bool CheckPlacementVoid(Player __instance, object[] __args) { return Allowed(__instance, __args); } } internal static class CorpseEyes { private static Material gray; private static readonly HashSet<string> reported = new HashSet<string>(); private static readonly Color Gray = new Color(0.39f, 0.39f, 0.39f, 1f); private static void WarnOnce(Action<string> warn, string message) { if (reported.Add(message)) { warn(message); } } private static bool Usable(Material m) { if (Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader) && m.shader.isSupported) { return ((Object)m.shader).name != "Hidden/InternalErrorShader"; } return false; } private static bool Opaque(Material m) { if (Usable(m) && m.renderQueue <= 2500 && !m.IsKeywordEnabled("_ALPHATEST_ON") && !m.IsKeywordEnabled("_ALPHABLEND_ON") && !m.IsKeywordEnabled("_ALPHAPREMULTIPLY_ON")) { if (!(m.GetTag("RenderType", false, "") == "Opaque")) { return m.GetTag("RenderType", false, "") == ""; } return true; } return false; } private static bool HasColorTexture(Material m) { if (!m.HasProperty("_MainTex") && !m.HasProperty("_BaseMap")) { return m.HasProperty("_BaseColorMap"); } return true; } private static Material GetGray(Material fallback) { //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Expected O, but got Unknown //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: 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_0125: 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_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Expected O, but got Unknown //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)gray)) { return gray; } Material val = null; string[] array = new string[4] { "Wood", "Stone", "piece_workbench", "wood_floor" }; foreach (string text in array) { GameObject prefab = PrefabManager.Instance.GetPrefab(text); if (Object.op_Implicit((Object)(object)prefab)) { val = prefab.GetComponentsInChildren<Renderer>(true).SelectMany((Renderer r) => r.sharedMaterials).FirstOrDefault((Func<Material, bool>)((Material m) => Opaque(m) && HasColorTexture(m))); if (Object.op_Implicit((Object)(object)val)) { break; } } } if (!Object.op_Implicit((Object)(object)val) && Opaque(fallback) && HasColorTexture(fallback)) { val = fallback; } if (!Object.op_Implicit((Object)(object)val)) { return null; } Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false); ((Object)val2).name = "Corpse01_GrayEyes"; val2.SetPixels((Color[])(object)new Color[4] { Gray, Gray, Gray, Gray }); val2.Apply(false, true); Material val3 = new Material(val); ((Object)val3).name = "Corpse_MatteGrayEyes"; array = new string[3] { "_MainTex", "_BaseMap", "_BaseColorMap" }; foreach (string text2 in array) { if (val3.HasProperty(text2)) { val3.SetTexture(text2, (Texture)(object)val2); val3.SetTextureScale(text2, Vector2.one); val3.SetTextureOffset(text2, Vector2.zero); } } array = new string[4] { "_Color", "_BaseColor", "_SkinColor", "_HairColor" }; foreach (string text3 in array) { if (val3.HasProperty(text3)) { val3.SetColor(text3, Color.white); } } array = new string[7] { "_Glossiness", "_Smoothness", "_Metallic", "_BumpScale", "_EmissionStrength", "_SpecularHighlights", "_GlossyReflections" }; foreach (string text4 in array) { if (val3.HasProperty(text4)) { val3.SetFloat(text4, 0f); } } array = new string[2] { "_EmissionColor", "_SpecColor" }; foreach (string text5 in array) { if (val3.HasProperty(text5)) { val3.SetColor(text5, Color.black); } } array = new string[5] { "_BumpMap", "_DetailNormalMap", "_DetailAlbedoMap", "_MetallicGlossMap", "_EmissionMap" }; foreach (string text6 in array) { if (val3.HasProperty(text6)) { val3.SetTexture(text6, (Texture)null); } } array = new string[4] { "_NORMALMAP", "_DETAIL_MULX2", "_METALLICGLOSSMAP", "_EMISSION" }; foreach (string text7 in array) { val3.DisableKeyword(text7); } gray = val3; return gray; } private static void SetBlock(MeshRenderer r, int slot, Material m) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) MaterialPropertyBlock val = new MaterialPropertyBlock(); string[] array = new string[3] { "_MainTex", "_BaseMap", "_BaseColorMap" }; foreach (string text in array) { if (m.HasProperty(text)) { val.SetTexture(text, m.GetTexture(text)); } } array = new string[4] { "_Color", "_BaseColor", "_SkinColor", "_HairColor" }; foreach (string text2 in array) { if (m.HasProperty(text2)) { val.SetColor(text2, Color.white); } } array = new string[3] { "_Glossiness", "_Smoothness", "_Metallic" }; foreach (string text3 in array) { if (m.HasProperty(text3)) { val.SetFloat(text3, 0f); } } if (m.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", Color.black); } ((Renderer)r).SetPropertyBlock(val, slot); } private static bool EyeUV(Vector2 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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_0027: Unknown result type (might be due to invalid IL or missing references) if (p.x >= 0.45703125f && p.x <= 0.5019531f && p.y >= 0.9003906f) { return p.y <= 0.9238281f; } return false; } internal static bool Apply(Mesh mesh, MeshRenderer renderer, Action<string> info, Action<string> warn) { //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) try { Material[] array = ((Renderer)renderer).sharedMaterials; if (array.Length != mesh.subMeshCount || array.Length == 0) { WarnOnce(warn, "Dead eyes: incompatible mesh/material layout."); return false; } Material val = GetGray(array[0]); if (!Object.op_Implicit((Object)(object)val)) { WarnOnce(warn, "Dead eyes: no compatible loaded native opaque material; leaving original eyes."); return false; } Vector2[] uv = mesh.uv; if (uv.Length != mesh.vertexCount) { WarnOnce(warn, "Dead eyes: UV data missing; leaving original eyes."); return false; } List<int> list = new List<int>(); Dictionary<int, List<int>> dictionary = new Dictionary<int, List<int>>(); List<int> list2 = new List<int>(); for (int i = 0; i < array.Length; i++) { if (!Object.op_Implicit((Object)(object)array[i])) { continue; } string name = ((Object)array[i]).name; if (name.StartsWith("eye_", StringComparison.OrdinalIgnoreCase) || name.StartsWith("eyes", StringComparison.OrdinalIgnoreCase)) { list2.Add(i); } else if (name.IndexOf("PlayerMaterial", StringComparison.OrdinalIgnoreCase) >= 0) { int[] triangles = mesh.GetTriangles(i); List<int> list3 = new List<int>(); List<int> list4 = new List<int>(); for (int j = 0; j + 2 < triangles.Length; j += 3) { List<int> obj = ((EyeUV(uv[triangles[j]]) && EyeUV(uv[triangles[j + 1]]) && EyeUV(uv[triangles[j + 2]])) ? list4 : list3); obj.Add(triangles[j]); obj.Add(triangles[j + 1]); obj.Add(triangles[j + 2]); } if (list4.Count > 0 && list3.Count > 0) { dictionary[i] = list3; list.AddRange(list4); } } } if (list2.Count == 0 && list.Count == 0) { WarnOnce(warn, "Dead eyes: no matching eye material/UV triangles; leaving original eyes."); return false; } foreach (int item in list2) { array[item] = val; } if (list.Count > 0) { int subMeshCount = mesh.subMeshCount; mesh.subMeshCount = subMeshCount + 1; foreach (KeyValuePair<int, List<int>> item2 in dictionary) { mesh.SetTriangles(item2.Value, item2.Key, false); } mesh.SetTriangles(list, subMeshCount, false); array = array.Concat((IEnumerable<Material>)(object)new Material[1] { val }).ToArray(); } ((Renderer)renderer).sharedMaterials = array; foreach (int item3 in list2) { SetBlock(renderer, item3, val); } if (list.Count > 0) { SetBlock(renderer, array.Length - 1, val); } info("Dead eyes: native " + ((Object)val.shader).name + ", gray triangles=" + list.Count / 3 + ", eye material slots=" + list2.Count); return true; } catch (Exception ex) { WarnOnce(warn, "Dead eyes fallback failed: " + ex.Message); return false; } } } internal static class CorpsePermissions { private static ConfigEntry<bool> placement; private static ConfigEntry<bool> interaction; private static ConfigEntry<bool> equip; private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private static readonly FieldInfo Slots = AccessTools.Field(typeof(ArmorStand), "m_slots"); internal static bool PlayerPlacement { get { if (placement != null) { return placement.Value; } return false; } } internal static bool PlayerInteraction { get { if (interaction != null) { return interaction.Value; } return true; } } internal static bool PlayerEquip { get { if (equip != null) { return equip.Value; } return false; } } internal static bool CanPlace { get { if (!IsAdmin()) { return PlayerPlacement; } return true; } } internal static bool CanInteract { get { if (!IsAdmin()) { return PlayerInteraction; } return true; } } internal static bool CanEquip { get { if (!IsAdmin()) { if (PlayerInteraction) { return PlayerEquip; } return false; } return true; } } internal static bool IsAdmin() { try { return (Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer()) || SynchronizationManager.Instance.PlayerIsAdmin; } catch { return false; } } internal static void Bind(ConfigFile config) { placement = BindBool(config, "AllowPlayerPlacement", value: false, "Allow non-admin players to build decorative bodies."); interaction = BindBool(config, "AllowPlayerInteraction", value: true, "Allow non-admin players to search bodies and remove equipment."); equip = BindBool(config, "AllowPlayerEquip", value: false, "Allow non-admin players to attach equipment. Requires AllowPlayerInteraction."); } private static ConfigEntry<bool> BindBool(ConfigFile config, string key, bool value, string description) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown return config.Bind<bool>("Permissions", key, value, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); } internal static bool IsCorpse(Component c) { if (!Object.op_Implicit((Object)(object)c)) { return false; } ArmorStand val = (ArmorStand)(object)((c is ArmorStand) ? c : null); if (!Object.op_Implicit((Object)(object)val)) { val = c.GetComponentInParent<ArmorStand>(); } if (Object.op_Implicit((Object)(object)val)) { return CorpseAdminBuild.IsCorpse(((Component)val).gameObject); } return false; } internal static string PlayerHover() { if (!CanInteract) { return ""; } return "[<color=yellow><b>" + LocalizationManager.Instance.TryTranslate("$KEY_Use") + "</b></color>] " + LocalizationManager.Instance.TryTranslate("$corpse_search"); } private static bool IsEquipmentSwitch(Switch sw) { ArmorStand componentInParent = ((Component)sw).GetComponentInParent<ArmorStand>(); if (!Object.op_Implicit((Object)(object)componentInParent)) { return false; } if (!(Slots?.GetValue(componentInParent) is IEnumerable enumerable)) { return false; } foreach (object item in enumerable) { if (item != null && AccessTools.Field(item.GetType(), "m_switch")?.GetValue(item) == sw) { return true; } } return false; } private static HarmonyMethod Hook(string n, int p = 800) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Expected O, but got Unknown return new HarmonyMethod(typeof(CorpsePermissions).GetMethod(n, BindingFlags.Static | BindingFlags.NonPublic)) { priority = p }; } internal static void Install(Harmony harmony, Action<string> info, Action<string> warn) { int num = 0; int num2 = 0; int num3 = 0; Type[] array = new Type[2] { typeof(ArmorStand), typeof(Switch) }; foreach (Type type in array) { foreach (MethodInfo item in from m in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where !m.IsAbstract && !m.ContainsGenericParameters select m) { string text = item.Name.Split('.').Last(); try { if (item.ReturnType == typeof(bool) && text == "UseItem") { harmony.Patch((MethodBase)item, Hook((type == typeof(ArmorStand)) ? "StandUse" : "SwitchUse"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; } else if (type == typeof(Switch) && item.ReturnType == typeof(bool) && text == "Interact") { harmony.Patch((MethodBase)item, Hook("SwitchInteract"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num2++; } else if (item.ReturnType == typeof(string) && (text == "GetHoverText" || text == "GetHoverName")) { harmony.Patch((MethodBase)item, (HarmonyMethod)null, Hook((text == "GetHoverText") ? "HoverText" : "HoverName", 0), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num3++; } } catch (Exception ex) { warn("Corpse permissions hook " + item.Name + ": " + ex.Message); } } } info("Corpse permissions: use=" + num + ", interaction=" + num2 + ", hover=" + num3); if (num == 0 || num2 == 0) { warn("Corpse native interaction hook missing; verify equipment permissions."); } } private static bool StandUse(ArmorStand __instance, ref bool __result) { if (!IsCorpse((Component)(object)__instance) || CanEquip) { return true; } __result = false; return false; } private static bool SwitchUse(Switch __instance, ref bool __result) { if (!IsCorpse((Component)(object)__instance) || CanEquip) { return true; } __result = false; return false; } private static bool SwitchInteract(Switch __instance, ref bool __result) { if (!IsCorpse((Component)(object)__instance) || IsAdmin() || (PlayerInteraction && IsEquipmentSwitch(__instance))) { return true; } __result = false; return false; } private static void HoverText(Component __instance, ref string __result) { if (IsCorpse(__instance) && !IsAdmin()) { __result = PlayerHover(); } } private static void HoverName(Component __instance, ref string __result) { if (IsCorpse(__instance) && !IsAdmin()) { __result = ""; } } } internal static class CorpseServerGuard { private sealed class ReceiveScope { internal ZRpc Rpc; internal HashSet<ZDO> Created; internal void Track(ZDO zdo) { if (Created == null) { Created = new HashSet<ZDO>(); } Created.Add(zdo); } } private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static readonly HashSet<int> CorpseHashes = new HashSet<int>(from i in Enumerable.Range(1, 20) select StableHash("prop_boby_" + i)); private static readonly FieldInfo AdminList = AccessTools.Field(typeof(ZNet), "m_adminList"); private static readonly MethodInfo ListContains = typeof(ZNet).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "ListContainsId" && m.ReturnType == typeof(bool) && m.GetParameters().Length == 2 && m.GetParameters()[1].ParameterType == typeof(string)); private static Action<string> Warn; private static bool warnedAuth; private static bool warnedReject; private static bool warnedRollback; private static readonly FieldInfo Uid = AccessTools.Field(typeof(ZDO), "m_uid"); private static readonly MethodInfo FindZdo = AccessTools.Method(typeof(ZDOMan), "GetZDO", new Type[1] { typeof(ZDOID) }, (Type[])null); private static readonly MethodInfo Destroy = AccessTools.Method(typeof(ZDOMan), "DestroyZDO", new Type[1] { typeof(ZDO) }, (Type[])null); private static readonly MethodInfo Session = AccessTools.Method(typeof(ZDOMan), "GetSessionID", Type.EmptyTypes, (Type[])null) ?? AccessTools.Method(typeof(ZDOMan), "GetMyID", Type.EmptyTypes, (Type[])null); private static readonly MethodInfo Owner = AccessTools.Method(typeof(ZDO), "SetOwner", new Type[1] { typeof(long) }, (Type[])null); [ThreadStatic] private static ReceiveScope scope; private static int StableHash(string value) { int num = 5381; int num2 = 5381; for (int i = 0; i < value.Length; i += 2) { num = ((num << 5) + num) ^ value[i]; if (i == value.Length - 1) { break; } num2 = ((num2 << 5) + num2) ^ value[i + 1]; } return num + num2 * 1566083941; } private static HarmonyMethod Hook(string name) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown return new HarmonyMethod(typeof(CorpseServerGuard).GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)); } internal static void Install(Harmony harmony, Action<string> info, Action<string> warn) { Warn = warn; try { MethodInfo methodInfo = AccessTools.Method(typeof(ZDOMan), "RPC_ZDOData", new Type[2] { typeof(ZRpc), typeof(ZPackage) }, (Type[])null); MethodInfo[] array = (from m in typeof(ZDOMan).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) where !m.IsStatic && m.Name == "CreateNewZDO" && m.ReturnType == typeof(ZDO) && m.GetParameters().Any((ParameterInfo p) => p.ParameterType == typeof(ZDOID)) select m).ToArray(); if (methodInfo == null || array.Length == 0 || AdminList == null || Uid == null || FindZdo == null || Destroy == null || Session == null || Owner == null) { throw new MissingMethodException("ZDOData, CreateNewZDO, ownership or admin API unavailable"); } MethodInfo[] array2 = array; foreach (MethodInfo methodInfo2 in array2) { harmony.Patch((MethodBase)methodInfo2, Hook("BeforeCreate"), Hook("AfterCreate"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } harmony.Patch((MethodBase)methodInfo, Hook("BeginReceive"), (HarmonyMethod)null, (HarmonyMethod)null, Hook("EndReceive"), (HarmonyMethod)null); info("Corpse server guard: incoming ZDOData and " + array.Length + " CreateNewZDO hooks installed."); } catch (Exception ex) { warn("Corpse server guard unavailable: " + ex.Message + ". Client restrictions only; verify before public deployment."); } } private static bool PeerIsAdmin(ZRpc rpc) { try { ZNet instance = ZNet.instance; object obj; if (rpc == null) { obj = null; } else { ISocket socket = rpc.GetSocket(); obj = ((socket != null) ? socket.GetHostName() : null); } string text = (string)obj; if (!Object.op_Implicit((Object)(object)instance) || string.IsNullOrEmpty(text)) { return false; } object value = AdminList.GetValue(instance); if (value == null) { return false; } if (ListContains != null) { return (bool)ListContains.Invoke(ListContains.IsStatic ? null : instance, new object[2] { value, text }); } MethodInfo methodInfo = AccessTools.Method(value.GetType(), "Contains", new Type[1] { typeof(string) }, (Type[])null); if (methodInfo != null) { return (bool)methodInfo.Invoke(value, new object[1] { text }); } throw new MissingMethodException("Admin list membership method missing"); } catch (Exception ex) { if (!warnedAuth) { warnedAuth = true; Warn?.Invoke("Corpse server admin check failed (deny): " + ex.Message); } return false; } } private static void BeginReceive(ZRpc __0, out ReceiveScope __state) { __state = scope; scope = ((Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer()) ? new ReceiveScope { Rpc = __0 } : null); } private static void BeforeCreate(ZDOMan __instance, object[] __args, out bool __state) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) __state = false; if (scope == null) { return; } for (int i = 0; i < __args.Length; i++) { if (__args[i] is ZDOID val) { __state = FindZdo.Invoke(__instance, new object[1] { val }) == null; break; } } } private static void AfterCreate(ZDO __result, bool __state) { if (__state && scope != null && __result != null && (__result.GetPrefab() == 0 || CorpseHashes.Contains(__result.GetPrefab()))) { scope.Track(__result); } } private static Exception EndReceive(ZDOMan __instance, ReceiveScope __state, Exception __exception) { ReceiveScope receiveScope = scope; scope = __state; if (receiveScope == null || receiveScope.Created == null || CorpsePermissions.PlayerPlacement || PeerIsAdmin(receiveScope.Rpc)) { return __exception; } foreach (ZDO item in receiveScope.Created) { try { if (CorpseHashes.Contains(item.GetPrefab()) && FindZdo.Invoke(__instance, new object[1] { Uid.GetValue(item) }) == item) { long num = Convert.ToInt64(Session.Invoke(Session.IsStatic ? null : __instance, null)); Owner.Invoke(item, new object[1] { num }); Destroy.Invoke(__instance, new object[1] { item }); if (!warnedReject) { warnedReject = true; Warn?.Invoke("Corpse server guard: rejected new corpse from non-admin connection (further notices suppressed)."); } } } catch (Exception ex) { if (!warnedRollback) { warnedRollback = true; Warn?.Invoke("Corpse server guard rollback failed: " + ex.Message); } } } return __exception; } } internal static class CorpseStaticMeshes { private static Mesh MeshOf(MeshRenderer r) { MeshFilter component = ((Component)r).GetComponent<MeshFilter>(); if (!Object.op_Implicit((Object)(object)component)) { return null; } return component.sharedMesh; } internal static bool EmptyBlocks(MeshRenderer r) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown MaterialPropertyBlock val = new MaterialPropertyBlock(); ((Renderer)r).GetPropertyBlock(val); if (!val.isEmpty) { return false; } for (int i = 0; i < ((Renderer)r).sharedMaterials.Length; i++) { val.Clear(); ((Renderer)r).GetPropertyBlock(val, i); if (!val.isEmpty) { return false; } } return true; } private static bool Compatible(MeshRenderer r, MeshRenderer first, Transform parent) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) Mesh val = MeshOf(r); Material[] sharedMaterials = ((Renderer)r).sharedMaterials; if (!Object.op_Implicit((Object)(object)val) || sharedMaterials.Length == 0 || sharedMaterials.Length != val.subMeshCount || !sharedMaterials.SequenceEqual(((Renderer)first).sharedMaterials)) { return false; } if (sharedMaterials.Any((Material x) => !Object.op_Implicit((Object)(object)x) || x.renderQueue > 2500)) { return false; } Matrix4x4 val2 = parent.worldToLocalMatrix * ((Component)r).transform.localToWorldMatrix; if (((Matrix4x4)(ref val2)).determinant <= 0f) { return false; } if (((Renderer)r).enabled && !((Renderer)r).forceRenderingOff && ((Component)r).gameObject.layer == ((Component)first).gameObject.layer && ((Renderer)r).shadowCastingMode == ((Renderer)first).shadowCastingMode && ((Renderer)r).receiveShadows == ((Renderer)first).receiveShadows && ((Renderer)r).lightProbeUsage == ((Renderer)first).lightProbeUsage && ((Renderer)r).reflectionProbeUsage == ((Renderer)first).reflectionProbeUsage && ((Renderer)r).sortingLayerID == ((Renderer)first).sortingLayerID && ((Renderer)r).sortingOrder == ((Renderer)first).sortingOrder) { return ((Renderer)r).renderingLayerMask == ((Renderer)first).renderingLayerMask; } return false; } private static void CopyState(MeshRenderer from, MeshRenderer to) { //IL_000e: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown ((Renderer)to).sharedMaterials = ((Renderer)from).sharedMaterials; ((Renderer)to).shadowCastingMode = ((Renderer)from).shadowCastingMode; ((Renderer)to).receiveShadows = ((Renderer)from).receiveShadows; ((Renderer)to).lightProbeUsage = ((Renderer)from).lightProbeUsage; ((Renderer)to).reflectionProbeUsage = ((Renderer)from).reflectionProbeUsage; ((Renderer)to).sortingLayerID = ((Renderer)from).sortingLayerID; ((Renderer)to).sortingOrder = ((Renderer)from).sortingOrder; ((Renderer)to).renderingLayerMask = ((Renderer)from).renderingLayerMask; MaterialPropertyBlock val = new MaterialPropertyBlock(); ((Renderer)from).GetPropertyBlock(val); ((Renderer)to).SetPropertyBlock(val); for (int i = 0; i < ((Renderer)from).sharedMaterials.Length; i++) { val.Clear(); ((Renderer)from).GetPropertyBlock(val, i); ((Renderer)to).SetPropertyBlock(val, i); } } internal static void CopyPreview(MeshRenderer from, MeshRenderer to) { CopyState(from, to); } private static void Prune(Transform t, Transform stop) { while (Object.op_Implicit((Object)(object)t) && (Object)(object)t != (Object)(object)stop && t.childCount == 0 && ((Component)t).GetComponents<Component>().Length == 1) { Transform parent = t.parent; Object.DestroyImmediate((Object)(object)((Component)t).gameObject); t = parent; } } internal static void Merge(GameObject root, IEnumerable<MeshRenderer> candidates, Action<string> info, Action<string> warn) { //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Expected O, but got Unknown //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Expected O, but got Unknown MeshRenderer[] array = candidates.Where((MeshRenderer r) => Object.op_Implicit((Object)(object)r) && Object.op_Implicit((Object)(object)MeshOf(r))).ToArray(); if (array.Length < 2) { return; } MeshRenderer first = array[0]; MeshRenderer[] group = array.Where((MeshRenderer r) => Compatible(r, first, root.transform)).ToArray(); if (group.Length < 2) { return; } List<Mesh> temps = new List<Mesh>(); Mesh val = null; GameObject val2 = null; try { Mesh[] sourceMeshes = group.Select((MeshRenderer r) => WeaponVisuals.ReadableForMerge(MeshOf(r))).ToArray(); int num = ((Renderer)first).sharedMaterials.Length; Matrix4x4[] matrices = group.Select((MeshRenderer r) => root.transform.worldToLocalMatrix * ((Component)r).transform.localToWorldMatrix).ToArray(); long totalVertices = ((IEnumerable<Mesh>)sourceMeshes).Sum((Func<Mesh, long>)((Mesh m) => m.vertexCount)); Mesh[] array2 = Enumerable.Range(0, num).Select(Build).ToArray(); if (num == 1) { val = array2[0]; temps.Remove(val); } else { val = new Mesh(); if (((IEnumerable<Mesh>)array2).Sum((Func<Mesh, long>)((Mesh m) => m.vertexCount)) > 65535) { val.indexFormat = (IndexFormat)1; } val.CombineMeshes(array2.Select(delegate(Mesh m) { //IL_0002: 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_0024: Unknown result type (might be due to invalid IL or missing references) CombineInstance result = default(CombineInstance); ((CombineInstance)(ref result)).mesh = m; ((CombineInstance)(ref result)).subMeshIndex = 0; ((CombineInstance)(ref result)).transform = Matrix4x4.identity; return result; }).ToArray(), false, false, false); if (val.subMeshCount != num) { throw new InvalidOperationException("Combined material slots mismatch"); } for (int num2 = 0; num2 < num; num2++) { if (val.GetIndexCount(num2) != array2[num2].GetIndexCount(0)) { throw new InvalidOperationException("Combined submesh mismatch"); } } } ((Object)val).name = ((Object)root).name + "_CombinedStatic"; val.RecalculateBounds(); val2 = new GameObject("CorpseCombinedStatic"); val2.transform.SetParent(root.transform, false); val2.layer = ((Component)first).gameObject.layer; val2.AddComponent<MeshFilter>().sharedMesh = val; MeshRenderer to = val2.AddComponent<MeshRenderer>(); CopyState(first, to); Mesh Build(int slot) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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) CombineInstance[] array4 = (CombineInstance[])(object)new CombineInstance[group.Length]; long num4 = 0L; for (int i = 0; i < array4.Length; i++) { Mesh val4 = sourceMeshes[i]; if ((int)val4.GetTopology(slot) != 0) { throw new InvalidOperationException("Non-triangle static mesh"); } int num5 = i; CombineInstance val5 = default(CombineInstance); ((CombineInstance)(ref val5)).mesh = val4; ((CombineInstance)(ref val5)).subMeshIndex = slot; ((CombineInstance)(ref val5)).transform = matrices[i]; array4[num5] = val5; num4 += val4.GetIndexCount(slot); } Mesh val6 = new Mesh(); temps.Add(val6); if (totalVertices > 65535) { val6.indexFormat = (IndexFormat)1; } val6.CombineMeshes(array4, true, true, false); if (val6.subMeshCount != 1 || val6.GetIndexCount(0) != num4 || val6.vertexCount == 0) { throw new InvalidOperationException("Combined triangle count mismatch"); } return val6; } } catch (Exception ex) { if (Object.op_Implicit((Object)(object)val2)) { Object.DestroyImmediate((Object)(object)val2); } if (Object.op_Implicit((Object)(object)val)) { Object.DestroyImmediate((Object)(object)val); } warn(((Object)root).name + ": static merge skipped; original meshes retained: " + ex.Message); return; } finally { foreach (Mesh item in temps) { if (Object.op_Implicit((Object)(object)item)) { Object.DestroyImmediate((Object)(object)item); } } } MeshRenderer[] array3 = group; foreach (MeshRenderer val3 in array3) { if (Object.op_Implicit((Object)(object)val3)) { Transform transform = ((Component)val3).transform; MeshFilter component = ((Component)val3).GetComponent<MeshFilter>(); Object.DestroyImmediate((Object)(object)val3); if (Object.op_Implicit((Object)(object)component)) { Object.DestroyImmediate((Object)(object)component); } Prune(transform, root.transform); } } info(((Object)root).name + ": combined " + group.Length + " static renderers into one."); } internal static List<Bounds> ReduceBounds(IEnumerable<Bounds> input, int limit) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) List<Bounds> list = input.ToList(); while (list.Count > limit) { int index = 0; int index2 = 1; float num = float.PositiveInfinity; Bounds value = list[0]; for (int i = 0; i < list.Count; i++) { for (int j = i + 1; j < list.Count; j++) { Bounds val = list[i]; ((Bounds)(ref val)).Encapsulate(list[j]); float num2 = Volume(val) - Volume(list[i]) - Volume(list[j]); if (num2 < num) { num = num2; index = i; index2 = j; value = val; } } } list[index] = value; list.RemoveAt(index2); } return list; static float Volume(Bounds b) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) Vector3 size = ((Bounds)(ref b)).size; return Mathf.Max(0.035f, size.x) * Mathf.Max(0.035f, size.y) * Mathf.Max(0.035f, size.z); } } } [BepInPlugin("yadren1y.corpse01.preview", "Props_Corpses", "0.9.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public sealed class Corpse01 : BaseUnityPlugin { private static readonly int[] RetainedPoses = new int[20] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; private const string Category = "LootBodies"; private Harmony harmony; private ConfigEntry<bool> exportBlender; private static ConfigEntry<bool> debugLogging; private int registeredCount; private static readonly ManualLogSource HelmetLog = Logger.CreateLogSource("Corpse Helmet"); private static readonly ManualLogSource StandLog = Logger.CreateLogSource("Corpse ArmorStand"); internal static bool DebugLogging { get { if (debugLogging != null) { return debugLogging.Value; } return false; } } internal static bool Headless { get; private set; } private bool ExportBlender { get { if (!Headless) { return exportBlender.Value; } return false; } } private void DebugInfo(string message) { if (DebugLogging) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); } } private void Awake() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Expected O, but got Unknown //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Expected O, but got Unknown //IL_022c: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Expected O, but got Unknown //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Expected O, but got Unknown Headless = (int)SystemInfo.graphicsDeviceType == 4; debugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Logging", "DebugLogging", false, "Write detailed body, weapon, appearance and equipment diagnostics."); exportBlender = ((BaseUnityPlugin)this).Config.Bind<bool>("Blender", "ExportRigsOnStartup", false, "Enable only when refreshing Blender assets from Valheim. Overrides the obsolete ExportRigs setting."); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Props_Corpses 0.9.0 loaded."); PoseBridge.Initialize(ExportBlender, DebugInfo, delegate(string m) { ((BaseUnityPlugin)this).Logger.LogWarning((object)m); }); harmony = new Harmony("yadren1y.corpse01.armorstand"); CorpsePermissions.Bind(((BaseUnityPlugin)this).Config); CorpsePermissions.Install(harmony, DebugInfo, delegate(string m) { ((BaseUnityPlugin)this).Logger.LogWarning((object)m); }); CorpseAdminBuild.Install(harmony, DebugInfo, delegate(string m) { ((BaseUnityPlugin)this).Logger.LogWarning((object)m); }); CorpseServerGuard.Install(harmony, DebugInfo, delegate(string m) { ((BaseUnityPlugin)this).Logger.LogWarning((object)m); }); MethodInfo methodInfo = AccessTools.Method(typeof(VisEquipment), "UpdateVisuals", Type.EmptyTypes, (Type[])null); if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Corpse01).GetMethod("UpdateServerVisuals", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Headless equipment visual guard unavailable: VisEquipment.UpdateVisuals missing"); } HarmonyMethod val = new HarmonyMethod(typeof(Corpse01).GetMethod("StandVisualChanged", BindingFlags.Static | BindingFlags.NonPublic)); foreach (MethodInfo item in from m in typeof(ArmorStand).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where m.Name == "SetVisualItem" select m) { try { harmony.Patch((MethodBase)item, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("ArmorStand visual hook: " + ex.Message)); } } HarmonyMethod val2 = new HarmonyMethod(typeof(Corpse01).GetMethod("AlignStaticHelmet", BindingFlags.Static | BindingFlags.NonPublic)); foreach (MethodInfo item2 in from m in typeof(VisEquipment).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where m.Name == "SetHelmetEquipped" select m) { try { harmony.Patch((MethodBase)item2, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception ex2) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Helmet alignment hook: " + ex2.Message)); } } MethodInfo methodInfo2 = typeof(ArmorStand).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "CanAttach" && m.ReturnType == typeof(bool) && m.GetParameters().Length == 2 && m.GetParameters()[1].ParameterType == typeof(ItemData)); if (methodInfo2 != null) { try { harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Corpse01).GetMethod("RestrictStaticEquipment", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception ex3) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Helmet restriction hook: " + ex3)); } } CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); Dictionary<string, string> dictionary = new Dictionary<string, string> { { "jotunn_cat_lootbodies", "Loot bodies" }, { "corpse_desc", "Decorative body" }, { "corpse_attach", "Attach equipment" }, { "corpse_take", "Remove equipment" }, { "corpse_search", "Search" } }; Dictionary<string, string> dictionary2 = new Dictionary<string, string> { { "jotunn_cat_lootbodies", "Лут-тела" }, { "corpse_desc", "Декоративное тело" }, { "corpse_attach", "Прикрепить снаряжение" }, { "corpse_take", "Снять снаряжение" }, { "corpse_search", "Обыскать" } }; int[] retainedPoses = RetainedPoses; for (int num = 0; num < retainedPoses.Length; num++) { int num2 = retainedPoses[num]; dictionary["corpse_body_" + num2] = "prop boby " + num2; dictionary2["corpse_body_" + num2] = "Тело " + num2; } string text = "English"; localization.AddTranslation(ref text, dictionary); text = "Russian"; localization.AddTranslation(ref text, dictionary2); PrefabManager.OnVanillaPrefabsAvailable += Register; } private void OnDestroy() { PrefabManager.OnVanillaPrefabsAvailable -= Register; if (harmony != null) { harmony.UnpatchSelf(); } } private static bool RestrictStaticEquipment(ArmorStand __instance, object __0, ItemData __1, ref bool __result) { CorpseInteraction component = ((Component)__instance).GetComponent<CorpseInteraction>(); if (!Object.op_Implicit((Object)(object)component) || !component.HelmetOnly) { return true; } IList list = ReadField(__0, "m_supportedTypes") as IList; if (__1 != null && ((object)Unsafe.As<ItemType, ItemType>(ref __1.m_shared.m_itemType)/*cast due to .constrained prefix*/).ToString() == "Helmet" && (string.Equals(Convert.ToString(ReadField(__0, "m_slot")), "Helmet", StringComparison.OrdinalIgnoreCase) || (list != null && list.Cast<object>().Any((object t) => t.ToString() == "Helmet")))) { return true; } __result = false; return false; } private static void AlignStaticHelmet(VisEquipment __instance) { CorpseHelmetMount componentInParent = ((Component)__instance).GetComponentInParent<CorpseHelmetMount>(); if (!Object.op_Implicit((Object)(object)componentInParent) || (Object)(object)componentInParent.Visual != (Object)(object)__instance) { return; } try { componentInParent.Align(); SetField(__instance, "m_helmet", componentInParent.Joint); } catch (Exception ex) { HelmetLog.LogWarning((object)ex); } } private static void StandVisualChanged(ArmorStand __instance) { CorpseHelmetMount component = ((Component)__instance).GetComponent<CorpseHelmetMount>(); if (Object.op_Implicit((Object)(object)component)) { component.Align(); } CorpseGroom componentInParent = ((Component)__instance).GetComponentInParent<CorpseGroom>(); if (Object.op_Implicit((Object)(object)componentInParent)) { try { componentInParent.SyncBody(); } catch (Exception ex) { StandLog.LogWarning((object)ex); } } try { CorpseGroom.SyncGroom(__instance); } catch (Exception ex2) { StandLog.LogWarning((object)("Groom sync: " + ex2)); } } private static bool UpdateServerVisuals(VisEquipment __instance) { if (Headless) { return !CorpsePermissions.IsCorpse((Component)(object)__instance); } return true; } private static FieldInfo Field(Type type, string name) { return type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } private static object ReadField(object instance, string name) { if (instance != null) { return Field(instance.GetType(), name)?.GetValue(instance); } return null; } private static bool Visible(Transform t, Transform root) { while (Object.op_Implicit((Object)(object)t) && (Object)(object)t != (Object)(object)root) { if (!((Component)t).gameObject.activeSelf) { return false; } t = t.parent; } return (Object)(object)t == (Object)(object)root; } private static bool IsGroomVisual(Transform node, Transform root) { while (Object.op_Implicit((Object)(object)node) && (Object)(object)node != (Object)(object)root) { string name = ((Object)node).name; if (name.StartsWith("Hair", StringComparison.OrdinalIgnoreCase) || name.StartsWith("Beard", StringComparison.OrdinalIgnoreCase)) { return true; } node = node.parent; } return false; } private static void SetField(object o, string name, object value) { if (o != null) { FieldInfo field = o.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && field.FieldType.IsInstanceOfType(value)) { field.SetValue(o, value); } } } private Sprite Icon(GameObject root, int pose, Sprite fallback) { //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Expected O, but got Unknown //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Expected O, but got Unknown //IL_0185: 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_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: 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_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: 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) if (Headless) { return fallback; } GameObject val = null; try { string text; using (SHA256 sHA = SHA256.Create()) { using MemoryStream memoryStream = new MemoryStream(); Assembly assembly = typeof(Corpse01).Assembly; string[] array = ((pose != 6) ? new string[2] { "Corpse01.Poses.body_" + pose + ".pose", "Corpse01.Poses.body_" + pose + "_weapons.wpt" } : new string[1] { "Corpse01.Meshes.body_6.mesh.gz" }); foreach (string name in array) { using Stream stream = assembly.GetManifestResourceStream(name); stream?.CopyTo(memoryStream); } text = BitConverter.ToString(sHA.ComputeHash(memoryStream.ToArray()), 0, 8).Replace("-", ""); } val = new GameObject("Corpse01_Preview_" + pose + "_" + text); MeshRenderer[] componentsInChildren = root.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val2 in componentsInChildren) { if (((Renderer)val2).enabled && !((Renderer)val2).forceRenderingOff && Visible(((Component)val2).transform, root.transform)) { MeshFilter component = ((Component)val2).GetComponent<MeshFilter>(); if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMesh)) { Matrix4x4 val3 = root.transform.worldToLocalMatrix * ((Component)val2).transform.localToWorldMatrix; GameObject val4 = new GameObject("PreviewMesh"); val4.transform.SetParent(val.transform, false); val4.transform.localPosition = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(Vector3.zero); val4.transform.localRotation = ((Matrix4x4)(ref val3)).rotation; val4.transform.localScale = ((Matrix4x4)(ref val3)).lossyScale; val4.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh; MeshRenderer to = val4.AddComponent<MeshRenderer>(); CorpseStaticMeshes.CopyPreview(val2, to); } } } if (val.transform.childCount == 0) { throw new Exception("No visible mesh for icon"); } RenderRequest val5 = new RenderRequest(val) { Rotation = RenderManager.IsometricRotation, UseCache = true, TargetPlugin = ((BaseUnityPlugin)this).Info.Metadata }; Sprite obj = RenderManager.Instance.Render(val5); if (!Object.op_Implicit((Object)(object)obj)) { throw new Exception("RenderManager returned no sprite"); } return obj; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Body " + pose + " icon: " + ex.Message)); return fallback; } finally { if (Object.op_Implicit((Object)(object)val)) { Object.DestroyImmediate((Object)(object)val); } } } private void Register() { try { GameObject val = PrefabManager.Instance.GetPrefab("Player"); if (!Object.op_Implicit((Object)(object)val)) { val = ((IEnumerable<GameObject>)Resources.FindObjectsOfTypeAll<GameObject>()).FirstOrDefault((Func<GameObject, bool>)((GameObject g) => ((Object)g).name == "Player" && Object.op_Implicit((Object)(object)g.GetComponent("Player")))); } if (!Object.op_Implicit((Object)(object)val)) { throw new Exception("Vanilla Player prefab not found"); } GameObject prefab = PrefabManager.Instance.GetPrefab("ArmorStand"); if (!Object.op_Implicit((Object)(object)prefab) || !Object.op_Implicit((Object)(object)prefab.GetComponentInChildren<ArmorStand>(true))) { throw new Exception("Vanilla ArmorStand prefab not found"); } if (ExportBlender) { WeaponVisuals.ExportLibrary(DebugInfo, delegate(string m) { ((BaseUnityPlugin)this).Logger.LogWarning((object)m); }); } registeredCount = 0; int[] retainedPoses = RetainedPoses; for (int num = 0; num < retainedPoses.Length; num++) { int num2 = retainedPoses[num]; if (num2 == 6) { RegisterStatic(val, prefab, num2); } else { RegisterSingle(val, prefab, "prop_boby_" + num2, "$corpse_body_" + num2, "$corpse_desc", num2); } } if (registeredCount == RetainedPoses.Length) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Registered " + registeredCount + "/" + RetainedPoses.Length + " bodies.")); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Registered " + registeredCount + "/" + RetainedPoses.Length + " bodies. See registration errors above.")); } PrefabManager.OnVanillaPrefabsAvailable -= Register; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Corpse registration failed: " + ex)); PoseBridge.Status("Registration failed: " + ex); } } private void RegisterStatic(GameObject source, GameObject standSource, int id) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_068f: Unknown result type (might be due to invalid IL or missing references) //IL_0694: Unknown result type (might be due to invalid IL or missing references) //IL_06ab: Unknown result type (might be due to invalid IL or missing references) //IL_06b6: Unknown result type (might be due to invalid IL or missing references) //IL_06c1: Unknown result type (might be due to invalid IL or missing references) //IL_06cc: Unknown result type (might be due to invalid IL or missing references) //IL_06eb: Unknown result type (might be due to invalid IL or missing references) //IL_06f2: Unknown result type (might be due to invalid IL or missing references) //IL_06ff: Expected O, but got Unknown //IL_0708: Unknown result type (might be due to invalid IL or missing references) //IL_0712: Expected O, but got Unknown //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0343: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_0360: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_0371: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Unknown result type (might be due to invalid IL or missing references) //IL_03d6: Unknown result type (might be due to invalid IL or missing references) //IL_03f8: Unknown result type (might be due to invalid IL or missing references) //IL_03fd: Unknown result type (might be due to invalid IL or missing references) //IL_0402: Unknown result type (might be due to invalid IL or missing references) GameObject val = null; try { val = PrefabManager.Instance.CreateClonedPrefab("prop_boby_" + id, standSource); if (!Object.op_Implicit((Object)(object)val)) { throw new Exception("Cannot clone armor stand"); } val.transform.localScale = Vector3.one; ArmorStand component = val.GetComponent<ArmorStand>(); if (!Object.op_Implicit((Object)(object)component)) { throw new Exception("Missing ArmorStand"); } object obj = ReadField(component, "m_visEquipment"); VisEquipment val2 = (VisEquipment)((obj is VisEquipment) ? obj : null); if (!Object.op_Implicit((Object)(object)val2)) { val2 = val.GetComponentInChildren<VisEquipment>(true); } if (!Object.op_Implicit((Object)(object)val2)) { throw new Exception("Missing VisEquipment"); } Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true); foreach (Renderer obj2 in componentsInChildren) { obj2.enabled = false; obj2.forceRenderingOff = true; } Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = false; } Behaviour[] componentsInChildren3 = val.GetComponentsInChildren<Behaviour>(true); foreach (Behaviour val3 in componentsInChildren3) { if (((object)val3).GetType().Name == "Animator") { val3.enabled = false; } } SetField(component, "m_name", "$corpse_body_" + id); SetField(component, "m_visEquipment", val2); CorpseInteraction corpseInteraction = val.AddComponent<CorpseInteraction>(); corpseInteraction.Stand = component; corpseInteraction.HelmetOnly = true; Transform val4 = StaticBodies.AddVisual(source, val, id, ExportBlender, DebugInfo, delegate(string m) { ((BaseUnityPlugin)this).Logger.LogWarning((object)m); }); try { object obj3 = ReadField(source.GetComponentInChildren<VisEquipment>(true), "m_helmet"); Transform val5 = (Transform)((obj3 is Transform) ? obj3 : null); SkinnedMeshRenderer val6 = (from r in source.GetComponentsInChildren<SkinnedMeshRenderer>(true) where Object.op_Implicit((Object)(object)r.sharedMesh) && r.bones.Any((Transform t) => Object.op_Implicit((Object)(object)t) && ((Object)t).name == "Hips") && r.bones.Any((Transform t) => Object.op_Implicit((Object)(object)t) && ((Object)t).name == "LeftUpLeg") orderby r.bones.Length descending select r).FirstOrDefault(); Transform val7 = (Object.op_Implicit((Object)(object)val6) ? ((IEnumerable<Transform>)val6.bones).FirstOrDefault((Func<Transform, bool>)((Transform t) => Object.op_Implicit((Object)(object)t) && ((Object)t).name == "Head")) : null); object obj4 = ReadField(val2, "m_helmet"); Transform val8 = (Transform)((obj4 is Transform) ? obj4 : null); object obj5 = ReadField(val2, "m_bodyModel"); SkinnedMeshRenderer val9 = (SkinnedMeshRenderer)((obj5 is SkinnedMeshRenderer) ? obj5 : null); Transform val10 = (Object.op_Implicit((Object)(object)val9) ? ((IEnumerable<Transform>)val9.bones).FirstOrDefault((Func<Transform, bool>)((Transform t) => Object.op_Implicit((Object)(object)t) && ((Object)t).name == "Head")) : null); if (!Object.op_Implicit((Object)(object)val10)) { val10 = ((IEnumerable<Transform>)val.GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Head")); } CorpseHelmetMount corpseHelmetMount = val.AddComponent<CorpseHelmetMount>(); corpseHelmetMount.Visual = val2; corpseHelmetMount.Head = val4; corpseHelmetMount.NativeHead = val10; corpseHelmetMount.Driver = val9; if (!Object.op_Implicit((Object)(object)val8)) { val8 = new GameObject("HelmetMount").transform; val8.SetParent(val4, false); } corpseHelmetMount.Joint = val8; if (Object.op_Implicit((Object)(object)val5) && Object.op_Implicit((Object)(object)val7)) { corpseHelmetMount.Offset = Quaternion.Inverse(val7.rotation) * (val5.position - val7.position); corpseHelmetMount.Rotation = Quaternion.Inverse(val7.rotation) * val5.rotation; } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Body 6: using exported head joint without native offset"); } corpseHelmetMount.Align(); SetField(val2, "m_helmet", val8); object obj6 = ReadField(val2, "m_helmet"); if ((Object)((obj6 is Transform) ? obj6 : null) != (Object)(object)val8) { throw new Exception("Helmet mount binding failed"); } PoseBridge.Status("Body 6: baked head=" + ((object)val4.localPosition/*cast due to .constrained prefix*/).ToString() + ", helmet=" + ((object)val.transform.InverseTransformPoint(val8.position)/*cast due to .constrained prefix*/).ToString() + ", native head=" + (Object.op_Implicit((Object)(object)val10) ? ((Object)val10).name : "none")); IList obj7 = (ReadField(component, "m_slots") as IList) ?? throw new Exception("ArmorStand slots unavailable"); int num = 0; foreach (object item in obj7) { IList list = ReadField(item, "m_supportedTypes") as IList; if (string.Equals(Convert.ToString(ReadField(item, "m_slot")), "Helmet", StringComparison.OrdinalIgnoreCase) || (list != null && list.Cast<object>().Any((object t) => t.ToString() == "Helmet"))) { num++; continue; } object obj8 = ReadField(item, "m_switch"); Switch val11 = (Switch)((obj8 is Switch) ? obj8 : null); if (Object.op_Implicit((Object)(object)val11)) { ((Behaviour)val11).enabled = false; } } if (num == 0) { throw new Exception("No native helmet slot identified"); } DebugInfo("Static body " + id + ": helmet mount configured; compatible slots=" + num); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Static body " + id + ": helmet setup failed; continuing piece registration: " + ex)); PoseBridge.Status("Static body " + id + ": helmet setup failed; continuing piece registration: " + ex); } if (!Object.op_Implicit((Object)(object)val.GetComponent<ZNetView>())) { throw new Exception("ArmorStand network view missing"); } SetField(val.GetComponent<ZNetView>(), "m_persistent", true); Piece component2 = val.GetComponent<Piece>(); if (!Object.op_Implicit((Object)(object)component2)) { throw new Exception("ArmorStand piece missing"); } FieldInfo fieldInfo = Field(typeof(Piece), "m_craftingStation"); if (fieldInfo != null) { fieldInfo.SetValue(component2, null); } SetField(component2, "m_resources", Array.Empty<Requirement>()); SetField(component2, "m_canBeRemoved", true); SetField(component2, "m_groundPiece", false); SetField(component2, "m_groundOnly", false); SetField(component2, "m_noInWater", false); CorpseAdminBuild.RelaxPiece(component2); PieceConfig val12 = new PieceConfig { Name = "$corpse_body_" + id, Description = "$corpse_desc", Category = "LootBodies", PieceTable = "Hammer", Icon = Icon(val, id, (Sprite)/*isinst with value type is only supported in some contexts*/), AllowedInDungeons = true, Requirements = Array.Empty<RequirementConfig>() }; if (!PieceManager.Instance.AddPiece(new CustomPiece(val, false, val12))) { throw new Exception("Jotunn rejected static body"); } registeredCount++; DebugInfo("Static body " + id + ": piece registered; no primitive cube"); PoseBridge.Status("Static body " + id + ": piece registered"); } catch (Exception ex2) { ((BaseUnityPlugin)this).Logger.LogError((object)("Static body " + id + ": " + ex2)); PoseBridge.Status("Static body " + id + ": " + ex2); if (Object.op_Implicit((Object)(object)val)) { Object.DestroyImmediate((Object)(object)val); } } } private void RegisterSingle(GameObject source, GameObject standSource, string prefabName, string locName, string locDesc, int poseIndex) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0278: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Expected O, but got Unknown //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Expected O, but got Unknown GameObject val = null; try { val = PrefabManager.Instance.CreateClonedPrefab(prefabName, standSource); val.transform.localScale = Vector3.one; ArmorStand componentInChildren = val.GetComponentInChildren<ArmorStand>(true); if (!Object.op_Implicit((Object)(object)componentInChildren) || (Object)(object)((Component)componentInChildren).gameObject != (Object)(object)val) { throw new Exception("ArmorStand component must be on the piece root"); } object obj = ReadField(componentInChildren, "m_visEquipment"); VisEquipment val2 = (VisEquipment)((obj is VisEquipment) ? obj : null); if (!Object.op_Implicit((Object)(object)val2)) { val2 = val.GetComponentInChildren<VisEquipment>(true); } if (!Object.op_Implicit((Object)(object)val2)) { throw new Exception("ArmorStand VisEquipment missing"); } Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true); foreach (Renderer obj2 in componentsInChildren) { obj2.enabled = false; obj2.forceRenderingOff = true; } Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = false; } Behaviour[] componentsInChildren3 = val.GetComponentsInChildren<Behaviour>(true); foreach (Behaviour val3 in componentsInChildren3) { if (((object)val3).GetType().Name == "Animator") { val3.enabled = false; } } SetField(componentInChildren, "m_name", locName); SetField(componentInChildren, "m_visEquipment", val2); CorpseGroom corpseGroom = val.AddComponent<CorpseGroom>(); corpseGroom.Visual = val2; corpseGroom.Mount = BuildVisual(source, val, poseIndex, val2, corpseGroom); val.AddComponent<CorpseInteraction>().Stand = componentInChildren; if (!Object.op_Implicit((Object)(object)val.GetComponent<ZNetView>())) { throw new Exception("ArmorStand network view missing"); } SetField(val.GetComponent<ZNetView>(), "m_persistent", true); Piece component = val.GetComponent<Piece>(); if (!Object.op_Implicit((Object)(object)component)) { throw new Exception("ArmorStand piece missing"); } FieldInfo fieldInfo = Field(typeof(Piece), "m_craftingStation"); if (fieldInfo != null) { fieldInfo.SetValue(component, null); } SetField(component, "m_resources", Array.Empty<Requirement>()); SetField(component, "m_canBeRemoved", true); SetField(component, "m_groundPiece", false); SetField(component, "m_groundOnly", false); SetField(component, "m_noInWater", false); CorpseAdminBuild.RelaxPiece(component); PieceConfig val4 = new PieceConfig { Name = locName, Description = locDesc, Category = "LootBodies", PieceTable = "Hammer", Icon = Icon(val, poseIndex, (Sprite)/*isinst with value type is only supported in some contexts*/), AllowedInDungeons = true, Requirements = Array.Empty<RequirementConfig>() }; if (!PieceManager.Instance.AddPiece(new CustomPiece(val, false, val4))) { throw new Exception("Jotunn rejected custom body piece"); } registeredCount++; DebugInfo("Registered " + prefabName + " in LootBodies hammer category with native ArmorStand."); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Corpse registration failed for " + prefabName + ": " + ex)); PoseBridge.Status("Registration failed for " + prefabName + ": " + ex); if (Object.op_Implicit((Object)(object)val)) { Object.DestroyImmediate((Object)(object)val); } } } private static Mesh SkinToLocal(SkinnedMeshRenderer skin, Transform frame) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0119: 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_0127: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0332: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_0354: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0373: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_039b: Unknown result type (might be due to invalid IL or missing references) //IL_03a0: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_040b: Unknown result type (might be due to invalid IL or missing references) //IL_03da: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Unknown result type (might be due to invalid IL or missing references) //IL_0417: Unknown result type (might be due to invalid IL or missing references) //IL_041c: Unknown result type (might be due to invalid IL or missing references) //IL_0423: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Unknown result type (might be due to invalid IL or missing references) //IL_042f: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Unknown result type (might be due to invalid IL or missing references) //IL_04bf: Unknown result type (might be due to invalid IL or missing references) //IL_04cb: Unknown result type (might be due to invalid IL or missing references) //IL_04d0: Unknown result type (might be due to invalid IL or missing references) //IL_04e7: Unknown result type (might be due to invalid IL or missing references) //IL_04ec: Unknown result type (might be due to invalid IL or missing references) //IL_0503: Unknown result type (might be due to invalid IL or missing references) //IL_0508: Unknown result type (might be due to invalid IL or missing references) //IL_0513: Unknown result type (might be due to invalid IL or missing references) //IL_051f: Unknown result type (might be due to invalid IL or missing references) //IL_052b: Unknown result type (might be due to invalid IL or missing references) //IL_0543: Unknown result type (might be due to invalid IL or missing references) //IL_0548: Unknown result type (might be due to invalid IL or missing references) Mesh sharedMesh = skin.sharedMesh; Matrix4x4 inverse; if (!sharedMesh.isReadable) { Mesh val = new Mesh(); skin.updateWhenOffscreen = true; skin.BakeMesh(val, false); Matrix4x4 val2 = frame.worldToLocalMatrix * ((Component)skin).transform.localToWorldMatrix; Vector3[] vertices = val.vertices; Vector3[] normals = val.normals; Vector4[] tangents = val.tangents; inverse = ((Matrix4x4)(ref val2)).inverse; Matrix4x4 transpose = ((Matrix4x4)(ref inverse)).transpose; for (int i = 0; i < vertices.Length; i++) { vertices[i] = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(vertices[i]); } Vector3 val3; for (int j = 0; j < normals.Length; j++) { int num = j; val3 = ((Matrix4x4)(ref transpose)).MultiplyVector(normals[j]); normals[num] = ((Vector3)(ref val3)).normalized; } for (int k = 0; k < tangents.Length; k++) { val3 = ((Matrix4x4)(ref val2)).MultiplyVector(new Vector3(tangents[k].x, tangents[k].y, tangents[k].z)); Vector3 normalized = ((Vector3)(ref val3)).normalized; tangents[k] = new Vector4(normalized.x, normalized.y, normalized.z, tangents[k].w); } val.vertices = vertices; if (normals.Length == vertices.Length) { val.normals = normals; } if (tangents.Length == vertices.Length) { val.tangents = tangents; } val.RecalculateBounds(); return val; } Vector3[] vertices2 = sharedMesh.vertices; Vector3[] normals2 = sharedMesh.normals; Vector4[] tangents2 = sharedMesh.tangents; BoneWeight[] boneWeights = sharedMesh.boneWeights; Matrix4x4[] bindposes = sharedMesh.bindposes; Transform[] bones = skin.bones; if (boneWeights.Length != vertices2.Length || bones.Length != bindposes.Length) { throw new Exception("Unsupported body skin weights: " + ((Object)skin).name); } for (int l = 0; l < sharedMesh.blendShapeCount; l++) { float blendShapeWeight = skin.GetBlendShapeWeight(l); int blendShapeFrameCount = sharedMesh.GetBlendShapeFrameCount(l); if (Mathf.Abs(blendShapeWeight) < 0.001f || blendShapeFrameCount == 0) { continue; } int num2 = blendShapeFrameCount - 1; float blendShapeFrameWeight = sharedMesh.GetBlendShapeFrameWeight(l, num2); if (Mathf.Abs(blendShapeFrameWeight) < 0.001f) { continue; } Vector3[] array = (Vector3[])(object)new Vector3[vertices2.Length]; Vector3[] array2 = (Vector3[])(object)new Vector3[vertices2.Length]; Vector3[] array3 = (Vector3[])(object)new Vector3[vertices2.Length]; sharedMesh.GetBlendShapeFrameVertices(l, num2, array, array2, array3); float num3 = blendShapeWeight / blendShapeFrameWeight; for (int m = 0; m < vertices2.Length; m++) { ref Vector3 reference = ref vertices2[m]; reference += array[m] * num3; if (normals2.Length == vertices2.Length) { ref Vector3 reference2 = ref normals2[m]; reference2 += array2[m] * num3; } } } Matrix4x4[] matrices = (Matrix4x4[])(object)new Matrix4x4[bones.Length]; Matrix4x4[] normalMatrices = (Matrix4x4[])(object)new Matrix4x4[bones.Length]; for (int n = 0; n < bones.Length; n++) { if (!Object.op_Implicit((Object)(object)bones[n])) { throw new Exception("Missing skin bone"); } matrices[n] = frame.worldToLocalMatrix * bones[n].localToWorldMatrix * bindposes[n]; Matrix4x4[] array4 = normalMatrices; int num4 = n; inverse = ((Matrix4x4)(ref matrices[n])).inverse; array4[num4] = ((Matrix4x4)(ref inverse)).transpose; } for (int num5 = 0; num5 < vertices2.Length; num5++) { BoneWeight val4 = boneWeights[num5]; Vector3 v = vertices2[num5]; Vector3 n2 = ((normals2.Length == vertices2.Length) ? normals2[num5] : Vector3.zero); Vector3 tangent = (Vector3)((tangents2.Length == vertices2.Length) ? new Vector3(tangents2[num5].x, tangents2[num5].y, tangents2[num5].z) : Vector3.zero); Vector3 p = Vector3.zero; Vector3 nn = Vector3.zero; Vector3 tt = Vector3.zero; float sum = 0f; Add(((BoneWeight)(ref val4)).boneIndex0, ((BoneWeight)(ref val4)).weight0); Add(((BoneWeight)(ref val4)).boneIndex1, ((BoneWeight)(ref val4)).weight1); Add(((BoneWeight)(ref val4)).boneIndex2, ((BoneWeight)(ref val4)).weight2); Add(((BoneWeight)(ref val4)).boneIndex3, ((BoneWeight)(ref val4)).weight3); if (sum < 0.0001f) { throw new Exception("Unweighted vertex in body mesh"); } vertices2[num5] = p / sum; if (normals2.Length == vertices2.Length) { normals2[num5] = ((Vector3)(ref nn)).normalized; } if (tangents2.Length == vertices2.Length) { tt = ((Vector3)(ref tt)).normalized; tangents2[num5] = new Vector4(tt.x, tt.y, tt.z, tangents2[num5].w); } void Add(int b, float a) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) if (!(a <= 0f)) { p += ((Matrix4x4)(ref matrices[b])).MultiplyPoint3x4(v) * a; nn += ((Matrix4x4)(ref normalMatrices[b])).MultiplyVector(n2) * a; tt += ((Matrix4x4)(ref matrices[b])).MultiplyVector(tangent) * a; sum += a; } } } Mesh val5 = Object.Instantiate<Mesh>(sharedMesh); val5.ClearBlendShapes(); val5.vertices = vertices2; if (normals2.Length == vertices2.Length) { val5.normals = normals2; } else { val5.RecalculateNormals(); } if (tangents2.Length == vertices2.Length) { val5.tangents = tangents2; } val5.RecalculateBounds(); return val5; } private unsafe Transform BuildVisual(GameObject source, GameObject root, int poseIndex, VisEquipment targetVis, CorpseGroom appearance) { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Expected O, but got Unknown //IL_0276: Unknown result type (might be due to invalid IL or missing references) //IL_05e1: Unknown result type (might be due to invalid IL or missing references) //IL_05ed: Unknown result type (might be due to invalid IL or missing references) //IL_05f2: Unknown result type (might be due to invalid IL or missing references) //IL_05f7: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Expected O, but got Unknown //IL_057a: Unknown result type (might be due to invalid IL or missing references) //IL_0588: Unknown result type (might be due to invalid IL or missing references) //IL_058d: Unknown result type (might be due to invalid IL or missing references) //IL_0592: Unknown result type (might be due to invalid IL or missing references) //IL_0596: Unknown result type (might be due to invalid IL or missing references) //IL_08a2: Unknown result type (might be due to invalid IL or missing references) //IL_08a7: Unknown result type (might be due to invalid IL or missing references) //IL_0aba: Unknown result type (might be due to invalid IL or missing references) //IL_0adf: Unknown result type (might be due to invalid IL or missing references) //IL_0b04: Unknown result type (might be due to invalid IL or missing references) //IL_0b29: Unknown result type (might be due to invalid IL or missing references) //IL_0b4e: Unknown result type (might be due to invalid IL or missing references) //IL_0d47: Unknown result type (might be due to invalid IL or missing references) //IL_0d5b: Unknown result type (might be due to invalid IL or missing references) //IL_0d6f: Unknown result type (might be due to invalid IL or missing references) //IL_0d83: Unknown result type (might be due to invalid IL or missing references) //IL_0d97: Unknown result type (might be due to invalid IL or missing references) //IL_0dcb: Unknown result type (might be due to invalid IL or missing references) //IL_0ddf: Unknown result type (might be due to invalid IL or missing references) //IL_0df3: Unknown result type (might be due to invalid IL or missing references) //IL_0e12: Unknown result type (might be due to invalid IL or missing references) //IL_0e26: Unknown result type (might be due to invalid IL or missing references) //IL_0e3a: Unknown result type (might be due to invalid IL or missing references) //IL_0e59: Unknown result type (might be due to invalid IL or missing references) //IL_0e6d: Unknown result type (might be due to invalid IL or missing references) //IL_0e8c: Unknown result type (might be due to invalid IL or missing references) //IL_0ea0: Unknown result type (might be due to invalid IL or missing references) //IL_0ebf: Unknown result type (might be due to invalid IL or missing references) //IL_0ed3: Unknown result type (might be due to invalid IL or missing references) //IL_0ef2: Unknown result type (might be due to invalid IL or missing references) //IL_0f11: Unknown result type (might be due to invalid IL or missing references) //IL_0bd4: Unknown result type (might be due to invalid IL or missing references) //IL_0bf9: Unknown result type (might be due to invalid IL or missing references) //IL_0c1e: Unknown result type (might be due to invalid IL or missing references) //IL_0c43: Unknown result type (might be due to invalid IL or missing references) //IL_0c68: Unknown result type (might be due to invalid IL or missing references) //IL_0c8d: Unknown result type (might be due to invalid IL or missing references) //IL_0cb2: Unknown result type (might be due to invalid IL or missing references) //IL_0cd7: Unknown result type (might be due to invalid IL or missing references) //IL_0cfc: Unknown result type (might be due to invalid IL or missing references) //IL_0d21: Unknown result type (might be due to invalid IL or missing references) //IL_0b71: Unknown result type (might be due to invalid IL or missing references) //IL_0b76: Unknown result type (might be due to invalid IL or missing references) //IL_0b7b: Unknown result type (might be due to invalid IL or missing references) //IL_0b80: Unknown result type (might be due to invalid IL or missing references) //IL_0b8b: Unknown result type (might be due to invalid IL or missing references) //IL_0b90: Unknown result type (might be due to invalid IL or missing references) //IL_0b95: Unknown result type (might be due to invalid IL or missing references) //IL_0b9a: Unknown result type (might be due to invalid IL or missing references) //IL_0b9f: Unknown result type (might be due to invalid IL or missing references) //IL_0baa: Unknown result type (might be due to invalid IL or missing references) //IL_0baf: Unknown result type (might be due to invalid IL or missing references) //IL_0a01: Unknown result type (might be due to invalid IL or missing references) //IL_0a06: Unknown result type (might be due to invalid IL or missing references) //IL_0a0b: Unknown result type (might be due to invalid IL or missing references) //IL_0a10: Unknown result type (might be due to invalid IL or missing references) //IL_0946: Unknown result type (might be due to invalid IL or missing references) //IL_094d: Unknown result type (might be due to invalid IL or missing references) //IL_0952: Unknown result type (might be due to invalid IL or missing references) //IL_0957: Unknown result type (might be due to invalid IL or missing references) //IL_095b: Unknown result type (might be due to invalid IL or missing references) //IL_0960: Unknown result type (might be due to invalid IL or missing references) //IL_0964: Unknown result type (might be due to invalid IL or missing references) //IL_096b: Unknown result type (might be due to invalid IL or missing references) //IL_0970: Unknown result type (might be due to invalid IL or missing references) //IL_0975: Unknown result type (might be due to invalid IL or missing references) //IL_0977: Unknown result type (might be due to invalid IL or missing references) //IL_097c: Unknown result type (might be due to invalid IL or missing references) //IL_0980: Unknown result type (might be due to invalid IL or missing references) //IL_0985: Unknown result type (might be due to invalid IL or missing references) //IL_0987: Unknown result type (might be due to invalid IL or missing references) //IL_0989: Unknown result type (might be due to in