Decompiled source of DSP God Mode Button v1.0.2

DSPGodModeButton.dll

Decompiled a week 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.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DSP God Mode Button")]
[assembly: AssemblyDescription("Mod for Dyson Sphere Program will allow the player to toggle God build mode with a button on the HUD.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DSP God Mode Button")]
[assembly: AssemblyCopyright("Copyright ©  2021-2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5b422ce7-f11a-4686-a43e-b16fc4582a50")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.2.0")]
namespace DSPGodModeButton;

[BepInPlugin("greyhak.dysonsphereprogram.godmodebutton", "DSP God Mode Button", "1.0.2")]
[BepInProcess("DSPGAME.exe")]
[BepInProcess("Dyson Sphere Program.exe")]
public class DSPGodModeButton : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static UnityAction <>9__11_0;

		internal void <GameMain_Begin_Prefix>b__11_0()
		{
			PlayerController.operationWhenBuild = !PlayerController.operationWhenBuild;
			DSPGame.globalOption.buildingViewMode = (PlayerController.operationWhenBuild ? 1 : 0);
		}
	}

	public const string pluginGuid = "greyhak.dysonsphereprogram.godmodebutton";

	public const string pluginName = "DSP God Mode Button";

	public const string pluginVersion = "1.0.2";

	internal static ManualLogSource Logger;

	private Harmony harmony;

	public static bool initialCheckFlag = true;

	public static bool valueAtLastCheck = true;

	public static RectTransform enableDisableButton = null;

	public static Sprite enabledSprite;

	public static Sprite disabledSprite;

	public void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		Logger = ((BaseUnityPlugin)this).Logger;
		harmony = new Harmony("greyhak.dysonsphereprogram.godmodebutton");
		harmony.PatchAll(typeof(DSPGodModeButton));
		enabledSprite = GetSprite(new Color(0f, 1f, 0f));
		disabledSprite = GetSprite(new Color(0.5f, 0.5f, 0.5f));
		Logger.LogInfo((object)"Initialization complete.");
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GameMain), "Begin")]
	public static void GameMain_Begin_Prefix()
	{
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Expected O, but got Unknown
		if (!((Object)(object)GameMain.instance != (Object)null) || !Object.op_Implicit((Object)(object)GameObject.Find("Game Menu/button-1-bg")) || !((Object)(object)enableDisableButton == (Object)null))
		{
			return;
		}
		RectTransform component = GameObject.Find("Game Menu").GetComponent<RectTransform>();
		RectTransform component2 = GameObject.Find("Game Menu/button-1-bg").GetComponent<RectTransform>();
		Vector3 localPosition = ((Transform)GameObject.Find("Game Menu/button-1-bg").GetComponent<RectTransform>()).localPosition;
		enableDisableButton = Object.Instantiate<RectTransform>(component2);
		((Object)((Component)enableDisableButton).gameObject).name = "greyhak-god-mode-button";
		UIButton component3 = ((Component)enableDisableButton).GetComponent<UIButton>();
		component3.tips.delay = 0f;
		((Transform)enableDisableButton).SetParent((Transform)(object)component);
		((Transform)enableDisableButton).localScale = new Vector3(0.35f, 0.35f, 0.35f);
		((Transform)enableDisableButton).localPosition = new Vector3(localPosition.x + 23.5f, localPosition.y + 161f, localPosition.z);
		component3.OnPointerDown((PointerEventData)null);
		component3.OnPointerEnter((PointerEventData)null);
		ButtonClickedEvent onClick = component3.button.onClick;
		object obj = <>c.<>9__11_0;
		if (obj == null)
		{
			UnityAction val = delegate
			{
				PlayerController.operationWhenBuild = !PlayerController.operationWhenBuild;
				DSPGame.globalOption.buildingViewMode = (PlayerController.operationWhenBuild ? 1 : 0);
			};
			<>c.<>9__11_0 = val;
			obj = (object)val;
		}
		((UnityEvent)onClick).AddListener((UnityAction)obj);
	}

	public static Sprite GetSprite(Color color)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(48, 48, (TextureFormat)4, false);
		ulong[] array = new ulong[48]
		{
			496uL, 1008uL, 4080uL, 16368uL, 32752uL, 131056uL, 524272uL, 1048560uL, 4194288uL, 16777200uL,
			33554416uL, 134217712uL, 536870896uL, 1073741808uL, 4294475760uL, 17177780208uL, 34351351792uL, 137405399536uL, 549688705264uL, 1099445010672uL,
			4397913325680uL, 17592053915760uL, 70368614150256uL, 281474846683248uL, 281474846683248uL, 70368614150256uL, 17592053915760uL, 4397913325680uL, 1099445010672uL, 549688705264uL,
			137405399536uL, 34351351792uL, 17177780208uL, 4294475760uL, 1073741808uL, 536870896uL, 134217712uL, 33554416uL, 16777200uL, 4194288uL,
			1048560uL, 524272uL, 131056uL, 32752uL, 16368uL, 4080uL, 1008uL, 496uL
		};
		for (int i = 0; i < 48; i++)
		{
			for (int j = 0; j < 48; j++)
			{
				val.SetPixel(i, j, (Color)((((array[i] >> j) & 1) == 1) ? color : new Color(0f, 0f, 0f, 0f)));
			}
		}
		((Object)val).name = "greyhak-god-mode-icon";
		val.Apply();
		return Sprite.Create(val, new Rect(0f, 0f, 48f, 48f), new Vector2(0f, 0f), 1000f);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(SpaceSector), "GameTick")]
	public static void SpaceSector_GameTick_Postfix()
	{
		if ((Object)(object)enableDisableButton != (Object)null && (initialCheckFlag || valueAtLastCheck != PlayerController.operationWhenBuild))
		{
			initialCheckFlag = false;
			valueAtLastCheck = PlayerController.operationWhenBuild;
			DSPGame.globalOption.buildingViewMode = (PlayerController.operationWhenBuild ? 1 : 0);
			((GameOption)(ref DSPGame.globalOption)).SaveGlobal();
			bool num = Chainloader.PluginInfos.ContainsKey("doobist.dsp.godmodetoggle");
			UIButton component = ((Component)enableDisableButton).GetComponent<UIButton>();
			component.tips.tipTitle = (PlayerController.operationWhenBuild ? "God Mode Disabled" : "God Mode Enabled");
			component.tips.tipText = (PlayerController.operationWhenBuild ? "Click to enable god build mode." : "Click to disable god build mode.");
			if (num)
			{
				component.tips.tipText += "\nOr press \\ to toggle mode.";
			}
			((Component)((Component)enableDisableButton).transform.Find("button-1/icon")).GetComponent<Image>().sprite = (PlayerController.operationWhenBuild ? disabledSprite : enabledSprite);
			component.UpdateTip();
		}
	}
}