Decompiled source of UnderNewManagement v1.5.0
Proprietor.dll
Decompiled 3 weeks 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.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.Json; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem; using Il2CppSystem.Collections.Generic; using Il2CppSystem.Reflection; using Microsoft.CodeAnalysis; using ProtectorateShared; using SOD.Common; using SOD.Common.Helpers; using SOD.Common.Helpers.DialogObjects; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("Proprietor")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.5.0.0")] [assembly: AssemblyInformationalVersion("1.5.0+b5fb013c4df0fee8d9443eff145d058f6dd61920")] [assembly: AssemblyProduct("Proprietor")] [assembly: AssemblyTitle("Proprietor")] [assembly: AssemblyVersion("1.5.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 ProtectorateShared { [HarmonyPatch] internal static class DialogGuard { private static ManualLogSource log; private static readonly PropertyInfo ResponseInfo = typeof(DialogObject).GetProperty("ResponseInfo", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static ManualLogSource Log => log ?? (log = Logger.CreateLogSource("DialogGuard")); [HarmonyPatch(typeof(DialogController), "Start")] [HarmonyPrefix] internal static void Protect() { foreach (DialogObject knownModDialog in Lib.Dialogs.KnownModDialogs) { try { Keep((Object)(object)knownModDialog.Preset); object? obj = ResponseInfo?.GetValue(knownModDialog); Keep((Object)((obj is Object) ? obj : null)); } catch (Exception ex) { Log.LogError((object)ex.Message); } } } private static void Keep(Object o) { //IL_000b: 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) if (o != (Object)null) { o.hideFlags = (HideFlags)(o.hideFlags | 0x20); } } [HarmonyPatch(typeof(EvidenceWitness), "GetDialogOptions", new Type[] { typeof(List<DataKey>) })] [HarmonyPostfix] private static void DropDead(List<DialogOption> __result) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown if (__result == null) { return; } bool flag = default(bool); for (int num = __result.Count - 1; num >= 0; num--) { DialogOption obj = __result[num]; DialogPreset val = ((obj != null) ? obj.preset : null); if (val != null && !((SoCustomComparison)(object)val != (SoCustomComparison)null)) { ManualLogSource obj2 = Log; BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(52, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Skipped a destroyed dialog option (msgID "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val.msgID); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", ranking "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(val.ranking); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(")"); } obj2.LogWarning(val2); __result.RemoveAt(num); } } } } } namespace Proprietor { public class Crate { public int RoomId { get; set; } public float X { get; set; } public float Y { get; set; } public float Z { get; set; } public float Yaw { get; set; } public float HoursLeft { get; set; } } [HarmonyPatch] internal static class Crates { private const int MaxPerBusiness = 2; private static readonly string[] PresetNames = new string[3] { "WoodenCrate", "SmallCrate", "CardboardBoxLarge" }; private static readonly string[][] RoomPreference = new string[3][] { new string[3] { "storeroom", "stockroom", "storage" }, new string[2] { "backroom", "back room" }, new string[1] { "kitchen" } }; private static readonly Dictionary<Crate, Interactable> spawned = new Dictionary<Crate, Interactable>(); private static readonly HashSet<int> ids = new HashSet<int>(); private static InteractablePreset preset; public static void Delivered(Business b, Company c) { //IL_0074: 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_008c: 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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown if (!Plugin.DeliveryCrates.Value || (Object)(object)((c != null) ? c.address : null) == (Object)null) { return; } if (b.Crates.Count >= 2) { List<Crate> crates = b.Crates; crates[crates.Count - 1].HoursLeft += 1f; return; } (NewRoom, Vector3)? tuple = FindSpot(c, b); if (!tuple.HasValue) { return; } (NewRoom, Vector3) value = tuple.Value; NewRoom item = value.Item1; Vector3 item2 = value.Item2; Crate crate = new Crate { RoomId = item.roomID, X = item2.x, Y = item2.y, Z = item2.z, Yaw = Random.Range(0f, 360f), HoursLeft = Random.Range(2, 5) }; if (Spawn(c, crate)) { b.Crates.Add(crate); ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(25, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(b.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": delivery crate left in "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item.name); } logger.LogInfo(val); } } public static void Hourly() { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown bool flag = default(bool); foreach (Business value in Store.Owned.Values) { if (value.Crates.Count == 0) { continue; } Company val = Store.FindCompany(value.CompanyId); if (val == null) { continue; } List<Occupation> currentStaff = val.currentStaff; if (currentStaff == null || currentStaff.Count == 0) { continue; } Crate crate = value.Crates[0]; crate.HoursLeft -= 1f; if (!(crate.HoursLeft > 0f)) { Despawn(crate); value.Crates.RemoveAt(0); ManualLogSource logger = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(33, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(value.Name); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": staff unpacked a delivery crate"); } logger.LogInfo(val2); } } } public static void Restore() { spawned.Clear(); ids.Clear(); foreach (Business value in Store.Owned.Values) { Company val = Store.FindCompany(value.CompanyId); if (val == null) { value.Crates.Clear(); continue; } foreach (Crate item in value.Crates.ToList()) { if (!Spawn(val, item)) { value.Crates.Remove(item); } } } } public static void Remove(Business b) { foreach (Crate crate in b.Crates) { Despawn(crate); } b.Crates.Clear(); } public static void Forget() { spawned.Clear(); ids.Clear(); } private static bool Spawn(Company c, Crate crate) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) try { if (preset == null) { preset = FindPreset(); } if ((SoCustomComparison)(object)preset == (SoCustomComparison)null) { return false; } Interactable val = InteractableCreator.Instance.CreateWorldInteractable(preset, c.director, (Human)null, (Human)null, new Vector3(crate.X, crate.Y, crate.Z), new Vector3(0f, crate.Yaw, 0f), (List<Passed>)null, (Object)null, ""); if (val == null) { return false; } spawned[crate] = val; ids.Add(val.id); return true; } catch (Exception ex) { Plugin.Logger.LogError((object)("Couldn't place a delivery crate: " + ex.Message)); return false; } } private static void Despawn(Crate crate) { if (!spawned.TryGetValue(crate, out var value)) { return; } spawned.Remove(crate); try { ids.Remove(value.id); value.Delete(); } catch (Exception ex) { Plugin.Logger.LogError((object)("Couldn't remove a delivery crate: " + ex.Message)); } } private static InteractablePreset FindPreset() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown Dictionary<string, InteractablePreset> objectPresetDictionary = Toolbox.Instance.objectPresetDictionary; string[] presetNames = PresetNames; bool flag = default(bool); foreach (string b in presetNames) { Enumerator<string, InteractablePreset> enumerator = objectPresetDictionary.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<string, InteractablePreset> current = enumerator.Current; if (string.Equals(current.Key, b, StringComparison.OrdinalIgnoreCase)) { ManualLogSource logger = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Delivery crates use '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(current.Key); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'"); } logger.LogInfo(val); return current.Value; } } } Plugin.Logger.LogWarning((object)"No crate object found; deliveries won't show crates"); return null; } private static (NewRoom, Vector3)? FindSpot(Company c, Business b) { //IL_01d3: 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) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02dd: Unknown result type (might be due to invalid IL or missing references) List<NewRoom> list = new List<NewRoom>(); Enumerator<NewRoom> enumerator = ((NewGameLocation)c.address).rooms.GetEnumerator(); while (enumerator.MoveNext()) { NewRoom current = enumerator.Current; if ((Object)(object)current != (Object)null && current.nodes.Count > 0) { list.Add(current); } } if (list.Count == 0) { return null; } List<NewRoom> list2 = list.Where((NewRoom r) => Rank(r) < RoomPreference.Length).OrderBy(Rank).ToList(); if (list2.Count == 0) { Plugin.Logger.LogInfo((object)(c.name + ": no stockroom, back room or kitchen for delivery crates (rooms: " + string.Join(", ", list.Select(delegate(NewRoom r) { string name = r.name; RoomConfiguration obj = r.preset; return name + " [" + ((obj != null) ? ((Object)obj).name : null) + "]"; })) + ")")); return null; } List<Vector3> taken = ((IEnumerable<Crate>)b.Crates).Select((Func<Crate, Vector3>)((Crate k) => new Vector3(k.X, k.Y, k.Z))).ToList(); foreach (NewRoom item in list2) { NewNode val = null; float num = float.MaxValue; Enumerator<NewNode> enumerator3 = item.nodes.GetEnumerator(); while (enumerator3.MoveNext()) { NewNode current3 = enumerator3.Current; if (Usable(current3) && current3.allowNewFurniture && current3.individualFurniture.Count <= 0) { float num2 = Vector3.Distance(current3.position, item.middleRoomPosition); if (num2 < num) { num = num2; val = current3; } } } if (val != null) { return (item, val.position); } } foreach (NewRoom item2 in list2) { List<Vector3> list3 = (from val3 in Nodes(item2) where val3 != null && val3.isIndoorsEntrance select val3.position).ToList(); NewNode val2 = null; float num3 = float.MinValue; Enumerator<NewNode> enumerator3 = item2.nodes.GetEnumerator(); while (enumerator3.MoveNext()) { NewNode n = enumerator3.Current; if (Usable(n) && n.walkableNodeSpace.Count != 0) { float num4 = ((list3.Count > 0) ? list3.Min((Vector3 d) => Vector3.Distance(d, n.position)) : (0f - Vector3.Distance(n.position, item2.middleRoomPosition))); if (n.individualFurniture.Count > 0) { num4 -= 100f; } if (num4 > num3) { num3 = num4; val2 = n; } } } if (val2 != null) { return (item2, val2.position); } } Plugin.Logger.LogInfo((object)(c.name + ": no room for a delivery crate in " + string.Join(", ", list2.Select((NewRoom r) => $"{r.name} ({r.nodes.Count} tiles, {Nodes(r).Count((NewNode n2) => Usable(n2))} floor, {Nodes(r).Count((NewNode val3) => Usable(val3) && val3.walkableNodeSpace.Count > 0)} walkable)")))); return null; bool Usable(NewNode val3) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Invalid comparison between Unknown and I4 if (val3 != null && !val3.isObstacle && !val3.noPassThrough && !val3.isIndoorsEntrance && ((int)val3.floorType == 1 || (int)val3.floorType == 2)) { return !taken.Any((Vector3 t) => Vector3.Distance(t, val3.position) < 1f); } return false; } } private static List<NewNode> Nodes(NewRoom r) { List<NewNode> list = new List<NewNode>(); Enumerator<NewNode> enumerator = r.nodes.GetEnumerator(); while (enumerator.MoveNext()) { NewNode current = enumerator.Current; list.Add(current); } return list; } private static int Rank(NewRoom r) { string[] array = new string[5]; RoomConfiguration obj = r.preset; array[0] = ((obj != null) ? ((Object)obj).name : null); array[1] = " "; RoomTypePreset roomType = r.roomType; array[2] = ((roomType != null) ? ((Object)roomType).name : null); array[3] = " "; array[4] = r.name; string text = string.Concat(array).ToLowerInvariant(); for (int i = 0; i < RoomPreference.Length; i++) { if (RoomPreference[i].Any(text.Contains)) { return i; } } return RoomPreference.Length; } [HarmonyPatch(typeof(Interactable), "IsSaveStateEligable")] [HarmonyPostfix] private static void NotSaved(Interactable __instance, ref bool __result) { if (__result && ids.Count > 0 && ids.Contains(__instance.id)) { __result = false; } } } [HarmonyPatch] internal static class DecorPatch { private static NewAddress lent; private static readonly int Emissive = Shader.PropertyToID("_EmissiveColor"); private static float nextGlowLog; private static bool Editing => (Object)(object)lent != (Object)null; private static NewAddress OwnedBusinessHere() { Player instance = Player.Instance; object obj; if (instance == null) { obj = null; } else { NewGameLocation currentGameLocation = ((Actor)instance).currentGameLocation; obj = ((currentGameLocation != null) ? currentGameLocation.thisAsAddress : null); } NewAddress val = (NewAddress)obj; if (!((Object)(object)val != (Object)null) || Store.Get(val.company) == null) { return null; } return val; } private static bool DecorAllowed() { if (!Game.Instance.sandboxMode) { if ((Object)(object)ChapterController.Instance != (Object)null) { return ChapterController.Instance.currentPart >= 30; } return false; } return true; } private static void Lend(NewAddress address) { if (!((Object)(object)lent != (Object)null) && !((Object)(object)address == (Object)null) && !Player.Instance.apartmentsOwned.Contains(address)) { Player.Instance.apartmentsOwned.Add(address); lent = address; } } internal static void Return() { if ((Object)(object)lent == (Object)null) { return; } try { Player instance = Player.Instance; if (instance != null) { instance.apartmentsOwned.Remove(lent); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Decor: couldn't hand the business back: " + ex.Message)); } lent = null; } [HarmonyPatch(typeof(BioScreenController), "UpdateDecorEditButton")] [HarmonyPostfix] private static void ShowButton(BioScreenController __instance) { try { if (!SessionData.Instance.isFloorEdit && DecorAllowed() && (Object)(object)OwnedBusinessHere() != (Object)null) { ((Component)__instance.editDecorButton).gameObject.SetActive(true); } } catch { } } [HarmonyPatch(typeof(BioScreenController), "DecorEditButton")] [HarmonyPrefix] private static bool StartEditing() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown try { NewAddress val = OwnedBusinessHere(); if ((Object)(object)val == (Object)null || SessionData.Instance.isDecorEdit || !DecorAllowed()) { return true; } Lend(val); InteractionController.Instance.StartDecorEdit(); ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(15, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Decor: editing "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val).name); } logger.LogInfo(val2); return false; } catch (Exception ex) { Plugin.Logger.LogError((object)("Decor: couldn't start editing: " + ex.Message)); Return(); return true; } } private static bool StillEditing() { if (SessionData.Instance.isDecorEdit) { return true; } PlayerApartmentController instance = PlayerApartmentController.Instance; if ((Object)(object)instance != (Object)null && (instance.furniturePlacementMode || instance.decoratingMode)) { return true; } Enumerator<InfoWindow> enumerator = InterfaceController.Instance.activeWindows.GetEnumerator(); while (enumerator.MoveNext()) { InfoWindow current = enumerator.Current; if ((Object)(object)current != (Object)null && (SoCustomComparison)(object)current.preset != (SoCustomComparison)null && ((Object)current.preset).name == "ApartmentDecor") { return true; } } return false; } [HarmonyPatch(typeof(Player), "Update")] [HarmonyPostfix] private static void Watch() { if ((Object)(object)lent == (Object)null) { return; } try { NewGameLocation currentGameLocation = ((Actor)Player.Instance).currentGameLocation; NewAddress val = ((currentGameLocation != null) ? currentGameLocation.thisAsAddress : null); if (!StillEditing() || (Object)(object)val == (Object)null || ((Il2CppObjectBase)val).Pointer != ((Il2CppObjectBase)lent).Pointer) { Return(); } } catch { Return(); } } [HarmonyPatch(typeof(PlayerApartmentController), "ApplyDecor")] [HarmonyPostfix] private static void RememberCeiling(PlayerApartmentController __instance, MaterialType decorType, bool saveChanges) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown if (!Editing || !saveChanges || (int)decorType != 2) { return; } try { NewRoom decoratingRoom = __instance.decoratingRoom; Business business = Store.Get(lent.company); if (!((Object)(object)decoratingRoom == (Object)null) && business != null) { if (!business.PaintedCeilings.Contains(decoratingRoom.roomID)) { business.PaintedCeilings.Add(decoratingRoom.roomID); } int num = TintGlow(decoratingRoom); ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(60, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Decor: painted ceiling in "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(decoratingRoom.name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (room "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(decoratingRoom.roomID); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("); glow tinted on "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" piece(s)"); } logger.LogInfo(val); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Decor: couldn't record the painted ceiling: " + ex.Message)); } } private static int TintGlow(NewRoom room) { //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_00ac: 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_003a: 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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_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_0096: 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_009c: 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_00a2: 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) if ((SoCustomComparison)(object)((room != null) ? room.preset : null) == (SoCustomComparison)null) { return 0; } Color target = Color.black; if (room.mainLightStatus) { Color val = ((room.lightZones != null && room.lightZones.Count > 0) ? room.lightZones[0].areaLightColour : Color.white); Color val2 = ((room.ceilingMatKey != (MaterialKey)null && room.ceilingMatKey.mainColour != Color.clear) ? room.ceilingMatKey.mainColour : Color.white); target = room.preset.ceilingEmissionBoost * val * val2; } int num = 0; num += SetGlow(room.ceilingMat, target); num += SetGlow(room.combinedCeiling, target); Enumerator<NewNode> enumerator = room.nodes.GetEnumerator(); while (enumerator.MoveNext()) { NewNode current = enumerator.Current; if (current != null) { num += SetGlow(current.spawnedCeiling, target); } } return num; } private static int SetGlow(GameObject ceiling, Color target) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ceiling == (Object)null) { return 0; } int num = 0; foreach (MeshRenderer componentsInChild in ceiling.GetComponentsInChildren<MeshRenderer>(true)) { foreach (Material item in (Il2CppArrayBase<Material>)(object)((Renderer)componentsInChild).sharedMaterials) { num += SetGlow(item, target); } } return num; } private static int SetGlow(Material mat, Color target) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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_0077: 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_0043: 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_005c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)mat == (Object)null || !mat.HasProperty(Emissive)) { return 0; } Color color = mat.GetColor(Emissive); if (Mathf.Abs(color.r - target.r) < 0.01f && Mathf.Abs(color.g - target.g) < 0.01f && Mathf.Abs(color.b - target.b) < 0.01f) { return 0; } mat.SetColor(Emissive, target); return 1; } [HarmonyPatch(typeof(Player), "Update")] [HarmonyPostfix] private static void KeepCeilingsPainted() { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown try { Player instance = Player.Instance; object c; if (instance == null) { c = null; } else { NewGameLocation currentGameLocation = ((Actor)instance).currentGameLocation; if (currentGameLocation == null) { c = null; } else { NewAddress thisAsAddress = currentGameLocation.thisAsAddress; c = ((thisAsAddress != null) ? thisAsAddress.company : null); } } Business business = Store.Get((Company)c); if (business == null || business.PaintedCeilings.Count == 0) { return; } NewRoom val = default(NewRoom); bool flag = default(bool); foreach (int paintedCeiling in business.PaintedCeilings) { if (CityData.Instance.roomDictionary.TryGetValue(paintedCeiling, ref val) && TintGlow(val) > 0 && Time.unscaledTime >= nextGlowLog) { nextGlowLog = Time.unscaledTime + 5f; ManualLogSource logger = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(56, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Decor: the game reset the ceiling glow in "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val.name); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("; tinted again"); } logger.LogInfo(val2); } } } catch { } } private static bool Refuse(string what) { Plugin.Message("That belongs to the business. It stays where it is.", good: false); Plugin.Logger.LogInfo((object)("Decor: kept " + what)); return false; } private static bool Locked(FurnitureLocation furniture) { if (Editing && furniture != null && !furniture.userPlaced) { return !IsRefuse(furniture); } return false; } private static bool IsRefuse(FurnitureLocation furniture) { FurniturePreset furniture2 = furniture.furniture; string text = ((furniture2 == null) ? null : ((Object)furniture2).name?.ToLowerInvariant()); if (text == null || text.Contains("bin")) { return false; } if (!text.Contains("litter") && !text.Contains("ceilingrot") && !text.StartsWith("junk")) { return text.Contains("cardboardbox"); } return true; } private static bool Locked(Interactable item) { if (!Editing || item == null || IsRefuse(item)) { return false; } Human belongsTo = item.belongsTo; if (!((Object)(object)belongsTo == (Object)null) && !((Object)(object)Player.Instance == (Object)null)) { return ((Il2CppObjectBase)belongsTo).Pointer != ((Il2CppObjectBase)Player.Instance).Pointer; } return true; } private static bool IsRefuse(Interactable item) { try { InteractablePreset preset = item.preset; if ((SoCustomComparison)(object)preset == (SoCustomComparison)null || (Object)(object)item.inInventory != (Object)null || item.jobParent != null || IsBin(item) || IsCaseEvidence(item)) { return false; } CleanupController instance = CleanupController.Instance; if ((Object)(object)instance != (Object)null && instance.trash.Contains(item)) { return true; } if ((SoCustomComparison)(object)preset.retailItem != (SoCustomComparison)null && preset.retailItem.isConsumable && item.cs <= 0.1f) { return true; } if (preset.markAsTrashOnCreate) { return true; } SubObject subObject = item.subObject; object obj; if (subObject == null) { obj = null; } else { SubObjectClassPreset preset2 = subObject.preset; obj = ((preset2 != null) ? ((Object)preset2).name : null); } string text = (string)obj; if (text != null && text.Contains("Junk")) { return true; } return ((Object)preset).name != null && ((Object)preset).name.StartsWith("CardboardBox"); } catch { return false; } } private static bool IsBin(Interactable item) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Invalid comparison between Unknown and I4 if ((int)item.preset.specialCaseFlag == 42) { return true; } if ((Object)(object)item.preset.prefab != (Object)null && item.preset.prefab.CompareTag("Garbage")) { return true; } if ((Object)(object)item.spawnedObject != (Object)null) { return item.spawnedObject.CompareTag("Garbage"); } return false; } private static bool IsCaseEvidence(Interactable item) { MurderController instance = MurderController.Instance; if ((Object)(object)instance == (Object)null) { return false; } List<Murder>[] array = new List<Murder>[2] { instance.activeMurders, instance.inactiveMurders }; foreach (List<Murder> val in array) { if (val == null) { continue; } Enumerator<Murder> enumerator = val.GetEnumerator(); while (enumerator.MoveNext()) { Murder current = enumerator.Current; if (current != null && ((current.weapon != null && current.weapon.id == item.id) || (current.ammo != null && current.ammo.id == item.id) || (current.callingCard != null && current.callingCard.id == item.id))) { return true; } } } return false; } [HarmonyPatch(typeof(PlayerApartmentController), "SetFurniturePlacementMode")] [HarmonyPrefix] private static bool NoMoving(bool val, FurniturePlacement newPlacement) { if (!val || ((newPlacement != null) ? newPlacement.existing : null) == null || newPlacement.existing.id == 0) { return true; } if (Locked(newPlacement.existing)) { FurniturePreset furniture = newPlacement.existing.furniture; return Refuse((furniture != null) ? ((Object)furniture).name : null); } return true; } [HarmonyPatch(typeof(PlayerApartmentController), "MoveFurnitureToStorage")] [HarmonyPrefix] private static bool NoStoring(FurnitureLocation newStorage) { if (Locked(newStorage)) { FurniturePreset furniture = newStorage.furniture; return Refuse((furniture != null) ? ((Object)furniture).name : null); } return true; } [HarmonyPatch(typeof(PlayerApartmentController), "SellFurniture")] [HarmonyPrefix] private static bool NoSelling(FurnitureLocation newSell) { if (Locked(newSell)) { FurniturePreset furniture = newSell.furniture; return Refuse((furniture != null) ? ((Object)furniture).name : null); } return true; } [HarmonyPatch(typeof(PlayerApartmentController), "MoveItemToStorage")] [HarmonyPrefix] private static bool NoStoringItems(Interactable newStorage) { if (Locked(newStorage)) { InteractablePreset preset = newStorage.preset; return Refuse((preset != null) ? ((Object)preset).name : null); } return true; } [HarmonyPatch(typeof(PlayerApartmentController), "SellItem")] [HarmonyPrefix] private static bool NoSellingItems(Interactable newSell) { if (Locked(newSell)) { InteractablePreset preset = newSell.preset; return Refuse((preset != null) ? ((Object)preset).name : null); } return true; } } internal static class Dialogs { private sealed class SellLogic : IDialogLogic { private readonly bool viaStaff; public SellLogic(bool viaStaff) { this.viaStaff = viaStaff; } public bool IsDialogShown(DialogPreset preset, Citizen saysTo, SideJob jobRef) { return Returnable((Human)(object)saysTo, viaStaff) != null; } public ForceSuccess ShouldDialogSucceedOverride(DialogController instance, DialogOption dialog, Citizen saysTo, NewNode where, Actor saidBy) { if (Returnable((Human)(object)saysTo, viaStaff) != null) { return (ForceSuccess)1; } return (ForceSuccess)2; } public void OnDialogExecute(DialogController instance, Citizen saysTo, Interactable saysToInteractable, NewNode where, Actor saidBy, bool success, NewRoom roomRef, SideJob jobRef) { if (!success) { return; } try { Company val = Returnable((Human)(object)saysTo, viaStaff); if (val != null) { Store.Sell(val, out var message); Plugin.Message(message); Plugin.Logger.LogInfo((object)message); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Selling failed: " + ex)); } } } private sealed class BuyLogic : IDialogLogic { private readonly bool viaStaff; public BuyLogic(bool viaStaff) { this.viaStaff = viaStaff; } public bool IsDialogShown(DialogPreset preset, Citizen saysTo, SideJob jobRef) { return ForSale((Human)(object)saysTo, viaStaff) != null; } public ForceSuccess ShouldDialogSucceedOverride(DialogController instance, DialogOption dialog, Citizen saysTo, NewNode where, Actor saidBy) { Company val = ForSale((Human)(object)saysTo, viaStaff); if (val != null && GameplayController.Instance.money >= Store.Price(val)) { return (ForceSuccess)1; } return (ForceSuccess)2; } public void OnDialogExecute(DialogController instance, Citizen saysTo, Interactable saysToInteractable, NewNode where, Actor saidBy, bool success, NewRoom roomRef, SideJob jobRef) { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected O, but got Unknown if (!success) { return; } try { Company val = ForSale((Human)(object)saysTo, viaStaff); if (val != null) { int num = Store.Price(val); Store.Buy(val, num); if (val.director.passcode != null) { GameplayController.Instance.AddPasscode(val.director.passcode, false); } Plugin.Message($"You now own {val.name}. Log in to its cruncher as {val.shortName}_Admin."); ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(62, 6, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Bought "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val.name); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" (company "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(val.companyID); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(") for ¢"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": regulars "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(Store.Regulars(val), "0.#"); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", "); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("land value "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(((Object)(object)val.address != (Object)null) ? val.address.normalizedLandValue : 0f, "0.00"); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", menu factor "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(Store.MenuFactor(val), "0.00"); } logger.LogInfo(val2); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Buying failed: " + ex)); } } } public const string BuyName = "Proprietor_Buy"; public const string SellName = "Proprietor_Sell"; public const string StaffBuyName = "Proprietor_BuyViaStaff"; public const string StaffSellName = "Proprietor_SellViaStaff"; public static void Register() { Lib.Dialogs.Builder("Proprietor_Buy").SetText("I'd like to buy your business.").SetDialogLogic((IDialogLogic)(object)new BuyLogic(viaStaff: false)) .ModifyDialogOptions((Action<DialogPreset>)delegate(DialogPreset p) { p.cost = 1; p.ranking = 5; }) .AddResponse("You've got yourself a deal. I'll stay on and keep the place running for you. The office cruncher's yours too.", true, true) .AddResponse("Come back when you've got the money.", false, true) .CreateAndRegister(); Lib.Dialogs.Builder("Proprietor_BuyViaStaff").SetText("I'd like to buy this business. Can you get the owner on the phone?").SetDialogLogic((IDialogLogic)(object)new BuyLogic(viaStaff: true)) .ModifyDialogOptions((Action<DialogPreset>)delegate(DialogPreset p) { p.cost = 1; p.ranking = 5; }) .AddResponse("Hang on, I'll call the boss... They say you've got a deal. They'll stay on and run the place for you.", true, true) .AddResponse("The boss says come back when you've got the money.", false, true) .CreateAndRegister(); Lib.Dialogs.Builder("Proprietor_SellViaStaff").SetText("Can you call the manager? I want to sell the business back to them.").SetDialogLogic((IDialogLogic)(object)new SellLogic(viaStaff: true)) .ModifyDialogOptions((Action<DialogPreset>)delegate(DialogPreset p) { p.ranking = 4; }) .AddResponse("One moment... They'll take it back. The money's on its way to you.", true, true) .CreateAndRegister(); Lib.Dialogs.Builder("Proprietor_Sell").SetText("I'd like to sell the business back to you.").SetDialogLogic((IDialogLogic)(object)new SellLogic(viaStaff: false)) .ModifyDialogOptions((Action<DialogPreset>)delegate(DialogPreset p) { p.ranking = 4; }) .AddResponse("If that's what you want. Here's your money; I'll take it from here.", true, true) .CreateAndRegister(); } public static Company SellerCompany(Human h) { if ((Object)(object)h == (Object)null || ((Actor)h).isPlayer) { return null; } Occupation job = h.job; Company val = ((job != null) ? job.employer : null); if (val != null && (Object)(object)val.director != (Object)null && val.director.humanID == h.humanID) { return val; } return null; } public static Company StaffOnShift(Human h) { if ((Object)(object)h == (Object)null || ((Actor)h).isPlayer || !((Actor)h).isAtWork) { return null; } Occupation job = h.job; Company val = ((job != null) ? job.employer : null); if (val == null || (Object)(object)val.address == (Object)null || (Object)(object)val.director == (Object)null || val.director.humanID == h.humanID) { return null; } NewGameLocation currentGameLocation = ((Actor)h).currentGameLocation; NewAddress val2 = ((currentGameLocation != null) ? currentGameLocation.thisAsAddress : null); if (!((Object)(object)val2 != (Object)null) || !(((Il2CppObjectBase)val2).Pointer == ((Il2CppObjectBase)val.address).Pointer)) { return null; } return val; } public static Company ForSale(Human h, bool viaStaff) { Company val = (viaStaff ? StaffOnShift(h) : SellerCompany(h)); if (val == null || !Store.Sellable(val)) { return null; } return val; } public static Company Returnable(Human h, bool viaStaff) { Company val = (viaStaff ? StaffOnShift(h) : ManagedForPlayer(h)); if (val == null || Store.Get(val) == null) { return null; } return val; } public static Company ManagedForPlayer(Human h) { if ((Object)(object)h == (Object)null || ((Actor)h).isPlayer) { return null; } Occupation job = h.job; Company val = ((job != null) ? job.employer : null); if (val == null || !((Object)(object)val.director != (Object)null) || val.director.humanID != h.humanID || Store.Get(val) == null) { return null; } return val; } } [HarmonyPatch(typeof(DialogPreset), "GetCost")] internal static class CostPatch { private static void Postfix(DialogPreset __instance, Actor talkingTo, ref int __result) { if ((SoCustomComparison)(object)__instance == (SoCustomComparison)null) { return; } string name = ((Object)__instance).name; if (name != "Proprietor_Buy" && name != "Proprietor_BuyViaStaff") { return; } try { Company val = Dialogs.ForSale((talkingTo != null) ? ((Il2CppObjectBase)talkingTo).TryCast<Human>() : null, name == "Proprietor_BuyViaStaff"); if (val != null) { __result = Store.Price(val); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Price lookup failed: " + ex.Message)); } } } [HarmonyPatch] internal static class LedgerApp { private enum RowKind { Till, Deposit, Item, Business, Back } private sealed class Row { public RowKind Kind; public string Item; public int Price; public int CompanyId; } public const string AppName = "BusinessLedger"; public const string Marker = "\u200b"; private const string Currency = "¢"; private static CruncherAppPreset preset; private static readonly Dictionary<IntPtr, Row> rows = new Dictionary<IntPtr, Row>(); private static readonly Dictionary<IntPtr, int> viewing = new Dictionary<IntPtr, int>(); private static readonly Dictionary<IntPtr, CruncherAppPreset> wizcardsRemoved = new Dictionary<IntPtr, CruncherAppPreset>(); internal static void Reset() { rows.Clear(); viewing.Clear(); } private static bool AtHome(ComputerController cc) { object obj; if (cc == null) { obj = null; } else { InteractableController ic = cc.ic; if (ic == null) { obj = null; } else { Interactable interactable = ic.interactable; if (interactable == null) { obj = null; } else { NewNode node = interactable.node; if (node == null) { obj = null; } else { NewGameLocation gameLocation = node.gameLocation; obj = ((gameLocation != null) ? gameLocation.thisAsAddress : null); } } } } NewAddress val = (NewAddress)obj; if ((Object)(object)val == (Object)null || (Object)(object)Player.Instance == (Object)null) { return false; } Enumerator<NewAddress> enumerator = Player.Instance.apartmentsOwned.GetEnumerator(); while (enumerator.MoveNext()) { NewAddress current = enumerator.Current; if ((Object)(object)current != (Object)null && ((Il2CppObjectBase)current).Pointer == ((Il2CppObjectBase)val).Pointer) { return true; } } return false; } private static Company Shown(ComputerController cc) { Company val = CompanyAt(cc); if (Store.Get(val) != null) { return val; } if (!AtHome(cc) || !viewing.TryGetValue(((Il2CppObjectBase)cc).Pointer, out var value)) { return null; } return Store.FindCompany(value); } private static bool IsLedger(ComputerController cc) { if ((SoCustomComparison)(object)preset != (SoCustomComparison)null && (Object)(object)cc != (Object)null && (SoCustomComparison)(object)cc.currentApp != (SoCustomComparison)null) { return ((Il2CppObjectBase)cc.currentApp).Pointer == ((Il2CppObjectBase)preset).Pointer; } return false; } private static Company CompanyAt(ComputerController cc) { if (cc == null) { return null; } InteractableController ic = cc.ic; if (ic == null) { return null; } Interactable interactable = ic.interactable; if (interactable == null) { return null; } NewNode node = interactable.node; if (node == null) { return null; } NewGameLocation gameLocation = node.gameLocation; if (gameLocation == null) { return null; } NewAddress thisAsAddress = gameLocation.thisAsAddress; if (thisAsAddress == null) { return null; } return thisAsAddress.company; } [HarmonyPatch(typeof(DesktopApp), "UpdateIcons")] [HarmonyPrefix] private static void Install(DesktopApp __instance) { try { ComputerController controller = ((CruncherAppContent)__instance).controller; object obj; if (controller == null) { obj = null; } else { InteractableController ic = controller.ic; if (ic == null) { obj = null; } else { Interactable interactable = ic.interactable; if (interactable == null) { obj = null; } else { InteractablePreset obj2 = interactable.preset; obj = ((obj2 != null) ? obj2.additionalApps : null); } } } List<CruncherAppPreset> val = (List<CruncherAppPreset>)obj; if (val == null) { return; } if ((SoCustomComparison)(object)preset == (SoCustomComparison)null) { Create(); } if ((SoCustomComparison)(object)preset == (SoCustomComparison)null) { return; } ComputerController controller2 = ((CruncherAppContent)__instance).controller; bool num = Store.Get(CompanyAt(controller2)) != null; bool flag = !num && Store.Owned.Count > 0 && AtHome(controller2); int num2 = IndexOf(val, (CruncherAppPreset a) => ((Il2CppObjectBase)a).Pointer == ((Il2CppObjectBase)preset).Pointer); if (num) { if (num2 < 0) { int num3 = IndexOf(val, IsWizcards); if (num3 >= 0) { wizcardsRemoved[((Il2CppObjectBase)val).Pointer] = val[num3]; val[num3] = preset; } else { val.Add(preset); } } return; } if (num2 >= 0 && wizcardsRemoved.TryGetValue(((Il2CppObjectBase)val).Pointer, out var value)) { val[num2] = value; wizcardsRemoved.Remove(((Il2CppObjectBase)val).Pointer); num2 = -1; } if (flag && num2 < 0) { val.Add(preset); } else if (!flag && num2 >= 0) { val.RemoveAt(num2); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Couldn't set up the Business Ledger: " + ex)); } } private static int IndexOf(List<CruncherAppPreset> apps, Func<CruncherAppPreset, bool> match) { for (int i = 0; i < apps.Count; i++) { if ((SoCustomComparison)(object)apps[i] != (SoCustomComparison)null && match(apps[i])) { return i; } } return -1; } private static bool IsWizcards(CruncherAppPreset app) { Enumerator<GameObject> enumerator = app.appContent.GetEnumerator(); while (enumerator.MoveNext()) { GameObject current = enumerator.Current; if ((Object)(object)current != (Object)null && (Object)(object)current.GetComponent<WizcardsApp>() != (Object)null) { return true; } } return false; } private static void Create() { //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown CruncherAppPreset val = null; foreach (CruncherAppPreset item in Resources.FindObjectsOfTypeAll<CruncherAppPreset>()) { if ((SoCustomComparison)(object)item != (SoCustomComparison)null && ((Object)item).name != "BusinessLedger" && IsSalesRecords(item)) { val = item; break; } } if (!((SoCustomComparison)(object)val == (SoCustomComparison)null)) { preset = Object.Instantiate<CruncherAppPreset>(val); ((Object)preset).name = "BusinessLedger"; preset.alwaysInstalled = true; preset.companyOnly = false; preset.salesRecordsOnly = false; preset.onlyIfOwner = false; preset.onlyIfResidential = false; preset.onlyIfCorporateSabotageSkill = false; preset.installationConditions = new List<AppAccess>(); preset.onlyInAddresses = new List<AddressPreset>(); Object.DontDestroyOnLoad((Object)(object)preset); ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(39, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Business Ledger program created from '"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val).name); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'"); } logger.LogInfo(val2); } } private static bool IsSalesRecords(CruncherAppPreset app) { Enumerator<GameObject> enumerator = app.appContent.GetEnumerator(); while (enumerator.MoveNext()) { GameObject current = enumerator.Current; if ((Object)(object)current != (Object)null && (Object)(object)current.GetComponent<SalesRecordsApp>() != (Object)null) { return true; } } return false; } [HarmonyPatch(typeof(DesktopIconController), "Setup")] [HarmonyPostfix] private static void IconName(DesktopIconController __instance, CruncherAppPreset newApp) { if ((SoCustomComparison)(object)preset != (SoCustomComparison)null && (SoCustomComparison)(object)newApp != (SoCustomComparison)null && ((Il2CppObjectBase)newApp).Pointer == ((Il2CppObjectBase)preset).Pointer) { ((TMP_Text)__instance.iconText).text = "Business Ledger"; } } [HarmonyPatch(typeof(SalesRecordsApp), "UpdateEntries")] [HarmonyPrefix] private static bool Entries(SalesRecordsApp __instance) { if (!IsLedger(((CruncherAppContent)__instance).controller)) { return true; } try { Fill(__instance); } catch (Exception ex) { Plugin.Logger.LogError((object)("Business Ledger couldn't list: " + ex)); } return false; } private static void Fill(SalesRecordsApp app) { ComputerController controller = ((CruncherAppContent)app).controller; bool flag = AtHome(controller) && Store.Get(CompanyAt(controller)) == null; Company val = Shown(controller); Business business = Store.Get(val); rows.Clear(); List<OSMultiOption> val2 = new List<OSMultiOption>(); if (business == null && flag) { ((TMP_Text)app.titleText).text = "MY BUSINESSES"; foreach (Business item in Store.Owned.Values.OrderBy((Business x) => x.Name)) { val2.Add(Option(Summary(item), new Row { Kind = RowKind.Business, CompanyId = item.CompanyId })); } if (val2.Count == 0) { val2.Add(Option("You don't own any businesses.", null)); } app.list.UpdateElements(val2); app.UpdateSelected(); return; } ((TMP_Text)app.titleText).text = ((val != null) ? val.name.ToUpperInvariant() : "BUSINESS LEDGER"); if (business == null) { val2.Add(Option("You don't own this business.", null)); app.list.UpdateElements(val2); return; } if (flag) { val2.Add(Option("< ALL BUSINESSES\nBack to the list", new Row { Kind = RowKind.Back })); } float now = SessionData.Instance.gameTime; List<Sale> list = business.Sales.Where((Sale s) => now - s.Time <= 24f).ToList(); int num = Store.StaffCount(val); int num2 = business.Transfers.Sum((Transfer t) => t.Amount); val2.Add(Option($"TILL: {"¢"}{business.Till}" + ((Store.Float(business) > 0) ? $" (keeps {"¢"}{Store.Float(business)})" : "") + ((num2 > 0) ? $"\n{"¢"}{num2} on its way to you" : "") + "\n" + OpenState(val) + $"\n24h: {list.Count} sales, {"¢"}{list.Sum((Sale s) => s.Total)}, {business.TurnedAway} turned away" + $"\n{(business.ManagerRestocks ? "Wages+raise" : "Wages")}: {"¢"}{num * Plugin.WagePerStaff.Value + (business.ManagerRestocks ? Plugin.ManagerRaise.Value : 0)}/day", new Row { Kind = RowKind.Till, CompanyId = business.CompanyId })); val2.Add(Option($"PUT MONEY IN\nFrom your wallet, {"¢"}{Plugin.DepositStep.Value} at a time\nPays wages and the manager's restocking", new Row { Kind = RowKind.Deposit, CompanyId = business.CompanyId })); foreach (KeyValuePair<InteractablePreset, int> item2 in Store.Menu(val)) { string name = ((Object)item2.Key).name; int value; int num3 = (business.Stock.TryGetValue(name, out value) ? value : 0); List<Order> list2 = business.Orders.Where((Order o) => o.Item == name).ToList(); string text = $"{Store.ItemName(name)}: {((num3 > 0) ? (num3 + " in stock") : "OUT OF STOCK")}\nPrice {"¢"}{item2.Value}\nCost {"¢"}{Store.UnitCost(item2.Value)}"; foreach (Order item3 in list2) { int num4 = Store.DaysUntil(item3.Arrives); text += $"\n+{item3.Quantity} due {((num4 <= 0) ? "today" : ((num4 == 1) ? "tomorrow" : $"in {num4} days"))}"; } val2.Add(Option(text, new Row { Kind = RowKind.Item, Item = name, Price = item2.Value, CompanyId = business.CompanyId })); } foreach (Sale item4 in business.Sales.Take(40)) { string text2 = SessionData.Instance.TimeAndDate(item4.Time, false, true, true) + " " + item4.Customer; string text3 = string.Join("\n", item4.Items.Select((SaleItem i) => "<align=\"left\">" + Store.ItemName(i.Item) + " <align=\"right\">¢" + i.Price)); val2.Add(Option(text2 + "\n" + text3, null)); } app.list.UpdateElements(val2); app.UpdateSelected(); } private static string OpenState(Company c) { int num = c.currentStaff?.Count ?? 0; int value = Store.StaffCount(c); string value2 = ((!c.openForBusinessDesired) ? "Closed (hours)" : (c.openForBusinessActual ? "Open" : "Closed (no staff in)")); if (num == 0 && Plugin.LogEachSale.Value) { LogStaff(c); } return $"{value2}, {num}/{value} staff in"; } private static void LogStaff(Company c) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_005e: 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_00dc: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown try { ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(36, 5, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Staff] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(c.name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" at "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(SessionData.Instance.decimalClock, "0.00"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<WeekDay>(SessionData.Instance.day); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): open="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(c.openForBusinessActual); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", wanted open="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(c.openForBusinessDesired); } logger.LogInfo(val); Enumerator<Occupation> enumerator = c.companyRoster.GetEnumerator(); while (enumerator.MoveNext()) { Occupation current = enumerator.Current; Human val2 = ((current != null) ? current.employee : null); if ((Object)(object)val2 == (Object)null) { ManualLogSource logger2 = Plugin.Logger; val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Staff] "); BepInExInfoLogInterpolatedStringHandler obj = val; object obj2; if (current == null) { obj2 = null; } else { OccupationPreset obj3 = current.preset; obj2 = ((obj3 != null) ? ((Object)obj3).name : null); } ((BepInExLogInterpolatedStringHandler)obj).AppendFormatted<string>((string)obj2); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": vacant"); } logger2.LogInfo(val); continue; } List<string> list = new List<string>(); Enumerator<WeekDay> enumerator2 = current.workDaysList.GetEnumerator(); while (enumerator2.MoveNext()) { list.Add(((object)enumerator2.Current/*cast due to .constrained prefix*/).ToString().Substring(0, 3)); } ManualLogSource logger3 = Plugin.Logger; val = new BepInExInfoLogInterpolatedStringHandler(59, 10, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Staff] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(val2.GetCitizenName()); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ("); BepInExInfoLogInterpolatedStringHandler obj4 = val; OccupationPreset obj5 = current.preset; ((BepInExLogInterpolatedStringHandler)obj4).AppendFormatted<string>((obj5 != null) ? ((Object)obj5).name : null); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") shift "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(current.startTimeDecimalHour, "0.#"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("-"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(current.endTimeDecialHour, "0.#"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(string.Join("/", list)); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("atWork="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(((Actor)val2).isAtWork); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" dead="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(((Actor)val2).isDead); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" asleep="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(((Actor)val2).isAsleep); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" at '"); BepInExInfoLogInterpolatedStringHandler obj6 = val; NewGameLocation currentGameLocation = ((Actor)val2).currentGameLocation; ((BepInExLogInterpolatedStringHandler)obj6).AppendFormatted<string>((currentGameLocation != null) ? ((Object)currentGameLocation).name : null); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' goal '"); BepInExInfoLogInterpolatedStringHandler obj7 = val; NewAIController ai = ((Actor)val2).ai; object obj8; if (ai == null) { obj8 = null; } else { NewAIGoal currentGoal = ai.currentGoal; if (currentGoal == null) { obj8 = null; } else { AIGoalPreset obj9 = currentGoal.preset; obj8 = ((obj9 != null) ? ((Object)obj9).name : null); } } ((BepInExLogInterpolatedStringHandler)obj7).AppendFormatted<string>((string)obj8); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'"); } logger3.LogInfo(val); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Staff log failed: " + ex.Message)); } } private static string Summary(Business b) { float now = SessionData.Instance.gameTime; List<Sale> list = b.Sales.Where((Sale s) => now - s.Time <= 24f).ToList(); int num = b.Stock.Count((KeyValuePair<string, int> kv) => kv.Value <= Plugin.LowStock.Value); return $"{b.Name}\nTill {"¢"}{b.Till}\n24h: {list.Count} sales, {"¢"}{list.Sum((Sale s) => s.Total)}\n" + ((num > 0) ? $"LOW STOCK: {num} item{((num == 1) ? "" : "s")}" : "Stock OK") + ((b.Orders.Count > 0) ? $"\nOrders due: {b.Orders.Count}" : ""); } private static OSMultiOption Option(string text, Row row) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown OSMultiOption val = new OSMultiOption("\u200b" + text, (Human)null); if (row != null) { rows[((Il2CppObjectBase)val).Pointer] = row; } return val; } private static Row Selected(SalesRecordsApp app) { ComputerOSMultiSelect list = app.list; object obj; if (list == null) { obj = null; } else { ComputerOSMultiSelectElement selected = list.selected; obj = ((selected != null) ? selected.option : null); } OSMultiOption val = (OSMultiOption)obj; if (val == null || !rows.TryGetValue(((Il2CppObjectBase)val).Pointer, out var value)) { return null; } return value; } [HarmonyPatch(typeof(ComputerOSMultiSelectElement), "Setup")] [HarmonyPostfix] private static void RowText(ComputerOSMultiSelectElement __instance, OSMultiOption newOpt) { string text = ((newOpt != null) ? newOpt.text : null); if (text != null && text.StartsWith("\u200b")) { int num = text.IndexOf('\n'); ((TMP_Text)__instance.elementText).text = ((num < 0) ? text : text.Substring(0, num)).Substring("\u200b".Length); if ((Object)(object)__instance.elementText2 != (Object)null) { ((TMP_Text)__instance.elementText2).text = ((num < 0) ? "" : text.Substring(num + 1)); } } } [HarmonyPatch(typeof(SalesRecordsApp), "UpdateSelected")] [HarmonyPostfix] private static void ActionButton(SalesRecordsApp __instance) { if (!IsLedger(((CruncherAppContent)__instance).controller) || (Object)(object)__instance.printButton == (Object)null) { return; } try { Row row = Selected(__instance); Business business = ((row != null) ? Store.Get(Store.FindCompany(row.CompanyId)) : null); bool flag = Store.Get(CompanyAt(((CruncherAppContent)__instance).controller)) == null; string text; switch (row?.Kind) { case RowKind.Back: text = "BACK"; break; case RowKind.Business: text = "OPEN"; break; case RowKind.Deposit: if (business != null) { text = $"DEPOSIT {"¢"}{Plugin.DepositStep.Value}"; break; } goto default; case RowKind.Till: if (business != null && flag) { text = $"TRANSFER {"¢"}{Store.TransferNet(Store.Collectable(business))}"; break; } if (business != null) { text = $"COLLECT {"¢"}{Store.Collectable(business)}"; break; } goto default; case RowKind.Item: if (business != null) { text = $"ORDER {Store.OrderSize(Store.FindCompany(row.CompanyId))} - {"¢"}{Store.UnitCost(row.Price) * Store.OrderSize(Store.FindCompany(row.CompanyId))}"; break; } goto default; default: text = null; break; } string text2 = text; ((Component)__instance.printButton).gameObject.SetActive(text2 != null); TextMeshProUGUI val = ((text2 != null) ? Label(__instance) : null); if ((Object)(object)val != (Object)null) { ((TMP_Text)val).text = text2; } } catch (Exception ex) { Plugin.Logger.LogError((object)("Business Ledger button failed: " + ex.Message)); } } private static TextMeshProUGUI Label(SalesRecordsApp app) { TextMeshProUGUI componentInChildren = ((Component)app.printButton).GetComponentInChildren<TextMeshProUGUI>(true); if ((Object)(object)componentInChildren == (Object)null) { return null; } ComputerAutoTextController component = ((Component)componentInChildren).GetComponent<ComputerAutoTextController>(); if ((Object)(object)component != (Object)null && ((Behaviour)component).enabled) { ((Behaviour)component).enabled = false; Widen(app.printButton, 2.5f); ((TMP_Text)componentInChildren).fontSizeMax = ((TMP_Text)componentInChildren).fontSize; ((TMP_Text)componentInChildren).fontSizeMin = ((TMP_Text)componentInChildren).fontSize * 0.6f; ((TMP_Text)componentInChildren).enableAutoSizing = true; ((TMP_Text)componentInChildren).enableWordWrapping = false; ((TMP_Text)componentInChildren).overflowMode = (TextOverflowModes)3; ((TMP_Text)componentInChildren).alignment = (TextAlignmentOptions)514; } return componentInChildren; } private static void Widen(RectTransform rect, float factor) { //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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_0054: 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) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_0107: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) try { Rect rect2 = rect.rect; float width = ((Rect)(ref rect2)).width; float num = width * (factor - 1f); ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(47, 6, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Button] width "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(width); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", anchors "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector2>(rect.anchorMin); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("-"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector2>(rect.anchorMax); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", pivot "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector2>(rect.pivot); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", pos "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector2>(rect.anchoredPosition); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", size "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector2>(rect.sizeDelta); } logger.LogInfo(val); LayoutElement component = ((Component)rect).GetComponent<LayoutElement>(); if ((Object)(object)component != (Object)null) { if (component.preferredWidth > 0f) { component.preferredWidth = width * factor; } if (component.minWidth > 0f) { component.minWidth = width * factor; } } rect.sizeDelta = new Vector2(rect.sizeDelta.x + num, rect.sizeDelta.y); rect.anchoredPosition = new Vector2(rect.anchoredPosition.x - num * (1f - rect.pivot.x), rect.anchoredPosition.y); } catch (Exception ex) { Plugin.Logger.LogError((object)("Couldn't widen the button: " + ex.Message)); } } private static void LogHierarchy(Transform t, int depth) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown List<string> list = new List<string>(); foreach (Component component in ((Component)t).GetComponents<Component>()) { list.Add(((MemberInfo)((Object)component).GetIl2CppType()).Name); } ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(12, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Button] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(new string(' ', depth * 2)); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)t).name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(string.Join(", ", list)); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")"); } logger.LogInfo(val); for (int i = 0; i < t.childCount; i++) { LogHierarchy(t.GetChild(i), depth + 1); } } [HarmonyPatch(typeof(SalesRecordsApp), "OnPrintEntry")] [HarmonyPrefix] private static bool Action(SalesRecordsApp __instance) { //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Expected O, but got Unknown //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Expected O, but got Unknown //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Expected O, but got Unknown if (!IsLedger(((CruncherAppContent)__instance).controller)) { return true; } try { Row row = Selected(__instance); if (row == null) { return false; } ComputerController controller = ((CruncherAppContent)__instance).controller; if (row.Kind == RowKind.Business || row.Kind == RowKind.Back) { if (row.Kind == RowKind.Business) { viewing[((Il2CppObjectBase)controller).Pointer] = row.CompanyId; } else { viewing.Remove(((Il2CppObjectBase)controller).Pointer); } Sound(controller, AudioControls.Instance.computerPrint); __instance.list.page = 0; Fill(__instance); __instance.OnChangePage(); return false; } Business business = Store.Get(Store.FindCompany(row.CompanyId)); if (business == null) { return false; } bool flag = Store.Get(CompanyAt(controller)) == null; bool flag2 = default(bool); if (row.Kind == RowKind.Deposit) { int value = Plugin.DepositStep.Value; if (GameplayController.Instance.money < value) { Plugin.Message($"You don't have {"¢"}{value} on you.", good: false); Sound(controller, AudioControls.Instance.computerInvalidPasscode); return false; } GameplayController.Instance.AddMoney(-value, true, "proprietor_deposit"); business.Till += value; ManualLogSource logger = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(25, 3, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(business.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": deposited ¢"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", till now ¢"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(business.Till); } logger.LogInfo(val); Sound(controller, AudioControls.Instance.computerPrint); } else if (row.Kind == RowKind.Till) { if (Store.Collectable(business) <= 0) { int value2 = Store.Float(business); Plugin.Message((business.Till <= 0) ? "The till is empty." : $"The till only holds what it needs for wages and stock ({"¢"}{value2}).", good: false); Sound(controller, AudioControls.Instance.computerInvalidPasscode); return false; } if (flag) { string text = Store.Transfer(business); Plugin.Message(text); ManualLogSource logger2 = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(2, 2, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(business.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); } logger2.LogInfo(val); } else { int num = Store.Collectable(business); GameplayController.Instance.AddMoney(num, true, "proprietor_collect"); business.Till -= num; ManualLogSource logger3 = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(33, 3, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(business.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": collected ¢"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", left ¢"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(business.Till); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" in the till"); } logger3.LogInfo(val); } Sound(controller, AudioControls.Instance.computerPrint); } else { string message; bool flag3 = Store.PlaceOrder(business, row.Item, row.Price, out message); Plugin.Message(message, flag3); ManualLogSource logger4 = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(2, 2, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(business.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(message); } logger4.LogInfo(val); Sound(controller, flag3 ? AudioControls.Instance.computerPrint : AudioControls.Instance.computerInvalidPasscode); } int page = __instance.list.page; Fill(__instance); if (page != __instance.list.page) { __instance.list.NextPage(page - __instance.list.page); } __instance.OnChangePage(); } catch (Exception ex) { Plugin.Logger.LogError((object)("Business Ledger action failed: " + ex)); } return false; } private static void Sound(ComputerController cc, AudioEvent e) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) try { AudioController.Instance.PlayWorldOneShot(e, (Actor)(object)Player.Instance, cc.ic.interactable.node, cc.ic.interactable.wPos, (Interactable)null, (List<FMODParam>)null, 1f, (List<NewNode>)null, false, (SoundMaterialOverride)null, false); } catch { } } } [HarmonyPatch(typeof(ComputerOSMultiSelect), "SpawnList")] internal static class LedgerListPatch { private static bool Prefix(ComputerOSMultiSelect __instance) { //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) List<OSMultiOption> allOptions = __instance.allOptions; if (allOptions != null && allOptions.Count != 0) { OSMultiOption obj = allOptions[0]; if (((obj != null) ? obj.text : null) != null && allOptions[0].text.StartsWith("\u200b")) { try { Enumerator<ComputerOSMultiSelectElement> enumerator = __instance.options.GetEnumerator(); while (enumerator.MoveNext()) { ComputerOSMultiSelectElement current = enumerator.Current; if ((Object)(object)current != (Object)null) { Object.Destroy((Object)(object)((Component)current).gameObject); } } __instance.options.Clear(); int num = (__instance.usePages ? (__instance.page * __instance.maxPerPage) : 0); int num2 = (__instance.usePages ? (num + __instance.maxPerPage) : allOptions.Count); float num3 = 0f; for (int i = num; i < num2 && i < allOptions.Count; i++) { ComputerOSMultiSelectElement component = Object.Instantiate<GameObject>(__instance.elementPrefab, (Transform)(object)__instance.elementParent).GetComponent<ComputerOSMultiSelectElement>(); component.Setup(allOptions[i], __instance); component.rect.anchoredPosition = new Vector2(0f, num3); num3 -= component.rect.sizeDelta.y; __instance.options.Add(component); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Business Ledger couldn't draw its list: " + ex.Message)); } return false; } } return true; } } public class FavouriteChange { public int HumanId { get; set; } public int Category { get; set; } public int AddressId { get; set; } public int OriginalAddressId { get; set; } } internal static class Loyalty { private const string FileName = "proprietor_regulars.json"; private static Dictionary<(int, int), FavouriteChange> changes = new Dictionary<(int, int), FavouriteChange>(); private static readonly CompanyCategory[] Errands; public static void Load(SaveGameArgs args) { //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_007d: 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) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) changes = new Dictionary<(int, int), FavouriteChange>(); try { string saveGameDataPath = Lib.SaveGame.GetSaveGameDataPath(args, "proprietor_regulars.json"); if (!File.Exists(saveGameDataPath)) { return; } int num = 0; NewAddress val4 = default(NewAddress); foreach (FavouriteChange item in JsonSerializer.Deserialize<List<FavouriteChange>>(File.ReadAllText(saveGameDataPath))) { Human val = FindHuman(item.HumanId); NewAddress val2 = FindAddress(item.AddressId); if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null)) { CompanyCategory val3 = (CompanyCategory)item.Category; if (val.favouritePlaces.TryGetValue(val3, ref val4) && (Object)(object)val4 != (Object)null) { item.OriginalAddressId = val4.id; } SetFavourite(val, val3, val2); changes[(item.HumanId, item.Category)] = item; num++; } } ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(45, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Regulars: "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(num); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" changed favourite place(s) applied"); } logger.LogInfo(val5); } catch (Exception ex) { Plugin.Logger.LogError((object)("Couldn't load regulars: " + ex)); } } public static void Save(SaveGameArgs args) { try { string saveGameDataPath = Lib.SaveGame.GetSaveGameDataPath(args, "proprietor_regulars.json"); if (changes.Count == 0) { if (File.Exists(saveGameDataPath)) { File.Delete(saveGameDataPath); } } else { File.WriteAllText(saveGameDataPath, JsonSerializer.Serialize(changes.Values.ToList(), new JsonSerializerOptions { WriteIndented = true })); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Couldn't save regulars: " + ex)); } } public static void Revert() { try { foreach (FavouriteChange value in changes.Values) { Human val = FindHuman(value.HumanId); NewAddress val2 = FindAddress(value.OriginalAddressId); if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null) { SetFavourite(val, (CompanyCategory)value.Category, val2); } } } catch (Exception ex) { Plugin.Logger.LogError((object)("Couldn't put regulars back: " + ex.Message)); } changes = new Dictionary<(int, int), FavouriteChange>(); } public static void TurnedAway(Business b, Company c, Human who) { //IL_0041: 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_0048: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown b.LastTurnedAway = SessionData.Instance.gameTime; if ((Object)(object)who == (Object)null || (Object)(object)((c != null) ? c.address : null) == (Object)null) { return; } bool flag = default(bool); foreach (CompanyCategory item in ErrandsFor(who, c)) { if (IsFavourite(who, item, c.address)) { string key = StrikeKey(who.humanID, item); b.Strikes[key] = (b.Strikes.TryGetValue(key, out var value) ? value : 0) + 1; ManualLogSource logger = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(35, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(b.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": regular "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(who.GetCitizenName()); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" turned away ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(b.Strikes[key]); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" strike(s))"); } logger.LogInfo(val); } } } public static void Served(Business b, Company c, Human who) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: 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) if ((Object)(object)who == (Object)null || (Object)(object)((c != null) ? c.address : null) == (Object)null || ((Actor)who).isDead) { return; } Occupation job = who.job; if ((((job != null) ? job.employer : null) != null && who.job.employer.companyID == c.companyID) || SessionData.Instance.gameTime - b.LastTurnedAway < 24f) { return; } foreach (CompanyCategory item in ErrandsFor(who, c)) { if (!IsFavourite(who, item, c.address) && !(Random.value > Plugin.WinChance.Value)) { NewAddress val = Change(who, item, c.address); b.RegularsGained++; if (((val != null) ? val.company : null) != null) { Store.Get(val.company)?.RegularsLost.Add(c.name); } Plugin.Logger.LogInfo((object)($"{b.Name}: {who.GetCitizenName()} is a new regular for {item}" + (((Object)(object)val != (Object)null) ? (" (was " + ((Object)val).name + ")") : ""))); } } } public static void Midnight() { //IL_00a0: 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_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Expected O, but got Unknown //IL_017d: Unknown result type (might be due to invalid IL or missing references) bool flag = default(bool); foreach (Business value in Store.Owned.Values) { Company val = Store.FindCompany(value.CompanyId); if ((Object)(object)((val != null) ? val.address : null) == (Object)null) { value.Strikes.Clear(); continue; } foreach (KeyValuePair<string, int> strike in value.Strikes) { if (!ParseKey(strike.Key, out var id, out var cat)) { continue; } Human val2 = FindHuman(id); if ((Object)(object)val2 == (Object)null || ((Actor)val2).isDead || !IsFavourite(val2, cat, val.address)) { continue; } float num = 1f - Mathf.Pow(1f - Plugin.LoseChance.Value, (float)strike.Value); if (Random.value > num) { continue; } Company val3 = NearestRival(val2, cat, val); if (val3 != null) { Change(val2, cat, val3.address); value.RegularsLost.Add(val3.name); ManualLogSource logger = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(35, 5, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(value.Name); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(": regular "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(val2.GetCitizenName()); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" left for "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(val3.name); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" ("); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<CompanyCategory>(cat); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(", "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(strike.Value); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" strike(s))"); } logger.LogInfo(val4); } } value.Strikes.Clear(); } } public static string Report(Business b) { int count = b.RegularsLost.Count; int regularsGained = b.RegularsGained; b.RegularsGained = 0; b.RegularsLost.Clear(); if (count >= 2) { return "Some of the regulars haven't been in lately."; } if (count == 1) { return "Haven't seen one of the regulars in a while."; } if (regularsGained >= 2) { return "Lot of new faces lately."; } if (regularsGained == 1) { return "Looks like we've got a new regular."; } return null; } public static int Count(Company c) { Company obj = c; if ((Object)(object)((obj != null) ? obj.address : null) == (Object)null) { return 0; } int num = 0; Enumerator<Human> enumerator = c.address.favouredCustomers.GetEnumerator(); while (enumerator.MoveNext()) { Human h = enumerator.Current; if ((Object)(object)h != (Object)null && Errands.Any((CompanyCategory cat) => IsFavourite(h, cat, c.address))) { num++; } } return num; } private static IEnumerable<CompanyCategory> ErrandsFor(Human who, Company c) { CompanyPreset preset = c.preset; List<CompanyCategory> cats = ((preset != null) ? preset.companyCategories : null); if (cats == null) { yield break; } NewAIController ai = ((Actor)who).ai; object obj; if (ai == null) { obj = null; } else { NewAIGoal currentGoal = ai.currentGoal; obj = ((currentGoal != null) ? currentGoal.preset : null); } AIGoalPreset val = (AIGoalPreset)obj; if ((SoCustomComparison)(object)val != (SoCustomComparison)null && Errands.Contains(val.desireCategory) && cats.Contains(val.desireCategory)) { yield return val.desireCategory; yield break; } CompanyCategory[] errands = Errands; foreach (CompanyCategory val2 in errands) { if (cats.Contains(val2)) { yield return val2; } } } private static bool IsFavourite(Human h, CompanyCategory cat, NewAddress address) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) NewAddress val = default(NewAddress); if (h.favouritePlaces.TryGetValue(cat, ref val) && (Object)(object)val != (Object)null) { return ((Il2CppObjectBase)val).Pointer == ((Il2CppObjectBase)address).Pointer; } return false; } private static NewAddress Change(Human h, CompanyCategory cat, NewAddress to) { //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_001d: Expected I4, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Expected I4, but got Unknown NewAddress val = default(NewAddress); h.favouritePlaces.TryGetValue(cat, ref val); (int, int) key = (h.humanID, (int)cat); if (!changes.TryGetValue(key, out var value)) { Dictionary<(int, int), FavouriteChange> dictionary = changes; FavouriteChange obj = new FavouriteChange { HumanId = h.humanID, Category = (int)cat, OriginalAddressId = ((val != null) ? val.id : (-1)) }; value = obj; dictionary[key] = obj; } value.AddressId = to.id; SetFavourite(h, cat, to); return val; } private static void SetFavourite(Human h, CompanyCategory cat, NewAddress to) { //IL_0018: 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) NewAddress from = default(NewAddress); h.favouritePlaces.TryGetValue(cat, ref from); if (!((Object)(object)from != (Object)null) || !(((Il2CppObjectBase)from).Pointer == ((Il2CppObjectBase)to).Pointer)) { h.favouritePlaces[cat] = to; if ((Object)(object)from != (Object)null && !Errands.Any((CompanyCategory e) => IsFavourite(h, e, from)) && from.favouredCustomers.Contains(h)) { from.favouredCustomers.Remove(h); } if (!to.favouredCustomers.Contains(h)) { to.favouredCustomers.Add(h); } } } private static Company NearestRival(Human h, CompanyCategory cat, Company not) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_00f7: 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_0129: Unknown result type (might be due to invalid IL or missing references) Vector3 val = (((Object)(object)h.home != (Object)null && ((NewGameLocation)h.home).nodes.Count > 0) ? ((NewGameLocation)h.home).nodes[0].position : ((((NewGameLocation)not.address).nodes.Count > 0) ? ((NewGameLocation)not.address).nodes[0].position : Vector3.zero)); Company result = null; float num = float.MaxValue; Enumerator<Company> enumerator = CityData.Instance.companyDirectory.GetEnumerator(); while (enumerator.MoveNext()) { Company current = enumerator.Current; if (current == null || current.companyID == not.companyID || (Object)(object)current.address == (Object)null || ((NewGameLocation)current.address).nodes.Count == 0 || !current.publicFacing) { continue; } CompanyPreset preset = current.preset; if (((preset != null) ? preset.companyCategories : null) != null && current.preset.companyCategories.Contains(cat) && current.prices != null && current.prices.Count != 0) { float num2 = Vector3.Distance(val, ((NewGameLocation)current.address).nodes[0].position); if (num2 < num) { num = num2; result = current; } } } return result; } private static string StrikeKey(int id, CompanyCategory cat) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected I4, but got Unknown return $"{id}:{(int)cat}"; } private static bool ParseKey(string key, out int id, out CompanyCategory cat) { id = 0; cat = (CompanyCategory)0; string[] array = key.Split(':'); if (array.Length != 2 || !int.TryParse(array[0], out id) || !int.TryParse(array[1], out var result)) { return false; } cat = (CompanyCategory)result; return true; } private static Human FindHuman(int id) { Human result = default(Human); if (!CityData.Instance.citizenDictionary.TryGetValue(id, ref result)) { return null; } return result; } private static NewAddress FindAddress(int id) { NewAddress result = default(NewAddress); if (id < 0 || !CityData.Instance.addressDictionary.TryGetValue(id, ref result)) { return null; } return result; } static Loyalty() { CompanyCategory[] array = new CompanyCategory[4]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); Errands = (CompanyCategory[])(object)array; } } [HarmonyPatch] internal static class OnTheHousePatch { [HarmonyPatch(typeof(ShopSelectButtonController), "Setup")] [HarmonyPrefix] private static void Price(InteractablePreset newPreset, ref int newPrice, BuyInterfaceController newBuyController, bool newSellMode) { if (Free(newPreset, (newBuyController != null) ? newBuyController.company : null, newSellMode) != null) { newPrice = 0; } } [HarmonyPatch(typeof(ShopSelectButtonController), "Setup")] [HarmonyPostfix] private static void Label(ShopSelectButtonController __instance) { try { InteractablePreset preset = __instance.preset; BuyInterfaceController buyController = __instance.buyController; if (Free(preset, (buyController != null) ? buyController.company : null, __instance.sellMode) != null && (Object)(object)__instance.priceText != (Object)null) { ((TMP_Text)__instance.priceText).text = "Free"; } } catch (Exception ex) { Plugin.Logger.LogError((object)("Couldn't label a free item: " + ex.Message)); } } [HarmonyPatch(typeof(ShopSelectButtonController), "PurchaseExecute")] [HarmonyPrefix] private static void TakeFromStock(ShopSelectButtonController __instance) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown try { InteractablePreset preset = __instance.preset; BuyInterfaceController buyController = __instance.buyController; Business business = Free(preset, (buyController != null) ? buyController.company : null, __instance.sellMode); if (business != null && __instance.price == 0) { string name = ((Object)__instance.preset).name; business.Stock[name] = Math.Max(0, business.Stock[name] - 1); ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(36, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(business.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Store.ItemName(name)); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" on the house for the boss ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(business.Stock[name]); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" left)"); } logger.LogInfo(val); } } catch (Exception ex) { Plugin.Logger.LogError((object)("Couldn't take a free item from stock: " + ex.Message)); } } private static Business Free(InteractablePreset item, Company c, bool selling) { if (!Plugin.FreeForOwner.Value || selling || (SoCustomComparison)(object)item == (SoCustomComparison)null) { return null; } Business business = Store.Get(c); if (business == null || !business.Stock.TryGetValue(((Object)item).name, out var value) || value <= 0) { return null; } if (c.prices == null || !c.prices.ContainsKey(item)) { return null; } return business; } } [BepInPlugin("sodmods.proprietor", "Under New Management", "1.5.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BasePlugin { public const string Guid = "sodmods.proprietor"; internal static ManualLogSource Logger; internal static ConfigEntry<int> BasePrice; internal static ConfigEntry<int> PricePerRegular; internal static ConfigEntry<int> MinOrder; internal static ConfigEntry<int> MaxOrder; internal static ConfigEntry<int> MaxStock; internal static ConfigEntry<int> WagePerStaff; internal static ConfigEntry<int> MinDeliveryDays; internal static ConfigEntry<int> MaxDeliveryDays; internal static ConfigEntry<float> WholesaleShare; internal static ConfigEntry<float> TransferFee; internal static ConfigEntry<float> TransferHour; internal static ConfigEntry<float> TypicalMenuPrice; internal static ConfigEntry<float> SellBackShare; internal static ConfigEntry<int> LowStock; internal static ConfigEntry<int> ManagerRaise; internal static ConfigEntry<int> DepositStep; internal static ConfigEntry<float> DemandPerRegular; internal static ConfigEntry<float> DaysOfStock; internal static ConfigEntry<float> LoseChance; internal static ConfigEntry<float> WinChance; internal static ConfigEntry<int> RobberySafe; internal static ConfigEntry<int> RobberyDanger; internal static ConfigEntry<float> RetailShoppersPerDay; internal static ConfigEntry<string> RetailShopTypes; internal static ConfigEntry<float> RobberyChance; internal static ConfigEntry<float> RobberyMinShare; internal s