Decompiled source of LogisticsBotsTweaks v1.1.0

LogisticsBotsTweaks.dll

Decompiled 3 months ago
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("LogisticsBotsTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("LogisticsBotsTweaks")]
[assembly: AssemblyTitle("LogisticsBotsTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace LogisticsBotsTweaks;

[BepInPlugin("starfi5h.plugin.LogisticsBotsTweaks", "LogisticsBotsTweaks", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "starfi5h.plugin.LogisticsBotsTweaks";

	public const string NAME = "LogisticsBotsTweaks";

	public const string VERSION = "1.1.0";

	public static ManualLogSource Log;

	private Harmony harmony;

	public void Awake()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Expected O, but got Unknown
		Patch_LogisticsBot.logisticsBotSpeedScale = ((BaseUnityPlugin)this).Config.Bind<float>("Bot", "SpeedScale", 1f, "Scale of logistics bots flight speed. 物流配送机的飞行速度倍率").Value;
		Patch_LogisticsBot.logisticsBotCapacity = ((BaseUnityPlugin)this).Config.Bind<int>("Bot", "Capacity", 0, "If > 0, Overwirte carrying capacity of logistics bots. 覆写配送运输机运载量").Value;
		Patch_LogisticsBot.dispenserDeliveryMaxAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Bot", "DeliveryMaxAngle", 0f, new ConfigDescription("If > 0, Overwirte distribution range of logistics bots. 覆写配送范围(度)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 180f), Array.Empty<object>())).Value;
		Patch_Distributor.dispenserMaxCourierCount = ((BaseUnityPlugin)this).Config.Bind<int>("Distributor", "MaxBotCount", 10, "Max logistics bots count. 物流配送器的最大运输机数量").Value;
		Patch_Distributor.maxChargePowerScale = ((BaseUnityPlugin)this).Config.Bind<float>("Distributor", "MaxChargePowerScale", 1f, "Scale of max charge power. 物流配送器的最大充电功率倍率").Value;
		Log = ((BaseUnityPlugin)this).Logger;
		harmony = new Harmony("starfi5h.plugin.LogisticsBotsTweaks");
		if (Patch_LogisticsBot.logisticsBotSpeedScale != 1f || Patch_LogisticsBot.logisticsBotCapacity > 0 || Patch_LogisticsBot.dispenserDeliveryMaxAngle > 0f)
		{
			harmony.PatchAll(typeof(Patch_LogisticsBot));
		}
		if (Patch_Distributor.dispenserMaxCourierCount != 10 || Patch_Distributor.maxChargePowerScale != 1f)
		{
			harmony.PatchAll(typeof(Patch_Distributor));
		}
	}

	public void OnDestroy()
	{
		harmony.UnpatchSelf();
	}
}
internal class Patch_LogisticsBot
{
	public static float logisticsBotSpeedScale = 1f;

	public static int logisticsBotCapacity = 0;

	public static float dispenserDeliveryMaxAngle = 0f;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameHistoryData), "Import")]
	[HarmonyPatch(typeof(GameHistoryData), "SetForNewGame")]
	[HarmonyPatch(typeof(GameHistoryData), "UnlockTechFunction")]
	public static void LogisticCourierSpeedModified(GameHistoryData __instance)
	{
		if (logisticsBotSpeedScale != 1f)
		{
			__instance.logisticCourierSpeed = Configs.freeMode.logisticCourierSpeed * logisticsBotSpeedScale;
		}
		if (logisticsBotCapacity > 0)
		{
			__instance.logisticCourierCarries = logisticsBotCapacity;
		}
		if (dispenserDeliveryMaxAngle > 0f)
		{
			__instance.dispenserDeliveryMaxAngle = dispenserDeliveryMaxAngle;
		}
	}
}
internal class Patch_Distributor
{
	public static int dispenserMaxCourierCount = 10;

	public static float maxChargePowerScale = 1f;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(DispenserComponent), "Init")]
	public static void Init(DispenserComponent __instance, PrefabDesc _desc)
	{
		if (dispenserMaxCourierCount > _desc.dispenserMaxCourierCount)
		{
			__instance.workCourierDatas = (CourierData[])(object)new CourierData[dispenserMaxCourierCount];
			__instance.orders = (DeliveryLogisticOrder[])(object)new DeliveryLogisticOrder[dispenserMaxCourierCount];
			__instance.holdupPackage = (DispenserStore[])(object)new DispenserStore[dispenserMaxCourierCount * 2];
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(DispenserComponent), "Import")]
	public static void Import(DispenserComponent __instance)
	{
		if (dispenserMaxCourierCount > __instance.workCourierDatas.Length)
		{
			CourierData[] workCourierDatas = __instance.workCourierDatas;
			__instance.workCourierDatas = (CourierData[])(object)new CourierData[dispenserMaxCourierCount];
			Array.Copy(workCourierDatas, __instance.workCourierDatas, workCourierDatas.Length);
			DeliveryLogisticOrder[] orders = __instance.orders;
			__instance.orders = (DeliveryLogisticOrder[])(object)new DeliveryLogisticOrder[dispenserMaxCourierCount];
			Array.Copy(orders, __instance.orders, orders.Length);
			DispenserStore[] holdupPackage = __instance.holdupPackage;
			__instance.holdupPackage = (DispenserStore[])(object)new DispenserStore[dispenserMaxCourierCount * 2];
			Array.Copy(holdupPackage, __instance.holdupPackage, holdupPackage.Length);
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(UIDispenserWindow), "OnCourierIconClick")]
	public static IEnumerable<CodeInstruction> OnCourierIconClick_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: 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: Expected O, but got Unknown
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Expected O, but got Unknown
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected O, but got Unknown
		try
		{
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldfld && ((FieldInfo)i.operand).Name == "dispenserMaxCourierCount"), (string)null)
			}).Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Pop, (object)null),
				new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(Patch_Distributor), "dispenserMaxCourierCount"))
			})
				.InstructionEnumeration();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
			return instructions;
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(UIDispenserWindow), "OnDispenserIdChange")]
	public static IEnumerable<CodeInstruction> OnDispenserIdChange_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0002: 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: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		try
		{
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "set_maxValue"), (string)null)
			}).Insert((CodeInstruction[])(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(Patch_Distributor), "maxChargePowerScale")),
				new CodeInstruction(OpCodes.Mul, (object)null)
			}).InstructionEnumeration();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)ex);
			return instructions;
		}
	}
}