Some mods target the Mono version of the game, which is available by opting into the Steam beta branch "alternate"
Decompiled source of Sell Property v1.1.3
Mods/WoodStudios.SellProperty.dll
Decompiled an hour ago
The result has been truncated due to the large size, download it to view full contents!
using System; 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 FybCommon; using HarmonyLib; using HoldTheFort; using Il2CppFishNet; using Il2CppFishNet.Object; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppScheduleOne; using Il2CppScheduleOne.AvatarFramework; using Il2CppScheduleOne.AvatarFramework.Animation; using Il2CppScheduleOne.Core.Items.Framework; using Il2CppScheduleOne.DevUtilities; using Il2CppScheduleOne.Employees; using Il2CppScheduleOne.EntityFramework; using Il2CppScheduleOne.Instancing; using Il2CppScheduleOne.ItemFramework; using Il2CppScheduleOne.Map; using Il2CppScheduleOne.NPCs; using Il2CppScheduleOne.Networking; using Il2CppScheduleOne.Persistence; using Il2CppScheduleOne.PlayerScripts; using Il2CppScheduleOne.Property; using Il2CppScheduleOne.Storage; using Il2CppScheduleOne.UI; using Il2CppScheduleOne.Variables; using Il2CppScheduleOne.Vehicles; using Il2CppScheduleOne.Weather; using Il2CppSteamworks; using Il2CppSystem; using Il2CppSystem.Collections.Generic; using Il2CppSystem.Reflection; using MelonLoader; using MelonLoader.Preferences; using MelonLoader.Utils; using Microsoft.CodeAnalysis; using S1API.Lifecycle; using S1API.Money; using S1API.PhoneApp; using S1API.UI; using S1API.Utils; using SellProperty; using UnityEngine; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(SellCore), "Sell Property", "1.1.3", "Wood Studios", null)] [assembly: MelonGame("TVGS", "Schedule I")] [assembly: MelonOptionalDependencies(new string[] { "HoldTheFort" })] [assembly: AssemblyCompany("WoodStudios.SellProperty")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("WoodStudios.SellProperty")] [assembly: AssemblyTitle("WoodStudios.SellProperty")] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace SellProperty { internal static class Cars { public sealed class CarQuote { public LandVehicle Veh; public string Id; public string Name; public int Paid; public int Price; public int Stored; public bool Occupied; } private const string RequestKey = "SellProperty_SellCar"; private static float _next; public static List<LandVehicle> Owned() { List<LandVehicle> list = new List<LandVehicle>(); try { VehicleManager instance = NetworkSingleton<VehicleManager>.Instance; List<LandVehicle> val = ((instance != null) ? instance.PlayerOwnedVehicles : null); int num = 0; while (val != null && num < val.Count) { LandVehicle val2 = val[num]; if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).gameObject != (Object)null && val2.IsPlayerOwned && !list.Contains(val2)) { list.Add(val2); } num++; } } catch { } return list; } public static string IdOf(LandVehicle v) { //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) try { return ((object)v.GUID/*cast due to .constrained prefix*/).ToString(); } catch { return null; } } public static CarQuote Price(LandVehicle v) { CarQuote carQuote = new CarQuote { Veh = v, Id = IdOf(v) }; try { carQuote.Name = v.VehicleName; } catch { } if (string.IsNullOrEmpty(carQuote.Name)) { carQuote.Name = "Your car"; } try { carQuote.Paid = Mathf.RoundToInt(v.VehiclePrice); } catch { } carQuote.Price = Mathf.RoundToInt((float)carQuote.Paid * Mathf.Clamp01(Realty.Share())); try { carQuote.Occupied = v.IsOccupied; } catch { } try { StorageEntity storage = v.Storage; List<ItemSlot> val = ((storage != null) ? storage.ItemSlots : null); int num = 0; while (val != null && num < val.Count) { ItemSlot obj4 = val[num]; if (((obj4 != null) ? obj4.ItemInstance : null) != null) { carQuote.Stored += Math.Max(1, val[num].Quantity); } num++; } } catch { } return carQuote; } public static string Sell(LandVehicle v) { if ((Object)(object)v == (Object)null || (Object)(object)((Component)v).gameObject == (Object)null) { return "That car is gone already."; } CarQuote carQuote = Price(v); if (carQuote.Occupied) { return "Get everyone out of the " + carQuote.Name + " first."; } if (carQuote.Stored > 0) { return $"Empty the {carQuote.Name}'s trunk first ({carQuote.Stored} item(s) still inside)."; } if (FortifyApi.IsGuest) { if (carQuote.Id == null) { return "Couldn't sell that car."; } FortifyApi.SendRequest("SellProperty_SellCar", carQuote.Id); return "Asked the host to sell the " + carQuote.Name + "."; } return SellNow(v, carQuote); } private static string SellNow(LandVehicle v, CarQuote q) { try { VehicleManager instance = NetworkSingleton<VehicleManager>.Instance; try { if (instance != null) { instance.PlayerOwnedVehicles?.Remove(v); } } catch { } bool flag = false; try { v.DestroyVehicle(); flag = true; } catch (Exception ex) { Realty.Warn("Car sale: " + ex.Message); } if (!flag) { try { if (InstanceFinder.IsServer && (Object)(object)((NetworkBehaviour)v).NetworkObject != (Object)null) { InstanceFinder.ServerManager.Despawn(((NetworkBehaviour)v).NetworkObject, (Nullable<DespawnType>)null); flag = true; } } catch (Exception ex2) { Realty.Warn("Car sale (despawn): " + ex2.Message); } } if (!flag) { try { if (instance != null) { instance.PlayerOwnedVehicles?.Add(v); } } catch { } return "Couldn't sell the " + q.Name + "."; } try { if (instance != null) { instance.AllVehicles?.Remove(v); } } catch { } } catch (Exception ex3) { return "Couldn't sell the " + q.Name + ": " + ex3.Message; } try { Money.CreateOnlineTransaction("Sold " + q.Name, (float)q.Price, 1f, "Sold your " + q.Name); } catch (Exception ex4) { Realty.Warn("Couldn't pay for the " + q.Name + ": " + ex4.Message); } Realty.Log($"Sold the {q.Name} for ${q.Price:N0}."); try { FortifyApi.Notify("Car sold", $"{q.Name}: ${q.Price:N0} paid into your bank account."); } catch { } return $"Sold the {q.Name}. ${q.Price:N0} went into your bank account."; } public static void Update() { if (FortifyApi.IsGuest || Time.unscaledTime < _next) { return; } _next = Time.unscaledTime + 0.5f; foreach (string item in FortifyApi.TakeRequests("SellProperty_SellCar")) { foreach (LandVehicle item2 in Owned()) { if (IdOf(item2) == item) { CarQuote carQuote = Price(item2); if (!carQuote.Occupied && carQuote.Stored == 0) { SellNow(item2, carQuote); } break; } } } } } internal static class Realty { public sealed class Quote { public Property Prop; public string Name; public float Paid; public float Price; public float Equipment; public float Laundering; public int Items; public int Workers; public int Stored; public float Total => Price + Equipment; } public const string DataKey = "SoldProperties"; public static Func<float> Share = () => 0.75f; public static Action<string> Log = delegate { }; public static Action<string> Warn = delegate { }; public static bool ShowApp = true; public static bool ShowProperties = true; private static readonly List<string> Sold = new List<string>(); private static bool _ready; private static float _nextCheck; public static List<Property> Sellable() { List<Property> list = new List<Property>(); try { List<Property> ownedProperties = Property.OwnedProperties; int num = 0; while (ownedProperties != null && num < ownedProperties.Count) { Property val = ownedProperties[num]; if (!((Object)(object)val == (Object)null) && !val.OwnedByDefault && !(val.Price <= 0f)) { list.Add(val); } num++; } } catch (Exception ex) { Warn("Couldn't list your properties: " + ex.Message); } list.Sort((Property a, Property b) => string.Compare(Name(a), Name(b), StringComparison.OrdinalIgnoreCase)); return list; } public static string Name(Property p) { try { string propertyName = p.PropertyName; return string.IsNullOrWhiteSpace(propertyName) ? p.PropertyCode : propertyName; } catch { return "Property"; } } private static Property ByCode(string code) { try { List<Property> properties = Property.Properties; int num = 0; while (properties != null && num < properties.Count) { if ((Object)(object)properties[num] != (Object)null && string.Equals(properties[num].PropertyCode, code, StringComparison.OrdinalIgnoreCase)) { return properties[num]; } num++; } } catch { } return null; } public static Quote Price(Property p, bool countStored = false) { float num = Mathf.Clamp(Share(), 0f, 1f); Quote quote = new Quote { Prop = p, Name = Name(p), Paid = p.Price }; quote.Price = Mathf.Round(p.Price * num); float num2 = 0f; try { List<BuildableItem> buildableItems = p.BuildableItems; int num3 = 0; while (buildableItems != null && num3 < buildableItems.Count) { BuildableItem val = buildableItems[num3]; if (!((Object)(object)val == (Object)null) && !val.IsDestroyed) { quote.Items++; try { ItemInstance itemInstance = val.ItemInstance; object obj; if (itemInstance == null) { obj = null; } else { ItemDefinition definition = itemInstance.Definition; obj = ((definition != null) ? ((Il2CppObjectBase)definition).TryCast<StorableItemDefinition>() : null); } StorableItemDefinition val2 = (StorableItemDefinition)obj; if ((Object)(object)val2 != (Object)null) { num2 += val2.BasePurchasePrice; } } catch { } if (countStored) { quote.Stored += Stored(((Component)val).gameObject); } } num3++; } } catch { } quote.Equipment = Mathf.Round(num2 * num); try { quote.Workers = ((p.Employees != null) ? p.Employees.Count : 0); } catch { } try { Business val3 = ((Il2CppObjectBase)p).TryCast<Business>(); if (((val3 != null) ? val3.LaunderingOperations : null) != null) { for (int i = 0; i < val3.LaunderingOperations.Count; i++) { float laundering = quote.Laundering; LaunderingOperation obj5 = val3.LaunderingOperations[i]; quote.Laundering = laundering + ((obj5 != null) ? obj5.amount : 0f); } } } catch { } return quote; } private static int Stored(GameObject go) { int num = 0; try { HashSet<IntPtr> hashSet = new HashSet<IntPtr>(); foreach (MonoBehaviour componentsInChild in go.GetComponentsInChildren<MonoBehaviour>(true)) { IItemSlotOwner val = (((Object)(object)componentsInChild != (Object)null) ? ((Il2CppObjectBase)componentsInChild).TryCast<IItemSlotOwner>() : null); if (val == null || !hashSet.Add(((Il2CppObjectBase)val).Pointer)) { continue; } List<ItemSlot> itemSlots = val.ItemSlots; int num2 = 0; while (itemSlots != null && num2 < itemSlots.Count) { if (itemSlots[num2] != null) { num += Mathf.Max(0, itemSlots[num2].Quantity); } num2++; } } } catch { } return num; } public static string Sell(Property p) { if ((Object)(object)p == (Object)null || !p.IsOwned) { return "You don't own that place any more."; } if (!FortifyApi.IsHost) { return "Only the host can sell properties."; } Quote quote = Price(p); string name = quote.Name; try { Business val = ((Il2CppObjectBase)p).TryCast<Business>(); if (((val != null) ? val.LaunderingOperations : null) != null) { List<LaunderingOperation> list = new List<LaunderingOperation>(); for (int i = 0; i < val.LaunderingOperations.Count; i++) { if (val.LaunderingOperations[i] != null) { list.Add(val.LaunderingOperations[i]); } } foreach (LaunderingOperation item in list) { try { val.CompleteOperation(item); } catch (Exception ex) { Warn("Laundering: " + ex.Message); } } } } catch { } int value = LetWorkersGo(p); int num = ClearOut(p); Unown(p); try { Money.CreateOnlineTransaction("Sold " + name, quote.Total, 1f, (num > 0) ? $"{name} and {num} piece(s) of equipment" : name); } catch (Exception ex2) { Warn("Couldn't pay for " + name + ": " + ex2.Message); } string text = null; try { text = p.PropertyCode; } catch { } if (!string.IsNullOrEmpty(text) && !Sold.Contains(text)) { Sold.Add(text); } Log($"Sold {name} for ${quote.Total:N0} (${quote.Price:N0} for the place, ${quote.Equipment:N0} for {num} piece(s) of equipment). {value} worker(s) let go."); try { FortifyApi.Notify("Property sold", $"{name}: ${quote.Total:N0} paid into your bank account."); } catch { } return $"Sold {name}. ${quote.Total:N0} went into your bank account."; } private static int LetWorkersGo(Property p) { int num = 0; try { List<Employee> list = new List<Employee>(); List<Employee> employees = p.Employees; int num2 = 0; while (employees != null && num2 < employees.Count) { if ((Object)(object)employees[num2] != (Object)null) { list.Add(employees[num2]); } num2++; } foreach (Employee item in list) { try { item.SendFire(); num++; } catch { try { item.Fire(); num++; } catch (Exception ex) { Warn("Couldn't let a worker go: " + ex.Message); } } } } catch { } return num; } private static int ClearOut(Property p) { int num = 0; try { List<BuildableItem> list = new List<BuildableItem>(); List<BuildableItem> buildableItems = p.BuildableItems; int num2 = 0; while (buildableItems != null && num2 < buildableItems.Count) { if ((Object)(object)buildableItems[num2] != (Object)null && !buildableItems[num2].IsDestroyed) { list.Add(buildableItems[num2]); } num2++; } foreach (BuildableItem item in list) { try { item.Destroy(); num++; } catch (Exception ex) { Warn("Couldn't remove a piece of equipment: " + ex.Message); } } } catch { } return num; } private static void Unown(Property p) { try { p._IsOwned_k__BackingField = false; } catch (Exception ex) { Warn("Ownership: " + ex.Message); } try { Property.OwnedProperties.Remove(p); if (!Property.UnownedProperties.Contains(p)) { Property.UnownedProperties.Add(p); } } catch { } try { Business val = ((Il2CppObjectBase)p).TryCast<Business>(); if ((Object)(object)val != (Object)null) { Business.OwnedBusinesses.Remove(val); if (!Business.UnownedBusinesses.Contains(val)) { Business.UnownedBusinesses.Add(val); } } } catch { } try { if ((Object)(object)p.ForSaleSign != (Object)null) { p.ForSaleSign.SetActive(true); } } catch { } try { if ((Object)(object)p.ListingPoster != (Object)null) { ((Component)p.ListingPoster).gameObject.SetActive(true); } } catch { } try { if ((Object)(object)p.PoI != (Object)null) { bool active = false; bool enabled = true; List<Property> unownedProperties = Property.UnownedProperties; int num = 0; while (unownedProperties != null && num < unownedProperties.Count) { Property val2 = unownedProperties[num]; if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)p) && !((Object)(object)val2.PoI == (Object)null)) { active = ((Component)val2.PoI).gameObject.activeSelf; enabled = ((Behaviour)val2.PoI).enabled; break; } num++; } ((Component)p.PoI).gameObject.SetActive(active); ((Behaviour)p.PoI).enabled = enabled; } } catch { } try { string isOwnedVariable = p.IsOwnedVariable; VariableDatabase instance = NetworkSingleton<VariableDatabase>.Instance; if ((Object)(object)instance != (Object)null && !string.IsNullOrEmpty(isOwnedVariable)) { instance.SetVariableValue(isOwnedVariable, "false", true); } } catch { } try { p.HasChanged = true; } catch { } } public static void Loaded() { Sold.Clear(); try { string data = FortifyApi.GetData("SoldProperties"); if (!string.IsNullOrEmpty(data)) { List<string> list = JsonSerializer.Deserialize<List<string>>(data); if (list != null) { Sold.AddRange(list); } } } catch (Exception ex) { Warn("Couldn't read the sold list: " + ex.Message); } int num = 0; string[] array = Sold.ToArray(); for (int i = 0; i < array.Length; i++) { Property val = ByCode(array[i]); if (!((Object)(object)val == (Object)null) && val.IsOwned) { LetWorkersGo(val); ClearOut(val); Unown(val); num++; } } if (num > 0) { Log($"Kept {num} sold place(s) on the market."); } _ready = true; _nextCheck = Time.unscaledTime + 3f; } public static void Saving() { try { FortifyApi.SetData("SoldProperties", JsonSerializer.Serialize(Sold)); } catch { } } public static void Reset() { Sold.Clear(); _ready = false; RealtyApp.Close(); } public static void Update() { if (!_ready) { return; } RealtyApp.Tick(); try { Cars.Update(); } catch { } if (Time.unscaledTime < _nextCheck || Sold.Count == 0) { return; } _nextCheck = Time.unscaledTime + 1f; for (int num = Sold.Count - 1; num >= 0; num--) { Property val = ByCode(Sold[num]); if ((Object)(object)val != (Object)null && val.IsOwned) { Log(Name(val) + " is yours again."); Sold.RemoveAt(num); } } } } public sealed class RealtyApp : PhoneApp { private static RealtyApp _instance; private static Sprite _icon; private static float _nextFill; private RectTransform _list; private Text _head; private Text _confirmText; private GameObject _confirm; private Property _pending; private LandVehicle _pendingCar; private string _shown = ""; private string _message; private bool _iconHidden; protected override string AppName => "SellProperty_Realty"; protected override string AppTitle => "Sell Property & Cars"; protected override string IconLabel => "Sell It"; protected override string IconFileName => ((PhoneApp)this).AppName + ".png"; protected override Sprite IconSprite => _icon ?? (_icon = MakeIcon()); protected override void OnCreated() { ((PhoneApp)this).OnCreated(); _instance = this; } protected override void OnCreatedUI(GameObject container) { try { Build(container); } catch (Exception ex) { try { Realty.Warn("Realty app: couldn't build its screen (" + ex.Message + ")."); } catch { } } } private void Build(GameObject container) { //IL_001a: 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_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0288: 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_02b1: 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_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_0382: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) GameObject val = UIFactory.Panel("RealtyPanel", container.transform, new Color(0.07f, 0.08f, 0.07f), (Vector2?)null, (Vector2?)null, true); Place(((Graphic)UIFactory.Text("Title", "SELL PROPERTY", val.transform, 26, (TextAnchor)1, (FontStyle)1)).rectTransform, -8f, 40f, 20f); _head = UIFactory.Text("Head", "", val.transform, 16, (TextAnchor)1, (FontStyle)0); ((Graphic)_head).color = new Color(0.72f, 0.85f, 0.7f); _head.horizontalOverflow = (HorizontalWrapMode)0; _head.supportRichText = true; Place(((Graphic)_head).rectTransform, -44f, 46f, 30f); ScrollRect val2 = default(ScrollRect); _list = UIFactory.ScrollableVerticalList("RealtyList", val.transform, ref val2); _list.sizeDelta = new Vector2(0f, _list.sizeDelta.y); RectTransform component = ((Component)val2).GetComponent<RectTransform>(); if ((Object)(object)component != (Object)null) { component.anchorMin = new Vector2(0f, 0f); component.anchorMax = new Vector2(1f, 1f); component.offsetMin = new Vector2(10f, 10f); component.offsetMax = new Vector2(-10f, -96f); } if ((Object)(object)val2 != (Object)null) { val2.scrollSensitivity = Mathf.Max(val2.scrollSensitivity, 40f); } _confirm = UIFactory.Panel("RealtyConfirm", val.transform, new Color(0.06f, 0.07f, 0.06f, 1f), (Vector2?)null, (Vector2?)null, true); try { Image component2 = _confirm.GetComponent<Image>(); if ((Object)(object)component2 != (Object)null) { ((Graphic)component2).color = new Color(0.06f, 0.07f, 0.06f, 1f); } } catch { } _confirmText = UIFactory.Text("Text", "", _confirm.transform, 19, (TextAnchor)1, (FontStyle)0); _confirmText.horizontalOverflow = (HorizontalWrapMode)0; _confirmText.supportRichText = true; RectTransform rectTransform = ((Graphic)_confirmText).rectTransform; rectTransform.anchorMin = new Vector2(0f, 0.3f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.offsetMin = new Vector2(24f, 0f); rectTransform.offsetMax = new Vector2(-24f, -24f); var (val3, val4, _) = UIFactory.ButtonWithLabel("Sell", "Sell it", _confirm.transform, new Color(0.62f, 0.2f, 0.15f), 170f, 46f); Anchor(val3.GetComponent<RectTransform>(), new Vector2(0.5f, 0f), new Vector2(-100f, 36f)); var (val5, val6, _) = UIFactory.ButtonWithLabel("Keep", "Keep it", _confirm.transform, new Color(0.22f, 0.4f, 0.24f), 170f, 46f); Anchor(val5.GetComponent<RectTransform>(), new Vector2(0.5f, 0f), new Vector2(100f, 36f)); EventHelper.AddListener((Action)ConfirmSell, (UnityEvent)(object)val4.onClick); EventHelper.AddListener((Action)delegate { _pending = null; _pendingCar = null; _confirm.SetActive(false); }, (UnityEvent)(object)val6.onClick); _confirm.SetActive(false); _shown = null; Fill(); } private static void Place(RectTransform rt, float y, float h, float margin) { //IL_000b: 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_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) rt.anchorMin = new Vector2(0f, 1f); rt.anchorMax = new Vector2(1f, 1f); rt.pivot = new Vector2(0.5f, 1f); rt.sizeDelta = new Vector2(0f - margin, h); rt.anchoredPosition = new Vector2(0f, y); } private static void Anchor(RectTransform rt, Vector2 anchor, Vector2 pos) { //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) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) rt.anchorMin = anchor; rt.anchorMax = anchor; rt.pivot = new Vector2(0.5f, 0f); rt.anchoredPosition = pos; } public static void Tick() { if (_instance == null || Time.unscaledTime < _nextFill) { return; } _nextFill = Time.unscaledTime + (Realty.ShowApp ? 1f : 3f); if (!Realty.ShowApp) { _instance.HideIcon(); return; } bool flag = false; try { flag = ((PhoneApp)_instance).IsOpen(); } catch { } if (!flag) { _instance._shown = null; return; } try { _instance.Fill(); } catch { } } public static void Close() { if (_instance == null) { return; } _instance._pending = null; _instance._pendingCar = null; _instance._message = null; try { if ((Object)(object)_instance._confirm != (Object)null) { _instance._confirm.SetActive(false); } } catch { } } private void HideIcon() { if (_iconHidden) { return; } try { foreach (RectTransform item in Object.FindObjectsOfType<RectTransform>(true)) { if (!((Object)(object)item == (Object)null) && !(((Object)item).name != ((PhoneApp)this).AppName) && !((Object)(object)((Transform)item).parent == (Object)null) && !(((Object)((Transform)item).parent).name != "AppIcons")) { ((Component)item).gameObject.SetActive(false); _iconHidden = true; } } } catch { } } private void Fill() { //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Expected O, but got Unknown //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_0406: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_0444: Unknown result type (might be due to invalid IL or missing references) //IL_0498: Unknown result type (might be due to invalid IL or missing references) //IL_04d3: Unknown result type (might be due to invalid IL or missing references) //IL_04e8: Unknown result type (might be due to invalid IL or missing references) //IL_04fd: Unknown result type (might be due to invalid IL or missing references) //IL_0511: Unknown result type (might be due to invalid IL or missing references) //IL_0589: Unknown result type (might be due to invalid IL or missing references) //IL_0590: Expected O, but got Unknown //IL_05dd: Unknown result type (might be due to invalid IL or missing references) //IL_06f2: Unknown result type (might be due to invalid IL or missing references) //IL_0707: Unknown result type (might be due to invalid IL or missing references) //IL_071c: Unknown result type (might be due to invalid IL or missing references) //IL_0730: Unknown result type (might be due to invalid IL or missing references) //IL_0784: Unknown result type (might be due to invalid IL or missing references) //IL_07b1: Unknown result type (might be due to invalid IL or missing references) //IL_07c6: Unknown result type (might be due to invalid IL or missing references) //IL_07db: Unknown result type (might be due to invalid IL or missing references) //IL_07ef: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_list == (Object)null || (Object)(object)_head == (Object)null) { return; } List<Property> list = (Realty.ShowProperties ? Realty.Sellable() : new List<Property>()); List<Cars.CarQuote> list2 = new List<Cars.CarQuote>(); foreach (LandVehicle item4 in Cars.Owned()) { list2.Add(Cars.Price(item4)); } List<Realty.Quote> list3 = new List<Realty.Quote>(); StringBuilder stringBuilder = new StringBuilder(_message ?? ""); foreach (Property item5 in list) { Realty.Quote quote = Realty.Price(item5); list3.Add(quote); stringBuilder.Append(quote.Name).Append(quote.Total).Append(';'); } foreach (Cars.CarQuote item6 in list2) { stringBuilder.Append("car:").Append(item6.Id).Append(item6.Price) .Append(';'); } int value = Mathf.RoundToInt(Mathf.Clamp01(Realty.Share()) * 100f); string text = ((list.Count == 0 && list2.Count == 0) ? "You don't own anything you can sell right now." : (Realty.ShowProperties ? $"Places and cars sell for {value}% of what you paid (places also get {value}% of the shop price of any equipment left inside)." : $"Your cars sell for {value}% of what you paid. Sell your places in Fortify Your Base's Realty app.")); if (!string.IsNullOrEmpty(_message)) { text = "<b>" + _message + "</b>\n" + text; } _head.text = text; if (stringBuilder.ToString() == _shown) { return; } _shown = stringBuilder.ToString(); for (int num = ((Transform)_list).childCount - 1; num >= 0; num--) { Object.Destroy((Object)(object)((Component)((Transform)_list).GetChild(num)).gameObject); } foreach (Realty.Quote item7 in list3) { GameObject val = new GameObject("Row"); val.transform.SetParent((Transform)(object)_list, false); val.AddComponent<RectTransform>(); LayoutElement obj = val.AddComponent<LayoutElement>(); obj.preferredHeight = 70f; obj.minHeight = 70f; ((Graphic)val.AddComponent<Image>()).color = new Color(0.13f, 0.15f, 0.13f); string value2 = ((item7.Items > 0) ? $" + ${item7.Equipment:N0} equipment" : ""); Text obj2 = UIFactory.Text("Text", $"<b>{item7.Name}</b>\n<size=16>Paid ${item7.Paid:N0}. Sells for ${item7.Price:N0}{value2}</size>", val.transform, 20, (TextAnchor)3, (FontStyle)0); obj2.horizontalOverflow = (HorizontalWrapMode)0; obj2.supportRichText = true; RectTransform rectTransform = ((Graphic)obj2).rectTransform; rectTransform.anchorMin = new Vector2(0f, 0f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.offsetMin = new Vector2(12f, 3f); rectTransform.offsetMax = new Vector2(-150f, -3f); ValueTuple<GameObject, Button, Text> valueTuple = UIFactory.ButtonWithLabel("Sell", $"Sell ${item7.Total:N0}", val.transform, new Color(0.55f, 0.22f, 0.15f), 136f, 44f); GameObject item = valueTuple.Item1; Button item2 = valueTuple.Item2; Text item3 = valueTuple.Item3; RectTransform component = item.GetComponent<RectTransform>(); component.anchorMin = new Vector2(1f, 0.5f); component.anchorMax = new Vector2(1f, 0.5f); component.pivot = new Vector2(1f, 0.5f); component.anchoredPosition = new Vector2(-10f, 0f); item3.fontSize = 17; Property prop = item7.Prop; EventHelper.AddListener((Action)delegate { AskToSell(prop); }, (UnityEvent)(object)item2.onClick); } foreach (Cars.CarQuote item8 in list2) { GameObject val2 = new GameObject("CarRow"); val2.transform.SetParent((Transform)(object)_list, false); val2.AddComponent<RectTransform>(); LayoutElement obj3 = val2.AddComponent<LayoutElement>(); obj3.preferredHeight = 70f; obj3.minHeight = 70f; ((Graphic)val2.AddComponent<Image>()).color = new Color(0.12f, 0.14f, 0.17f); string value3 = (item8.Occupied ? " (someone's in it)" : ((item8.Stored > 0) ? $" ({item8.Stored} item(s) in the trunk)" : "")); Text obj4 = UIFactory.Text("Text", $"<b>{item8.Name}</b> <size=14>car</size>\n<size=16>Paid ${item8.Paid:N0}. Sells for ${item8.Price:N0}{value3}</size>", val2.transform, 20, (TextAnchor)3, (FontStyle)0); obj4.horizontalOverflow = (HorizontalWrapMode)0; obj4.supportRichText = true; RectTransform rectTransform2 = ((Graphic)obj4).rectTransform; rectTransform2.anchorMin = new Vector2(0f, 0f); rectTransform2.anchorMax = new Vector2(1f, 1f); rectTransform2.offsetMin = new Vector2(12f, 3f); rectTransform2.offsetMax = new Vector2(-150f, -3f); (GameObject, Button, Text) tuple = UIFactory.ButtonWithLabel("SellCar", $"Sell ${item8.Price:N0}", val2.transform, new Color(0.55f, 0.22f, 0.15f), 136f, 44f); RectTransform component2 = tuple.Item1.GetComponent<RectTransform>(); component2.anchorMin = new Vector2(1f, 0.5f); component2.anchorMax = new Vector2(1f, 0.5f); component2.pivot = new Vector2(1f, 0.5f); component2.anchoredPosition = new Vector2(-10f, 0f); tuple.Item3.fontSize = 17; LandVehicle veh = item8.Veh; EventHelper.AddListener((Action)delegate { AskToSellCar(veh); }, (UnityEvent)(object)tuple.Item2.onClick); } } private void AskToSell(Property p) { if (!((Object)(object)p == (Object)null) && !((Object)(object)_confirm == (Object)null)) { Realty.Quote quote = Realty.Price(p, countStored: true); StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder2 = stringBuilder; StringBuilder stringBuilder3 = stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(31, 1, stringBuilder2); handler.AppendLiteral("<size=26><b>Sell "); handler.AppendFormatted(quote.Name); handler.AppendLiteral("?</b></size>\n\n"); stringBuilder3.Append(ref handler); stringBuilder2 = stringBuilder; StringBuilder stringBuilder4 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(37, 1, stringBuilder2); handler.AppendLiteral("You get <b>$"); handler.AppendFormatted(quote.Total, "N0"); handler.AppendLiteral("</b> in your bank account"); stringBuilder4.Append(ref handler); stringBuilder.Append((quote.Items > 0) ? $": ${quote.Price:N0} for the place and ${quote.Equipment:N0} for the {quote.Items} piece(s) of equipment inside.\n" : ".\n"); if (quote.Workers > 0) { stringBuilder2 = stringBuilder; StringBuilder stringBuilder5 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(38, 1, stringBuilder2); handler.AppendLiteral("\nYour "); handler.AppendFormatted(quote.Workers); handler.AppendLiteral(" worker(s) there will be let go."); stringBuilder5.Append(ref handler); } if (quote.Laundering > 0f) { stringBuilder2 = stringBuilder; StringBuilder stringBuilder6 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(46, 1, stringBuilder2); handler.AppendLiteral("\nThe $"); handler.AppendFormatted(quote.Laundering, "N0"); handler.AppendLiteral(" being laundered there is paid in first."); stringBuilder6.Append(ref handler); } stringBuilder.Append((quote.Stored > 0) ? $"\n<color=#ffb27a>Still stored inside: {quote.Stored} item(s). Anything left inside (product, cash, plants) goes with the sale.</color>" : "\nAnything still inside (product, cash, plants) goes with the sale."); stringBuilder.Append("\n\nIt goes back on the market at its full price."); _confirmText.text = stringBuilder.ToString(); _pending = p; _confirm.SetActive(true); } } private void AskToSellCar(LandVehicle v) { if (!((Object)(object)v == (Object)null) && !((Object)(object)_confirm == (Object)null)) { Cars.CarQuote carQuote = Cars.Price(v); string text = $"<size=26><b>Sell your {carQuote.Name}?</b></size>\n\nYou get <b>${carQuote.Price:N0}</b> in your bank account ({Mathf.RoundToInt(Mathf.Clamp01(Realty.Share()) * 100f)}% of the ${carQuote.Paid:N0} it cost)."; if (carQuote.Occupied) { text += "\n<color=#ffb27a>Someone's in it: everyone has to get out first.</color>"; } if (carQuote.Stored > 0) { text += $"\n<color=#ffb27a>Its trunk still has {carQuote.Stored} item(s) in it: empty it first.</color>"; } text += "\n\nThe car is gone once it's sold."; _confirmText.text = text; _pending = null; _pendingCar = v; _confirm.SetActive(true); } } private void ConfirmSell() { LandVehicle pendingCar = _pendingCar; _pendingCar = null; if ((Object)(object)pendingCar != (Object)null) { if ((Object)(object)_confirm != (Object)null) { _confirm.SetActive(false); } try { _message = Cars.Sell(pendingCar); } catch (Exception ex) { _message = "Couldn't sell it: " + ex.Message; Realty.Warn(_message); } _shown = null; Fill(); return; } Property pending = _pending; _pending = null; if ((Object)(object)_confirm != (Object)null) { _confirm.SetActive(false); } if (!((Object)(object)pending == (Object)null)) { try { _message = Realty.Sell(pending); } catch (Exception ex2) { _message = "Couldn't sell it: " + ex2.Message; Realty.Warn(_message); } _shown = null; Fill(); } } private static Sprite MakeIcon() { //IL_01cf: 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) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Expected O, but got Unknown //IL_0073: 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_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: 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_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0160: 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_0185: Unknown result type (might be due to invalid IL or missing references) Color32[] array = (Color32[])(object)new Color32[16384]; Color val = default(Color); ((Color)(ref val))..ctor(0.16f, 0.42f, 0.24f); Color val2 = default(Color); ((Color)(ref val2))..ctor(0.96f, 0.95f, 0.9f); Color val3 = default(Color); ((Color)(ref val3))..ctor(0.16f, 0.42f, 0.24f); Color val4 = default(Color); ((Color)(ref val4))..ctor(0.95f, 0.72f, 0.2f); for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { Color val5 = val; if (j >= 34 && j <= 94 && i >= 26 && i <= 70) { val5 = val2; } if (i > 68 && i < 104 && Mathf.Abs((float)j - 64f) < (float)(104 - i) * 1.15f) { val5 = val2; } if (j >= 56 && j <= 72 && i >= 26 && i <= 52) { val5 = val3; } if (j >= 80 && j <= 86 && i >= 84 && i <= 100) { val5 = val2; } float num = (float)j - 98f; float num2 = (float)i - 40f; if (num * num + num2 * num2 < 225f) { val5 = val4; } if (Mathf.Abs(num) < 2.5f && Mathf.Abs(num2) < 9f) { val5 = val2; } if (Mathf.Abs(num2 - 5f) < 2f && Mathf.Abs(num) < 6f) { val5 = val2; } if (Mathf.Abs(num2 + 5f) < 2f && Mathf.Abs(num) < 6f) { val5 = val2; } array[i * 128 + j] = Color32.op_Implicit(val5); } } Texture2D val6 = new Texture2D(128, 128, (TextureFormat)4, false); val6.SetPixels32(new Il2CppStructArray<Color32>(array)); val6.Apply(); ((Object)val6).hideFlags = (HideFlags)32; Sprite obj = Sprite.Create(val6, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f)); ((Object)obj).hideFlags = (HideFlags)32; return obj; } } public sealed class SellCore : MelonMod { private static MelonPreferences_Entry<float> _share; private static bool _ok; private static bool _toldLinked; private static float _warnedAt = -100f; public override void OnInitializeMelon() { try { FortifyApi.Init((MelonMod)(object)this, "SellProperty", "Sell Property"); _share = MelonPreferences.GetCategory("SellProperty").CreateEntry<float>("SellPercent", 75f, "Sell percent", "How much of what you paid you get back when you sell (0 to 100). Equipment left inside is bought back at the same share of its shop price.", false, false, (ValueValidator)null, (string)null); Realty.Share = () => Mathf.Clamp(_share?.Value ?? 75f, 0f, 100f) / 100f; Realty.Log = delegate(string s) { ((MelonBase)this).LoggerInstance.Msg(s); }; Realty.Warn = delegate(string s) { ((MelonBase)this).LoggerInstance.Warning(s); }; FortifyApi.SetNotifyIcon("cash"); FortifyApi.AfterLoad += Realty.Loaded; FortifyApi.BeforeSave += Realty.Saving; FortifyApi.Unloaded += Realty.Reset; _ok = true; ((MelonBase)this).LoggerInstance.Msg("Sell Property loaded. Open the Realty app on your phone to sell a place you own."); } catch (Exception ex) { ((MelonBase)this).LoggerInstance.Error("Sell Property couldn't start: " + ex.Message + ". It needs MelonLoader 0.7 and S1API (Bars fork) 3.2.3 or newer."); } } public override void OnUpdate() { if (!_ok || !FortifyApi.InGame) { return; } try { FortifyApi.Frame(); Realty.ShowApp = true; Realty.ShowProperties = !FortifyApi.Linked; if (FortifyApi.Linked && !_toldLinked) { _toldLinked = true; ((MelonBase)this).LoggerInstance.Msg("Fortify Your Base is installed and sells your properties in its own Realty app, so this Realty app only sells your cars."); } Realty.Update(); } catch (Exception ex) { if (Time.unscaledTime - _warnedAt > 30f) { _warnedAt = Time.unscaledTime; ((MelonBase)this).LoggerInstance.Warning("Sell Property: " + ex.Message); } } } } } namespace FybCommon { internal static class FortifyApi { private sealed class SaveDoc { public int Version { get; set; } = 1; public string Created { get; set; } public Dictionary<string, string> Data { get; set; } = new Dictionary<string, string>(); } private static Instance _log; private static string _folder; private static MelonPreferences_Entry<bool> _devKeys; private static KeyCode _use = (KeyCode)101; private static readonly List<string> DrawnIds = new List<string>(); 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<string, string> _data = new Dictionary<string, string>(); private static string _file; private static bool _readThisSession; private static bool _patched; private static readonly Dictionary<string, Material> Mats = new Dictionary<string, Material>(); private static Shader _lit; private static readonly HashSet<IntPtr> Drawn = new HashSet<IntPtr>(); private static float _nextDraw; private static readonly List<(string label, AudioClip clip)> NoSongs = new List<(string, AudioClip)>(); private static GUIStyle _hintStyle; 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<LoadManager>.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<bool> 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<bool>("DevKeys", false, "Developer keys", "Test keys (for the mod's author).", false, false, (ValueValidator)null, (string)null); _use = Keys.Parse(obj.CreateEntry<string>("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<NotificationsManager>.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<ItemDefinition>(_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<string, string>(); _file = FileFor(SavePath()); try { if (_file != null && File.Exists(_file)) { SaveDoc saveDoc = JsonSerializer.Deserialize<SaveDoc>(File.ReadAllText(_file)); if (saveDoc != null && SaveStamp.IsStale(_file, saveDoc.Created)) { Log("This is a new game in a save slot that was used before, so this mod starts fresh here (the old game's data was set aside)."); SaveStamp.Retire(_file); saveDoc = null; } 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) || SaveStamp.IsStale(path, null)) { 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 { Created = SaveStamp.Current(), 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<string, string>(); Shared.Reset(); Pins.Reset(); Drawn.Clear(); RainCover.Reset(); TreeCut.Reset(); } private static string SavePath() { LoadManager instance = Singleton<LoadManager>.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<Material>()) { 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<Collider>()); } 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<MeshRenderer>()).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<PlayerCamera>.Instance; if ((Object)(object)instance != (Object)null) { instance.AddActiveUIElement(name); instance.SetCanLook(false); } } catch { } try { PlayerMovement instance2 = PlayerSingleton<PlayerMovement>.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<PlayerCamera>.Instance; if ((Object)(object)instance != (Object)null) { instance.RemoveActiveUIElement(name); instance.SetCanLook(true); } } catch { } try { PlayerMovement instance2 = PlayerSingleton<PlayerMovement>.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_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown if (string.IsNullOrEmpty(text)) { return; } float num = Screen.width; float num2 = Screen.height; float num3 = Mathf.Clamp(num2 / 1080f, 0.9f, 2f); int num4 = Mathf.RoundToInt(17f * num3); float num5 = Mathf.Min(num - 40f, 840f * num3); float num6 = 34f * num3; try { if (_hintStyle == null) { _hintStyle = new GUIStyle(GUI.skin.label) { fontStyle = (FontStyle)1, wordWrap = true }; } _hintStyle.fontSize = num4; num6 = Mathf.Max(num6, _hintStyle.CalcHeight(new GUIContent(text), num5 - 24f * num3) + 12f * num3); } catch { } Rect r = default(Rect); ((Rect)(ref r))..ctor(num * 0.5f - num5 * 0.5f, num2 * 0.68f, num5, num6); Ui.Fill(r, new Color(0f, 0f, 0f, 0.55f)); Ui.Text(new Rect(((Rect)(ref r)).x + 12f * num3, ((Rect)(ref r)).y, ((Rect)(ref r)).width - 24f * num3, ((Rect)(ref r)).height), text, num4, 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<string> 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<NPC>() : 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<NPC> 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<Vector3, bool> 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<Vector3, bool> 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<T>(Func<T> 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<Vector3, bool> 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<Vector3, bool> 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<KeyCode>(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 obj2 = Control(key); if (obj2 == null) { return false; } return ((ButtonControl)obj2).wasPressedThisFrame; } 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 obj2 = Control(key); if (obj2 == null) { return false; } return ((ButtonControl)obj2).isPressed; } 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<Key>(text, ignoreCase: true, out result) ? current[result] : null; } catch { return null; } } } internal static class Pins { private static readonly HashSet<IntPtr> Held = new HashSet<IntPtr>(); 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<string, Func<Vector3, bool>> Shelters = new Dictionary<string, Func<Vector3, bool>>(); private static readonly List<Renderer> Rain = new List<Renderer>(); private static readonly List<Renderer> Hidden = new List<Renderer>(); private static readonly List<ScriptableRendererFeature> HiddenFeatures = new List<ScriptableRendererFeature>(); private static bool _scanned; private static bool _inside; private static float _next; public static void Add(string key, Func<Vector3, bool> 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_00ac: 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_0086: 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<PlayerCamera>.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<Vector3, bool> 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<int> hashSet = new HashSet<int>(); foreach (RainController item in Object.FindObjectsOfType<RainController>()) { foreach (Renderer componentsInChild in ((Component)item).GetComponentsInChildren<Renderer>(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<UniversalRenderPipelineAsset>() : null); Il2CppReferenceArray<ScriptableRendererData> val2 = (((Object)(object)val != (Object)null) ? val.m_RendererDataList : null); int num = 0; while (val2 != null && num < ((Il2CppArrayBase<ScriptableRendererData>)(object)val2).Length) { ScriptableRendererData val3 = ((Il2CppArrayBase<ScriptableRendererData>)(object)val2)[num]; if (!((Object)(object)val3 == (Object)null) && val3.rendererFeatures != null) { Enumerator<ScriptableRendererFeature> 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 SaveStamp { public static string Current() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) try { LoadManager instance = Singleton<LoadManager>.Instance; SaveInfo val = ((instance != null) ? instance.ActiveSaveInfo : null); if (val == null) { return ""; } DateTime dateCreated = val.DateCreated; long ticks = ((DateTime)(ref dateCreated)).Ticks; return (ticks > 0) ? ticks.ToString() : ""; } catch { return ""; } } public static bool IsStale(string path, string stored) { //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_0058: 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_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Invalid comparison between Unknown and I4 try { string text = Current(); if (text.Length == 0 || path == null || !File.Exists(path)) { return false; } if (!string.IsNullOrEmpty(stored)) { return stored != text; } SaveInfo activeSaveInfo = Singleton<LoadManager>.Instance.ActiveSaveInfo; DateTime dateCreated = activeSaveInfo.DateCreated; DateTime dateTime = new DateTime(((DateTime)(ref dateCreated)).Ticks); bool flag = false; try { dateCreated = activeSaveInfo.DateCreated; flag = (int)((DateTime)(ref dateCreated)).Kind == 1; } catch { } return (flag ? File.GetLastWriteTimeUtc(path) : File.GetLastWriteTime(path)) < dateTime - TimeSpan.FromMinutes(2.0); } catch { return false; } } public static void Retire(string path) { try { string text = path + ".previous-game"; if (File.Exists(text)) { File.Delete(text); } File.Move(path, text); } catch { } } } internal static class Shared { private const string Tag = "fyb2|"; private const int MaxChunk = 2800; private static readonly Dictionary<string, string> Local = new Dictionary<string, string>(); private static readonly Dictionary<string, string> Sent = new Dictionary<string, string>(); private static readonly Dictionary<string, string> Remote = new Dictionary<string, string>(); private static readonly Dictionary<string, (int n, string[] parts)> Partial = new Dictionary<string, (int, string[])>(); private static readonly Dictionary<string, List<string>> Inbox = new Dictionary<string, List<string>>(); private static float _nextFlush; private static float _nextFull; private static float _helloAt = -100f; private static float _answeredHelloAt = -100f; private static bool _wantFull; private static int _chunkSeq; private static readonly string Me = Guid.NewGuid().ToString("N").Substring(0, 8); private static ulong _pollLobby; private static int _nextChat; private static float _nextPoll; private static Il2CppStructArray<byte> _buf; internal static string Echo; private static bool IsGuest => FortifyApi.IsGuest; private static SteamLobbyService Service() { try { Lobby instance = Singleton<Lobby>.Instance; object result; if (instance == null) { result = null; } else { ILobbyService lobbyService = instance._lobbyService; result = ((lobbyService != null) ? ((Il2CppObjectBase)lobbyService).TryCast<SteamLobbyService>() : null); } return (SteamLobbyService)result; } catch { return null; } } public static ulong LobbyId() { try { Lobby instance = Singleton<Lobby>.Instance; if ((Object)(object)instance == (Object)null) { return 0uL; } ulong lobbyID = instance.LobbyID; if (lobbyID != 0L) { return lobbyID; } SteamLobbyService val = Service(); return (val != null) ? val._lobbyID : 0; } catch { return 0uL; } } public static bool InLobby(out CSteamID lobby) { //IL_0001: 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_003c: 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) lobby = default(CSteamID); try { Lobby instance = Singleton<Lobby>.Instance; ulong num = LobbyId(); if ((Object)(object)instance == (Object)null || num == 0L || !instance.IsInLobby) { return false; } lobby = new CSteamID { m_SteamID = num }; return instance.PlayerCount > 1 || IsGuest; } catch { return false; } } private static void Poll() { //IL_005f: 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_006e: 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) if (Time.unscaledTime < _nextPoll) { return; } _nextPoll = Time.unscaledTime + 0.1f; ulong num = LobbyId(); if (num == 0L) { return; } if (num != _pollLobby) { _pollLobby = num; _nextChat = 0; Partial.Clear(); } try { if (_buf == null) { _buf = new Il2CppStructArray<byte>(8192L); } CSteamID val = new CSteamID { m_SteamID = num }; CSteamID val2 = default(CSteamID); EChatEntryType val3 = default(EChatEntryType); for (int i = 0; i < 60; i++) { int lobbyChatEntry = SteamMatchmaking.GetLobbyChatEntry(val, _nextChat, ref val2, _buf, 8192, ref val3); if (lobbyChatEntry <= 0) { break; } _nextChat++; if (lobbyChatEntry >= "fyb2|".Length + 2 && ((Il2CppArrayBase<byte>)(object)_buf)[0] == 102 && ((Il2CppArrayBase<byte>)(object)_buf)[3] == 50 && ((Il2CppArrayBase<byte>)(object)_buf)[4] == 124) { byte[] array = new byte[lobbyChatEntry]; for (int j = 0; j < lobbyChatEntry; j++) { array[j] = ((Il2CppArrayBase<byte>)(object)_buf)[j]; } int num2 = lobbyChatEntry; while (num2 > 0 && array[num2 - 1] == 0) { num2--; } OnMessage(Encoding.UTF8.GetString(array, 0, num2)); } } } catch { } } private static void Send(string text) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) try { ulong num = LobbyId(); if (num != 0L) { byte[] bytes = Encoding.UTF8.GetBytes(text + "\0"); SteamMatchmaking.SendLobbyChatMsg(new CSteamID { m_SteamID = num }, new Il2CppStructArray<byte>(bytes), bytes.Length); } } catch { } } private static void Pack(StringBuilder sb, string key, string value) { if (value == null) { value = ""; } sb.Append(key.Length.ToString(CultureInfo.InvariantCulture)).Append(',').Append(value.Length.ToString(CultureInfo.InvariantCulture)) .Append(':') .Append(key) .Append(value); } private static IEnumerable<(string key, string value)> Unpack(string s, int start) { int num = start; while (num < s.Length) { int num2 = s.IndexOf(',', num); int num3 = ((num2 < 0) ? (-1) : s.IndexOf(':', num2)); if (num2 < 0 || num3 < 0 || !int.TryParse(s.Substring(num, num2 - num), out var kl) || !int.TryParse(s.Substring(num2 + 1, num3 - num2 - 1), out var vl)) { break; } int body = num3 + 1; if (kl < 0 || vl < 0 || body + kl + vl > s.Length) { break; } yield return (key: s.Substring(body, kl), value: s.Substring(body + kl, vl)); num = body + kl + vl; } } private static void OnMessage(string msg) { try { if (msg == null || !msg.StartsWith("fyb2|", StringComparison.Ordinal) || msg.Length < "fyb2|".Length + 2) { return; } char c = msg["fyb2|".Length]; int num = "fyb2|".Length + 2; switch (c) { case 'S': if (!IsGuest) { break; } { foreach (var (key2, value2) in Unpack(msg, num)) { Remote[key2] = value2; } break; } case 'P': if (IsGuest) { TakeChunk(msg, num); } break; case 'R': if (IsGuest) { break; } { foreach (var (key, value) in Unpack(msg, num)) { Queue(key, value); } break; } case 'H': if (!IsGuest) { _wantFull = true; } break; case 'T': Echo = msg; break; } } catch { } } private static void TakeChunk(string msg, int body) { string[] array = msg.Substring(body).Split(new char[1] { '|' }, 5); if (array.Length < 5 || !int.TryParse(array[1], out var result) || !int.TryParse(array[2], out var result2) || result2 <= 0 || result2 > 400 || result < 0 || result >= result2) { return; } string key = array[0] + "/" + array[3]; if (!Partial.TryGetValue(key, out (int, string[]) value) || value.Item1 != result2) { value = (result2, new string[result2]); Partial[key] = value; } value.Item2[result] = array[4]; string[] item = value.Item2; for (int i = 0; i < item.Length; i++) { if (item[i] == null) { return; } } Remote[array[3]] = string.Concat(value.Item2); Partial.Remove(key); } public static void Set(string key, string value) { if (key != null) { Local[key] = value ?? ""; } } public static string Get(string key) { if (key == null) { return null; } if (!IsGuest) { if (!Local.TryGetValue(key, out var value)) { return null; } return value; } Poll(); if (!Remote.TryGetValue(key, out var value2) || string.IsNullOrEmpty(value2)) { return null; } return value2; } public static void Request(string key, string value) { if (key != null) { CSteamID lobby; if (!IsGuest) { Queue(key, value); } else if (InLobby(out lobby)) { StringBuilder stringBuilder = new StringBuilder("fyb2|").Append("R|"); Pack(stringBuilder, key, value ?? ""); Send(stringBuilder.ToString()); } } } public static List<string> Take(string key) { List<string> list = new List<string>(); 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)) { List<string> list = (Inbox[key] = new List<string>()); value2 = list; } if (value2.Count < 40) { value2.Add(value ?? ""); } } public static void Update() { Poll(); if (Time.unscaledTime < _nextFlush) { return; } _nextFlush = Time.unscaledTime + 0.4f; if (!InLobby(out var _)) { return; } if (IsGuest) { if (Remote.Count == 0 && Time.unscaledTime - _helloAt > 6f) { _helloAt = Time.unscaledTime; Send("fyb2|H|" + Me); } return; } bool all = false; if (_wantFull && Time.unscaledTime - _answeredHelloAt > 3f) { _wantFull = false; _answeredHelloAt = Time.unscaledTime; all = true; } if (Time.unscaledTime > _nextFull) { _nextFull = Time.unscaledTime + 30f; all = true; } Flush(all); } private static void Flush(bool all) { StringBuilder stringBuilder = new StringBuilder("fyb2|").Append("S|"); int length = stringBuilder.Length; foreach (KeyValuePair<string, string> item in Local) { if (!all && Sent.TryGetValue(item.Key, out var value) && value == item.Value) { continue; } Sent[item.Key] = item.Value; string text = item.Value ?? ""; if (text.Length + item.Key.Length + 16 > 2800) { SendChunked(item.Key, text); continue; } if (stringBuilder.Length + text.Length + item.Key.Length + 16 > 2800) { Send(stringBuilder.ToString()); stringBuilder.Length = length; } Pack(stringBuilder, item.Key, text); } if (stringBuilder.Length > length) { Send(stringBuilder.ToString()); } } private static void SendChunked(string key, string v) { int num = 2800 - key.Length - 40; int num2 = (v.Length + num - 1) / num; string me = Me; int num3 = ++_chunkSeq; string text = me + num3.ToString(CultureInfo.InvariantCulture); for (int i = 0; i < num2; i++) { string text2 = v.Substring(i * num, Math.Min(num, v.Length - i * num)); Send("fyb2|P|" + text + "|" + i + "|" + num2 + "|" + key + "|" + text2); } } public static void Listen(string key) { if (key != null && !Inbox.ContainsKey(key)) { Inbox[key] = new List<string>(); } } internal static void TestEcho(string text) { Send("fyb2|T|" + text); } internal static void TestPoll() { Poll(); } public static void Reset() { Local.Clear(); Sent.Clear(); Remote.Clear(); Partial.Clear(); Inbox.Clear(); _wantFull = false; _helloAt = -100f; } } internal static class TreeCut { private static readonly Dictionary<string, (Vector3 c, float r)> Clearings = new Dictionary<string, (Vector3, float)>(); private static readonly Dictionary<int, (Texture2D tex, byte[] orig, int count)> Textures = new Dictionary<int, (Texture2D, byte[], int)>(); private static readonly List<GameObject> Trunks = new List<GameObject>(); private static bool _dirty; public static void Add(string key, Vector3 centre, float radius) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if