Decompiled source of RanongTextureChanger v1.0.0

RanongTextureChanger.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using UnityEngine;
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(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("RanongTextureChanger")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RanongTextureChanger")]
[assembly: AssemblyTitle("RanongTextureChanger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RanongTextureChanger;

[BepInPlugin("com.ranongpatama.ranongtexturechanger", "RanongTextureChanger", "1.0.0")]
public class RanongTextureChanger : BaseUnityPlugin
{
	public enum CharacterCategory
	{
		ActiveFamily,
		SpousesRetired,
		Retainers
	}

	public static ManualLogSource Log;

	private bool _showWindow = false;

	private CharacterCategory _selectedCategory = CharacterCategory.ActiveFamily;

	private int _selectedCharIndex = -1;

	private Vector2 _charListScroll = Vector2.zero;

	private Vector2 _editorScroll = Vector2.zero;

	private string _backHair = "0";

	private string _outfit = "0";

	private string _faceShape = "0";

	private string _frontHair = "0";

	private string _expression = "0";

	private List<string> _backHairIds = new List<string>();

	private List<string> _outfitIds = new List<string>();

	private List<string> _faceShapeIds = new List<string>();

	private List<string> _frontHairIds = new List<string>();

	private List<string> _expressionIds = new List<string>();

	private int _backHairIdx = 0;

	private int _outfitIdx = 0;

	private int _faceShapeIdx = 0;

	private int _frontHairIdx = 0;

	private int _expressionIdx = 0;

	private readonly Dictionary<string, List<string>> _scannedAssetsCache = new Dictionary<string, List<string>>();

	private string _statusMessage = "";

	private float _statusTime = 0f;

	private bool _isErrorStatus = false;

	private Canvas _previewCanvas;

	private GameObject _previewPortrait;

	private string _originalLiHuiId = "";

	private string _originalPxId = "";

	private int _lastEditedCharIndex = -1;

	private CharacterCategory _lastEditedCategory = CharacterCategory.ActiveFamily;

	private bool _hasUnsavedChanges = false;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"RanongTextureChanger Mod by RanongPatama loaded! Press F9 in-game to open the changer panel.");
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)290))
		{
			ToggleWindow(!_showWindow);
		}
	}

	private void ToggleWindow(bool show)
	{
		_showWindow = show;
		if (_showWindow)
		{
			_statusMessage = "Select a character to customize appearance.";
			_isErrorStatus = false;
			_selectedCharIndex = -1;
			_lastEditedCharIndex = -1;
			_hasUnsavedChanges = false;
			CreatePreviewScene();
		}
		else
		{
			RollbackUnsavedChanges();
			DestroyPreviewScene();
		}
	}

	private void OnGUI()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: 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_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		if (_showWindow)
		{
			GUI.skin.box.padding = new RectOffset(15, 15, 15, 15);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(40f, 40f, 280f, (float)Screen.height - 80f);
			GUI.Box(val, "", GUI.skin.box);
			GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 10f, ((Rect)(ref val)).y + 10f, ((Rect)(ref val)).width - 20f, ((Rect)(ref val)).height - 20f));
			DrawCharacterListColumn();
			GUILayout.EndArea();
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor((float)Screen.width - 360f, 40f, 320f, (float)Screen.height - 80f);
			GUI.Box(val2, "", GUI.skin.box);
			GUILayout.BeginArea(new Rect(((Rect)(ref val2)).x + 10f, ((Rect)(ref val2)).y + 10f, ((Rect)(ref val2)).width - 20f, ((Rect)(ref val2)).height - 20f));
			DrawEditorColumn();
			GUILayout.EndArea();
			if (_selectedCharIndex >= 0)
			{
				Rect val3 = default(Rect);
				((Rect)(ref val3))..ctor(340f, 40f, (float)Screen.width - 720f, 120f);
				GUILayout.BeginArea(val3);
				DrawMiddleHeader();
				GUILayout.EndArea();
			}
		}
	}

	private void DrawStatus()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_0082: 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)
		if (!string.IsNullOrEmpty(_statusMessage))
		{
			if (Time.time > _statusTime && _statusTime > 0f)
			{
				_statusMessage = "";
				return;
			}
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontStyle = (FontStyle)1,
				fontSize = 12
			};
			val.normal.textColor = (_isErrorStatus ? Color.red : Color.green);
			GUILayout.Box(_statusMessage, val, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.ExpandWidth(true),
				GUILayout.Height(25f)
			});
		}
	}

	private void DrawCharacterListColumn()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_0048: 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)
		//IL_0055: 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)
		//IL_0070: Expected O, but got Unknown
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Expected O, but got Unknown
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Expected O, but got Unknown
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label("<b>RANONG TEXTURE CHANGER</b>", new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4,
			richText = true,
			fontSize = 14
		}, Array.Empty<GUILayoutOption>());
		GUILayout.Label("<color=grey>Created by RanongPatama</color>", new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4,
			richText = true,
			fontSize = 10
		}, Array.Empty<GUILayoutOption>());
		GUILayout.Space(10f);
		DrawStatus();
		GUILayout.Space(5f);
		GUILayout.Label("<b>Choose Category</b>", new GUIStyle(GUI.skin.label)
		{
			richText = true
		}, Array.Empty<GUILayoutOption>());
		string[] array = new string[3] { "Clan Member", "Spouse", "Retainers" };
		int selectedCategory = (int)_selectedCategory;
		int num = GUILayout.Toolbar(selectedCategory, array, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) });
		if (num != selectedCategory)
		{
			RollbackUnsavedChanges();
			_selectedCategory = (CharacterCategory)num;
			_selectedCharIndex = -1;
			UpdatePreviewPortrait();
			ShowStatus("Category switched.", isError: false);
		}
		GUILayout.Space(15f);
		GUILayout.Label("<b>Characters</b>", new GUIStyle(GUI.skin.label)
		{
			richText = true
		}, Array.Empty<GUILayoutOption>());
		if (Mainload.Member_now == null)
		{
			GUILayout.Label("No save game active!", GUI.skin.label, Array.Empty<GUILayoutOption>());
			return;
		}
		int count = GetCount(_selectedCategory);
		if (count == 0)
		{
			GUILayout.Label("No characters found.", GUI.skin.label, Array.Empty<GUILayoutOption>());
			return;
		}
		_charListScroll = GUILayout.BeginScrollView(_charListScroll, false, true, Array.Empty<GUILayoutOption>());
		for (int i = 0; i < count; i++)
		{
			string name = GetName(_selectedCategory, i);
			string sex = GetSex(_selectedCategory, i);
			string arg = ((sex == "1") ? "M" : "F");
			int age = GetAge(_selectedCategory, i);
			string text = $"[{arg}] {name} ({age})";
			GUIStyle val = new GUIStyle(GUI.skin.button);
			if (i == _selectedCharIndex)
			{
				val.normal.textColor = Color.yellow;
				val.fontStyle = (FontStyle)1;
			}
			if (GUILayout.Button(text, val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				LoadCharacterAppearance(i);
			}
		}
		GUILayout.EndScrollView();
	}

	private void DrawMiddleHeader()
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Expected O, but got Unknown
		string name = GetName(_selectedCategory, _selectedCharIndex);
		string sex = GetSex(_selectedCategory, _selectedCharIndex);
		string arg = ((sex == "1") ? "Male" : "Female");
		int age = GetAge(_selectedCategory, _selectedCharIndex);
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4,
			fontStyle = (FontStyle)1,
			fontSize = 24,
			richText = true
		};
		val.normal.textColor = Color.yellow;
		GUIStyle val2 = new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4,
			fontSize = 16,
			richText = true
		};
		val2.normal.textColor = new Color(0.85f, 0.85f, 0.85f, 1f);
		GUILayout.Label("<b>" + name + "</b>", val, Array.Empty<GUILayoutOption>());
		GUILayout.Label($"{arg} | Age {age}", val2, Array.Empty<GUILayoutOption>());
		GUILayout.Label("<color=cyan>Live character preview shown in center</color>", new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4,
			richText = true,
			fontSize = 11
		}, Array.Empty<GUILayoutOption>());
	}

	private void DrawEditorColumn()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_003e: 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)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Label("<b>Appearance Settings</b>", new GUIStyle(GUI.skin.label)
		{
			richText = true,
			fontSize = 14
		}, Array.Empty<GUILayoutOption>());
		GUILayout.Space(10f);
		_editorScroll = GUILayout.BeginScrollView(_editorScroll, false, false, Array.Empty<GUILayoutOption>());
		DrawAssetRow("Back Hair (houfa)", ref _backHair, _backHairIds, ref _backHairIdx);
		GUILayout.Space(8f);
		DrawAssetRow("Front Hair (qianfa)", ref _frontHair, _frontHairIds, ref _frontHairIdx);
		GUILayout.Space(8f);
		DrawAssetRow("Outfit (shen)", ref _outfit, _outfitIds, ref _outfitIdx);
		GUILayout.Space(8f);
		DrawAssetRow("Face Shape (tou)", ref _faceShape, _faceShapeIds, ref _faceShapeIdx);
		GUILayout.Space(8f);
		DrawAssetRow("Expression (PX)", ref _expression, _expressionIds, ref _expressionIdx);
		GUILayout.Space(15f);
		GUILayout.EndScrollView();
		GUILayout.Space(10f);
		if (GUILayout.Button("Apply & Save Changes", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) }))
		{
			ApplyChanges();
		}
		GUILayout.Space(5f);
		if (GUILayout.Button("Close Changer (F9)", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
		{
			ToggleWindow(show: false);
		}
	}

	private void DrawAssetRow(string label, ref string currentVal, List<string> idList, ref int idx)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Expected O, but got Unknown
		GUILayout.Label("<b>" + label + "</b>", new GUIStyle(GUI.skin.label)
		{
			richText = true
		}, Array.Empty<GUILayoutOption>());
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("<", (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(35f),
			GUILayout.Height(24f)
		}) && idList.Count > 0)
		{
			idx = (idx - 1 + idList.Count) % idList.Count;
			currentVal = idList[idx];
			OnValueCycled();
		}
		string text = currentVal;
		currentVal = GUILayout.TextField(currentVal, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Height(24f),
			GUILayout.Width(60f)
		});
		if (text != currentVal)
		{
			int num = idList.IndexOf(currentVal);
			if (num >= 0)
			{
				idx = num;
			}
			OnValueCycled();
		}
		if (GUILayout.Button(">", (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(35f),
			GUILayout.Height(24f)
		}) && idList.Count > 0)
		{
			idx = (idx + 1) % idList.Count;
			currentVal = idList[idx];
			OnValueCycled();
		}
		GUILayout.EndHorizontal();
		if (idList.Count > 0)
		{
			int num2 = idList.IndexOf(currentVal);
			string text2 = ((num2 >= 0) ? $"Choice {num2 + 1} of {idList.Count}" : "Custom ID (Unscanned)");
			GUILayout.Label("<color=cyan><size=11>" + text2 + "</size></color>", new GUIStyle(GUI.skin.label)
			{
				richText = true
			}, Array.Empty<GUILayoutOption>());
		}
	}

	private void OnValueCycled()
	{
		if (_selectedCharIndex >= 0)
		{
			_hasUnsavedChanges = true;
			string value = _backHair + "|" + _outfit + "|" + _faceShape + "|" + _frontHair;
			SetLiHuiId(_selectedCategory, _selectedCharIndex, value);
			SetPxId(_selectedCategory, _selectedCharIndex, _expression);
			UpdatePreviewPortrait();
		}
	}

	private void LoadCharacterAppearance(int charIndex)
	{
		RollbackUnsavedChanges();
		_selectedCharIndex = charIndex;
		_lastEditedCharIndex = charIndex;
		_lastEditedCategory = _selectedCategory;
		_hasUnsavedChanges = false;
		_originalLiHuiId = GetLiHuiId(_selectedCategory, charIndex);
		_originalPxId = GetPxId(_selectedCategory, charIndex);
		string[] array = _originalLiHuiId.Split(new char[1] { '|' });
		_backHair = ((array.Length != 0) ? array[0] : "0");
		_outfit = ((array.Length > 1) ? array[1] : "0");
		_faceShape = ((array.Length > 2) ? array[2] : "0");
		_frontHair = ((array.Length > 3) ? array[3] : "0");
		_expression = _originalPxId;
		string sex = GetSex(_selectedCategory, charIndex);
		int age = GetAge(_selectedCategory, charIndex);
		GetAgeCategories(age, out var hf, out var shen, out var tou, out var px, out var qf);
		_backHairIds = GetCachedOrScan(sex, hf, "houfa");
		_outfitIds = GetCachedOrScan(sex, shen, "shen");
		_faceShapeIds = GetCachedOrScan(sex, tou, "tou");
		_frontHairIds = GetCachedOrScan(sex, qf, "qianfa");
		_expressionIds = GetCachedOrScan(sex, px, "PX");
		EnsureValueInList(_backHairIds, _backHair);
		EnsureValueInList(_outfitIds, _outfit);
		EnsureValueInList(_faceShapeIds, _faceShape);
		EnsureValueInList(_frontHairIds, _frontHair);
		EnsureValueInList(_expressionIds, _expression);
		_backHairIdx = _backHairIds.IndexOf(_backHair);
		_outfitIdx = _outfitIds.IndexOf(_outfit);
		_faceShapeIdx = _faceShapeIds.IndexOf(_faceShape);
		_frontHairIdx = _frontHairIds.IndexOf(_frontHair);
		_expressionIdx = _expressionIds.IndexOf(_expression);
		UpdatePreviewPortrait();
		ShowStatus("Loaded " + GetName(_selectedCategory, charIndex) + ".", isError: false);
	}

	private List<string> GetCachedOrScan(string sex, string ageCategory, string partType)
	{
		string key = sex + "_" + ageCategory + "_" + partType;
		if (_scannedAssetsCache.TryGetValue(key, out var value))
		{
			return value;
		}
		List<string> list = new List<string>();
		for (int i = 0; i <= 120; i++)
		{
			string text = i.ToString();
			string text2 = "AllLooks/Member_B/" + sex + "/" + ageCategory + "/" + partType + "/" + text;
			if (Resources.Load(text2) != (Object)null)
			{
				list.Add(text);
			}
		}
		_scannedAssetsCache[key] = list;
		Log.LogInfo((object)$"[RanongTextureChanger] Scanned '{partType}' for Sex {sex}, AgeCategory {ageCategory}. Cached {list.Count} IDs.");
		return list;
	}

	private void EnsureValueInList(List<string> list, string val)
	{
		if (!list.Contains(val))
		{
			list.Add(val);
			list.Sort((string a, string b) => (int.TryParse(a, out var result) && int.TryParse(b, out var result2)) ? result.CompareTo(result2) : string.Compare(a, b, StringComparison.OrdinalIgnoreCase));
		}
	}

	private void ApplyChanges()
	{
		if (_selectedCharIndex < 0)
		{
			return;
		}
		string sex = GetSex(_selectedCategory, _selectedCharIndex);
		int age = GetAge(_selectedCategory, _selectedCharIndex);
		GetAgeCategories(age, out var hf, out var shen, out var tou, out var px, out var qf);
		if (!ValidateAsset("houfa", sex, hf, _backHair, out var checkedPath))
		{
			ShowStatus("Error: Invalid Back Hair ID '" + _backHair + "'! Path not found:\n" + checkedPath, isError: true);
			return;
		}
		if (!ValidateAsset("qianfa", sex, qf, _frontHair, out var checkedPath2))
		{
			ShowStatus("Error: Invalid Front Hair ID '" + _frontHair + "'! Path not found:\n" + checkedPath2, isError: true);
			return;
		}
		if (!ValidateAsset("shen", sex, shen, _outfit, out var checkedPath3))
		{
			ShowStatus("Error: Invalid Outfit ID '" + _outfit + "'! Path not found:\n" + checkedPath3, isError: true);
			return;
		}
		if (!ValidateAsset("tou", sex, tou, _faceShape, out var checkedPath4))
		{
			ShowStatus("Error: Invalid Face Shape ID '" + _faceShape + "'! Path not found:\n" + checkedPath4, isError: true);
			return;
		}
		if (!ValidateAsset("PX", sex, px, _expression, out var checkedPath5))
		{
			ShowStatus("Error: Invalid Expression ID '" + _expression + "'! Path not found:\n" + checkedPath5, isError: true);
			return;
		}
		string text = _backHair + "|" + _outfit + "|" + _faceShape + "|" + _frontHair;
		SetLiHuiId(_selectedCategory, _selectedCharIndex, text);
		SetPxId(_selectedCategory, _selectedCharIndex, _expression);
		try
		{
			SaveCategoryData(_selectedCategory);
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"[RanongTextureChanger] Failed to save to ES3: {arg}");
			ShowStatus("Error: Save failed!", isError: true);
			return;
		}
		_originalLiHuiId = text;
		_originalPxId = _expression;
		_hasUnsavedChanges = false;
		RefreshScenePortraits(_selectedCategory, _selectedCharIndex);
		ShowStatus("Changes applied and saved successfully!", isError: false);
	}

	private bool ValidateAsset(string partType, string sex, string ageCategory, string id, out string checkedPath)
	{
		checkedPath = "AllLooks/Member_B/" + sex + "/" + ageCategory + "/" + partType + "/" + id;
		Object val = Resources.Load(checkedPath);
		return val != (Object)null;
	}

	private void RollbackUnsavedChanges()
	{
		if (_hasUnsavedChanges && _lastEditedCharIndex >= 0)
		{
			SetLiHuiId(_lastEditedCategory, _lastEditedCharIndex, _originalLiHuiId);
			SetPxId(_lastEditedCategory, _lastEditedCharIndex, _originalPxId);
			RefreshScenePortraits(_lastEditedCategory, _lastEditedCharIndex);
			_hasUnsavedChanges = false;
			Log.LogInfo((object)$"[RanongTextureChanger] Unsaved changes rolled back for character {_lastEditedCharIndex}.");
		}
	}

	private void RefreshScenePortraits(CharacterCategory category, int charIndex)
	{
		int showId = GetShowId(category);
		string text = charIndex.ToString();
		PerLiHuiBig[] array = Object.FindObjectsOfType<PerLiHuiBig>();
		int num = 0;
		PerLiHuiBig[] array2 = array;
		foreach (PerLiHuiBig val in array2)
		{
			if (val.ShowID == showId && ((Object)val).name == text)
			{
				RefreshBigPortrait(val);
				num++;
			}
		}
		PerLiHuiSmall[] array3 = Object.FindObjectsOfType<PerLiHuiSmall>();
		int num2 = 0;
		PerLiHuiSmall[] array4 = array3;
		foreach (PerLiHuiSmall val2 in array4)
		{
			if (val2.ShowID == showId && ((Object)val2).name == text)
			{
				RefreshSmallPortrait(val2);
				num2++;
			}
		}
		MemberNowInfoPanel val3 = Object.FindObjectOfType<MemberNowInfoPanel>();
		if ((Object)(object)val3 != (Object)null && ((Component)val3).gameObject.activeInHierarchy && Mainload.MemberNowIndex_Enter == charIndex && category == CharacterCategory.ActiveFamily)
		{
			MethodInfo method = typeof(MemberNowInfoPanel).GetMethod("OnEnableData", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method2 = typeof(MemberNowInfoPanel).GetMethod("OnEnableShow", BindingFlags.Instance | BindingFlags.NonPublic);
			method?.Invoke(val3, null);
			method2?.Invoke(val3, null);
		}
	}

	private void RefreshBigPortrait(PerLiHuiBig component)
	{
		for (int num = ((Component)component).transform.childCount - 1; num >= 0; num--)
		{
			Object.Destroy((Object)(object)((Component)((Component)component).transform.GetChild(num)).gameObject);
		}
		MethodInfo method = typeof(PerLiHuiBig).GetMethod("initData", BindingFlags.Instance | BindingFlags.NonPublic);
		MethodInfo method2 = typeof(PerLiHuiBig).GetMethod("initShow", BindingFlags.Instance | BindingFlags.NonPublic);
		method?.Invoke(component, null);
		method2?.Invoke(component, null);
	}

	private void RefreshSmallPortrait(PerLiHuiSmall component)
	{
		for (int num = ((Component)component).transform.childCount - 1; num >= 0; num--)
		{
			Object.Destroy((Object)(object)((Component)((Component)component).transform.GetChild(num)).gameObject);
		}
		MethodInfo method = typeof(PerLiHuiSmall).GetMethod("initData", BindingFlags.Instance | BindingFlags.NonPublic);
		MethodInfo method2 = typeof(PerLiHuiSmall).GetMethod("initShow", BindingFlags.Instance | BindingFlags.NonPublic);
		method?.Invoke(component, null);
		method2?.Invoke(component, null);
	}

	private void CreatePreviewScene()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_previewCanvas != (Object)null)
		{
			return;
		}
		GameObject val = new GameObject("RanongPreviewCanvas");
		_previewCanvas = val.AddComponent<Canvas>();
		_previewCanvas.renderMode = (RenderMode)0;
		_previewCanvas.sortingOrder = 9995;
		val.AddComponent<CanvasScaler>();
		val.AddComponent<GraphicRaycaster>();
		GameObject val2 = new GameObject("Backdrop");
		val2.transform.SetParent(val.transform, false);
		Image val3 = val2.AddComponent<Image>();
		((Graphic)val3).color = new Color(0.04f, 0.04f, 0.04f, 0.78f);
		RectTransform component = ((Component)val3).GetComponent<RectTransform>();
		component.anchorMin = Vector2.zero;
		component.anchorMax = Vector2.one;
		component.sizeDelta = Vector2.zero;
		GameObject val4 = Resources.Load<GameObject>("PerLiHuiBig");
		if ((Object)(object)val4 != (Object)null)
		{
			_previewPortrait = Object.Instantiate<GameObject>(val4, val.transform, false);
			((Object)_previewPortrait).name = "0";
			_previewPortrait.SetActive(false);
			RectTransform component2 = _previewPortrait.GetComponent<RectTransform>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.anchorMin = new Vector2(0.5f, 0.5f);
				component2.anchorMax = new Vector2(0.5f, 0.5f);
				component2.pivot = new Vector2(0.5f, 0.5f);
				component2.anchoredPosition = new Vector2(-20f, -80f);
				((Transform)component2).localScale = new Vector3(2.5f, 2.5f, 1f);
			}
			PerLiHuiBig component3 = _previewPortrait.GetComponent<PerLiHuiBig>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.ShowID = GetShowId(_selectedCategory);
				component3.isShowInfo = false;
			}
		}
	}

	private void UpdatePreviewPortrait()
	{
		if ((Object)(object)_previewPortrait == (Object)null)
		{
			return;
		}
		if (_selectedCharIndex < 0)
		{
			_previewPortrait.SetActive(false);
			return;
		}
		_previewPortrait.SetActive(true);
		((Object)_previewPortrait).name = _selectedCharIndex.ToString();
		PerLiHuiBig component = _previewPortrait.GetComponent<PerLiHuiBig>();
		if ((Object)(object)component != (Object)null)
		{
			component.ShowID = GetShowId(_selectedCategory);
		}
		RefreshBigPortrait(component);
	}

	private void DestroyPreviewScene()
	{
		if ((Object)(object)_previewCanvas != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_previewCanvas).gameObject);
			_previewCanvas = null;
		}
		_previewPortrait = null;
	}

	private void OnDestroy()
	{
		RollbackUnsavedChanges();
		DestroyPreviewScene();
	}

	private static int GetCount(CharacterCategory category)
	{
		if (Mainload.Member_now == null)
		{
			return 0;
		}
		return category switch
		{
			CharacterCategory.ActiveFamily => Mainload.Member_now.Count, 
			CharacterCategory.SpousesRetired => (Mainload.Member_qu != null) ? Mainload.Member_qu.Count : 0, 
			CharacterCategory.Retainers => (Mainload.MenKe_Now != null) ? Mainload.MenKe_Now.Count : 0, 
			_ => 0, 
		};
	}

	private static string GetName(CharacterCategory category, int charIndex)
	{
		return category switch
		{
			CharacterCategory.ActiveFamily => Mainload.Member_now[charIndex][4].Split(new char[1] { '|' })[0], 
			CharacterCategory.SpousesRetired => Mainload.Member_qu[charIndex][2].Split(new char[1] { '|' })[0], 
			CharacterCategory.Retainers => Mainload.MenKe_Now[charIndex][2].Split(new char[1] { '|' })[0], 
			_ => "", 
		};
	}

	private static string GetSex(CharacterCategory category, int charIndex)
	{
		return category switch
		{
			CharacterCategory.ActiveFamily => Mainload.Member_now[charIndex][4].Split(new char[1] { '|' })[4], 
			CharacterCategory.SpousesRetired => Mainload.Member_qu[charIndex][2].Split(new char[1] { '|' })[4], 
			CharacterCategory.Retainers => Mainload.MenKe_Now[charIndex][2].Split(new char[1] { '|' })[4], 
			_ => "0", 
		};
	}

	private static int GetAge(CharacterCategory category, int charIndex)
	{
		return category switch
		{
			CharacterCategory.ActiveFamily => int.Parse(Mainload.Member_now[charIndex][6]), 
			CharacterCategory.SpousesRetired => int.Parse(Mainload.Member_qu[charIndex][5]), 
			CharacterCategory.Retainers => int.Parse(Mainload.MenKe_Now[charIndex][3]), 
			_ => 0, 
		};
	}

	private static string GetLiHuiId(CharacterCategory category, int charIndex)
	{
		return category switch
		{
			CharacterCategory.ActiveFamily => Mainload.Member_now[charIndex][1], 
			CharacterCategory.SpousesRetired => Mainload.Member_qu[charIndex][1], 
			CharacterCategory.Retainers => Mainload.MenKe_Now[charIndex][1], 
			_ => "", 
		};
	}

	private static void SetLiHuiId(CharacterCategory category, int charIndex, string value)
	{
		switch (category)
		{
		case CharacterCategory.ActiveFamily:
			Mainload.Member_now[charIndex][1] = value;
			break;
		case CharacterCategory.SpousesRetired:
			Mainload.Member_qu[charIndex][1] = value;
			break;
		case CharacterCategory.Retainers:
			Mainload.MenKe_Now[charIndex][1] = value;
			break;
		}
	}

	private static string GetPxId(CharacterCategory category, int charIndex)
	{
		return category switch
		{
			CharacterCategory.ActiveFamily => Mainload.Member_now[charIndex][5], 
			CharacterCategory.SpousesRetired => Mainload.Member_qu[charIndex][2].Split(new char[1] { '|' })[8], 
			CharacterCategory.Retainers => Mainload.MenKe_Now[charIndex][2].Split(new char[1] { '|' })[8], 
			_ => "", 
		};
	}

	private static void SetPxId(CharacterCategory category, int charIndex, string value)
	{
		switch (category)
		{
		case CharacterCategory.ActiveFamily:
			Mainload.Member_now[charIndex][5] = value;
			break;
		case CharacterCategory.SpousesRetired:
		{
			string[] array2 = Mainload.Member_qu[charIndex][2].Split(new char[1] { '|' });
			if (array2.Length > 8)
			{
				array2[8] = value;
				Mainload.Member_qu[charIndex][2] = string.Join("|", array2);
			}
			break;
		}
		case CharacterCategory.Retainers:
		{
			string[] array = Mainload.MenKe_Now[charIndex][2].Split(new char[1] { '|' });
			if (array.Length > 8)
			{
				array[8] = value;
				Mainload.MenKe_Now[charIndex][2] = string.Join("|", array);
			}
			break;
		}
		}
	}

	private static int GetShowId(CharacterCategory category)
	{
		return category switch
		{
			CharacterCategory.ActiveFamily => 0, 
			CharacterCategory.SpousesRetired => 3, 
			CharacterCategory.Retainers => 4, 
			_ => 0, 
		};
	}

	private static void SaveCategoryData(CharacterCategory category)
	{
		string text = Mainload.CunDangIndex_now + "/GameData.es3";
		switch (category)
		{
		case CharacterCategory.ActiveFamily:
			ES3.Save<List<List<string>>>("Member_now", (object)Mainload.Member_now, text);
			break;
		case CharacterCategory.SpousesRetired:
			ES3.Save<List<List<string>>>("Member_qu", (object)Mainload.Member_qu, text);
			break;
		case CharacterCategory.Retainers:
			ES3.Save<List<List<string>>>("MenKe_Now", (object)Mainload.MenKe_Now, text);
			break;
		}
	}

	private static void GetAgeCategories(int age, out string hf, out string shen, out string tou, out string px, out string qf)
	{
		List<int> oldFenjie = Mainload.OldFenjie;
		int num = 14;
		int num2 = 30;
		int num3 = 60;
		if (oldFenjie != null && oldFenjie.Count >= 3)
		{
			num = oldFenjie[0];
			num2 = oldFenjie[1];
			num3 = oldFenjie[2];
		}
		if (age < num)
		{
			hf = (shen = (tou = (px = (qf = "0"))));
			return;
		}
		if (age >= num && age < num2)
		{
			hf = (shen = (tou = (px = (qf = "1"))));
			return;
		}
		if (age >= num2 && age < num3)
		{
			hf = (shen = (tou = (px = (qf = "2"))));
			return;
		}
		hf = "3";
		shen = "2";
		tou = "2";
		px = "2";
		qf = "3";
	}

	private void ShowStatus(string msg, bool isError)
	{
		_statusMessage = msg;
		_statusTime = Time.time + 5f;
		_isErrorStatus = isError;
	}
}