Decompiled source of BetterReform v1.0.2

BetterReform.dll

Decompiled a year ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BetterReform")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterReform")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dbe2d784-32ae-4b54-8591-695aa198a05f")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.2.0")]
namespace BetterReformMod;

[BepInPlugin("com.hetima.dsp.BetterReform", "BetterReform", "1.0.2")]
public class BetterReform : BaseUnityPlugin
{
	private static class Patch
	{
		internal static bool _initialized;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameMain), "Begin")]
		public static void GameMain_Begin_Prefix()
		{
			if (!_initialized)
			{
				_initialized = true;
				_mainPanel = UIBetterReformPanel.CreateInstance();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIBuildMenu), "OnCategoryButtonClick")]
		public static void UIBuildMenu_OnCategoryButtonClick_Postfix(UIBuildMenu __instance)
		{
			if (__instance.currentCategory == 9 && (Object)(object)_mainPanel != (Object)null)
			{
				HoldFoundationInHands();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void BuildTool_Reform_Constructor_Postfix(BuildTool_Reform __instance)
		{
			int num = 400;
			if (__instance.cursorIndices.Length < num)
			{
				__instance.cursorIndices = new int[num];
			}
			if (__instance.cursorPoints.Length < num)
			{
				__instance.cursorPoints = (Vector3[])(object)new Vector3[num];
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(BuildTool_Reform), "ReformAction")]
		[HarmonyBefore(new string[] { "Appun.DSP.plugin.BigFormingSize" })]
		public static IEnumerable<CodeInstruction> BuildTool_Reform_ReformAction_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			MethodInfo method = typeof(BetterReform).GetMethod("ModBrushSize");
			FieldInfo fieldInfo = AccessTools.Field(typeof(BuildTool_Reform), "brushSize");
			MethodInfo method2 = typeof(PlatformSystem).GetMethod("SetReformColor");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(BuildTool_Reform), "cursorPointCount");
			typeof(BetterReform).GetMethod("ModCursorPointCount");
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			int num = 0;
			for (int i = 0; i < list.Count - 40; i++)
			{
				if (num < 2 && list[i].opcode == OpCodes.Ldfld && list[i].operand is FieldInfo fieldInfo3 && fieldInfo3 == fieldInfo && list[i + 1].opcode == OpCodes.Ldc_I4_S && list[i + 1].operand is sbyte b && b == 10 && (list[i + 2].opcode == OpCodes.Ble || list[i + 2].opcode == OpCodes.Bge))
				{
					list[i + 1].operand = (sbyte)20;
					num++;
				}
				if (!flag && list[i].opcode == OpCodes.Ldc_R4 && list[i].operand is float num2 && num2 > 0.99f && num2 < 0.994f && list[i + 4].opcode == OpCodes.Mul && list[i + 2].opcode == OpCodes.Ldfld && list[i + 2].operand is FieldInfo fieldInfo4 && fieldInfo4 == fieldInfo)
				{
					list[i + 2].opcode = OpCodes.Call;
					list[i + 2].operand = method;
					flag = true;
				}
				if (!flag3 && list[i].opcode == OpCodes.Callvirt && list[i].operand is MethodInfo methodInfo && methodInfo == method2)
				{
					flag2 = true;
				}
				if (flag2 && !flag3 && list[i].opcode == OpCodes.Ldfld && list[i].operand is FieldInfo fieldInfo5 && fieldInfo5 == fieldInfo2)
				{
					flag3 = true;
				}
			}
			return list.AsEnumerable();
		}
	}

	public const string __NAME__ = "BetterReform";

	public const string __GUID__ = "com.hetima.dsp.BetterReform";

	public static UIBetterReformPanel _mainPanel;

	public const int maxStampSize = 20;

	internal static ManualLogSource Logger;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		Logger = ((BaseUnityPlugin)this).Logger;
		new Harmony("com.hetima.dsp.BetterReform").PatchAll(typeof(Patch));
	}

	public static void Log(string str)
	{
		Logger.LogInfo((object)str);
	}

	public static void HoldFoundationInHands()
	{
		UIBuildMenu buildMenu = UIRoot.instance.uiGame.buildMenu;
		if (buildMenu.currentCategory == 9 && !buildMenu.childButtons[1].highlighted)
		{
			buildMenu.OnChildButtonClick(1);
		}
	}

	public static int ModBrushSize(BuildTool_Reform tool)
	{
		_mainPanel.RefreshState();
		return tool.brushSize;
	}

	public static int ModCursorPointCount(BuildTool_Reform tool)
	{
		_mainPanel.IsStampReady();
		return tool.cursorPointCount;
	}
}
public class UIBetterReformPanel : ManualBehaviour
{
	public RectTransform rectTrans;

	public UIButton type1Button;

	public UIButton type2Button;

	public UIButton iconTagButton;

	public Image iconTagImage;

	public static UIBetterReformPanel CreateInstance()
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0575: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0604: Unknown result type (might be due to invalid IL or missing references)
		//IL_0646: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_051a: Unknown result type (might be due to invalid IL or missing references)
		//IL_052e: Unknown result type (might be due to invalid IL or missing references)
		UIBetterReformPanel win = null;
		UIBuildMenu buildMenu = UIRoot.instance.uiGame.buildMenu;
		GameObject reformGroup = buildMenu.reformGroup;
		UIButton veinBuriedButton = buildMenu.veinBuriedButton;
		UIReformSelect reformSelect = buildMenu.reformSelect;
		GameObject val = Object.Instantiate<GameObject>(reformSelect.reformTypeGroup.gameObject);
		((Object)val).name = "betterReformPanel";
		win = val.AddComponent<UIBetterReformPanel>();
		ref RectTransform reference = ref win.rectTrans;
		Transform transform = val.transform;
		reference = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		win.rectTrans.sizeDelta = new Vector2(600f, 60f);
		Transform transform2 = ((Component)buildMenu.sandPanel).transform;
		Transform obj = ((transform2 is RectTransform) ? transform2 : null);
		SetPosition_((RectTransform)(object)obj, 240f);
		Transform obj2 = obj.Find("icon");
		if (obj2 != null)
		{
			GameObject gameObject = ((Component)obj2).gameObject;
			if (gameObject != null)
			{
				gameObject.SetActive(false);
			}
		}
		obj.SetSiblingIndex(0);
		Transform transform3 = ((Component)buildMenu.reformTypeButton1).transform;
		SetPosition_((RectTransform)(object)((transform3 is RectTransform) ? transform3 : null), 1500f, -500f);
		Transform transform4 = ((Component)buildMenu.reformTypeButton0).transform;
		SetPosition_((RectTransform)(object)((transform4 is RectTransform) ? transform4 : null), 190f);
		buildMenu.reformTypeButton0.tips.delay = 0.6f;
		buildMenu.veinBuriedButton.tips.delay = 0.6f;
		Util.RemovePersistentCalls(((Component)buildMenu.reformTypeButton0).gameObject);
		buildMenu.reformTypeButton0.onClick += win.OnTypeSelectClick;
		buildMenu.reformTypeButton0.data = 7;
		Transform obj3 = reformGroup.transform.Find("sep-line-left-0");
		SetPosition_((RectTransform)(object)((obj3 is RectTransform) ? obj3 : null), -118f);
		Transform obj4 = reformGroup.transform.Find("sep-line-right-0");
		SetPosition_((RectTransform)(object)((obj4 is RectTransform) ? obj4 : null), -117f);
		Transform transform5 = ((Component)veinBuriedButton).transform;
		SetPosition_((RectTransform)(object)((transform5 is RectTransform) ? transform5 : null), -84f);
		Transform obj5 = reformGroup.transform.Find("sep-line-left-1");
		SetPosition_((RectTransform)(object)((obj5 is RectTransform) ? obj5 : null), -51f);
		Transform obj6 = reformGroup.transform.Find("sep-line-right-1");
		SetPosition_((RectTransform)(object)((obj6 is RectTransform) ? obj6 : null), -50f);
		((Component)reformGroup.transform.Find("sep-line-left-2")).gameObject.SetActive(false);
		((Component)reformGroup.transform.Find("sep-line-right-2")).gameObject.SetActive(false);
		((Component)reformGroup.transform.Find("sep-line-left-3")).gameObject.SetActive(false);
		((Component)reformGroup.transform.Find("sep-line-right-3")).gameObject.SetActive(false);
		for (int num = val.transform.childCount - 1; num >= 0; num--)
		{
			GameObject gameObject2 = ((Component)val.transform.GetChild(num)).gameObject;
			if (((Object)gameObject2).name != "bg")
			{
				if (((Object)gameObject2).name == "bt-type-0")
				{
					UIButton component = gameObject2.GetComponent<UIButton>();
					Sprite s_2 = null;
					if ((Object)(object)component != (Object)null)
					{
						Transform obj7 = ((Component)component).transform.Find("icon-0");
						object obj8;
						if (obj7 == null)
						{
							obj8 = null;
						}
						else
						{
							Image component2 = ((Component)obj7).gameObject.GetComponent<Image>();
							obj8 = ((component2 != null) ? component2.sprite : null);
						}
						s_2 = (Sprite)obj8;
					}
					win.type1Button = SetupTypeSelectButton_(s_2, 1, 90f);
					((Object)((Component)win.type1Button).gameObject).name = "type1Button";
				}
				else if (((Object)gameObject2).name == "bt-type-1")
				{
					UIButton component3 = gameObject2.GetComponent<UIButton>();
					Sprite s_3 = null;
					if ((Object)(object)component3 != (Object)null)
					{
						Transform obj9 = ((Component)component3).transform.Find("icon-1");
						object obj10;
						if (obj9 == null)
						{
							obj10 = null;
						}
						else
						{
							Image component4 = ((Component)obj9).gameObject.GetComponent<Image>();
							obj10 = ((component4 != null) ? component4.sprite : null);
						}
						s_3 = (Sprite)obj10;
					}
					win.type2Button = SetupTypeSelectButton_(s_3, 2, 140f);
					((Object)((Component)win.type2Button).gameObject).name = "type2Button";
				}
				else
				{
					gameObject2.SetActive(false);
				}
			}
		}
		UIButton reformColorSelectBtn = buildMenu.reformColorSelectBtn;
		if ((Object)(object)reformColorSelectBtn != (Object)null)
		{
			GameObject val2 = Object.Instantiate<GameObject>(((Component)reformColorSelectBtn).gameObject, ((Component)reformColorSelectBtn).transform.parent);
			buildMenu.reformColorSelectBtn = val2.GetComponent<UIButton>();
			Transform transform6 = ((Component)reformColorSelectBtn).transform;
			Transform obj11 = ((transform6 is RectTransform) ? transform6 : null);
			((RectTransform)obj11).sizeDelta = new Vector2(36f, 36f);
			SetPosition_((RectTransform)(object)obj11, 40f);
			reformColorSelectBtn.tips.delay = 0.6f;
			Transform transform7 = reformSelect.reformColorGroup.transform;
			Transform obj12 = ((transform7 is RectTransform) ? transform7 : null);
			obj12.localScale = new Vector3(1.1f, 1.1f, 1.1f);
			((RectTransform)obj12).anchoredPosition = new Vector2(40f, 4f);
		}
		UIButton obj13 = Util.MakeSmallTextButton("1x", 42f, 22f, 14);
		Transform transform8 = ((Component)obj13).transform;
		SetPosition_((RectTransform)(object)((transform8 is RectTransform) ? transform8 : null), -22f, -2f);
		((Component)((Component)obj13).transform).transform.localScale = Vector3.one;
		obj13.data = 1;
		obj13.onClick += win.OnBrushSizeBtnClick;
		obj13.onRightClick += win.OnBrushSizeBtnRightClick;
		((Object)((Component)obj13).gameObject).name = "1x1-btn";
		obj13.tips.tipTitle = "Brush Size";
		obj13.tips.tipText = "Click to set brush size to 1x1.";
		obj13.tips.corner = 2;
		obj13.tips.offset = new Vector2(0f, -6f);
		UIButton obj14 = Util.MakeSmallTextButton("10x", 42f, 22f, 14);
		Transform transform9 = ((Component)obj14).transform;
		SetPosition_((RectTransform)(object)((transform9 is RectTransform) ? transform9 : null), -22f, 22f);
		((Component)((Component)obj14).transform).transform.localScale = Vector3.one;
		obj14.data = 10;
		obj14.onClick += win.OnBrushSizeBtnClick;
		obj14.onRightClick += win.OnBrushSizeBtnRightClick;
		((Object)((Component)obj14).gameObject).name = "10x10-btn";
		obj14.tips.tipTitle = "Brush Size";
		obj14.tips.tipText = "Click to set brush size to 10x10.\nRight-Click to set 20x20.";
		obj14.tips.corner = 8;
		obj14.tips.offset = new Vector2(0f, 6f);
		val.SetActive(false);
		return win;
		void SetPosition_(RectTransform rect_, float x_, float y_ = 10f)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rect_ != (Object)null)
			{
				((Transform)rect_).SetParent(reformGroup.transform);
				rect_.anchorMin = new Vector2(0.5f, 0.5f);
				rect_.anchorMax = new Vector2(0.5f, 0.5f);
				rect_.pivot = new Vector2(0.5f, 0.5f);
				rect_.anchoredPosition3D = new Vector3(x_, y_, 0f);
			}
		}
		UIButton SetupTypeSelectButton_(Sprite s_, int data_, float pos_)
		{
			GameObject val3 = Object.Instantiate<GameObject>(((Component)buildMenu.reformTypeButton0).gameObject);
			Util.RemovePersistentCalls(val3);
			UIButton component5 = val3.GetComponent<UIButton>();
			Transform obj15 = val3.transform.Find("icon");
			Image val4 = ((obj15 != null) ? ((Component)obj15).gameObject.GetComponent<Image>() : null);
			if ((Object)(object)val4 != (Object)null)
			{
				val4.sprite = s_;
			}
			component5.onClick += win.OnTypeSelectClick;
			component5.data = data_;
			Transform transform10 = ((Component)component5).transform;
			SetPosition_((RectTransform)(object)((transform10 is RectTransform) ? transform10 : null), pos_);
			component5.tips.tipTitle = buildMenu.reformTypeButton1.tips.tipTitle;
			component5.tips.tipText = buildMenu.reformTypeButton1.tips.tipText;
			component5.tips.delay = 0.6f;
			val3.SetActive(true);
			return component5;
		}
	}

	public void RefreshState()
	{
		Player mainPlayer = GameMain.mainPlayer;
		BuildTool_Reform val = ((mainPlayer != null) ? mainPlayer.controller.actionBuild.reformTool : null);
		if (val != null)
		{
			type1Button.highlighted = val.brushType == 1;
			type2Button.highlighted = val.brushType == 2;
		}
	}

	public bool IsStampReady()
	{
		return false;
	}

	public void OnBrushSizeBtnClick(int obj)
	{
		Player mainPlayer = GameMain.mainPlayer;
		BuildTool_Reform val = ((mainPlayer != null) ? mainPlayer.controller.actionBuild.reformTool : null);
		if (val != null && obj > 0)
		{
			val.brushSize = obj;
			BetterReform.HoldFoundationInHands();
		}
	}

	public void OnBrushSizeBtnRightClick(int obj)
	{
		Player mainPlayer = GameMain.mainPlayer;
		BuildTool_Reform val = ((mainPlayer != null) ? mainPlayer.controller.actionBuild.reformTool : null);
		if (val != null && obj > 0)
		{
			if (obj == 1)
			{
				val.brushSize = 5;
			}
			else
			{
				val.brushSize = obj * 2;
			}
			if (20 < val.brushSize)
			{
				val.brushSize = 20;
			}
			BetterReform.HoldFoundationInHands();
		}
	}

	public void OnTypeSelectClick(int data)
	{
		UIBuildMenu buildMenu = UIRoot.instance.uiGame.buildMenu;
		if (data == 7)
		{
			buildMenu.OnReformTypeRemoveClick(7);
		}
		else
		{
			Player mainPlayer = GameMain.mainPlayer;
			BuildTool_Reform val = ((mainPlayer != null) ? mainPlayer.controller.actionBuild.reformTool : null);
			if (val != null)
			{
				val.brushType = data;
			}
			BetterReform.HoldFoundationInHands();
		}
		RefreshState();
	}
}
public static class Util
{
	public static Color DSPBlue => new Color(0.3821f, 0.8455f, 1f, 0.7059f);

	public static Color DSPOrange => new Color(0.9906f, 0.5897f, 0.3691f, 0.7059f);

	public static void RemovePersistentCalls(GameObject go)
	{
		Button component = go.GetComponent<Button>();
		UIButton component2 = go.GetComponent<UIButton>();
		if ((Object)(object)component2 != (Object)null && (Object)(object)component != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component);
			component2.button = go.AddComponent<Button>();
		}
	}

	public static RectTransform NormalizeRect(GameObject go, float width = 0f, float height = 0f)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = (RectTransform)go.transform;
		val.anchorMax = Vector2.zero;
		val.anchorMin = Vector2.zero;
		val.pivot = Vector2.zero;
		if (width > 0f && height > 0f)
		{
			val.sizeDelta = new Vector2(width, height);
		}
		return val;
	}

	public static RectTransform NormalizeRectB(GameObject go)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		RectTransform val = (RectTransform)go.transform;
		val.anchorMax = Vector2.one;
		val.anchorMin = Vector2.zero;
		val.pivot = new Vector2(0.5f, 0.5f);
		return val;
	}

	public static RectTransform NormalizeRectC(GameObject go, float width = 0f, float height = 0f)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = (RectTransform)go.transform;
		val.anchorMax = new Vector2(0.5f, 0.5f);
		val.anchorMin = new Vector2(0.5f, 0.5f);
		val.pivot = new Vector2(0.5f, 0.5f);
		if (width > 0f && height > 0f)
		{
			val.sizeDelta = new Vector2(width, height);
		}
		return val;
	}

	public static RectTransform NormalizeRectD(GameObject go, float width = 0f, float height = 0f)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = (RectTransform)go.transform;
		val.anchorMax = Vector2.up;
		val.anchorMin = Vector2.up;
		val.pivot = Vector2.up;
		if (width > 0f && height > 0f)
		{
			val.sizeDelta = new Vector2(width, height);
		}
		return val;
	}

	public static Sprite LoadSpriteResource(string path)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		Sprite val = Resources.Load<Sprite>(path);
		if ((Object)(object)val != (Object)null)
		{
			return val;
		}
		Texture2D val2 = Resources.Load<Texture2D>(path);
		if ((Object)(object)val2 != (Object)null)
		{
			return Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
		}
		return null;
	}

	public static UIButton MakeSmallTextButton(string label = "", float width = 0f, float height = 0f, int fontSize = 12)
	{
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Object.Instantiate<GameObject>(((Component)UIRoot.instance.uiGame.assemblerWindow.copyButton).gameObject);
		UIButton component = val.GetComponent<UIButton>();
		Transform obj = val.transform.Find("Text");
		Object.DestroyImmediate((Object)(object)((Component)obj).GetComponent<Localizer>());
		Text component2 = ((Component)obj).GetComponent<Text>();
		component2.text = label;
		component2.fontSize = fontSize;
		component.tips.tipText = "";
		component.tips.tipTitle = "";
		component.tips.delay = 0.6f;
		if (width > 0f || height > 0f)
		{
			RectTransform val2 = (RectTransform)val.transform;
			if (width == 0f)
			{
				width = val2.sizeDelta.x;
			}
			if (height == 0f)
			{
				height = val2.sizeDelta.y;
			}
			val2.sizeDelta = new Vector2(width, height);
		}
		val.transform.localScale = Vector3.one;
		return component;
	}

	public static UIButton MakeIconButtonB(Sprite sprite, float size = 60f)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = Object.Instantiate<GameObject>(((Component)UIRoot.instance.uiGame.researchQueue.pauseButton).gameObject);
		UIButton component = obj.GetComponent<UIButton>();
		RectTransform val = (RectTransform)obj.transform;
		float num = size / 60f;
		((Transform)val).localScale = new Vector3(num, num, num);
		Transform obj2 = obj.transform.Find("icon");
		Image val2 = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
		if ((Object)(object)val2 != (Object)null)
		{
			val2.sprite = sprite;
		}
		component.tips.tipText = "";
		component.tips.tipTitle = "";
		return component;
	}

	public static UIButton MakeIconButton(Transform parent, Sprite sprite, float posX = 0f, float posY = 0f, bool right = false, bool bottom = false)
	{
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		GameObject gameObject = ((Component)UIRoot.instance.uiGame.researchQueue.pauseButton).gameObject;
		if ((Object)(object)gameObject == (Object)null)
		{
			return null;
		}
		UIButton val = MakeGameObject<UIButton>(parent, gameObject, posX, posY, 0f, 0f, right, bottom);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		Transform val2 = ((Component)val).gameObject.transform.Find("bg");
		if ((Object)(object)val2 != (Object)null)
		{
			((Component)val2).gameObject.SetActive(false);
		}
		Transform val3 = ((Component)val).gameObject.transform.Find("sd");
		if ((Object)(object)val3 != (Object)null)
		{
			((Component)val3).gameObject.SetActive(false);
		}
		Transform val4 = ((Component)val).gameObject.transform.Find("icon");
		if ((Object)(object)sprite != (Object)null && (Object)(object)val4 != (Object)null)
		{
			Image component = ((Component)val4).GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				component.sprite = sprite;
				((Graphic)component).color = new Color(0.94f, 0.74f, 0.24f, 0.6f);
			}
			val4.localScale = new Vector3(1.6f, 1.6f, 1.6f);
		}
		((Component)val).gameObject.transform.localScale = new Vector3(0.28f, 0.28f, 0.28f);
		val.tips.offset = new Vector2(0f, -10f);
		val.tips.corner = 0;
		val.tips.delay = 0.5f;
		val.tips.tipText = "";
		val.tips.tipTitle = "";
		return val;
	}

	public static T MakeGameObject<T>(Transform parent, GameObject src, float posX = 0f, float posY = 0f, float width = 0f, float height = 0f, bool right = false, bool bottom = false)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)src == (Object)null)
		{
			return default(T);
		}
		GameObject val = Object.Instantiate<GameObject>(src);
		if ((Object)(object)val == (Object)null)
		{
			return default(T);
		}
		RectTransform val2 = (RectTransform)val.transform;
		if ((Object)(object)val2 != (Object)null)
		{
			float num = ((!bottom) ? 1 : 0);
			float num2 = (right ? 1 : 0);
			val2.anchorMax = new Vector2(num2, num);
			val2.anchorMin = new Vector2(num2, num);
			val2.pivot = new Vector2(0f, 0f);
			if (width == -1f)
			{
				width = val2.sizeDelta.x;
			}
			if (height == -1f)
			{
				height = val2.sizeDelta.y;
			}
			if (width > 0f && height > 0f)
			{
				val2.sizeDelta = new Vector2(width, height);
			}
			((Transform)val2).SetParent(parent, false);
			val2.anchoredPosition = new Vector2(posX, posY);
		}
		return val.GetComponent<T>();
	}

	public static string KMGFormat(long num)
	{
		if (num >= 100000000000000L)
		{
			return (num / 1000000000000L).ToString("#,0T");
		}
		if (num >= 10000000000000L)
		{
			return (num / 1000000000000L).ToString("0.#") + "T";
		}
		if (num >= 100000000000L)
		{
			return (num / 1000000000).ToString("#,0G");
		}
		if (num >= 10000000000L)
		{
			return (num / 1000000000).ToString("0.#") + "G";
		}
		if (num >= 100000000)
		{
			return (num / 1000000).ToString("#,0M");
		}
		if (num >= 10000000)
		{
			return (num / 1000000).ToString("0.#") + "M";
		}
		if (num >= 100000)
		{
			return (num / 1000).ToString("#,0K");
		}
		if (num >= 10000)
		{
			return (num / 1000).ToString("0.#") + "K";
		}
		return num.ToString("#,0");
	}

	public static Sprite StampSprite()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(2, 2);
		byte[] array = new byte[398]
		{
			137, 80, 78, 71, 13, 10, 26, 10, 0, 0,
			0, 13, 73, 72, 68, 82, 0, 0, 0, 24,
			0, 0, 0, 24, 8, 4, 0, 0, 0, 74,
			126, 245, 115, 0, 0, 0, 9, 112, 72, 89,
			115, 0, 0, 11, 19, 0, 0, 11, 19, 1,
			0, 154, 156, 24, 0, 0, 1, 64, 73, 68,
			65, 84, 120, 218, 165, 210, 3, 168, 88, 81,
			28, 128, 241, 251, 172, 56, 164, 217, 150, 194,
			172, 48, 91, 202, 67, 90, 182, 133, 101, 46,
			75, 179, 148, 61, 134, 217, 82, 152, 109, 222,
			243, 123, 167, 206, 179, 241, 125, 87, 56, 127,
			213, 201, 186, 141, 130, 120, 86, 26, 97, 164,
			170, 142, 134, 44, 246, 216, 103, 159, 188, 177,
			176, 35, 217, 7, 168, 231, 187, 57, 89, 166,
			176, 237, 128, 19, 8, 146, 28, 84, 150, 190,
			183, 30, 240, 10, 1, 228, 184, 162, 119, 170,
			209, 122, 192, 249, 186, 128, 128, 51, 170, 218,
			171, 176, 88, 61, 127, 109, 75, 249, 219, 64,
			149, 79, 32, 224, 101, 27, 227, 42, 84, 20,
			45, 80, 106, 63, 114, 1, 199, 178, 76, 177,
			248, 93, 97, 147, 182, 26, 190, 218, 131, 28,
			236, 109, 184, 66, 65, 163, 23, 125, 141, 54,
			214, 80, 195, 156, 67, 136, 114, 221, 40, 195,
			141, 53, 206, 128, 166, 21, 118, 185, 228, 177,
			135, 110, 187, 226, 159, 90, 130, 251, 110, 121,
			228, 137, 155, 118, 40, 104, 184, 252, 143, 246,
			248, 110, 119, 237, 242, 158, 222, 226, 191, 92,
			178, 33, 181, 223, 254, 225, 185, 113, 41, 96,
			172, 47, 200, 5, 209, 218, 123, 19, 255, 227,
			141, 101, 41, 96, 146, 111, 58, 194, 71, 27,
			82, 64, 127, 47, 241, 165, 29, 185, 99, 70,
			10, 40, 52, 207, 198, 120, 206, 138, 206, 108,
			197, 121, 214, 155, 166, 36, 171, 197, 20, 19,
			141, 104, 197, 225, 209, 169, 166, 102, 245, 168,
			208, 62, 31, 140, 174, 219, 17, 74, 189, 242,
			197, 123, 239, 226, 217, 146, 239, 252, 240, 80,
			255, 250, 10, 133, 86, 217, 100, 133, 229, 173,
			186, 197, 106, 133, 89, 87, 168, 6, 106, 22,
			55, 237, 209, 68, 68, 150, 0, 0, 0, 0,
			73, 69, 78, 68, 174, 66, 96, 130
		};
		ImageConversion.LoadImage(val, array);
		return Sprite.Create(val, new Rect(0f, 0f, 24f, 24f), new Vector2(0f, 0f));
	}
}