Decompiled source of CyberMultiplier v1.0.1

CyberMultiplier.dll

Decompiled 9 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Timers;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CyberMultiplier")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CyberMultiplier")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9b9458f6-bf67-47e7-b50a-166aea5b2673")]
[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 CyberMultiplier;

internal class CyberGrindPatch
{
	[HarmonyPrefix]
	[HarmonyPatch(typeof(EndlessGrid), "OnTriggerEnter")]
	private static bool ActivateCheck(EndlessGrid __instance)
	{
		return ((Component)__instance).GetComponent<Collider>().enabled;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(EndlessGrid), "OnTriggerEnter")]
	private static void StartOthers(EndlessGrid __instance)
	{
		if (Plugin.syncIn.Value)
		{
			CyberManager.StartGrids();
		}
		CyberManager.setFinished(__instance, val: false);
		CyberManager.disable(__instance);
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(EndlessGrid), "Update")]
	private static bool WaitOthers(EndlessGrid __instance, ref int ___enemyAmount, ref ActivateNextWave ___anw)
	{
		if (!Plugin.syncOut.Value)
		{
			return true;
		}
		if (((Component)__instance).GetComponent<Collider>().enabled)
		{
			return true;
		}
		if (___anw.deadEnemies >= ___enemyAmount)
		{
			CyberManager.setFinished(__instance, val: true);
			if (!CyberManager.otherFinished())
			{
				return false;
			}
		}
		return true;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(EndlessGrid), "Update")]
	private static void Enemies(EndlessGrid __instance, ref Text ___enemiesLeftText)
	{
		if (((object)__instance).Equals((object?)CyberLogic.GetGrid(0)) && Plugin.screenCram.Value)
		{
			List<EnemyIdentifier> enemies = MonoSingleton<EnemyTracker>.Instance.enemies;
			enemies.RemoveAll((EnemyIdentifier e) => (Object)(object)e == (Object)null || e.dead);
			___enemiesLeftText.text = enemies.Count.ToString();
		}
	}
}
internal class CyberManager : MonoSingleton<CyberManager>
{
	private static bool gridsStarting;

	private static bool allowNextWaxe;

	private static bool logs;

	private static ManualLogSource mls;

	public static void Listen()
	{
		logs = Plugin.logGrids.Value;
		mls = Plugin.mls;
		if ((Plugin.multiplier.Value <= 1 && !Plugin.allInvValues.Value) || Plugin.multiplier.Value == 1)
		{
			return;
		}
		SceneManager.sceneLoaded += delegate
		{
			if (SceneHelper.CurrentScene == "Endless")
			{
				if (Plugin.syncOut.Value)
				{
					if (logs)
					{
						mls.LogInfo((object)"Starting timer");
					}
					CyberLogic.StartTimer();
				}
				CyberLogic.InitContainers();
				Initialize();
			}
			else if (SceneHelper.CurrentScene == "Main menu")
			{
				if (logs)
				{
					mls.LogInfo((object)"Stopping timer");
				}
				CyberLogic.StopTimer();
			}
		};
	}

	private static void Initialize()
	{
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		CyberLogic.RegisterGrid(GameObject.Find("Everything"));
		if ((Object)(object)CyberLogic.GetGrid(0) == (Object)null)
		{
			mls.LogError((object)"The CyberGrind GameObject could not be found!");
			return;
		}
		int value = Plugin.multiplier.Value;
		for (int i = -value / 2; (float)i < (float)value / 2f; i++)
		{
			for (int j = -value / 2; (float)j < (float)value / 2f; j++)
			{
				GameObject val = Object.Instantiate<GameObject>(CyberLogic.GetGrid(0));
				((Component)val.transform.GetChild(0)).gameObject.SetActive(false);
				((Component)val.transform.GetChild(1)).gameObject.SetActive(false);
				val.transform.position = new Vector3((float)(80 * i), 0f, (float)(80 * j));
				CyberLogic.RegisterGrid(val);
				if (logs)
				{
					mls.LogInfo((object)("New grid created at: " + val.transform.position.x + " 0 " + val.transform.position.z));
				}
			}
		}
		if (logs)
		{
			mls.LogInfo((object)"Deleting clone grid at 0 0 0");
		}
		int index = value * value / 2 + ((value % 2 != 0) ? 1 : (1 + value / 2));
		Object.Destroy((Object)(object)CyberLogic.GetGrid(index));
		CyberLogic.RemoveGrid(index);
	}

	public static void StartGrids()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		if (gridsStarting)
		{
			return;
		}
		gridsStarting = true;
		if (logs)
		{
			mls.LogInfo((object)"Starting grids...");
		}
		EndlessGrid eG = CyberLogic.GetEG(0);
		((Component)CyberLogic.GetGrid(0).transform.GetChild(3)).gameObject.SetActive(true);
		GameObject val = new GameObject
		{
			tag = "Player"
		};
		val.AddComponent<BoxCollider>();
		MethodInfo method = ((object)eG).GetType().GetMethod("OnTriggerEnter", BindingFlags.Instance | BindingFlags.NonPublic);
		MethodInfo methodInfo = method;
		EndlessGrid obj = eG;
		object[] parameters = (object[])(object)new Object[1] { (Object)val.GetComponent<BoxCollider>() };
		methodInfo.Invoke(obj, parameters);
		if (logs)
		{
			mls.LogInfo((object)"Grid started: 0");
		}
		for (int num = CyberLogic.GridsCount() - 1; num > 0; num--)
		{
			eG = CyberLogic.GetEG(num);
			method = ((object)eG).GetType().GetMethod("OnTriggerEnter", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo methodInfo2 = method;
			EndlessGrid obj2 = eG;
			parameters = (object[])(object)new Object[1] { (Object)val.GetComponent<BoxCollider>() };
			methodInfo2.Invoke(obj2, parameters);
			if (logs)
			{
				mls.LogInfo((object)("Grid started: " + num));
			}
		}
		gridsStarting = false;
	}

	public static void setFinished(EndlessGrid eg, bool val)
	{
		CyberLogic.AddEGStatus(eg, val);
		CyberLogic.SetEGStatus(eg, val);
	}

	public static bool otherFinished()
	{
		if (gridsStarting)
		{
			return true;
		}
		return allowNextWaxe;
	}

	internal static void CalculateAllow(object sender, ElapsedEventArgs e)
	{
		bool flag = true;
		EndlessGrid[] eGStatusesKeys = CyberLogic.GetEGStatusesKeys();
		for (int num = CyberLogic.EGStatusesCount() - 1; num >= 0; num--)
		{
			flag = flag && CyberLogic.GetEGStatus(eGStatusesKeys[num]);
			CyberLogic.SetEGStatus(eGStatusesKeys[num], status: false);
		}
		allowNextWaxe = flag;
	}

	public static void disable(EndlessGrid eg)
	{
		GameObject grid = CyberLogic.GetGrid(eg);
		if (!((object)grid).Equals((object?)CyberLogic.GetGrid(0)))
		{
			((Component)grid.transform.GetChild(3).GetChild(0)).gameObject.SetActive(false);
			((Component)grid.transform.GetChild(4)).gameObject.SetActive(false);
		}
	}
}
internal abstract class CyberLogic
{
	private static List<GameObject> grids;

	private static Dictionary<EndlessGrid, GameObject> egToGrid;

	private static Dictionary<EndlessGrid, bool> finishedGrids;

	private static Timer allowTimer = new Timer(5000.0);

	public static void InitContainers()
	{
		grids = new List<GameObject>();
		egToGrid = new Dictionary<EndlessGrid, GameObject>();
		finishedGrids = new Dictionary<EndlessGrid, bool>();
	}

	public static void StartTimer()
	{
		if (allowTimer.Enabled)
		{
			allowTimer.Stop();
			allowTimer.Dispose();
		}
		allowTimer = new Timer(5000.0);
		allowTimer.Elapsed += CyberManager.CalculateAllow;
		allowTimer.Start();
	}

	public static void StopTimer()
	{
		if (allowTimer.Enabled)
		{
			allowTimer.Stop();
			allowTimer.Dispose();
		}
	}

	public static void AddGrid(GameObject grid)
	{
		grids.Add(grid);
	}

	public static GameObject GetGrid(int index)
	{
		return grids[index];
	}

	public static GameObject GetGrid(EndlessGrid eg)
	{
		return egToGrid[eg];
	}

	public static int GridsCount()
	{
		return grids.Count;
	}

	public static EndlessGrid GetEG(int index)
	{
		return ((Component)grids[index].transform.GetChild(2)).GetComponent<EndlessGrid>();
	}

	public static EndlessGrid GetEG(GameObject grid)
	{
		return ((Component)grid.transform.GetChild(2)).GetComponent<EndlessGrid>();
	}

	public static void AddEGMap(EndlessGrid eg, GameObject grid)
	{
		if (!egToGrid.ContainsKey(eg))
		{
			egToGrid.Add(eg, grid);
		}
	}

	public static int EGMapCount()
	{
		return egToGrid.Count;
	}

	public static void RegisterGrid(GameObject grid)
	{
		AddGrid(grid);
		AddEGMap(GetEG(grid), grid);
	}

	public static void RemoveGrid(int index)
	{
		egToGrid.Remove(GetEG(index));
		grids.RemoveAt(index);
	}

	public static void RemoveGrid(GameObject grid)
	{
		egToGrid.Remove(GetEG(grid));
		grids.Remove(grid);
	}

	public static void AddEGStatus(EndlessGrid eg, bool status)
	{
		if (!egToGrid.ContainsKey(eg))
		{
			finishedGrids.Add(eg, status);
		}
	}

	public static void SetEGStatus(EndlessGrid eg, bool status)
	{
		finishedGrids[eg] = status;
	}

	public static bool GetEGStatus(EndlessGrid eg)
	{
		return finishedGrids[eg];
	}

	public static EndlessGrid[] GetEGStatusesKeys()
	{
		EndlessGrid[] array = (EndlessGrid[])(object)new EndlessGrid[finishedGrids.Count];
		finishedGrids.Keys.CopyTo(array, 0);
		return array;
	}

	public static int EGStatusesCount()
	{
		return finishedGrids.Count;
	}
}
[BepInPlugin("fenicemaster.CyberMultiplier", "CyberMultiplier", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("fenicemaster.CyberMultiplier");

	public static Plugin instance;

	internal static ManualLogSource mls;

	internal static ConfigEntry<int> multiplier;

	internal static ConfigEntry<bool> syncIn;

	internal static ConfigEntry<bool> syncOut;

	internal static ConfigEntry<bool> screenCram;

	internal static ConfigEntry<bool> allInvValues;

	internal static ConfigEntry<bool> logGrids;

	public void Awake()
	{
		mls = Logger.CreateLogSource(" fenicemaster.CyberMultiplier");
		mls.LogInfo((object)"CyberMultiplier is loading...");
		configs();
		if ((Object)(object)instance == (Object)null)
		{
			instance = this;
		}
		harmony.PatchAll(typeof(Plugin));
		harmony.PatchAll(typeof(CyberGrindPatch));
		harmony.PatchAll(typeof(CyberManager));
		CyberManager.Listen();
		mls.LogInfo((object)"CyberMultiplier is loaded");
	}

	public void configs()
	{
		multiplier = ((BaseUnityPlugin)this).Config.Bind<int>("CyberGrind", "CyberGrind arena multiplier", 2, "This setting will make the CyberGrind bigger.\nIf N is the number given, the CyberGrind will be enlarged to be NxN big.\n(numbers < 1 will be read as 1)");
		syncIn = ((BaseUnityPlugin)this).Config.Bind<bool>("CyberGrind", "Start sync", true, "This setting allows the activation of everything at once at the activation of one grid.");
		syncOut = ((BaseUnityPlugin)this).Config.Bind<bool>("CyberGrind", "Change sync", false, "This setting makes grids wait the death of all enemies to change.");
		screenCram = ((BaseUnityPlugin)this).Config.Bind<bool>("CyberGrind", "Screen cram", true, "This setting makes the screen count for all the grids enemies.");
		allInvValues = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Allow invalid values", false, "This setting will make the generation accept invalid values that are < than 1.");
		logGrids = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log things", true, "This setting will toggle the logs for most stuff.");
	}
}