Decompiled source of SuperAccumulator v20231215.17.1

SuperAccumulator.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModCommon;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SuperAccumulator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SuperAccumulator")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ff3407c9-7456-44c8-b7f6-f251d370f791")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 SuperAccumulator
{
	[BepInPlugin("ZHYB.DSP.MOD.SuperAccumulator", "ZHYB.DSP.MOD.SuperAccumulator", "2023.1215.1")]
	[BepInProcess("DSPGAME.exe")]
	public class SuperAccumulator : BaseUnityPlugin
	{
		public const string Plugin_GUID = "ZHYB.DSP.MOD.SuperAccumulator";

		public const string Plugin_NAME = "ZHYB.DSP.MOD.SuperAccumulator";

		public const string Plugin_Process = "DSPGAME.exe";

		public const string Plugin_VERSION = "2023.1215.1";

		private Harmony harmony;

		public void Start()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			global::ModCommon.ModCommon.logger = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("ZHYB.DSP.MOD.SuperAccumulator");
			harmony.PatchAll();
		}

		public void OnDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
	[HarmonyPatch(typeof(PrefabDesc))]
	internal class PatchPrefabDesc
	{
		[HarmonyPostfix]
		[HarmonyPatch("ReadPrefab")]
		public static void PatchReadPrefab(PrefabDesc __instance)
		{
			if (__instance.isAccumulator)
			{
				__instance.inputEnergyPerTick = 1000000000000L;
				__instance.outputEnergyPerTick = 1000000000000L;
				__instance.maxAcuEnergy = 1000000000000000000L;
			}
		}
	}
}
namespace Patch
{
	[HarmonyPatch(typeof(PlayerAction_Build))]
	internal class PatchPlayerAction_Build
	{
		[HarmonyPrefix]
		[HarmonyPatch("DoDismantleObject")]
		public static bool DoDismantleObject(PlayerAction_Build __instance, int objId, ref bool __result)
		{
			PlanetFactory factory = __instance.factory;
			__instance.SetFactoryReferences();
			if (objId == 0)
			{
				__result = false;
			}
			if (objId > 0 && factory.entityPool[objId].id == 0)
			{
				__result = false;
			}
			if (objId < 0 && factory.prebuildPool[-objId].id == 0)
			{
				__result = false;
			}
			int num = ((Proto)(((BuildTool)__instance.noneTool).GetItemProto(objId)?)).ID ?? 0;
			int num2 = num;
			if (objId > 0)
			{
				EntityData[] entityPool = factory.entityPool;
				PowerSystem powerSystem = factory.powerSystem;
				int powerAccId = entityPool[objId].powerAccId;
				powerSystem.accPool[powerAccId].curEnergy = powerSystem.accPool[powerAccId].maxEnergy;
				if (powerAccId > 0 && powerSystem.accPool[powerAccId].curEnergy == powerSystem.accPool[powerAccId].maxEnergy)
				{
					ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)entityPool[objId].protoId);
					if (val != null && val.HeatValue == 0)
					{
						int modelIndex = val.ModelIndex;
						val = ((ProtoSet<ItemProto>)(object)LDB.items).Select(entityPool[objId].protoId + 1);
						val.HeatValue = powerSystem.accPool[powerAccId].maxEnergy;
						if (val != null && val.HeatValue == powerSystem.accPool[powerAccId].maxEnergy && modelIndex == val.ModelIndex)
						{
							num2++;
						}
					}
				}
			}
			int num3 = __instance.ObjectAssetValue(objId);
			if (num3 > 0)
			{
				int num4 = ((PlayerAction)__instance).player.TryAddItemToPackage(num2, num3, 0, true, objId, false);
				UIItemup.Up(num2, num4);
			}
			factory.DismantleFinally(((PlayerAction)__instance).player, objId, ref num);
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(PowerSystem))]
	internal class Patch_PowerSystem
	{
		[HarmonyPostfix]
		[HarmonyPatch("NewGeneratorComponent")]
		public static void PatchNewGeneratorComponent(PowerSystem __instance, int __result)
		{
		}

		[HarmonyPostfix]
		[HarmonyPatch("NewAccumulatorComponent")]
		public static void PatchNewAccumulatorComponent(PowerSystem __instance, int __result)
		{
			__instance.accPool[__result].curEnergy = __instance.accPool[__result].maxEnergy;
		}

		[HarmonyPostfix]
		[HarmonyPatch("NewConsumerComponent")]
		public static void PatchNewConsumerComponent(PowerSystem __instance, int __result)
		{
		}

		[HarmonyPostfix]
		[HarmonyPatch("NewExchangerComponent")]
		public static void PatchNewExchangerComponent(PowerSystem __instance, int __result)
		{
		}
	}
}
namespace ModCommon
{
	public static class ModCommon
	{
		public static ManualLogSource logger;

		public static PlanetFactory factory;

		public static void Log(string str)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (logger == null)
			{
				logger = new ManualLogSource("ZHYB.DSP.MOD.ModCommon");
			}
			logger.LogMessage((object)str);
		}
	}
}