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 RuinedBodies v1.0.0
BepInEx/plugins/RuinedBodies/RuinedBodies.dll
Decompiled 11 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Collections; using Unity.Netcode; using UnityEngine; [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("erockuli")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright © 2026 erockuli")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("RuinedBodies")] [assembly: AssemblyTitle("RuinedBodies")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace RuinedBodies { [BepInPlugin("chatgpt.ruinedbodies", "Ruined Bodies", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class RuinedBodiesPlugin : BaseUnityPlugin { [HarmonyPatch] private static class NetworkObjectSpawnPatch { private static IEnumerable<MethodBase> TargetMethods() { return from method in AccessTools.GetDeclaredMethods(typeof(NetworkObject)) where method.Name == "Spawn" select method; } private static void Postfix(NetworkObject __instance) { Instance?.OnNetworkObjectSpawned(__instance); } } [HarmonyPatch] private static class LocalNetworkSpawnPatch { private static IEnumerable<MethodBase> TargetMethods() { return from method in AccessTools.GetDeclaredMethods(typeof(NetworkSpawnManager)) where method.Name.IndexOf("SpawnNetworkObjectLocally", StringComparison.OrdinalIgnoreCase) >= 0 select method; } private static void Postfix(object[] __args) { RuinedBodiesPlugin instance = Instance; if ((Object)(object)instance == (Object)null || __args == null) { return; } foreach (object obj in __args) { NetworkObject val = (NetworkObject)((obj is NetworkObject) ? obj : null); if (val != null) { instance.OnNetworkObjectSpawned(val); break; } if (obj is ulong key) { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton != (Object)null && singleton.SpawnManager != null && singleton.SpawnManager.SpawnedObjects.TryGetValue(key, out var value) && (Object)(object)value != (Object)null) { instance.OnNetworkObjectSpawned(value); break; } } } } } [HarmonyPatch] private static class RuinedVisualLifecyclePatch { private static readonly string[] TargetNames = new string[5] { "Start", "GrabItem", "EquipItem", "DiscardItem", "OnNetworkSpawn" }; private static IEnumerable<MethodBase> TargetMethods() { return from method in AccessTools.GetDeclaredMethods(typeof(GrabbableObject)) where TargetNames.Contains(method.Name) select method; } [HarmonyPostfix] private static void Postfix(GrabbableObject __instance) { Instance?.EnforceKnownRuinedVisual(__instance); } } [HarmonyPatch(typeof(GrabbableObject), "SetScrapValue")] private static class RuinedScrapValuePatch { [HarmonyPrefix] private static void Prefix(GrabbableObject __instance, ref int __0) { RuinedBodiesPlugin instance = Instance; if ((Object)(object)instance != (Object)null && instance.IsKnownRuinedItem(__instance)) { __0 = 0; } } [HarmonyPostfix] private static void Postfix(GrabbableObject __instance) { Instance?.EnforceKnownRuinedItem(__instance); } } public const string PluginGuid = "chatgpt.ruinedbodies"; public const string PluginName = "Ruined Bodies"; public const string PluginVersion = "1.0.0"; private const string RuinedDecisionMessage = "chatgpt.ruinedbodies.RuinedDecision.v1"; private const float SweepIntervalSeconds = 2f; private const float MaintenanceIntervalSeconds = 0.5f; private const string RuinedPrefix = "Ruined "; private const string GutsVisualObjectName = "RuinedGutsPileVisual"; private const string ZeroValueText = "Value: $0"; private Harmony _harmony; private ConfigEntry<int> _ruinedChancePercent; private ConfigEntry<bool> _replaceVisualWithGuts; private ConfigEntry<bool> _invertGutsColors; private ConfigEntry<string> _matchNameFragment; private ConfigEntry<string> _excludedNameFragments; private ConfigEntry<bool> _logAllGrabbableSpawns; private ConfigEntry<bool> _logBodyDecisions; private NetworkManager _registeredNetworkManager; private bool _messageHandlerRegistered; private bool _clientConnectedCallbackRegistered; private float _nextSweepTime; private Coroutine _maintenanceCoroutine; private float _nextNetworkRegistrationWarningTime; private readonly HashSet<ulong> _processedServerNetworkIds = new HashSet<ulong>(); private readonly Dictionary<ulong, bool> _serverRuinedDecisions = new Dictionary<ulong, bool>(); private readonly Dictionary<ulong, bool> _clientRuinedDecisions = new Dictionary<ulong, bool>(); private readonly Dictionary<ulong, bool> _pendingClientDecisions = new Dictionary<ulong, bool>(); private readonly Dictionary<ScanNodeProperties, string> _originalScanHeaders = new Dictionary<ScanNodeProperties, string>(); private HashSet<string> _excludedFragments = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private string _bodyNameFragment = "body"; private static Mesh _lowPolyChunkMesh; private static Mesh _gutsTubeMeshA; private static Mesh _gutsTubeMeshB; private static Material[] _gutsMaterials; private static Texture2D _gutsTexture; internal static RuinedBodiesPlugin Instance { get; private set; } private void Awake() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown Instance = this; _ruinedChancePercent = ((BaseUnityPlugin)this).Config.Bind<int>("Ruined Bodies", "RuinedChancePercent", 80, new ConfigDescription("Percentage chance (0-100) that each detected monster body becomes ruined. Ruined bodies remain pick-up-able but have a scan name prefixed with 'Ruined' and a sale value of $0.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); _replaceVisualWithGuts = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "ReplaceRuinedBodyWithGutsPile", true, "When enabled, ruined bodies use a stylized low-poly guts-pile visual instead of the original body model. Set false to keep the original body appearance."); _invertGutsColors = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "InvertGutsColors", false, "Invert colours on the Ruined Bodies texture only. Disabled by default for the original red/burgundy palette; enable to use the teal/green/blue palette."); ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Migration", "InvertGutsColorsDefaultOffApplied", false, "Internal one-time migration marker; do not edit."); if (!val.Value) { _invertGutsColors.Value = false; val.Value = true; ((BaseUnityPlugin)this).Config.Save(); } _matchNameFragment = ((BaseUnityPlugin)this).Config.Bind<string>("Detection", "NameFragment", "body", "A spawned grabbable item is considered a monster body if its item name or GameObject name contains this text (case-insensitive)."); _excludedNameFragments = ((BaseUnityPlugin)this).Config.Bind<string>("Detection", "ExcludedNameFragments", "bodycam,body cam,body camera", "Comma-separated name fragments that should not be treated as monster bodies (for example, body cameras)."); _logAllGrabbableSpawns = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "LogAllGrabbableSpawns", false, "Log every spawned networked grabbable item's names. Enable temporarily if some body items are not being detected; this can make the log noisy."); _logBodyDecisions = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "LogBodyDecisions", true, "Log each detected body's ruined roll and final state."); RefreshDetectionConfig(); if (_replaceVisualWithGuts.Value) { EnsureGutsAssets(); } _harmony = new Harmony("chatgpt.ruinedbodies"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Loaded. All matched monster bodies remain pick-up-able. Host ruined chance: {_ruinedChancePercent.Value}%; guts-pile visual: {_replaceVisualWithGuts.Value}; invert texture colours: {_invertGutsColors.Value}."); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Performance: event-driven object processing is primary; network readiness maintenance runs every " + 0.5f.ToString("0.##") + "s and the full spawned-object fallback sweep runs every " + 2f.ToString("0.##") + "s (no per-frame Update polling).")); _maintenanceCoroutine = ((MonoBehaviour)this).StartCoroutine(MaintenanceLoop()); } private IEnumerator MaintenanceLoop() { WaitForSecondsRealtime wait = new WaitForSecondsRealtime(0.5f); while (true) { EnsureNetworkHandlerRegistration(); ApplyPendingClientDecisions(); if (Time.unscaledTime >= _nextSweepTime) { _nextSweepTime = Time.unscaledTime + 2f; SweepSpawnedObjects(); } yield return wait; } } private void OnDestroy() { if (_maintenanceCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(_maintenanceCoroutine); _maintenanceCoroutine = null; } CleanupNetworkHandlerRegistration(); if (_harmony != null) { _harmony.UnpatchSelf(); _harmony = null; } if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } private void RefreshDetectionConfig() { _bodyNameFragment = (string.IsNullOrWhiteSpace(_matchNameFragment.Value) ? "body" : _matchNameFragment.Value.Trim()); _excludedFragments = new HashSet<string>(from fragment in (_excludedNameFragments.Value ?? string.Empty).Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries) select fragment.Trim() into fragment where fragment.Length > 0 select fragment, StringComparer.OrdinalIgnoreCase); } internal void OnNetworkObjectSpawned(NetworkObject networkObject) { if ((Object)(object)networkObject == (Object)null || !networkObject.IsSpawned) { return; } EnsureNetworkHandlerRegistration(); GrabbableObject grabbableObject = GetGrabbableObject(networkObject); if ((Object)(object)grabbableObject == (Object)null) { return; } if (_logAllGrabbableSpawns.Value) { string arg = (((Object)(object)grabbableObject.itemProperties != (Object)null) ? grabbableObject.itemProperties.itemName : "<no item properties>"); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"[diagnostic] Grabbable spawn: object='{((Object)((Component)networkObject).gameObject).name}', item='{arg}', networkId={networkObject.NetworkObjectId}"); } if (!LooksLikeMonsterBody(grabbableObject)) { return; } ulong networkObjectId = networkObject.NetworkObjectId; NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null)) { grabbableObject.grabbable = true; bool value; if (singleton.IsServer) { ProcessServerBody(networkObject, grabbableObject); } else if (_clientRuinedDecisions.TryGetValue(networkObjectId, out value)) { ApplyDecisionToItem(grabbableObject, networkObjectId, value); _pendingClientDecisions.Remove(networkObjectId); } else if (_pendingClientDecisions.ContainsKey(networkObjectId)) { TryApplyClientDecisionToSpawnedObject(networkObjectId, _pendingClientDecisions[networkObjectId]); } } } private void ProcessServerBody(NetworkObject networkObject, GrabbableObject item) { if ((Object)(object)networkObject == (Object)null || (Object)(object)item == (Object)null) { return; } ulong networkObjectId = networkObject.NetworkObjectId; item.grabbable = true; if (_serverRuinedDecisions.TryGetValue(networkObjectId, out var value)) { ApplyDecisionToItem(item, networkObjectId, value); } else if (_processedServerNetworkIds.Add(networkObjectId)) { float num = Random.Range(0f, 100f); bool flag = num < (float)_ruinedChancePercent.Value; _serverRuinedDecisions[networkObjectId] = flag; ApplyDecisionToItem(item, networkObjectId, flag); if (_logBodyDecisions.Value) { string text = (((Object)(object)item.itemProperties != (Object)null) ? item.itemProperties.itemName : "<no item properties>"); string text2 = (flag ? "RUINED / VALUE $0" : "NORMAL BODY / ORIGINAL VALUE"); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Body roll for '{text}' (object '{((Object)((Component)networkObject).gameObject).name}', network ID {networkObjectId}): rolled {num:0.0}; ruined chance {_ruinedChancePercent.Value}%; {text2}"); } BroadcastRuinedDecision(networkObjectId, flag); } } private GrabbableObject GetGrabbableObject(NetworkObject networkObject) { if ((Object)(object)networkObject == (Object)null) { return null; } GrabbableObject val = ((Component)networkObject).GetComponent<GrabbableObject>(); if ((Object)(object)val == (Object)null) { val = ((Component)networkObject).GetComponentInChildren<GrabbableObject>(true); } return val; } private bool LooksLikeMonsterBody(GrabbableObject item) { if ((Object)(object)item == (Object)null) { return false; } string text = (((Object)(object)item.itemProperties != (Object)null) ? item.itemProperties.itemName : string.Empty); string text2 = (((Object)(object)((Component)item).gameObject != (Object)null) ? ((Object)((Component)item).gameObject).name : string.Empty); if (string.Equals(text.Trim(), "Body", StringComparison.OrdinalIgnoreCase) && text2.IndexOf("RagdollGrabbableObject", StringComparison.OrdinalIgnoreCase) >= 0) { return false; } string text3 = (text + " " + text2).ToLowerInvariant(); foreach (string excludedFragment in _excludedFragments) { if (text3.Contains(excludedFragment.ToLowerInvariant())) { return false; } } return text3.Contains(_bodyNameFragment.ToLowerInvariant()); } private void ApplyDecisionToItem(GrabbableObject item, ulong networkId, bool isRuined) { if ((Object)(object)item == (Object)null) { return; } item.grabbable = true; if (isRuined) { ApplyRuinedNameAndValue(item); if (_replaceVisualWithGuts.Value) { ReplaceOriginalVisualWithGutsPile(item); } } } private void ApplyRuinedNameAndValue(GrabbableObject item) { if ((Object)(object)item == (Object)null) { return; } item.scrapValue = 0; ScanNodeProperties[] componentsInChildren = ((Component)item).GetComponentsInChildren<ScanNodeProperties>(true); foreach (ScanNodeProperties val in componentsInChildren) { if ((Object)(object)val == (Object)null) { continue; } if (!_originalScanHeaders.TryGetValue(val, out var value)) { value = val.headerText; if (string.IsNullOrWhiteSpace(value)) { value = (((Object)(object)item.itemProperties != (Object)null) ? item.itemProperties.itemName : "Monster Body"); } value = RemoveRuinedPrefix(value); _originalScanHeaders[val] = value; } string text = "Ruined " + value; if (!string.Equals(val.headerText, text, StringComparison.Ordinal)) { val.headerText = text; } if (!string.Equals(val.subText, "Value: $0", StringComparison.Ordinal)) { val.subText = "Value: $0"; } if (val.scrapValue != 0) { val.scrapValue = 0; } } } private static string RemoveRuinedPrefix(string header) { if (string.IsNullOrWhiteSpace(header)) { return "Monster Body"; } string text = header.Trim(); while (text.StartsWith("Ruined ", StringComparison.OrdinalIgnoreCase)) { text = text.Substring("Ruined ".Length).TrimStart(); } if (!string.IsNullOrWhiteSpace(text)) { return text; } return "Monster Body"; } private void EnforceKnownRuinedItem(GrabbableObject item) { EnforceKnownRuinedVisual(item); } private void EnforceKnownRuinedVisual(GrabbableObject item) { if (!((Object)(object)item == (Object)null) && IsKnownRuinedItem(item)) { ApplyRuinedNameAndValue(item); if (_replaceVisualWithGuts.Value) { ReplaceOriginalVisualWithGutsPile(item); } } } private bool IsKnownRuinedItem(GrabbableObject item) { NetworkObject networkObject = GetNetworkObject(item); if ((Object)(object)networkObject == (Object)null) { return false; } NetworkManager singleton = NetworkManager.Singleton; bool value; if ((Object)(object)singleton != (Object)null && singleton.IsServer) { return _serverRuinedDecisions.TryGetValue(networkObject.NetworkObjectId, out value) && value; } bool value2; return _clientRuinedDecisions.TryGetValue(networkObject.NetworkObjectId, out value2) && value2; } private static NetworkObject GetNetworkObject(GrabbableObject item) { if ((Object)(object)item == (Object)null) { return null; } NetworkObject val = ((Component)item).GetComponent<NetworkObject>(); if ((Object)(object)val == (Object)null) { val = ((Component)item).GetComponentInParent<NetworkObject>(); } if ((Object)(object)val == (Object)null) { val = ((Component)item).GetComponentInChildren<NetworkObject>(true); } return val; } private void EnsureNetworkHandlerRegistration() { //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening) { if ((Object)(object)_registeredNetworkManager != (Object)null && ((Object)(object)singleton == (Object)null || singleton != _registeredNetworkManager || !_registeredNetworkManager.IsListening)) { CleanupNetworkHandlerRegistration(); } } else { if (singleton == _registeredNetworkManager && _messageHandlerRegistered && _clientConnectedCallbackRegistered) { return; } if ((Object)(object)_registeredNetworkManager != (Object)null && singleton != _registeredNetworkManager) { CleanupNetworkHandlerRegistration(); } else if ((Object)(object)_registeredNetworkManager != (Object)null) { UnregisterNetworkCallbacksKeepingState(); } _registeredNetworkManager = singleton; try { singleton.CustomMessagingManager.RegisterNamedMessageHandler("chatgpt.ruinedbodies.RuinedDecision.v1", new HandleNamedMessageDelegate(ReceiveRuinedDecision)); _messageHandlerRegistered = true; singleton.OnClientConnectedCallback += OnClientConnected; _clientConnectedCallbackRegistered = true; _nextNetworkRegistrationWarningTime = 0f; if (singleton.IsServer) { foreach (ulong connectedClientsId in singleton.ConnectedClientsIds) { if (connectedClientsId != singleton.LocalClientId) { SendAllExistingDecisionsToClient(connectedClientsId); } } } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Ruined-body multiplayer sync registered (server/host={singleton.IsServer}); host decisions and late-join replay are enabled."); } catch (Exception ex) { UnregisterNetworkCallbacksKeepingState(); if (Time.unscaledTime >= _nextNetworkRegistrationWarningTime) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not register ruined-body synchronization yet; will retry in 5 seconds: " + ex.Message)); _nextNetworkRegistrationWarningTime = Time.unscaledTime + 5f; } } } } private void UnregisterNetworkCallbacksKeepingState() { NetworkManager registeredNetworkManager = _registeredNetworkManager; if ((Object)(object)registeredNetworkManager == (Object)null) { _clientConnectedCallbackRegistered = false; _messageHandlerRegistered = false; return; } if (_clientConnectedCallbackRegistered) { try { registeredNetworkManager.OnClientConnectedCallback -= OnClientConnected; } catch { } _clientConnectedCallbackRegistered = false; } if (!_messageHandlerRegistered) { return; } try { if (registeredNetworkManager.IsListening) { registeredNetworkManager.CustomMessagingManager.UnregisterNamedMessageHandler("chatgpt.ruinedbodies.RuinedDecision.v1"); } } catch { } _messageHandlerRegistered = false; } private void CleanupNetworkHandlerRegistration() { UnregisterNetworkCallbacksKeepingState(); _registeredNetworkManager = null; _processedServerNetworkIds.Clear(); _serverRuinedDecisions.Clear(); _clientRuinedDecisions.Clear(); _pendingClientDecisions.Clear(); _originalScanHeaders.Clear(); _nextNetworkRegistrationWarningTime = 0f; } private void BroadcastRuinedDecision(ulong networkId, bool isRuined) { NetworkManager val = _registeredNetworkManager ?? NetworkManager.Singleton; if ((Object)(object)val == (Object)null || !val.IsServer) { return; } foreach (ulong connectedClientsId in val.ConnectedClientsIds) { if (connectedClientsId != val.LocalClientId) { SendRuinedDecisionToClient(connectedClientsId, networkId, isRuined); } } } private void SendAllExistingDecisionsToClient(ulong clientId) { NetworkManager registeredNetworkManager = _registeredNetworkManager; if ((Object)(object)registeredNetworkManager == (Object)null || !registeredNetworkManager.IsServer || registeredNetworkManager.SpawnManager == null) { return; } KeyValuePair<ulong, bool>[] array = _serverRuinedDecisions.ToArray(); for (int i = 0; i < array.Length; i++) { KeyValuePair<ulong, bool> keyValuePair = array[i]; if (!registeredNetworkManager.SpawnManager.SpawnedObjects.ContainsKey(keyValuePair.Key)) { _serverRuinedDecisions.Remove(keyValuePair.Key); _processedServerNetworkIds.Remove(keyValuePair.Key); } else { SendRuinedDecisionToClient(clientId, keyValuePair.Key, keyValuePair.Value); } } } private unsafe void SendRuinedDecisionToClient(ulong clientId, ulong networkId, bool isRuined) { //IL_0034: 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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) NetworkManager val = _registeredNetworkManager ?? NetworkManager.Singleton; if ((Object)(object)val == (Object)null || !val.IsServer) { return; } try { FastBufferWriter val2 = default(FastBufferWriter); ((FastBufferWriter)(ref val2))..ctor(9, (Allocator)2, -1); try { ((FastBufferWriter)(ref val2)).WriteValueSafe<ulong>(ref networkId, default(ForPrimitives)); ((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref isRuined, default(ForPrimitives)); val.CustomMessagingManager.SendNamedMessage("chatgpt.ruinedbodies.RuinedDecision.v1", clientId, val2, (NetworkDelivery)3); } finally { ((IDisposable)(*(FastBufferWriter*)(&val2))/*cast due to .constrained prefix*/).Dispose(); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"Failed to sync ruined-body decision for network object {networkId} to client {clientId}: {ex.Message}"); } } private void ReceiveRuinedDecision(ulong senderClientId, FastBufferReader reader) { //IL_003f: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) NetworkManager registeredNetworkManager = _registeredNetworkManager; if ((Object)(object)registeredNetworkManager == (Object)null || registeredNetworkManager.IsServer) { return; } if (senderClientId != 0L) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"Ignored ruined-body decision from non-host client {senderClientId}."); return; } try { ulong num = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref num, default(ForPrimitives)); bool flag = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives)); _clientRuinedDecisions[num] = flag; if (!TryApplyClientDecisionToSpawnedObject(num, flag)) { _pendingClientDecisions[num] = flag; } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Failed to read a synchronized ruined-body decision: " + ex.Message)); } } private bool TryApplyClientDecisionToSpawnedObject(ulong networkId, bool isRuined) { NetworkManager val = _registeredNetworkManager ?? NetworkManager.Singleton; if ((Object)(object)val == (Object)null || val.SpawnManager == null) { return false; } if (!val.SpawnManager.SpawnedObjects.TryGetValue(networkId, out var value) || (Object)(object)value == (Object)null) { return false; } GrabbableObject grabbableObject = GetGrabbableObject(value); if ((Object)(object)grabbableObject == (Object)null) { return false; } ApplyDecisionToItem(grabbableObject, networkId, isRuined); _pendingClientDecisions.Remove(networkId); return true; } private void ApplyPendingClientDecisions() { if (_pendingClientDecisions.Count != 0) { KeyValuePair<ulong, bool>[] array = _pendingClientDecisions.ToArray(); for (int i = 0; i < array.Length; i++) { KeyValuePair<ulong, bool> keyValuePair = array[i]; TryApplyClientDecisionToSpawnedObject(keyValuePair.Key, keyValuePair.Value); } } } private void SweepSpawnedObjects() { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || singleton.SpawnManager == null) { return; } KeyValuePair<ulong, NetworkObject>[] array; if (singleton.IsServer) { array = singleton.SpawnManager.SpawnedObjects.ToArray(); for (int i = 0; i < array.Length; i++) { KeyValuePair<ulong, NetworkObject> keyValuePair = array[i]; NetworkObject value = keyValuePair.Value; if ((Object)(object)value == (Object)null || !value.IsSpawned) { continue; } GrabbableObject grabbableObject = GetGrabbableObject(value); if (!((Object)(object)grabbableObject == (Object)null) && LooksLikeMonsterBody(grabbableObject)) { if (!_serverRuinedDecisions.ContainsKey(keyValuePair.Key)) { ProcessServerBody(value, grabbableObject); } else { ApplyDecisionToItem(grabbableObject, keyValuePair.Key, _serverRuinedDecisions[keyValuePair.Key]); } } } ulong[] array2 = _serverRuinedDecisions.Keys.ToArray(); foreach (ulong num in array2) { if (!singleton.SpawnManager.SpawnedObjects.ContainsKey(num)) { _serverRuinedDecisions.Remove(num); _processedServerNetworkIds.Remove(num); } } return; } array = singleton.SpawnManager.SpawnedObjects.ToArray(); for (int i = 0; i < array.Length; i++) { KeyValuePair<ulong, NetworkObject> keyValuePair2 = array[i]; NetworkObject value2 = keyValuePair2.Value; if ((Object)(object)value2 == (Object)null || !value2.IsSpawned) { continue; } GrabbableObject grabbableObject2 = GetGrabbableObject(value2); if (!((Object)(object)grabbableObject2 == (Object)null)) { if (_clientRuinedDecisions.TryGetValue(keyValuePair2.Key, out var value3)) { grabbableObject2.grabbable = true; ApplyDecisionToItem(grabbableObject2, keyValuePair2.Key, value3); } else if (LooksLikeMonsterBody(grabbableObject2)) { grabbableObject2.grabbable = true; } } } } private void OnClientConnected(ulong clientId) { NetworkManager registeredNetworkManager = _registeredNetworkManager; if (!((Object)(object)registeredNetworkManager == (Object)null) && registeredNetworkManager.IsServer && clientId != registeredNetworkManager.LocalClientId) { SendAllExistingDecisionsToClient(clientId); } } private static Bounds CalculateLocalRendererBounds(Transform root, Renderer[] renderers, out bool foundAny) { //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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(Vector3.zero, Vector3.zero); foundAny = false; if ((Object)(object)root == (Object)null || renderers == null) { return result; } Vector3 val2 = default(Vector3); foreach (Renderer val in renderers) { if ((Object)(object)val == (Object)null || !val.enabled) { continue; } Bounds bounds = val.bounds; for (int j = 0; j < 8; j++) { ((Vector3)(ref val2))..ctor(((j & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((j & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((j & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z); Vector3 val3 = root.InverseTransformPoint(val2); if (!foundAny) { ((Bounds)(ref result))..ctor(val3, Vector3.zero); foundAny = true; } else { ((Bounds)(ref result)).Encapsulate(val3); } } } return result; } private void ReplaceOriginalVisualWithGutsPile(GrabbableObject item) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0095: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_0306: Unknown result type (might be due to invalid IL or missing references) //IL_031a: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)item == (Object)null) { return; } EnsureGutsAssets(); if (_gutsMaterials == null || _gutsMaterials.Length != 4 || (Object)(object)_lowPolyChunkMesh == (Object)null || (Object)(object)_gutsTubeMeshA == (Object)null || (Object)(object)_gutsTubeMeshB == (Object)null) { return; } Transform val = ((Component)item).transform.Find("RuinedGutsPileVisual"); if ((Object)(object)val == (Object)null) { Renderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<Renderer>(true); bool foundAny; Bounds val2 = CalculateLocalRendererBounds(((Component)item).transform, componentsInChildren, out foundAny); if (!foundAny) { ((Bounds)(ref val2))..ctor(Vector3.zero, new Vector3(0.8f, 0.4f, 0.8f)); } float num = Mathf.Max(((Bounds)(ref val2)).size.x, ((Bounds)(ref val2)).size.z); if (num < 0.1f) { num = 0.8f; } float num2 = Mathf.Clamp(num * 0.86f, 0.45f, 1.8f); float num3 = Mathf.Clamp(num2 * 0.34f, 0.16f, 0.55f); Vector3 localPosition = default(Vector3); ((Vector3)(ref localPosition))..ctor(((Bounds)(ref val2)).center.x, ((Bounds)(ref val2)).min.y + Mathf.Max(0.005f, ((Bounds)(ref val2)).size.y * 0.015f), ((Bounds)(ref val2)).center.z); val = new GameObject("RuinedGutsPileVisual").transform; val.SetParent(((Component)item).transform, false); val.localPosition = localPosition; val.localRotation = Quaternion.identity; val.localScale = new Vector3(num2, num3, num2); AddGutsChunk(val, "MeatLobe_Main", new Vector3(-0.02f, 0.31f, 0.01f), new Vector3(0.88f, 0.54f, 0.78f), _gutsMaterials[0]); AddGutsChunk(val, "MeatLobe_Left", new Vector3(-0.25f, 0.26f, 0.08f), new Vector3(0.48f, 0.42f, 0.49f), _gutsMaterials[1]); AddGutsChunk(val, "MeatLobe_Right", new Vector3(0.24f, 0.25f, -0.07f), new Vector3(0.48f, 0.4f, 0.52f), _gutsMaterials[0]); AddGutsChunk(val, "MeatLobe_Back", new Vector3(0.02f, 0.27f, -0.23f), new Vector3(0.5f, 0.42f, 0.42f), _gutsMaterials[2]); AddGutsChunk(val, "MeatLobe_Front", new Vector3(0.08f, 0.23f, 0.22f), new Vector3(0.46f, 0.33f, 0.38f), _gutsMaterials[3]); AddGutsChunk(val, "MeatLobe_Small", new Vector3(-0.3f, 0.2f, -0.17f), new Vector3(0.31f, 0.3f, 0.29f), _gutsMaterials[2]); AddGutsTube(val, "GutCoil_Left", _gutsTubeMeshA, _gutsMaterials[3], new Vector3(0f, 0f, 0f), new Vector3(0.88f, 0.88f, 0.88f)); AddGutsTube(val, "GutCoil_Right", _gutsTubeMeshB, _gutsMaterials[1], new Vector3(0.01f, 0.01f, 0.015f), new Vector3(0.78f, 0.84f, 0.78f)); ((BaseUnityPlugin)this).Logger.LogDebug((object)("Created textured ruined-body visual for '" + ((Object)((Component)item).gameObject).name + "'.")); } if (!((Component)val).gameObject.activeSelf) { ((Component)val).gameObject.SetActive(true); } Renderer[] componentsInChildren2 = ((Component)item).GetComponentsInChildren<Renderer>(true); foreach (Renderer val3 in componentsInChildren2) { if (!((Object)(object)val3 == (Object)null)) { bool enabled = (Object)(object)((Component)val3).transform == (Object)(object)val || ((Component)val3).transform.IsChildOf(val); val3.enabled = enabled; } } } private static void AddGutsChunk(Transform parent, string name, Vector3 localPosition, Vector3 localScale, Material material) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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_002c: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); Transform transform = val.transform; transform.SetParent(parent, false); transform.localPosition = localPosition; transform.localRotation = Quaternion.identity; transform.localScale = localScale; val.AddComponent<MeshFilter>().sharedMesh = _lowPolyChunkMesh; ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = material; } private static void AddGutsTube(Transform parent, string name, Mesh mesh, Material material, Vector3 localPosition, Vector3 localScale) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); Transform transform = val.transform; transform.SetParent(parent, false); transform.localPosition = localPosition; transform.localRotation = Quaternion.identity; transform.localScale = localScale; val.AddComponent<MeshFilter>().sharedMesh = mesh; ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = material; } private static void EnsureGutsAssets() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0236: 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_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0412: Unknown result type (might be due to invalid IL or missing references) //IL_042e: Unknown result type (might be due to invalid IL or missing references) //IL_0447: Unknown result type (might be due to invalid IL or missing references) //IL_0463: 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_0378: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Unknown result type (might be due to invalid IL or missing references) //IL_03c6: Unknown result type (might be due to invalid IL or missing references) //IL_03e8: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_lowPolyChunkMesh == (Object)null) { _lowPolyChunkMesh = BuildLowPolyChunkMesh(); } if ((Object)(object)_gutsTubeMeshA == (Object)null) { _gutsTubeMeshA = BuildTubeMesh((Vector3[])(object)new Vector3[9] { new Vector3(-0.37f, 0.24f, -0.06f), new Vector3(-0.36f, 0.42f, -0.22f), new Vector3(-0.17f, 0.48f, -0.34f), new Vector3(0.03f, 0.43f, -0.23f), new Vector3(0.04f, 0.37f, -0.07f), new Vector3(-0.15f, 0.34f, 0.02f), new Vector3(-0.1f, 0.42f, 0.15f), new Vector3(0.11f, 0.39f, 0.19f), new Vector3(0.3f, 0.3f, 0.05f) }, 0.065f, 5); } if ((Object)(object)_gutsTubeMeshB == (Object)null) { _gutsTubeMeshB = BuildTubeMesh((Vector3[])(object)new Vector3[10] { new Vector3(-0.31f, 0.26f, 0.18f), new Vector3(-0.22f, 0.36f, 0.29f), new Vector3(-0.02f, 0.43f, 0.3f), new Vector3(0.17f, 0.37f, 0.23f), new Vector3(0.27f, 0.43f, 0.09f), new Vector3(0.15f, 0.39f, -0.02f), new Vector3(-0.02f, 0.35f, -0.14f), new Vector3(-0.04f, 0.44f, -0.29f), new Vector3(0.17f, 0.38f, -0.34f), new Vector3(0.36f, 0.29f, -0.19f) }, 0.052f, 5); } if ((Object)(object)_gutsTexture == (Object)null) { _gutsTexture = LoadGutsTexture(); } if (_gutsMaterials != null && _gutsMaterials.Length == 4) { return; } Shader val = Shader.Find("HDRP/Lit"); if ((Object)(object)val == (Object)null) { val = Shader.Find("HDRP/Unlit"); } if ((Object)(object)val == (Object)null) { val = Shader.Find("Universal Render Pipeline/Lit"); } if ((Object)(object)val == (Object)null) { val = Shader.Find("Standard"); } if ((Object)(object)val == (Object)null) { val = Shader.Find("Unlit/Texture"); } if ((Object)(object)val == (Object)null) { val = Shader.Find("Sprites/Default"); } if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)"Ruined Bodies could not find a supported shader for the optional guts-pile visual."); return; } if ((Object)(object)Instance != (Object)null) { ((BaseUnityPlugin)Instance).Logger.LogInfo((object)("Guts-pile material using shader '" + ((Object)val).name + "' (HDRP shaders are preferred for Lethal Company).")); } if ((Object)(object)_gutsTexture != (Object)null) { _gutsMaterials = (Material[])(object)new Material[4] { CreateGutsMaterial(val, Color32.op_Implicit(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue))), CreateGutsMaterial(val, Color32.op_Implicit(new Color32((byte)218, (byte)218, (byte)218, byte.MaxValue))), CreateGutsMaterial(val, Color32.op_Implicit(new Color32((byte)184, (byte)184, (byte)184, byte.MaxValue))), CreateGutsMaterial(val, Color32.op_Implicit(new Color32((byte)238, (byte)238, (byte)238, byte.MaxValue))) }; } else { _gutsMaterials = (Material[])(object)new Material[4] { CreateFallbackGutsMaterial(val, new Color32((byte)106, (byte)39, (byte)49, byte.MaxValue)), CreateFallbackGutsMaterial(val, new Color32((byte)148, (byte)55, (byte)62, byte.MaxValue)), CreateFallbackGutsMaterial(val, new Color32((byte)77, (byte)31, (byte)39, byte.MaxValue)), CreateFallbackGutsMaterial(val, new Color32((byte)183, (byte)83, (byte)91, byte.MaxValue)) }; } } private static Texture2D LoadGutsTexture() { //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Expected O, but got Unknown try { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RuinedBodies.Assets.RuinedBodies_GutsPalette.rgba"); if (stream == null) { Debug.LogWarning((object)"Ruined Bodies could not find embedded art asset 'RuinedBodies.Assets.RuinedBodies_GutsPalette.rgba'. The fallback flat-colour mesh will be used."); return null; } byte[] array = new byte[1048576]; int i; int num; for (i = 0; i < array.Length; i += num) { num = stream.Read(array, i, array.Length - i); if (num <= 0) { break; } } if (i != 1048576) { Debug.LogWarning((object)$"Ruined Bodies art asset size was {i} bytes; expected {1048576}. The fallback mesh will be used."); return null; } bool flag = (Object)(object)Instance != (Object)null && Instance._invertGutsColors != null && Instance._invertGutsColors.Value; if (flag) { for (int j = 0; j < array.Length; j += 4) { array[j] = (byte)(255 - array[j]); array[j + 1] = (byte)(255 - array[j + 1]); array[j + 2] = (byte)(255 - array[j + 2]); } } Texture2D val = new Texture2D(512, 512, (TextureFormat)4, false) { name = "RuinedBodies_GutsPalette" }; val.LoadRawTextureData(array); ((Texture)val).wrapMode = (TextureWrapMode)0; ((Texture)val).filterMode = (FilterMode)1; ((Texture)val).anisoLevel = 4; val.Apply(false, true); Debug.Log((object)$"Ruined Bodies loaded embedded guts art texture ({512}x{512}); colour inversion: {flag}."); return val; } catch (Exception ex) { Debug.LogWarning((object)("Ruined Bodies failed to load its embedded art texture; using flat-colour fallback: " + ex.Message)); return null; } } private static Material CreateGutsMaterial(Shader shader, Color color) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_001a: 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_0033: Unknown result type (might be due to invalid IL or missing references) Material val = new Material(shader); if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", color); } if (val.HasProperty("_Color")) { val.SetColor("_Color", color); } val.color = color; if ((Object)(object)_gutsTexture != (Object)null) { if (val.HasProperty("_BaseColorMap")) { val.SetTexture("_BaseColorMap", (Texture)(object)_gutsTexture); } if (val.HasProperty("_MainTex")) { val.SetTexture("_MainTex", (Texture)(object)_gutsTexture); } val.mainTexture = (Texture)(object)_gutsTexture; } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", 0.12f); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", 0.12f); } return val; } private static Material CreateFallbackGutsMaterial(Shader shader, Color32 baseColour) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_0058: Unknown result type (might be due to invalid IL or missing references) Color32 val = baseColour; if ((Object)(object)Instance != (Object)null && Instance._invertGutsColors != null && Instance._invertGutsColors.Value) { ((Color32)(ref val))..ctor((byte)(255 - val.r), (byte)(255 - val.g), (byte)(255 - val.b), val.a); } return CreateGutsMaterial(shader, Color32.op_Implicit(val)); } private static Vector2 CalculateSphericalUv(Vector3 vertex) { //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_0013: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) Vector3 normalized = ((Vector3)(ref vertex)).normalized; float num = 0.5f + Mathf.Atan2(normalized.z, normalized.x) / (MathF.PI * 2f); float num2 = 0.5f - Mathf.Asin(Mathf.Clamp(normalized.y, -1f, 1f)) / MathF.PI; return new Vector2(num, num2); } private static Mesh BuildLowPolyChunkMesh() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: 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_0118: 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) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018d: 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_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: 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_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_031b: Unknown result type (might be due to invalid IL or missing references) //IL_0323: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Expected O, but got Unknown //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: 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_02ca: 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_026e: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) float num = (1f + Mathf.Sqrt(5f)) / 2f; Vector3[] array = (Vector3[])(object)new Vector3[12] { new Vector3(-1f, num, 0f), new Vector3(1f, num, 0f), new Vector3(-1f, 0f - num, 0f), new Vector3(1f, 0f - num, 0f), new Vector3(0f, -1f, num), new Vector3(0f, 1f, num), new Vector3(0f, -1f, 0f - num), new Vector3(0f, 1f, 0f - num), new Vector3(num, 0f, -1f), new Vector3(num, 0f, 1f), new Vector3(0f - num, 0f, -1f), new Vector3(0f - num, 0f, 1f) }; int[] array2 = new int[60] { 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1 }; Vector3[] array3 = (Vector3[])(object)new Vector3[array2.Length]; Vector2[] array4 = (Vector2[])(object)new Vector2[array2.Length]; int[] array5 = new int[array2.Length]; for (int i = 0; i < array2.Length; i += 3) { Vector3 val = ((Vector3)(ref array[array2[i]])).normalized * 0.5f; Vector3 val2 = ((Vector3)(ref array[array2[i + 1]])).normalized * 0.5f; Vector3 val3 = ((Vector3)(ref array[array2[i + 2]])).normalized * 0.5f; array3[i] = val; array3[i + 1] = val2; array3[i + 2] = val3; Vector2 val4 = CalculateSphericalUv(val); Vector2 val5 = CalculateSphericalUv(val2); Vector2 val6 = CalculateSphericalUv(val3); float num2 = Mathf.Min(val4.x, Mathf.Min(val5.x, val6.x)); if (Mathf.Max(val4.x, Mathf.Max(val5.x, val6.x)) - num2 > 0.5f) { if (val4.x < 0.5f) { val4.x += 1f; } if (val5.x < 0.5f) { val5.x += 1f; } if (val6.x < 0.5f) { val6.x += 1f; } } array4[i] = val4; array4[i + 1] = val5; array4[i + 2] = val6; array5[i] = i; array5[i + 1] = i + 1; array5[i + 2] = i + 2; } Mesh val7 = new Mesh { name = "RuinedBodies_LowPolyFleshChunk", vertices = array3, uv = array4, triangles = array5 }; val7.RecalculateNormals(); val7.RecalculateBounds(); return val7; } private static Mesh BuildTubeMesh(Vector3[] controlPoints, float radius, int radialSegments) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //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_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: 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_0106: 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_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: 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_0123: 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_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: 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_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03a6: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03bc: Unknown result type (might be due to invalid IL or missing references) //IL_03c3: Expected O, but got Unknown //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0248: 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_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_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_0268: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_0276: 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_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: 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) //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) if (controlPoints != null && controlPoints.Length >= 2) { int num = 5; int num2 = (controlPoints.Length - 1) * num + 1; Vector3[] array = (Vector3[])(object)new Vector3[num2]; for (int i = 0; i < num2; i++) { float num3 = (float)i / (float)(num2 - 1) * (float)(controlPoints.Length - 1); int num4 = Mathf.Min(Mathf.FloorToInt(num3), controlPoints.Length - 2); float num5 = num3 - (float)num4; Vector3 val = controlPoints[Mathf.Max(0, num4 - 1)]; Vector3 val2 = controlPoints[num4]; Vector3 val3 = controlPoints[num4 + 1]; Vector3 val4 = controlPoints[Mathf.Min(controlPoints.Length - 1, num4 + 2)]; float num6 = num5 * num5; float num7 = num6 * num5; array[i] = 0.5f * (2f * val2 + (-val + val3) * num5 + (2f * val - 5f * val2 + 4f * val3 - val4) * num6 + (-val + 3f * val2 - 3f * val3 + val4) * num7); } Vector3[] array2 = (Vector3[])(object)new Vector3[num2 * radialSegments]; int[] array3 = new int[(num2 - 1) * radialSegments * 6]; Vector2[] array4 = (Vector2[])(object)new Vector2[array2.Length]; for (int j = 0; j < num2; j++) { Vector3 val5 = ((j == 0) ? (array[1] - array[0]) : ((j != num2 - 1) ? (array[j + 1] - array[j - 1]) : (array[j] - array[j - 1]))); val5 = ((((Vector3)(ref val5)).sqrMagnitude < 0.0001f) ? Vector3.forward : ((Vector3)(ref val5)).normalized); Vector3 val6 = Vector3.Cross(val5, Vector3.up); if (((Vector3)(ref val6)).sqrMagnitude < 0.0001f) { val6 = Vector3.Cross(val5, Vector3.right); } ((Vector3)(ref val6)).Normalize(); Vector3 val7 = Vector3.Cross(val5, val6); Vector3 normalized = ((Vector3)(ref val7)).normalized; for (int k = 0; k < radialSegments; k++) { float num8 = (float)k / (float)radialSegments * MathF.PI * 2f; Vector3 val8 = val6 * Mathf.Cos(num8) + normalized * Mathf.Sin(num8); int num9 = j * radialSegments + k; array2[num9] = array[j] + val8 * radius; array4[num9] = new Vector2((float)k / (float)radialSegments, (float)j / (float)(num2 - 1)); } } int num10 = 0; for (int l = 0; l < num2 - 1; l++) { for (int m = 0; m < radialSegments; m++) { int num11 = (m + 1) % radialSegments; int num12 = l * radialSegments + m; int num13 = l * radialSegments + num11; int num14 = (l + 1) * radialSegments + m; int num15 = (l + 1) * radialSegments + num11; array3[num10++] = num12; array3[num10++] = num13; array3[num10++] = num14; array3[num10++] = num13; array3[num10++] = num15; array3[num10++] = num14; } } Mesh val9 = new Mesh { name = "RuinedBodies_LowPolyGutTube", vertices = array2, triangles = array3, uv = array4 }; val9.RecalculateNormals(); val9.RecalculateBounds(); return val9; } return new Mesh { name = "RuinedBodies_EmptyGutTube" }; } } }