using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.Json; using CounterfeitMod; using FybCommon; using HarmonyLib; using HoldTheFort; using Il2CppFishNet; using Il2CppInterop.Runtime; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppScheduleOne; using Il2CppScheduleOne.AvatarFramework; using Il2CppScheduleOne.AvatarFramework.Animation; using Il2CppScheduleOne.Building; using Il2CppScheduleOne.Core.Items.Framework; using Il2CppScheduleOne.DevUtilities; using Il2CppScheduleOne.Equipping; using Il2CppScheduleOne.Instancing; using Il2CppScheduleOne.ItemFramework; using Il2CppScheduleOne.Law; using Il2CppScheduleOne.Map; using Il2CppScheduleOne.NPCs; using Il2CppScheduleOne.Networking; using Il2CppScheduleOne.Persistence; using Il2CppScheduleOne.PlayerScripts; using Il2CppScheduleOne.Property; using Il2CppScheduleOne.Storage; using Il2CppScheduleOne.Tiles; using Il2CppScheduleOne.UI; using Il2CppScheduleOne.UI.Shop; using Il2CppScheduleOne.Weather; using Il2CppSteamworks; using Il2CppSystem; using Il2CppSystem.Collections.Generic; using Il2CppSystem.Reflection; using Il2CppTMPro; using MelonLoader; using MelonLoader.Preferences; using MelonLoader.Utils; using Microsoft.CodeAnalysis; using S1API.GameTime; using S1API.Items; using S1API.Items.Storable; using S1API.Lifecycle; using S1API.Money; using S1API.Rendering; using S1API.Shops; using UnityEngine; using UnityEngine.AI; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; using UnityEngine.UI; using WoodKit; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(PressCore), "Counterfeit Press", "1.0.3", "Wood Studios", null)] [assembly: MelonGame("TVGS", "Schedule I")] [assembly: MelonOptionalDependencies(new string[] { "HoldTheFort" })] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("WoodStudios.CounterfeitPress")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("WoodStudios.CounterfeitPress")] [assembly: AssemblyTitle("WoodStudios.CounterfeitPress")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.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 WoodKit { internal static class GltfLoader { public static GameObject LoadEmbedded(string fileName, Transform parent) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Kit.ModelResourcePrefix + fileName); if (stream == null) { throw new FileNotFoundException("Embedded model missing: " + fileName); } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); return Load(memoryStream.ToArray(), Path.GetFileNameWithoutExtension(fileName), parent); } public static GameObject Load(byte[] glb, string name, Transform parent) { //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown if (glb.Length < 20 || BitConverter.ToUInt32(glb, 0) != 1179937895) { throw new InvalidDataException("Not a GLB file"); } int num = (int)BitConverter.ToUInt32(glb, 12); string json = Encoding.UTF8.GetString(glb, 20, num); int bin = 20 + num + 8; using JsonDocument jsonDocument = JsonDocument.Parse(json); JsonElement rootElement = jsonDocument.RootElement; Material[] materials = BuildMaterials(rootElement); Dictionary meshCache = new Dictionary(); GameObject val = new GameObject(name); val.transform.SetParent(parent, false); JsonElement property = rootElement.GetProperty("nodes"); HashSet hashSet = new HashSet(); for (int i = 0; i < property.GetArrayLength(); i++) { if (!property[i].TryGetProperty("children", out var value)) { continue; } foreach (JsonElement item in value.EnumerateArray()) { hashSet.Add(item.GetInt32()); } } for (int j = 0; j < property.GetArrayLength(); j++) { if (!hashSet.Contains(j)) { BuildNode(rootElement, property, j, val.transform, glb, bin, materials, meshCache); } } return val; } private static void BuildNode(JsonElement root, JsonElement nodes, int index, Transform parent, byte[] glb, int bin, Material[] materials, Dictionary meshCache) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) JsonElement jsonElement = nodes[index]; JsonElement value; GameObject val = new GameObject(jsonElement.TryGetProperty("name", out value) ? value.GetString() : ("node" + index)); Transform transform = val.transform; transform.SetParent(parent, false); if (jsonElement.TryGetProperty("translation", out var value2)) { transform.localPosition = new Vector3(value2[0].GetSingle(), value2[1].GetSingle(), 0f - value2[2].GetSingle()); } if (jsonElement.TryGetProperty("rotation", out var value3)) { transform.localRotation = new Quaternion(0f - value3[0].GetSingle(), 0f - value3[1].GetSingle(), value3[2].GetSingle(), value3[3].GetSingle()); } if (jsonElement.TryGetProperty("scale", out var value4)) { transform.localScale = new Vector3(value4[0].GetSingle(), value4[1].GetSingle(), value4[2].GetSingle()); } if (jsonElement.TryGetProperty("mesh", out var value5)) { int @int = value5.GetInt32(); if (!meshCache.TryGetValue(@int, out var value6)) { value6 = (meshCache[@int] = BuildMesh(root, @int, glb, bin, materials)); } val.AddComponent().sharedMesh = value6.Item1; MeshRenderer val2 = val.AddComponent(); Il2CppReferenceArray val3 = new Il2CppReferenceArray((long)value6.Item2.Length); for (int i = 0; i < value6.Item2.Length; i++) { ((Il2CppArrayBase)(object)val3)[i] = value6.Item2[i]; } ((Renderer)val2).sharedMaterials = val3; } if (!jsonElement.TryGetProperty("children", out var value7)) { return; } foreach (JsonElement item in value7.EnumerateArray()) { BuildNode(root, nodes, item.GetInt32(), transform, glb, bin, materials, meshCache); } } private static (Mesh, Material[]) BuildMesh(JsonElement root, int meshIndex, byte[] glb, int bin, Material[] materials) { //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_02ed: Expected O, but got Unknown //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) JsonElement property = root.GetProperty("meshes")[meshIndex].GetProperty("primitives"); List list = new List(); List list2 = new List(); List list3 = new List(); List list4 = new List(); List list5 = new List(); foreach (JsonElement item in property.EnumerateArray()) { JsonElement property2 = item.GetProperty("attributes"); int count = list.Count; int count2; float[] array = ReadFloats(root, property2.GetProperty("POSITION").GetInt32(), glb, bin, out count2); for (int i = 0; i < count2; i++) { list.Add(new Vector3(array[i * 3], array[i * 3 + 1], 0f - array[i * 3 + 2])); } int count3; if (property2.TryGetProperty("NORMAL", out var value)) { float[] array2 = ReadFloats(root, value.GetInt32(), glb, bin, out count3); for (int j = 0; j < count2; j++) { list2.Add(new Vector3(array2[j * 3], array2[j * 3 + 1], 0f - array2[j * 3 + 2])); } } else { for (int k = 0; k < count2; k++) { list2.Add(Vector3.up); } } if (property2.TryGetProperty("TEXCOORD_0", out var value2)) { float[] array3 = ReadFloats(root, value2.GetInt32(), glb, bin, out count3); for (int l = 0; l < count2; l++) { list3.Add(new Vector2(array3[l * 2], 1f - array3[l * 2 + 1])); } } else { for (int m = 0; m < count2; m++) { list3.Add(Vector2.zero); } } int[] array4; if (item.TryGetProperty("indices", out var value3)) { array4 = ReadIndices(root, value3.GetInt32(), glb, bin); } else { array4 = new int[count2]; for (int n = 0; n < count2; n++) { array4[n] = n; } } for (int num = 0; num + 2 < array4.Length; num += 3) { int num2 = array4[num] + count; int num3 = array4[num + 1] + count; int num4 = array4[num + 2] + count; array4[num] = num2; array4[num + 1] = num4; array4[num + 2] = num3; } list4.Add(array4); JsonElement value4; int num5 = (item.TryGetProperty("material", out value4) ? value4.GetInt32() : (-1)); list5.Add((num5 >= 0 && num5 < materials.Length) ? materials[num5] : Models.Mat("gltf_default", Color.gray)); } Mesh val = new Mesh { name = "HTF_" + meshIndex }; if (list.Count > 65000) { val.indexFormat = (IndexFormat)1; } val.vertices = new Il2CppStructArray(list.ToArray()); val.normals = new Il2CppStructArray(list2.ToArray()); val.uv = new Il2CppStructArray(list3.ToArray()); val.subMeshCount = list4.Count; for (int num6 = 0; num6 < list4.Count; num6++) { val.SetTriangles(new Il2CppStructArray(list4[num6]), num6); } val.RecalculateBounds(); ((Object)val).hideFlags = (HideFlags)32; return (val, list5.ToArray()); } private static Material[] BuildMaterials(JsonElement root) { //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_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) if (!root.TryGetProperty("materials", out var value)) { return Array.Empty(); } Material[] array = (Material[])(object)new Material[value.GetArrayLength()]; for (int i = 0; i < array.Length; i++) { JsonElement jsonElement = value[i]; JsonElement value2; string text = (jsonElement.TryGetProperty("name", out value2) ? value2.GetString() : ("mat" + i)); Color white = Color.white; float metallic = 1f; float num = 1f; if (jsonElement.TryGetProperty("pbrMetallicRoughness", out var value3)) { if (value3.TryGetProperty("baseColorFactor", out var value4)) { ((Color)(ref white))..ctor(value4[0].GetSingle(), value4[1].GetSingle(), value4[2].GetSingle(), value4[3].GetSingle()); } if (value3.TryGetProperty("metallicFactor", out var value5)) { metallic = value5.GetSingle(); } if (value3.TryGetProperty("roughnessFactor", out var value6)) { num = value6.GetSingle(); } } Color? emission = null; if (jsonElement.TryGetProperty("emissiveFactor", out var value7)) { float num2 = 1f; if (jsonElement.TryGetProperty("extensions", out var value8) && value8.TryGetProperty("KHR_materials_emissive_strength", out var value9) && value9.TryGetProperty("emissiveStrength", out var value10)) { num2 = value10.GetSingle(); } Color value11 = new Color(value7[0].GetSingle(), value7[1].GetSingle(), value7[2].GetSingle()) * Mathf.Min(num2, 8f) * 0.5f; if (((Color)(ref value11)).maxColorComponent > 0.001f) { emission = value11; } } array[i] = Models.Mat("glb_" + text, white, metallic, 1f - num, emission); } return array; } private static float[] ReadFloats(JsonElement root, int accessor, byte[] glb, int bin, out int count) { JsonElement jsonElement = root.GetProperty("accessors")[accessor]; count = jsonElement.GetProperty("count").GetInt32(); int num = Components(jsonElement.GetProperty("type").GetString()); JsonElement jsonElement2 = root.GetProperty("bufferViews")[jsonElement.GetProperty("bufferView").GetInt32()]; JsonElement value; JsonElement value2; int num2 = bin + (jsonElement2.TryGetProperty("byteOffset", out value) ? value.GetInt32() : 0) + (jsonElement.TryGetProperty("byteOffset", out value2) ? value2.GetInt32() : 0); JsonElement value3; int num3 = (jsonElement2.TryGetProperty("byteStride", out value3) ? value3.GetInt32() : (num * 4)); float[] array = new float[count * num]; for (int i = 0; i < count; i++) { for (int j = 0; j < num; j++) { array[i * num + j] = BitConverter.ToSingle(glb, num2 + i * num3 + j * 4); } } return array; } private static int[] ReadIndices(JsonElement root, int accessor, byte[] glb, int bin) { JsonElement jsonElement = root.GetProperty("accessors")[accessor]; int @int = jsonElement.GetProperty("count").GetInt32(); int int2 = jsonElement.GetProperty("componentType").GetInt32(); JsonElement value; JsonElement value2; int num = bin + (root.GetProperty("bufferViews")[jsonElement.GetProperty("bufferView").GetInt32()].TryGetProperty("byteOffset", out value) ? value.GetInt32() : 0) + (jsonElement.TryGetProperty("byteOffset", out value2) ? value2.GetInt32() : 0); int[] array = new int[@int]; for (int i = 0; i < @int; i++) { int[] array2 = array; int num2 = i; array2[num2] = int2 switch { 5121 => glb[num + i], 5123 => BitConverter.ToUInt16(glb, num + i * 2), _ => (int)BitConverter.ToUInt32(glb, num + i * 4), }; } return array; } private static int Components(string type) { return type switch { "SCALAR" => 1, "VEC2" => 2, "VEC3" => 3, "VEC4" => 4, _ => 1, }; } } internal static class Host { public static bool Ok; private static bool _linkedTold; private static string _linkedNote; private static Action _onLoaded; private static Action _onUnloaded; private static string _folder; public static void Init(MelonMod mod, string folder, string title, string prefix, string linkedNote = null, Action onLoaded = null, Action onUnloaded = null) { _folder = folder; Kit.Log = ((MelonBase)mod).LoggerInstance; Kit.Prefix = prefix; Kit.Title = title; Kit.ModelResourcePrefix = ((object)mod).GetType().Namespace + ".models."; FortifyApi.Init(mod, folder, title); _linkedNote = linkedNote; _onLoaded = onLoaded; _onUnloaded = onUnloaded; FortifyApi.AfterLoad += Loaded; FortifyApi.BeforeSave += Placement.Save; FortifyApi.Unloaded += Unloaded; } private static void Loaded() { Registration.ResetForNewScene(); Placement.Load(); try { _onLoaded?.Invoke(); } catch (Exception ex) { Instance log = Kit.Log; if (log != null) { log.Warning("Loading: " + ex.Message); } } MelonCoroutines.Start(Registration.RenderIcons()); } private static void Unloaded() { try { _onUnloaded?.Invoke(); } catch { } Placement.Reset(); } public static bool Update() { //IL_00aa: Unknown result type (might be due to invalid IL or missing references) if (!Ok) { return false; } try { Registration.TryRegister(); } catch { } if (!FortifyApi.InGame) { return false; } FortifyApi.Frame(); if (FortifyApi.Linked && _linkedNote != null) { if (!_linkedTold) { _linkedTold = true; Instance log = Kit.Log; if (log != null) { log.Msg(_linkedNote); } TellLinkedOnce(); } } else { Registration.TryAddToShops(); } try { Placement.Update(); } catch (Exception ex) { if (Time.frameCount % 600 == 0) { Instance log2 = Kit.Log; if (log2 != null) { log2.Warning("Placement: " + ex.Message); } } } if (FortifyApi.DevKeys && FortifyApi.KeyHeld((KeyCode)308) && FortifyApi.KeyDown(Kit.DevGiveKey)) { Placement.DevGive(); } return true; } private static void TellLinkedOnce() { try { MelonPreferences_Category val = MelonPreferences.GetCategory(_folder) ?? MelonPreferences.CreateCategory(_folder, Kit.Title); MelonPreferences_Entry val2 = val.GetEntry("LinkedNoticeShown") ?? val.CreateEntry("LinkedNoticeShown", false, "Linked notice shown", "Set once the in-game note about Fortify Your Base has been shown.", true, false, (ValueValidator)null, (string)null); if (!val2.Value) { val2.Value = true; FortifyApi.Notify(Kit.Title, "Fortify Your Base already sells these at the hardware stores."); MelonPreferences.Save(); } } catch { } } public static void DrawHint() { if (!Ok || !FortifyApi.InGame) { return; } try { FortifyApi.Hint(Placement.Hint); PickupHold.Draw(); } catch { } } } internal static class InputUtil { private static bool _legacyBroken; public static bool Suppressed; public static KeyCode Parse(string name, KeyCode fallback) { //IL_001a: 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) if (!string.IsNullOrWhiteSpace(name) && Enum.TryParse(name.Trim(), ignoreCase: true, out KeyCode result)) { return result; } return fallback; } public static bool Down(KeyCode key) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!Suppressed) { return RawDown(key); } return false; } public static bool Held(KeyCode key) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!Suppressed) { return RawHeld(key); } return false; } public static bool RawDown(KeyCode key) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!_legacyBroken) { try { return Input.GetKeyDown(key); } catch { _legacyBroken = true; } } KeyControl val = Control(key); if (val != null) { return ((ButtonControl)val).wasPressedThisFrame; } return false; } public static bool RawHeld(KeyCode key) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!_legacyBroken) { try { return Input.GetKey(key); } catch { _legacyBroken = true; } } KeyControl val = Control(key); if (val != null) { return ((ButtonControl)val).isPressed; } return false; } public static bool MouseDown(int button) { if (!_legacyBroken) { try { return Input.GetMouseButtonDown(button); } catch { _legacyBroken = true; } } try { Mouse current = Mouse.current; if (current == null) { return false; } return (button == 0) ? current.leftButton.wasPressedThisFrame : current.rightButton.wasPressedThisFrame; } catch { return false; } } public static bool MouseHeld(int button) { if (!_legacyBroken) { try { return Input.GetMouseButton(button); } catch { _legacyBroken = true; } } try { Mouse current = Mouse.current; if (current == null) { return false; } return (button == 0) ? current.leftButton.isPressed : current.rightButton.isPressed; } catch { return false; } } private unsafe static KeyControl Control(KeyCode key) { //IL_0098: Unknown result type (might be due to invalid IL or missing references) try { Keyboard current = Keyboard.current; if (current == null) { return null; } string text = ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString(); if (text.StartsWith("Alpha")) { text = "Digit" + text.Substring(5); } else if (text == "Return") { text = "Enter"; } else if (text == "KeypadEnter") { text = "NumpadEnter"; } else if (text.StartsWith("Keypad")) { text = "Numpad" + text.Substring(6); } if (!Enum.TryParse(text, ignoreCase: true, out Key result)) { return null; } return current[result]; } catch { return null; } } } internal enum PlaceKind { Ground, Wall } internal sealed class ItemSpec { public string Id; public string Name; public string Description; public float Price; public PlaceKind Kind; public int StackLimit = 10; public float RotateStep = 90f; public Color IconColor = Color.gray; public Func BuildModel; public Func IconModel; public string[] Stores; public bool NotSold; public float FitLift; public Bounds? FitBounds; public GameObject Template; } internal static class Kit { public delegate bool UseHandler(Placement.Placed p, RaycastHit hit, out string hint); public delegate bool Placer(ItemSpec spec, Camera cam, Player player, out string hint); public static string Prefix = "wk_"; public static string ModelResourcePrefix = "WoodKit.models."; public static string Title = "Wood Studios"; public static string SaveKey = "Items"; public static Instance Log; public static string[] Stores = new string[2] { "Dan's Hardware", "Handy Hank's Hardware" }; public static Func PriceMultiplier = () => 1f; public static KeyCode RotateKey = (KeyCode)114; public static KeyCode DevGiveKey = (KeyCode)117; public static readonly Dictionary Use = new Dictionary(StringComparer.OrdinalIgnoreCase); public static readonly Dictionary CustomPlace = new Dictionary(StringComparer.OrdinalIgnoreCase); public static Func Busy = () => false; public static Func CanPickUp; public static event Action Created; public static event Action Removed; internal static void RaiseCreated(Placement.Placed p) { try { Kit.Created?.Invoke(p); } catch (Exception ex) { Instance log = Log; if (log != null) { log.Warning(p?.Spec?.Name + ": " + ex.Message); } } } internal static void RaiseRemoved(Placement.Placed p) { try { Kit.Removed?.Invoke(p); } catch (Exception ex) { Instance log = Log; if (log != null) { log.Warning(p?.Spec?.Name + ": " + ex.Message); } } } } internal static class Core { internal const string PickupLabel = "Hold Right Click"; public static Instance Log => Kit.Log; public static KeyCode ViewKey => FortifyApi.UseKey; public static KeyCode RotateKey => Kit.RotateKey; } internal static class Catalog { public static readonly List Items = new List(); private static readonly Dictionary ById = new Dictionary(StringComparer.OrdinalIgnoreCase); public static void Add(ItemSpec s) { Items.Add(s); ById[s.Id] = s; } public static ItemSpec Get(string id) { if (string.IsNullOrEmpty(id) || !ById.TryGetValue(id, out var value)) { return null; } return value; } public static void BuildTemplates() { foreach (ItemSpec item in Items) { if ((Object)(object)item.Template != (Object)null || item.BuildModel == null) { continue; } try { item.Template = item.BuildModel(); if ((Object)(object)item.Template != (Object)null && (Object)(object)item.Template.transform.parent == (Object)null) { item.Template.transform.SetParent(Models.Root, false); } } catch (Exception ex) { Instance log = Kit.Log; if (log != null) { log.Error("Couldn't build the " + item.Name + " model: " + ex.Message); } } } } } internal static class Registration { private static readonly Dictionary Definitions = new Dictionary(StringComparer.OrdinalIgnoreCase); private static bool _registered; private static bool _shopsDone; private static bool _iconsRendered; private static int _shopAttempts; private static float _nextAttempt; private static float _nextShopAttempt; private static StoredItem _storedFallback; public static bool Registered => _registered; public static bool TryRegister() { //IL_00e5: Unknown result type (might be due to invalid IL or missing references) if (_registered) { return true; } if (Time.unscaledTime < _nextAttempt) { return false; } _nextAttempt = Time.unscaledTime + 1f; try { if (!Singleton.InstanceExists || !Registry.ItemExists("grandfatherclock")) { return false; } } catch { return false; } Catalog.BuildTemplates(); int num = 0; foreach (ItemSpec item in Catalog.Items) { try { Equippable val = ItemCreator.CreateEquippableBuilder().CreateBasicEquippable(Kit.Prefix + "Equippable_" + item.Id).WithInteraction(true, true) .Build(); StorableItemDefinition val2 = ((StorableItemDefinitionBuilderBase)(object)((StorableItemDefinitionBuilderBase)(object)((StorableItemDefinitionBuilderBase)(object)((StorableItemDefinitionBuilderBase)(object)((StorableItemDefinitionBuilderBase)(object)ItemCreator.CreateBuilder()).WithBasicInfo(item.Id, item.Name, item.Description, (ItemCategory)4)).WithPricing(item.Price * Mathf.Max(0f, Kit.PriceMultiplier()), 0.5f)).WithStackLimit(item.StackLimit)).WithIcon(Models.FallbackIcon(item.IconColor))).WithEquippable(val).Build(); if ((ItemDefinition)(object)val2 != (ItemDefinition)null) { Definitions[item.Id] = (ItemDefinition)(object)val2; num++; } } catch (Exception ex) { Instance log = Kit.Log; if (log != null) { log.Error("Couldn't create '" + item.Name + "': " + ex.Message); } } } FixShopSettings(); _registered = true; Instance log2 = Kit.Log; if (log2 != null) { log2.Msg($"Registered {num} item(s)."); } return true; } private static void FixShopSettings() { List val = null; try { StorableItemDefinition item = Registry.GetItem("largestoragerack"); if ((Object)(object)item != (Object)null && item.ShopCategories != null && item.ShopCategories.Count > 0) { val = item.ShopCategories; } } catch { } foreach (string key in Definitions.Keys) { try { StorableItemDefinition item2 = Registry.GetItem(key); if ((Object)(object)item2 == (Object)null) { continue; } item2.RequiresLevelToPurchase = false; if (val != null) { item2.ShopCategories = val; } if (BadStored(item2.StoredItem)) { StoredItem val2 = StoredFallback(); if ((Object)(object)val2 != (Object)null) { item2.StoredItem = val2; } } } catch { } } } private static bool BadStored(StoredItem s) { if ((Object)(object)s == (Object)null) { return true; } try { List coordinateFootprintTilePairs = s._coordinateFootprintTilePairs; return coordinateFootprintTilePairs == null || coordinateFootprintTilePairs.Count == 0; } catch { return true; } } internal static StoredItem StoredFallback() { if ((Object)(object)_storedFallback != (Object)null) { return _storedFallback; } string[] array = new string[5] { "paracetamol", "flumedicine", "cuke", "energydrink", "baggie" }; foreach (string text in array) { try { StorableItemDefinition item = Registry.GetItem(text); if ((Object)(object)item != (Object)null && !BadStored(item.StoredItem)) { _storedFallback = item.StoredItem; break; } } catch { } } if ((Object)(object)_storedFallback == (Object)null) { Instance log = Kit.Log; if (log != null) { log.Warning("No stored model found for storage racks; our items may not show on racks."); } } return _storedFallback; } public static void ResetForNewScene() { _shopsDone = false; _shopAttempts = 0; } public static void TryAddToShops() { if (_shopsDone || !_registered || Definitions.Count == 0 || Time.unscaledTime < _nextShopAttempt) { return; } _nextShopAttempt = Time.unscaledTime + 2f; _shopAttempts++; HashSet hashSet = new HashSet(StringComparer.OrdinalIgnoreCase); foreach (ItemSpec item2 in Catalog.Items) { if (!item2.NotSold) { string[] array = item2.Stores ?? Kit.Stores; foreach (string item in array) { hashSet.Add(item); } } } if (hashSet.Count == 0) { _shopsDone = true; return; } int num = 0; foreach (string item3 in hashSet) { Shop val = null; try { val = ShopManager.GetShopByName(item3); } catch { } if (val == null) { continue; } num++; foreach (ItemSpec item4 in Catalog.Items) { if (item4.NotSold || Array.IndexOf(item4.Stores ?? Kit.Stores, item3) < 0 || !Definitions.TryGetValue(item4.Id, out var value)) { continue; } try { if (!val.HasItem(item4.Id)) { val.AddItem(value, (float?)null); } } catch (Exception ex) { Instance log = Kit.Log; if (log != null) { log.Warning($"Couldn't add {item4.Name} to {item3}: {ex.Message}"); } } } } if (num == hashSet.Count || (num > 0 && _shopAttempts > 10)) { _shopsDone = true; Instance log2 = Kit.Log; if (log2 != null) { log2.Msg("For sale at " + string.Join(" and ", hashSet) + "."); } } else if (_shopAttempts > 30) { _shopsDone = true; Instance log3 = Kit.Log; if (log3 != null) { log3.Warning("Couldn't find the shops, so nothing is for sale this session."); } } } public static IEnumerator RenderIcons() { if (_iconsRendered) { yield break; } float wait = Time.unscaledTime + 6f; while (Time.unscaledTime < wait) { yield return null; } int done = 0; List failed = new List(); foreach (ItemSpec item in Catalog.Items) { if (RenderIcon(item)) { done++; } else { failed.Add(item); } yield return null; } for (int attempt = 0; attempt < 2; attempt++) { if (failed.Count <= 0) { break; } wait = Time.unscaledTime + 4f; while (Time.unscaledTime < wait) { yield return null; } for (int i = failed.Count - 1; i >= 0; i--) { if (RenderIcon(failed[i])) { done++; failed.RemoveAt(i); } yield return null; } } _iconsRendered = done > 0; } private static bool RenderIcon(ItemSpec spec) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) GameObject val = null; try { val = ((spec.IconModel != null) ? spec.IconModel() : (((Object)(object)spec.Template != (Object)null) ? Object.Instantiate(spec.Template) : null)); if ((Object)(object)val == (Object)null) { return true; } val.transform.SetParent((Transform)null, false); val.transform.position = new Vector3(0f, -500f, 0f); val.SetActive(true); Sprite val2 = IconFactory.GenerateIconSprite(val.transform, 256, false, true, 0.8f); if ((Object)(object)val2 == (Object)null) { return false; } ((Object)val2).hideFlags = (HideFlags)32; if ((Object)(object)val2.texture != (Object)null) { ((Object)val2.texture).hideFlags = (HideFlags)32; } ItemDefinition item = Registry.GetItem(spec.Id); if ((Object)(object)item != (Object)null) { ((BaseItemDefinition)item).Icon = val2; } try { ShopManager.RefreshItemIcon(spec.Id); } catch { } return true; } catch (Exception ex) { Instance log = Kit.Log; if (log != null) { log.Warning("Icon for " + spec.Name + " couldn't be rendered: " + ex.Message); } return true; } finally { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } } } } internal static class Models { private static GameObject _root; private static readonly Dictionary Mats = new Dictionary(); private static Shader _litShader; public const float WallHeight = 2.4f; public const float WallThick = 0.25f; public static Transform Root { get { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown if ((Object)(object)_root == (Object)null) { _root = new GameObject(Kit.Prefix + "Templates"); _root.SetActive(false); Object.DontDestroyOnLoad((Object)(object)_root); } return _root.transform; } } internal static Material Concrete => Mat("concrete", new Color(0.58f, 0.58f, 0.56f), 0f, 0.12f); internal static Material Mortar => Mat("mortar", new Color(0.42f, 0.42f, 0.41f), 0f, 0.05f); internal static Material SteelDark => Mat("steel_dark", new Color(0.2f, 0.21f, 0.23f), 0.8f, 0.45f); internal static Material SteelLight => Mat("steel_light", new Color(0.55f, 0.57f, 0.6f), 0.85f, 0.55f); internal static Material Housing => Mat("housing", new Color(0.86f, 0.86f, 0.84f), 0.1f, 0.5f); internal static Material BlackPlastic => Mat("black", new Color(0.05f, 0.05f, 0.06f), 0.2f, 0.6f); internal static Material LedRed => Mat("led_red", new Color(1f, 0.1f, 0.1f), 0f, 0.8f, (Color?)new Color(4f, 0.2f, 0.2f)); internal static Material LensWarm => Mat("lens_warm", new Color(1f, 0.96f, 0.85f), 0f, 0.9f, (Color?)new Color(3f, 2.8f, 2.3f)); internal static Material Chain => Mat("chain", new Color(0.52f, 0.54f, 0.57f), 0.7f, 0.4f); internal static Material Burlap => Mat("burlap", new Color(0.62f, 0.55f, 0.4f), 0f, 0.05f); internal static Material Hazard => Mat("hazard", new Color(0.95f, 0.75f, 0.1f)); public static Sprite FallbackIcon(Color color) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_0081: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false); Color val2 = default(Color); ((Color)(ref val2))..ctor(0f, 0f, 0f, 0f); for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { bool flag = i > 6 && i < 57 && j > 6 && j < 57; bool flag2 = flag && (i < 11 || i > 52 || j < 11 || j > 52); val.SetPixel(i, j, (!flag) ? val2 : (flag2 ? (color * 0.55f) : color)); } } val.Apply(); ((Object)val).hideFlags = (HideFlags)32; Sprite obj = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f)); ((Object)obj).hideFlags = (HideFlags)32; return obj; } private static Shader LitShader() { if ((Object)(object)_litShader != (Object)null) { return _litShader; } _litShader = Shader.Find("Universal Render Pipeline/Lit"); if ((Object)(object)_litShader == (Object)null) { _litShader = Shader.Find("Universal Render Pipeline/Simple Lit"); } if ((Object)(object)_litShader == (Object)null) { foreach (Material item in Resources.FindObjectsOfTypeAll()) { if ((Object)(object)item != (Object)null && (Object)(object)item.shader != (Object)null && ((Object)item.shader).name.Contains("Lit")) { _litShader = item.shader; break; } } } if ((Object)(object)_litShader == (Object)null) { _litShader = Shader.Find("Standard"); } return _litShader; } public static Material Mat(string key, Color color, float metallic = 0f, float smoothness = 0.3f, Color? emission = null) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) if (Mats.TryGetValue(key, out var value) && (Object)(object)value != (Object)null) { return value; } Material val = new Material(LitShader()); ((Object)val).name = Kit.Prefix + key; val.color = color; if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", color); } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", metallic); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", smoothness); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", smoothness); } if (emission.HasValue) { val.EnableKeyword("_EMISSION"); if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", emission.Value); } val.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1; } ((Object)val).hideFlags = (HideFlags)32; Mats[key] = val; return val; } internal static GameObject NewRoot(string name) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown GameObject val = new GameObject(name); val.transform.SetParent(Root, false); return val; } internal static GameObject Prim(PrimitiveType type, Transform parent, Vector3 pos, Vector3 scale, Material mat, Vector3? euler = null, bool keepCollider = false) { //IL_0000: 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_0038: 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_002f: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive(type); val.transform.SetParent(parent, false); val.transform.localPosition = pos; val.transform.localRotation = (euler.HasValue ? Quaternion.Euler(euler.Value) : Quaternion.identity); val.transform.localScale = scale; MeshRenderer component = val.GetComponent(); if ((Object)(object)component != (Object)null) { ((Renderer)component).sharedMaterial = mat; } if (!keepCollider) { Collider component2 = val.GetComponent(); if ((Object)(object)component2 != (Object)null) { Object.DestroyImmediate((Object)(object)component2); } } return val; } internal static GameObject Box(Transform p, Vector3 pos, Vector3 size, Material m, Vector3? euler = null) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) return Prim((PrimitiveType)3, p, pos, size, m, euler); } internal static GameObject Rod(Transform p, Vector3 pos, float radius, float height, Material m, Vector3? euler = null) { //IL_0002: 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) return Prim((PrimitiveType)2, p, pos, new Vector3(radius * 2f, height * 0.5f, radius * 2f), m, euler); } internal static void AddBoxCollider(GameObject go, Vector3 center, Vector3 size) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) BoxCollider obj = go.AddComponent(); obj.center = center; obj.size = size; } internal static void NavBlock(GameObject go, Vector3 center, Vector3 size) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) AddNavObstacle(go, center, size); } private static void AddNavObstacle(GameObject go, Vector3 center, Vector3 size) { //IL_000e: 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) try { NavMeshObstacle obj = go.AddComponent(); obj.shape = (NavMeshObstacleShape)1; obj.center = center; obj.size = size; obj.carving = true; } catch { } } public static void Combine(Transform root) { //IL_00d7: 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_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Expected O, but got Unknown //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) Dictionary> dictionary = new Dictionary>(); Dictionary dictionary2 = new Dictionary(); foreach (MeshFilter componentsInChild in ((Component)root).GetComponentsInChildren(true)) { if ((Object)(object)((Component)componentsInChild).transform == (Object)(object)root || (Object)(object)componentsInChild.sharedMesh == (Object)null) { continue; } if (!componentsInChild.sharedMesh.isReadable) { return; } MeshRenderer component = ((Component)componentsInChild).GetComponent(); if (!((Object)(object)component == (Object)null) && !((Object)(object)((Renderer)component).sharedMaterial == (Object)null)) { int instanceID = ((Object)((Renderer)component).sharedMaterial).GetInstanceID(); if (!dictionary.TryGetValue(instanceID, out var value)) { value = (dictionary[instanceID] = new List()); dictionary2[instanceID] = ((Renderer)component).sharedMaterial; } value.Add(componentsInChild); } } Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix; foreach (KeyValuePair> item in dictionary) { if (item.Value.Count < 2) { continue; } Il2CppStructArray val = new Il2CppStructArray((long)item.Value.Count); for (int i = 0; i < item.Value.Count; i++) { CombineInstance val2 = default(CombineInstance); ((CombineInstance)(ref val2)).mesh = item.Value[i].sharedMesh; ((CombineInstance)(ref val2)).transform = worldToLocalMatrix * ((Component)item.Value[i]).transform.localToWorldMatrix; ((Il2CppArrayBase)(object)val)[i] = val2; } Mesh val3 = new Mesh { name = "HTF_Combined" }; val3.indexFormat = (IndexFormat)1; val3.CombineMeshes(val, true, true); val3.RecalculateBounds(); ((Object)val3).hideFlags = (HideFlags)32; GameObject val4 = new GameObject("Combined_" + ((Object)dictionary2[item.Key]).name); val4.transform.SetParent(root, false); val4.AddComponent().sharedMesh = val3; ((Renderer)val4.AddComponent()).sharedMaterial = dictionary2[item.Key]; foreach (MeshFilter item2 in item.Value) { Object.DestroyImmediate((Object)(object)((Component)item2).gameObject); } } } internal static void MeshColliders(GameObject root, params string[] prefixes) { foreach (MeshFilter componentsInChild in root.GetComponentsInChildren(true)) { foreach (string value in prefixes) { if (((Object)componentsInChild).name.StartsWith(value, StringComparison.Ordinal)) { ((Component)componentsInChild).gameObject.AddComponent().sharedMesh = componentsInChild.sharedMesh; break; } } } } internal static Light AddPointLight(Transform parent, string name, Vector3 local, float range, float intensity, Color color) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); val.transform.localPosition = local; Light obj = val.AddComponent(); obj.type = (LightType)2; obj.range = range; obj.intensity = intensity; obj.color = color; obj.shadows = (LightShadows)0; return obj; } internal static AudioSource AddAudio(Transform parent, string name, Vector3 local, AudioClip clip, bool loop, bool playOnAwake, float volume, float maxDistance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); val.transform.localPosition = local; AudioSource obj = val.AddComponent(); obj.clip = clip; obj.loop = loop; obj.playOnAwake = playOnAwake; obj.spatialBlend = 1f; obj.rolloffMode = (AudioRolloffMode)1; obj.minDistance = 1.5f; obj.maxDistance = maxDistance; obj.volume = volume; return obj; } } internal sealed class PlacedRecord { public string Id { get; set; } public float[] Pos { get; set; } public float[] Rot { get; set; } public bool Active { get; set; } = true; public int Channel { get; set; } public string Text { get; set; } public float[] Extra { get; set; } } internal static class Placement { internal sealed class Placed { public GameObject Go; public ItemSpec Spec; public PlacedRecord Rec; public bool Active = true; public int Channel; public string Text; public string Label; public Camera Feed; public bool OnShip; public Vector3[] Extra; public object State; } private const float PlaceReach = 8f; private const float UseReach = 3.5f; private const float Tile = 0.25f; private static readonly List Items = new List(); internal static int Version; private static GameObject _ghost; private static string _ghostId; private static Bounds _ghostLocalBounds; private static float _ghostLift; private static Bounds? _ghostFit; private static float _blockedLogAt = -100f; internal static string LastBlocker; private static bool _ghostShowingValid; private static int _rotIndex; private static float _turn; private const float FineTurn = 15f; private static string _hint; private static readonly HashSet Ignored = new HashSet(); private static float _ignoredRefreshAt; internal static List All => Items; public static string Hint => _hint; internal static int Count(string id) { int num = 0; foreach (Placed item in Items) { if ((Object)(object)item.Go != (Object)null && string.Equals(item.Spec.Id, id, StringComparison.OrdinalIgnoreCase)) { num++; } } return num; } public static void Load() { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) Reset(); List list = null; try { string data = FortifyApi.GetData(Kit.SaveKey); if (!string.IsNullOrEmpty(data)) { list = JsonSerializer.Deserialize>(data); } } catch (Exception ex) { Instance log = Kit.Log; if (log != null) { log.Warning("Couldn't read the saved items (" + ex.Message + ")."); } } if (list == null) { return; } int num = 0; foreach (PlacedRecord item in list) { ItemSpec itemSpec = Catalog.Get(item?.Id); if (itemSpec != null && !((Object)(object)itemSpec.Template == (Object)null) && item.Pos != null && item.Rot != null) { Placed placed = Create(itemSpec, V(item.Pos), Q(item.Rot), item); Items.Add(placed); num++; Kit.RaiseCreated(placed); } } Version++; if (num > 0) { Instance log2 = Kit.Log; if (log2 != null) { log2.Msg($"Put back {num} placed item(s)."); } } } public static void Save() { try { List list = new List(); foreach (Placed item in Items) { if (!((Object)(object)item.Go == (Object)null)) { UpdateRecord(item); list.Add(item.Rec); } } FortifyApi.SetData(Kit.SaveKey, JsonSerializer.Serialize(list)); } catch (Exception ex) { Instance log = Kit.Log; if (log != null) { log.Warning("Couldn't save the placed items: " + ex.Message); } } } public static void Reset() { foreach (Placed item in Items) { Kit.RaiseRemoved(item); if ((Object)(object)item.Go != (Object)null) { Object.Destroy((Object)(object)item.Go); } } Items.Clear(); Version++; DestroyGhost(); _hint = null; } internal static void UpdateRecord(Placed p) { //IL_0039: 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) Transform transform = p.Go.transform; if (p.Rec == null) { p.Rec = new PlacedRecord { Id = p.Spec.Id }; } p.Rec.Pos = F(transform.position); p.Rec.Rot = F(transform.rotation); p.Rec.Active = p.Active; p.Rec.Channel = p.Channel; p.Rec.Text = p.Text; if (p.Extra != null) { float[] array = new float[p.Extra.Length * 3]; for (int i = 0; i < p.Extra.Length; i++) { array[i * 3] = p.Extra[i].x; array[i * 3 + 1] = p.Extra[i].y; array[i * 3 + 2] = p.Extra[i].z; } p.Rec.Extra = array; } } public static void Update() { _hint = null; Player local = Player.Local; Camera camera = GetCamera(); if ((Object)(object)local == (Object)null || (Object)(object)camera == (Object)null || UiBusy(local)) { HideGhost(); return; } ItemSpec itemSpec = Catalog.Get(EquippedId()); if (itemSpec != null) { if (Kit.CustomPlace.TryGetValue(itemSpec.Id, out var value)) { HideGhost(); value(itemSpec, camera, local, out _hint); } else { UpdatePlacing(itemSpec, camera, local); } } else { HideGhost(); UpdateLooking(camera, local); } } private static void UpdatePlacing(ItemSpec spec, Camera cam, Player player) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_03b7: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02f2: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_0347: Unknown result type (might be due to invalid IL or missing references) //IL_0349: Unknown result type (might be due to invalid IL or missing references) //IL_034b: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Unknown result type (might be due to invalid IL or missing references) //IL_0355: Unknown result type (might be due to invalid IL or missing references) //IL_0359: Unknown result type (might be due to invalid IL or missing references) //IL_035d: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_03fb: Unknown result type (might be due to invalid IL or missing references) //IL_03fd: Unknown result type (might be due to invalid IL or missing references) //IL_0456: Unknown result type (might be due to invalid IL or missing references) //IL_0458: Unknown result type (might be due to invalid IL or missing references) if (_ghostId != spec.Id) { DestroyGhost(); _rotIndex = 0; _turn = 0f; CreateGhost(spec); } bool flag = spec.RotateStep > 0f; bool flag2 = FortifyApi.KeyHeld((KeyCode)308); if (FortifyApi.KeyDown(Kit.RotateKey)) { if (spec.Kind == PlaceKind.Wall) { if (flag) { _rotIndex++; } } else { _turn = Mathf.Repeat(_turn + (flag2 ? 15f : (flag ? spec.RotateStep : 90f)), 360f); } } string text = ((spec.Kind != PlaceKind.Wall) ? (flag2 ? $" [{Kit.RotateKey}] Turn {15f:0}°" : $" [{Kit.RotateKey}] Rotate") : (flag ? $" [{Kit.RotateKey}] Rotate" : "")); if (!Aim(cam, 8f, player, out var best)) { HideGhost(); _hint = ((spec.Kind == PlaceKind.Wall) ? "Aim at a wall" : "Aim at the ground or a floor"); return; } string text2 = null; Vector3 val2; Quaternion val3; if (spec.Kind == PlaceKind.Wall) { Vector3 normal = ((RaycastHit)(ref best)).normal; if (Mathf.Abs(normal.y) > 0.35f) { HideGhost(); _hint = "Aim at a wall, not the floor or ceiling"; return; } Vector3 val = new Vector3(normal.x, 0f, normal.z); Vector3 normalized = ((Vector3)(ref val)).normalized; val2 = ((RaycastHit)(ref best)).point + normalized * 0.004f; val3 = Quaternion.LookRotation(normalized, Vector3.up); if (flag) { val3 *= Quaternion.Euler(0f, 0f, spec.RotateStep * (float)(_rotIndex % Mathf.Max(1, Mathf.RoundToInt(360f / spec.RotateStep)))); } if (!FitsWall(val2, val3, ((RaycastHit)(ref best)).collider, player, flag2)) { text2 = (flag2 ? "Doesn't fit here" : "Doesn't fit here (hold Left Alt to fit it in closer)"); } } else { if (((RaycastHit)(ref best)).normal.y < 0.75f) { HideGhost(); _hint = "Aim at flat ground or a floor"; return; } GridFrame(((RaycastHit)(ref best)).point, out var origin, out var yaw); Quaternion val4 = Quaternion.Euler(0f, yaw, 0f); val2 = ((RaycastHit)(ref best)).point; if (!flag2) { Vector3 val5 = Quaternion.Inverse(val4) * (val2 - origin); val5.x = Mathf.Round(val5.x / 0.25f) * 0.25f; val5.z = Mathf.Round(val5.z / 0.25f) * 0.25f; val2 = origin + val4 * val5; val2.y = GroundY(val2, ((RaycastHit)(ref best)).point.y, player); } int num = Mathf.RoundToInt(Mathf.DeltaAngle(yaw, ((Component)cam).transform.eulerAngles.y) / 90f); val3 = Quaternion.Euler(0f, yaw + 90f * (float)num + _turn, 0f); if (!Fits(val2, val3, ((RaycastHit)(ref best)).collider, player, flag2)) { text2 = (FortifyApi.DevKeys ? ("Doesn't fit here (" + LastBlocker + ")") : (flag2 ? "Doesn't fit here" : "Doesn't fit here (hold Left Alt to fit it in closer)")); } } ShowGhost(val2, val3, text2 == null); if (text2 != null) { _hint = text2; return; } string text3 = (flag2 ? " Free placement" : ((spec.Kind == PlaceKind.Ground) ? " [Hold Left Alt] Place freely" : "")); _hint = "[Click] Place " + spec.Name + text + text3; if (GameInput.GetButtonDown((ButtonCode)0)) { PlaceNow(spec, val2, val3); } } private static float GroundY(Vector3 snapped, float fallback, Player player) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) Il2CppStructArray val = Physics.RaycastAll(new Ray(snapped + Vector3.up * 1.2f, Vector3.down), 3f, -5, (QueryTriggerInteraction)1); float num = float.MaxValue; float result = fallback; for (int i = 0; i < ((Il2CppArrayBase)(object)val).Length; i++) { RaycastHit val2 = ((Il2CppArrayBase)(object)val)[i]; if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null) && !Ignored.Contains(((Object)((RaycastHit)(ref val2)).collider).GetInstanceID()) && !((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(((Component)player).transform) && (!((Object)(object)_ghost != (Object)null) || !((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(_ghost.transform)) && !(((RaycastHit)(ref val2)).normal.y < 0.75f) && ((RaycastHit)(ref val2)).distance < num) { num = ((RaycastHit)(ref val2)).distance; result = ((RaycastHit)(ref val2)).point.y; } } return result; } internal static Placed PlaceNow(ItemSpec spec, Vector3 pos, Quaternion rot, Vector3[] extra = null) { //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_007b: Unknown result type (might be due to invalid IL or missing references) PlayerInventory instance = PlayerSingleton.Instance; HotbarSlot val = (((Object)(object)instance != (Object)null) ? instance.equippedSlot : null); if (val == null || ((ItemSlot)val).ItemInstance == null || !string.Equals(((BaseItemInstance)((ItemSlot)val).ItemInstance).ID, spec.Id, StringComparison.OrdinalIgnoreCase)) { return null; } Placed placed = Create(spec, pos, rot, null, extra); UpdateRecord(placed); Items.Add(placed); Version++; ((ItemSlot)val).ChangeQuantity(-1, false); try { BuildManager instance2 = NetworkSingleton.Instance; if (instance2 != null) { instance2.PlayBuildSound((EBuildSoundType)1, pos); } } catch { } Kit.RaiseCreated(placed); return placed; } internal static Placed PlaceFree(ItemSpec spec, Vector3 pos, Quaternion rot) { //IL_0017: 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) if ((Object)(object)spec?.Template == (Object)null) { return null; } Placed placed = Create(spec, pos, rot, null); UpdateRecord(placed); Items.Add(placed); Version++; Kit.RaiseCreated(placed); return placed; } private static Placed Create(ItemSpec spec, Vector3 pos, Quaternion rot, PlacedRecord rec, Vector3[] extra = null) { //IL_003a: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate(spec.Template); ((Object)val).name = Kit.Prefix + "Placed_" + spec.Id; val.transform.SetParent((Transform)null, false); val.transform.SetPositionAndRotation(pos, rot); val.SetActive(true); Placed placed = new Placed { Go = val, Spec = spec, Rec = rec, Extra = extra }; if (rec != null) { placed.Active = rec.Active; placed.Channel = rec.Channel; placed.Text = rec.Text; if (rec.Extra != null && rec.Extra.Length >= 3) { placed.Extra = (Vector3[])(object)new Vector3[rec.Extra.Length / 3]; for (int i = 0; i < placed.Extra.Length; i++) { placed.Extra[i] = new Vector3(rec.Extra[i * 3], rec.Extra[i * 3 + 1], rec.Extra[i * 3 + 2]); } } } return placed; } internal static void DevGive() { PlayerInventory instance = PlayerSingleton.Instance; if ((Object)(object)instance == (Object)null) { return; } foreach (ItemSpec item2 in Catalog.Items) { try { ItemDefinition item = Registry.GetItem(item2.Id); ItemInstance val = ((item != null) ? item.GetDefaultInstance(2) : null); if (val != null && instance.CanItemFitInInventory(val, 1)) { instance.AddItemToInventory(val); } } catch { } } Instance log = Kit.Log; if (log != null) { log.Msg("Dev: items given."); } } private static void UpdateLooking(Camera cam, Player player) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) if (!Aim(cam, 3.5f, player, out var best)) { return; } Placed placed = FindPlaced(((RaycastHit)(ref best)).collider); if (placed != null) { string hint = null; if (!Kit.Use.TryGetValue(placed.Spec.Id, out var value) || !value(placed, best, out hint)) { hint = "[Hold Right Click] Pick up " + placed.Spec.Name; } _hint = hint; if ((Kit.CanPickUp == null || Kit.CanPickUp(placed)) && PickupHold.Held(placed.Go)) { PickUp(placed); } } } internal static void PickUp(Placed p) { PlayerInventory instance = PlayerSingleton.Instance; ItemDefinition item = Registry.GetItem(p.Spec.Id); if (!((Object)(object)instance == (Object)null) && !((Object)(object)item == (Object)null)) { ItemInstance defaultInstance = item.GetDefaultInstance(1); if (!instance.CanItemFitInInventory(defaultInstance, 1)) { _hint = "Your inventory is full"; return; } instance.AddItemToInventory(defaultInstance); Remove(p); } } internal static void Remove(Placed p) { Kit.RaiseRemoved(p); if ((Object)(object)p.Go != (Object)null) { Object.Destroy((Object)(object)p.Go); } Items.Remove(p); Version++; } internal static Placed FindPlaced(Collider col) { if ((Object)(object)col == (Object)null) { return null; } string value = Kit.Prefix + "Placed_"; Transform val = ((Component)col).transform; while ((Object)(object)val != (Object)null) { if (((Object)val).name.StartsWith(value, StringComparison.Ordinal)) { foreach (Placed item in Items) { if ((Object)(object)item.Go != (Object)null && (Object)(object)item.Go.transform == (Object)(object)val) { return item; } } break; } val = val.parent; } return null; } private static void CreateGhost(ItemSpec spec) { //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) if ((Object)(object)spec.Template == (Object)null) { return; } _ghost = Object.Instantiate(spec.Template); ((Object)_ghost).name = Kit.Prefix + "Ghost"; _ghost.transform.SetParent((Transform)null, false); _ghostLocalBounds = LocalBounds(_ghost); _ghostLift = spec.FitLift; _ghostFit = spec.FitBounds; foreach (Collider componentsInChild in _ghost.GetComponentsInChildren(true)) { Object.DestroyImmediate((Object)(object)componentsInChild); } foreach (NavMeshObstacle componentsInChild2 in _ghost.GetComponentsInChildren(true)) { Object.DestroyImmediate((Object)(object)componentsInChild2); } foreach (Light componentsInChild3 in _ghost.GetComponentsInChildren(true)) { ((Behaviour)componentsInChild3).enabled = false; } foreach (AudioSource componentsInChild4 in _ghost.GetComponentsInChildren(true)) { ((Behaviour)componentsInChild4).enabled = false; } foreach (Camera componentsInChild5 in _ghost.GetComponentsInChildren(true)) { ((Behaviour)componentsInChild5).enabled = false; } SetLayer(_ghost.transform, 2); _ghostId = spec.Id; _ghostShowingValid = false; ApplyGhostMaterial(valid: true); _ghost.SetActive(false); } private static void ShowGhost(Vector3 pos, Quaternion rot, bool valid) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_ghost == (Object)null)) { _ghost.transform.SetPositionAndRotation(pos, rot); if (!_ghost.activeSelf) { _ghost.SetActive(true); } if (valid != _ghostShowingValid) { ApplyGhostMaterial(valid); } } } private static void ApplyGhostMaterial(bool valid) { //IL_0081: 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) _ghostShowingValid = valid; Material val = null; try { BuildManager instance = NetworkSingleton.Instance; if ((Object)(object)instance != (Object)null) { val = (valid ? instance.ghostMaterial_White : instance.ghostMaterial_Red); } } catch { } if ((Object)(object)val == (Object)null) { val = (valid ? Models.Mat("ghost_ok", new Color(0.8f, 0.9f, 1f)) : Models.Mat("ghost_bad", new Color(1f, 0.3f, 0.3f))); } foreach (Renderer componentsInChild in _ghost.GetComponentsInChildren(true)) { int num = Mathf.Max(1, ((Il2CppArrayBase)(object)componentsInChild.sharedMaterials).Length); Il2CppReferenceArray val2 = new Il2CppReferenceArray((long)num); for (int i = 0; i < num; i++) { ((Il2CppArrayBase)(object)val2)[i] = val; } componentsInChild.sharedMaterials = val2; } } internal static void HideGhost() { if ((Object)(object)_ghost != (Object)null && _ghost.activeSelf) { _ghost.SetActive(false); } } private static void DestroyGhost() { if ((Object)(object)_ghost != (Object)null) { Object.Destroy((Object)(object)_ghost); } _ghost = null; _ghostId = null; } internal static bool Aim(Camera cam, float reach, Player player, out RaycastHit best) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) best = default(RaycastHit); Il2CppStructArray val = Physics.RaycastAll(new Ray(((Component)cam).transform.position, ((Component)cam).transform.forward), reach, -5, (QueryTriggerInteraction)1); float num = float.MaxValue; bool result = false; RefreshIgnored(); for (int i = 0; i < ((Il2CppArrayBase)(object)val).Length; i++) { RaycastHit val2 = ((Il2CppArrayBase)(object)val)[i]; if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null) && !((RaycastHit)(ref val2)).collider.isTrigger && !Ignored.Contains(((Object)((RaycastHit)(ref val2)).collider).GetInstanceID())) { Transform transform = ((Component)((RaycastHit)(ref val2)).collider).transform; if (!transform.IsChildOf(((Component)player).transform) && (!((Object)(object)_ghost != (Object)null) || !transform.IsChildOf(_ghost.transform)) && ((RaycastHit)(ref val2)).distance < num) { num = ((RaycastHit)(ref val2)).distance; best = val2; result = true; } } } return result; } internal static void GridFrame(Vector3 point, out Vector3 origin, out float yaw) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) origin = Vector3.zero; yaw = 0f; try { if (!Nearest(Property.OwnedProperties, point, 25f, ref origin, ref yaw)) { Nearest(Property.Properties, point, 6f, ref origin, ref yaw); } } catch { } } internal static Property PropertyAt(Vector3 point, float within = 12f) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) try { List ownedProperties = Property.OwnedProperties; Property result = null; float num = within; int num2 = 0; while (ownedProperties != null && num2 < ownedProperties.Count) { Property val = ownedProperties[num2]; if (!((Object)(object)val == (Object)null)) { float num3 = DistanceToProperty(val, point); if (num3 < num) { num = num3; result = val; } } num2++; } return result; } catch { return null; } } private static bool Nearest(List list, Vector3 point, float within, ref Vector3 origin, ref float yaw) { //IL_0077: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (list == null) { return false; } float num = within; bool result = false; for (int i = 0; i < list.Count; i++) { Property val = list[i]; if ((Object)(object)val == (Object)null) { continue; } float num2 = DistanceToProperty(val, point); if (num2 >= num) { continue; } num = num2; Transform transform = ((Component)val).transform; try { List grids = val.Grids; if (grids != null && grids.Count > 0 && (Object)(object)grids[0] != (Object)null) { transform = ((Component)grids[0]).transform; } } catch { } origin = transform.position; yaw = transform.eulerAngles.y; result = true; } return result; } private static float DistanceToProperty(Property prop, Vector3 p) { //IL_005c: 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_002b: Unknown result type (might be due to invalid IL or missing references) float num = float.MaxValue; try { Il2CppReferenceArray propertyBoundsColliders = prop.propertyBoundsColliders; if (propertyBoundsColliders != null) { for (int i = 0; i < ((Il2CppArrayBase)(object)propertyBoundsColliders).Length; i++) { if ((Object)(object)((Il2CppArrayBase)(object)propertyBoundsColliders)[i] != (Object)null) { num = Mathf.Min(num, DistanceToBox(((Il2CppArrayBase)(object)propertyBoundsColliders)[i], p)); } } } } catch { } if (num == float.MaxValue) { num = Mathf.Max(0f, Vector3.Distance(((Component)prop).transform.position, p) - 15f); } return num; } private static float DistanceToBox(BoxCollider box, Vector3 p) { //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_000f: 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) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)box).transform; Vector3 val = transform.InverseTransformPoint(p) - box.center; Vector3 val2 = box.size * 0.5f; Vector3 val3 = default(Vector3); ((Vector3)(ref val3))..ctor(Mathf.Clamp(val.x, 0f - val2.x, val2.x), Mathf.Clamp(val.y, 0f - val2.y, val2.y), Mathf.Clamp(val.z, 0f - val2.z, val2.z)); return Vector3.Distance(p, transform.TransformPoint(val3 + box.center)); } private static bool Fits(Vector3 pos, Quaternion rot, Collider ground, Player player, bool close = false) { //IL_0019: 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_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) Bounds val = (Bounds)(((??)_ghostFit) ?? _ghostLocalBounds); float num = _ghostLift; if (num > 0f) { float num2 = pos.y; for (int i = 0; i < 9; i++) { float num3 = (float)(i % 3 - 1) * Mathf.Max(0f, ((Bounds)(ref val)).extents.x - 0.15f); float num4 = (float)(i / 3 - 1) * Mathf.Max(0f, ((Bounds)(ref val)).extents.z - 0.15f); Vector3 val2 = pos + rot * new Vector3(((Bounds)(ref val)).center.x + num3, 0f, ((Bounds)(ref val)).center.z + num4); num2 = Mathf.Max(num2, GroundY(val2 + Vector3.up * 0.8f, pos.y, player)); } if (num2 - pos.y > 1.2f) { return false; } num = Mathf.Max(num, num2 - pos.y + 0.3f); } num = Mathf.Clamp(num, 0f, Mathf.Max(0f, ((Bounds)(ref val)).size.y - 0.3f)); float num5 = (close ? 0.6f : 1f); Vector3 half = default(Vector3); ((Vector3)(ref half))..ctor(Mathf.Max(0.02f, ((Bounds)(ref val)).extents.x * num5 - 0.06f), Mathf.Max(0.02f, ((Bounds)(ref val)).extents.y - 0.06f - num * 0.5f), Mathf.Max(0.02f, ((Bounds)(ref val)).extents.z * num5 - 0.06f)); return Clear(pos + rot * (((Bounds)(ref val)).center + Vector3.up * (0.06f + num * 0.5f)), half, rot, ground, player); } private static bool FitsWall(Vector3 pos, Quaternion rot, Collider wall, Player player, bool close = false) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) Bounds ghostLocalBounds = _ghostLocalBounds; float num = (close ? 0.6f : 1f); Vector3 half = default(Vector3); ((Vector3)(ref half))..ctor(Mathf.Max(0.02f, ((Bounds)(ref ghostLocalBounds)).extents.x * num - 0.04f), Mathf.Max(0.02f, ((Bounds)(ref ghostLocalBounds)).extents.y * num - 0.04f), Mathf.Max(0.02f, ((Bounds)(ref ghostLocalBounds)).extents.z - 0.04f)); return Clear(pos + rot * (((Bounds)(ref ghostLocalBounds)).center + Vector3.forward * 0.03f), half, rot, wall, player); } private static bool Clear(Vector3 center, Vector3 half, Quaternion rot, Collider surface, Player player) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) Il2CppReferenceArray val = Physics.OverlapBox(center, half, rot, -5, (QueryTriggerInteraction)1); for (int i = 0; i < ((Il2CppArrayBase)(object)val).Length; i++) { Collider val2 = ((Il2CppArrayBase)(object)val)[i]; if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)surface || val2.isTrigger || Ignored.Contains(((Object)val2).GetInstanceID()) || ((Component)val2).transform.IsChildOf(((Component)player).transform) || ((MemberInfo)((Object)val2).GetIl2CppType()).Name == "TerrainCollider") { continue; } try { if ((Object)(object)((Component)val2).GetComponentInParent() != (Object)null || (Object)(object)((Component)val2).GetComponentInParent() != (Object)null) { continue; } goto IL_00a5; } catch { goto IL_00a5; } IL_00a5: LastBlocker = ((Object)val2).name; if (FortifyApi.DevKeys && Time.unscaledTime - _blockedLogAt > 2f) { _blockedLogAt = Time.unscaledTime; Instance log = Kit.Log; if (log != null) { log.Msg("Dev: no room, " + ((Object)val2).name + " is in the way."); } } return false; } return true; } internal static bool IsPropertyBounds(Collider c) { if ((Object)(object)c != (Object)null) { return Ignored.Contains(((Object)c).GetInstanceID()); } return false; } private static void RefreshIgnored() { if (Time.unscaledTime < _ignoredRefreshAt) { return; } _ignoredRefreshAt = Time.unscaledTime + 5f; Ignored.Clear(); try { List properties = Property.Properties; int num = 0; while (properties != null && num < properties.Count) { Il2CppReferenceArray val = (((Object)(object)properties[num] != (Object)null) ? properties[num].propertyBoundsColliders : null); int num2 = 0; while (val != null && num2 < ((Il2CppArrayBase)(object)val).Length) { if ((Object)(object)((Il2CppArrayBase)(object)val)[num2] != (Object)null) { Ignored.Add(((Object)((Il2CppArrayBase)(object)val)[num2]).GetInstanceID()); } num2++; } num++; } } catch { } } internal static bool UiBusy(Player player) { try { if (Kit.Busy != null && Kit.Busy()) { return true; } if (GameInput.IsTyping) { return true; } if (player.IsInVehicle || player.IsSleeping || player.IsArrested) { return true; } PlayerCamera instance = PlayerSingleton.Instance; if ((Object)(object)instance != (Object)null && instance.ActiveUIElementCount > 0) { return true; } } catch { } return false; } internal static Camera GetCamera() { try { PlayerCamera instance = PlayerSingleton.Instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.Camera != (Object)null) { return instance.Camera; } } catch { } return Camera.main; } internal static string EquippedId() { try { PlayerInventory instance = PlayerSingleton.Instance; object obj; if (instance == null) { obj = null; } else { HotbarSlot equippedSlot = instance.equippedSlot; obj = ((equippedSlot != null) ? ((ItemSlot)equippedSlot).ItemInstance : null); } return (obj != null) ? ((BaseItemInstance)obj).ID : null; } catch { return null; } } private static Bounds LocalBounds(GameObject go) { //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_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) Matrix4x4 worldToLocalMatrix = go.transform.worldToLocalMatrix; bool flag = false; Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(Vector3.zero, Vector3.zero); foreach (MeshRenderer componentsInChild in go.GetComponentsInChildren(true)) { MeshFilter component = ((Component)componentsInChild).GetComponent(); if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null) { continue; } Bounds bounds = component.sharedMesh.bounds; Matrix4x4 val = worldToLocalMatrix * ((Component)componentsInChild).transform.localToWorldMatrix; for (int i = 0; i < 8; i++) { Vector3 val2 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1)))); Vector3 val3 = ((Matrix4x4)(ref val)).MultiplyPoint3x4(val2); if (!flag) { result = new Bounds(val3, Vector3.zero); flag = true; } else { ((Bounds)(ref result)).Encapsulate(val3); } } } return result; } internal static void SetLayer(Transform t, int layer) { ((Component)t).gameObject.layer = layer; for (int i = 0; i < t.childCount; i++) { SetLayer(t.GetChild(i), layer); } } private static float[] F(Vector3 v) { //IL_0008: 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_001a: Unknown result type (might be due to invalid IL or missing references) return new float[3] { v.x, v.y, v.z }; } private static float[] F(Quaternion q) { //IL_0008: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) return new float[4] { q.x, q.y, q.z, q.w }; } private static Vector3 V(float[] a) { //IL_0009: 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) if (a == null || a.Length < 3) { return Vector3.zero; } return new Vector3(a[0], a[1], a[2]); } private static Quaternion Q(float[] a) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (a == null || a.Length < 4) { return Quaternion.identity; } return new Quaternion(a[0], a[1], a[2], a[3]); } } internal static class PickupHold { private const float Seconds = 0.6f; private static float _start = -1f; private static int _target; private static int _lastFrame = -10; public static float Progress { get; private set; } public static bool Showing { get { if (Progress > 0f) { return Time.frameCount - _lastFrame <= 2; } return false; } } public static bool Held(GameObject target) { int num = (((Object)(object)target != (Object)null) ? ((Object)target).GetInstanceID() : 0); int frameCount = Time.frameCount; bool flag = frameCount - _lastFrame > 2; _lastFrame = frameCount; if (num == 0 || !MouseHeld() || HoldingWeapon()) { _start = -1f; Progress = 0f; _target = num; return false; } if (_start < 0f || num != _target || flag) { _target = num; Progress = 0f; if (!Keys.MouseDown(1)) { _start = -1f; return false; } _start = Time.unscaledTime; } Progress = Mathf.Clamp01((Time.unscaledTime - _start) / 0.6f); if (Progress < 1f) { return false; } _start = -1f; Progress = 0f; return true; } private static bool MouseHeld() { try { return Input.GetMouseButton(1); } catch { try { Mouse current = Mouse.current; return current != null && current.rightButton.isPressed; } catch { return false; } } } private static bool HoldingWeapon() { try { PlayerInventory instance = PlayerSingleton.Instance; Equippable val = ((instance != null) ? instance.Equippable : null); if ((Object)(object)val == (Object)null) { return false; } return (Object)(object)((Il2CppObjectBase)val).TryCast() != (Object)null || (Object)(object)((Il2CppObjectBase)val).TryCast() != (Object)null; } catch { return false; } } public static void Draw() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) if (Showing) { float num = 220f; float num2 = (float)Screen.width * 0.5f - num * 0.5f; float num3 = (float)Screen.height * 0.68f + 40f; FortifyApi.UiFill(new Rect(num2, num3, num, 8f), new Color(0f, 0f, 0f, 0.6f)); FortifyApi.UiFill(new Rect(num2, num3, num * Progress, 8f), new Color(1f, 1f, 1f, 0.9f)); } } } internal static class Statics { public static bool Writable(string field) { try { IntPtr nativeClassPtr = Il2CppClassPointerStore.NativeClassPtr; if (nativeClassPtr == IntPtr.Zero) { return false; } IntPtr il2CppField = IL2CPP.GetIl2CppField(nativeClassPtr, field); if (il2CppField == IntPtr.Zero) { return false; } int num = IL2CPP.il2cpp_field_get_flags(il2CppField); return (num & 0x10) != 0 && (num & 0x40) == 0; } catch { return false; } } } internal static class StorageGrid { private static bool _changed; private static bool _btnMoved; private static bool _patched; private static Constraint _was; private static int _countWas; private static Vector2 _btnWas; public static void Patch(Harmony h) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown if (_patched || h == null) { return; } _patched = true; try { HarmonyMethod val = new HarmonyMethod(typeof(StorageGrid), "Before", (Type[])null); int num = 0; foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(typeof(StorageMenu))) { if (declaredMethod.Name == "Open" || declaredMethod.Name == "Close" || declaredMethod.Name == "CloseMenu") { h.Patch((MethodBase)declaredMethod, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); num++; } } if (num == 0) { Instance log = Kit.Log; if (log != null) { log.Warning("Storage screen: nothing to hook, so its layout is put back when ours closes only."); } } } catch (Exception ex) { Instance log2 = Kit.Log; if (log2 != null) { log2.Warning("Storage screen: " + ex.Message); } } } private static void Before() { Restore(); } public static void Columns(StorageMenu menu, int cols, int slots) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) GridLayoutGroup val = ((menu != null) ? menu.SlotGridLayout : null); if ((Object)(object)val == (Object)null || cols < 1) { return; } if (!_changed) { _was = val.constraint; _countWas = val.constraintCount; _changed = true; } int num = Mathf.CeilToInt((float)slots / (float)cols); val.constraint = (Constraint)1; val.constraintCount = cols; RectTransform closeButtonContainer = menu.CloseButtonContainer; if (!((Object)(object)closeButtonContainer == (Object)null)) { if (!_btnMoved) { _btnWas = closeButtonContainer.anchoredPosition; _btnMoved = true; } closeButtonContainer.anchoredPosition = _btnWas - new Vector2(0f, (float)Mathf.Max(0, num - 1) * (val.cellSize.y + val.spacing.y)); } } public static void Restore() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) if (!_changed && !_btnMoved) { return; } try { StorageMenu instance = Singleton.Instance; GridLayoutGroup val = (((Object)(object)instance != (Object)null) ? instance.SlotGridLayout : null); if (_changed && (Object)(object)val != (Object)null) { val.constraint = _was; val.constraintCount = _countWas; } RectTransform val2 = (((Object)(object)instance != (Object)null) ? instance.CloseButtonContainer : null); if (_btnMoved && (Object)(object)val2 != (Object)null) { val2.anchoredPosition = _btnWas; } } catch { } _changed = false; _btnMoved = false; } } internal static class Ui { private static Vector2 _mouse; private static bool _click; private static int _clickFrame; private static readonly Dictionary Styles = new Dictionary(); private static readonly Dictionary Solid = new Dictionary(); private static readonly Dictionary Pictures = new Dictionary(); public static Vector2 MousePos => _mouse; public static void Capture() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) _mouse = MouseGui(); if (InputUtil.MouseDown(0)) { _click = true; _clickFrame = Time.frameCount; } else if (_click && Time.frameCount - _clickFrame > 1) { _click = false; } } private static Vector2 MouseGui() { //IL_0002: 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_000f: 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) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) Vector2 val = default(Vector2); bool flag = false; try { val = Vector2.op_Implicit(Input.mousePosition); flag = true; } catch { } if (!flag) { try { Mouse current = Mouse.current; if (current != null) { val = ((InputControl)(object)((Pointer)current).position).ReadValue(); } } catch { } } return new Vector2(val.x, (float)Screen.height - val.y); } public static bool Hover(Rect r) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) return ((Rect)(ref r)).Contains(_mouse); } public static bool Click(Rect r) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (!_click || !((Rect)(ref r)).Contains(_mouse)) { return false; } _click = false; return true; } private static GUIStyle SolidStyle(Color c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Expected O, but got Unknown //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Expected O, but got Unknown //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Expected O, but got Unknown //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Expected O, but got Unknown int num = (int)(Math.Clamp(c.r, 0f, 1f) * 255f + 0.5f); int num2 = (int)(Math.Clamp(c.g, 0f, 1f) * 255f + 0.5f); int num3 = (int)(Math.Clamp(c.b, 0f, 1f) * 255f + 0.5f); int num4 = (int)(Math.Clamp(c.a, 0f, 1f) * 255f + 0.5f); int key = (num << 24) | (num2 << 16) | (num3 << 8) | num4; if (Solid.TryGetValue(key, out var value) && value != null && (Object)(object)value.normal.background != (Object)null) { return value; } if (Solid.Count > 600) { foreach (GUIStyle value2 in Solid.Values) { if (value2 != null && (Object)(object)value2.normal.background != (Object)null) { Object.Destroy((Object)(object)value2.normal.background); } } Solid.Clear(); } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); Color32 val2 = default(Color32); ((Color32)(ref val2))..ctor((byte)num, (byte)num2, (byte)num3, (byte)num4); val.SetPixels32(new Il2CppStructArray((Color32[])(object)new Color32[4] { val2, val2, val2, val2 })); val.Apply(); ((Object)val).hideFlags = (HideFlags)32; value = new GUIStyle(); value.normal.background = val; value.border = new RectOffset(0, 0, 0, 0); value.padding = new RectOffset(0, 0, 0, 0); value.margin = new RectOffset(0, 0, 0, 0); Solid[key] = value; return value; } public static void Fill(Rect r, Color c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (!(c.a <= 0.003f)) { GUI.Label(r, "", SolidStyle(c)); } } public static void Image(Rect r, Texture2D tex) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)tex == (Object)null)) { if (!Pictures.TryGetValue(((Il2CppObjectBase)tex).Pointer, out var value) || value == null) { value = new GUIStyle(); value.normal.background = tex; value.border = new RectOffset(0, 0, 0, 0); value.padding = new RectOffset(0, 0, 0, 0); Pictures[((Il2CppObjectBase)tex).Pointer] = value; } GUI.Label(r, "", value); } } public static void Picture(Rect r, Texture tex) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 //IL_001d: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)tex == (Object)null)) { Event current = Event.current; if (current != null && (int)current.type == 7) { Graphics.DrawTexture(r, tex); } } } public static void Frame(Rect r, Color c, float t = 2f) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, t), c); Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - t, ((Rect)(ref r)).width, t), c); Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), c); Fill(new Rect(((Rect)(ref r)).xMax - t, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), c); } public static void Text(Rect r, string s, int size, Color c, TextAnchor a = (TextAnchor)4, bool bold = true, bool wrap = true) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected I4, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown int key = size * 64 + a * 4 + (bold ? 2 : 0) + wrap; if (!Styles.TryGetValue(key, out var value) || value == null) { value = new GUIStyle(GUI.skin.label) { fontSize = size, alignment = a, fontStyle = (FontStyle)(bold ? 1 : 0), wordWrap = wrap }; Styles[key] = value; } value.normal.textColor = c; GUI.Label(r, s ?? "", value); } public static bool Button(Rect r, string label, bool enabled = true, bool selected = false, int size = 17) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) bool flag = enabled && Hover(r); Color c = ((!enabled) ? new Color(0.18f, 0.18f, 0.2f, 0.9f) : (selected ? new Color(0.85f, 0.65f, 0.2f, 0.97f) : (flag ? new Color(0.36f, 0.32f, 0.46f, 0.97f) : new Color(0.24f, 0.22f, 0.3f, 0.95f)))); Fill(r, c); Frame(r, enabled ? new Color(1f, 1f, 1f, flag ? 0.55f : 0.25f) : new Color(1f, 1f, 1f, 0.08f)); Text(r, label, size, (Color)((!enabled) ? new Color(0.5f, 0.5f, 0.55f) : (selected ? Color.black : Color.white)), (TextAnchor)4); if (enabled) { return Click(r); } return false; } } } namespace FybCommon { internal static class FortifyApi { private sealed class SaveDoc { public int Version { get; set; } = 1; public Dictionary Data { get; set; } = new Dictionary(); } private static Instance _log; private static string _folder; private static MelonPreferences_Entry _devKeys; private static KeyCode _use = (KeyCode)101; private static readonly List DrawnIds = new List(); private static Harmony _harmony; private static bool _loaded; private static int _inGameFrame = -1; private static bool _inGame; private static string _iconItem; private static Sprite _icon; private static Dictionary _data = new Dictionary(); private static string _file; private static bool _readThisSession; private static bool _patched; private static readonly Dictionary Mats = new Dictionary(); private static Shader _lit; private static readonly HashSet Drawn = new HashSet(); private static float _nextDraw; private static readonly List<(string label, AudioClip clip)> NoSongs = new List<(string, AudioClip)>(); public static bool Linked => FybLink.Present; public static string LinkedVersion { get { if (!FybLink.Present) { return null; } return Safe(FybLink.Version, "?"); } } public static bool InGame { get { if (Time.frameCount == _inGameFrame) { return _inGame; } _inGameFrame = Time.frameCount; _inGame = false; if (_loaded) { try { LoadManager instance = Singleton.Instance; _inGame = (Object)(object)instance != (Object)null && instance.IsGameLoaded; } catch { } } return _inGame; } } public static bool IsGuest { get { try { return InstanceFinder.IsClient && !InstanceFinder.IsServer; } catch { return false; } } } public static bool IsHost => !IsGuest; public static bool DevKeys { get { MelonPreferences_Entry devKeys = _devKeys; if (devKeys == null || !devKeys.Value) { if (FybLink.Present) { return Safe(FybLink.DevKeys, fallback: false); } return false; } return true; } } public static bool DataReady { get; private set; } public static KeyCode UseKey { get { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (!FybLink.Present) { return _use; } return Safe(FybLink.UseKey, _use); } } public static IReadOnlyList<(string label, AudioClip clip)> YourSongs { get { if (FybLink.Present) { try { return FybLink.Songs() ?? NoSongs; } catch { } } return NoSongs; } } public static event Action BeforeSave; public static event Action AfterLoad; public static event Action Unloaded; public static void Init(MelonMod mod, string folder, string title, params string[] keepDrawnIdPrefixes) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) _log = ((MelonBase)mod).LoggerInstance; _folder = folder; DrawnIds.AddRange(keepDrawnIdPrefixes); MelonPreferences_Category obj = MelonPreferences.CreateCategory(folder, title); _devKeys = obj.CreateEntry("DevKeys", false, "Developer keys", "Test keys (for the mod's author).", false, false, (ValueValidator)null, (string)null); _use = Keys.Parse(obj.CreateEntry("UseKey", "E", "Use key", "Key for using things. With Fortify Your Base installed, its own use key is used instead.", false, false, (ValueValidator)null, (string)null).Value, (KeyCode)101); GameLifecycle.OnLoadComplete += OnLoaded; GameLifecycle.OnSaveStart += OnSaving; GameLifecycle.OnPreSceneChange += OnLeaving; _harmony = ((MelonBase)mod).HarmonyInstance; } public static void Log(string msg) { Instance log = _log; if (log != null) { log.Msg(msg); } } public static void Frame() { Ui.Capture(); Shared.Update(); DrawPass(); RainCover.Update(); TreeCut.Update(); } public static void SetNotifyIcon(string itemId) { _iconItem = itemId; _icon = null; } public static void Notify(string title, string text) { try { NotificationsManager instance = Singleton.Instance; if ((Object)(object)instance == (Object)null) { Log(title + ": " + text); return; } if ((Object)(object)_icon == (Object)null && !string.IsNullOrEmpty(_iconItem)) { try { ItemDefinition item = Registry.GetItem(_iconItem); _icon = ((item != null) ? ((BaseItemDefinition)item).Icon : null); } catch { } } instance.SendNotification(title, text, _icon, 6f, true); } catch (Exception ex) { Log($"{title}: {text} ({ex.Message})"); } } public static void LogEvent(string kind, string place, int crew, string outcome) { if (FybLink.Present) { try { FybLink.LogEvent(kind, place, crew, outcome); } catch { } } } public static string GetData(string key) { if (key == null || !_data.TryGetValue(key, out var value)) { return null; } return value; } public static void SetData(string key, string value) { if (key != null) { _data[key] = value ?? ""; } } private static void OnLoaded() { _loaded = true; if (!_patched) { _patched = true; try { Pins.Patch(_harmony); } catch (Exception ex) { Log("Pins: " + ex.Message); } } _data = new Dictionary(); _file = FileFor(SavePath()); try { if (_file != null && File.Exists(_file)) { SaveDoc saveDoc = JsonSerializer.Deserialize(File.ReadAllText(_file)); if (saveDoc?.Data != null) { _data = saveDoc.Data; } } else if (_file != null) { Migrate(); } } catch (Exception ex2) { Log("Couldn't read the save (" + ex2.Message + "); starting fresh."); } _readThisSession = true; DataReady = true; Log(FybLink.Present ? ("Linked up with Fortify Your Base " + LinkedVersion + ".") : "Running on its own."); try { FortifyApi.AfterLoad?.Invoke(); } catch (Exception ex3) { Log("Load: " + ex3.Message); } } private static void Migrate() { try { string path = Path.Combine(MelonEnvironment.UserDataDirectory, "HoldTheFort", "Saves", Path.GetFileName(_file)); if (!File.Exists(path)) { return; } using JsonDocument jsonDocument = JsonDocument.Parse(File.ReadAllText(path)); if (!jsonDocument.RootElement.TryGetProperty("Addons", out var value) || value.ValueKind != JsonValueKind.Object) { return; } int num = 0; foreach (JsonProperty item in value.EnumerateObject()) { if (item.Value.ValueKind == JsonValueKind.String) { _data[item.Name] = item.Value.GetString(); num++; } } if (num > 0) { Log("Picked up this save's progress from Fortify Your Base's save file."); } } catch (Exception ex) { Log("Couldn't read Fortify Your Base's save file (" + ex.Message + ")."); } } private static void OnSaving() { if (!DataReady || !_readThisSession || IsGuest) { return; } try { FortifyApi.BeforeSave?.Invoke(); } catch (Exception ex) { Log("Save: " + ex.Message); } string text = _file ?? FileFor(SavePath()); if (text == null) { return; } try { string text2 = text + ".tmp"; File.WriteAllText(text2, JsonSerializer.Serialize(new SaveDoc { Data = _data }, new JsonSerializerOptions { WriteIndented = true })); if (File.Exists(text)) { File.Delete(text); } File.Move(text2, text); } catch (Exception ex2) { Log("Couldn't save: " + ex2.Message); } } private static void OnLeaving() { if (DataReady) { try { FortifyApi.Unloaded?.Invoke(); } catch { } } DataReady = false; _loaded = false; _readThisSession = false; _file = null; _data = new Dictionary(); Shared.Reset(); Pins.Reset(); Drawn.Clear(); RainCover.Reset(); TreeCut.Reset(); } private static string SavePath() { LoadManager instance = Singleton.Instance; string text = null; try { object obj; if (instance == null) { obj = null; } else { SaveInfo activeSaveInfo = instance.ActiveSaveInfo; obj = ((activeSaveInfo != null) ? activeSaveInfo.SavePath : null); } text = (string)obj; } catch { } if (string.IsNullOrEmpty(text)) { try { text = ((instance != null) ? instance.LoadedGameFolderPath : null); } catch { } } return text; } private static string FileFor(string savePath) { if (string.IsNullOrWhiteSpace(savePath)) { return null; } string text = savePath.TrimEnd('/', '\\'); StringBuilder stringBuilder = new StringBuilder(); string fileName = Path.GetFileName(text); foreach (char c in fileName) { stringBuilder.Append((char.IsLetterOrDigit(c) || c == '_' || c == '-') ? c : '_'); } uint num = 2166136261u; fileName = text.ToLowerInvariant().Replace('\\', '/'); foreach (char c2 in fileName) { num ^= c2; num *= 16777619; } string text2 = Path.Combine(MelonEnvironment.UserDataDirectory, _folder ?? "FortifyAddon", "Saves"); Directory.CreateDirectory(text2); return Path.Combine(text2, $"{stringBuilder}_{num:x8}.json"); } public static bool KeyDown(KeyCode k) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return Keys.Down(k); } public static bool KeyHeld(KeyCode k) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return Keys.Held(k); } public static void Typing(bool on) { Keys.Suppressed = on; try { GameInput.IsTyping = on; } catch { } if (FybLink.Present) { try { FybLink.Suppress(on); } catch { } } } private static Shader LitShader() { if ((Object)(object)_lit != (Object)null) { return _lit; } _lit = Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Universal Render Pipeline/Simple Lit"); if ((Object)(object)_lit == (Object)null) { foreach (Material item in Resources.FindObjectsOfTypeAll()) { if ((Object)(object)item != (Object)null && (Object)(object)item.shader != (Object)null && ((Object)item.shader).name.Contains("Lit")) { _lit = item.shader; break; } } } if ((Object)(object)_lit == (Object)null) { _lit = Shader.Find("Standard"); } return _lit; } private static Material MakeMat(string key, Color color, float metallic, float smoothness, Color? emission) { //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_0036: Expected O, but got Unknown //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) if (Mats.TryGetValue(key, out var value) && (Object)(object)value != (Object)null) { return value; } Material val = new Material(LitShader()) { name = "FYBA_" + key }; val.color = color; if (val.HasProperty("_BaseColor")) { val.SetColor("_BaseColor", color); } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", metallic); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", smoothness); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", smoothness); } if (emission.HasValue) { val.EnableKeyword("_EMISSION"); if (val.HasProperty("_EmissionColor")) { val.SetColor("_EmissionColor", emission.Value); } val.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1; } ((Object)val).hideFlags = (HideFlags)32; Mats[key] = val; return val; } public static Material Mat(string key, Color c, float metallic = 0f, float smoothness = 0.3f) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return MakeMat(key, c, metallic, smoothness, null); } public static Material Emissive(string key, Color c, Color emission, float smoothness = 0.4f) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) return MakeMat(key, c, 0f, smoothness, emission); } public static Material Glow(string key, Color c) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) return MakeMat(key, c, 0f, 0.5f, c * 2.5f); } public static GameObject Part(Transform parent, PrimitiveType type, Vector3 pos, Vector3 scale, Material m, Vector3? euler = null, bool collider = false, string name = null) { //IL_0000: 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_0041: 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_005f: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.CreatePrimitive(type); if (!collider) { Object.DestroyImmediate((Object)(object)val.GetComponent()); } val.transform.SetParent(parent, false); val.transform.localPosition = pos; val.transform.localRotation = Quaternion.Euler((Vector3)(((??)euler) ?? Vector3.zero)); val.transform.localScale = scale; ((Renderer)val.GetComponent()).sharedMaterial = m; if (name != null) { ((Object)val).name = name; } return val; } public static void UiFill(Rect r, Color c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) Ui.Fill(r, c); } public static void UiFrame(Rect r, Color c, float t = 2f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) Ui.Frame(r, c, t); } public static void UiText(Rect r, string s, int size, Color c, TextAnchor a = (TextAnchor)4, bool bold = true) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) Ui.Text(r, s, size, c, a, bold); } public static bool UiButton(Rect r, string label, bool enabled = true, bool selected = false, int size = 17) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return Ui.Button(r, label, enabled, selected, size); } public static void OpenMenu(string name) { try { PlayerCamera instance = PlayerSingleton.Instance; if ((Object)(object)instance != (Object)null) { instance.AddActiveUIElement(name); instance.SetCanLook(false); } } catch { } try { PlayerMovement instance2 = PlayerSingleton.Instance; if ((Object)(object)instance2 != (Object)null) { instance2.CanMove = false; } } catch { } Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; } public static void CloseMenu(string name) { try { PlayerCamera instance = PlayerSingleton.Instance; if ((Object)(object)instance != (Object)null) { instance.RemoveActiveUIElement(name); instance.SetCanLook(true); } } catch { } try { PlayerMovement instance2 = PlayerSingleton.Instance; if ((Object)(object)instance2 != (Object)null) { instance2.CanMove = true; } } catch { } Cursor.lockState = (CursorLockMode)1; Cursor.visible = false; } public static void Hint(string text) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) if (!string.IsNullOrEmpty(text)) { float num = Screen.width; float num2 = Screen.height; Rect r = new Rect(num * 0.5f - 420f, num2 * 0.68f, 840f, 34f); Ui.Fill(r, new Color(0f, 0f, 0f, 0.55f)); Ui.Text(r, text, 17, Color.white, (TextAnchor)4); } } public static void ShareState(string key, string value) { Shared.Set(key, value); } public static string SharedState(string key) { return Shared.Get(key); } public static void SendRequest(string key, string value) { Shared.Request(key, value); } public static List TakeRequests(string key) { Shared.Listen(key); return Shared.Take(key); } public static void Pin(GameObject npc, bool on) { try { NPC val = (((Object)(object)npc != (Object)null) ? npc.GetComponent() : null); if ((Object)(object)val != (Object)null) { Pins.Set(val, on); } } catch { } } public static void KeepDrawn(NPC n) { if ((Object)(object)n == (Object)null) { return; } try { Avatar avatar = n.Avatar; if (!((Object)(object)avatar == (Object)null)) { if (avatar._cullingRange < 130f) { avatar._cullingRange = 130f; } if (avatar._visibilityRangeSqr < 16900f) { avatar._visibilityRangeSqr = 16900f; } } } catch { } } private static void DrawPass() { if (DrawnIds.Count == 0 || Time.unscaledTime < _nextDraw || !_loaded) { return; } _nextDraw = Time.unscaledTime + 2f; try { List nPCRegistry = NPCManager.NPCRegistry; for (int i = 0; nPCRegistry != null && i < nPCRegistry.Count; i++) { NPC val = nPCRegistry[i]; if ((Object)(object)val == (Object)null) { continue; } bool flag = Drawn.Contains(((Il2CppObjectBase)val).Pointer); if (!flag) { string text = val.ID ?? ""; foreach (string drawnId in DrawnIds) { if (text.StartsWith(drawnId, StringComparison.Ordinal)) { flag = true; break; } } if (!flag) { continue; } Drawn.Add(((Il2CppObjectBase)val).Pointer); } KeepDrawn(val); } } catch { } } public static void ReserveArea(string key, Vector3 centre, float radius, float lot = 0f) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (FybLink.Present) { try { FybLink.ReserveArea(key, centre, radius, lot); } catch { } } } public static void AddBuildArea(string key, Func inside, Transform gridFrame = null) { if (FybLink.Present) { try { FybLink.AddBuildArea(key, inside, gridFrame); } catch { } } } public static void RemoveBuildArea(string key) { if (FybLink.Present) { try { FybLink.RemoveBuildArea(key); } catch { } } } public static void AddShelter(string key, Func inside) { if (FybLink.Present) { try { FybLink.AddShelter(key, inside); return; } catch { return; } } RainCover.Add(key, inside); } public static void RemoveShelter(string key) { if (FybLink.Present) { try { FybLink.RemoveShelter(key); return; } catch { return; } } RainCover.Remove(key); } public static void AddTreeClearing(string key, Vector3 centre, float radius) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (FybLink.Present) { try { FybLink.AddTreeClearing(key, centre, radius); return; } catch { return; } } TreeCut.Add(key, centre, radius); } public static void RemoveTreeClearing(string key) { if (FybLink.Present) { try { FybLink.RemoveTreeClearing(key); return; } catch { return; } } TreeCut.Remove(key); } public static bool ParkFoodTruck(string key, Vector3 pos, float yaw) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (FybLink.Present) { try { return FybLink.ParkFoodTruck(key, pos, yaw); } catch { } } return false; } public static void ReleaseFoodTruck(string key) { if (FybLink.Present) { try { FybLink.ReleaseFoodTruck(key); } catch { } } } public static bool FoodTruckParkedBy(string key) { if (FybLink.Present) { try { return FybLink.FoodTruckParkedBy(key); } catch { } } return false; } public static void DevView(Vector3 from, Vector3 at) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (FybLink.Present) { try { FybLink.DevView(from, at); } catch { } } } public static void DevViewEnd() { if (FybLink.Present) { try { FybLink.DevViewEnd(); } catch { } } } private static T Safe(Func f, T fallback) { try { return f(); } catch { return fallback; } } } internal static class FybLink { private static int _present = -1; public static bool Present { get { if (_present >= 0) { return _present == 1; } _present = 0; try { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { if (assemblies[i].GetName().Name == "HoldTheFort") { _present = ((Level() >= 3) ? 1 : 0); break; } } } catch { _present = 0; } return _present == 1; } } [MethodImpl(MethodImplOptions.NoInlining)] private static int Level() { try { return LevelInner(); } catch { return 0; } } [MethodImpl(MethodImplOptions.NoInlining)] private static int LevelInner() { return FortifyApi.Level; } [MethodImpl(MethodImplOptions.NoInlining)] public static string Version() { return FortifyApi.Version; } [MethodImpl(MethodImplOptions.NoInlining)] public static bool DevKeys() { return FortifyApi.DevKeys; } [MethodImpl(MethodImplOptions.NoInlining)] public static KeyCode UseKey() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return FortifyApi.UseKey; } [MethodImpl(MethodImplOptions.NoInlining)] public static void LogEvent(string kind, string place, int crew, string outcome) { FortifyApi.LogEvent(kind, place, crew, outcome); } [MethodImpl(MethodImplOptions.NoInlining)] public static IReadOnlyList<(string label, AudioClip clip)> Songs() { return FortifyApi.YourSongs; } [MethodImpl(MethodImplOptions.NoInlining)] public static void ReserveArea(string key, Vector3 c, float r, float lot) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) FortifyApi.ReserveArea(key, c, r, lot); } [MethodImpl(MethodImplOptions.NoInlining)] public static void AddBuildArea(string key, Func inside, Transform frame) { FortifyApi.AddBuildArea(key, inside, frame); } [MethodImpl(MethodImplOptions.NoInlining)] public static void RemoveBuildArea(string key) { FortifyApi.RemoveBuildArea(key); } [MethodImpl(MethodImplOptions.NoInlining)] public static void AddShelter(string key, Func inside) { FortifyApi.AddShelter(key, inside); } [MethodImpl(MethodImplOptions.NoInlining)] public static void RemoveShelter(string key) { FortifyApi.RemoveShelter(key); } [MethodImpl(MethodImplOptions.NoInlining)] public static void AddTreeClearing(string key, Vector3 c, float r) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) FortifyApi.AddTreeClearing(key, c, r); } [MethodImpl(MethodImplOptions.NoInlining)] public static void RemoveTreeClearing(string key) { FortifyApi.RemoveTreeClearing(key); } [MethodImpl(MethodImplOptions.NoInlining)] public static bool ParkFoodTruck(string key, Vector3 p, float yaw) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return FortifyApi.ParkFoodTruck(key, p, yaw); } [MethodImpl(MethodImplOptions.NoInlining)] public static void ReleaseFoodTruck(string key) { FortifyApi.ReleaseFoodTruck(key); } [MethodImpl(MethodImplOptions.NoInlining)] public static bool FoodTruckParkedBy(string key) { return FortifyApi.FoodTruckParkedBy(key); } [MethodImpl(MethodImplOptions.NoInlining)] public static void DevView(Vector3 from, Vector3 at) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) FortifyApi.DevView(from, at); } [MethodImpl(MethodImplOptions.NoInlining)] public static void DevViewEnd() { FortifyApi.DevViewEnd(); } public static void Suppress(bool on) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { if (!(assembly.GetName().Name != "HoldTheFort")) { (assembly.GetType("HoldTheFort.InputUtil")?.GetField("Suppressed", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))?.SetValue(null, on); break; } } } } internal static class Keys { private static bool _legacyBroken; public static bool Suppressed; public static KeyCode Parse(string name, KeyCode fallback) { //IL_0018: 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) if (string.IsNullOrWhiteSpace(name) || !Enum.TryParse(name.Trim(), ignoreCase: true, out KeyCode result)) { return fallback; } return result; } public static bool Down(KeyCode key) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!Suppressed) { return RawDown(key); } return false; } public static bool Held(KeyCode key) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!Suppressed) { return RawHeld(key); } return false; } public static bool RawDown(KeyCode key) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!_legacyBroken) { try { return Input.GetKeyDown(key); } catch { _legacyBroken = true; } } KeyControl val = Control(key); if (val != null) { return ((ButtonControl)val).wasPressedThisFrame; } return false; } public static bool RawHeld(KeyCode key) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!_legacyBroken) { try { return Input.GetKey(key); } catch { _legacyBroken = true; } } KeyControl val = Control(key); if (val != null) { return ((ButtonControl)val).isPressed; } return false; } public static bool MouseDown(int button) { if (!_legacyBroken) { try { return Input.GetMouseButtonDown(button); } catch { _legacyBroken = true; } } try { Mouse current = Mouse.current; return current != null && ((button == 0) ? current.leftButton.wasPressedThisFrame : current.rightButton.wasPressedThisFrame); } catch { return false; } } public static string Typed(bool shift) { if (!_legacyBroken) { try { return Input.inputString ?? ""; } catch { _legacyBroken = true; } } StringBuilder stringBuilder = new StringBuilder(); for (char c = 'a'; c <= 'z'; c = (char)(c + 1)) { if (RawDown((KeyCode)(97 + (c - 97)))) { stringBuilder.Append(shift ? char.ToUpperInvariant(c) : c); } } for (int i = 0; i <= 9; i++) { if (RawDown((KeyCode)(48 + i))) { stringBuilder.Append(shift ? ")!@#$%^&*("[i] : ((char)(48 + i))); } } if (RawDown((KeyCode)32)) { stringBuilder.Append(' '); } if (RawDown((KeyCode)45)) { stringBuilder.Append('-'); } if (RawDown((KeyCode)39)) { stringBuilder.Append('\''); } if (RawDown((KeyCode)46)) { stringBuilder.Append('.'); } if (RawDown((KeyCode)8)) { stringBuilder.Append('\b'); } return stringBuilder.ToString(); } private unsafe static KeyControl Control(KeyCode key) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) try { Keyboard current = Keyboard.current; if (current == null) { return null; } string text = ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString(); if (text.StartsWith("Alpha")) { text = "Digit" + text.Substring(5); } else if (text == "Return") { text = "Enter"; } else if (text == "KeypadEnter") { text = "NumpadEnter"; } else if (text.StartsWith("Keypad")) { text = "Numpad" + text.Substring(6); } Key result; return Enum.TryParse(text, ignoreCase: true, out result) ? current[result] : null; } catch { return null; } } } internal static class Ui { private static Vector2 _mouse; private static bool _click; private static int _clickFrame; private static readonly Dictionary Styles = new Dictionary(); private static readonly Dictionary Solid = new Dictionary(); public static void Capture() { //IL_0002: 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_000f: 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) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) Vector2 val = default(Vector2); bool flag = false; try { val = Vector2.op_Implicit(Input.mousePosition); flag = true; } catch { } if (!flag) { try { Mouse current = Mouse.current; if (current != null) { val = ((InputControl)(object)((Pointer)current).position).ReadValue(); } } catch { } } _mouse = new Vector2(val.x, (float)Screen.height - val.y); if (Keys.MouseDown(0)) { _click = true; _clickFrame = Time.frameCount; } else if (_click && Time.frameCount - _clickFrame > 1) { _click = false; } } public static bool Hover(Rect r) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) return ((Rect)(ref r)).Contains(_mouse); } public static bool Click(Rect r) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (!_click || !((Rect)(ref r)).Contains(_mouse)) { return false; } _click = false; return true; } private static GUIStyle SolidStyle(Color c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Expected O, but got Unknown //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Expected O, but got Unknown //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Expected O, but got Unknown //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Expected O, but got Unknown int num = (int)(Math.Clamp(c.r, 0f, 1f) * 255f + 0.5f); int num2 = (int)(Math.Clamp(c.g, 0f, 1f) * 255f + 0.5f); int num3 = (int)(Math.Clamp(c.b, 0f, 1f) * 255f + 0.5f); int num4 = (int)(Math.Clamp(c.a, 0f, 1f) * 255f + 0.5f); int key = (num << 24) | (num2 << 16) | (num3 << 8) | num4; if (Solid.TryGetValue(key, out var value) && value != null && (Object)(object)value.normal.background != (Object)null) { return value; } if (Solid.Count > 600) { foreach (GUIStyle value2 in Solid.Values) { if (value2 != null && (Object)(object)value2.normal.background != (Object)null) { Object.Destroy((Object)(object)value2.normal.background); } } Solid.Clear(); } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); Color32 val2 = default(Color32); ((Color32)(ref val2))..ctor((byte)num, (byte)num2, (byte)num3, (byte)num4); val.SetPixels32(new Il2CppStructArray((Color32[])(object)new Color32[4] { val2, val2, val2, val2 })); val.Apply(); ((Object)val).hideFlags = (HideFlags)32; value = new GUIStyle(); value.normal.background = val; value.border = new RectOffset(0, 0, 0, 0); value.padding = new RectOffset(0, 0, 0, 0); value.margin = new RectOffset(0, 0, 0, 0); Solid[key] = value; return value; } public static void Fill(Rect r, Color c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (!(c.a <= 0.003f)) { GUI.Label(r, "", SolidStyle(c)); } } public static void Frame(Rect r, Color c, float t = 2f) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, t), c); Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - t, ((Rect)(ref r)).width, t), c); Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), c); Fill(new Rect(((Rect)(ref r)).xMax - t, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), c); } public static void Text(Rect r, string s, int size, Color c, TextAnchor a = (TextAnchor)4, bool bold = true, bool wrap = true) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: 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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected I4, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown int key = size * 64 + a * 4 + (bold ? 2 : 0) + wrap; if (!Styles.TryGetValue(key, out var value) || value == null) { value = new GUIStyle(GUI.skin.label) { fontSize = size, alignment = a, fontStyle = (FontStyle)(bold ? 1 : 0), wordWrap = wrap }; Styles[key] = value; } value.normal.textColor = c; GUI.Label(r, s ?? "", value); } public static bool Button(Rect r, string label, bool enabled = true, bool selected = false, int size = 17) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) bool flag = enabled && Hover(r); Color c = ((!enabled) ? new Color(0.18f, 0.18f, 0.2f, 0.9f) : (selected ? new Color(0.85f, 0.65f, 0.2f, 0.97f) : (flag ? new Color(0.36f, 0.32f, 0.46f, 0.97f) : new Color(0.24f, 0.22f, 0.3f, 0.95f)))); Fill(r, c); Frame(r, enabled ? new Color(1f, 1f, 1f, flag ? 0.55f : 0.25f) : new Color(1f, 1f, 1f, 0.08f)); Text(r, label, size, (Color)((!enabled) ? new Color(0.5f, 0.5f, 0.55f) : (selected ? Color.black : Color.white)), (TextAnchor)4); if (enabled) { return Click(r); } return false; } } internal static class Shared { private const string Prefix = "fyb_"; private static readonly Dictionary Local = new Dictionary(); private static readonly Dictionary Sent = new Dictionary(); private static readonly Dictionary Read = new Dictionary(); private static readonly Dictionary MySeq = new Dictionary(); private static readonly Dictionary SeenSeq = new Dictionary(); private static readonly Dictionary> Inbox = new Dictionary>(); private static readonly HashSet Watched = new HashSet(); private static float _nextFlush; private static bool InLobby(out CSteamID lobby) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_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) lobby = default(CSteamID); try { Lobby instance = Singleton.Instance; if ((Object)(object)instance == (Object)null || !instance.IsInLobby || instance.LobbyID == 0L) { return false; } lobby = new CSteamID { m_SteamID = instance.LobbyID }; return instance.PlayerCount > 1 || FortifyApi.IsGuest; } catch { return false; } } public static void Set(string key, string value) { if (key != null) { Local[key] = value ?? ""; } } public static string Get(string key) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) if (key == null) { return null; } if (!FortifyApi.IsGuest) { if (!Local.TryGetValue(key, out var value)) { return null; } return value; } if (Read.TryGetValue(key, out (string, float) value2) && Time.unscaledTime - value2.Item2 < 0.5f) { return value2.Item1; } string text = null; try { if (InLobby(out var lobby)) { text = SteamMatchmaking.GetLobbyData(lobby, "fyb_" + key); } } catch { } if (string.IsNullOrEmpty(text)) { text = null; } Read[key] = (text, Time.unscaledTime); return text; } public static void Request(string key, string value) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) if (key == null) { return; } if (!FortifyApi.IsGuest) { Queue(key, value); return; } try { if (InLobby(out var lobby)) { int value3; int value2 = (MySeq.TryGetValue(key, out value3) ? value3 : Random.Range(1, 1000)) + 1; MySeq[key] = value2; SteamMatchmaking.SetLobbyMemberData(lobby, "fyb_rq_" + key, value2 + "|" + value); } } catch { } } public static List Take(string key) { List list = new List(); if (key != null && Inbox.TryGetValue(key, out var value)) { list.AddRange(value); value.Clear(); } return list; } private static void Queue(string key, string value) { if (!Inbox.TryGetValue(key, out var value2)) { value2 = (Inbox[key] = new List()); } if (value2.Count < 20) { value2.Add(value ?? ""); } } public static void Update() { //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_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) if (FortifyApi.IsGuest || Time.unscaledTime < _nextFlush) { return; } _nextFlush = Time.unscaledTime + 0.5f; if (!InLobby(out var lobby)) { return; } try { foreach (KeyValuePair item in Local) { if ((!Sent.TryGetValue(item.Key, out var value) || !(value == item.Value)) && SteamMatchmaking.SetLobbyData(lobby, "fyb_" + item.Key, item.Value)) { Sent[item.Key] = item.Value; } } foreach (string key2 in Inbox.Keys) { Watched.Add(key2); } int numLobbyMembers = SteamMatchmaking.GetNumLobbyMembers(lobby); ulong num = 0uL; try { num = SteamUser.GetSteamID().m_SteamID; } catch { } for (int i = 0; i < numLobbyMembers; i++) { CSteamID lobbyMemberByIndex = SteamMatchmaking.GetLobbyMemberByIndex(lobby, i); if (lobbyMemberByIndex.m_SteamID == num) { continue; } foreach (string item2 in Watched) { string lobbyMemberData = SteamMatchmaking.GetLobbyMemberData(lobby, lobbyMemberByIndex, "fyb_rq_" + item2); if (string.IsNullOrEmpty(lobbyMemberData)) { continue; } int num2 = lobbyMemberData.IndexOf('|'); if (num2 <= 0 || !int.TryParse(lobbyMemberData.Substring(0, num2), out var result)) { continue; } string key = lobbyMemberByIndex.m_SteamID + "/" + item2; if (!SeenSeq.TryGetValue(key, out var value2) || value2 != result) { bool num3 = !SeenSeq.ContainsKey(key); SeenSeq[key] = result; if (!num3) { Queue(item2, lobbyMemberData.Substring(num2 + 1)); } } } } } catch { } } public static void Listen(string key) { if (key != null && !Inbox.ContainsKey(key)) { Inbox[key] = new List(); } } public static void Reset() { Local.Clear(); Sent.Clear(); Read.Clear(); Inbox.Clear(); SeenSeq.Clear(); Watched.Clear(); } } internal static class Pins { private static readonly HashSet Held = new HashSet(); public static void Set(NPC nat, bool on) { try { NPCMovement val = (((Object)(object)nat != (Object)null) ? nat.Movement : null); if (!((Object)(object)val == (Object)null)) { if (on) { Held.Add(((Il2CppObjectBase)val).Pointer); } else { Held.Remove(((Il2CppObjectBase)val).Pointer); } } } catch { } } public static bool IsHeld(NPC nat) { try { NPCMovement val = (((Object)(object)nat != (Object)null) ? nat.Movement : null); return (Object)(object)val != (Object)null && Held.Contains(((Il2CppObjectBase)val).Pointer); } catch { return false; } } public static void Reset() { Held.Clear(); } public static void Patch(Harmony h) { //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Expected O, but got Unknown //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Expected O, but got Unknown if (h == null) { return; } Type typeFromHandle = typeof(NPCMovement); foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(typeFromHandle)) { try { if (declaredMethod.Name == "Warp" || declaredMethod.Name == "Warp_Client") { h.Patch((MethodBase)declaredMethod, new HarmonyMethod(typeof(Pins), "WarpPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else if (declaredMethod.Name == "IsNPCPositionValid" && declaredMethod.ReturnType == typeof(bool)) { h.Patch((MethodBase)declaredMethod, new HarmonyMethod(typeof(Pins), "ValidPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } catch { } } try { MethodInfo methodInfo = AccessTools.DeclaredPropertyGetter(typeFromHandle, "Velocity"); if (methodInfo != null) { h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Pins), "VelocityPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } catch { } try { MethodInfo methodInfo2 = AccessTools.DeclaredMethod(typeof(NPCAnimation), "UpdateMovementAnimation", (Type[])null, (Type[])null); if (methodInfo2 != null) { h.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Pins), "AnimPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } catch { } } private static bool WarpPrefix(NPCMovement __instance) { try { return (Object)(object)__instance == (Object)null || !Held.Contains(((Il2CppObjectBase)__instance).Pointer); } catch { return true; } } private static void VelocityPostfix(NPCMovement __instance, ref Vector3 __result) { //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) try { if ((Object)(object)__instance != (Object)null && Held.Contains(((Il2CppObjectBase)__instance).Pointer)) { __result = Vector3.zero; } } catch { } } private static bool AnimPrefix(NPCAnimation __instance) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) try { NPC val = (((Object)(object)__instance != (Object)null) ? __instance.npc : null); if ((Object)(object)val == (Object)null || !IsHeld(val)) { return true; } AvatarAnimation val2 = (((Object)(object)val.Avatar != (Object)null) ? val.Avatar.Animation : null); if ((Object)(object)val2 != (Object)null) { val2.SetMotion(Vector3.zero, false); val2.SetDirection(0f); val2.SetStrafe(0f); } return false; } catch { return true; } } private static bool ValidPrefix(NPCMovement __instance, ref bool __result) { try { if ((Object)(object)__instance == (Object)null || !Held.Contains(((Il2CppObjectBase)__instance).Pointer)) { return true; } __result = true; return false; } catch { return true; } } } internal static class RainCover { private static readonly Dictionary> Shelters = new Dictionary>(); private static readonly List Rain = new List(); private static readonly List Hidden = new List(); private static readonly List HiddenFeatures = new List(); private static bool _scanned; private static bool _inside; private static float _next; public static void Add(string key, Func inside) { if (key != null && inside != null) { Shelters[key] = inside; } } public static void Remove(string key) { if (key != null) { Shelters.Remove(key); } } public static void Update() { //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) if ((Shelters.Count == 0 && !_inside) || Time.unscaledTime < _next) { return; } _next = Time.unscaledTime + 0.2f; Vector3 position; try { PlayerCamera instance = PlayerSingleton.Instance; Transform val = (((Object)(object)instance != (Object)null && (Object)(object)instance.Camera != (Object)null) ? ((Component)instance.Camera).transform : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform : null)); if ((Object)(object)val == (Object)null) { return; } position = val.position; } catch { return; } bool flag = false; foreach (Func value in Shelters.Values) { try { if (value(position)) { flag = true; break; } } catch { } } if (flag != _inside) { _inside = flag; if (flag) { Hide(); } else { Restore(); } } } private static void Hide() { try { if (!_scanned) { _scanned = true; HashSet hashSet = new HashSet(); foreach (RainController item in Object.FindObjectsOfType()) { foreach (Renderer componentsInChild in ((Component)item).GetComponentsInChildren(true)) { if ((Object)(object)componentsInChild != (Object)null && hashSet.Add(((Object)componentsInChild).GetInstanceID())) { Rain.Add(componentsInChild); } } } } foreach (Renderer item2 in Rain) { if ((Object)(object)item2 != (Object)null && item2.enabled) { item2.enabled = false; Hidden.Add(item2); } } RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline; UniversalRenderPipelineAsset val = ((currentRenderPipeline != null) ? ((Il2CppObjectBase)currentRenderPipeline).TryCast() : null); Il2CppReferenceArray val2 = (((Object)(object)val != (Object)null) ? val.m_RendererDataList : null); int num = 0; while (val2 != null && num < ((Il2CppArrayBase)(object)val2).Length) { ScriptableRendererData val3 = ((Il2CppArrayBase)(object)val2)[num]; if (!((Object)(object)val3 == (Object)null) && val3.rendererFeatures != null) { Enumerator enumerator4 = val3.rendererFeatures.GetEnumerator(); while (enumerator4.MoveNext()) { ScriptableRendererFeature current3 = enumerator4.Current; if (!((Object)(object)current3 == (Object)null) && current3.isActive && (((Object)current3).name + " " + ((MemberInfo)((Object)current3).GetIl2CppType()).Name).IndexOf("rain", StringComparison.OrdinalIgnoreCase) >= 0) { current3.SetActive(false); HiddenFeatures.Add(current3); } } } num++; } } catch { } } private static void Restore() { foreach (Renderer item in Hidden) { if ((Object)(object)item != (Object)null) { item.enabled = true; } } Hidden.Clear(); foreach (ScriptableRendererFeature hiddenFeature in HiddenFeatures) { try { if ((Object)(object)hiddenFeature != (Object)null) { hiddenFeature.SetActive(true); } } catch { } } HiddenFeatures.Clear(); } public static void Reset() { Restore(); _inside = false; _scanned = false; Rain.Clear(); Shelters.Clear(); } } internal static class TreeCut { private static readonly Dictionary Clearings = new Dictionary(); private static readonly Dictionary Textures = new Dictionary(); private static readonly List Trunks = new List(); private static bool _dirty; public static void Add(string key, Vector3 centre, float radius) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) if (key != null) { Clearings[key] = (centre, radius); _dirty = true; } } public static void Remove(string key) { if (key != null && Clearings.Remove(key)) { _dirty = true; } } public static void Update() { if (_dirty) { _dirty = false; Apply(); } } private static bool Cleared(float x, float z, float pad) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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) foreach (var value in Clearings.Values) { Vector3 item = value.c; float item2 = value.r; float num = x - item.x; float num2 = z - item.z; float num3 = item2 + pad; if (num * num + num2 * num2 < num3 * num3) { return true; } } return false; } private static void Apply() { //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: Unknown result type (might be due to invalid IL or missing references) int num = 0; int num2 = 0; try { Find(); foreach (KeyValuePair texture in Textures) { var (val, array, num3) = texture.Value; if ((Object)(object)val == (Object)null) { continue; } float[] array2 = new float[array.Length / 4]; Buffer.BlockCopy(array, 0, array2, 0, array.Length); for (int i = 0; i < num3; i++) { int num4 = i * 4; if (!(array2[num4 + 3] <= 0f) && Cleared(array2[num4], array2[num4 + 2], 2.5f)) { array2[num4 + 3] = 0f; num++; } } byte[] array3 = new byte[array.Length]; Buffer.BlockCopy(array2, 0, array3, 0, array3.Length); val.LoadRawTextureData(new Il2CppStructArray(array3)); val.Apply(false, false); } foreach (GameObject trunk in Trunks) { if ((Object)(object)trunk != (Object)null) { trunk.SetActive(true); } } Trunks.Clear(); if (Clearings.Count > 0) { foreach (FoliageRustleSound item in Object.FindObjectsOfType()) { if (!((Object)(object)item == (Object)null) && ((Object)item).name.StartsWith("Tree", StringComparison.OrdinalIgnoreCase)) { Vector3 position = ((Component)item).transform.position; if (Cleared(position.x, position.z, 2.5f)) { ((Component)item).gameObject.SetActive(false); Trunks.Add(((Component)item).gameObject); num2++; } } } } } catch (Exception ex) { FortifyApi.Log("Trees: couldn't clear the lot (" + ex.Message + ")."); return; } if (Clearings.Count > 0) { FortifyApi.Log($"Trees: {num} tree(s) cleared off the lot ({num2} trunk(s))."); } } private static void Find() { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Invalid comparison between Unknown and I4 List list = new List(); try { InstancingManager val = Object.FindObjectOfType(); List val2 = (((Object)(object)val != (Object)null) ? val.BackedInstanceObjects : null); int num = 0; while (val2 != null && num < val2.Count) { if ((Object)(object)val2[num] != (Object)null) { list.Add(val2[num]); } num++; } } catch { } foreach (InstanceObjectData item in list) { try { if ((item.Id ?? "").IndexOf("tree", StringComparison.OrdinalIgnoreCase) < 0) { continue; } Texture2D positionData = item.PositionData; if ((Object)(object)positionData == (Object)null || !((Texture)positionData).isReadable || (int)positionData.format != 20) { continue; } int instanceID = ((Object)positionData).GetInstanceID(); if (!Textures.ContainsKey(instanceID)) { Il2CppStructArray rawTextureData = positionData.GetRawTextureData(); byte[] array = new byte[((Il2CppArrayBase)(object)rawTextureData).Length]; for (int i = 0; i < array.Length; i++) { array[i] = ((Il2CppArrayBase)(object)rawTextureData)[i]; } Textures[instanceID] = (positionData, array, Math.Min(item.InstanceCount, array.Length / 16)); } } catch { } } } public static void Reset() { try { foreach (KeyValuePair texture in Textures) { var (val, array, _) = texture.Value; if (!((Object)(object)val == (Object)null)) { val.LoadRawTextureData(new Il2CppStructArray(array)); val.Apply(false, false); } } } catch { } foreach (GameObject trunk in Trunks) { if ((Object)(object)trunk != (Object)null) { trunk.SetActive(true); } } Trunks.Clear(); Textures.Clear(); Clearings.Clear(); _dirty = false; } } } namespace CounterfeitMod { internal static class Bills { private static string _hint; private static float _hintUntil; private static bool _inBuy; private static ShopInterface _restore; private static EPaymentType _restorePay; public static string Hint { get { if (!(Time.unscaledTime < _hintUntil)) { return null; } return _hint; } } private static void Say(string s, float secs = 4f) { _hint = s; _hintUntil = Time.unscaledTime + secs; } public static void Patch(Harmony h) { //IL_0029: 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_004b: Expected O, but got Unknown //IL_004b: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Expected O, but got Unknown //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Expected O, but got Unknown //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Expected O, but got Unknown try { MethodInfo methodInfo = AccessTools.Method(typeof(Cart), "Buy", (Type[])null, (Type[])null); h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Bills), "BuyPrefix", (Type[])null), new HarmonyMethod(typeof(Bills), "BuyPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception ex) { Instance log = Kit.Log; if (log != null) { log.Warning("Stores won't take fake bills (" + ex.Message + ")."); } } try { h.Patch((MethodBase)AccessTools.Method(typeof(Cart), "CanPlayerAffordCart", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Bills), "AffordPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); h.Patch((MethodBase)AccessTools.Method(typeof(Cart), "CanCheckout", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Bills), "CheckoutPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); h.Patch((MethodBase)AccessTools.Method(typeof(Cart), "UpdateProblem", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Bills), "ProblemPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception ex2) { Instance log2 = Kit.Log; if (log2 != null) { log2.Warning("Fake bills only work when your real money covers the cart (" + ex2.Message + ")."); } } } private static int FakesFor(Cart cart, out bool realOk) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Invalid comparison between Unknown and I4 realOk = true; ShopInterface val = ((cart != null) ? cart.Shop : null); if ((Object)(object)val == (Object)null) { return 0; } PlayerInventory instance = PlayerSingleton.Instance; if ((Object)(object)instance == (Object)null) { return 0; } uint amountOfItem = instance.GetAmountOfItem("cf_bills"); if (amountOfItem == 0) { return 0; } float priceSum = cart.GetPriceSum(); if (priceSum <= 0f) { return 0; } float cashBalance = Money.GetCashBalance(); float num = 0f; try { num = Money.GetOnlineBalance(); } catch { } EPaymentType paymentType = val.PaymentType; realOk = (((int)paymentType == 0) ? (cashBalance >= priceSum) : (((int)paymentType == 1) ? (num >= priceSum) : (cashBalance >= priceSum || num >= priceSum))); int num2 = (int)Math.Min(amountOfItem, (uint)Mathf.CeilToInt(priceSum / 100f)); if (num2 <= 0 || !(cashBalance + (float)num2 * 100f >= priceSum)) { return 0; } return num2; } private static bool RealOk(Cart cart) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 try { ShopInterface val = ((cart != null) ? cart.Shop : null); if ((Object)(object)val == (Object)null) { return true; } float priceSum = cart.GetPriceSum(); float cashBalance = Money.GetCashBalance(); float num = 0f; try { num = Money.GetOnlineBalance(); } catch { } EPaymentType paymentType = val.PaymentType; return ((int)paymentType == 0) ? (cashBalance >= priceSum) : (((int)paymentType == 1) ? (num >= priceSum) : (cashBalance >= priceSum || num >= priceSum)); } catch { return true; } } private static void AffordPostfix(Cart __instance, ref bool __result) { if (__result || _inBuy) { return; } try { if (FakesFor(__instance, out var realOk) > 0 && !realOk) { __result = true; } } catch { } } private static void CheckoutPostfix(Cart __instance, ref bool __result, ref string reason) { if (__result || _inBuy) { return; } try { if (FakesFor(__instance, out var realOk) > 0 && !realOk) { __result = true; reason = string.Empty; } } catch { } } private static void ProblemPostfix(Cart __instance) { if (_inBuy) { return; } try { bool realOk; int num = FakesFor(__instance, out realOk); if (!(num <= 0 || realOk)) { if ((Object)(object)__instance.buyButton != (Object)null) { ((Selectable)__instance.buyButton).interactable = true; } if ((Object)(object)__instance.ProblemText != (Object)null) { ((TMP_Text)__instance.ProblemText).text = string.Empty; } if ((Object)(object)__instance.WarningText != (Object)null) { ((TMP_Text)__instance.WarningText).text = $"Paying with {num} fake $100{((num == 1) ? "" : "s")}"; ((Component)__instance.WarningText).gameObject.SetActive(true); } } } catch { } } public static float CatchChance(int bills) { return Mathf.Clamp01(Mathf.Min(0.4f, 0.05f + 0.025f * (float)bills) * Mathf.Max(0f, PressCore.CatchChance?.Value ?? 1f)); } private static bool BuyPrefix(Cart __instance) { //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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Invalid comparison between Unknown and I4 //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) _inBuy = true; try { ShopInterface shop = __instance.Shop; if ((Object)(object)shop == (Object)null) { return true; } EPaymentType paymentType = shop.PaymentType; if (FortifyApi.DevKeys) { Instance log = Kit.Log; if (log != null) { log.Msg($"Fake bills: {shop.ShopName} takes {paymentType}."); } } PlayerInventory instance = PlayerSingleton.Instance; if ((Object)(object)instance == (Object)null) { return true; } uint amountOfItem = instance.GetAmountOfItem("cf_bills"); if (amountOfItem == 0) { return true; } float priceSum = __instance.GetPriceSum(); if (priceSum <= 0f) { return true; } int num = (int)Math.Min(amountOfItem, (uint)Mathf.CeilToInt(priceSum / 100f)); float cashBalance = Money.GetCashBalance(); if (num <= 0 || cashBalance + (float)num * 100f < priceSum) { return true; } Money.ChangeCashBalance((float)num * 100f, false, false); if ((int)paymentType != 0 && (int)paymentType != 2) { _restore = shop; _restorePay = paymentType; shop.PaymentType = (EPaymentType)2; } string text = default(string); if (!__instance.CanCheckout(ref text)) { Money.ChangeCashBalance((float)(-num) * 100f, false, false); Restore(); if (!RealOk(__instance)) { Say(string.IsNullOrEmpty(text) ? "The store can't take this order." : text); _inBuy = false; return false; } return true; } instance.RemoveAmountOfItem("cf_bills", (uint)num); float num2 = CatchChance(num); if (Random.value < num2) { Money.ChangeCashBalance((float)(-num) * 100f, false, false); Restore(); Caught(shop, num); _inBuy = false; return false; } float num3 = (float)num * 100f - priceSum; string text2 = $"{num} fake $100{((num == 1) ? "" : "s")}"; Say((num3 >= 0.5f) ? $"Paid with {text2}. ${num3:N0} change in real cash." : ((num3 > -0.5f) ? ("Paid with " + text2 + ".") : $"Paid with {text2} and ${0f - num3:N0} of your own.")); Instance log2 = Kit.Log; if (log2 != null) { log2.Msg($"Fake bills: {num} passed at {shop.ShopName} for a ${priceSum:N0} sale ({num2 * 100f:0}% chance of being caught)."); } return true; } catch (Exception ex) { Restore(); Instance log3 = Kit.Log; if (log3 != null) { log3.Warning("Fake bills: " + ex.Message); } return true; } } private static void Restore() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_restore == (Object)null)) { try { _restore.PaymentType = _restorePay; } catch { } _restore = null; } } private static void BuyPostfix() { _inBuy = false; Restore(); } private static void Caught(ShopInterface shop, int n) { //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown string value = ((shop != null) ? shop.ShopName : null) ?? "the store"; FortifyApi.Notify("Counterfeit Press", $"The clerk at {value} spotted a fake $100 and called the police. They kept {((n == 1) ? "it" : $"all {n}")}."); Say("The clerk spotted a fake bill. The police are on their way.", 5f); Instance log = Kit.Log; if (log != null) { log.Msg($"Fake bills: caught at {value} with {n}."); } try { if (shop != null) { Cart cart = shop.Cart; if (cart != null) { cart.ClearCart(); } } } catch { } try { if (shop != null) { shop.Close(); } } catch { } try { Player local = Player.Local; LawManager val = Object.FindObjectOfType(); if ((Object)(object)local != (Object)null && (Object)(object)val != (Object)null) { val.PoliceCalled(local, (Crime)new Theft()); } } catch (Exception ex) { Instance log2 = Kit.Log; if (log2 != null) { log2.Warning("Fake bills: couldn't call the police (" + ex.Message + ")."); } } } public static void DevGive(int n) { PlayerInventory instance = PlayerSingleton.Instance; ItemDefinition item = Registry.GetItem("cf_bills"); ItemInstance val = ((item != null) ? item.GetDefaultInstance(n) : null); if ((Object)(object)instance != (Object)null && val != null && instance.CanItemFitInInventory(val, n)) { instance.AddItemToInventory(val); } } public static void DevOpenShop() { //IL_008e: Unknown result type (might be due to invalid IL or missing references) Enumerator enumerator = ShopInterface.AllShops.GetEnumerator(); while (enumerator.MoveNext()) { ShopInterface current = enumerator.Current; if ((Object)(object)current != (Object)null && current.ShopName == "Dan's Hardware") { if (FortifyApi.KeyHeld((KeyCode)304)) { current.PaymentType = (EPaymentType)0; } current.SetIsOpen(true); Instance log = Kit.Log; if (log != null) { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(40, 4); defaultInterpolatedStringHandler.AppendLiteral("Dev: "); defaultInterpolatedStringHandler.AppendFormatted(current.ShopName); defaultInterpolatedStringHandler.AppendLiteral(" open (takes "); defaultInterpolatedStringHandler.AppendFormatted(current.PaymentType); defaultInterpolatedStringHandler.AppendLiteral("); cash "); defaultInterpolatedStringHandler.AppendFormatted(Money.GetCashBalance(), "N0"); defaultInterpolatedStringHandler.AppendLiteral(", fake bills "); PlayerInventory instance = PlayerSingleton.Instance; defaultInterpolatedStringHandler.AppendFormatted((instance != null) ? new uint?(instance.GetAmountOfItem("cf_bills")) : ((uint?)null)); defaultInterpolatedStringHandler.AppendLiteral("."); log.Msg(defaultInterpolatedStringHandler.ToStringAndClear()); } return; } } Instance log2 = Kit.Log; if (log2 != null) { log2.Msg("Dev: Dan's Hardware not found."); } } public static void DevBuy() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) ShopInterface val = null; Enumerator enumerator = ShopInterface.AllShops.GetEnumerator(); while (enumerator.MoveNext()) { ShopInterface current = enumerator.Current; if (!((Object)(object)current == (Object)null)) { if (current.ShopName == "Dan's Hardware") { val = current; break; } if ((Object)(object)val == (Object)null && (int)current.PaymentType == 0) { val = current; } } } if ((Object)(object)val == (Object)null) { Instance log = Kit.Log; if (log != null) { log.Msg("Dev: no cash store found."); } return; } ShopListing val2 = null; Enumerator enumerator2 = val.Listings.GetEnumerator(); while (enumerator2.MoveNext()) { ShopListing current2 = enumerator2.Current; if (current2 != null && current2.Price > 0f && (val2 == null || current2.Price < val2.Price)) { val2 = current2; } } if (val2 != null) { float cashBalance = Money.GetCashBalance(); PlayerInventory instance = PlayerSingleton.Instance; uint value = ((instance != null) ? instance.GetAmountOfItem("cf_bills") : 0u); val.Cart.ClearCart(); val.Cart.AddItem(val2, 1); val.Cart.Buy(); val.Cart.ClearCart(); float cashBalance2 = Money.GetCashBalance(); PlayerInventory instance2 = PlayerSingleton.Instance; uint value2 = ((instance2 != null) ? instance2.GetAmountOfItem("cf_bills") : 0u); Instance log2 = Kit.Log; if (log2 != null) { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(49, 7); defaultInterpolatedStringHandler.AppendLiteral("Dev: bought "); StorableItemDefinition item = val2.Item; defaultInterpolatedStringHandler.AppendFormatted((item != null) ? ((BaseItemDefinition)item).Name : null); defaultInterpolatedStringHandler.AppendLiteral(" ($"); defaultInterpolatedStringHandler.AppendFormatted(val2.Price, "N0"); defaultInterpolatedStringHandler.AppendLiteral(") at "); defaultInterpolatedStringHandler.AppendFormatted(val.ShopName); defaultInterpolatedStringHandler.AppendLiteral(". Cash "); defaultInterpolatedStringHandler.AppendFormatted(cashBalance, "N0"); defaultInterpolatedStringHandler.AppendLiteral(" -> "); defaultInterpolatedStringHandler.AppendFormatted(cashBalance2, "N0"); defaultInterpolatedStringHandler.AppendLiteral(", fake bills "); defaultInterpolatedStringHandler.AppendFormatted(value); defaultInterpolatedStringHandler.AppendLiteral(" -> "); defaultInterpolatedStringHandler.AppendFormatted(value2); defaultInterpolatedStringHandler.AppendLiteral("."); log2.Msg(defaultInterpolatedStringHandler.ToStringAndClear()); } } } } public sealed class PressCore : MelonMod { internal const string PressId = "cf_press"; internal const string PaperId = "cf_paper"; internal const string BillsId = "cf_bills"; internal static MelonPreferences_Entry CatchChance; internal static MelonPreferences_Entry PrintMinutes; internal static MelonPreferences_Entry BillsPerSheet; private static MelonPreferences_Entry _price; private static float _warnedAt = -100f; public override void OnInitializeMelon() { //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) try { Host.Init((MelonMod)(object)this, "CounterfeitPress", "Counterfeit Press", "cf_", null, null, Presses.Reset); MelonPreferences_Category category = MelonPreferences.GetCategory("CounterfeitPress"); _price = category.CreateEntry("PriceMultiplier", 1f, "Price multiplier", "Multiplies the shop prices (1 = normal, 0 = free). Applies after a game restart.", false, false, (ValueValidator)null, (string)null); CatchChance = category.CreateEntry("CatchChance", 1f, "Chance of getting caught", "Multiplies the chance a clerk spots your fake bills (1 = normal, 0 = never, 2 = twice as often).", false, false, (ValueValidator)null, (string)null); PrintMinutes = category.CreateEntry("PrintMinutes", 60f, "Printing time (game minutes)", "How long the press takes to print one ream of banknote paper.", false, false, (ValueValidator)null, (string)null); BillsPerSheet = category.CreateEntry("BillsPerReam", 10, "Bills per ream", "How many fake $100 bills one ream of banknote paper makes.", false, false, (ValueValidator)null, (string)null); Kit.PriceMultiplier = () => _price?.Value ?? 1f; FortifyApi.SetNotifyIcon("cf_bills"); Catalog.Add(new ItemSpec { Id = "cf_press", Name = "Counterfeit Press", Kind = PlaceKind.Ground, Price = 6500f, RotateStep = 90f, StackLimit = 2, IconColor = new Color(0.25f, 0.4f, 0.35f), BuildModel = PressModel.Press, FitLift = 0.2f, Description = "An offset press on a work table, with a cutter, a UV lamp and a drying line. Load banknote paper and it prints fake $100 bills, ten to a ream. Press E to load it and to take the bills." }); Catalog.Add(new ItemSpec { Id = "cf_paper", Name = "Banknote Paper", Kind = PlaceKind.Ground, Price = 60f, RotateStep = 0f, StackLimit = 20, IconColor = new Color(0.85f, 0.84f, 0.78f), BuildModel = PressModel.Paper, Description = "A ream of cotton banknote paper. Load it into a Counterfeit Press: one ream prints ten fake $100 bills." }); Catalog.Add(new ItemSpec { Id = "cf_bills", Name = "Fake $100 Bill", Kind = PlaceKind.Ground, Price = 1f, RotateStep = 0f, StackLimit = 50, NotSold = true, IconColor = new Color(0.3f, 0.45f, 0.28f), BuildModel = PressModel.Bills, Description = "A fake $100 bill, fresh off your press. Stores take them like cash and give you real change, but now and then a clerk spots one and calls the police." }); Kit.Use["cf_press"] = Presses.TryUse; Kit.Created += Presses.OnCreated; Kit.Removed += Presses.OnRemoved; Kit.CanPickUp = (Placement.Placed p) => p?.Spec?.Id != "cf_press" || Presses.CanPickUp(p); Kit.CustomPlace["cf_paper"] = Holding; Kit.CustomPlace["cf_bills"] = Holding; Bills.Patch(((MelonBase)this).HarmonyInstance); Host.Ok = true; ((MelonBase)this).LoggerInstance.Msg("Counterfeit Press loaded. The press and banknote paper are at Dan's Hardware and Handy Hank's Hardware."); } catch (Exception ex) { ((MelonBase)this).LoggerInstance.Error("Counterfeit Press couldn't start: " + ex.Message + ". It needs MelonLoader 0.7 and S1API (Bars fork) 3.2.3 or newer."); } } private static bool Holding(ItemSpec s, Camera cam, Player pl, out string hint) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) hint = null; if (Placement.Aim(cam, 3.5f, pl, out var best)) { Placement.Placed placed = Placement.FindPlaced(((RaycastHit)(ref best)).collider); if (placed != null && placed.Spec.Id == "cf_press" && Presses.TryUse(placed, best, out hint)) { return true; } } hint = ((s.Id == "cf_paper") ? "Banknote Paper: look at a Counterfeit Press and press E to load it." : "Fake $100s: pay with them at any store and get real change. Clerks don't always fall for it."); return true; } public override void OnUpdate() { if (!Host.Update()) { return; } try { Presses.Update(); if (FortifyApi.DevKeys && (FortifyApi.KeyHeld((KeyCode)306) || FortifyApi.KeyHeld((KeyCode)305))) { if (FortifyApi.KeyDown((KeyCode)121)) { Placement.DevGive(); Bills.DevGive(20); } if (FortifyApi.KeyDown((KeyCode)117)) { Presses.DevHour(); } if (FortifyApi.KeyDown((KeyCode)105)) { Bills.DevBuy(); } if (FortifyApi.KeyDown((KeyCode)111)) { Bills.DevOpenShop(); } } } catch (Exception ex) { if (Time.unscaledTime - _warnedAt > 30f) { _warnedAt = Time.unscaledTime; ((MelonBase)this).LoggerInstance.Warning("Counterfeit Press: " + ex.Message); } } } public override void OnGUI() { if (Host.Ok && FortifyApi.InGame) { if (Placement.Hint == null && Bills.Hint != null) { FortifyApi.Hint(Bills.Hint); } else { Host.DrawHint(); } } } } internal static class Presses { private sealed class Press { public Placement.Placed P; public int Paper; public int Out; public double Start = -1.0; public Transform Rollers; public Transform PaperStack; public Transform OutStack; public Transform[] RollerParts; public Transform[] Sheets; public Renderer Lamp; public Material LampOn; public bool ShownOn; } private const int MaxPaper = 5; private const int MaxOut = 100; private static readonly List All = new List(); private static float _next; private static double Now { get { try { return (double)TimeManager.ElapsedDays * 1440.0 + (double)TimeManager.GetMinutesFrom24HourTime(TimeManager.CurrentTime); } catch { return -1.0; } } } private static float Minutes => Mathf.Max(1f, PressCore.PrintMinutes?.Value ?? 60f); private static int PerReam => Mathf.Clamp(PressCore.BillsPerSheet?.Value ?? 10, 1, 50); public static void Reset() { All.Clear(); } public static void OnCreated(Placement.Placed p) { if (p?.Spec?.Id != "cf_press" || (Object)(object)p.Go == (Object)null) { return; } Press press = new Press { P = p }; string[] array = (p.Text ?? "").Split('|'); if (array.Length >= 3) { int.TryParse(array[0], out press.Paper); double.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out press.Start); int.TryParse(array[2], out press.Out); } press.Rollers = Find(p.Go.transform, "Rollers"); press.PaperStack = Find(p.Go.transform, "PaperStack"); press.OutStack = Find(p.Go.transform, "OutStack"); if ((Object)(object)press.Rollers != (Object)null) { List list = new List(); for (int i = 0; i < press.Rollers.childCount; i++) { list.Add(press.Rollers.GetChild(i)); } press.RollerParts = list.ToArray(); } if ((Object)(object)press.OutStack != (Object)null) { List list2 = new List(); for (int j = 0; j < press.OutStack.childCount; j++) { list2.Add(press.OutStack.GetChild(j)); } press.Sheets = list2.ToArray(); } Transform val = Find(p.Go.transform, "Lamp"); if ((Object)(object)val != (Object)null) { press.Lamp = ((Component)val).GetComponent(); if ((Object)(object)press.Lamp != (Object)null) { press.LampOn = press.Lamp.sharedMaterial; } } p.State = press; All.Add(press); Show(press); } public static void OnRemoved(Placement.Placed p) { if (p?.State is Press item) { All.Remove(item); } } public static bool CanPickUp(Placement.Placed p) { if (p?.State is Press press) { if (press.Paper == 0) { return press.Out == 0; } return false; } return true; } private static Transform Find(Transform t, string name) { if ((Object)(object)t == (Object)null) { return null; } if (((Object)t).name == name) { return t; } for (int i = 0; i < t.childCount; i++) { Transform val = Find(t.GetChild(i), name); if ((Object)(object)val != (Object)null) { return val; } } return null; } private static void Store(Press pr) { pr.P.Text = $"{pr.Paper}|{pr.Start.ToString(CultureInfo.InvariantCulture)}|{pr.Out}"; Placement.UpdateRecord(pr.P); } private static bool Printing(Press pr) { if (pr.Paper > 0) { return pr.Out + PerReam <= 100; } return false; } private static float Progress(Press pr) { if (!Printing(pr) || pr.Start < 0.0) { return 0f; } double now = Now; if (!(now < 0.0)) { return Mathf.Clamp01((float)((now - pr.Start) / (double)Minutes)); } return 0f; } public static bool TryUse(Placement.Placed p, RaycastHit hit, out string hint) { //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) hint = null; if (!(p.State is Press press)) { return false; } PlayerInventory instance = PlayerSingleton.Instance; uint num = 0u; try { num = (((Object)(object)instance != (Object)null) ? instance.GetAmountOfItem("cf_paper") : 0u); } catch { } string value = (Printing(press) ? $"printing, {Progress(press) * 100f:0}%" : ((press.Out + PerReam > 100) ? "the tray is full" : "idle")); string value2 = ((press.Paper > 0) ? $", {press.Paper} ream{((press.Paper == 1) ? "" : "s")} loaded" : ""); string value3 = ((press.Out > 0) ? $", {press.Out} bills ready" : ""); string value4 = ((press.Out > 0) ? $"[{FortifyApi.UseKey}] Take the fake $100s" : ((num != 0 && press.Paper < 5) ? $"[{FortifyApi.UseKey}] Load banknote paper ({num} on you)" : ((press.Paper != 0) ? "" : "Needs banknote paper (Dan's Hardware)"))); string value5 = (CanPickUp(p) ? " [Hold Right Click] Pick up" : ""); hint = $"Counterfeit Press: {value}{value2}{value3} {value4}{value5}"; if (FortifyApi.KeyDown(FortifyApi.UseKey)) { if (press.Out > 0) { Collect(press); } else if (num != 0 && press.Paper < 5) { Load(press, instance, num); } } return true; } private static void Load(Press pr, PlayerInventory inv, uint have) { int num = (int)Math.Min(have, (uint)(5 - pr.Paper)); if (num > 0) { inv.RemoveAmountOfItem("cf_paper", (uint)num); if (pr.Paper == 0 || pr.Start < 0.0) { pr.Start = Now; } pr.Paper += num; Store(pr); Show(pr); } } private static void Collect(Press pr) { PlayerInventory instance = PlayerSingleton.Instance; ItemDefinition item = Registry.GetItem("cf_bills"); if ((Object)(object)instance == (Object)null || (Object)(object)item == (Object)null) { return; } int num = 0; while (pr.Out > 0) { int num2 = Mathf.Min(pr.Out, 50); ItemInstance defaultInstance = item.GetDefaultInstance(num2); if (defaultInstance == null || !instance.CanItemFitInInventory(defaultInstance, num2)) { break; } instance.AddItemToInventory(defaultInstance); pr.Out -= num2; num += num2; } if (num == 0) { FortifyApi.Notify("Counterfeit Press", "No room in your pockets for the bills."); return; } if (pr.Start >= 0.0 && pr.Paper > 0 && !Printing(pr)) { pr.Start = Now; } Store(pr); Show(pr); } public static void Update() { //IL_0065: Unknown result type (might be due to invalid IL or missing references) float deltaTime = Time.deltaTime; foreach (Press item in All) { if ((Object)(object)item.P?.Go == (Object)null || item.RollerParts == null || !Printing(item)) { continue; } Transform[] rollerParts = item.RollerParts; foreach (Transform val in rollerParts) { if ((Object)(object)val != (Object)null) { val.Rotate(Vector3.right, 220f * deltaTime, (Space)1); } } } if (Time.unscaledTime < _next) { return; } _next = Time.unscaledTime + 1f; double now = Now; if (now < 0.0) { return; } foreach (Press item2 in All) { if (!((Object)(object)item2.P?.Go == (Object)null)) { bool flag = false; if (item2.Paper > 0 && item2.Start < 0.0) { item2.Start = now; flag = true; } while (Printing(item2) && item2.Start >= 0.0 && now - item2.Start >= (double)Minutes) { item2.Paper--; item2.Out += PerReam; item2.Start += Minutes; flag = true; } if (item2.Paper == 0 && item2.Start >= 0.0) { item2.Start = -1.0; flag = true; } if (item2.Paper > 0 && !Printing(item2) && item2.Start >= 0.0 && now - item2.Start > (double)Minutes) { item2.Start = now; flag = true; } if (flag) { Store(item2); Show(item2); } else if (item2.ShownOn != Printing(item2)) { Show(item2); } } } } private static void Show(Press pr) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) bool flag = (pr.ShownOn = Printing(pr)); if ((Object)(object)pr.Lamp != (Object)null) { pr.Lamp.sharedMaterial = ((flag && (Object)(object)pr.LampOn != (Object)null) ? pr.LampOn : PressModel.LampOff); } if ((Object)(object)pr.PaperStack != (Object)null) { ((Component)pr.PaperStack).gameObject.SetActive(pr.Paper > 0); Vector3 localScale = pr.PaperStack.localScale; pr.PaperStack.localScale = new Vector3(localScale.x, Mathf.Max(0.15f, (float)pr.Paper / 5f), localScale.z); } if (pr.Sheets == null) { return; } int num = ((pr.Out > 0) ? Mathf.Clamp(Mathf.CeilToInt((float)pr.Out / (100f / (float)pr.Sheets.Length)), 1, pr.Sheets.Length) : 0); for (int i = 0; i < pr.Sheets.Length; i++) { if ((Object)(object)pr.Sheets[i] != (Object)null) { ((Component)pr.Sheets[i]).gameObject.SetActive(i < num); } } } public static void DevHour() { foreach (Press item in All) { if (item.Start >= 0.0) { item.Start -= Minutes; } } _next = 0f; Instance log = Kit.Log; if (log != null) { log.Msg("Dev: an hour of printing."); } } } internal static class PressModel { private static readonly HashSet Fixed = new HashSet(); public static Material LampOff => FortifyApi.Mat("cf_lamp_off", new Color(0.25f, 0.2f, 0.15f), 0f, 0.5f); private static GameObject Load(string name, string file) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); ((Object)GltfLoader.LoadEmbedded(file, val.transform)).name = "Model"; foreach (Renderer componentsInChild in val.GetComponentsInChildren(true)) { foreach (Material item in (Il2CppArrayBase)(object)componentsInChild.sharedMaterials) { if (!((Object)(object)item == (Object)null) && Fixed.Add(((Object)item).GetInstanceID())) { Color color = item.color; Color val2 = (item.color = ((Color)(ref color)).gamma); if (item.HasProperty("_BaseColor")) { item.SetColor("_BaseColor", val2); } if (item.HasProperty("_EmissionColor") && item.IsKeywordEnabled("_EMISSION")) { color = item.GetColor("_EmissionColor"); item.SetColor("_EmissionColor", ((Color)(ref color)).gamma); } } } } return val; } public static GameObject Press() { //IL_002a: 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_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) GameObject obj = Load("cf_Press", "CF_Press.glb"); Transform transform = obj.transform; Box(transform, "Table", new Vector3(0f, 0.43f, 0f), new Vector3(1.7f, 0.86f, 0.75f)); Box(transform, "Body", new Vector3(0.05f, 1.08f, 0.05f), new Vector3(0.9f, 0.46f, 0.52f)); Box(transform, "Line", new Vector3(0f, 1.3f, 0.34f), new Vector3(1.7f, 0.9f, 0.06f)); return obj; } public static GameObject Paper() { return Load("cf_Paper", "CF_Paper.glb"); } public static GameObject Bills() { return Load("cf_Bills", "CF_Bills.glb"); } private static void Box(Transform parent, string name, Vector3 c, Vector3 size) { //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_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("CF_" + name); val.transform.SetParent(parent, false); val.transform.localPosition = c; val.AddComponent().size = size; } } }