using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DSP Infinite Resource Nodes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DSP Infinite Resource Nodes")]
[assembly: AssemblyCopyright("Copyright © 2021-2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ae038210-d58b-47e3-a479-1db53bdcc8bf")]
[assembly: AssemblyFileVersion("1.2.4")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.2.4.0")]
namespace DSPInfiniteResourceNodes;
public static class DSPInfiniteResourceNodes
{
public static ManualLogSource Logger = Logger.CreateLogSource("DSP Infinite Resource Nodes");
public static ConfigEntry<bool> enableMinerPatchFlag;
public static ConfigEntry<bool> enableOilPatchFlag;
public static ConfigEntry<bool> enableIcarusPatchFlag;
public const bool enableDebug_miner = false;
public const bool enableDebug_oil = false;
public const bool enableDebug_icarus = false;
public static IEnumerable<string> TargetDLLs { get; } = new string[1] { "Assembly-CSharp.dll" };
public static void BindConfigs()
{
//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_0030: Unknown result type (might be due to invalid IL or missing references)
ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "greyhak.dysonsphereprogram.infiniteresources.cfg"), true);
enableMinerPatchFlag = val.Bind<bool>("General", "EnableMinerPatchFlag", true, "Enable/Disable Infinite Ores.");
enableOilPatchFlag = val.Bind<bool>("General", "EnableOilPatchFlag", true, "Enable/Disable Infinite Oil.");
enableIcarusPatchFlag = val.Bind<bool>("General", "EnableIcarusPatchFlag", true, "Enable/Disable Infinite Icarus Mining.");
}
public static void Patch(AssemblyDefinition assembly)
{
//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_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: 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_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0473: Unknown result type (might be due to invalid IL or missing references)
//IL_0478: Unknown result type (might be due to invalid IL or missing references)
//IL_0499: Unknown result type (might be due to invalid IL or missing references)
//IL_049e: Unknown result type (might be due to invalid IL or missing references)
//IL_030b: Unknown result type (might be due to invalid IL or missing references)
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
//IL_0507: Unknown result type (might be due to invalid IL or missing references)
BindConfigs();
if (assembly.MainModule == null)
{
return;
}
Enumerator<MethodDefinition> enumerator = assembly.MainModule.GetType("MinerComponent").Methods.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
MethodDefinition current = enumerator.Current;
if (((MemberReference)current).Name == "InternalUpdate")
{
ILProcessor iLProcessor = current.Body.GetILProcessor();
int num = Find(current.Body.Instructions, 0, new string[6] { "ldflda System.Int32 VeinData::amount", "dup", "ldind.i4", "ldloc.s V_7", "sub", "stind.i4" });
int num2 = Find(current.Body.Instructions, 0, new string[7] { "ldflda System.Int64 VeinGroup::amount", "dup", "ldind.i8", "ldloc.s V_7", "conv.i8", "sub", "stind.i8" });
if (num == -1 || num2 == -1 || current.Body.Instructions[num + 3].OpCode != OpCodes.Ldloc_S || current.Body.Instructions[num2 + 3].OpCode != OpCodes.Ldloc_S)
{
Logger.LogError((object)"ERROR: The Dyson Sphere Program appears to have been updated. The Infinite Resource Nodes mod needs to be updated. Until then miners will consume node resources.");
}
else if (enableMinerPatchFlag.Value)
{
iLProcessor.Replace(iLProcessor.Body.Instructions[num + 3], Instruction.Create(OpCodes.Ldc_I4_0));
iLProcessor.Replace(iLProcessor.Body.Instructions[num2 + 3], Instruction.Create(OpCodes.Ldc_I4_0));
Logger.LogInfo((object)"Infinite resources patch applied for miners.");
}
int num3 = Find(current.Body.Instructions, 0, new string[1] { "ldsfld System.Single VeinData::oilSpeedMultiplier" });
int num4 = -1;
int num5 = -1;
if (num3 != -1)
{
num4 = Find(current.Body.Instructions, num3, new string[6] { "ldflda System.Int32 VeinData::amount", "dup", "ldind.i4", "ldloc.s V_18", "sub", "stind.i4" });
num5 = Find(current.Body.Instructions, num3, new string[7] { "ldflda System.Int64 VeinGroup::amount", "dup", "ldind.i8", "ldloc.s V_18", "conv.i8", "sub", "stind.i8" });
}
if (num4 == -1 || num5 == -1 || current.Body.Instructions[num4 + 3].OpCode != OpCodes.Ldloc_S || current.Body.Instructions[num5 + 3].OpCode != OpCodes.Ldloc_S)
{
Logger.LogError((object)"ERROR: The Dyson Sphere Program appears to have been updated. The Infinite Resource Nodes mod needs to be updated. Until then oil extractors will consume crude oil seep resources.");
}
else if (enableOilPatchFlag.Value)
{
iLProcessor.Replace(iLProcessor.Body.Instructions[num4 + 3], Instruction.Create(OpCodes.Ldc_I4_0));
iLProcessor.Replace(iLProcessor.Body.Instructions[num5 + 3], Instruction.Create(OpCodes.Ldc_I4_0));
Logger.LogInfo((object)"Infinite resources patch applied for crude oil extraction.");
}
break;
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
enumerator = assembly.MainModule.GetType("PlayerAction_Mine").Methods.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
MethodDefinition current2 = enumerator.Current;
if (((MemberReference)current2).Name == "GameTick")
{
ILProcessor iLProcessor2 = current2.Body.GetILProcessor();
int num6 = Find(current2.Body.Instructions, 0, new string[6] { "ldflda System.Int32 VeinData::amount", "dup", "ldind.i4", "ldc.i4.1", "sub", "stind.i4" });
int num7 = Find(current2.Body.Instructions, 0, new string[7] { "ldflda System.Int64 VeinGroup::amount", "dup", "ldind.i8", "ldc.i4.1", "conv.i8", "sub", "stind.i8" });
if (num6 == -1 || num7 == -1 || current2.Body.Instructions[num6 + 4].OpCode != OpCodes.Sub || current2.Body.Instructions[num7 + 5].OpCode != OpCodes.Sub)
{
Logger.LogError((object)"ERROR: The Dyson Sphere Program appears to have been updated. The Infinite Resource Nodes mod needs to be updated. Until then Icarus will consume node resources.");
}
else if (enableIcarusPatchFlag.Value)
{
iLProcessor2.Replace(iLProcessor2.Body.Instructions[num6 + 4], Instruction.Create(OpCodes.Pop));
iLProcessor2.Replace(iLProcessor2.Body.Instructions[num7 + 5], Instruction.Create(OpCodes.Pop));
Logger.LogInfo((object)"Infinite resources patch applied for Icarus.");
}
break;
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
}
public static int Find(Collection<Instruction> haystack, int startPosition, string[] needle)
{
for (int i = startPosition; i < haystack.Count - needle.Length; i++)
{
bool flag = true;
for (int j = 0; j < needle.Length; j++)
{
if (((object)haystack[i + j]).ToString().Substring(9) != needle[j])
{
flag = false;
break;
}
}
if (flag)
{
return i;
}
}
return -1;
}
}