Decompiled source of GraveOverhaul v1.2.0
plugins/GraveOverhaul/GraveOverhaul.dll
Decompiled 6 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Logging; using GraveyardOrbit; using GraveyardOrbit.Audio; using GraveyardOrbit.UI; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json.Linq; using UnityEngine; using UnityEngine.UIElements; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace GraveOverhaul { [HarmonyPatch(typeof(DroneCatalog), "RoleBlurbEnglish")] internal static class DroneRoleBlurbPatch { private static void Postfix(DroneRole r, ref string __result) { //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_0005: Invalid comparison between Unknown and I4 if ((int)r != 0) { if ((int)r == 1) { __result = "Fetches ore left lying. As a Mule it banks the hold on the planet: 1 run a sortie, 2 at 12 upgrades, 3 at 14. Drone Research adds more."; } } else { __result = "Breaks tiles near the ship, reaching further with each upgrade. Does not collect. A colour it has taken it cuts at full damage."; } } } internal static class DroneEconomyPatch { public const int MinerBuy = 600; public const int HaulerBuy = 900; public const int SeekerBuy = 1200; public const int ScrapRefundPercent = 60; public const int RepairBuyPercent = 20; public const int RepairLevelPercent = 5; public const int HaulerHoldPercent = 50; internal static DroneData RepairContext; public static int BuyFor(DroneRole role) { //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_0005: Invalid comparison between Unknown and I4 if ((int)role != 0) { if ((int)role == 1) { return 900; } return 1200; } return 600; } public static int AdjustLevelMoney(DroneRole role, DroneDial dial, int money) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 if ((int)role == 1 && (int)dial == 4) { return (money * 50 + 50) / 100; } return money; } public static int ExpectedLevel(DroneRole role, DroneDial dial, int currentLevel) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) return AdjustLevelMoney(role, dial, DroneEconomy.LevelPriceAt(currentLevel, DroneEconomy.ProgressIndex()).Money); } public static int TotalLevelSpend(DroneData d) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) if (d == null) { return 0; } int num = 0; DroneDial[] array = DroneCatalog.DialsOf(d.Role); foreach (DroneDial val in array) { int num2 = d.Level(val); for (int j = 0; j < num2; j++) { num += ExpectedLevel(d.Role, val, j); } } return num; } public static int TotalSpent(DroneData d) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (d == null) { return 0; } return DroneEconomy.BuyPrice(d.Role).Money + TotalLevelSpend(d); } public static int ExpectedScrap(DroneData d) { if (d == null) { return 0; } return (TotalSpent(d) * 60 + 50) / 100; } public static int ExpectedRepair(DroneData d) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) if (d == null) { return 0; } return (DroneEconomy.BuyPrice(d.Role).Money * 20 + TotalLevelSpend(d) * 5 + 50) / 100; } public static DronePrice RepairPriceFor(DroneData d) { //IL_0012: 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) if (d == null) { return DroneEconomy.RepairPrice(); } return new DronePrice(ExpectedRepair(d), 0, (string)null, 0); } public static DroneData MakeTestDrone(DroneRole role, IDictionary<DroneDial, int> levels = null) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_008b: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: 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_00b6: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) JObject val = new JObject(); DroneDial[] array = DroneCatalog.DialsOf(role); foreach (DroneDial val2 in array) { int num = 0; if (levels != null && levels.TryGetValue(val2, out var value)) { num = value; } val[DroneCatalog.DialKey(val2)] = JToken.op_Implicit(num); } JObject val3 = new JObject { ["id"] = JToken.op_Implicit(-1), ["name"] = JToken.op_Implicit("Probe"), ["role"] = JToken.op_Implicit(DroneCatalog.RoleKey(role)), ["spec"] = JToken.op_Implicit(DroneCatalog.SpecKey(DroneCatalog.BaseSpec(role))), ["specs"] = (JToken)new JArray(), ["levels"] = (JToken)(object)val, ["knockedOut"] = JToken.op_Implicit(true) }; return (DroneData)AccessTools.Constructor(typeof(DroneData), new Type[1] { typeof(JObject) }, false).Invoke(new object[1] { val3 }); } public static void ProbeLog() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: 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_00e1: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) DroneRole[] roles = DroneCatalog.Roles; foreach (DroneRole val in roles) { DroneData val2 = MakeTestDrone(val); Dictionary<DroneDial, int> dictionary = new Dictionary<DroneDial, int>(); DroneDial[] array = DroneCatalog.DialsOf(val); foreach (DroneDial key in array) { dictionary[key] = 2; } DroneData val3 = MakeTestDrone(val, dictionary); Plugin.Log.LogInfo((object)$"DroneEconomy probe {val}: buy={DroneEconomy.BuyPrice(val).Money} (want {BuyFor(val)})"); DroneData[] array2 = (DroneData[])(object)new DroneData[2] { val2, val3 }; foreach (DroneData val4 in array2) { string text = ""; array = DroneCatalog.DialsOf(val); foreach (DroneDial val5 in array) { text += $" {DroneCatalog.DialKey(val5)}@{val4.Level(val5)}->{DroneEconomy.LevelPrice(val4, val5).Money}(want {ExpectedLevel(val, val5, val4.Level(val5))})"; } RepairContext = val4; int money; try { money = DroneEconomy.RepairPrice().Money; } finally { RepairContext = null; } Plugin.Log.LogInfo((object)$" total={val4.TotalLevel} spent={TotalSpent(val4)} scrap={DroneEconomy.ScrapValue(val4)} (want {ExpectedScrap(val4)}) repair={money} (want {ExpectedRepair(val4)}) levels:{text}"); } } } } [HarmonyPatch(typeof(DroneEconomy), "ProgressIndex")] internal static class DroneProgressIndexPatch { private static bool Prefix(ref int __result) { __result = 0; return false; } } [HarmonyPatch(typeof(DroneEconomy), "GrowMoney")] internal static class DroneGrowMoneyPatch { private static bool Prefix(int baseMoney, ref int __result) { if (baseMoney <= 0) { __result = 0; return false; } int priceRound = DroneCatalog.PriceRound; __result = Mathf.Max(priceRound, Mathf.RoundToInt((float)baseMoney / (float)priceRound) * priceRound); return false; } } [HarmonyPatch(typeof(DroneCatalog), "BuyMoney")] internal static class DroneBuyMoneyPatch { private static void Postfix(DroneRole r, ref int __result) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) __result = DroneEconomyPatch.BuyFor(r); } } [HarmonyPatch(typeof(DroneEconomy), "LevelPrice")] internal static class DroneLevelPricePatch { private static void Postfix(DroneData d, DroneDial dial, ref DronePrice __result) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (d != null) { int num = DroneEconomyPatch.AdjustLevelMoney(d.Role, dial, __result.Money); if (num != __result.Money) { __result = new DronePrice(num, __result.Green, __result.ShardKey, __result.Shards); } } } } [HarmonyPatch(typeof(DroneEconomy), "CanRepair")] internal static class DroneCanRepairContextPatch { private static void Prefix(DroneData d, out DroneData __state) { __state = DroneEconomyPatch.RepairContext; DroneEconomyPatch.RepairContext = d; } private static Exception Finalizer(Exception __exception, DroneData __state) { DroneEconomyPatch.RepairContext = __state; return __exception; } } [HarmonyPatch(typeof(DroneEconomy), "Repair")] internal static class DroneRepairContextPatch { private static void Prefix(DroneData d, out DroneData __state) { __state = DroneEconomyPatch.RepairContext; DroneEconomyPatch.RepairContext = d; } private static Exception Finalizer(Exception __exception, DroneData __state) { DroneEconomyPatch.RepairContext = __state; return __exception; } } [HarmonyPatch(typeof(DroneEconomy), "RepairPrice")] internal static class DroneRepairPricePatch { private static void Postfix(ref DronePrice __result) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) DroneData repairContext = DroneEconomyPatch.RepairContext; if (repairContext != null) { __result = new DronePrice(DroneEconomyPatch.ExpectedRepair(repairContext), 0, (string)null, 0); } } } [HarmonyPatch(typeof(DroneBayScreen), "BuildIdentity")] internal static class DroneBayRepairLabelPatch { private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { MethodInfo vanilla = AccessTools.Method(typeof(DroneEconomy), "RepairPrice", Type.EmptyTypes, (Type[])null); MethodInfo replacement = AccessTools.Method(typeof(DroneEconomyPatch), "RepairPriceFor", (Type[])null, (Type[])null); int replaced = 0; foreach (CodeInstruction instruction in instructions) { if (CodeInstructionExtensions.Calls(instruction, vanilla)) { CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_1, (object)null); CodeInstructionExtensions.MoveLabelsFrom(val, instruction); CodeInstructionExtensions.MoveBlocksFrom(val, instruction); yield return val; yield return new CodeInstruction(OpCodes.Call, (object)replacement); replaced++; } else { yield return instruction; } } if (replaced != 1) { Plugin.Log.LogWarning((object)$"DroneEconomy: expected one RepairPrice() call in DroneBayScreen.BuildIdentity, rewrote {replaced}; the repair label may show the wrong price."); } } } [HarmonyPatch(typeof(DroneEconomy), "ScrapValue")] internal static class DroneScrapValuePatch { private static bool Prefix(DroneData d, ref int __result) { __result = DroneEconomyPatch.ExpectedScrap(d); return false; } } public sealed class DroneModDef : IResearchNode { private readonly string _nameKey; private readonly string _nameEnglish; private readonly string _descKey; private readonly string _descEnglish; public string Id { get; } public DroneRole Role { get; } public int Col { get; } public int Row { get; } public string[] Parents { get; } public Dictionary<string, int> Price { get; } public float Value { get; } public string Name => Loc.T(_nameKey, _nameEnglish); public string Desc => Loc.T(_descKey, _descEnglish); internal DroneModDef(string id, DroneRole role, string name, string desc, int col, int row, string[] parents, Dictionary<string, int> price, float value) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) Id = id; Role = role; Col = col; Row = row; Parents = parents ?? new string[0]; Price = price ?? new Dictionary<string, int>(); Value = value; _nameKey = "graveoverhaul.drone_research." + id + ".name"; _nameEnglish = name; _descKey = "graveoverhaul.drone_research." + id + ".desc"; _descEnglish = desc; } } public static class DroneModCatalog { public const string MinerRadius1 = "miner_radius_1"; public const string HaulerRuns1 = "hauler_runs_1"; public const string HaulerRuns2 = "hauler_runs_2"; public const string SeekerPing1 = "seeker_ping_1"; private static readonly Dictionary<DroneRole, DroneModDef[]> Nodes = new Dictionary<DroneRole, DroneModDef[]> { { (DroneRole)0, new DroneModDef[1] { new DroneModDef("miner_radius_1", (DroneRole)0, "Extended Work Radius I", "Miners work tiles up to +100 further from the ship.", 0, 0, new string[0], new Dictionary<string, int> { { "tok_blue", 4 } }, 100f) } }, { (DroneRole)1, new DroneModDef[2] { new DroneModDef("hauler_runs_1", (DroneRole)1, "Extra Cargo Run I", "Mule Haulers make +1 bank run per sortie: one more trip running a load down to the planet to keep.", 0, 0, new string[0], new Dictionary<string, int> { { "tok_gold", 8 } }, 1f), new DroneModDef("hauler_runs_2", (DroneRole)1, "Extra Cargo Run II", "Mule Haulers make a further +1 bank run per sortie (+2 with Extra Cargo Run I).", 1, 0, new string[1] { "hauler_runs_1" }, new Dictionary<string, int> { { "tok_gold", 10 }, { "tok_blue", 4 } }, 1f) } }, { (DroneRole)2, new DroneModDef[1] { new DroneModDef("seeker_ping_1", (DroneRole)2, "Keen Sensors I", "Seekers ping 1 second more often (never faster than once every 2 seconds).", 0, 0, new string[0], new Dictionary<string, int> { { "tok_gold", 3 } }, 1f) } } }; private static readonly DroneRole[] RoleOrder = (DroneRole[])(object)new DroneRole[3] { default(DroneRole), (DroneRole)1, (DroneRole)2 }; private static readonly List<DroneModDef> AllList = RoleOrder.Where(Nodes.ContainsKey).SelectMany((DroneRole r) => Nodes[r]).ToList(); private static readonly Dictionary<string, DroneModDef> ById = AllList.ToDictionary((DroneModDef d) => d.Id); public static IReadOnlyList<DroneModDef> All => AllList; public static IEnumerable<DroneRole> Roles => RoleOrder.Where(Nodes.ContainsKey); public static DroneModDef Get(string id) { if (string.IsNullOrEmpty(id)) { return null; } if (!ById.TryGetValue(id, out var value)) { return null; } return value; } public static IReadOnlyList<DroneModDef> For(DroneRole role) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (!Nodes.TryGetValue(role, out var value)) { return new DroneModDef[0]; } return value; } public static float OwnedValue(params string[] ids) { float num = 0f; foreach (string id in ids) { if (DroneModState.IsOwned(id)) { num += Get(id)?.Value ?? 0f; } } return num; } } public static class DroneModState { public const string RootKey = "drone_mods"; private static readonly HashSet<string> OwnedCache = new HashSet<string>(); private static JArray _cachedArray; private static int _cachedCount = -1; private static bool _cacheValid; public const int RefundDivisor = 2; public static event Action Changed; public static bool IsOwned(string id) { if (string.IsNullOrEmpty(id)) { return false; } if (Refresh()) { return OwnedCache.Contains(id); } return false; } public static IEnumerable<string> Owned() { if (!Refresh()) { return new string[0]; } return new List<string>(OwnedCache); } public static bool CanBuy(string id, out string reason) { DroneModDef droneModDef = DroneModCatalog.Get(id); if (droneModDef == null) { reason = Loc.T("graveoverhaul.drone_research.buy_unknown", "Unknown research"); return false; } if (GameState.I == null) { reason = Loc.T("graveoverhaul.drone_research.buy_no_game", "No game loaded"); return false; } if (IsOwned(id)) { reason = Loc.T("graveoverhaul.drone_research.buy_owned", "Owned"); return false; } string[] parents = droneModDef.Parents; for (int i = 0; i < parents.Length; i++) { if (!IsOwned(parents[i])) { reason = Loc.T("graveoverhaul.drone_research.buy_parent", "Research the previous upgrade first"); return false; } } foreach (KeyValuePair<string, int> item in droneModDef.Price) { if (!ColourTokens.CanAfford(item.Key, item.Value)) { reason = Loc.T("graveoverhaul.drone_research.buy_no_shards", "Not enough Shards"); return false; } } reason = null; return true; } public static bool Buy(string id) { if (!CanBuy(id, out var _)) { return false; } GameState i = GameState.I; JArray val = OwnedArray(i, create: true); if (val == null) { return false; } foreach (KeyValuePair<string, int> item in DroneModCatalog.Get(id).Price) { if (!ColourTokens.Spend(item.Key, item.Value)) { Plugin.Log.LogWarning((object)$"Drone Research: spending {item.Value} {item.Key} for '{id}' failed part-way."); _cacheValid = false; return false; } } val.Add(JToken.op_Implicit(id)); _cacheValid = false; i.Save(false); GameState.LogEvent("DRONE RESEARCH BOUGHT — " + id); SafeExec.Run("Drone Research Changed handler", delegate { DroneModState.Changed?.Invoke(); }); return true; } public static Dictionary<string, int> RefundFor(DroneModDef def) { Dictionary<string, int> dictionary = new Dictionary<string, int>(); if (def == null) { return dictionary; } foreach (KeyValuePair<string, int> item in def.Price) { int num = item.Value / 2; if (num > 0) { dictionary[item.Key] = num; } } return dictionary; } public static Dictionary<string, int> RefundFor(IEnumerable<string> ids) { Dictionary<string, int> dictionary = new Dictionary<string, int>(); if (ids == null) { return dictionary; } foreach (string id in ids) { foreach (KeyValuePair<string, int> item in RefundFor(DroneModCatalog.Get(id))) { dictionary.TryGetValue(item.Key, out var value); dictionary[item.Key] = value + item.Value; } } return dictionary; } public static Dictionary<string, int> PreviewRefund(GameState gs) { if (gs == null) { return new Dictionary<string, int>(); } return RefundFor(Owned()); } public static bool CanRespec(GameState gs) { if (gs != null && gs == GameState.I) { return Owned().Any(); } return false; } public static Dictionary<string, int> Respec(GameState gs, bool save = true) { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown Dictionary<string, int> result = new Dictionary<string, int>(); if (gs == null || gs != GameState.I) { return result; } List<string> list = Owned().ToList(); if (list.Count == 0) { return result; } JObject profile = ProfileReflection.GetProfile(gs); JToken obj = ((profile != null) ? profile["drone_mods"] : null); JObject val = (JObject)(object)((obj is JObject) ? obj : null); if (val == null) { return result; } result = RefundFor(list); foreach (KeyValuePair<string, int> item in result) { ColourTokens.Grant(item.Key, item.Value); } val["owned"] = (JToken)new JArray(); _cacheValid = false; if (save) { gs.Save(false); } string text = string.Join(", ", result.Select((KeyValuePair<string, int> kv) => kv.Value + " " + kv.Key)); Plugin.Log.LogInfo((object)string.Format("Drone Research respec: {0} node(s) cleared, refunded {1}.", list.Count, (text.Length > 0) ? text : "nothing")); GameState.LogEvent($"DRONE RESEARCH RESPEC — {list.Count} nodes, {result.Values.Sum()} shards back"); SafeExec.Run("Drone Research Changed handler", delegate { DroneModState.Changed?.Invoke(); }); return result; } private static bool Refresh() { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Invalid comparison between Unknown and I4 JArray val; try { val = OwnedArray(GameState.I, create: false); } catch (Exception arg) { Plugin.Log.LogError((object)$"Drone Research: reading owned list failed: {arg}"); return false; } if (val == null) { if (!_cacheValid || _cachedArray != null) { OwnedCache.Clear(); _cachedArray = null; _cachedCount = -1; _cacheValid = true; } return GameState.I != null; } if (_cacheValid && val == _cachedArray && ((JContainer)val).Count == _cachedCount) { return true; } OwnedCache.Clear(); foreach (JToken item in val) { if ((int)item.Type == 8) { string text = (string)item; if (DroneModCatalog.Get(text) != null) { OwnedCache.Add(text); } } } _cachedArray = val; _cachedCount = ((JContainer)val).Count; _cacheValid = true; return true; } private static JArray OwnedArray(GameState gs, bool create) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_003b: Expected O, but got Unknown JObject profile = ProfileReflection.GetProfile(gs); if (profile == null) { return null; } JToken obj = profile["drone_mods"]; JObject val = (JObject)(object)((obj is JObject) ? obj : null); if (val == null) { if (!create) { return null; } val = (JObject)(object)(profile["drone_mods"] = (JToken)new JObject { ["owned"] = (JToken)new JArray() }); } JToken obj2 = val["owned"]; JArray val3 = (JArray)(object)((obj2 is JArray) ? obj2 : null); if (val3 == null && create) { val3 = (JArray)(object)(val["owned"] = (JToken)new JArray()); } return val3; } } internal static class DroneResearchButtonPatch { [HarmonyPatch(typeof(DroneBayScreen), "BindInto")] internal static class BindIntoPatch { private static void Postfix(DroneBayScreen __instance) { SafeExec.Run("Drone Research button setup", delegate { AddButton(__instance); }); } } [HarmonyPatch(typeof(DroneBayScreen), "Hide")] internal static class HidePatch { private static void Postfix() { SafeExec.Run("Drone Research close on hide", DroneResearchPanel.CloseIfOpen); } } [HarmonyPatch(typeof(GameRoot), "Update")] internal static class EscapePatch { private static void Prefix(GameRoot __instance) { if (!DroneResearchPanel.IsOpen) { return; } SafeExec.Run("Drone Research escape", delegate { if (In.KeyDown((KeyCode)27) && !In.BackClaimed && !Handbook.Showing && !PauseOpen(__instance)) { In.ClaimBack(); DroneResearchPanel.CloseIfOpen(); } }); } } internal const string ButtonName = "go-drone-research-key"; private const string DividerName = "go-drone-research-divider"; private const float KeyWidth = 220f; private const float KeyHeight = 48f; private static readonly FieldInfo MsgField = AccessTools.Field(typeof(DroneBayScreen), "_msg"); private static readonly FieldInfo RootField = AccessTools.Field(typeof(DroneBayScreen), "_root"); private static readonly FieldInfo PauseField = AccessTools.Field(typeof(GameRoot), "_pause"); private static bool _warned; private static bool PauseOpen(GameRoot root) { object? obj = PauseField?.GetValue(root); PauseMenu val = (PauseMenu)((obj is PauseMenu) ? obj : null); if (val != null && (Object)(object)val != (Object)null) { return val.IsOpen; } return false; } private static void AddButton(DroneBayScreen screen) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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_0177: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: 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) DroneResearchPanel.CloseIfOpen(); object? obj = MsgField?.GetValue(screen); Label val = (Label)((obj is Label) ? obj : null); if (val == null || ((VisualElement)val).parent == null) { WarnOnce("DroneBayScreen._msg (or its header row) not found; the Research key is not shown."); return; } VisualElement parent = ((VisualElement)val).parent; if (UQueryExtensions.Q<VisualElement>(parent, "go-drone-research-key", (string)null) != null) { return; } VisualElement val2 = new VisualElement { name = "go-drone-research-divider", pickingMode = (PickingMode)1 }; val2.style.width = StyleLength.op_Implicit(1f); val2.style.height = StyleLength.op_Implicit(30f); val2.style.marginLeft = StyleLength.op_Implicit(26f); val2.style.marginRight = StyleLength.op_Implicit(26f); val2.style.backgroundColor = StyleColor.op_Implicit(Color.Lerp(MetaUi.Orange, Color.black, 0.6f)); parent.Add(val2); VisualElement key = null; key = MetaUi.Key(Loc.T("graveoverhaul.drone_research.ui.button", "RESEARCH"), (Action)delegate { SafeExec.Run("Drone Research open", delegate { if (!screen.IsTyping) { object? obj2 = RootField?.GetValue(screen); VisualElement val4 = (VisualElement)((obj2 is VisualElement) ? obj2 : null); if (val4 == null) { WarnOnce("DroneBayScreen._root not found; the Research panel can't open."); } else { VisualElement obj3 = key; DroneResearchPanel.Open(val4, (VisualElement)(object)((obj3 != null) ? UQueryExtensions.Q<Button>(obj3, (string)null, (string)null) : null), delegate { SafeExec.Run("Drone Research bay repaint", delegate { if ((Object)(object)screen != (Object)null && screen.IsOpen) { screen.Refresh(); } }); }); } } }); }, 220f, (Color?)null); key.name = "go-drone-research-key"; key.style.height = StyleLength.op_Implicit(48f); Button val3 = UQueryExtensions.Q<Button>(key, (string)null, (string)null); if (val3 != null) { ((VisualElement)val3).style.paddingTop = StyleLength.op_Implicit(0f); ((VisualElement)val3).style.paddingBottom = StyleLength.op_Implicit(0f); ((VisualElement)val3).style.height = StyleLength.op_Implicit(Length.Percent(100f)); ((VisualElement)val3).AddToClassList("sfx-swipe"); } parent.Add(key); } private static void WarnOnce(string message) { if (!_warned) { _warned = true; Plugin.Log.LogWarning((object)("Drone Research: " + message)); } } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class ResearchMinerWorkRadiusPatch { private static void Postfix(ref float __result) { __result += DroneModCatalog.OwnedValue("miner_radius_1"); } } [HarmonyPatch(typeof(DroneCatalog), "BankRuns")] internal static class ResearchBankRunsPatch { private static void Postfix(ref int __result) { __result += Mathf.RoundToInt(DroneModCatalog.OwnedValue("hauler_runs_1", "hauler_runs_2")); } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class ResearchSeekerPingPatch { internal const float MinPingSecs = 2f; private static void Postfix(ref float __result) { float num = DroneModCatalog.OwnedValue("seeker_ping_1"); if (!(num <= 0f)) { __result = Mathf.Max(Mathf.Min(__result, 2f), __result - num); } } } internal static class DroneResearchPanel { public static bool IsOpen => ResearchPanel.IsOpenFor(DroneResearchTree.I); public static void Open(VisualElement screenRoot, VisualElement returnFocus, Action onClosed = null) { ResearchPanel.Open(DroneResearchTree.I, screenRoot, returnFocus, onClosed); } public static void CloseIfOpen() { ResearchPanel.CloseIfOpen(DroneResearchTree.I); } } internal sealed class DroneResearchTree : ResearchTree { public static readonly DroneResearchTree I = new DroneResearchTree(); public override string ModalName => "go-drone-research-modal"; public override string LogName => "Drone Research"; public override string HubTop => Loc.T("graveoverhaul.drone_research.ui.hub_top", "DRONE"); public override string OwnedLine => Loc.T("graveoverhaul.drone_research.ui.tip_owned", "Researched · always active on your drones"); public override string RespecTitle => Loc.T("graveoverhaul.drone_research.ui.respec_title", "RESPEC DRONE RESEARCH"); private DroneResearchTree() { } public override IEnumerable<ResearchArm> Arms() { foreach (DroneRole role in DroneModCatalog.Roles) { yield return new ResearchArm(DroneCatalog.RoleName(role).ToUpperInvariant(), RoleColour(role), ResearchTree.TextTone(RoleColour(role)), ShapeOf(role), IconOf(role), DroneModCatalog.For(role)); } } public override IResearchNode Get(string id) { return DroneModCatalog.Get(id); } public override string ValueText(IResearchNode node) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 if (!(node is DroneModDef droneModDef)) { return ""; } if ((int)droneModDef.Role == 2) { return "-" + Mathf.Abs(droneModDef.Value).ToString("0.##", Loc.Culture) + "s"; } return "+" + Mathf.RoundToInt(droneModDef.Value); } public override string KindWord(ResearchShape shape) { return shape switch { ResearchShape.Diamond => Loc.T("graveoverhaul.drone_research.ui.kind_speed", "SPEED"), ResearchShape.Square => Loc.T("graveoverhaul.drone_research.ui.kind_capacity", "CAPACITY"), _ => Loc.T("graveoverhaul.drone_research.ui.kind_range", "RANGE"), }; } public override string LegendText(ResearchShape shape) { return shape switch { ResearchShape.Diamond => Loc.T("graveoverhaul.drone_research.ui.legend_diamond", "Speed"), ResearchShape.Square => Loc.T("graveoverhaul.drone_research.ui.legend_square", "Capacity"), ResearchShape.Hex => Loc.T("station.mods.legend_hex", "Capstone"), _ => Loc.T("graveoverhaul.drone_research.ui.legend_circle", "Range"), }; } public override string AppliesText(string armName) { return Loc.F("graveoverhaul.drone_research.ui.applies", "APPLIES TO EVERY {role}", new(string, object)[1] { ("role", armName) }); } public override string RespecBody(string refund) { return Loc.F("graveoverhaul.drone_research.ui.respec_body", "Every Drone Research upgrade is cleared and stops working at once. Only HALF of the shards you spent come back (rounded down per cost): you get {refund}.", new(string, object)[1] { ("refund", refund) }); } public override bool IsOwned(string id) { return DroneModState.IsOwned(id); } public override bool CanBuy(string id, out string reason) { return DroneModState.CanBuy(id, out reason); } public override bool Buy(string id) { return DroneModState.Buy(id); } public override bool CanRespec(GameState gs) { return DroneModState.CanRespec(gs); } public override Dictionary<string, int> PreviewRefund(GameState gs) { return DroneModState.PreviewRefund(gs); } public override void Respec(GameState gs) { DroneModState.Respec(gs); } public override void Subscribe(Action handler) { DroneModState.Changed += handler; } public override void Unsubscribe(Action handler) { DroneModState.Changed -= handler; } private static Color RoleColour(DroneRole role) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_000f: 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) //IL_0006: Invalid comparison between Unknown and I4 //IL_001a: 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) if ((int)role != 1) { if ((int)role == 2) { return MetaUi.Hex(10189823); } return MetaUi.Orange; } return MetaUi.Hex(4885759); } private static ResearchShape ShapeOf(DroneRole role) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 if ((int)role != 1) { if ((int)role == 2) { return ResearchShape.Diamond; } return ResearchShape.Circle; } return ResearchShape.Square; } private static string IconOf(DroneRole role) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 if ((int)role != 1) { if ((int)role == 2) { return "echo"; } return "rings"; } return "magnet"; } } [HarmonyPatch(typeof(RefinerySim), "Tick")] internal static class LaserDoubleShotPatch { private static readonly ConditionalWeakTable<Machine, StrongBox<int>> BurstState = new ConditionalWeakTable<Machine, StrongBox<int>>(); private static void Prefix(RefinerySim __instance, out Dictionary<MachineStat, int> __state) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) Dictionary<MachineStat, int> dictionary = new Dictionary<MachineStat, int>(); foreach (MachineStat machine in __instance.Machines) { if (machine.m != null && (int)machine.m.kind == 0) { dictionary[machine] = machine.hits; } } __state = dictionary; } private static void Postfix(RefinerySim __instance, Dictionary<MachineStat, int> __state) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) if (__state == null) { return; } foreach (MachineStat machine in __instance.Machines) { Machine m = machine.m; if (m != null && (int)m.kind == 0 && __state.TryGetValue(machine, out var value) && machine.hits == value + 1) { StrongBox<int> orCreateValue = BurstState.GetOrCreateValue(m); if (orCreateValue.Value == 0) { machine.ready = machine.lastFire; orCreateValue.Value = 1; } else { orCreateValue.Value = 0; } } } } } [HarmonyPatch(typeof(RefineryLine), "RateOf")] internal static class LaserDoubleShotRatePatch { private static bool Prefix(Machine m, ref float __result) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) if (m == null || (int)m.kind != 0) { return true; } __result = 2f * RefineryLine.LaserRate(m.level); return false; } } internal static class LaserLevels { public const int Max = 7; public static float RateFor(int level) { return 1.5f * (float)Mathf.Clamp(level, 1, 7); } public static int PriceFor(int currentLevel) { switch (currentLevel) { case 3: return 150; case 4: return 250; case 5: return 400; default: if (currentLevel >= 3) { return 600; } return 60; } } } [HarmonyPatch(typeof(RefineryScreen), "MaxLevel")] internal static class MaxLevelPatch { private static bool Prefix(Machine m, ref int __result) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if ((int)m.kind != 0) { return true; } __result = 7; return false; } } [HarmonyPatch(typeof(RefineryLine), "LevelUp")] internal static class LaserLevelCapPatch { private static bool Prefix(RefineryLine __instance, Machine m, ref bool __result) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) if (m == null || (int)m.kind != 0 || m.level < 3 || m.level >= 7) { return true; } __result = RefineryReflection.TryLevelUp(__instance, m); return false; } } [HarmonyPatch(typeof(RefineryLine), "LaserRate")] internal static class LaserRatePatch { private static bool Prefix(int level, ref float __result) { __result = LaserLevels.RateFor(level); return false; } } [HarmonyPatch(typeof(RefineryLine), "LaserLevelPrice")] internal static class LaserLevelPricePatch { private static bool Prefix(Machine m, ref int __result) { __result = LaserLevels.PriceFor(m.level); return false; } } [HarmonyPatch(typeof(RefineryScreen), "State")] internal static class LaserLevelStatePatch { private static void Postfix(RefineryScreen __instance, CardKind kind, ref CardState __result) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) if ((int)kind == 5) { Machine selected = __instance.Selected; if (selected != null && (int)selected.kind == 0) { bool flag = selected.level >= 7; int num = ((!flag) ? LaserLevels.PriceFor(selected.level) : 0); int num2 = ((GameState.I != null) ? GameState.I.Money : 0); __result.progress = Loc.F("station.refinery.level_of", "LEVEL {level} / {max}", new(string, object)[2] { ("level", selected.level), ("max", 7) }); __result.desc = (flag ? Loc.T("station.refinery.tip_top_laser", "It is as fast as it gets.") : Loc.F("graveoverhaul.refinery.level_laser_faster", "Works ×{mult} as fast.", new(string, object)[1] { ("mult", selected.level + 1) })); __result.cost = num; __result.maxed = flag; __result.affordable = !flag && num2 >= num; } } } } [HarmonyPatch(typeof(RefineryScreen), "ShowTip")] internal static class LaserLevelTipPatch { private static readonly FieldInfo UpFillField = AccessTools.Field(typeof(RefineryScreen), "_upFill"); private static void Postfix(RefineryScreen __instance, Machine m) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (m == null || (int)m.kind != 0) { return; } SafeExec.Run("Laser level tip fixup", delegate { //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) Card tipCard = RefineryReflection.GetTipCard(__instance); if (tipCard != null && tipCard.lv != null && tipCard.pips != null) { ((TextElement)tipCard.lv).text = Loc.F("station.refinery.lv_of", "LV {level} / {max}", new(string, object)[2] { ("level", m.level), ("max", 7) }); tipCard.pips.Count = 7; tipCard.pips.Filled = m.level; if (m.level >= 3 && m.level < 7) { int num = LaserLevels.PriceFor(m.level); bool flag = ((GameState.I != null) ? GameState.I.Money : 0) >= num; ((TextElement)tipCard.nextHead).text = Loc.F("station.refinery.tip_next_lv", "NEXT · LV {level}", new(string, object)[1] { ("level", m.level + 1) }); ((VisualElement)tipCard.nextHead).style.color = StyleColor.op_Implicit(TipCardKit.Green); ((TextElement)tipCard.nextText).text = Loc.F("graveoverhaul.refinery.level_laser_faster", "Works ×{mult} as fast.", new(string, object)[1] { ("mult", m.level + 1) }); bool active = PadNav.Active; string text = (active ? "button_a" : "kbm_mouse_left"); string text2 = (active ? Loc.F("station.refinery.btn_hold_button", "HOLD {button}", new(string, object)[1] { ("button", PadNav.Word("button_a")) }) : Loc.T("station.refinery.btn_hold_left", "HOLD LEFT CLICK")); string text3 = (flag ? text2 : Loc.F("station.refinery.row_short_money", "{button} · NOT ENOUGH MONEY", new(string, object)[1] { ("button", text2) })); TipCardKit.FillRow(tipCard.rows[0], text, Loc.T("station.refinery.row_level_up", "Level up"), text3, "$" + num.ToString("N0", Loc.Culture), TipCardKit.Green, flag); object? value = UpFillField.GetValue(__instance); VisualElement val = (VisualElement)((value is VisualElement) ? value : null); if (val != null) { val.parent.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!flag)); } } } }); } } [HarmonyPatch(typeof(RefineryScreen), "OpenSocket")] internal static class LaserLevelPopoverPatch { private static void Postfix(RefineryScreen __instance, Machine m) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (m == null || (int)m.kind != 0) { return; } SafeExec.Run("Laser level popover fixup", delegate { VisualElement popover = __instance.Popover; PipLane val = ((popover != null) ? UQueryExtensions.Q<PipLane>(popover, "pop-pips", (string)null) : null); if (val != null) { val.Count = 7; val.Filled = m.level; VisualElement parent = ((VisualElement)val).parent; Label val2 = ((parent != null) ? UQueryExtensions.Q<Label>(parent, (string)null, (string)null) : null); if (val2 != null) { ((TextElement)val2).text = Loc.F("station.refinery.lv_of", "LV {level} / {max}", new(string, object)[2] { ("level", m.level), ("max", 7) }); } } }); } } [HarmonyPatch(typeof(RefinerySim), "Tick")] internal static class LaserSmallestFirstPatch { private static readonly FieldInfo ChunksField = AccessTools.Field(typeof(RefinerySim), "_chunks"); private static void Prefix(RefinerySim __instance) { SafeExec.Run("Laser smallest-first reorder", delegate { //IL_006b: Unknown result type (might be due to invalid IL or missing references) object value = ChunksField.GetValue(__instance); List<Chunk> chunks = value as List<Chunk>; if (chunks != null && chunks.Count >= 2) { HashSet<int> hashSet = null; foreach (MachineStat machine in __instance.Machines) { if (machine.m != null && (int)machine.m.kind == 0) { (hashSet ?? (hashSet = new HashSet<int>())).Add(machine.m.lane); } } if (hashSet != null) { List<int> list = null; for (int i = 0; i < chunks.Count; i++) { if (hashSet.Contains(chunks[i].lane)) { (list ?? (list = new List<int>())).Add(i); } } if (list != null && list.Count >= 2) { List<Chunk> list2 = (from index in list select chunks[index] into c orderby c.face select c).ToList(); for (int num = 0; num < list.Count; num++) { chunks[list[num]] = list2[list.Count - 1 - num]; } } } } }); } } internal static class MachineLevels { public const int Max = 3; private static readonly Dictionary<MachineKind, float[]> Rates = new Dictionary<MachineKind, float[]> { { (MachineKind)1, new float[3] { 4f, 6f, 8f } }, { (MachineKind)4, new float[3] { 1f, 1.5f, 2f } }, { (MachineKind)5, new float[3] { 3f, 4.5f, 6f } }, { (MachineKind)6, new float[3] { 2f, 3f, 4f } } }; private static readonly float[] LottoIntervals = new float[3] { 5f, 3.5f, 2.5f }; private static readonly Dictionary<MachineKind, int[]> Prices = new Dictionary<MachineKind, int[]> { { (MachineKind)1, new int[2] { 120, 180 } }, { (MachineKind)4, new int[2] { 90, 140 } }, { (MachineKind)5, new int[2] { 72, 110 } }, { (MachineKind)6, new int[2] { 120, 180 } }, { (MachineKind)8, new int[2] { 180, 260 } } }; private static readonly Dictionary<MachineKind, (string key, string english)> NextDesc = new Dictionary<MachineKind, (string, string)> { { (MachineKind)1, ("graveoverhaul.refinery.level_next_crusher", "Splits rocks faster.") }, { (MachineKind)4, ("graveoverhaul.refinery.level_next_kickback", "Kicks rocks around faster.") }, { (MachineKind)5, ("graveoverhaul.refinery.level_next_igniter", "Ignites rocks faster.") }, { (MachineKind)6, ("graveoverhaul.refinery.level_next_compliance", "Inspects rocks faster.") }, { (MachineKind)8, ("graveoverhaul.refinery.level_next_lotto", "Rolls more often.") } }; private static readonly Dictionary<MachineKind, (string key, string english)> TopDesc = new Dictionary<MachineKind, (string, string)> { { (MachineKind)1, ("graveoverhaul.refinery.level_top_crusher", "It splits as fast as it gets.") }, { (MachineKind)4, ("graveoverhaul.refinery.level_top_kickback", "It kicks as fast as it gets.") }, { (MachineKind)5, ("graveoverhaul.refinery.level_top_igniter", "It ignites as fast as it gets.") }, { (MachineKind)6, ("graveoverhaul.refinery.level_top_compliance", "It inspects as fast as it gets.") }, { (MachineKind)8, ("graveoverhaul.refinery.level_top_lotto", "It rolls as fast as it gets.") } }; public static bool IsLeveled(MachineKind kind) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 if (!Rates.ContainsKey(kind)) { return (int)kind == 8; } return true; } public static float RateFor(MachineKind kind, int level) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Clamp(level, 1, 3) - 1; if (!Rates.TryGetValue(kind, out var value)) { return 0f; } return value[num]; } public static float LottoIntervalFor(int level) { return LottoIntervals[Mathf.Clamp(level, 1, 3) - 1]; } public static int PriceFor(MachineKind kind, int currentLevel) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (currentLevel < 1 || currentLevel > 2) { return 0; } if (!Prices.TryGetValue(kind, out var value)) { return 0; } return value[currentLevel - 1]; } public static string NextDescFor(MachineKind kind) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (!NextDesc.TryGetValue(kind, out (string, string) value)) { return ""; } return Loc.T(value.Item1, value.Item2); } public static string TopDescFor(MachineKind kind) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (!TopDesc.TryGetValue(kind, out (string, string) value)) { return ""; } return Loc.T(value.Item1, value.Item2); } } [HarmonyPatch(typeof(RefineryScreen), "Levels")] internal static class LevelsGatePatch { private static bool Prefix(Machine m, ref bool __result) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) if (m != null && MachineLevels.IsLeveled(m.kind)) { __result = true; return false; } return true; } } [HarmonyPatch(typeof(RefineryLine), "LevelUp")] internal static class MachineLevelUpPatch { private static bool Prefix(RefineryLine __instance, Machine m, ref bool __result) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) if (m == null || !MachineLevels.IsLeveled(m.kind) || m.level >= 3) { return true; } __result = RefineryReflection.TryLevelUp(__instance, m); return false; } } [HarmonyPatch(typeof(RefineryScreen), "State")] internal static class MachineLevelStatePatch { private static void Postfix(RefineryScreen __instance, CardKind kind, ref CardState __result) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) if ((int)kind == 5) { Machine selected = __instance.Selected; if (selected != null && (int)selected.kind != 0 && MachineLevels.IsLeveled(selected.kind)) { bool flag = selected.level >= 3; int num = ((!flag) ? MachineLevels.PriceFor(selected.kind, selected.level) : 0); int num2 = ((GameState.I != null) ? GameState.I.Money : 0); __result.progress = Loc.F("station.refinery.level_of", "LEVEL {level} / {max}", new(string, object)[2] { ("level", selected.level), ("max", 3) }); __result.desc = (flag ? MachineLevels.TopDescFor(selected.kind) : MachineLevels.NextDescFor(selected.kind)); __result.cost = num; __result.maxed = flag; __result.affordable = !flag && num2 >= num; } } } } [HarmonyPatch(typeof(RefineryLine), "RateOf")] internal static class MachineRateOfPatch { private static bool Prefix(Machine m, ref float __result) { //IL_0004: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Invalid comparison between Unknown and I4 //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) if (m == null || (int)m.kind == 0 || !MachineLevels.IsLeveled(m.kind)) { return true; } if ((int)m.kind == 8) { return true; } __result = MachineLevels.RateFor(m.kind, m.level) * RefineryResearchRate.Multiplier(m.kind); return false; } } [HarmonyPatch(typeof(RefinerySim), "Tick")] internal static class MachineTickRatePatch { private static void Postfix(RefinerySim __instance, float dt) { //IL_0036: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Invalid comparison between Unknown and I4 //IL_00a6: Unknown result type (might be due to invalid IL or missing references) if (dt <= 0f) { return; } float clock = __instance.Clock; foreach (MachineStat machine in __instance.Machines) { Machine m = machine.m; if (m == null || (int)m.kind == 0 || !MachineLevels.IsLeveled(m.kind)) { continue; } float num = RefineryResearchRate.Multiplier(m.kind); if (m.level <= 1 && num == 1f) { continue; } if ((int)m.kind == 8) { float num2 = MachineLevels.LottoIntervalFor(m.level) / num; if (machine.lottoT > num2) { machine.lottoT = num2; } } else if (machine.lastFire == clock) { float num3 = MachineLevels.RateFor(m.kind, m.level) * num; if (num3 > 0f) { machine.ready = machine.lastFire + 1f / num3; } } } } } [HarmonyPatch(typeof(RefineryScreen), "ShowTip")] internal static class MachineLevelTipMaxedTextPatch { private static void Postfix(RefineryScreen __instance, Machine m) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (m == null || (int)m.kind == 0 || !MachineLevels.IsLeveled(m.kind) || m.level < 3) { return; } SafeExec.Run("Machine level tip maxed-text fixup", delegate { //IL_0023: Unknown result type (might be due to invalid IL or missing references) Card tipCard = RefineryReflection.GetTipCard(__instance); if (tipCard != null && tipCard.nextText != null) { ((TextElement)tipCard.nextText).text = MachineLevels.TopDescFor(m.kind); } }); } } [HarmonyPatch(typeof(RefineryScreen), "LevelPrice")] internal static class MachineLevelPriceMethodPatch { private static bool Prefix(Machine m, ref int __result) { //IL_0004: 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_001c: Unknown result type (might be due to invalid IL or missing references) if (m == null || (int)m.kind == 0 || !MachineLevels.IsLeveled(m.kind)) { return true; } __result = MachineLevels.PriceFor(m.kind, m.level); return false; } } [HarmonyPatch(typeof(RefineryScreen), "OpenSocket")] internal static class MachineLevelPopoverPatch { private static void Postfix(RefineryScreen __instance, Machine m) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) if (m == null || (int)m.kind == 0 || !MachineLevels.IsLeveled(m.kind)) { return; } SafeExec.Run("Machine level popover build", delegate { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: 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_00b4: Expected O, but got Unknown //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) VisualElement popover = __instance.Popover; if (popover != null) { CardState val = __instance.State((CardKind)5); VisualElement val2 = new VisualElement(); val2.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2); val2.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2); val2.style.marginTop = StyleLength.op_Implicit(12f); Label val3 = new Label(Loc.F("station.refinery.lv_of", "LV {level} / {max}", new(string, object)[2] { ("level", m.level), ("max", 3) })) { pickingMode = (PickingMode)1 }; ((VisualElement)val3).style.marginRight = StyleLength.op_Implicit(16f); ((VisualElement)val3).style.color = StyleColor.op_Implicit(Color.white); val2.Add((VisualElement)(object)val3); Button val4 = new Button((Action)delegate { __instance.Buy((CardKind)5); }); ((TextElement)val4).text = (val.maxed ? Loc.T("station.refinery.key_maxed", "MAXED") : Loc.F("station.refinery.key_level_up_price", "LEVEL UP · {price}", new(string, object)[1] { ("price", $"${val.cost:N0}") })); Button val5 = val4; ((VisualElement)val5).SetEnabled(!val.maxed && val.affordable); val2.Add((VisualElement)(object)val5); popover.Add(val2); } }); } } [BepInPlugin("com.luminaex.graveoverhaul", "GraveOverhaul", "1.2.0")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "com.luminaex.graveoverhaul"; public const string PluginName = "GraveOverhaul"; public const string PluginVersion = "1.2.0"; internal static ManualLogSource Log; private void Awake() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; new Harmony("com.luminaex.graveoverhaul").PatchAll(); Log.LogInfo((object)"GraveOverhaul: gameplay/economy patches applied."); } } [HarmonyPatch(typeof(GameConfig), "Load")] internal static class QuotaRebalancePatch { private static bool _done; private static readonly Dictionary<int, int> FamilyTargets = new Dictionary<int, int> { { 150, 300 }, { 400, 800 }, { 1000, 2000 } }; internal static readonly Dictionary<string, int> RetargetedFrom = new Dictionary<string, int>(); public static bool Applied => _done; private static void Postfix() { if (_done) { return; } _done = true; try { int num = 0; foreach (QuotaDef item in QuotaCatalog.All) { if (item == null || item.id == null) { continue; } if (item.IsFamily && item.id.StartsWith("fam_", StringComparison.Ordinal) && FamilyTargets.TryGetValue(item.target, out var value) && item.id == $"fam_{item.family}_{item.target}") { RetargetedFrom[item.id] = item.target; item.text = FamilyText(item.family, value); item.target = value; num++; continue; } switch (item.id) { case "gold_16": case "cinnabar_16": item.rewardMetaCount = 2; num++; break; case "destroy_3000": item.reward = 450; num++; break; case "ore_1500": item.reward = 250; num++; break; } } Plugin.Log.LogInfo((object)$"QuotaRebalance: adjusted {num} quota entries ({RetargetedFrom.Count} family targets doubled, 4 rewards raised)."); } catch (Exception arg) { Plugin.Log.LogError((object)$"QuotaRebalance setup failed: {arg}"); } } private static string FamilyText(string family, int target) { string text = ((family == "drones") ? "" : "a "); string text2 = family switch { "laser" => "Laser", "ballistics" => "Cannon", "sweeper" => "Dynamo", "pulse" => "Pulse", "contact" => "Drill", "drones" => "Drones", _ => family, }; return "Destroy " + target.ToString("n0", CultureInfo.InvariantCulture) + " tiles with " + text + text2; } public static (bool found, int target, int money, string meta, int metaCount) Probe(string id) { QuotaDef val = QuotaCatalog.Get(id); if (val == null) { return (found: false, target: 0, money: 0, meta: null, metaCount: 0); } return (found: true, target: val.target, money: val.reward, meta: val.rewardMeta, metaCount: val.rewardMetaCount); } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class QuotaRebalanceTextPatch { private static void Postfix(QuotaDef __instance, ref string __result) { if (__result == null || Loc.IsEnglish || __instance == null || __instance.id == null || !QuotaRebalancePatch.RetargetedFrom.TryGetValue(__instance.id, out var value)) { return; } int target = __instance.target; CultureInfo cultureInfo = Loc.Culture ?? CultureInfo.InvariantCulture; string text = value.ToString("n0", cultureInfo); if (__result.Contains(text)) { __result = __result.Replace(text, target.ToString("n0", cultureInfo)); return; } string text2 = value.ToString("n0", CultureInfo.InvariantCulture); if (__result.Contains(text2)) { __result = __result.Replace(text2, target.ToString("n0", CultureInfo.InvariantCulture)); return; } string text3 = value.ToString(CultureInfo.InvariantCulture); if (__result.Contains(text3)) { __result = __result.Replace(text3, target.ToString(CultureInfo.InvariantCulture)); } } } internal static class RefineryEvReadoutPatch { [HarmonyPatch(typeof(RefineryScreen), "BuildPage")] internal static class BuildPagePatch { private static void Postfix(RefineryScreen __instance) { SafeExec.Run("Refinery EV readout setup", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown Label val = (Label)HaulRateField.GetValue(__instance); VisualElement val2 = (((int)val != 0) ? ((VisualElement)val).parent : null); if (val2 != null) { Label val3 = new Label("") { pickingMode = (PickingMode)1 }; ((VisualElement)val3).AddToClassList("rl-top__rate"); val2.Add((VisualElement)(object)val3); EvLabels.Remove(__instance); EvLabels.Add(__instance, val3); } }); } } [HarmonyPatch(typeof(RefineryScreen), "Refresh")] internal static class RefreshPatch { private static void Postfix(RefineryScreen __instance) { SafeExec.Run("Refinery EV readout refresh", delegate { if (EvLabels.TryGetValue(__instance, out var value)) { RefineryLine board = RefineryLine.Board; if (board != null) { Dictionary<Colour, float> dictionary = board.SharesFromPending(); float num = 1f / Mathf.Max(0.001f, RefinerySim.FeedInterval(board.PendingTotal)); float num2 = board.ExpectedPayPerOre(num, (IReadOnlyDictionary<Colour, float>)dictionary); float num3 = board.ExpectedKeptUp(num, (IReadOnlyDictionary<Colour, float>)dictionary); ((TextElement)value).text = Loc.F("graveoverhaul.refinery.ev_readout", "EXPECTED ×{mult} · KEEPING {pct}%", new(string, object)[2] { ("mult", num2.ToString("0.00")), ("pct", (num3 * 100f).ToString("0")) }); } } }); } } internal static readonly ConditionalWeakTable<RefineryScreen, Label> EvLabels = new ConditionalWeakTable<RefineryScreen, Label>(); private static readonly FieldInfo HaulRateField = AccessTools.Field(typeof(RefineryScreen), "_haulRate"); } internal static class RefineryReflection { private static readonly FieldInfo MachinesField = AccessTools.Field(typeof(RefineryLine), "_machines"); private static readonly FieldInfo XCardField = AccessTools.Field(typeof(RefineryScreen), "_xCard"); private static readonly FieldInfo TipCardField = AccessTools.Field(typeof(RefineryScreen), "_tipCard"); public static bool TryLevelUp(RefineryLine line, Machine m) { if (!(MachinesField.GetValue(line) is List<Machine> list) || !list.Contains(m)) { return false; } m.level++; return true; } public static Card GetXCard(RefineryScreen screen) { object? value = XCardField.GetValue(screen); return (Card)((value is Card) ? value : null); } public static Card GetTipCard(RefineryScreen screen) { object? value = TipCardField.GetValue(screen); return (Card)((value is Card) ? value : null); } } internal static class ProfileReflection { private static readonly Func<GameState, JObject> ProfileGetter = AccessTools.MethodDelegate<Func<GameState, JObject>>(AccessTools.PropertyGetter(typeof(GameState), "ProfileObj"), (object)null, true); public static JObject GetProfile(GameState gs) { if (gs == null) { return null; } return ProfileGetter(gs); } } internal static class SafeExec { public static void Run(string label, Action action) { try { action(); } catch (Exception arg) { Plugin.Log.LogError((object)$"{label} failed: {arg}"); } } } [HarmonyPatch(typeof(RefineryScreen), "PartDesc")] internal static class PartDescCapPatch { private static void Postfix(CardKind kind, Colour colour, ref string __result) { //IL_0000: 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) if ((int)kind == 0) { string item = RefineryPalette.Name(colour).ToLowerInvariant(); int num = Mathf.RoundToInt(LaserCaps.ReadNormal()); __result = Loc.F("station.refinery.desc_laser", "Only fires at {color} rocks passing under it. Every hit adds $1, up to ${cap} a rock. Buy more or upgrade to keep up with the pace.", new(string, object)[2] { ("color", item), ("cap", num) }); } } } [HarmonyPatch(typeof(RefineryScreen), "ShowPartTip")] internal static class ShowPartTipCapPatch { private static readonly FieldInfo PtipRowsField = AccessTools.Field(typeof(RefineryScreen), "_ptipRows"); private const int PaysRowIndex = 1; private static void Postfix(RefineryScreen __instance, CardKind kind) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) if ((int)kind != 0) { return; } SafeExec.Run("Refinery PAYS-row cap fixup", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown VisualElement val = (VisualElement)PtipRowsField.GetValue(__instance); if (val != null && val.childCount > 1) { VisualElement obj = val[1]; Label val2 = (Label)(object)((obj is Label) ? obj : null); if (val2 != null) { int num = Mathf.RoundToInt(LaserCaps.ReadNormal()); string text = Loc.F("station.refinery.pays_laser", "+$1 A HIT, UP TO ${cap}", new(string, object)[1] { ("cap", num) }); string text2 = Loc.T("station.refinery.row_pays", "PAYS"); ((TextElement)val2).text = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(text2.ToLowerInvariant()) + ": " + text.ToLowerInvariant(); } } }); } } internal static class LaserCaps { public const float Normal = 5f; public const float Split = 8.5f; public static readonly Func<float> ReadNormal = AccessTools.MethodDelegate<Func<float>>(AccessTools.PropertyGetter(typeof(LineRules), "LaserCapX"), (object)null, true); public static readonly Func<float> ReadSplit = AccessTools.MethodDelegate<Func<float>>(AccessTools.PropertyGetter(typeof(LineRules), "HalfCapX"), (object)null, true); } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class LaserCapPatch { private static bool Prefix(ref float __result) { __result = 5f; return false; } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] internal static class HalfCapPatch { private static bool Prefix(ref float __result) { __result = 8.5f; return false; } } [HarmonyPatch(typeof(LineRules), "CapOf")] internal static class CapOfPatch { private static bool Prefix(in RockState r, ref float __result) { __result = (r.split ? 8.5f : 5f) * r.face; return false; } } public sealed class RefineryModDef : IResearchNode { private readonly string _nameKey; private readonly string _nameEnglish; private readonly string _descKey; private readonly string _descEnglish; public string Id { get; } public MachineKind Kind { get; } public int Col { get; } public int Row { get; } public string[] Parents { get; } public Dictionary<string, int> Price { get; } public float Value { get; } public string Name => Loc.T(_nameKey, _nameEnglish); public string Desc => Loc.T(_descKey, _descEnglish); internal RefineryModDef(string id, MachineKind kind, string name, string desc, int col, int row, string[] parents, Dictionary<string, int> price, float value) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) Id = id; Kind = kind; Col = col; Row = row; Parents = parents ?? new string[0]; Price = price ?? new Dictionary<string, int>(); Value = value; _nameKey = "graveoverhaul.research." + id + ".name"; _nameEnglish = name; _descKey = "graveoverhaul.research." + id + ".desc"; _descEnglish = desc; } } public static class RefineryModCatalog { public const string LaserFocus1 = "laser_focus_1"; public const string LaserFocus2 = "laser_focus_2"; public const string IgniterHeat1 = "igniter_heat_1"; public const string PressTemper1 = "press_temper_1"; public const string PressTemper2 = "press_temper_2"; public const string CrusherSpeed1 = "crusher_speed_1"; public const string CrusherSpeed2 = "crusher_speed_2"; public const string RebateSpeed1 = "rebate_speed_1"; public const string RebateSpeed2 = "rebate_speed_2"; public const string CutterSpeed1 = "cutter_speed_1"; public const string CutterSpeed2 = "cutter_speed_2"; public const string LottoSpeed1 = "lotto_speed_1"; public const string LottoSpeed2 = "lotto_speed_2"; private static readonly Dictionary<MachineKind, RefineryModDef[]> Nodes = new Dictionary<MachineKind, RefineryModDef[]> { { (MachineKind)0, new RefineryModDef[2] { new RefineryModDef("laser_focus_1", (MachineKind)0, "Focused Beam I", "Each Laser hit adds +0.15 extra value to the rock (the Laser cap still applies).", 0, 0, new string[0], new Dictionary<string, int> { { "tok_gold", 2 } }, 0.15f), new RefineryModDef("laser_focus_2", (MachineKind)0, "Focused Beam II", "Each Laser hit adds a further +0.15 extra value to the rock (the Laser cap still applies).", 1, 0, new string[1] { "laser_focus_1" }, new Dictionary<string, int> { { "tok_gold", 4 } }, 0.15f) } }, { (MachineKind)5, new RefineryModDef[1] { new RefineryModDef("igniter_heat_1", (MachineKind)5, "Hotter Ignition", "The next Laser hit on an ignited rock adds +0.5 extra value (the Laser cap still applies).", 0, 0, new string[0], new Dictionary<string, int> { { "tok_gold", 3 } }, 0.5f) } }, { (MachineKind)3, new RefineryModDef[2] { new RefineryModDef("press_temper_1", (MachineKind)3, "Tempered Dies I", "Press ingot bonus +5% (for example 20% becomes 25%).", 0, 0, new string[0], new Dictionary<string, int> { { "tok_blue", 2 } }, 0.05f), new RefineryModDef("press_temper_2", (MachineKind)3, "Tempered Dies II", "Press ingot bonus a further +5%.", 1, 0, new string[1] { "press_temper_1" }, new Dictionary<string, int> { { "tok_blue", 6 } }, 0.05f) } }, { (MachineKind)1, new RefineryModDef[2] { new RefineryModDef("crusher_speed_1", (MachineKind)1, "Sharper Jaws I", "Crusher splits rocks 15% faster.", 0, 0, new string[0], new Dictionary<string, int> { { "tok_green", 2 } }, 0.15f), new RefineryModDef("crusher_speed_2", (MachineKind)1, "Sharper Jaws II", "Crusher splits rocks a further 15% faster.", 1, 0, new string[1] { "crusher_speed_1" }, new Dictionary<string, int> { { "tok_green", 4 }, { "tok_gold", 2 } }, 0.15f) } }, { (MachineKind)4, new RefineryModDef[2] { new RefineryModDef("rebate_speed_1", (MachineKind)4, "Quick Recoil I", "Kickback kicks rocks 15% faster.", 0, 0, new string[0], new Dictionary<string, int> { { "tok_purple", 2 } }, 0.15f), new RefineryModDef("rebate_speed_2", (MachineKind)4, "Quick Recoil II", "Kickback kicks rocks a further 15% faster.", 1, 0, new string[1] { "rebate_speed_1" }, new Dictionary<string, int> { { "tok_purple", 4 }, { "tok_pink", 2 } }, 0.15f) } }, { (MachineKind)6, new RefineryModDef[2] { new RefineryModDef("cutter_speed_1", (MachineKind)6, "Fast-Track Review I", "Compliance inspects rocks 15% faster.", 0, 0, new string[0], new Dictionary<string, int> { { "tok_pink", 2 } }, 0.15f), new RefineryModDef("cutter_speed_2", (MachineKind)6, "Fast-Track Review II", "Compliance inspects rocks a further 15% faster.", 1, 0, new string[1] { "cutter_speed_1" }, new Dictionary<string, int> { { "tok_pink", 4 }, { "tok_blue", 2 } }, 0.15f) } }, { (MachineKind)8, new RefineryModDef[2] { new RefineryModDef("lotto_speed_1", (MachineKind)8, "Lucky Streak I", "Lotto rolls 15% more often.", 0, 0, new string[0], new Dictionary<string, int> { { "tok_gold", 3 } }, 0.15f), new RefineryModDef("lotto_speed_2", (MachineKind)8, "Lucky Streak II", "Lotto rolls a further 15% more often.", 1, 0, new string[1] { "lotto_speed_1" }, new Dictionary<string, int> { { "tok_gold", 4 }, { "tok_green", 2 } }, 0.15f) } } }; private static readonly MachineKind[] KindOrder; private static readonly List<RefineryModDef> AllList; private static readonly Dictionary<string, RefineryModDef> ById; public static IReadOnlyList<RefineryModDef> All => AllList; public static IEnumerable<MachineKind> Kinds => KindOrder.Where(Nodes.ContainsKey); public static bool IsRateKind(MachineKind kind) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Invalid comparison between Unknown and I4 if ((int)kind != 1 && (int)kind != 4 && (int)kind != 6) { return (int)kind == 8; } return true; } public static RefineryModDef Get(string id) { if (string.IsNullOrEmpty(id)) { return null; } if (!ById.TryGetValue(id, out var value)) { return null; } return value; } public static IReadOnlyList<RefineryModDef> For(MachineKind kind) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (!Nodes.TryGetValue(kind, out var value)) { return new RefineryModDef[0]; } return value; } static RefineryModCatalog() { MachineKind[] array = new MachineKind[7]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); KindOrder = (MachineKind[])(object)array; AllList = KindOrder.Where(Nodes.ContainsKey).SelectMany((MachineKind k) => Nodes[k]).ToList(); ById = AllList.ToDictionary((RefineryModDef d) => d.Id); } } public static class RefineryModState { public const string RootKey = "refinery_mods"; private static readonly HashSet<string> OwnedCache = new HashSet<string>(); private static JArray _cachedArray; private static int _cachedCount = -1; private static bool _cacheValid; public const int RefundDivisor = 2; public static event Action Changed; public static bool IsOwned(string id) { if (string.IsNullOrEmpty(id)) { return false; } if (Refresh()) { return OwnedCache.Contains(id); } return false; } public static IEnumerable<string> Owned() { if (!Refresh()) { return new string[0]; } return new List<string>(OwnedCache); } public static bool CanBuy(string id, out string reason) { RefineryModDef refineryModDef = RefineryModCatalog.Get(id); if (refineryModDef == null) { reason = Loc.T("graveoverhaul.research.buy_unknown", "Unknown research"); return false; } if (GameState.I == null) { reason = Loc.T("graveoverhaul.research.buy_no_game", "No game loaded"); return false; } if (IsOwned(id)) { reason = Loc.T("graveoverhaul.research.buy_owned", "Owned"); return false; } string[] parents = refineryModDef.Parents; for (int i = 0; i < parents.Length; i++) { if (!IsOwned(parents[i])) { reason = Loc.T("graveoverhaul.research.buy_parent", "Research the previous upgrade first"); return false; } } foreach (KeyValuePair<string, int> item in refineryModDef.Price) { if (!ColourTokens.CanAfford(item.Key, item.Value)) { reason = Loc.T("graveoverhaul.research.buy_no_shards", "Not enough Shards"); return false; } } reason = null; return true; } public static bool Buy(string id) { if (!CanBuy(id, out var _)) { return false; } GameState i = GameState.I; JArray val = OwnedArray(i, create: true); if (val == null) { return false; } foreach (KeyValuePair<string, int> item in RefineryModCatalog.Get(id).Price) { if (!ColourTokens.Spend(item.Key, item.Value)) { Plugin.Log.LogWarning((object)$"Refinery Research: spending {item.Value} {item.Key} for '{id}' failed part-way."); _cacheValid = false; return false; } } val.Add(JToken.op_Implicit(id)); _cacheValid = false; i.Save(false); GameState.LogEvent("REFINERY RESEARCH BOUGHT — " + id); SafeExec.Run("Refinery Research Changed handler", delegate { RefineryModState.Changed?.Invoke(); }); return true; } public static Dictionary<string, int> RefundFor(RefineryModDef def) { Dictionary<string, int> dictionary = new Dictionary<string, int>(); if (def == null) { return dictionary; } foreach (KeyValuePair<string, int> item in def.Price) { int num = item.Value / 2; if (num > 0) { dictionary[item.Key] = num; } } return dictionary; } public static Dictionary<string, int> RefundFor(IEnumerable<string> ids) { Dictionary<string, int> dictionary = new Dictionary<string, int>(); if (ids == null) { return dictionary; } foreach (string id in ids) { foreach (KeyValuePair<string, int> item in RefundFor(RefineryModCatalog.Get(id))) { dictionary.TryGetValue(item.Key, out var value); dictionary[item.Key] = value + item.Value; } } return dictionary; } public static Dictionary<string, int> PreviewRefund(GameState gs) { if (gs == null) { return new Dictionary<string, int>(); } return RefundFor(Owned()); } public static bool CanRespec(GameState gs) { if (gs != null && gs == GameState.I) { return Owned().Any(); } return false; } public static Dictionary<string, int> Respec(GameState gs, bool save = true) { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown Dictionary<string, int> result = new Dictionary<string, int>(); if (gs == null || gs != GameState.I) { return result; } List<string> list = Owned().ToList(); if (list.Count == 0) { return result; } JObject profile = ProfileReflection.GetProfile(gs); JToken obj = ((profile != null) ? profile["refinery_mods"] : null); JObject val = (JObject)(object)((obj is JObject) ? obj : null); if (val == null) { return result; } result = RefundFor(list); foreach (KeyValuePair<string, int> item in result) { ColourTokens.Grant(item.Key, item.Value); } val["owned"] = (JToken)new JArray(); _cacheValid = false; if (save) { gs.Save(false); } string text = string.Join(", ", result.Select((KeyValuePair<string, int> kv) => kv.Value + " " + kv.Key)); Plugin.Log.LogInfo((object)string.Format("Refinery Research respec: {0} node(s) cleared, refunded {1}.", list.Count, (text.Length > 0) ? text : "nothing")); GameState.LogEvent($"REFINERY RESEARCH RESPEC — {list.Count} nodes, {result.Values.Sum()} shards back"); SafeExec.Run("Refinery Research Changed handler", delegate { RefineryModState.Changed?.Invoke(); }); return result; } private static bool Refresh() { //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Invalid comparison between Unknown and I4 JArray val; try { val = OwnedArray(GameState.I, create: false); } catch (Exception arg) { Plugin.Log.LogError((object)$"Refinery Research: reading owned list failed: {arg}"); return false; } if (val == null) { if (!_cacheValid || _cachedArray != null) { OwnedCache.Clear(); _cachedArray = null; _cachedCount = -1; _cacheValid = true; } return GameState.I != null; } if (_cacheValid && val == _cachedArray && ((JContainer)val).Count == _cachedCount) { return true; } OwnedCache.Clear(); foreach (JToken item in val) { if ((int)item.Type == 8) { string text = (string)item; if (RefineryModCatalog.Get(text) != null) { OwnedCache.Add(text); } } } _cachedArray = val; _cachedCount = ((JContainer)val).Count; _cacheValid = true; return true; } private static JArray OwnedArray(GameState gs, bool create) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_003b: Expected O, but got Unknown JObject profile = ProfileReflection.GetProfile(gs); if (profile == null) { return null; } JToken obj = profile["refinery_mods"]; JObject val = (JObject)(object)((obj is JObject) ? obj : null); if (val == null) { if (!create) { return null; } val = (JObject)(object)(profile["refinery_mods"] = (JToken)new JObject { ["owned"] = (JToken)new JArray() }); } JToken obj2 = val["owned"]; JArray val3 = (JArray)(object)((obj2 is JArray) ? obj2 : null); if (val3 == null && create) { val3 = (JArray)(object)(val["owned"] = (JToken)new JArray()); } return val3; } } [HarmonyPatch(typeof(LineRules), "Rebate")] internal static class RebateRuleFixPatch { private static bool Prefix(in RockState r, ref bool __result) { __result = !r.ingot && !r.gem && !r.jackpot && !r.kicked && !r.split && r.value <= 1.001f; return false; } } internal static class RefineryResearchButtonPatch { [HarmonyPatch(typeof(RefineryScreen), "BuildPage")] internal static class BuildPagePatch { private static void Postfix(RefineryScreen __instance) { SafeExec.Run("Refinery Research button setup", delegate { AddButton(__instance); }); } } [HarmonyPatch(typeof(RefineryScreen), "Hide")] internal static class HidePatch { private static void Postfix() { SafeExec.Run("Refinery Research close on hide", RefineryResearchPanel.CloseIfOpen); } } [HarmonyPatch(typeof(GameRoot), "Update")] internal static class EscapePatch { private static void Prefix(GameRoot __instance) { if (!RefineryResearchPanel.IsOpen) { return; } SafeExec.Run("Refinery Research escape", delegate { if (In.KeyDown((KeyCode)27) && !In.BackClaimed && !Handbook.Showing && !PauseOpen(__instance)) { In.ClaimBack(); RefineryResearchPanel.CloseIfOpen(); } }); } } internal const string ButtonName = "go-research-key"; private static readonly FieldInfo ReportField = AccessTools.Field(typeof(RefineryScreen), "_report"); private static readonly FieldInfo RootField = AccessTools.Field(typeof(RefineryScreen), "_root"); private static readonly FieldInfo PauseField = AccessTools.Field(typeof(GameRoot), "_pause"); private static bool _warned; private static bool PauseOpen(GameRoot root) { object? obj = PauseField?.GetValue(root); PauseMenu val = (PauseMenu)((obj is PauseMenu) ? obj : null); if (val != null && (Object)(object)val != (Object)null) { return val.IsOpen; } return false; } private static void AddButton(RefineryScreen screen) { //IL_00a2: Unknown result type (might be due to invalid IL or missing references) object? obj = ReportField?.GetValue(screen); VisualElement val = (VisualElement)((obj is VisualElement) ? obj : null); if (val == null) { WarnOnce("RefineryScreen._report not found; the Research button is not shown."); } else { if (UQueryExtensions.Q<VisualElement>(val, "go-research-key", (string)null) != null) { return; } VisualElement key = null; key = MetaUi.Key(Loc.T("graveoverhaul.research.ui.button", "RESEARCH"), (Action)delegate { SafeExec.Run("Refinery Research open", delegate { object? obj3 = RootField?.GetValue(screen); VisualElement val2 = (VisualElement)((obj3 is VisualElement) ? obj3 : null); if (val2 == null) { WarnOnce("RefineryScreen._root not found; the Research panel can't open."); } else { VisualElement obj4 = key; RefineryResearchPanel.Open(val2, (VisualElement)(object)((obj4 != null) ? UQueryExtensions.Q<Button>(obj4, (string)null, (string)null) : null)); } }); }, 404f, (Color?)null); key.name = "go-research-key"; key.style.marginTop = StyleLength.op_Implicit(16f); Button obj2 = UQueryExtensions.Q<Button>(key, (string)null, (string)null); if (obj2 != null) { ((VisualElement)obj2).AddToClassList("sfx-swipe"); } val.Add(key); } } private static void WarnOnce(string message) { if (!_warned) { _warned = true; Plugin.Log.LogWarning((object)("Refinery Research: " + message)); } } } [HarmonyPatch(typeof(LineRules), "LaserAdd")] internal static class ResearchLaserAddPatch { private static void Postfix(in RockState r, ref float __result) { float num = 0f; if (RefineryModState.IsOwned("laser_focus_1")) { num += RefineryModCatalog.Get("laser_focus_1").Value; } if (RefineryModState.IsOwned("laser_focus_2")) { num += RefineryModCatalog.Get("laser_focus_2").Value; } if (r.tagged && RefineryModState.IsOwned("igniter_heat_1")) { num += RefineryModCatalog.Get("igniter_heat_1").Value; } if (!(num <= 0f)) { float num2 = LineRules.CapOf(ref r) - r.value; __result = Mathf.Max(__result, Mathf.Min(__result + num, num2)); } } } internal static class RefineryResearchRate { public static float Multiplier(MachineKind kind) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (!RefineryModCatalog.IsRateKind(kind)) { return 1f; } float num = 1f; foreach (RefineryModDef item in RefineryModCatalog.For(kind)) { if (RefineryModState.IsOwned(item.Id)) { num += item.Value; } } return num; } } [HarmonyPatch(typeof(RefineryLine), "PressBonus")] internal static class ResearchPressBonusPatch { private static void Postfix(ref float __result) { if (RefineryModState.IsOwned("press_temper_1")) { __result += RefineryModCatalog.Get("press_temper_1").Value; } if (RefineryModState.IsOwned("press_temper_2")) { __result += RefineryModCatalog.Get("press_temper_2").Value; } } } internal static class RefineryResearchPanel { public static bool IsOpen => ResearchPanel.IsOpenFor(RefineryResearchTree.I); public static void Open(VisualElement screenRoot, VisualElement returnFocus) { ResearchPanel.Open(RefineryResearchTree.I, screenRoot, returnFocus); } public static void CloseIfOpen() { ResearchPanel.CloseIfOpen(RefineryResearchTree.I); } } internal sealed class RefineryResearchTree : ResearchTree { public static readonly RefineryResearchTree I = new RefineryResearchTree(); public override string ModalName => "go-research-modal"; public override string LogName => "Refinery Research"; public override string HubTop => Loc.T("graveoverhaul.research.ui.hub_top", "REFINERY"); public override string OwnedLine => Loc.T("graveoverhaul.research.ui.tip_owned", "Researched · always active on your refinery"); public override string RespecTitle => Loc.T("graveoverhaul.research.respec_title", "RESPEC REFINERY RESEARCH"); private RefineryResearchTree() { } public override IEnumerable<ResearchArm> Arms() { foreach (MachineKind kind in RefineryModCatalog.Kinds) { yield return new ResearchArm(KindName(kind), KindColour(kind), ResearchTree.TextTone(KindColour(kind)), ShapeOf(kind), IconOf(kind), RefineryModCatalog.For(kind)); } } public override IResearchNode Get(string id) { return RefineryModCatalog.Get(id); } public override string ValueText(IResearchNode node) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (!(node is RefineryModDef refineryModDef)) { return ""; } if ((int)refineryModDef.Kind != 3 && !RefineryModCatalog.IsRateKind(refineryModDef.Kind)) { return "+" + refineryModDef.Value.ToString("0.##", Loc.Culture); } return "+" + Mathf.RoundToInt(refineryModDef.Value * 100f) + "%"; } public override string KindWord(ResearchShape shape) { return shape switch { ResearchShape.Diamond => Loc.T("graveoverhaul.research.ui.kind_value", "VALUE"), ResearchShape.Square => Loc.T("station.mods.kind_mult", "MULTIPLIER"), _ => Loc.T("station.mods.kind_hit", "ON HIT"), }; } public override string LegendText(ResearchShape shape) { return shape switch { ResearchShape.Diamond => Loc.T("graveoverhaul.research.ui.legend_diamond", "Value per hit"), ResearchShape.Square => Loc.T("graveoverhaul.research.ui.legend_square", "Multiplier"), ResearchShape.Hex => Loc.T("station.mods.legend_hex", "Capstone"), _ => Loc.T("graveoverhaul.research.ui.legend_circle", "On hit"), }; } public override string AppliesText(string armName) { return Loc.F("graveoverhaul.research.ui.applies", "APPLIES TO EVERY {machine}", new(string, object)[1] { ("machine", armName) }); } public override string RespecBody(string refund) { return Loc.F("graveoverhaul.research.respec_body", "Every Refinery Research upgrade is cleared and stops working at once. Only HALF of the shards you spent come back (rounded down per cost): you get {refund}.", new(string, object)[1] { ("refund", refund) }); } public override bool IsOwned(string id) { return RefineryModState.IsOwned(id); } public override bool CanBuy(string id, out string reason) { return RefineryModState.CanBuy(id, out reason); } public override bool Buy(string id) { return RefineryModState.Buy(id); } public override bool CanRespec(GameState gs) { return RefineryModState.CanRespec(gs); } public override Dictionary<string, int> PreviewRefund(GameState gs) { return RefineryModState.PreviewRefund(gs); } public override void Respec(GameState gs) { RefineryModState.Respec(gs); } public override void Subscribe(Action handler) { RefineryModState.Changed += handler; } public override void Unsubscribe(Action handler) { RefineryModState.Changed -= handler; } private static ResearchShape ShapeOf(MachineKind kind) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 if (RefineryModCatalog.IsRateKind(kind)) { return ResearchShape.Square; } if ((int)kind != 0) { if ((int)kind == 3) { return ResearchShape.Square; } return ResearchShape.Circle; } return ResearchShape.Diamond; } private static string IconOf(MachineKind kind) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected I4, but got Unknown return (int)kind switch { 0 => "beam", 5 => "flame", 3 => "deep", 1 => "crack", _ => "burst", }; } private unsafe static string KindName(MachineKind kind) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected I4, but got Unknown return (int)kind switch { 0 => Loc.T("graveoverhaul.research.ui.kind_laser", "LASER"), 5 => Loc.T("station.refinery.machine_igniter", "IGNITER"), 3 => Loc.T("station.refinery.machine_press", "PRESS"), 1 => Loc.T("station.refinery.machine_crusher", "CRUSHER"), 4 => Loc.T("station.refinery.machine_kickback", "KICKBACK"), 6 => Loc.T("station.refinery.machine_compliance", "COMPLIANCE"), 8 => Loc.T("station.refinery.tray_lotto", "LOTTO"), 2 => Loc.T("station.refinery.tray_sorter", "SORTER"), _ => ((object)(*(MachineKind*)(&kind))/*cast due to .constrained prefix*/).ToString().ToUpperInvariant(), }; } private static Color KindColour(MachineKind kind) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected I4, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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: Unknown result type (might be due to invalid IL or missing references) return (Color)((int)kind switch { 0 => RefineryPalette.Laser, 5 => RefineryPalette.Tagger, 1 => RefineryPalette.Crusher, 4 => RefineryPalette.Rebate, 6 => RefineryPalette.Cutter, 8 => RefineryPalette.Lotto, 2 => RefineryPalette.Sorter, _ => RefineryPalette.Press, }); } } [HarmonyPatch(typeof(RefineryScreen), "State")] internal static class RefineryStatePatch { private static void Postfix(CardKind kind, ref CardState __result) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 if ((int)kind == 1) { RefineryLine board = RefineryLine.Board; if (board != null) { int num = RefineryLine.Tiers.Length; __result.maxed = board.Tier >= num; __result.progress = Loc.F("station.refinery.tier_of", "TIER {tier} / {max}", new(string, object)[2] { ("tier", board.Tier), ("max", num) }); } } } } [HarmonyPatch(typeof(RefineryScreen), "PaintExpand")] internal static class PaintExpandPatch { pri