using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using EquinoxsModUtils;
using HarmonyLib;
using UnityEngine;
using VerticalBeltFix.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("VerticalBeltFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VerticalBeltFix")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d3ca4ef6-711f-448d-96e4-836d40bbf01a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace VerticalBeltFix
{
[BepInPlugin("com.equinox.VerticalBeltFix", "VerticalBeltFix", "1.0.0")]
public class VerticalBeltFixPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.equinox.VerticalBeltFix";
private const string PluginName = "VerticalBeltFix";
private const string VersionString = "1.0.0";
private static readonly Harmony Harmony = new Harmony("com.equinox.VerticalBeltFix");
public static ManualLogSource Log = new ManualLogSource("VerticalBeltFix");
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: VerticalBeltFix, VersionString: 1.0.0 is loading...");
Harmony.PatchAll();
Harmony.CreateAndPatchAll(typeof(ConveyorInstancePatch), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: VerticalBeltFix, VersionString: 1.0.0 is loaded.");
Log = ((BaseUnityPlugin)this).Logger;
}
private void Update()
{
}
}
}
namespace VerticalBeltFix.Patches
{
internal class ConveyorInstancePatch
{
[HarmonyPatch(typeof(ConveyorInstance), "CanAcceptResourceFromInserter")]
[HarmonyPrefix]
private static bool ReplaceCheck(ref ConveyorInstance me, int resId, in Vector3Int posToAddAt, ref bool __result)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Invalid comparison between Unknown and I4
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: 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)
if ((int)me.beltShape != 6)
{
return true;
}
float num = ((Vector3Int)(ref me.gridInfo.minPos)).y;
if (!me.inputBottom)
{
num += (float)((Vector3Int)(ref me.gridInfo.dims)).y;
}
float num2 = num;
Vector3Int val = posToAddAt;
num = num2 - (float)((Vector3Int)(ref val)).y;
int num3 = 0;
ResTransportData[] curResPositions = me.curResPositions;
foreach (ResTransportData val2 in curResPositions)
{
if (val2.resType != 0 && val2.beltPos >= num && val2.beltPos <= num + 1f)
{
num3++;
}
}
__result = num3 < 3;
return false;
}
[HarmonyPatch(typeof(ConveyorInstance), "FindInserterDropSpot")]
[HarmonyPrefix]
private static bool ReplaceFindSpot(ConveyorInstance __instance, ref bool __result, out float beltPos, out int index, float minBeltRange, float maxBeltRange)
{
//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_0036: Invalid comparison between Unknown and I4
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: 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_0140: 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_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: 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)
index = 0;
beltPos = (minBeltRange + maxBeltRange) * 0.5f;
if ((int)__instance.beltShape != 6)
{
return true;
}
if (__instance.curResCount == __instance.curResPositions.Length)
{
return true;
}
List<ResTransportData> list = __instance.curResPositions.Where((ResTransportData data) => data.beltPos > minBeltRange && data.beltPos <= maxBeltRange).ToList();
if (list.Count == 0)
{
__result = true;
return false;
}
bool flag = false;
foreach (ResTransportData item in list)
{
if (item.beltPos + 0.42f <= maxBeltRange)
{
beltPos = item.beltPos + 0.42f;
flag = true;
break;
}
if (item.beltPos - 0.42f >= minBeltRange)
{
beltPos = item.beltPos - 0.42f;
flag = true;
break;
}
}
__result = flag;
GenericMachineInstanceRef targetMachineRef = Player.instance.interaction.TargetMachineRef;
if (((GenericMachineInstanceRef)(ref targetMachineRef)).IsValid())
{
targetMachineRef = Player.instance.interaction.TargetMachineRef;
if (((GenericMachineInstanceRef)(ref targetMachineRef)).GetCommonInfo().instanceId == __instance.commonInfo.instanceId)
{
ModUtils.PacedLog($"minBeltRange: {minBeltRange} | maxBeltRange: {maxBeltRange} | beltPos: {beltPos} | foundPos: {flag}", 1f);
}
}
return false;
}
}
}