using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("FixHaulCalculation")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Fix Haul Calculation")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FixHaulCalculation")]
[assembly: AssemblyTitle("FixHaulCalculation")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace FixHaulCalculation;
[BepInPlugin("ErrorJan.REPO.FixHaulCalculation", "Fix Haul Calculation", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private class HarmonyPatches
{
public static int UpdateAndCalculateSurplus(ExtractionPoint instance)
{
FieldInfo fieldInfo = AccessTools.Field(typeof(RoundDirector), "currentHaul");
FieldInfo fieldInfo2 = AccessTools.Field(typeof(RoundDirector), "extractionPointSurplus");
int num = (int)fieldInfo.GetValue(RoundDirector.instance) + (int)fieldInfo2.GetValue(RoundDirector.instance);
return num - instance.haulGoal;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(ExtractionPoint), "StateExtracting")]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
FieldInfo extractionPointsCompleted = AccessTools.Field(typeof(RoundDirector), "extractionPointsCompleted");
FieldInfo extractionPoints = AccessTools.Field(typeof(RoundDirector), "extractionPoints");
FieldInfo haulSurplus = AccessTools.Field(typeof(ExtractionPoint), "haulSurplus");
MethodInfo method_updateAndCalculateSurplus = AccessTools.Method(typeof(HarmonyPatches), "UpdateAndCalculateSurplus", (Type[])null, (Type[])null);
int check1 = 0;
int check2 = 0;
bool check3 = false;
bool isPatched = false;
foreach (CodeInstruction instruction in instructions)
{
if (!check3)
{
if (instruction.opcode.FlowControl == FlowControl.Cond_Branch && check1 > 0 && check2 > 0)
{
check3 = true;
}
check1--;
check2--;
if (CodeInstructionExtensions.LoadsField(instruction, extractionPointsCompleted, false))
{
check1 = 6;
}
if (CodeInstructionExtensions.LoadsField(instruction, extractionPoints, false))
{
check2 = 5;
}
}
else if (!isPatched && CodeInstructionExtensions.LoadsField(instruction, haulSurplus, false))
{
yield return new CodeInstruction(OpCodes.Call, (object)method_updateAndCalculateSurplus);
isPatched = true;
continue;
}
yield return instruction;
}
}
}
internal const string PluginGUID = "ErrorJan.REPO.FixHaulCalculation";
internal const string PluginName = "Fix Haul Calculation";
internal const string PluginVersion = "1.0.0";
internal static ManualLogSource _logger;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
_logger = ((BaseUnityPlugin)this).Logger;
Harmony val = new Harmony("ErrorJan.REPO.FixHaulCalculation");
val.PatchAll(typeof(HarmonyPatches));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Fix Haul Calculation is loaded!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "FixHaulCalculation";
public const string PLUGIN_NAME = "FixHaulCalculation";
public const string PLUGIN_VERSION = "1.0.0";
}