using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using GraveyardOrbit.Audio;
using GraveyardOrbit.UI;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace GraveyardOrbit.Tweaks
{
internal static class DronePricePatches
{
[HarmonyPatch(typeof(DroneEconomy), "BuyPriceAt")]
internal static class BuyHalfPatch
{
private static void Postfix(ref DronePrice __result)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
try
{
__result = Half(__result);
}
catch
{
}
}
}
[HarmonyPatch(typeof(DroneEconomy), "LevelPriceAt")]
internal static class LevelHalfPatch
{
private static void Postfix(ref DronePrice __result)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
try
{
__result = Half(__result);
}
catch
{
}
}
}
[HarmonyPatch(typeof(DroneEconomy), "RepairPriceAt")]
internal static class RepairPatch
{
private static void Postfix(ref DronePrice __result)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
try
{
__result = new DronePrice(100, __result.Green, __result.ShardKey, __result.Shards);
}
catch
{
}
}
}
private static DronePrice Half(DronePrice p)
{
//IL_0000: 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_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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)
int val = (int)Math.Round((double)p.Money * 0.5, MidpointRounding.AwayFromZero);
return new DronePrice(Math.Max(1, val), p.Green, p.ShardKey, p.Shards);
}
}
internal static class SorterColors
{
private const int NoSecondary = 7;
internal static Colour Secondary(Machine m)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
if (m != null && (int)m.kind == 2)
{
int lucky = m.lucky;
if (lucky >= 1 && lucky <= 5)
{
return (Colour)(byte)lucky;
}
return (Colour)0;
}
return (Colour)0;
}
internal static void SetSecondary(Machine m, Colour c)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Invalid comparison between Unknown and I4
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
if (m != null)
{
m.lucky = (((int)c < 1 || (int)c > 5) ? 7 : ((int)c));
}
}
}
internal static class DualSorterPatches
{
[HarmonyPatch(typeof(RefineryLine), "SetSorterColour")]
internal static class SetSorterColourPatch
{
private static bool Prefix(Machine m, Colour c)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: 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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: 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_0070: 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_0061: Unknown result type (might be due to invalid IL or missing references)
if (m == null || (int)m.kind != 2)
{
return true;
}
Colour colour = m.colour;
Colour val = SorterColors.Secondary(m);
if ((int)c == 0)
{
m.colour = (Colour)0;
SorterColors.SetSecondary(m, (Colour)0);
return false;
}
if (c == colour)
{
if ((int)val != 0)
{
m.colour = val;
SorterColors.SetSecondary(m, (Colour)0);
}
else
{
m.colour = (Colour)0;
}
return false;
}
if (c == val)
{
SorterColors.SetSecondary(m, (Colour)0);
return false;
}
if ((int)colour == 0)
{
m.colour = c;
SorterColors.SetSecondary(m, (Colour)0);
}
else
{
SorterColors.SetSecondary(m, c);
}
return false;
}
}
[HarmonyPatch(typeof(RefinerySim), "CycleSorterColour")]
internal static class CycleSorterColourPatch
{
private static bool Prefix(RefinerySim __instance, Machine s)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
if (s == null || (int)s.kind != 2)
{
return true;
}
RefineryLine line = __instance.Line;
if (line == null)
{
return true;
}
List<Colour> list = new List<Colour>();
Colour[] substrates = RefineryPalette.Substrates;
foreach (Colour item in substrates)
{
if (line.SeenColours.Contains(item))
{
list.Add(item);
}
}
if (list.Count == 0)
{
return false;
}
int num = list.IndexOf(s.colour);
Colour val = (s.colour = list[(num + 1) % list.Count]);
if (SorterColors.Secondary(s) == val)
{
SorterColors.SetSecondary(s, (Colour)0);
}
__instance.SaveState();
__instance.Rebuild();
__instance.OnEconomyChanged?.Invoke();
return false;
}
}
[HarmonyPatch(typeof(RefineryLine), "SortedTo")]
internal static class SortedToPatch
{
private static void Postfix(RefineryLine __instance, int lane, Colour c, ref bool __result)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
if (!__result && (int)c != 0)
{
Machine val = __instance.SorterOn(lane);
if (val != null && SorterColors.Secondary(val) == c)
{
__result = true;
}
}
}
}
[HarmonyPatch(typeof(RefineryPalette), "LabelOf")]
internal static class LabelOfPatch
{
private static void Postfix(Machine m, ref string __result)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: 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)
if (m != null && (int)m.kind == 2)
{
Colour val = SorterColors.Secondary(m);
if ((int)val != 0)
{
string item = (((int)m.colour == 0) ? Loc.T("station.refinery.color_any", "ANY") : RefineryPalette.Name(m.colour));
__result = Loc.F("station.refinery.machine_sorter_dual", "{primary}+{secondary}\nSORTER", new(string, object)[2]
{
("primary", item),
("secondary", RefineryPalette.Name(val))
});
}
}
}
}
[HarmonyPatch(typeof(RefineryScreen), "PartDesc")]
internal static class PartDescPatch
{
private static void Postfix(CardKind kind, ref string __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 == 3)
{
__result = Loc.T("station.refinery.desc_sorter_dual", "Sits at the start of a lane and sends one or two colours down it. Click a colour to add it; click it again to remove it. Max two. One lane always stays open.");
}
}
}
[HarmonyPatch(typeof(RefineryScreen), "State")]
internal static class DialStatePatch
{
private static void Postfix(CardKind kind, RefineryScreen __instance, 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_0016: Invalid comparison between Unknown and I4
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
if ((int)kind == 6)
{
Machine selected = __instance.Selected;
if (selected != null && (int)selected.kind == 2)
{
Colour val = SorterColors.Secondary(selected);
__result.desc = Loc.T("station.refinery.dial_desc_dual", "Click a colour to select it; click it again to remove it. Up to two colours go down this lane.");
string text = (((int)selected.colour == 0) ? Loc.T("station.refinery.dial_no_color", "NO COLOR") : RefineryPalette.Name(selected.colour));
__result.progress = (((int)val == 0) ? text : (text + " + " + RefineryPalette.Name(val)));
}
}
}
}
[HarmonyPatch(typeof(RefineryScreen), "OpenSocket")]
internal static class SorterPopoverPatch
{
private unsafe static void Postfix(RefineryScreen __instance, Machine m)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: 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_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
if (m == null || (int)m.kind != 2)
{
return;
}
VisualElement popover = __instance.Popover;
if (popover == null)
{
return;
}
Label val = UQueryExtensions.Q<Label>(popover, (string)null, "rl-opt__desc");
if (val != null)
{
((TextElement)val).text = Loc.T("station.refinery.dial_desc_dual", "Click a colour to select it; click it again to remove it. Up to two colours go down this lane.");
}
Colour val2 = SorterColors.Secondary(m);
Colour[] substrates = RefineryPalette.Substrates;
for (int i = 0; i < substrates.Length; i++)
{
Colour val3 = substrates[i];
Button val4 = UQueryExtensions.Q<Button>(popover, "pop-dial-" + ((object)(*(Colour*)(&val3))/*cast due to .constrained prefix*/).ToString(), (string)null);
if (val4 != null)
{
((TextElement)val4).text = RefineryPalette.Name(val3) + ((val2 == val3) ? " +" : "");
}
}
}
}
[HarmonyPatch(typeof(RefineryLineElement), "DrawMachine")]
internal static class SorterDrawPatch
{
private static readonly List<Vector2> Poly = new List<Vector2>(8);
private static readonly List<Vector2> Upper = new List<Vector2>(12);
private static readonly List<Vector2> Lower = new List<Vector2>(12);
private static void Postfix(Painter2D p, Machine m, Vector2 c, bool ghost)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
if (m == null || (int)m.kind != 2)
{
return;
}
Colour val = SorterColors.Secondary(m);
if ((int)val != 0)
{
float num = ((RefineryLine.Board != null) ? RefineryLine.Board.Scale : 1f);
float num2 = 124f * num;
if (!(num2 <= 1f))
{
float num3 = num2 * 0.09f;
Color val2 = (((int)m.colour == 0) ? RefineryPalette.Sorter : RefineryPalette.Of(m.colour));
Color val3 = RefineryPalette.Of(val);
BuildOctagon(Poly, c, num2, num3);
float split = c.x + c.y;
ClipHalf(Poly, Upper, split, upper: true);
ClipHalf(Poly, Lower, split, upper: false);
float num4 = (ghost ? 0.5f : (0.5f + 0.15f * Mathf.Sin(Time.realtimeSinceStartup * 9f)));
p.fillColor = new Color(0.055f, 0.06f, 0.07f, ghost ? 0.5f : 0.95f);
FillPoly(p, Poly);
Color val4 = Color.Lerp(val2, Color.white, 0.25f);
Color val5 = Color.Lerp(val3, Color.white, 0.25f);
p.fillColor = new Color(val4.r, val4.g, val4.b, num4);
FillPoly(p, Upper);
p.fillColor = new Color(val5.r, val5.g, val5.b, num4);
FillPoly(p, Lower);
Color val6 = Color.Lerp(val2, val3, 0.5f);
p.strokeColor = Color.Lerp(val6, Color.white, 0.3f);
p.lineWidth = 3f;
RefineryLineElement.Octagon(p, c, num2, num3);
p.Stroke();
Color val7 = Color.Lerp(val6, Color.white, 0.45f);
RefineryLineElement.Glyph(p, m.kind, c, num2 / 78f, m.level, val7, 0f, 0f);
}
}
}
private static void BuildOctagon(List<Vector2> into, Vector2 c, float size, float notch)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
float num = size * 0.5f;
into.Clear();
into.Add(new Vector2(c.x - num + notch, c.y - num));
into.Add(new Vector2(c.x + num - notch, c.y - num));
into.Add(new Vector2(c.x + num, c.y - num + notch));
into.Add(new Vector2(c.x + num, c.y + num - notch));
into.Add(new Vector2(c.x + num - notch, c.y + num));
into.Add(new Vector2(c.x - num + notch, c.y + num));
into.Add(new Vector2(c.x - num, c.y + num - notch));
into.Add(new Vector2(c.x - num, c.y - num + notch));
}
private static void ClipHalf(List<Vector2> src, List<Vector2> into, float split, bool upper)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
into.Clear();
for (int i = 0; i < src.Count; i++)
{
Vector2 val = src[i];
Vector2 val2 = src[(i + 1) % src.Count];
float num = val.x + val.y - split;
float num2 = val2.x + val2.y - split;
bool num3 = (upper ? (num <= 0f) : (num >= 0f));
bool flag = (upper ? (num2 <= 0f) : (num2 >= 0f));
if (num3)
{
into.Add(val);
}
if (num3 != flag)
{
float num4 = num / (num - num2);
into.Add(new Vector2(val.x + (val2.x - val.x) * num4, val.y + (val2.y - val.y) * num4));
}
}
}
private static void FillPoly(Painter2D p, List<Vector2> pts)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
if (pts.Count >= 3)
{
p.BeginPath();
p.MoveTo(pts[0]);
for (int i = 1; i < pts.Count; i++)
{
p.LineTo(pts[i]);
}
p.ClosePath();
p.Fill((FillRule)0);
}
}
}
}
internal static class IgniterPatches
{
[HarmonyPatch(typeof(RefineryLine), "LevelUp")]
internal static class LevelUpPatch
{
private static bool Prefix(Machine m)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
if (m == null || (int)m.kind != 5)
{
return true;
}
if (m.level >= 3)
{
return true;
}
m.level++;
return false;
}
}
[HarmonyPatch(typeof(RefineryLine), "RateOf")]
internal static class RatePatch
{
private static void Postfix(Machine m, ref float __result)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
if (m != null && (int)m.kind == 5)
{
__result = Rate(m.level);
}
}
}
[HarmonyPatch(typeof(RefineryScreen), "Levels")]
internal static class LevelsPatch
{
private static void Postfix(Machine m, ref bool __result)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
if (m != null && (int)m.kind == 5)
{
__result = true;
}
}
}
[HarmonyPatch(typeof(RefineryScreen), "LevelPrice")]
internal static class LevelPricePatch
{
private static void Postfix(Machine m, ref int __result)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
if (m != null && (int)m.kind == 5)
{
__result = LevelPrice(m);
}
}
}
[HarmonyPatch(typeof(RefinerySim), "Tick")]
internal static class SimTickPatch
{
private static void Postfix(RefinerySim __instance)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Invalid comparison between Unknown and I4
float clock = __instance.Clock;
IReadOnlyList<MachineStat> machines = __instance.Machines;
for (int i = 0; i < machines.Count; i++)
{
MachineStat val = machines[i];
if (val?.m != null && (int)val.m.kind == 5 && val.lastFire == clock)
{
val.ready = clock + 1f / Rate(val.m.level);
}
}
}
}
[HarmonyPatch(typeof(RefineryScreen), "Numbers")]
internal static class NumbersPatch
{
private static void Postfix(RefineryScreen __instance, Machine m, ref string __result)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
if (m != null && (int)m.kind == 5)
{
int num = 0;
try
{
RefinerySim value = Traverse.Create((object)__instance).Field("_sim").GetValue<RefinerySim>();
num = ((value == null) ? ((int?)null) : value.StatOf(m)?.visitHits).GetValueOrDefault();
}
catch
{
return;
}
__result = Loc.F("station.refinery.num_igniter", "{rate} ROCKS / S · IGNITED {n} THIS HAUL", new(string, object)[2]
{
("rate", Rate(m.level).ToString("0.#")),
("n", num)
});
}
}
}
[HarmonyPatch(typeof(RefineryScreen), "State")]
internal static class LevelCardPatch
{
private static void Postfix(CardKind kind, RefineryScreen __instance, 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_0016: Invalid comparison between Unknown and I4
if ((int)kind == 5)
{
Machine selected = __instance.Selected;
if (selected != null && (int)selected.kind == 5)
{
int num = LevelPrice(selected);
bool flag = selected.level >= 3;
int num2 = ((GameState.I != null) ? GameState.I.Money : 0);
__result.cost = num;
__result.maxed = flag;
__result.affordable = !flag && num2 >= num;
__result.progress = $"LEVEL {selected.level} / 3";
__result.desc = (flag ? "" : ((selected.level < 2) ? "Triggers faster: 4.5 rocks / s." : "Triggers faster: 6 rocks / s."));
}
}
}
}
private static int LevelPrice(Machine m)
{
if (m == null || m.level >= 2)
{
return 350;
}
return 200;
}
private static float Rate(int level)
{
if (level >= 3)
{
return 6f;
}
if (level == 2)
{
return 4.5f;
}
return 3f;
}
}
internal static class ScrapRefund
{
private static readonly List<(string key, int amount)> Refunded = new List<(string, int)>();
internal static bool HasRefund => Refunded.Count > 0;
internal static void Clear()
{
Refunded.Clear();
}
internal static void GrantFor(DroneData d)
{
//IL_002f: 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_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
Refunded.Clear();
if (d == null)
{
return;
}
int colourShards = DroneCatalog.ColourShards;
if (colourShards <= 0)
{
return;
}
HashSet<string> hashSet = new HashSet<string>();
foreach (DroneSpec spec in d.Specs)
{
if (DroneCatalog.IsColourSpec(spec))
{
string text = ColourTokens.KeyOfColour(DroneCatalog.SpecColour(spec));
if (!string.IsNullOrEmpty(text) && hashSet.Add(text))
{
ColourTokens.Grant(text, colourShards);
Refunded.Add((text, colourShards));
}
}
}
}
internal static string Describe()
{
if (Refunded.Count == 0)
{
return null;
}
StringBuilder stringBuilder = new StringBuilder();
foreach (var (text, num) in Refunded)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(" · ");
}
stringBuilder.Append('+').Append(num).Append(' ');
stringBuilder.Append((num == 1) ? ColourTokens.Name(text) : ColourTokens.NamePlural(text));
}
return stringBuilder.ToString();
}
}
internal static class ScrapRefundPatches
{
[HarmonyPatch(typeof(DroneEconomy), "Scrap")]
internal static class ScrapPatch
{
private static void Postfix(DroneData d, bool __result)
{
ScrapRefund.Clear();
if (!__result)
{
return;
}
ScrapRefund.GrantFor(d);
if (ScrapRefund.HasRefund)
{
GameState i = GameState.I;
if (i != null)
{
i.Save(false);
}
}
}
}
[HarmonyPatch(typeof(DroneBayScreen), "PressScrap")]
internal static class ScrapMessagePatch
{
private static void Prefix()
{
ScrapRefund.Clear();
}
private static void Postfix(DroneBayScreen __instance, bool __result)
{
if (!__result || !ScrapRefund.HasRefund)
{
return;
}
string text = ScrapRefund.Describe();
if (string.IsNullOrEmpty(text))
{
return;
}
try
{
Traverse val = Traverse.Create((object)__instance);
string value = val.Field("_message").GetValue<string>();
if (!string.IsNullOrEmpty(value))
{
val.Field("_message").SetValue((object)(value + " · " + text));
__instance.Refresh();
}
}
catch
{
}
}
}
}
internal static class ShipyardBuyAll
{
private sealed class Candidate
{
internal PlacedPart part;
internal long cost;
internal int level;
internal int uid;
internal bool magnet;
}
internal static bool CanBuyAnything()
{
GameState i = GameState.I;
AccretionShip val = ((i != null) ? i.Ship : null);
if (i == null || val == null)
{
return false;
}
foreach (Candidate item in NormalCandidates(val))
{
if (item.cost <= i.Money && IsLegal(item.part, i, val, out var _))
{
return true;
}
}
foreach (Candidate item2 in DriveCandidates(val))
{
if (item2.cost <= i.Money && PartLevels.CanBuy(i, item2.part))
{
return true;
}
}
return ReactorCandidates(i, val).Count > 0;
}
internal static void Run(ShipyardAccretionScreen screen)
{
GameState i = GameState.I;
AccretionShip val = ((i != null) ? i.Ship : null);
if (i != null && val != null)
{
bool bought = false;
BuyNormal(i, val, ref bought);
while (TryBuyDrive(i, val))
{
bought = true;
}
while (TryBuyReactor(i, val))
{
bought = true;
}
if (bought)
{
Sfx.Play("buy", 0f);
screen.ProbeRefresh();
}
else
{
UpdateButton(screen);
}
}
}
private static void BuyNormal(GameState gs, AccretionShip ship, ref bool bought)
{
HashSet<int> hashSet = new HashSet<int>();
int num = 0;
while (num++ < 500)
{
List<Candidate> list = NormalCandidates(ship);
list.Sort(CompareNormal);
bool flag = false;
foreach (Candidate item in list)
{
if (hashSet.Contains(item.uid))
{
continue;
}
if (item.cost > gs.Money)
{
break;
}
if (!IsLegal(item.part, gs, ship, out var energyBlocked))
{
if (energyBlocked)
{
if (TryBuyDrive(gs, ship))
{
bought = true;
hashSet.Clear();
flag = true;
break;
}
if (TryBuyReactor(gs, ship))
{
bought = true;
}
}
hashSet.Add(item.uid);
}
else
{
if (PartLevels.Buy(gs, item.part))
{
bought = true;
hashSet.Clear();
flag = true;
break;
}
hashSet.Add(item.uid);
}
}
if (!flag)
{
break;
}
}
}
private static bool IsLegal(PlacedPart p, GameState gs, AccretionShip ship, out bool energyBlocked)
{
energyBlocked = false;
if (PartLevels.IsMaxed(p))
{
return false;
}
if (!PartTiers.UsesLadder(p))
{
return PartLevels.CanBuy(gs, p);
}
if (PartTiers.IsLadderMaxed(p))
{
return false;
}
string text = default(string);
if (PartTiers.CanLevelUpIgnoringMoney(gs, p, ref text))
{
return true;
}
if (text != Loc.T("data.parts.level_no_fit", "Does not fit"))
{
int num = PartTiers.EnergyStepOfNext(p);
energyBlocked = num > 0 && ship.EnergyUsed + num > ship.EnergyCap;
}
return false;
}
private static List<Candidate> NormalCandidates(AccretionShip ship)
{
List<Candidate> list = new List<Candidate>();
foreach (CardModel card in UpgradeCards.BuildCards())
{
if (!(card.kind != "part"))
{
PlacedPart val = ((IEnumerable<PlacedPart>)ship.placed).FirstOrDefault((Func<PlacedPart, bool>)((PlacedPart x) => x.uid == card.uid));
if (val != null && !AccretionShip.IsDrive(val) && !PartLevels.IsMaxed(val) && (PartTiers.UsesLadder(val) || PartLevels.HasLevels(card.modelId)))
{
list.Add(new Candidate
{
part = val,
cost = PartLevels.CostOf(val),
level = val.level,
uid = val.uid
});
}
}
}
return list;
}
private static List<Candidate> DriveCandidates(AccretionShip ship)
{
List<Candidate> list = new List<Candidate>();
foreach (PlacedPart item in ship.placed)
{
if (AccretionShip.IsDrive(item) && item.level < 5)
{
list.Add(new Candidate
{
part = item,
cost = PartLevels.CostOf(item),
level = item.level,
uid = item.uid
});
}
}
return list;
}
private static List<Candidate> ReactorCandidates(GameState gs, AccretionShip ship)
{
List<Candidate> list = new List<Candidate>();
AddReactor(gs, ship, magnet: true, list);
AddReactor(gs, ship, magnet: false, list);
return list;
}
private static void AddReactor(GameState gs, AccretionShip ship, bool magnet, List<Candidate> list)
{
int num = (magnet ? ship.magnetLevel : ship.boostLevel);
if (num < 5 && PartLevels.CanBuyReactorUpgrade(gs, magnet, num))
{
list.Add(new Candidate
{
cost = PartLevels.Cost("REACTOR", num),
level = num,
magnet = magnet
});
}
}
private static int CompareNormal(Candidate a, Candidate b)
{
int num = a.cost.CompareTo(b.cost);
if (num != 0)
{
return num;
}
num = a.level.CompareTo(b.level);
if (num == 0)
{
return a.uid.CompareTo(b.uid);
}
return num;
}
private static int CompareDrive(Candidate a, Candidate b)
{
int num = a.level.CompareTo(b.level);
if (num != 0)
{
return num;
}
num = a.cost.CompareTo(b.cost);
if (num == 0)
{
return a.uid.CompareTo(b.uid);
}
return num;
}
private static int CompareReactor(Candidate a, Candidate b)
{
int num = a.cost.CompareTo(b.cost);
if (num != 0)
{
return num;
}
num = ((!a.magnet) ? 1 : 0).CompareTo((!b.magnet) ? 1 : 0);
if (num == 0)
{
return a.level.CompareTo(b.level);
}
return num;
}
private static bool TryBuyDrive(GameState gs, AccretionShip ship)
{
List<Candidate> list = DriveCandidates(ship);
list.Sort(CompareDrive);
foreach (Candidate item in list)
{
if (item.cost <= gs.Money && PartLevels.Buy(gs, item.part))
{
return true;
}
}
return false;
}
private static bool TryBuyReactor(GameState gs, AccretionShip ship)
{
List<Candidate> list = ReactorCandidates(gs, ship);
list.Sort(CompareReactor);
foreach (Candidate item in list)
{
if (item.cost > gs.Money)
{
break;
}
if (PartLevels.BuyReactorUpgrade(gs, item.magnet))
{
return true;
}
}
return false;
}
internal static void UpdateButton(ShipyardAccretionScreen screen)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
try
{
VisualElement value = Traverse.Create((object)screen).Field("_hlp").GetValue<VisualElement>();
Button val = ((value != null) ? UQueryExtensions.Q<Button>(value, "buy-all", (string)null) : null);
if (val != null)
{
bool flag = CanBuyAnything();
((VisualElement)val).SetEnabled(flag);
((VisualElement)val).style.opacity = StyleFloat.op_Implicit(flag ? 1f : 0.45f);
if (flag)
{
((VisualElement)val).RemoveFromClassList("pad-skip");
}
else
{
((VisualElement)val).AddToClassList("pad-skip");
}
}
}
catch
{
}
}
}
internal static class ShipyardBuyAllPatches
{
[HarmonyPatch(typeof(ShipyardAccretionScreen), "BuildHelperUi")]
internal static class BuildHelperPatch
{
private static void Postfix(ShipyardAccretionScreen __instance)
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Expected O, but got Unknown
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Expected O, but got Unknown
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: 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_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_026c: Unknown result type (might be due to invalid IL or missing references)
//IL_0271: 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)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_0288: Unknown result type (might be due to invalid IL or missing references)
//IL_0292: Unknown result type (might be due to invalid IL or missing references)
//IL_029c: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Expected O, but got Unknown
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_0301: Unknown result type (might be due to invalid IL or missing references)
try
{
VisualElement value = Traverse.Create((object)__instance).Field("_hlp").GetValue<VisualElement>();
VisualElement value2 = Traverse.Create((object)__instance).Field("_hlpHead").GetValue<VisualElement>();
VisualElement value3 = Traverse.Create((object)__instance).Field("_hlpScroll").GetValue<VisualElement>();
if (value == null || UQueryExtensions.Q<Button>(value, "buy-all", (string)null) != null)
{
return;
}
VisualElement val = new VisualElement
{
name = "buy-all-host"
};
val.style.flexShrink = StyleFloat.op_Implicit(0f);
val.style.paddingLeft = StyleLength.op_Implicit(4f);
val.style.paddingRight = StyleLength.op_Implicit(16f);
val.style.paddingTop = StyleLength.op_Implicit(4f);
val.style.paddingBottom = StyleLength.op_Implicit(12f);
Button button = new Button
{
name = "buy-all"
};
((VisualElement)button).AddToClassList("pad-nav");
((VisualElement)button).style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2);
((VisualElement)button).style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
((VisualElement)button).style.flexShrink = StyleFloat.op_Implicit(0f);
((VisualElement)button).style.paddingLeft = StyleLength.op_Implicit(20f);
((VisualElement)button).style.paddingRight = StyleLength.op_Implicit(18f);
((VisualElement)button).style.paddingTop = StyleLength.op_Implicit(16f);
((VisualElement)button).style.paddingBottom = StyleLength.op_Implicit(16f);
((VisualElement)button).style.marginBottom = StyleLength.op_Implicit(0f);
((VisualElement)button).style.backgroundColor = StyleColor.op_Implicit(Color.clear);
((VisualElement)button).style.borderLeftWidth = StyleFloat.op_Implicit(0f);
((VisualElement)button).style.borderRightWidth = StyleFloat.op_Implicit(0f);
((VisualElement)button).style.borderTopWidth = StyleFloat.op_Implicit(0f);
((VisualElement)button).style.borderBottomWidth = StyleFloat.op_Implicit(0f);
SlabFrame frame = new SlabFrame
{
Notch = 14f,
Stroke = 2f,
StrokeColor = MetaUi.Fade(MetaUi.Orange, 0.55f),
FillColor = MetaUi.Hex(1512207),
TintColor = Color.clear
};
frame.Behind((VisualElement)(object)button);
Label val2 = MetaUi.Text(Loc.T("station.shipyard.buy_all", "BUY ALL"), (Face)0, 24f, MetaUi.Ink, 1.5f, false);
((VisualElement)val2).style.flexGrow = StyleFloat.op_Implicit(1f);
((VisualElement)button).Add((VisualElement)(object)val2);
Action action = delegate
{
ShipyardBuyAll.Run(__instance);
};
button.clicked += action;
PadNav.Register((VisualElement)(object)button, action, (Action)delegate
{
if (((VisualElement)button).enabledSelf)
{
Paint(on: true);
}
}, (Action)delegate
{
Paint(on: false);
}, (Action)null, (Action)null, (string)null, (string)null, (string)null, (Func<string[]>)(() => new string[4]
{
Loc.T("station.shipyard.buy_all", "BUY ALL"),
null,
null,
PadNav.ExitWord
}));
((CallbackEventHandler)button).RegisterCallback<PointerEnterEvent>((EventCallback<PointerEnterEvent>)delegate
{
if (((VisualElement)button).enabledSelf)
{
Paint(on: true);
}
}, (TrickleDown)0);
((CallbackEventHandler)button).RegisterCallback<PointerLeaveEvent>((EventCallback<PointerLeaveEvent>)delegate
{
Paint(on: false);
}, (TrickleDown)0);
val.Add((VisualElement)(object)button);
int num = ((value2 != null) ? value.IndexOf(value2) : ((value3 != null) ? value.IndexOf(value3) : (-1)));
if (num < 0)
{
value.Add(val);
}
else
{
value.Insert(num, val);
}
ShipyardBuyAll.UpdateButton(__instance);
void Paint(bool on)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
frame.Stroke = (on ? 4f : 2f);
frame.StrokeColor = (on ? Color.Lerp(MetaUi.OrangeLt, Color.white, 0.45f) : MetaUi.Fade(MetaUi.Orange, 0.55f));
frame.FillColor = (on ? MetaUi.Hex(3021834) : MetaUi.Hex(1512207));
frame.TintColor = (on ? MetaUi.Fade(MetaUi.Orange, 0.3f) : Color.clear);
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(ShipyardAccretionScreen), "RenderHelper")]
internal static class RenderHelperPatch
{
private static void Postfix(ShipyardAccretionScreen __instance)
{
ShipyardBuyAll.UpdateButton(__instance);
}
}
}
internal static class ShipyardShiftBuy
{
internal static string Hint => Loc.T("tweaks.shipyard.shift_buy_max", "SHIFT+CLICK TO BUY MAX");
internal static bool ShiftHeld
{
get
{
Keyboard current = Keyboard.current;
if (current != null)
{
if (!((ButtonControl)current.leftShiftKey).isPressed)
{
return ((ButtonControl)current.rightShiftKey).isPressed;
}
return true;
}
return false;
}
}
internal static bool CanBuyMax(GameState gs, PlacedPart part)
{
if (gs == null || part == null)
{
return false;
}
if (part.type == "reactor")
{
return CanBuyReactor(gs);
}
return PartLevels.CanBuy(gs, part);
}
private static bool CanBuyReactor(GameState gs)
{
AccretionShip val = ((gs != null) ? gs.Ship : null);
if (val == null)
{
return false;
}
if (!PartLevels.CanBuyReactorUpgrade(gs, true, val.magnetLevel))
{
return PartLevels.CanBuyReactorUpgrade(gs, false, val.boostLevel);
}
return true;
}
internal static bool BuyMax(GameState gs, PlacedPart part)
{
if (gs == null || part == null)
{
return false;
}
if (part.type == "reactor")
{
return BuyMaxReactor(gs);
}
return BuyMaxPart(gs, part);
}
private static bool BuyMaxPart(GameState gs, PlacedPart part)
{
bool result = false;
for (int i = 0; i < 18; i++)
{
if (!PartLevels.CanBuy(gs, part))
{
break;
}
if (!PartLevels.Buy(gs, part))
{
break;
}
result = true;
}
return result;
}
private static bool BuyMaxReactor(GameState gs)
{
AccretionShip val = ((gs != null) ? gs.Ship : null);
if (val == null)
{
return false;
}
bool result = false;
for (int i = 0; i < 12; i++)
{
bool flag = PartLevels.CanBuyReactorUpgrade(gs, true, val.magnetLevel);
bool flag2 = PartLevels.CanBuyReactorUpgrade(gs, false, val.boostLevel);
if (!flag && !flag2)
{
break;
}
bool flag3;
if (flag && flag2)
{
int num = PartLevels.Cost("REACTOR", val.magnetLevel);
int num2 = PartLevels.Cost("REACTOR", val.boostLevel);
flag3 = num <= num2;
}
else
{
flag3 = flag;
}
if (!PartLevels.BuyReactorUpgrade(gs, flag3))
{
break;
}
result = true;
}
return result;
}
internal static void Apply(ShipyardAccretionScreen screen, bool bought)
{
if (!bought)
{
return;
}
if (Application.isPlaying)
{
Sfx.Play("buy", 0f);
}
screen.ProbeRefresh();
try
{
Traverse.Create((object)screen).Method("RefreshPartCardForWallet", Array.Empty<object>()).GetValue();
}
catch
{
}
}
}
internal static class ShipyardShiftBuyKeyPatches
{
[HarmonyPatch(typeof(ShipyardAccretionScreen), "BuyUpgrade")]
internal static class BuyUpgradePatch
{
private static bool Prefix(ShipyardAccretionScreen __instance, List<int> uids)
{
if (!ShipyardShiftBuy.ShiftHeld)
{
return true;
}
try
{
GameState i = GameState.I;
AccretionShip val = ((i != null) ? i.Ship : null);
if (i == null || val == null)
{
return true;
}
bool flag = false;
foreach (int uid in uids)
{
PlacedPart val2 = ((IEnumerable<PlacedPart>)val.placed).FirstOrDefault((Func<PlacedPart, bool>)((PlacedPart p) => p.uid == uid));
if (val2 != null && ShipyardShiftBuy.BuyMax(i, val2))
{
flag = true;
}
}
if (!flag)
{
return true;
}
ShipyardShiftBuy.Apply(__instance, bought: true);
return false;
}
catch
{
return true;
}
}
}
[HarmonyPatch(typeof(ShipyardAccretionScreen), "BuyCoreUpgrade")]
internal static class BuyCoreUpgradePatch
{
private static bool Prefix(ShipyardAccretionScreen __instance, bool magnet)
{
if (!ShipyardShiftBuy.ShiftHeld)
{
return true;
}
try
{
GameState i = GameState.I;
if (((i != null) ? i.Ship : null) == null)
{
return true;
}
bool flag = false;
for (int j = 0; j < 6; j++)
{
if (!PartLevels.BuyReactorUpgrade(i, magnet))
{
break;
}
flag = true;
}
if (!flag)
{
return true;
}
ShipyardShiftBuy.Apply(__instance, bought: true);
return false;
}
catch
{
return true;
}
}
}
}
internal static class ShipyardShiftBuyGridPatches
{
[HarmonyPatch(typeof(ShipyardAccretionScreen), "ClickAction")]
internal static class ClickActionPatch
{
private static bool Prefix(ShipyardAccretionScreen __instance)
{
try
{
object value = Traverse.Create((object)__instance).Field("_down").GetValue();
if (value == null)
{
return true;
}
Traverse val = Traverse.Create(value);
string value2 = val.Field("kind").GetValue<string>();
bool value3 = val.Field("shift").GetValue<bool>();
int uid = val.Field("uid").GetValue<int>();
if (!value3 || value2 != "ship")
{
return true;
}
GameState i = GameState.I;
AccretionShip val2 = ((i != null) ? i.Ship : null);
if (val2 == null || val2.pick != null)
{
return true;
}
PlacedPart val3 = ((IEnumerable<PlacedPart>)val2.placed).FirstOrDefault((Func<PlacedPart, bool>)((PlacedPart p) => p.uid == uid));
if (val3 == null || !ShipyardShiftBuy.CanBuyMax(i, val3))
{
return true;
}
if (ShipyardShiftBuy.BuyMax(i, val3))
{
try
{
if (val3.type == "reactor")
{
__instance.ClearSelection();
}
else
{
__instance.SelectPartsForUpgrades((IList<int>)new List<int> { uid });
}
}
catch
{
}
ShipyardShiftBuy.Apply(__instance, bought: true);
return false;
}
return true;
}
catch
{
return true;
}
}
}
}
internal static class ShipyardShiftBuyCardPatches
{
[HarmonyPatch(typeof(ShipyardAccretionScreen), "ShowPartCard")]
internal static class ShowPartCardPatch
{
private static void Postfix(ShipyardAccretionScreen __instance, PlacedPart p)
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
try
{
if (PadNav.Active || p == null || p.type == "reactor")
{
return;
}
GameState i = GameState.I;
if (i == null || !ShipyardShiftBuy.CanBuyMax(i, p))
{
return;
}
Card value = Traverse.Create((object)__instance).Field("_card").GetValue<Card>();
if (value?.rows != null && value.rows.Length != 0)
{
Row val = value.rows[0];
if (val?.root != null && !(val.root.style.display == StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1)))
{
Label sub = val.sub;
((TextElement)sub).text = ((TextElement)sub).text + " · " + ShipyardShiftBuy.Hint;
}
}
}
catch
{
}
}
}
[HarmonyPatch(typeof(ShipyardAccretionScreen), "HideCard")]
internal static class HideCardPatch
{
private static bool Prefix(ShipyardAccretionScreen __instance)
{
if (!ShipyardShiftBuy.ShiftHeld)
{
return true;
}
try
{
if (Traverse.Create((object)__instance).Field("_selecting").GetValue<bool>())
{
return true;
}
if (Traverse.Create((object)__instance).Field("_drag").GetValue() != null)
{
return true;
}
int value = Traverse.Create((object)__instance).Field("_cardUid").GetValue<int>();
string value2 = Traverse.Create((object)__instance).Field("_cardShopId").GetValue<string>();
return value < 0 || value2 != null;
}
catch
{
return true;
}
}
}
[HarmonyPatch(typeof(ShipyardAccretionScreen), "BuildCard")]
internal static class BuildCardPatch
{
private static void Postfix(ShipyardAccretionScreen __instance)
{
try
{
Card card = Traverse.Create((object)__instance).Field("_card").GetValue<Card>();
if (card?.rows == null || card.rows.Length == 0)
{
return;
}
VisualElement row = card.rows[0]?.root;
if (row == null)
{
return;
}
card.root.pickingMode = (PickingMode)1;
row.pickingMode = (PickingMode)1;
card.root.schedule.Execute((Action)delegate
{
//IL_0017: 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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: 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_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
try
{
PickingMode val = (PickingMode)((!ShipyardShiftBuy.ShiftHeld || !(card.root.style.display != StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1)) || row.panel == null) ? 1 : 0);
if (card.root.pickingMode != val)
{
card.root.pickingMode = val;
}
if (row.pickingMode != val)
{
row.pickingMode = val;
}
}
catch
{
}
}).Every(50L);
((CallbackEventHandler)row).RegisterCallback<ClickEvent>((EventCallback<ClickEvent>)delegate(ClickEvent evt)
{
if (!((PointerEventBase<ClickEvent>)(object)evt).shiftKey)
{
return;
}
try
{
int uid = Traverse.Create((object)__instance).Field("_cardUid").GetValue<int>();
string value = Traverse.Create((object)__instance).Field("_cardShopId").GetValue<string>();
if (uid >= 0 && value == null)
{
GameState i = GameState.I;
PlacedPart val = ((IEnumerable<PlacedPart>)((i != null) ? i.Ship : null)?.placed).FirstOrDefault((Func<PlacedPart, bool>)((PlacedPart q) => q.uid == uid));
if (val != null && !(val.type == "reactor") && ShipyardShiftBuy.CanBuyMax(i, val))
{
((EventBase)evt).StopPropagation();
ShipyardShiftBuy.Apply(__instance, ShipyardShiftBuy.BuyMax(i, val));
}
}
}
catch
{
}
}, (TrickleDown)0);
}
catch
{
}
}
}
}
internal static class ShipyardShiftBuyCoreKeyPatches
{
[HarmonyPatch(typeof(ShipyardAccretionScreen), "UpKey")]
internal static class UpKeyPatch
{
private static void Postfix(VisualElement __result, object[] __args)
{
//IL_006c: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
try
{
if (__result != null && __args != null && __args.Length >= 2 && Traverse.Create(__args[0]).Field("affordable").GetValue<bool>() && Traverse.Create(__args[1]).Property("IsCore", (object[])null).GetValue<bool>() && UQueryExtensions.Q<Label>(__result, "shift-buy-hint", (string)null) == null)
{
Label val = MetaUi.Text(ShipyardShiftBuy.Hint, (Face)0, 11f, MetaUi.Fade(MetaUi.Ink, 0.65f), 1f, false);
((VisualElement)val).name = "shift-buy-hint";
((VisualElement)val).pickingMode = (PickingMode)1;
((VisualElement)val).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
((VisualElement)val).style.marginTop = StyleLength.op_Implicit(2f);
__result.Add((VisualElement)(object)val);
__result.style.height = StyleLength.op_Implicit((StyleKeyword)2);
__result.style.minHeight = StyleLength.op_Implicit(49f);
__result.style.paddingTop = StyleLength.op_Implicit(6f);
__result.style.paddingBottom = StyleLength.op_Implicit(8f);
}
}
catch
{
}
}
}
}
[BepInPlugin("agentbox.graveyardorbit.tweaks", "Graveyard Orbit Tweaks", "0.4.0")]
public sealed class TweaksPlugin : BaseUnityPlugin
{
public const string PluginGuid = "agentbox.graveyardorbit.tweaks";
public const string PluginVersion = "0.4.0";
internal static ManualLogSource Log;
private Harmony _harmony;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
_harmony = new Harmony("agentbox.graveyardorbit.tweaks");
try
{
_harmony.PatchAll(typeof(TweaksPlugin).Assembly);
Log.LogInfo((object)"Tweaks loaded:");
Log.LogInfo((object)" drones: buy/upgrade prices halved, repair = $100");
Log.LogInfo((object)" igniter: levels 2 and 3 (4.5 / 6 rocks/s) for $200 / $350");
Log.LogInfo((object)" sorter: two colours per sorter (no extra cost)");
Log.LogInfo((object)" scrap: refunds shards spent on miner colour specs");
Log.LogInfo((object)" shipyard: BUY ALL button in the simple helper view");
Log.LogInfo((object)" shipyard: shift+click a part, upgrade key or level-up row to buy max");
}
catch (Exception ex)
{
Log.LogError((object)("Tweaks patch failure: " + ex));
}
}
private void OnDestroy()
{
try
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
catch
{
}
}
}
}