Decompiled source of LiHuiCreateMod v1.0.0

LiHuiCreateMod.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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("LiHuiCreateMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LiHuiCreateMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("db995b74-f103-49e8-be5d-e00f7b764f30")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LiHuiCreateMod;

[BepInPlugin("cs.iccth.HoL.LiHuiCreateMod", "LiHuiCreateMod", "1.0.0")]
public class LiHuiCreateMod : 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> femaleEyesOptions;

	private static ConfigEntry<string> maleBackHairOptions;

	private static ConfigEntry<string> maleBodyOptions;

	private static ConfigEntry<string> maleFaceOptions;

	private static ConfigEntry<string> maleFrontHairOptions;

	private static ConfigEntry<string> maleEyesOptions;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		femaleBackHairOptions = ((BaseUnityPlugin)this).Config.Bind<string>("女性外观配置 (Female Appearance)", "后发 (Back Hair)", "0 1 2 7 11 13 16 18", "自定义女性后发ID列表,用空格分隔。");
		femaleBodyOptions = ((BaseUnityPlugin)this).Config.Bind<string>("女性外观配置 (Female Appearance)", "身体 (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>("女性外观配置 (Female Appearance)", "脸型 (Face)", "2", "自定义女性脸型ID列表,用空格分隔。");
		femaleFrontHairOptions = ((BaseUnityPlugin)this).Config.Bind<string>("女性外观配置 (Female Appearance)", "前发 (Front Hair)", "0 5 12 16", "自定义女性前发ID列表,用空格分隔。");
		femaleEyesOptions = ((BaseUnityPlugin)this).Config.Bind<string>("女性外观配置 (Female Appearance)", "品性 (Eyes)", "骄傲 刚正 活泼 善良 真诚 洒脱 高冷 自卑 怯懦 腼腆 凶狠 善变 忧郁 多疑", "自定义女性品性列表,用空格分隔。");
		maleBackHairOptions = ((BaseUnityPlugin)this).Config.Bind<string>("男性外观配置 (Male Appearance)", "后发 (Back Hair)", "1 2 3 7 9 12 14 17", "自定义男性后发ID列表,用空格分隔。");
		maleBodyOptions = ((BaseUnityPlugin)this).Config.Bind<string>("男性外观配置 (Male Appearance)", "身体 (Body)", "0 1 2 3 5 6 7 8 12 13 17 18 19 20 21 22 23 24 25 26 27 28 29", "自定义男性身体ID列表,用空格分隔。");
		maleFaceOptions = ((BaseUnityPlugin)this).Config.Bind<string>("男性外观配置 (Male Appearance)", "脸型 (Face)", "0 1 2", "自定义男性脸型ID列表,用空格分隔。");
		maleFrontHairOptions = ((BaseUnityPlugin)this).Config.Bind<string>("男性外观配置 (Male Appearance)", "前发 (Front Hair)", "6 7 12 13 14 16 17 18 19", "自定义男性前发ID列表,用空格分隔。");
		maleEyesOptions = ((BaseUnityPlugin)this).Config.Bind<string>("男性外观配置 (Female Appearance)", "品性 (Eyes)", "骄傲 刚正 活泼 善良 真诚 洒脱 高冷 自卑 怯懦 腼腆 凶狠 善变 忧郁 多疑", "自定义男性品性列表,用空格分隔。");
		Harmony.CreateAndPatchAll(typeof(LiHuiCreateMod), (string)null);
		Log.LogInfo((object)"自定义立绘模组加载成功!");
	}

	public static string GenerateCustomLiHui(int sex)
	{
		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);
			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)];
			Log.LogInfo((object)($"性别: {sex}, " + "立绘组合:" + $"后发: {num}, " + $"身体: {num2}, " + $"脸型: {num3}, " + $"前发: {num4}"));
			return $"{num}|{num2}|{num3}|{num4}";
		}
		catch (Exception ex)
		{
			Log.LogError((object)("解析外观配置时出错: " + ex.Message + "。请检查配置文件中的ID是否为纯数字且用空格分隔。"));
			return null;
		}
	}

	public static string GenerateEye(int sex)
	{
		string text = ((sex != 0) ? maleEyesOptions.Value : femaleEyesOptions.Value);
		try
		{
			string[] array = text.Split(new char[1] { ' ' });
			int ranom = TrueRandom.GetRanom(array.Length);
			string text2 = array[ranom];
			string text3 = "不明 骄傲 刚正 活泼 善良 真诚 洒脱 高冷 自卑 怯懦 腼腆 凶狠 善变 忧郁 多疑";
			string[] array2 = text3.Split(new char[1] { ' ' });
			int num = Array.IndexOf(array2, text2);
			if (num != -1)
			{
				Log.LogInfo((object)$"从自定义品性列表中生成随机品性:“{text2}” 品性ID: {num}");
				return num.ToString();
			}
			Log.LogError((object)("解析品性配置时出错: 官方品性列表中不存在 “" + text2 + "”,请检查配置文件中的自定义品性列表,当前自动设置为“骄傲”品性。"));
			return "骄傲";
		}
		catch (Exception ex)
		{
			Log.LogError((object)("解析品性配置时出错: " + ex.Message + "。请检查配置文件中的品性是否用空格分隔。"));
			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 sex = int.Parse(array[4]);
				string text2 = GenerateCustomLiHui(sex);
				string text3 = GenerateEye(sex);
				if (text2 != null && text3 != null)
				{
					list[1] = text2;
					list[5] = text3;
					Mainload.Member_now[index] = list;
					Log.LogInfo((object)("新家族成员替换立绘后的数据字符串: " + string.Join("|", list)));
				}
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("处理New_MemberNow后置补丁时发生错误: " + ex.Message + "\n堆栈跟踪: " + ex.StackTrace));
		}
	}
}