Decompiled source of ProliferatorMultiplier v1.1.0

ProliferatorMultiplier\ProliferatorMultiplier.dll

Decompiled 13 hours 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.Configuration;
using BepInEx.Logging;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ProliferatorMultiplier")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ViliusVV")]
[assembly: AssemblyProduct("ProliferatorMultiplier")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6CD44CB7-E582-4F87-8174-9A172922F948")]
[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")]
namespace ProliferatorMultiplier;

[BepInPlugin("proliferatormultiplier", "ProliferatorMultiplier", "1.0")]
public class ProliferatorMultiplier : BaseUnityPlugin
{
	private const string PluginGuid = "proliferatormultiplier";

	private const string PluginName = "ProliferatorMultiplier";

	private const string PluginVersion = "1.0";

	private static bool _wasF5DownLastFrame;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Plugin {0} is loaded! Version: {1}, Dev Mode: {2}", "ProliferatorMultiplier", "1.0", false));
		((BaseUnityPlugin)this).Logger.LogInfo((object)((object)((BaseUnityPlugin)this).Config).ToString());
		((BaseUnityPlugin)this).Logger.LogInfo((object)((object)((BaseUnityPlugin)this).Logger).ToString());
		PatchProliferator.Init(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
	}

	private void Update()
	{
	}

	private void OnDestroy()
	{
		PatchProliferator.Teardown();
	}
}
public static class PatchProliferator
{
	public static ConfigEntry<int> MultProduction;

	public static ConfigEntry<int> MultSpeed;

	public static ConfigEntry<int> MultEnergy;

	private static readonly double[] BackupIncTableMilli = CopyTable(ref Cargo.incTableMilli);

	private static readonly double[] BackupAccTableMilli = CopyTable(ref Cargo.accTableMilli);

	private static readonly int[] BackupIncFastDivisionNumerator = CopyTable(ref Cargo.incFastDivisionNumerator);

	private static readonly int[] BackupIncTable = CopyTable(ref Cargo.incTable);

	private static readonly int[] BackupAccTable = CopyTable(ref Cargo.accTable);

	private static readonly int[] BackupPowerTable = CopyTable(ref Cargo.powerTable);

	private static readonly double[] BackupPowerTableRatio = CopyTable(ref Cargo.powerTableRatio);

	private static ConfigFile ConfigFile;

	private static ManualLogSource Log;

	public static void Init(ConfigFile config, ManualLogSource log)
	{
		ConfigFile = config;
		Log = log;
		Log.LogInfo((object)"Initializing...");
		InitConfig(ConfigFile);
		Patch();
	}

	public static void ReloadConfig()
	{
		Log.LogInfo((object)"Reloading config...");
		ConfigFile.Reload();
		InitConfig(ConfigFile);
		Patch();
		Log.LogInfo((object)"Config reloaded.");
	}

	private static void Patch()
	{
		PatchIncTable(MultProduction.Value, ref Cargo.incTableMilli);
		PatchIncTable(MultProduction.Value, ref Cargo.incTable);
		PatchIncDivisionTable(ref Cargo.incFastDivisionNumerator);
		PatchIncTable(MultSpeed.Value, ref Cargo.accTableMilli);
		PatchIncTable(MultSpeed.Value, ref Cargo.accTable);
		PatchIncTable(MultEnergy.Value, ref Cargo.powerTable);
		PatchPowerTableRatio(MultEnergy.Value, ref Cargo.powerTableRatio);
		PrintTables(BackupIncTableMilli, "Backup_incTableMilli");
		PrintTables(BackupIncTable, "Backup_incTable");
		PrintTables(BackupIncFastDivisionNumerator, "Backup_incFastDivisionNumerator");
		PrintTables(BackupAccTableMilli, "Backup_accTableMilli");
		PrintTables(BackupAccTable, "Backup_accTable");
		PrintTables(BackupPowerTable, "Backup_powerTable");
		PrintTables(BackupPowerTableRatio, "Backup_powerTableRatio");
		PrintTables(Cargo.incTableMilli, "Cargo.incTableMilli");
		PrintTables(Cargo.incTable, "Cargo.incTable");
		PrintTables(Cargo.incFastDivisionNumerator, "Cargo.incFastDivisionNumerator");
		PrintTables(Cargo.accTableMilli, "Cargo.accTableMilli");
		PrintTables(Cargo.accTable, "Cargo.accTable");
		PrintTables(Cargo.powerTable, "Cargo.powerTable");
		PrintTables(Cargo.powerTableRatio, "Cargo.powerTableRatio");
	}

	private static void InitConfig(ConfigFile confFile)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		Log.LogInfo((object)("Initializing config from " + confFile.ConfigFilePath + "..."));
		MultProduction = confFile.Bind<int>("1. Additional production", "MultProduction", 1, new ConfigDescription("Multiplies proliferator effect - Additional production", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
		MultSpeed = confFile.Bind<int>("1. Speed of production", "MultSpeed", 1, new ConfigDescription("Multiplies proliferator effect - Speed of production", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
		MultEnergy = confFile.Bind<int>("1. Energy consumption", "MultEnergy", 1, new ConfigDescription("Multiplies proliferator effect - Energy consumption", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
		Log.LogInfo((object)("Config initialized with MultProduction: " + MultProduction.Value + ", MultSpeed: " + MultSpeed.Value + ", MultEnergy: " + MultEnergy.Value));
	}

	public static void Teardown()
	{
		Log.LogInfo((object)"Teardown...");
		RestoreTable(ref Cargo.incTableMilli, BackupIncTableMilli);
		RestoreTable(ref Cargo.incTable, BackupIncTable);
		RestoreTable(ref Cargo.incFastDivisionNumerator, BackupIncFastDivisionNumerator);
		RestoreTable(ref Cargo.accTableMilli, BackupAccTableMilli);
		RestoreTable(ref Cargo.accTable, BackupAccTable);
		RestoreTable(ref Cargo.powerTable, BackupPowerTable);
		RestoreTable(ref Cargo.powerTableRatio, BackupPowerTableRatio);
		Log.LogInfo((object)"Teardown done.");
	}

	private static T[] CopyTable<T>(ref T[] original)
	{
		T[] array = new T[original.Length];
		Array.Copy(original, array, original.Length);
		return array;
	}

	private static void PatchIncTable(int mult, ref double[] original)
	{
		for (int i = 0; i < original.Length; i++)
		{
			original[i] *= mult;
		}
	}

	private static void PatchIncTable(int mult, ref int[] original)
	{
		for (int i = 0; i < original.Length; i++)
		{
			original[i] *= mult;
		}
	}

	private static void PatchIncDivisionTable(ref int[] original)
	{
		for (int i = 0; i < original.Length; i++)
		{
			original[i] = 40 + (int)Math.Round(Cargo.incTableMilli[i] * 40.0);
		}
	}

	private static void PatchPowerTableRatio(int mult, ref double[] original)
	{
		for (int i = 0; i < original.Length; i++)
		{
			original[i] = (original[i] - 1.0) * (double)mult + 1.0;
		}
	}

	private static void PrintTables<T>(T[] table, string tableName)
	{
		Log.LogInfo((object)(tableName + ": " + string.Join(", ", table)));
	}

	private static void RestoreTable<T>(ref T[] restoreTo, T[] backup)
	{
		Log.LogInfo((object)"RestoreTable called.");
		for (int i = 0; i < backup.Length; i++)
		{
			restoreTo[i] = backup[i];
		}
	}
}
public static class Utils
{
	internal const bool IsDev = false;
}