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 CrewExpendable v0.1.0
BepInEx/plugins/CrewExpendable/CrewExpendable.dll
Decompiled 39 minutes 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.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using DunGen; using GameNetcodeStuff; using HarmonyLib; using LethalLib.Modules; using Microsoft.CodeAnalysis; using MoreCompany; using MoreCompany.Cosmetics; using Newtonsoft.Json; using TMPro; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.AI; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("CrewExpendable")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0+62310234671d6c6d470cf6d084cc885059ced48a")] [assembly: AssemblyProduct("CrewExpendable")] [assembly: AssemblyTitle("CrewExpendable")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.0.0")] [module: UnverifiableCode] [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 CrewExpendable { internal static class Tailor { private const string Id = "nine78.suittailor"; private static bool looked; private static Func<bool, string[]> designs; private static Func<Renderer, string, bool> paint; public static string SuitName { get; private set; } public static bool Available { get { Find(); return paint != null; } } private static void Find() { if (looked) { return; } looked = true; if (!Chainloader.PluginInfos.TryGetValue("nine78.suittailor", out var value)) { return; } try { Type type = ((object)value.Instance).GetType().Assembly.GetType("SuitTailor.Api"); if (type == null) { Plugin.Log.LogInfo((object)$"Suit Tailor {value.Metadata.Version} is too old to share its suits; bodies need 0.2.1 or later for them"); return; } designs = (Func<bool, string[]>)AccessTools.Method(type, "GetDesigns", (Type[])null, (Type[])null).CreateDelegate(typeof(Func<bool, string[]>)); SuitName = (string)AccessTools.Field(type, "SuitName").GetRawConstantValue(); paint = (Func<Renderer, string, bool>)AccessTools.Method(type, "Paint", (Type[])null, (Type[])null).CreateDelegate(typeof(Func<Renderer, string, bool>)); Plugin.Log.LogInfo((object)$"Using Suit Tailor {value.Metadata.Version}'s suits on bodies"); } catch (Exception ex) { designs = null; paint = null; Plugin.Log.LogWarning((object)("Couldn't use Suit Tailor's suits: " + ex.Message)); } } public static string[] Designs(bool saved) { if (!Available) { return new string[0]; } try { return designs(saved) ?? new string[0]; } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't get Suit Tailor's suits: " + ex.Message)); return new string[0]; } } public static bool Paint(Renderer r, string code) { if (!Available || string.IsNullOrEmpty(code)) { return false; } try { return paint(r, code); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't paint a Suit Tailor suit: " + ex.Message)); return false; } } } internal static class Mirage { internal static bool Pretend; public static bool DecidesLook { get { if (Installed) { return Plugin.C.MirageLook.Value == LookFrom.Mirage; } return false; } } public static bool LimitsRaising { get { if (Installed) { return Plugin.C.MirageLimit.Value; } return false; } } public static bool PicksMimics { get { if (Installed) { return !Plugin.C.MirageLetters.Value; } return false; } } public static bool Installed { get { if (!Pretend) { return Chainloader.PluginInfos.ContainsKey("qwbarch.Mirage"); } return true; } } internal static Component Copier(MaskedPlayerEnemy m) { return ((IEnumerable<Component>)((Component)m).GetComponents<Component>()).FirstOrDefault((Func<Component, bool>)((Component x) => (Object)(object)x != (Object)null && ((object)x).GetType().Name == "MimicPlayer" && (((object)x).GetType().FullName ?? "").StartsWith("Mirage."))); } public static void Silence(MaskedPlayerEnemy m) { Component val = Copier(m); MethodInfo methodInfo = ((object)val)?.GetType().GetMethod("ResetMimicPlayer", Type.EmptyTypes); if (methodInfo == null) { if (Installed && !Pretend) { Plugin.Log.LogWarning((object)"Couldn't find how to stop Mirage's voice on a raised body"); } return; } try { methodInfo.Invoke(val, null); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't stop Mirage's voice on a raised body: " + (ex.InnerException ?? ex).Message)); } } public static bool SameKind(EnemyType a, EnemyType b) { if ((Object)(object)a != (Object)null && (Object)(object)b != (Object)null) { if (!((Object)(object)a == (Object)(object)b)) { if ((Object)(object)a.enemyPrefab != (Object)null) { return (Object)(object)a.enemyPrefab == (Object)(object)b.enemyPrefab; } return false; } return true; } return false; } public static int Limit(EnemyType mimic) { SelectableLevel currentLevel = StartOfRound.Instance.currentLevel; return ((from l in ((IEnumerable<SelectableLevel>)(object)new SelectableLevel[1] { currentLevel }).Concat(StartOfRound.Instance.levels) where l?.Enemies != null select l).SelectMany((SelectableLevel l) => l.Enemies).FirstOrDefault((Func<SpawnableEnemyWithRarity, bool>)((SpawnableEnemyWithRarity e) => SameKind(e?.enemyType, mimic)))?.enemyType ?? mimic).MaxCount; } } internal static class CompanyRnDMod { private const string Id = "nine78.companyrnd"; private static bool looked; private static Func<bool, string[]> carried; private static Func<string, int> price; private static Func<string, bool> hasCharge; public static bool Available { get { Find(); return hasCharge != null; } } private static void Find() { if (looked) { return; } looked = true; if (!Chainloader.PluginInfos.TryGetValue("nine78.companyrnd", out var value)) { return; } try { Type type = ((object)value.Instance).GetType().Assembly.GetType("CompanyRnD.Api"); if (type == null) { Plugin.Log.LogInfo((object)$"Company R&D {value.Metadata.Version} is too old to share its gear; 0.5.2 or later is needed to find it by bodies"); return; } carried = (Func<bool, string[]>)AccessTools.Method(type, "GetCarriedGear", (Type[])null, (Type[])null).CreateDelegate(typeof(Func<bool, string[]>)); price = (Func<string, int>)AccessTools.Method(type, "GetPrice", (Type[])null, (Type[])null).CreateDelegate(typeof(Func<string, int>)); hasCharge = (Func<string, bool>)AccessTools.Method(type, "HasCharge", (Type[])null, (Type[])null).CreateDelegate(typeof(Func<string, bool>)); Plugin.Log.LogInfo((object)$"Using Company R&D {value.Metadata.Version}'s gear"); } catch (Exception ex) { carried = null; price = null; hasCharge = null; Plugin.Log.LogWarning((object)("Couldn't use Company R&D's gear: " + ex.Message)); } } public static Dictionary<string, int> Gear() { Dictionary<string, int> dictionary = new Dictionary<string, int>(); if (Plugin.C.RnDGear.Value == RnDGear.None || !Available) { return dictionary; } try { string[] array = carried(Plugin.C.RnDGear.Value == RnDGear.All); foreach (string text in array) { dictionary[text] = price(text); } } catch (Exception ex) { dictionary.Clear(); Plugin.Log.LogWarning((object)("Couldn't get Company R&D's gear: " + ex.Message)); } return dictionary; } public static bool HasCharge(string item) { if (!Available) { return true; } try { return hasCharge(item); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't ask Company R&D about " + item + ": " + ex.Message)); return true; } } } internal static class Cosmetics { private static class Inner { [MethodImpl(MethodImplOptions.NoInlining)] public static int Count() { return CosmeticRegistry.cosmeticInstances.Count; } [MethodImpl(MethodImplOptions.NoInlining)] public static int Colliders(GameObject body) { return body.GetComponentInChildren<CosmeticApplication>(true)?.spawnedCosmetics.Where((CosmeticInstance c) => (Object)(object)c != (Object)null).Sum((CosmeticInstance c) => ((Component)c).GetComponentsInChildren<Collider>(true).Length) ?? 0; } [MethodImpl(MethodImplOptions.NoInlining)] public static int Hats(GameObject body) { return body.GetComponentInChildren<CosmeticApplication>(true)?.spawnedCosmetics.Count((CosmeticInstance c) => (Object)(object)c != (Object)null && (int)c.cosmeticType == 0) ?? 0; } [MethodImpl(MethodImplOptions.NoInlining)] public static int Worn(GameObject body, bool showing) { CosmeticApplication componentInChildren = body.GetComponentInChildren<CosmeticApplication>(true); if (!((Object)(object)componentInChildren == (Object)null)) { return componentInChildren.spawnedCosmetics.Count((CosmeticInstance c) => (Object)(object)c != (Object)null && (!showing || ((Component)c).gameObject.activeInHierarchy)); } return 0; } [MethodImpl(MethodImplOptions.NoInlining)] public static List<string> Choose(Random rng, int max, bool hats) { HashSet<string> off = new HashSet<string>(from s in (MainClass.disabledCosmetics?.Value ?? "").Split(',') select s.Trim() into s where s != "" select s); List<List<string>> list = (from c in CosmeticRegistry.cosmeticInstances where (Object)(object)c.Value != (Object)null && !off.Contains(c.Key) && (hats || (int)c.Value.cosmeticType > 0) group c by c.Value.cosmeticType into g orderby (int)g.Key select g.Select((KeyValuePair<string, CosmeticInstance> c) => c.Key).OrderBy<string, string>((string k) => k, StringComparer.Ordinal).ToList()).ToList(); List<string> list2 = new List<string>(); int num = 1 + rng.Next(max); while (num > 0 && list.Count > 0) { int index = rng.Next(list.Count); list2.Add(list[index][rng.Next(list[index].Count)]); list.RemoveAt(index); num--; } return list2; } [MethodImpl(MethodImplOptions.NoInlining)] public static void Wear(GameObject body, List<string> ids) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) CosmeticApplication val = body.GetComponent<CosmeticApplication>() ?? body.AddComponent<CosmeticApplication>(); val.parentType = (ParentType)1; val.ClearCosmetics(); foreach (string id in ids) { if (CosmeticRegistry.cosmeticInstances.ContainsKey(id)) { val.ApplyCosmetic(id, false); } } foreach (Collider item in val.spawnedCosmetics.Where((CosmeticInstance c) => (Object)(object)c != (Object)null).SelectMany((CosmeticInstance c) => ((Component)c).GetComponentsInChildren<Collider>(true))) { Object.DestroyImmediate((Object)(object)item); } foreach (CosmeticInstance spawnedCosmetic in val.spawnedCosmetics) { if ((Object)(object)spawnedCosmetic != (Object)null) { Transform transform = ((Component)spawnedCosmetic).transform; transform.localScale *= 0.38f; } } val.UpdateAllCosmeticVisibilities(false); } [MethodImpl(MethodImplOptions.NoInlining)] public static void WearMimic(MaskedPlayerEnemy mimic, List<string> ids) { //IL_0090: 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_0104: Unknown result type (might be due to invalid IL or missing references) Transform obj = ((Component)mimic).transform.Find("ScavengerModel"); Transform val = ((obj != null) ? obj.Find("metarig") : null); if ((Object)(object)val == (Object)null) { return; } List<string> list = ids.Where(CosmeticRegistry.cosmeticInstances.ContainsKey).ToList(); CosmeticApplication val2 = ((Component)val).GetComponent<CosmeticApplication>(); if (((Object)(object)val2 == (Object)null && list.Count == 0) || ((Object)(object)val2 != (Object)null && val2.spawnedCosmeticsIds.SequenceEqual(list))) { return; } if ((Object)(object)val2 == (Object)null) { val2 = ((Component)val).gameObject.AddComponent<CosmeticApplication>(); } val2.parentType = (ParentType)2; val2.ClearCosmetics(); foreach (string item in list) { val2.ApplyCosmetic(item, false); } foreach (CosmeticInstance spawnedCosmetic in val2.spawnedCosmetics) { if ((Object)(object)spawnedCosmetic != (Object)null) { Transform transform = ((Component)spawnedCosmetic).transform; transform.localScale *= 0.38f; } } val2.UpdateAllCosmeticVisibilities(false); ((EnemyAI)mimic).skinnedMeshRenderers = ((Component)mimic).GetComponentsInChildren<SkinnedMeshRenderer>(); ((EnemyAI)mimic).meshRenderers = ((Component)mimic).GetComponentsInChildren<MeshRenderer>(); } } public static bool Available => Chainloader.PluginInfos.ContainsKey("me.swipez.melonloader.morecompany"); public static List<string> Choose(Random rng, int max, bool hats = true) { if (!Available || max <= 0) { return new List<string>(); } try { return Inner.Choose(rng, max, hats); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't choose MoreCompany cosmetics: " + ex.Message)); return new List<string>(); } } public static void Wear(GameObject body, List<string> ids) { if (!Available || ids == null || ids.Count == 0) { return; } try { Inner.Wear(body, ids); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't put MoreCompany cosmetics on a body: " + ex.Message)); } } public static void WearMimic(MaskedPlayerEnemy mimic, List<string> ids) { if (!Available || (Object)(object)mimic == (Object)null) { return; } try { Inner.WearMimic(mimic, ids ?? new List<string>()); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't put MoreCompany cosmetics on a raised body: " + ex.Message)); } } public static int Count() { if (!Available) { return 0; } return Inner.Count(); } public static int Colliders(GameObject body) { if (!Available || !((Object)(object)body != (Object)null)) { return 0; } return Inner.Colliders(body); } public static int Hats(GameObject body) { if (!Available || !((Object)(object)body != (Object)null)) { return 0; } return Inner.Hats(body); } public static int Worn(GameObject body, bool showing) { if (!Available || !((Object)(object)body != (Object)null)) { return 0; } return Inner.Worn(body, showing); } } internal class BodyLook { public int Seed; public int Kind; public string Suit; public string Tailor; public List<string> Cosmetics; public int Flies; public float[] Pose; public BodyLook WithoutPose() { BodyLook obj = (BodyLook)MemberwiseClone(); obj.Pose = null; return obj; } } internal class CrewBody : PhysicsProp { public const string ItemName = "Body"; public static Item Item; private static readonly int Seeds = int.MaxValue; public BodyLook Look; private int seed = -1; private GameObject model; private Transform[] parts; private Rigidbody holdBy; private bool limp; private bool dropping; private float askAgain; internal bool Settled { get { if (Look?.Pose != null && (Object)(object)model != (Object)null && !limp) { return !dropping; } return false; } } internal bool HangingLimp { get { if (limp && (Object)(object)holdBy != (Object)null && holdBy.isKinematic) { return parts.Any((Transform p) => (Object)(object)p != (Object)null && (Object)(object)p != (Object)(object)((Component)holdBy).transform && !((Component)p).GetComponent<Rigidbody>().isKinematic); } return false; } } internal Vector3 Middle { get { //IL_007a: 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_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) if (parts != null && parts.Length != 0 && !((Object)(object)parts[0] == (Object)null)) { if (parts.Length <= 1 || !((Object)(object)parts[1] != (Object)null)) { return parts[0].position; } return (parts[0].position + parts[1].position) / 2f; } return ((Component)this).transform.position; } } public static void Register() { //IL_0042: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_00b6: 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_01f8: 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) GameObject val = NetworkPrefabs.CreateNetworkPrefab("CrewExpendable_Body"); int num = LayerMask.NameToLayer("Props"); if (num >= 0) { val.layer = num; } val.tag = "PhysicsProp"; BoxCollider obj = val.AddComponent<BoxCollider>(); obj.center = new Vector3(0f, 0.15f, 0f); obj.size = new Vector3(0.9f, 0.5f, 0.9f); val.AddComponent<MeshFilter>(); MeshRenderer mainObjectRenderer = val.AddComponent<MeshRenderer>(); GameObject val2 = new GameObject("ScanNode"); val2.transform.SetParent(val.transform, false); int num2 = LayerMask.NameToLayer("ScanNode"); if (num2 >= 0) { val2.layer = num2; } BoxCollider obj2 = val2.AddComponent<BoxCollider>(); ((Collider)obj2).isTrigger = true; obj2.size = Vector3.one * 0.6f; ScanNodeProperties obj3 = val2.AddComponent<ScanNodeProperties>(); obj3.headerText = "Body"; obj3.subText = "Value: "; obj3.nodeType = 2; obj3.minRange = 1; obj3.maxRange = 13; obj3.requiresLineOfSight = true; AudioSource obj4 = val.AddComponent<AudioSource>(); obj4.playOnAwake = false; obj4.spatialBlend = 1f; obj4.rolloffMode = (AudioRolloffMode)1; obj4.maxDistance = 25f; Item = ScriptableObject.CreateInstance<Item>(); ((Object)Item).name = "CrewExpendable_BodyItem"; Item.itemName = "Body"; Item.spawnPrefab = val; Item.isScrap = true; Item.minValue = 5; Item.maxValue = 20; Item.weight = 1.8f; Item.twoHanded = (Item.twoHandedAnimation = true); Item.grabAnim = "HoldLung"; Item.canBeGrabbedBeforeGameStart = true; Item.itemSpawnsOnGround = true; Item.saveItemVariable = true; Item.requiresBattery = false; Item.positionOffset = new Vector3(0f, 0.1f, 0.25f); Item.toolTips = new string[0]; Item.meshVariants = (Mesh[])(object)new Mesh[0]; Item.materialVariants = (Material[])(object)new Material[0]; Item.clinkAudios = (AudioClip[])(object)new AudioClip[0]; Item.spawnPositionTypes = new List<ItemGroup>(); CrewBody crewBody = val.AddComponent<CrewBody>(); ((GrabbableObject)crewBody).grabbable = true; ((GrabbableObject)crewBody).grabbableToEnemies = false; ((GrabbableObject)crewBody).itemProperties = Item; ((GrabbableObject)crewBody).mainObjectRenderer = mainObjectRenderer; val.AddComponent<Findable>(); NetworkPrefabs.RegisterNetworkPrefab(val); Items.RegisterItem(Item); } public static void Borrow() { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) StartOfRound instance = StartOfRound.Instance; object obj; if (instance == null) { obj = null; } else { GameObject ragdollGrabbableObjectPrefab = instance.ragdollGrabbableObjectPrefab; obj = ((ragdollGrabbableObjectPrefab == null) ? null : ragdollGrabbableObjectPrefab.GetComponent<GrabbableObject>()?.itemProperties); } Item val = (Item)obj; if (!((Object)(object)val == (Object)null)) { Item.itemIcon = val.itemIcon; Item.grabSFX = val.grabSFX; Item.dropSFX = val.dropSFX; Item.pocketSFX = val.pocketSFX; Item.positionOffset = val.positionOffset; Item.rotationOffset = val.rotationOffset; Item.weight = val.weight; Item.twoHanded = val.twoHanded; Item.twoHandedAnimation = val.twoHandedAnimation; Item.grabAnim = val.grabAnim; Item.grabAnimationTime = val.grabAnimationTime; } } public static CrewBody Spawn(Vector3 at, int seed, int value) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(Item.spawnPrefab, at + Vector3.up * 0.3f, Quaternion.Euler(0f, (float)(seed % 360), 0f), RoundManager.Instance.spawnedScrapContainer); CrewBody component = val.GetComponent<CrewBody>(); component.seed = seed; ((GrabbableObject)component).fallTime = 0f; val.GetComponent<NetworkObject>().Spawn(false); ((GrabbableObject)component).SetScrapValue(value); return component; } public override int GetItemDataToSave() { return seed; } public override void LoadItemSaveData(int saveData) { seed = saveData; } public override void Start() { ((GrabbableObject)this).Start(); Uncounted.Mark((GrabbableObject)(object)this); if (Net.IsHost) { if (seed < 0) { seed = Random.Range(0, Seeds); } Look = Looks.Choose(seed); ((MonoBehaviour)this).StartCoroutine(Settle()); } } public override void Update() { ((GrabbableObject)this).Update(); if (Look == null && !Net.IsHost && ((NetworkBehaviour)this).IsSpawned && !(Time.time < askAgain)) { askAgain = Time.time + 2f; Net.Ask(((NetworkBehaviour)this).NetworkObjectId); } } private IEnumerator Settle() { yield return (object)new WaitForSeconds(1f); if (!Build(physics: true)) { yield break; } Rigidbody[] bodies = model.GetComponentsInChildren<Rigidbody>(); for (float t = 0f; t < 4f; t += Time.deltaTime) { if (!((Object)(object)model != (Object)null)) { break; } if (t > 1f && bodies.All(delegate(Rigidbody b) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)b == (Object)null)) { Vector3 velocity = b.velocity; return ((Vector3)(ref velocity)).sqrMagnitude < 0.0004f; } return true; })) { break; } if (((GrabbableObject)this).isHeld) { break; } yield return null; } if ((Object)(object)this == (Object)null) { yield break; } if ((Object)(object)model == (Object)null || parts.Any((Transform p) => (Object)(object)p == (Object)null)) { Plugin.Log.LogWarning((object)$"A body (kind {Look.Kind}) disappeared while it fell; laid out a new one"); if (Build(physics: false)) { Look.Pose = ReadPose(); Net.SendLook(this); } } else if (((GrabbableObject)this).isHeld || limp) { Look.Pose = ReadPose(); Net.SendLook(this); } else { Rest(); } } public override void LateUpdate() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) ((GrabbableObject)this).LateUpdate(); if ((Object)(object)model == (Object)null || (Object)(object)holdBy == (Object)null) { return; } if (((GrabbableObject)this).isHeld) { if (!limp) { GoLimp(); } MatchHolder(); holdBy.position = ((Component)this).transform.position; holdBy.rotation = ((Component)this).transform.rotation; ((Component)holdBy).transform.SetPositionAndRotation(((Component)this).transform.position, ((Component)this).transform.rotation); } else if (limp && !dropping) { ((MonoBehaviour)this).StartCoroutine(Drop()); } } private void GoLimp() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_003e: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) limp = true; MatchHolder(); Transform transform = model.transform; transform.position += ((Component)this).transform.position - ((Component)holdBy).transform.position; Rigidbody[] componentsInChildren = model.GetComponentsInChildren<Rigidbody>(true); foreach (Rigidbody val in componentsInChildren) { val.isKinematic = (Object)(object)val == (Object)(object)holdBy; if (!val.isKinematic) { Vector3 velocity = (val.angularVelocity = Vector3.zero); val.velocity = velocity; val.maxDepenetrationVelocity = 0.3f; val.WakeUp(); } } Collider[] componentsInChildren2 = model.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = true; } } private void MatchHolder() { Transform val = (((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && ((GrabbableObject)this).playerHeldBy.isInElevator) ? StartOfRound.Instance.elevatorTransform : null); if ((Object)(object)model.transform.parent != (Object)(object)val) { model.transform.SetParent(val, true); } } private IEnumerator Drop() { dropping = true; bool onCounter = OnCounter(); if ((Object)(object)model.transform.parent != (Object)(object)((Component)this).transform.parent) { model.transform.SetParent(((Component)this).transform.parent, true); } if (!onCounter) { holdBy.isKinematic = false; Rigidbody[] bodies = model.GetComponentsInChildren<Rigidbody>(); for (float t = 0f; t < 4f; t += Time.deltaTime) { if (!((Object)(object)model != (Object)null)) { break; } if (((GrabbableObject)this).isHeld) { break; } if (t > 1f && bodies.All(delegate(Rigidbody b) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)b == (Object)null)) { Vector3 velocity = b.velocity; return ((Vector3)(ref velocity)).sqrMagnitude < 0.0004f; } return true; })) { break; } yield return null; } } dropping = false; if ((Object)(object)this == (Object)null || (Object)(object)model == (Object)null) { yield break; } if (((GrabbableObject)this).isHeld) { limp = false; yield break; } limp = false; model.transform.SetParent(((Component)this).transform, true); Freeze(); if (Net.IsHost) { if (onCounter || OnCounter()) { LieFlat(); } else { Rest(); } } } internal bool OnCounter() { return OnCounter(((Component)this).transform); } internal static bool OnCounter(Transform item) { DepositItemsDesk val = (((Object)(object)item.parent != (Object)null) ? Object.FindObjectOfType<DepositItemsDesk>() : null); if ((Object)(object)val != (Object)null && (Object)(object)val.deskObjectsContainer != (Object)null) { return item.IsChildOf(((Component)val.deskObjectsContainer).transform); } return false; } private void LieFlat() { if (Build(physics: false)) { Look.Pose = ReadPose(); Net.SendLook(this); } } public override void OnDestroy() { if ((Object)(object)model != (Object)null) { Object.Destroy((Object)(object)model); } ((GrabbableObject)this).OnDestroy(); } private void Rest() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) Freeze(); MoveToBody(); Vector3 val = parts[0].position - ((Component)this).transform.position; if (((Vector3)(ref val)).sqrMagnitude > 9f) { Plugin.Log.LogWarning((object)$"A body ended up {Vector3.Distance(parts[0].position, ((Component)this).transform.position):0.0} m away; laid it flat instead"); Build(physics: false); } Look.Pose = ReadPose(); Net.SendLook(this); } public void Show(BodyLook look, float[] at) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (at != null && at.Length == 3 && !((GrabbableObject)this).isHeld) { PlaceAt(new Vector3(at[0], at[1], at[2])); } bool flag = (Object)(object)model != (Object)null && Look != null && Look.Seed == look.Seed && Look.Kind == look.Kind; Look = look; if (!flag || (!((GrabbableObject)this).isHeld && !limp)) { if (flag) { model.transform.SetParent(((Component)this).transform, true); Freeze(); ApplyPose(look.Pose); } else if (Build(physics: false)) { ApplyPose(look.Pose); } } } private bool Build(bool physics) { //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown //IL_0345: 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_0365: Unknown result type (might be due to invalid IL or missing references) //IL_036f: Unknown result type (might be due to invalid IL or missing references) //IL_0374: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03f5: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: 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) if ((Object)(object)model != (Object)null) { Object.Destroy((Object)(object)model); } model = null; parts = null; holdBy = null; limp = false; List<GameObject> list = StartOfRound.Instance?.playerRagdolls; if (list == null || list.Count == 0) { Plugin.Log.LogWarning((object)"The game has no player bodies to copy"); return false; } GameObject val = list[Mathf.Clamp(Look.Kind, 0, list.Count - 1)] ?? list[0]; DeadBodyInfo component = val.GetComponent<DeadBodyInfo>(); string holdName = ((component?.bodyParts != null && component.bodyParts.Length > 5 && (Object)(object)component.bodyParts[5] != (Object)null) ? ((Object)component.bodyParts[5]).name : "spine.002"); GameObject val2 = new GameObject("CrewExpendable.Off"); val2.SetActive(false); model = Object.Instantiate<GameObject>(val, val2.transform); ((Object)model).name = "Body"; DeadBodyInfo[] componentsInChildren = model.GetComponentsInChildren<DeadBodyInfo>(true); for (int i = 0; i < componentsInChildren.Length; i++) { Object.DestroyImmediate((Object)(object)componentsInChildren[i]); } foreach (Transform item in model.GetComponentsInChildren<Transform>(true).ToList()) { if (!((Object)(object)item == (Object)null) && !((Object)(object)item == (Object)(object)model.transform)) { if (((Object)item).name == "ScanNode" || ((Object)item).name == "MapDot" || ((Object)item).name.StartsWith("Beam") || ((Object)item).name == "BodyAudio" || ((Object)item).name == "NightVisionRadar") { Object.DestroyImmediate((Object)(object)((Component)item).gameObject); } else { ((Component)item).gameObject.tag = "Untagged"; } } } model.tag = "Untagged"; Looks.Dress(model, Look); Cosmetics.Wear(model, Look.Cosmetics); parts = (from r in model.GetComponentsInChildren<Rigidbody>(true) select ((Component)r).transform).ToArray(); Rigidbody[] componentsInChildren2 = model.GetComponentsInChildren<Rigidbody>(true); holdBy = ((IEnumerable<Rigidbody>)componentsInChildren2).FirstOrDefault((Func<Rigidbody, bool>)((Rigidbody r) => ((Object)r).name == holdName)) ?? componentsInChildren2.FirstOrDefault(); Rigidbody[] componentsInChildren3 = model.GetComponentsInChildren<Rigidbody>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { componentsInChildren3[i].isKinematic = !physics; } if (!physics) { Collider[] componentsInChildren4 = model.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren4.Length; i++) { componentsInChildren4[i].enabled = false; } } else { Random random = new Random(Look.Seed); model.transform.localRotation = Quaternion.identity; model.transform.position = ((Component)this).transform.position + Vector3.up * 1.1f; model.transform.rotation = Quaternion.Euler((float)random.NextDouble() * 80f - 40f, (float)random.NextDouble() * 360f, (float)random.NextDouble() * 80f - 40f); } model.transform.SetParent(((Component)this).transform, physics); Object.Destroy((Object)(object)val2); if (!physics) { model.transform.localPosition = Vector3.up * 0.15f; model.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f); } Looks.AddFlies(model, parts, Look.Flies); return true; } private void MoveToBody() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00c3: 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_00e1: 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_0108: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) if (((GrabbableObject)this).isHeld) { return; } Vector3 middle = Middle; Vector3 val = middle - ((Component)this).transform.position; if (!(((Vector3)(ref val)).sqrMagnitude > 36f)) { Vector3 position = model.transform.position; Quaternion rotation = model.transform.rotation; (Vector3, Quaternion)[] array = parts.Select((Transform p) => (position: p.position, rotation: p.rotation)).ToArray(); RaycastHit val3 = default(RaycastHit); Vector3 val2 = (Vector3)(Physics.Raycast(middle + Vector3.up * 0.2f, Vector3.down, ref val3, 2f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) ? ((RaycastHit)(ref val3)).point : new Vector3(middle.x, ((Component)this).transform.position.y, middle.z)); PlaceAt(((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent.InverseTransformPoint(val2) : val2); model.transform.SetPositionAndRotation(position, rotation); for (int num = 0; num < parts.Length; num++) { parts[num].SetPositionAndRotation(array[num].Item1, array[num].Item2); } } } internal void PlaceAt(Vector3 local) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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_0018: Unknown result type (might be due to invalid IL or missing references) ((Component)this).transform.localPosition = (((GrabbableObject)this).startFallingPosition = (((GrabbableObject)this).targetFloorPosition = local)); ((GrabbableObject)this).fallTime = 1f; ((GrabbableObject)this).hasHitGround = true; ((GrabbableObject)this).reachedFloorTarget = true; } private void Freeze() { Rigidbody[] componentsInChildren = model.GetComponentsInChildren<Rigidbody>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].isKinematic = true; } Collider[] componentsInChildren2 = model.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = false; } } private float[] ReadPose() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004a: 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_0054: 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_0067: 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) Quaternion val = Quaternion.Inverse(((Component)this).transform.rotation); float[] array = new float[parts.Length * 7]; for (int i = 0; i < parts.Length; i++) { Vector3 val2 = ((Component)this).transform.InverseTransformPoint(parts[i].position); Quaternion val3 = val * parts[i].rotation; array[i * 7] = val2.x; array[i * 7 + 1] = val2.y; array[i * 7 + 2] = val2.z; array[i * 7 + 3] = val3.x; array[i * 7 + 4] = val3.y; array[i * 7 + 5] = val3.z; array[i * 7 + 6] = val3.w; } return array; } private void ApplyPose(float[] p) { //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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) if (p == null || p.Length != parts.Length * 7) { Plugin.Log.LogWarning((object)"A body's pose doesn't match this game's bodies; laid flat"); return; } for (int i = 0; i < parts.Length; i++) { parts[i].position = ((Component)this).transform.TransformPoint(new Vector3(p[i * 7], p[i * 7 + 1], p[i * 7 + 2])); parts[i].rotation = ((Component)this).transform.rotation * new Quaternion(p[i * 7 + 3], p[i * 7 + 4], p[i * 7 + 5], p[i * 7 + 6]); } } } internal class Findable : MonoBehaviour { private void Awake() { ((Object)((Component)this).gameObject).hideFlags = (HideFlags)0; } } [HarmonyPatch(typeof(StartOfRound), "Start")] internal static class StartPatch { private static void Postfix() { Net.Init(); CrewBody.Borrow(); CrewNote.Borrow(); ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Raise.Watch()); LetterLog.Begin(); Moons.AddSettings(); } } internal class GearTable { public class Row { public string Name; public float Price; public int Tickets; } public readonly List<Row> Rows; public readonly long Total; private const int SeedBits = 27; public GearTable(IEnumerable<(string name, float price)> items, float scale) { Rows = (from i in (from i in items where i.price > 0f && Norm(i.name) != "" group i by Norm(i.name) into g select g.First()).OrderBy<(string, float), string>(((string name, float price) i) => i.name, StringComparer.OrdinalIgnoreCase) select new Row { Name = i.name, Price = i.price, Tickets = TicketsFor(i.price, scale) }).ToList(); Total = ((IEnumerable<Row>)Rows).Sum((Func<Row, long>)((Row r) => r.Tickets)); } public static int TicketsFor(float price, float scale) { return (int)Math.Max(1.0, Math.Min(1000000.0, Math.Floor((double)scale / (double)price))); } public string Draw(Random rng, Func<string, bool> allowed = null) { List<Row> list = ((allowed == null) ? Rows : Rows.Where((Row r) => allowed(r.Name)).ToList()); long num = ((IEnumerable<Row>)list).Sum((Func<Row, long>)((Row r) => r.Tickets)); if (num <= 0) { return null; } long num2 = (long)(rng.NextDouble() * (double)num); foreach (Row item in list) { if ((num2 -= item.Tickets) < 0) { return item.Name; } } return list[list.Count - 1].Name; } public static int Pieces(Random rng, float[] chances, float distance, float bonus) { double num = 1.0 - (double)bonus + 2.0 * (double)bonus * (double)Clamp01(distance); double num2 = ((IEnumerable<float>)chances).Sum((Func<float, double>)((float c) => c)) * num; if (num2 > 1.0) { num /= num2; } double num3 = rng.NextDouble(); for (int num4 = 0; num4 < chances.Length; num4++) { if ((num3 -= (double)chances[num4] * num) < 0.0) { return num4 + 1; } } return 0; } public static float Charge(Random rng, float max, float farShare, float distance) { return (float)rng.NextDouble() * max * (1f + (farShare - 1f) * Clamp01(distance)); } public static int Bodies(Random rng, int size, int small, int large, int max, float curve, float spread, float amount = 1f) { if (max <= 0 || amount <= 0f) { return 0; } float num = ((large > small) ? Clamp01((float)(size - small) / (float)(large - small)) : ((size >= large) ? 1f : 0f)); double num2 = Math.Min(max, Math.Pow(num, curve) * (double)max * (double)amount); double num3 = (rng.NextDouble() * 2.0 - 1.0) * (double)spread * (double)max; return Math.Max(0, Math.Min(max, (int)Math.Round(num2 + num3))); } public static int RiskStep(string risk) { int val = Array.IndexOf(new string[8] { "D", "C", "B", "A", "S", "S+", "S++", "S+++" }, (risk ?? "").Trim().ToUpperInvariant()); return Math.Max(0, val); } public static string SettingName(string moon) { return new string((moon ?? "").Where((char ch) => !char.IsControl(ch) && "=\"'[]\\".IndexOf(ch) < 0).ToArray()).Trim(); } public static List<(string key, string value)> ReadPairs(string list) { return (from p in (list ?? "").Split(';') select p.Split('=') into p where p.Length == 2 select (key: Norm(p[0]), value: Norm(p[1])) into p where p.key != "" && p.value != "" select p).ToList(); } public static int PickKind(Random rng, double plain, List<(int kind, double weight)> kinds) { bool num = rng.NextDouble() < plain; double num2 = rng.NextDouble() * kinds.Sum(((int kind, double weight) k) => k.weight); if (num) { return 0; } foreach (var kind in kinds) { if ((num2 -= kind.weight) < 0.0) { return kind.kind; } } return 0; } public static int SeedWithKind(int seed, int kind) { return (seed & 0x7FFFFFF) | (((kind >= 0 && kind < 15) ? (kind + 1) : 0) << 27); } public static int KindInSeed(int seed) { return ((seed >> 27) & 0xF) - 1; } public static float Clamp01(float v) { if (!(v < 0f)) { if (!(v > 1f)) { return v; } return 1f; } return 0f; } public static string Norm(string s) { return new string((s ?? "").ToLowerInvariant().Where(char.IsLetterOrDigit).ToArray()); } public static HashSet<string> Names(string list) { return new HashSet<string>(from n in (list ?? "").Split(';').Select(Norm) where n != "" select n); } public static Dictionary<string, float> ReadPrices(string list) { Dictionary<string, float> dictionary = new Dictionary<string, float>(); string[] array = (list ?? "").Split(';'); foreach (string text in array) { int num = text.LastIndexOf('='); if (num > 0 && float.TryParse(text.Substring(num + 1).Trim(), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var result) && result > 0f) { dictionary[Norm(text.Substring(0, num))] = result; } } return dictionary; } } internal static class LetterLog { public class Entry { public string Text; public string Moon; public int Day; public int Key; } [HarmonyPatch(typeof(Terminal))] internal static class TerminalPatch { [HarmonyPostfix] [HarmonyPatch("Start")] private static void AddToHelp(Terminal __instance) { TerminalNode val = __instance.terminalNodes?.allKeywords?.FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => (Object)(object)k != (Object)null && k.word == "help"))?.specialKeywordResult; if (!((Object)(object)val == (Object)null) && !val.displayText.Contains(">LETTERS")) { int num = val.displayText.IndexOf("[numberOfItemsOnRoute]"); val.displayText = ((num >= 0) ? val.displayText.Insert(num, ">LETTERS\nLetters you've found by other crews' bodies.\n\n") : (val.displayText.TrimEnd('\n') + "\n\n>LETTERS\nLetters you've found by other crews' bodies.\n\n")); } } [HarmonyPrefix] [HarmonyPatch("ParsePlayerSentence")] private static bool Parse(Terminal __instance, ref TerminalNode __result) { TMP_InputField screenText = __instance.screenText; string text = ((screenText != null) ? screenText.text : null); if (text == null || __instance.textAdded <= 0 || text.Length < __instance.textAdded) { return true; } if ((Object)(object)__instance.currentNode != (Object)null && __instance.currentNode.overrideOptions) { return true; } string[] array = text.Substring(text.Length - __instance.textAdded).Trim().ToLowerInvariant() .Split(new char[1] { ' ' }, 2); if (array[0] != "letters" && array[0] != "letter") { return true; } __result = ScriptableObject.CreateInstance<TerminalNode>(); __result.displayText = Page((array.Length > 1) ? array[1].Trim() : "") + "\n\n"; __result.clearPreviousText = true; __result.maxCharactersToType = 35; return false; } } private const string SaveKey = "CrewExpendable.Letters"; private const int Most = 500; public static List<Entry> All = new List<Entry>(); private static bool synced; public static void Begin() { All = new List<Entry>(); synced = false; if (Net.IsHost) { Load(); } else { ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(AskUntilSynced()); } } private static IEnumerator AskUntilSynced() { while (!synced && (Object)(object)StartOfRound.Instance != (Object)null && !Net.IsHost) { Net.AskLog(); yield return (object)new WaitForSeconds(3f); } } internal static void Load() { All = new List<Entry>(); try { string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName; if (ES3.KeyExists("CrewExpendable.Letters", currentSaveFileName)) { All = JsonConvert.DeserializeObject<List<Entry>>(ES3.Load<string>("CrewExpendable.Letters", currentSaveFileName)) ?? new List<Entry>(); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't load the letters saved on the terminal: " + ex.Message)); } Words.StartUsed(All.Select((Entry e) => Words.Text.ByKey(e.Key)?.Id)); } public static void Add(Entry e, bool old) { if (Net.IsHost && Plugin.C.KeepOnTerminal.Value && !string.IsNullOrEmpty(e.Text) && !All.Any((Entry a) => (a.Text == e.Text && a.Day == e.Day && a.Moon == e.Moon) || (old && (a.Text == e.Text || (e.Key != 0 && a.Key == e.Key))))) { Got(e); try { ES3.Save<string>("CrewExpendable.Letters", JsonConvert.SerializeObject((object)All), GameNetworkManager.Instance.currentSaveFileName); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't save the letters on the terminal: " + ex.Message)); } Net.SendLetter(e); } } public static void Got(Entry e) { All.Add(e); if (All.Count > 500) { All.RemoveRange(0, All.Count - 500); } HUDManager instance = HUDManager.Instance; if (instance != null) { instance.DisplayGlobalNotification("Letter saved to the terminal: LETTERS"); } } public static void Sync(List<Entry> all) { All = all ?? new List<Entry>(); synced = true; } internal static string Page(string which) { if (All.Count == 0) { return "LETTERS\n\nNone yet. Crews leave letters by their bodies.\nRead one, and it's saved here."; } if (which != "") { if (!int.TryParse(which, out var result) || result < 1 || result > All.Count) { return "There's no letter " + which + ". Type LETTERS for the list."; } Entry entry = All[result - 1]; return $"LETTER {result}\nFound on {entry.Moon}, day {entry.Day}\n\n{entry.Text}\n\nType LETTERS for the list."; } StringBuilder stringBuilder = new StringBuilder("LETTERS\n\nType LETTERS and a number to read one.\n\n"); for (int num = All.Count - 1; num >= 0; num--) { string text = All[num].Text.Split(new string[1] { "\n\n" }, StringSplitOptions.None).Last().Split('\n')[0]; if (text.Length > 32) { text = text.Substring(0, 30).TrimEnd() + "..."; } stringBuilder.Append(num + 1).Append(". ").Append(All[num].Moon) .Append(", day ") .Append(All[num].Day) .Append("\n ") .Append(text) .Append("\n\n"); } return stringBuilder.ToString().TrimEnd(); } } internal static class Looks { public static BodyLook Choose(int seed) { Random random = new Random(seed); Cfg c = Plugin.C; BodyLook bodyLook = new BodyLook { Seed = seed }; double num = random.NextDouble(); double num2 = random.NextDouble(); double num3 = random.NextDouble(); double num4 = random.NextDouble(); double num5 = random.NextDouble(); double num6 = random.NextDouble(); double num7 = random.NextDouble(); bodyLook.Flies = ((!(num >= (double)c.FliesChance.Value)) ? ((!(num2 < (double)c.HeavyFliesChance.Value)) ? 1 : 2) : 0); HashSet<string> banned = GearTable.Names(c.BannedSuits.Value); if (Tailor.Available) { banned.Add(GearTable.Norm(Tailor.SuitName)); } List<string> list = (from u in StartOfRound.Instance.unlockablesList?.unlockables ?? new List<UnlockableItem>() where u != null && (Object)(object)u.suitMaterial != (Object)null && !banned.Contains(GearTable.Norm(u.unlockableName)) && (c.LockedSuits.Value || u.alreadyUnlocked || u.hasBeenUnlockedByPlayer) select u.unlockableName).Distinct().OrderBy<string, string>((string n) => n, StringComparer.Ordinal).ToList(); if (list.Count > 0) { bodyLook.Suit = list[(int)(num3 * (double)list.Count)]; } if (num5 < (double)c.TailorChance.Value) { string[] array = Tailor.Designs(c.SavedSuits.Value); if (array.Length != 0) { bodyLook.Tailor = array[(int)(num6 * (double)array.Length)]; } } List<GameObject> playerRagdolls = StartOfRound.Instance.playerRagdolls; List<int> list2 = Unusual(); int num8 = GearTable.KindInSeed(seed); bodyLook.Kind = ((num8 == 0 || list2.Contains(num8)) ? num8 : ((list2.Count != 0 && !(num4 < (double)c.PlainChance.Value)) ? list2[(int)((num4 - (double)c.PlainChance.Value) / (1.0 - (double)c.PlainChance.Value) * (double)list2.Count)] : 0)); if (num7 < (double)c.CosmeticsChance.Value) { bodyLook.Cosmetics = Cosmetics.Choose(random, c.MaxCosmetics.Value, !Headless(playerRagdolls[bodyLook.Kind])); } return bodyLook; } public static List<int> Unusual() { List<GameObject> kinds = StartOfRound.Instance.playerRagdolls; if (Plugin.C.Variants.Value) { return (from i in Enumerable.Range(1, Math.Max(0, kinds.Count - 1)) where Whole(kinds[i]) select i).ToList(); } return new List<int>(); } public static bool Headless(GameObject kind) { if ((Object)(object)kind != (Object)null) { if (!((Object)kind).name.Contains("Head") && !((Object)kind).name.Contains("Spring")) { return kind.GetComponent<DeadBodyInfo>()?.detachedHead ?? false; } return true; } return false; } public static bool CanRise(int kind) { List<GameObject> playerRagdolls = StartOfRound.Instance.playerRagdolls; GameObject val = ((kind >= 0 && kind < playerRagdolls.Count) ? playerRagdolls[kind] : null); if ((Object)(object)val != (Object)null) { if (!Plugin.C.RaiseAnyBody.Value) { if (!Headless(val) && !((Object)val).name.Contains("Slice")) { return val.GetComponent<DeadBodyInfo>()?.setMaterialToPlayerSuit ?? true; } return false; } return true; } return false; } private static bool Whole(GameObject kind) { if ((Object)(object)kind != (Object)null && (Object)(object)kind.GetComponent<DeadBodyInfo>() != (Object)null && !((Object)kind).name.Contains("Mask") && (Object)(object)kind.GetComponentInChildren<SkinnedMeshRenderer>(true) != (Object)null) { return kind.GetComponentsInChildren<Rigidbody>(true).Length >= 8; } return false; } public static void Dress(GameObject model, BodyLook look) { List<GameObject> playerRagdolls = StartOfRound.Instance.playerRagdolls; GameObject obj = playerRagdolls[Mathf.Clamp(look.Kind, 0, playerRagdolls.Count - 1)]; DeadBodyInfo val = ((obj != null) ? obj.GetComponent<DeadBodyInfo>() : null); if (!((Object)(object)val != (Object)null) || val.setMaterialToPlayerSuit) { SkinnedMeshRenderer componentInChildren = model.GetComponentInChildren<SkinnedMeshRenderer>(true); if ((Object)(object)componentInChildren != (Object)null) { Paint((Renderer)(object)componentInChildren, look); } } } public static void Paint(Renderer skin, BodyLook look) { UnlockableItem val = ((IEnumerable<UnlockableItem>)StartOfRound.Instance.unlockablesList.unlockables).FirstOrDefault((Func<UnlockableItem, bool>)((UnlockableItem u) => u != null && (Object)(object)u.suitMaterial != (Object)null && u.unlockableName == look.Suit)); if (val != null) { skin.sharedMaterial = val.suitMaterial; } Tailor.Paint(skin, look.Tailor); } public static void AddFlies(GameObject model, Transform[] parts, int amount) { //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_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Invalid comparison between Unknown and I4 if (amount <= 0) { return; } RandomFlyParticle val = ((IEnumerable<Item>)StartOfRound.Instance.allItemsList.itemsList).Select((Func<Item, RandomFlyParticle>)delegate(Item i) { if (i == null) { return (RandomFlyParticle)null; } GameObject spawnPrefab = i.spawnPrefab; return (spawnPrefab == null) ? null : spawnPrefab.GetComponent<RandomFlyParticle>(); }).FirstOrDefault((Func<RandomFlyParticle, bool>)((RandomFlyParticle f) => (Object)(object)f != (Object)null)); GameObject val2 = (((Object)(object)val == (Object)null) ? null : ((amount >= 2 && (Object)(object)val.badFlyPrefab != (Object)null) ? val.badFlyPrefab : val.flyPrefab)); if ((Object)(object)val2 == (Object)null) { Plugin.Log.LogWarning((object)"No fly effect found in this version of the game"); return; } Transform val3 = ((parts != null && parts.Length != 0) ? parts[0] : model.transform); GameObject val4 = Object.Instantiate<GameObject>(val2, val3.position, Quaternion.identity, val3); ((Object)val4).name = "Flies"; SkinnedMeshRenderer componentInChildren = model.GetComponentInChildren<SkinnedMeshRenderer>(true); ParticleSystem[] componentsInChildren = val4.GetComponentsInChildren<ParticleSystem>(true); for (int num = 0; num < componentsInChildren.Length; num++) { ShapeModule shape = componentsInChildren[num].shape; if ((Object)(object)componentInChildren != (Object)null && (int)((ShapeModule)(ref shape)).shapeType == 13) { ((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)14; ((ShapeModule)(ref shape)).skinnedMeshRenderer = componentInChildren; } } AudioSource componentInChildren2 = val4.GetComponentInChildren<AudioSource>(); if ((Object)(object)componentInChildren2 != (Object)null) { componentInChildren2.pitch = Random.Range(0.9f, 1.5f); componentInChildren2.volume = Random.Range(0.5f, 1f); componentInChildren2.Play(); } } } internal class LoreText { public class Note { public string Id; public string Basis; public string Text; public string Moon; public string Scrap; public string Monster; public string Body; public int Rarity = 1; } public class Letter { public string Basis; public string Text; } public class LetterSet { public List<string> Plain = new List<string>(); public List<Letter> Lore = new List<Letter>(); } public class Place { public string Moon; public HashSet<string> Scrap = new HashSet<string>(); public HashSet<string> Monsters = new HashSet<string>(); public bool Fresh; } public List<Note> Notes = new List<Note>(); public LetterSet Letters = new LetterSet(); public List<string> Relations = new List<string>(); public List<string> ScrapHints = new List<string>(); public Dictionary<string, List<string>> Warnings = new Dictionary<string, List<string>>(); public List<string> AnyWarning = new List<string>(); public static bool Fits(Note n, Place p) { if ((n.Moon == null || n.Moon == p.Moon) && (n.Scrap == null || p.Scrap.Contains(n.Scrap)) && (n.Monster == null || p.Monsters.Contains(n.Monster))) { if (!(n.Body != "fresh")) { return p.Fresh; } return true; } return false; } public Note PickNote(Random rng, Place p, Func<string, bool> basis, HashSet<string> used) { List<Note> list = Notes.Where((Note n) => basis(n.Basis) && Fits(n, p)).ToList(); List<Note> list2 = list.Where((Note n) => !used.Contains(n.Id)).ToList(); if (list2.Count == 0) { foreach (Note item in list) { used.Remove(item.Id); } list2 = list; } int num = ((list2.Count != 0) ? rng.Next(((IEnumerable<Note>)list2).Sum((Func<Note, int>)Weight)) : 0); foreach (Note item2 in list2) { if ((num -= Weight(item2)) < 0) { used.Add(item2.Id); return item2; } } return null; static int Weight(Note n) { return ((n.Rarity <= 1) ? 6 : ((n.Rarity != 2) ? 1 : 3)) * ((n.Moon == null && n.Scrap == null && n.Monster == null) ? 1 : 2); } } public static int Key(string id) { uint num = 2166136261u; foreach (char c in id) { num = (num ^ c) * 16777619; } return (int)((num & 0x7FFFFFFF) | 1); } public Note ByKey(int key) { if (key != 0) { return Notes.FirstOrDefault((Note n) => Key(n.Id) == key); } return null; } public string Warning(Random rng, string enemyName) { if (!Warnings.TryGetValue(enemyName, out var value) || value.Count <= 0) { return string.Format(Any(rng, AnyWarning), enemyName); } return Any(rng, value); } public string ScrapHint(Random rng, string item, string where) { return string.Format(Any(rng, ScrapHints), item, where); } public List<string> PickLetters(Random rng, int count, double loreChance, Func<string, bool> basis) { List<string> list = Shuffle(rng, Letters.Plain); List<string> list2 = Shuffle(rng, from l in Letters.Lore where basis(l.Basis) select l.Text); List<string> list3 = new List<string>(); int num = 0; int num2 = 0; for (int num3 = 0; num3 < count; num3++) { bool flag = rng.NextDouble() < loreChance && list2.Count > 0; if (!flag && list.Count == 0) { break; } string text = (flag ? list2[num2++ % list2.Count] : list[num++ % list.Count]); list3.Add(text + "\n\n- Their " + Any(rng, Relations)); } return list3; } public static string Where(float ahead, float right, float up) { List<string> list = new List<string>(); if (Round(ahead) > 0) { list.Add(string.Format("{0} m {1}", Round(ahead), (ahead > 0f) ? "ahead" : "back behind you")); } if (Round(right) > 0) { list.Add(string.Format("{0} m to the {1}", Round(right), (right > 0f) ? "right" : "left")); } if (Math.Abs(up) >= 2.5f) { list.Add(string.Format("{0} m {1}", Round(up), (up > 0f) ? "up" : "down")); } if (list.Count != 0) { return "coming in the main entrance, about " + string.Join(", ", list); } return "it's right by the main entrance"; static int Round(float v) { return (int)Math.Round(Math.Abs(v) / 5f) * 5; } } private static T Any<T>(Random rng, List<T> list) { return list[rng.Next(list.Count)]; } private static List<string> Shuffle(Random rng, IEnumerable<string> list) { return (from t in list select (t: t, rng.Next()) into x orderby x.Item2 select x.t).ToList(); } } internal static class Moons { private class Own { public ConfigEntry<float> Amount; public ConfigEntry<int> Most; } private static readonly Dictionary<string, Own> own = new Dictionary<string, Own>(); public static void AddSettings() { //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Expected O, but got Unknown SelectableLevel[] array = StartOfRound.Instance?.levels; if (array == null) { return; } List<SelectableLevel> list = array.Where((SelectableLevel l) => (Object)(object)l != (Object)null && l.spawnEnemiesAndScrap && !own.ContainsKey(Name(l))).ToList(); if (list.Count == 0) { return; } ConfigFile config = Plugin.C.Config; bool saveOnConfigSet = config.SaveOnConfigSet; config.SaveOnConfigSet = false; try { foreach (SelectableLevel item in list) { string text = Name(item); if (!(text == "") && !own.ContainsKey(text)) { own[text] = new Own { Amount = config.Bind<float>("Moons", text + " amount", 1f, new ConfigDescription("How many bodies " + text + " gets, compared with usual. 0 = none, 2 = twice as many.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>())), Most = config.Bind<int>("Moons", text + " most", -1, new ConfigDescription("The most bodies on " + text + ". -1 = the usual MaxBodies.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1, 64), Array.Empty<object>())) }; } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't make settings for every moon: " + ex.Message)); } finally { config.SaveOnConfigSet = saveOnConfigSet; } if (saveOnConfigSet) { config.Save(); } } private static string Name(SelectableLevel l) { return GearTable.SettingName(l.PlanetName); } public static (int most, float amount) For(SelectableLevel level) { AddSettings(); int value = Plugin.C.MaxBodies.Value; float num = 1f + Plugin.C.RiskBonus.Value * (float)GearTable.RiskStep(level.riskLevel); if (own.TryGetValue(Name(level), out var value2)) { if (value2.Most.Value >= 0) { value = value2.Most.Value; } num *= value2.Amount.Value; } return (most: value, amount: num); } public static List<(int kind, double weight)> Deaths(SelectableLevel level) { Cfg c = Plugin.C; Dictionary<string, double> shares = new Dictionary<string, double>(); List<SpawnableEnemyWithRarity>[] array = new List<SpawnableEnemyWithRarity>[3] { level.Enemies, level.OutsideEnemies, level.DaytimeEnemies }; for (int i = 0; i < array.Length; i++) { List<SpawnableEnemyWithRarity> list = (array[i] ?? new List<SpawnableEnemyWithRarity>()).Where((SpawnableEnemyWithRarity e) => (Object)(object)e?.enemyType != (Object)null && e.rarity > 0).ToList(); double num = ((IEnumerable<SpawnableEnemyWithRarity>)list).Sum((Func<SpawnableEnemyWithRarity, double>)((SpawnableEnemyWithRarity e) => e.rarity)); foreach (SpawnableEnemyWithRarity item2 in list) { string key = GearTable.Norm(item2.enemyType.enemyName); shares.TryGetValue(key, out var value); shares[key] = value + (double)item2.rarity / num; } } List<(string key, string value)> leaves = GearTable.ReadPairs(c.DeathsByMonster.Value); List<GameObject> kinds = StartOfRound.Instance.playerRagdolls; return Looks.Unusual().Select(delegate(int k) { string kind = GearTable.Norm(((Object)kinds[k]).name); double item = ((!c.MatchMonsters.Value) ? 1.0 : ((double)c.OtherDeaths.Value + leaves.Where(((string key, string value) p) => kind.Contains(p.value) && shares.ContainsKey(p.key)).Sum(((string key, string value) p) => shares[p.key]))); return (k: k, w: item); }).ToList(); } } internal static class Net { private class Msg { public ulong Id; public BodyLook Look; public int Value; public string Text; public List<string> Letters; public float Seconds; public bool Outside; public bool Keep; public List<LetterLog.Entry> Log; public LetterLog.Entry Entry; public float[] At; } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static HandleNamedMessageDelegate <>9__15_0; public static HandleNamedMessageDelegate <>9__15_1; public static HandleNamedMessageDelegate <>9__15_2; public static HandleNamedMessageDelegate <>9__15_3; public static HandleNamedMessageDelegate <>9__15_4; public static HandleNamedMessageDelegate <>9__15_5; public static HandleNamedMessageDelegate <>9__15_6; public static HandleNamedMessageDelegate <>9__15_7; public static HandleNamedMessageDelegate <>9__15_8; public static HandleNamedMessageDelegate <>9__15_9; internal void <Init>b__15_0(ulong who, FastBufferReader r) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (IsHost) { ulong id = default(ulong); ((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives)); CrewNote crewNote = Net.Find<CrewNote>(id); if ((Object)(object)crewNote != (Object)null) { Send("CrewExpendable.Note", new Msg { Id = id, Text = crewNote.ReadAndKeep() }, who); } } } internal void <Init>b__15_1(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg != null && msg.Text != null) { Net.Find<CrewNote>(msg.Id)?.Open(msg.Text); } } } internal void <Init>b__15_2(ulong who, FastBufferReader r) { if (IsHost) { Send("CrewExpendable.Log", new Msg { Log = LetterLog.All }, who); } } internal void <Init>b__15_3(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg != null) { LetterLog.Sync(msg.Log); } } } internal void <Init>b__15_4(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg?.Entry != null) { LetterLog.Got(msg.Entry); } } } internal void <Init>b__15_5(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg?.Look != null) { ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Raise.Apply(msg.Id, msg.Look, msg.Outside, msg.Keep)); } } } internal void <Init>b__15_6(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg?.Letters != null) { ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Words.ShowLetters(msg.Letters, msg.Seconds)); } } } internal void <Init>b__15_7(ulong who, FastBufferReader r) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (IsHost) { ulong id = default(ulong); ((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives)); CrewBody crewBody = Find(id); if (crewBody?.Look?.Pose != null) { Send("CrewExpendable.Look", Message(crewBody), who); } } } internal void <Init>b__15_8(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); CrewBody crewBody = ((msg == null) ? null : Find(msg.Id)); if (!((Object)(object)crewBody == (Object)null) && msg.Look != null) { crewBody.Show(msg.Look, msg.At); ((GrabbableObject)crewBody).SetScrapValue(msg.Value); } } } internal void <Init>b__15_9(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg != null) { ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(SetValue(msg.Id, msg.Value)); } } } } private const string MAsk = "CrewExpendable.Ask"; private const string MLook = "CrewExpendable.Look"; private const string MValue = "CrewExpendable.Value"; private const string MAskNote = "CrewExpendable.AskNote"; private const string MNote = "CrewExpendable.Note"; private const string MLetters = "CrewExpendable.Letters"; private const string MRaised = "CrewExpendable.Raised"; private const string MAskLog = "CrewExpendable.AskLog"; private const string MLog = "CrewExpendable.Log"; private const string MEntry = "CrewExpendable.Entry"; private static NetworkManager NM => NetworkManager.Singleton; public static bool IsHost { get { if ((Object)(object)NM != (Object)null) { return NM.IsServer; } return false; } } public static void Init() { //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown //IL_0116: 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_0121: Expected O, but got Unknown //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Expected O, but got Unknown //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Expected O, but got Unknown //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Expected O, but got Unknown //IL_01be: 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_01c9: Expected O, but got Unknown //IL_01e8: 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_01f3: Expected O, but got Unknown //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Expected O, but got Unknown //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Expected O, but got Unknown NetworkManager nM = NM; CustomMessagingManager val = ((nM != null) ? nM.CustomMessagingManager : null); if (val == null) { return; } string[] array = new string[3] { "CrewExpendable.Ask", "CrewExpendable.Look", "CrewExpendable.Value" }; foreach (string text in array) { val.UnregisterNamedMessageHandler(text); } array = new string[7] { "CrewExpendable.AskNote", "CrewExpendable.Note", "CrewExpendable.Letters", "CrewExpendable.Raised", "CrewExpendable.AskLog", "CrewExpendable.Log", "CrewExpendable.Entry" }; foreach (string text2 in array) { val.UnregisterNamedMessageHandler(text2); } object obj = <>c.<>9__15_0; if (obj == null) { HandleNamedMessageDelegate val2 = delegate(ulong who, FastBufferReader r) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (IsHost) { ulong id = default(ulong); ((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives)); CrewNote crewNote = Net.Find<CrewNote>(id); if ((Object)(object)crewNote != (Object)null) { Send("CrewExpendable.Note", new Msg { Id = id, Text = crewNote.ReadAndKeep() }, who); } } }; <>c.<>9__15_0 = val2; obj = (object)val2; } val.RegisterNamedMessageHandler("CrewExpendable.AskNote", (HandleNamedMessageDelegate)obj); object obj2 = <>c.<>9__15_1; if (obj2 == null) { HandleNamedMessageDelegate val3 = delegate(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg != null && msg.Text != null) { Net.Find<CrewNote>(msg.Id)?.Open(msg.Text); } } }; <>c.<>9__15_1 = val3; obj2 = (object)val3; } val.RegisterNamedMessageHandler("CrewExpendable.Note", (HandleNamedMessageDelegate)obj2); object obj3 = <>c.<>9__15_2; if (obj3 == null) { HandleNamedMessageDelegate val4 = delegate(ulong who, FastBufferReader r) { if (IsHost) { Send("CrewExpendable.Log", new Msg { Log = LetterLog.All }, who); } }; <>c.<>9__15_2 = val4; obj3 = (object)val4; } val.RegisterNamedMessageHandler("CrewExpendable.AskLog", (HandleNamedMessageDelegate)obj3); object obj4 = <>c.<>9__15_3; if (obj4 == null) { HandleNamedMessageDelegate val5 = delegate(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg != null) { LetterLog.Sync(msg.Log); } } }; <>c.<>9__15_3 = val5; obj4 = (object)val5; } val.RegisterNamedMessageHandler("CrewExpendable.Log", (HandleNamedMessageDelegate)obj4); object obj5 = <>c.<>9__15_4; if (obj5 == null) { HandleNamedMessageDelegate val6 = delegate(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg?.Entry != null) { LetterLog.Got(msg.Entry); } } }; <>c.<>9__15_4 = val6; obj5 = (object)val6; } val.RegisterNamedMessageHandler("CrewExpendable.Entry", (HandleNamedMessageDelegate)obj5); object obj6 = <>c.<>9__15_5; if (obj6 == null) { HandleNamedMessageDelegate val7 = delegate(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg?.Look != null) { ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Raise.Apply(msg.Id, msg.Look, msg.Outside, msg.Keep)); } } }; <>c.<>9__15_5 = val7; obj6 = (object)val7; } val.RegisterNamedMessageHandler("CrewExpendable.Raised", (HandleNamedMessageDelegate)obj6); object obj7 = <>c.<>9__15_6; if (obj7 == null) { HandleNamedMessageDelegate val8 = delegate(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg?.Letters != null) { ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Words.ShowLetters(msg.Letters, msg.Seconds)); } } }; <>c.<>9__15_6 = val8; obj7 = (object)val8; } val.RegisterNamedMessageHandler("CrewExpendable.Letters", (HandleNamedMessageDelegate)obj7); object obj8 = <>c.<>9__15_7; if (obj8 == null) { HandleNamedMessageDelegate val9 = delegate(ulong who, FastBufferReader r) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (IsHost) { ulong id = default(ulong); ((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref id, default(ForPrimitives)); CrewBody crewBody = Find(id); if (crewBody?.Look?.Pose != null) { Send("CrewExpendable.Look", Message(crewBody), who); } } }; <>c.<>9__15_7 = val9; obj8 = (object)val9; } val.RegisterNamedMessageHandler("CrewExpendable.Ask", (HandleNamedMessageDelegate)obj8); object obj9 = <>c.<>9__15_8; if (obj9 == null) { HandleNamedMessageDelegate val10 = delegate(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); CrewBody crewBody = ((msg == null) ? null : Find(msg.Id)); if (!((Object)(object)crewBody == (Object)null) && msg.Look != null) { crewBody.Show(msg.Look, msg.At); ((GrabbableObject)crewBody).SetScrapValue(msg.Value); } } }; <>c.<>9__15_8 = val10; obj9 = (object)val10; } val.RegisterNamedMessageHandler("CrewExpendable.Look", (HandleNamedMessageDelegate)obj9); object obj10 = <>c.<>9__15_9; if (obj10 == null) { HandleNamedMessageDelegate val11 = delegate(ulong who, FastBufferReader r) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (!IsHost && who == 0L) { Msg msg = Read(r); if (msg != null) { ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(SetValue(msg.Id, msg.Value)); } } }; <>c.<>9__15_9 = val11; obj10 = (object)val11; } val.RegisterNamedMessageHandler("CrewExpendable.Value", (HandleNamedMessageDelegate)obj10); } private static Msg Message(CrewBody b) { Msg msg = new Msg(); msg.Id = ((NetworkBehaviour)b).NetworkObjectId; msg.Look = b.Look; msg.Value = ((GrabbableObject)b).scrapValue; msg.At = (((GrabbableObject)b).isHeld ? null : new float[3] { ((GrabbableObject)b).targetFloorPosition.x, ((GrabbableObject)b).targetFloorPosition.y, ((GrabbableObject)b).targetFloorPosition.z }); return msg; } private static Msg Read(FastBufferReader r) { try { string text = default(string); ((FastBufferReader)(ref r)).ReadValueSafe(ref text, false); return JsonConvert.DeserializeObject<Msg>(text); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't read a message from the host: " + ex.Message)); return null; } } private static CrewBody Find(ulong id) { return Net.Find<CrewBody>(id); } internal static T Find<T>(ulong id) where T : Component { NetworkManager nM = NM; if (((nM != null) ? nM.SpawnManager : null) == null || !NM.SpawnManager.SpawnedObjects.TryGetValue(id, out var value) || !((Object)(object)value != (Object)null)) { return default(T); } return ((Component)value).GetComponent<T>(); } public static void Ask(ulong id) { AskFor("CrewExpendable.Ask", id); } public static void AskNote(ulong id) { AskFor("CrewExpendable.AskNote", id); } public static void AskLog() { AskFor("CrewExpendable.AskLog", 0uL); } public static void SendLetter(LetterLog.Entry e) { ToOthers("CrewExpendable.Entry", new Msg { Entry = e }); } public static void SendLetters(List<string> letters, float seconds) { ToOthers("CrewExpendable.Letters", new Msg { Letters = letters, Seconds = seconds }); ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Words.ShowLetters(letters, seconds)); } public static void SendRaised(ulong id, BodyLook look, bool outside, bool keep) { ToOthers("CrewExpendable.Raised", new Msg { Id = id, Look = look, Outside = outside, Keep = keep }); ((MonoBehaviour)StartOfRound.Instance).StartCoroutine(Raise.Apply(id, look, outside, keep)); } private unsafe static void AskFor(string name, ulong id) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) NetworkManager nM = NM; if (((nM != null) ? nM.CustomMessagingManager : null) == null) { return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref id, default(ForPrimitives)); NM.CustomMessagingManager.SendNamedMessage(name, 0uL, val, (NetworkDelivery)3); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } public static void SendLook(CrewBody b) { ToOthers("CrewExpendable.Look", Message(b)); } public static void SendValue(GrabbableObject g, int value) { ToOthers("CrewExpendable.Value", new Msg { Id = ((NetworkBehaviour)g).NetworkObjectId, Value = value }); } private static IEnumerator SetValue(ulong id, int value) { float end = Time.time + 10f; while (Time.time < end) { NetworkManager nM = NM; if (((nM != null) ? nM.SpawnManager : null) != null && NM.SpawnManager.SpawnedObjects.TryGetValue(id, out var value2) && (Object)(object)value2 != (Object)null) { GrabbableObject component = ((Component)value2).GetComponent<GrabbableObject>(); if ((Object)(object)component != (Object)null) { component.SetScrapValue(value); Uncounted.Mark(component); } break; } yield return null; } } private static void ToOthers(string name, Msg m) { if (!IsHost) { return; } foreach (ulong connectedClientsId in NM.ConnectedClientsIds) { if (connectedClientsId != NM.LocalClientId) { Send(name, m, connectedClientsId); } } } private unsafe static void Send(string name, Msg m, ulong to) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) string text = JsonConvert.SerializeObject((object)m); FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(FastBufferWriter.GetWriteSize(text, false) + 16, (Allocator)2, 1048576); try { ((FastBufferWriter)(ref val)).WriteValueSafe(text, false); NM.CustomMessagingManager.SendNamedMessage(name, to, val, (NetworkDelivery)4); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } } internal enum From { Both, CrewExpendable, Remnants } internal enum LookFrom { Mirage, CrewExpendable } internal class Parts { public readonly bool OurBodies; public readonly bool OurGear; public readonly bool TheirBodies; public readonly bool TheirGear; public bool WePlaceTheirs { get { if (TheirBodies) { return !TheirGear; } return false; } } public bool GearByTheirs { get { if (TheirBodies && TheirGear && !OurBodies) { return OurGear; } return false; } } public bool UsePlaces { get { if (!OurBodies) { return WePlaceTheirs; } return true; } } public Parts(bool remnants, From bodies, From gear) { OurBodies = !remnants || bodies != From.Remnants; OurGear = !remnants || gear != From.Remnants; TheirBodies = remnants && bodies != From.CrewExpendable; TheirGear = remnants && gear != From.CrewExpendable; } public bool TheirsHere(double roll) { if (WePlaceTheirs) { if (OurBodies) { return roll < 0.5; } return true; } return false; } } [BepInPlugin("nine78.crewexpendable", "Crew Expendable", "0.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "nine78.crewexpendable"; public const string Name = "Crew Expendable"; public const string Version = "0.1.0"; internal static ManualLogSource Log; internal static Cfg C; private void Awake() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; C = new Cfg(((BaseUnityPlugin)this).Config); CrewBody.Register(); CrewNote.Register(); Harmony val = new Harmony("nine78.crewexpendable"); val.PatchAll(typeof(Plugin).Assembly); RemnantsMod.Setup(val); GameObject val2 = new GameObject("CrewExpendable.Runner"); Object.DontDestroyOnLoad((Object)val2); ((Object)val2).hideFlags = (HideFlags)61; SelfTest.Start((MonoBehaviour)(object)val2.AddComponent<Runner>()); Log.LogInfo((object)"Crew Expendable 0.1.0 loaded"); } } internal class Runner : MonoBehaviour { } internal enum ListMode { Blacklist, Whitelist } internal enum RnDGear { None, Unlocked, All } internal class Cfg { public ConfigEntry<int> MaxBodies; public ConfigEntry<int> SmallInterior; public ConfigEntry<int> LargeInterior; public ConfigEntry<int> MinValue; public ConfigEntry<int> MaxValue; public ConfigEntry<int> MaxCopies; public ConfigEntry<int> MaxCosmetics; public ConfigEntry<float> SizeCurve; public ConfigEntry<float> Spread; public ConfigEntry<float> Spacing; public ConfigEntry<float> MinFromMain; public ConfigEntry<float> MinFromFire; public ConfigEntry<float> NearMain; public ConfigEntry<float> FarMain; public ConfigEntry<float> NearFire; public ConfigEntry<float> FarFire; public ConfigEntry<float> FliesChance; public ConfigEntry<float> HeavyFliesChance; public ConfigEntry<float> TailorChance; public ConfigEntry<float> CosmeticsChance; public ConfigEntry<float> One; public ConfigEntry<float> Two; public ConfigEntry<float> Three; public ConfigEntry<float> Four; public ConfigEntry<float> FarBonus; public ConfigEntry<float> TicketScale; public ConfigEntry<float> MaxCharge; public ConfigEntry<float> FarCharge; public ConfigEntry<float> NoteChance; public ConfigEntry<float> WarningChance; public ConfigEntry<float> LetterSeconds; public ConfigEntry<float> LoreNoteChance; public ConfigEntry<float> LoreLetterChance; public ConfigEntry<int> MaxLetters; public ConfigEntry<int> RaiseMax; public ConfigEntry<bool> Raise; public ConfigEntry<bool> RaiseInShip; public ConfigEntry<bool> RaisedCanRaise; public ConfigEntry<bool> RaiseAnyBody; public ConfigEntry<bool> KeepOnTerminal; public ConfigEntry<float> RaiseChance; public ConfigEntry<float> RaiseDistance; public ConfigEntry<float> RaiseDelay; public ConfigEntry<float> RiskBonus; public ConfigEntry<float> PlainChance; public ConfigEntry<float> OtherDeaths; public ConfigEntry<RnDGear> RnDGear; public ConfigEntry<bool> MatchMonsters; public ConfigEntry<LookFrom> MirageLook; public ConfigEntry<bool> MirageRaise; public ConfigEntry<bool> MirageVoices; public ConfigEntry<bool> MirageLimit; public ConfigEntry<bool> MirageLetters; public ConfigEntry<From> RemnantsBodies; public ConfigEntry<From> RemnantsGear; public ConfigEntry<bool> RemnantsLetters; public ConfigEntry<bool> RemnantsFamily; public ConfigEntry<bool> RemnantsRaise; public ConfigEntry<string> DeathsByMonster; public ConfigEntry<bool> Letters; public ConfigEntry<bool> Lore; public ConfigEntry<bool> LoreCanon; public ConfigEntry<bool> LoreGap; public ConfigEntry<bool> LoreTheory; public ConfigEntry<string> NotDangerous; public ConfigEntry<bool> LockedSuits; public ConfigEntry<bool> Variants; public ConfigEntry<bool> SavedSuits; public ConfigEntry<string> BannedSuits; public ConfigEntry<string> List; public ConfigEntry<string> Extra; public ConfigEntry<string> Prices; public ConfigEntry<string> MissingPrices; public ConfigEntry<ListMode> Mode; public readonly ConfigFile Config; public Cfg(ConfigFile c) { Config = c; MaxBodies = I("Bodies", "MaxBodies", 16, 0, 64, "The most bodies on one moon, in the largest interiors. 0 = none."); SmallInterior = I("Bodies", "SmallInterior", 1500, 0, 100000, "Interiors with this much floor (m2) or less get about 0 bodies. The log shows each interior's floor when you land. Measured in v81: Experimentation 2700, Vow 4900, March 5400, Rend 5600, Titan 6800-8200."); LargeInterior = I("Bodies", "LargeInterior", 8000, 1, 100000, "Interiors with this much floor (m2) or more get about MaxBodies."); SizeCurve = F("Bodies", "SizeCurve", 1f, 0.1f, 5f, "How the number grows between those sizes. 1 = evenly, above 1 = fewer in medium interiors, below 1 = more."); Spread = F("Bodies", "Spread", 0.25f, 0f, 1f, "How random the number is, as a share of MaxBodies. 0 = always the same for the same size."); RiskBonus = F("Bodies", "RiskBonus", 0.1f, 0f, 2f, "How many more bodies each risk level above D adds: 0.1 = 10% more each (C 10%, B 20%, up to S++ 60%), never above MaxBodies. 0 = risk doesn't matter. Each moon also has its own settings under Moons."); Spacing = F("Bodies", "Spacing", 4f, 0f, 50f, "Bodies are at least this far apart (m)."); MinFromMain = F("Bodies", "MinFromMainEntrance", 10f, 0f, 500f, "Bodies are at least this far from the main entrance (m, walking)."); MinFromFire = F("Bodies", "MinFromFireExits", 5f, 0f, 500f, "Bodies are at least this far from any fire exit (m, walking)."); NearMain = F("Bodies", "WeightNearMainEntrance", 1f, 0f, 100f, "How likely spots nearest the main entrance are, compared with WeightFarFromMainEntrance. Spots in between are in between."); FarMain = F("Bodies", "WeightFarFromMainEntrance", 1f, 0f, 100f, "How likely spots furthest from the main entrance are."); NearFire = F("Bodies", "WeightNearFireExits", 1f, 0f, 100f, "How likely spots nearest a fire exit are (multiplied with the main entrance's weight)."); FarFire = F("Bodies", "WeightFarFromFireExits", 1f, 0f, 100f, "How likely spots furthest from a fire exit are."); MinValue = I("Bodies", "MinValue", 5, 1, 10000, "The least a body is worth."); MaxValue = I("Bodies", "MaxValue", 20, 1, 10000, "The most a body is worth."); LockedSuits = c.Bind<bool>("Looks", "LockedSuits", true, "Bodies can wear suits you haven't unlocked."); BannedSuits = c.Bind<string>("Looks", "BannedSuits", "", "Suits bodies never wear, by name, separated by semicolons."); TailorChance = F("Looks", "SuitTailorChance", 0.4f, 0f, 1f, "With Suit Tailor (0.2.1 or later), the chance a body wears one of its suits instead of one from the game or a suit mod."); SavedSuits = c.Bind<bool>("Looks", "SavedSuits", true, "Suit Tailor suits can include the host's saved ones, not just presets. Players' games are sent the suit's name too."); CosmeticsChance = F("Looks", "CosmeticsChance", 0.6f, 0f, 1f, "With MoreCompany, the chance a body wears cosmetics. MoreCompany's own setting for cosmetics on dead bodies still counts."); MaxCosmetics = I("Looks", "MaxCosmetics", 3, 1, 7, "The most cosmetics on one body."); Variants = c.Bind<bool>("Looks", "CausesOfDeath", true, "Bodies can look burnt, electrocuted, scratched and so on (the game's own kinds of body). If false, they're always whole."); PlainChance = F("Looks", "PlainChance", 0.5f, 0f, 1f, "The chance a body is the plain kind, with nothing to show how they died. The rest are the other kinds."); MatchMonsters = c.Bind<bool>("Looks", "MatchMonsters", true, "The other kinds match the moon's monsters: the more often a monster spawns there, the more bodies it leaves. If false, every kind is equally likely everywhere."); OtherDeaths = F("Looks", "OtherDeaths", 0.02f, 0f, 1f, "With MatchMonsters, the weight every kind has even if nothing on the moon causes it. Each monster's weight is its share of the moon's spawns (0 to 1). 0 = only kinds that moon's monsters cause."); DeathsByMonster = c.Bind<string>("Looks", "DeathsByMonster", "Girl=HeadBurst; Spring=Spring; Red Locust Bees=Electrocuted; RadMech=Burnt; Clay Surgeon=SlicedInHalf; Bush Wolf=HeadGone; Feiopar=Scratched; Cadaver Bloom=Flowers; Cadaver Growths=Flowers", "Which kind of body each monster leaves, as Monster=Kind, separated by semicolons. Monsters use the game's own names, and modded ones can be added. Kinds: HeadBurst, Spring, Electrocuted, Burnt, SlicedInHalf, HeadGone, Scratched, Flowers. Other monsters leave plain bodies."); FliesChance = F("Looks", "FliesChance", 0.5f, 0f, 1f, "The chance that a body has attracted flies. The rest are fresh."); HeavyFliesChance = F("Looks", "HeavyFliesChance", 0.35f, 0f, 1f, "The chance that a body with flies has a lot of them."); One = F("Gear", "ChanceOfOne", 0.25f, 0f, 1f, "The chance a body has 1 piece of gear, at a middling distance. Whatever is left over is the chance of none."); Two = F("Gear", "ChanceOfTwo", 0.125f, 0f, 1f, "The chance of 2."); Three = F("Gear", "C