Decompiled source of LiHuiCreateMod v1.3.0

AppearanceCreateMod.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AppearanceCreateMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AppearanceCreateMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0f56db03-b2c6-4c09-94c2-18c1342195da")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AppearanceCreateMod;

[BepInPlugin("cs.iccth.HoL.AppearanceCreateMod", "AppearanceCreateMod", "1.3.0")]
public class AppearanceCreateMod : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private static ConfigEntry<string> femaleBackHairOptions;

	private static ConfigEntry<string> femaleBodyOptions;

	private static ConfigEntry<string> femaleFaceOptions;

	private static ConfigEntry<string> femaleFrontHairOptions;

	private static ConfigEntry<string> femalePersonalitysOptions;

	private static ConfigEntry<string> maleBackHairOptions;

	private static ConfigEntry<string> maleBodyOptions;

	private static ConfigEntry<string> maleFaceOptions;

	private static ConfigEntry<string> maleFrontHairOptions;

	private static ConfigEntry<string> malePersonalitysOptions;

	private static ConfigEntry<bool> enableNewMemberNowRoyalOutfits;

	private static ConfigEntry<bool> enableNewMemberOtherOption;

	private static ConfigEntry<bool> enableNewMemberOtherDebug;

	private static ConfigEntry<bool> enableNewMemberOtherRoyalOutfits;

	private static ConfigEntry<bool> enableNewMemberHanMenOption;

	private static ConfigEntry<bool> enableNewMemberHanMenDebug;

	private static ConfigEntry<bool> enableNewMemberHanMenRoyalOutfits;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		femaleBackHairOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "女性后发(female Back Hair)", "0 1 2 7 11 13 16 18 19", "自定义女性后发ID列表,用空格分隔。");
		femaleBodyOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "女性身体(female Body)", "0 1 4 5 6 7 8 9 10 11 12 13 14 15 18 19 21 22 23 27 28 30 31 32 33 34 35 36 37 38 39 40 41 46 47", "自定义女性身体ID列表,用空格分隔。");
		femaleFaceOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "女性脸型(female Face)", "0 2", "自定义女性脸型ID列表,用空格分隔。");
		femaleFrontHairOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "女性前发(female Front Hair)", "0 5 7 12 16", "自定义女性前发ID列表,用空格分隔。");
		femalePersonalitysOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "女性品性(female Eyes)", "1 2 3 4 5 6 9 11 12 14", "自定义女性品性(眼睛)列表,用空格分隔。\n1-骄傲 2-刚正 3-活泼 4-善良 5-真诚 6-洒脱 7-高冷 8-自卑 9-怯懦 10-腼腆 11-凶狠 12-善变 13-忧郁 14-多疑\n1-Proud 2-Righteous 3-Lively 4-Kind 5-Honest 6-Carefree 7-Cold 8-Insecure 9-Timid 10-Shy 11-Mean 12-Fickle 13-Gloomy 14-Paranoid");
		maleBackHairOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "男性后发(male Back Hair)", "1 2 3 7 8 9 12 14 17 18", "自定义男性后发ID列表,用空格分隔。");
		maleBodyOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "男性身体(male Body)", "0 1 2 3 5 6 7 8 12 13 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 40 41 45 46 47", "自定义男性身体ID列表,用空格分隔。");
		maleFaceOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "男性脸型(male Face)", "0 1 2", "自定义男性脸型ID列表,用空格分隔。");
		maleFrontHairOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "男性前发(male Front Hair)", "6 7 11 12 13 14 16 17 18 19", "自定义男性前发ID列表,用空格分隔。");
		malePersonalitysOptions = ((BaseUnityPlugin)this).Config.Bind<string>("自定义NPC外观生成 (Customize Appearance)", "男性品性(male Eyes)", "1 2 4 5 6 7 11 12 14", "自定义男性品性(眼睛)列表,用空格分隔。\n1-骄傲 2-刚正 3-活泼 4-善良 5-真诚 6-洒脱 7-高冷 8-自卑 9-怯懦 10-腼腆 11-凶狠 12-善变 13-忧郁 14-多疑\n1-Proud 2-Righteous 3-Lively 4-Kind 5-Honest 6-Carefree 7-Cold 8-Insecure 9-Timid 10-Shy 11-Mean 12-Fickle 13-Gloomy 14-Paranoid");
		enableNewMemberNowRoyalOutfits = ((BaseUnityPlugin)this).Config.Bind<bool>("自定义NPC外观生成 (Customize Appearance)", "是否在启用本家族子女生成皇室服装 (Enable royal outfits for new member in other clan)", true, "关闭后,即便自定义身体ID列表包含30到49之间的皇室服装ID,本家族新成员也不会生成皇室服装");
		enableNewMemberOtherOption = ((BaseUnityPlugin)this).Config.Bind<bool>("自定义NPC外观生成 (Customize Appearance)", "是否对其他世家新诞生角色生效 (Enable customize appearance for other clan)", true, "启用后,其他世家的新生成员外观也将根据自定义外观列表生成");
		enableNewMemberOtherDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("自定义NPC外观生成 (Customize Appearance)", "是否在控制台输出其他世家新NPC信息 (Enable new member information log in console for other clan)", false, "启用后,在控制台显示其他世家新成员数据信息(非常频繁,建议关闭)");
		enableNewMemberOtherRoyalOutfits = ((BaseUnityPlugin)this).Config.Bind<bool>("自定义NPC外观生成 (Customize Appearance)", "是否在启用其他世家子女生成皇室服装 (Enable royal outfits for new member in other clan)", true, "关闭后,即便自定义身体ID列表包含30到49之间的皇室服装ID,其他世家新成员也不会生成皇室服装");
		enableNewMemberHanMenOption = ((BaseUnityPlugin)this).Config.Bind<bool>("自定义NPC外观生成 (Customize Appearance)", "是否对郡城寒门子弟生效 (Enable customize appearance for civilian)", true, "启用后,郡城寒门子弟外观也将根据自定义外观列表生成");
		enableNewMemberHanMenDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("自定义NPC外观生成 (Customize Appearance)", "是否在控制台输出郡城寒门子弟信息 (Enable new member information log in console for civilian)", false, "启用后,在控制台显示郡城寒门子弟数据信息(非常频繁,建议关闭)");
		enableNewMemberHanMenRoyalOutfits = ((BaseUnityPlugin)this).Config.Bind<bool>("自定义NPC外观生成 (Customize Appearance)", "是否在启用郡城寒门子弟生成皇室服装 (Enable royal outfits for civilian)", false, "关闭后,即便自定义身体ID列表包含30到49之间的皇室服装ID,郡城寒门子弟也不会生成皇室服装");
		Harmony.CreateAndPatchAll(typeof(AppearanceCreateMod), (string)null);
		Log.LogInfo((object)"自定义立绘模组加载成功!");
	}

	public static string GenerateCustomLiHui(int sex, bool enableRoyalOutfits = true)
	{
		string value;
		string value2;
		string value3;
		string value4;
		if (sex == 0)
		{
			value = femaleBackHairOptions.Value;
			value2 = femaleBodyOptions.Value;
			value3 = femaleFaceOptions.Value;
			value4 = femaleFrontHairOptions.Value;
		}
		else
		{
			value = maleBackHairOptions.Value;
			value2 = maleBodyOptions.Value;
			value3 = maleFaceOptions.Value;
			value4 = maleFrontHairOptions.Value;
		}
		try
		{
			int[] array = Array.ConvertAll(value.Split(new char[1] { ' ' }), int.Parse);
			int[] array2 = Array.ConvertAll(value2.Split(new char[1] { ' ' }), int.Parse);
			if (!enableRoyalOutfits)
			{
				array2 = array2.Where((int id) => id < 30).ToArray();
			}
			int[] array3 = Array.ConvertAll(value3.Split(new char[1] { ' ' }), int.Parse);
			int[] array4 = Array.ConvertAll(value4.Split(new char[1] { ' ' }), int.Parse);
			int num = array[TrueRandom.GetRanom(array.Length)];
			int num2 = array2[TrueRandom.GetRanom(array2.Length)];
			int num3 = array3[TrueRandom.GetRanom(array3.Length)];
			int num4 = array4[TrueRandom.GetRanom(array4.Length)];
			return $"{num}|{num2}|{num3}|{num4}";
		}
		catch (Exception ex)
		{
			Log.LogError((object)("解析外观配置时出错: " + ex.Message + "。请检查配置文件中的ID是否为纯数字且用空格分隔。"));
			return null;
		}
	}

	public static string GeneratePersonality(int sex)
	{
		string text = ((sex != 0) ? malePersonalitysOptions.Value : femalePersonalitysOptions.Value);
		try
		{
			string[] array = text.Split(new char[1] { ' ' });
			int ranom = TrueRandom.GetRanom(array.Length);
			string text2 = array[ranom];
			if (int.TryParse(text2, out var result) && result >= 1 && result <= 14)
			{
				return text2;
			}
			int num = TrueRandom.GetRanom(15);
			if (num == 0)
			{
				num = 1;
			}
			string text3 = num.ToString();
			Log.LogError((object)("解析品性配置时出错: 自定义品性列表中存在无效品性ID \"" + text2 + "\",请检查配置文件中的自定义品性列表,当前使用默认随机品性\"" + text3 + "\"。"));
			return text3;
		}
		catch (Exception ex)
		{
			Log.LogError((object)("解析品性配置时出错: " + ex.Message + "。请检查配置文件中的品性ID格式。"));
			return null;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(FormulaData), "New_MemberNow")]
	public static void New_MemberNow_Postfix()
	{
		try
		{
			if (Mainload.Member_now.Count != 0)
			{
				int index = Mainload.Member_now.Count - 1;
				List<string> list = Mainload.Member_now[index];
				string text = list[4];
				string[] array = text.Split(new char[1] { '|' });
				int num = int.Parse(array[4]);
				string text2 = GenerateCustomLiHui(num, enableNewMemberNowRoyalOutfits.Value);
				string text3 = GeneratePersonality(num);
				if (text2 != null && text3 != null)
				{
					list[1] = text2;
					list[5] = text3;
					Mainload.Member_now[index] = list;
					Log.LogInfo((object)"【家族出现新成员】");
					Log.LogInfo((object)$"根据性别ID\"{num}\"从自定义外观配置中生成随机立绘组合: \"{text2}\" (后发|身体|脸型|前发)");
					Log.LogInfo((object)("生成随机品性ID: \"" + text3 + "\""));
					Log.LogInfo((object)("该成员替换外观后的数据字符串为: \"" + string.Join("|", list) + "\""));
				}
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("处理New_MemberNow后置补丁时发生错误: " + ex.Message + "\n堆栈跟踪: " + ex.StackTrace));
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(FormulaData), "New_MemberOther", new Type[]
	{
		typeof(int),
		typeof(int),
		typeof(string),
		typeof(string),
		typeof(string),
		typeof(bool)
	})]
	public static void New_MemberOther_Postfix(int shijiaIndex)
	{
		if (!enableNewMemberOtherOption.Value)
		{
			return;
		}
		try
		{
			if (shijiaIndex < 0 || shijiaIndex >= Mainload.Member_other.Count || Mainload.Member_other[shijiaIndex].Count == 0)
			{
				return;
			}
			int index = Mainload.Member_other[shijiaIndex].Count - 1;
			List<string> list = Mainload.Member_other[shijiaIndex][index];
			string text = list[2];
			string[] array = text.Split(new char[1] { '|' });
			int num = int.Parse(array[4]);
			string text2 = GenerateCustomLiHui(num, enableNewMemberOtherRoyalOutfits.Value);
			string text3 = GeneratePersonality(num);
			if (text2 != null && text3 != null)
			{
				list[1] = text2;
				string text4 = list[2];
				string[] array2 = text4.Split(new char[1] { '|' });
				array2[8] = text3;
				list[2] = string.Join("|", array2);
				Mainload.Member_other[shijiaIndex][index] = list;
				if (enableNewMemberOtherDebug.Value)
				{
					Log.LogInfo((object)"【检测到世家新成员生成】");
					Log.LogInfo((object)$"根据性别ID\"{num}\"从自定义外观配置中生成随机立绘组合: \"{text2}\" (后发|身体|脸型|前发)");
					Log.LogInfo((object)("生成随机品性ID: \"" + text3 + "\""));
					Log.LogInfo((object)("该成员替换外观后的数据字符串为: \"" + string.Join("|", list) + "\""));
				}
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("处理New_MemberOther后置补丁时发生错误: " + ex.Message + "\n堆栈跟踪: " + ex.StackTrace));
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(FormulaData), "CreatHanMenMemberData", new Type[]
	{
		typeof(string),
		typeof(string),
		typeof(int)
	})]
	public static void CreatHanMenMemberData_Postfix(string SexID, ref List<string> __result)
	{
		if (!enableNewMemberHanMenOption.Value)
		{
			return;
		}
		try
		{
			if (__result == null || __result.Count < 3)
			{
				return;
			}
			List<string> list = __result;
			int num = int.Parse(SexID);
			string text = GenerateCustomLiHui(num, enableNewMemberHanMenRoyalOutfits.Value);
			string text2 = GeneratePersonality(num);
			if (text != null && text2 != null)
			{
				list[1] = text;
				string text3 = list[2];
				string[] array = text3.Split(new char[1] { '|' });
				array[8] = text2;
				list[2] = string.Join("|", array);
				__result = list;
				if (enableNewMemberHanMenDebug.Value)
				{
					Log.LogInfo((object)"【检测到郡城寒门子弟生成】");
					Log.LogInfo((object)$"根据性别ID\"{num}\"从自定义外观配置中生成随机立绘组合: \"{text}\" (后发|身体|脸型|前发)");
					Log.LogInfo((object)("生成随机品性ID: \"" + text2 + "\""));
					Log.LogInfo((object)("该成员替换外观后的数据字符串为: \"" + string.Join("|", list) + "\""));
				}
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("处理Member_Hanmen后置补丁时发生错误: " + ex.Message + "\n堆栈跟踪: " + ex.StackTrace));
		}
	}
}