Decompiled source of CharacterEditButton v0.8.2

plugins/CharacterEdit.dll

Decompiled 7 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
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: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CharacterEdit;

[BepInPlugin("cjayride.CharacterEdit", "Character Edit", "0.8.2")]
public class BepInExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(FejdStartup), "Awake")]
	private static class FejdStartup_Awake_Patch
	{
		private static void Postfix(FejdStartup __instance)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			if (modEnabled.Value)
			{
				Transform val = FejdStartup.instance.m_selectCharacterPanel.transform.Find("BottomWindow");
				Transform val2 = Object.Instantiate<Transform>(val.Find("New"));
				((Object)val2).name = "Edit";
				((Component)val2).transform.SetParent(val);
				((Component)val2).GetComponent<RectTransform>().anchoredPosition = Vector2.op_Implicit(new Vector3(-100f, 50f, 0f));
				((Component)((Component)val2).transform.Find("Text")).GetComponent<TMP_Text>().text = buttonText.Value;
				((UnityEventBase)((Component)val2).GetComponent<Button>().onClick).RemoveAllListeners();
				((Component)val2).GetComponent<Button>().onClick = new ButtonClickedEvent();
				((UnityEvent)((Component)val2).GetComponent<Button>().onClick).AddListener(new UnityAction(StartCharacterEdit));
				((Component)val2).GetComponent<UIGamePad>().m_zinputKey = gamePadButton.Value;
				((TMP_Text)((Component)((Component)val2).transform.Find("gamepad_hint").Find("Text")).GetComponent<TextMeshProUGUI>()).text = gamePadButtonHint.Value;
				title = Object.Instantiate<Transform>(FejdStartup.instance.m_newCharacterPanel.transform.Find("Topic"));
				((Object)title).name = "EditTitle";
				title.SetParent(FejdStartup.instance.m_newCharacterPanel.transform);
				((Component)title).GetComponent<TMP_Text>().text = titleText.Value;
				((Component)title).GetComponent<RectTransform>().anchoredPosition = ((Component)FejdStartup.instance.m_newCharacterPanel.transform.Find("Topic")).GetComponent<RectTransform>().anchoredPosition;
				((Component)title).gameObject.SetActive(false);
			}
		}
	}

	[HarmonyPatch(typeof(FejdStartup), "OnNewCharacterDone")]
	private static class FejdStartup_OnNewCharacterDone_Patch
	{
		private static bool Prefix(FejdStartup __instance, ref List<PlayerProfile> ___m_profiles)
		{
			Dbgl($"New character done, editing {editingCharacter}");
			if (!editingCharacter)
			{
				return true;
			}
			((Component)title).gameObject.SetActive(false);
			((Component)FejdStartup.instance.m_newCharacterPanel.transform.Find("Topic")).gameObject.SetActive(true);
			editingCharacter = false;
			string text = ((TMP_InputField)__instance.m_csNewCharacterName).text;
			string text2 = text.ToLower();
			PlayerProfile val = Traverse.Create((object)FejdStartup.instance).Field("m_profiles").GetValue<List<PlayerProfile>>()[Traverse.Create((object)FejdStartup.instance).Field("m_profileIndex").GetValue<int>()];
			Player component = Traverse.Create((object)FejdStartup.instance).Field("m_playerInstance").GetValue<GameObject>()
				.GetComponent<Player>();
			val.SavePlayerData(component);
			val.SetName(text);
			val.Save();
			__instance.m_selectCharacterPanel.SetActive(true);
			__instance.m_newCharacterPanel.SetActive(false);
			___m_profiles = null;
			Traverse.Create((object)__instance).Method("SetSelectedProfile", new object[1] { text2 }).GetValue();
			return false;
		}
	}

	[HarmonyPatch(typeof(FejdStartup), "OnNewCharacterCancel")]
	private static class FejdStartup_OnNewCharacterCancel_Patch
	{
		private static void Postfix(FejdStartup __instance)
		{
			Dbgl($"New character cancel, editing {editingCharacter}");
			((Component)title).gameObject.SetActive(false);
			((Component)FejdStartup.instance.m_newCharacterPanel.transform.Find("Topic")).gameObject.SetActive(true);
			editingCharacter = false;
		}
	}

	[HarmonyPatch(typeof(PlayerCustomizaton), "OnEnable")]
	private static class PlayerCustomizaton_OnEnable_Patch
	{
		private static void Postfix(PlayerCustomizaton __instance)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			Dbgl("Player customization enabled");
			if (editingCharacter)
			{
				Dbgl("is editing");
				Player previewPlayer = ((Component)__instance).GetComponentInParent<FejdStartup>().GetPreviewPlayer();
				if (previewPlayer.GetPlayerModel() == 1)
				{
					__instance.m_maleToggle.isOn = false;
					__instance.m_femaleToggle.isOn = true;
				}
				VisEquipment value = Traverse.Create((object)previewPlayer).Field("m_visEquipment").GetValue<VisEquipment>();
				Vector3 value2 = Traverse.Create((object)value).Field("m_skinColor").GetValue<Vector3>();
				float value3 = Vector3.Distance(value2, Utils.ColorToVec3(__instance.m_skinColor0)) / Vector3.Distance(Utils.ColorToVec3(__instance.m_skinColor1), Utils.ColorToVec3(__instance.m_skinColor0)) * (__instance.m_skinHue.maxValue - __instance.m_skinHue.minValue) + __instance.m_skinHue.minValue;
				__instance.m_skinHue.value = value3;
			}
		}
	}

	[HarmonyPatch(typeof(Terminal), "InputText")]
	private static class InputText_Patch
	{
		private static bool Prefix(Terminal __instance)
		{
			if (!modEnabled.Value)
			{
				return true;
			}
			string text = ((TMP_InputField)__instance.m_input).text;
			if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
			{
				((BaseUnityPlugin)context).Config.Reload();
				((BaseUnityPlugin)context).Config.Save();
				__instance.AddString(text);
				__instance.AddString(((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded");
				return false;
			}
			return true;
		}
	}

	private static readonly bool isDebug = true;

	private static bool editingCharacter = false;

	private static BepInExPlugin context;

	private Harmony harmony;

	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<string> titleText;

	public static ConfigEntry<string> buttonText;

	public static ConfigEntry<string> gamePadButton;

	public static ConfigEntry<string> gamePadButtonHint;

	public static ConfigEntry<int> nexusID;

	private static Transform title;

	public static void Dbgl(string str = "", bool pref = true)
	{
		if (isDebug)
		{
			Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
		}
	}

	private void Awake()
	{
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Expected O, but got Unknown
		context = this;
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		buttonText = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ButtonText", "Edit", "Button text");
		titleText = ((BaseUnityPlugin)this).Config.Bind<string>("General", "TitleText", "Edit Character", "Title text");
		gamePadButton = ((BaseUnityPlugin)this).Config.Bind<string>("General", "GamePadButton", "JoyLTrigger", "Gamepad button used to press button. Possible values: JoyHide, JoyGPower, JoyRun, JoyCrouch, JoyMap, JoyMenu, JoyBlock, JoyAttack, JoySecondAttack, JoyAltPlace, JoyRotate, JoyPlace, JoyRemove, JoyTabLeft, JoyTabRight, JoyLStickLeft, JoyLStickRight, JoyLStickUp, JoyLStickDown, JoyDPadLeft, JoyDPadRight, JoyDPadUp, JoyDPadDown, JoyLTrigger, JoyRTrigger, JoyLStick, JoyRStick");
		gamePadButtonHint = ((BaseUnityPlugin)this).Config.Bind<string>("General", "GamePadButtonHint", "LT", "Hint to show for gamepad button");
		nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 650, "Nexus mod ID for updates");
		if (modEnabled.Value)
		{
			harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			harmony.PatchAll();
		}
	}

	private static void StartCharacterEdit()
	{
		Dbgl("Start editing character");
		editingCharacter = true;
		((Component)title).gameObject.SetActive(true);
		((Component)FejdStartup.instance.m_newCharacterPanel.transform.Find("Topic")).gameObject.SetActive(false);
		PlayerProfile val = Traverse.Create((object)FejdStartup.instance).Field("m_profiles").GetValue<List<PlayerProfile>>()[Traverse.Create((object)FejdStartup.instance).Field("m_profileIndex").GetValue<int>()];
		FejdStartup.instance.m_newCharacterPanel.SetActive(true);
		FejdStartup.instance.m_selectCharacterPanel.SetActive(false);
		((TMP_InputField)FejdStartup.instance.m_csNewCharacterName).text = val.GetName();
		FejdStartup.instance.m_newCharacterError.SetActive(false);
		Traverse.Create((object)FejdStartup.instance).Method("SetupCharacterPreview", new object[1] { val }).GetValue();
		Gogan.LogEvent("Screen", "Enter", "CreateCharacter", 0L);
	}
}