Decompiled source of MorePopulation v1.4.0

BepInEx/plugins/cs.HoLMod.MorePopulation.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("cs.HoLMod.MorePopulation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("cs.HoLMod.MorePopulation")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d1e8ebb6-3e94-4ac1-a0a1-bcbc5bdc0ff2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7", FrameworkDisplayName = ".NET Framework 4.7")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace cs.HoLMod.MorePopulation;

public static class PluginInfo
{
	public const string PLUGIN_GUID = "cs.HoLMod.MorePopulation.AnZhi20";

	public const string PLUGIN_NAME = "HoLMod.MorePopulation";

	public const string PLUGIN_VERSION = "1.4.0";
}
[BepInPlugin("cs.HoLMod.MorePopulation.AnZhi20", "HoLMod.MorePopulation", "1.4.0")]
public class Main : BaseUnityPlugin
{
	public static int PopulationCheatRate;

	public static float PopulationCorrectionRate;

	private int lastCorrectionYearMonth = 0;

	public static Main Instance { get; private set; }

	public static ManualLogSource Log
	{
		get
		{
			Main instance = Instance;
			return (instance != null) ? ((BaseUnityPlugin)instance).Logger : null;
		}
	}

	private void Awake()
	{
		Instance = this;
		PopulationCheatRate = ((BaseUnityPlugin)this).Config.Bind<int>("倍率调整(Adjustment)", "自然增加人口修正(Population Correction)", 1, "每月自然增加人口修正倍数,填1为默认修正值。(Monthly natural population growth correction factor, set to 1 for default value).").Value;
	}

	private void Update()
	{
		HandlePopulationCorrection();
	}

	private void HandlePopulationCorrection()
	{
		try
		{
			if ((Object)(object)Instance == (Object)null)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogWarning((object)"Main.Instance为null,无法执行人口修正");
				}
				return;
			}
			if (string.IsNullOrEmpty(Mainload.SceneID))
			{
				ManualLogSource log2 = Log;
				if (log2 != null)
				{
					log2.LogWarning((object)"Mainload.SceneID为空,无法确定当前场景");
				}
				return;
			}
			string[] array = Mainload.SceneID.Split(new char[1] { '|' });
			string text = array[0];
			if (text != "M" && text != "Z" && text != "S" && text != "H" && text != "F")
			{
				ManualLogSource log3 = Log;
				if (log3 != null)
				{
					log3.LogWarning((object)("当前场景类型[" + text + "]不是有效游戏场景,无法执行人口修正"));
				}
				return;
			}
			int num = Mainload.Time_now[0];
			int num2 = Mainload.Time_now[1];
			int num3 = Mainload.Time_now[2];
			switch (num)
			{
			case 1:
				PopulationCorrectionRate = 0.1f;
				break;
			case 2:
				PopulationCorrectionRate = 0.2f;
				break;
			case 3:
				PopulationCorrectionRate = 0.3f;
				break;
			case 4:
				PopulationCorrectionRate = 0.4f;
				break;
			case 5:
				PopulationCorrectionRate = 0.5f;
				break;
			case 6:
				PopulationCorrectionRate = 0.6f;
				break;
			case 7:
				PopulationCorrectionRate = 0.7f;
				break;
			case 8:
				PopulationCorrectionRate = 0.8f;
				break;
			case 9:
				PopulationCorrectionRate = 0.9f;
				break;
			case 10:
				PopulationCorrectionRate = 1f;
				break;
			case 11:
				PopulationCorrectionRate = 1.2f;
				break;
			case 12:
				PopulationCorrectionRate = 1.4f;
				break;
			case 13:
				PopulationCorrectionRate = 1.6f;
				break;
			case 14:
				PopulationCorrectionRate = 1.8f;
				break;
			case 15:
				PopulationCorrectionRate = 2f;
				break;
			case 16:
				PopulationCorrectionRate = 2.2f;
				break;
			case 17:
				PopulationCorrectionRate = 2.4f;
				break;
			case 18:
				PopulationCorrectionRate = 2.6f;
				break;
			case 19:
				PopulationCorrectionRate = 2.8f;
				break;
			case 20:
				PopulationCorrectionRate = 3f;
				break;
			default:
				PopulationCorrectionRate = 4f;
				break;
			}
			if (num3 != 1)
			{
				return;
			}
			int num4 = num * 100 + num2;
			if (num4 != lastCorrectionYearMonth)
			{
				PluginCommonInfo.PopulationCorrectionRate = (int)PopulationCorrectionRate;
				PluginCommonInfo.PopulationCheatRate = PopulationCheatRate;
				CorrectPopulation();
				ManualLogSource log4 = Log;
				if (log4 != null)
				{
					log4.LogInfo((object)$"已修正{num}年{num2}月的人口,修正倍率为{PopulationCheatRate},修正比例为{PopulationCorrectionRate}");
				}
				lastCorrectionYearMonth = num4;
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log5 = Log;
			if (log5 != null)
			{
				log5.LogError((object)("处理人口修正时发生错误:" + ex.Message));
			}
		}
	}

	public void CorrectPopulation()
	{
		for (int i = 0; i < 12; i++)
		{
			string s = Mainload.CityData_now[i][0][7];
			int num = (int)((float)int.Parse(s) + 300f * PopulationCorrectionRate * (float)PopulationCheatRate);
			int num2 = num - int.Parse(s);
			Mainload.CityData_now[i][0][7] = num.ToString();
			s = "";
			ManualLogSource log = Log;
			if (log != null)
			{
				log.LogInfo((object)$"已修正{PluginCommonInfo.JunList[i]}的人口,修正值为{num2},修正后人口为{num}");
			}
		}
		for (int j = 0; j < 12; j++)
		{
			int num3 = PluginCommonInfo.XianList[j].Length;
			for (int k = 0; k < num3; k++)
			{
				string s2 = Mainload.CityData_now[j][k + 1][3];
				int num4 = (int)((float)int.Parse(s2) + 100f * PopulationCorrectionRate * (float)PopulationCheatRate);
				int num5 = num4 - int.Parse(s2);
				Mainload.CityData_now[j][k + 1][3] = num4.ToString();
				s2 = "";
				ManualLogSource log2 = Log;
				if (log2 != null)
				{
					log2.LogInfo((object)$"已修正{PluginCommonInfo.XianList[j][k]}的人口,修正值为{num5},修正后人口为{num4}");
				}
			}
		}
	}
}
public static class PluginCommonInfo
{
	public const int PopulationCorrection = 100;

	public static int PopulationCorrectionRate;

	public static int PopulationCheatRate;

	public static string[] JunList = new string[12]
	{
		"南郡", "三川郡", "蜀郡", "丹阳郡", "陈留郡", "长沙郡", "会稽郡", "广陵郡", "太原郡", "益州郡",
		"南海郡", "云南郡"
	};

	public static string[][] XianList = new string[12][]
	{
		new string[8] { "临沮", "襄樊", "宜城", "麦城", "华容", "郢亭", "江陵", "夷陵" },
		new string[6] { "平阳", "荥阳", "原武", "阳武", "新郑", "宜阳" },
		new string[6] { "邛崃", "郫县", "什邡", "绵竹", "新都", "成都" },
		new string[6] { "秣陵", "江乘", "江宁", "溧阳", "建邺", "永世" },
		new string[6] { "长垣", "济阳", "成武", "襄邑", "宁陵", "封丘" },
		new string[8] { "零陵", "益阳", "湘县", "袁州", "庐陵", "衡山", "建宁", "桂阳" },
		new string[4] { "曲阿", "松江", "山阴", "余暨" },
		new string[4] { "平安", "射阳", "海陵", "江都" },
		new string[8] { "大陵", "晋阳", "九原", "石城", "阳曲", "魏榆", "孟县", "中都" },
		new string[8] { "连然", "谷昌", "同劳", "昆泽", "滇池", "俞元", "胜休", "南安" },
		new string[6] { "四会", "阳山", "龙川", "揭岭", "罗阳", "善禺" },
		new string[8] { "云平", "叶榆", "永宁", "遂久", "姑复", "蜻陵", "弄栋", "邪龙" }
	};
}
[HarmonyPatch(typeof(SaveData))]
[HarmonyPatch("ReadGameData")]
public static class SaveDataReadGameDataPatch
{
	private static void Postfix()
	{
		try
		{
			int num = Mainload.Time_now[0];
			int num2 = Mainload.Time_now[1];
			float num3 = 4f;
			switch (num)
			{
			case 1:
				num3 = 0.1f;
				break;
			case 2:
				num3 = 0.2f;
				break;
			case 3:
				num3 = 0.3f;
				break;
			case 4:
				num3 = 0.4f;
				break;
			case 5:
				num3 = 0.5f;
				break;
			case 6:
				num3 = 0.6f;
				break;
			case 7:
				num3 = 0.7f;
				break;
			case 8:
				num3 = 0.8f;
				break;
			case 9:
				num3 = 0.9f;
				break;
			case 10:
				num3 = 1f;
				break;
			case 11:
				num3 = 1.2f;
				break;
			case 12:
				num3 = 1.4f;
				break;
			case 13:
				num3 = 1.6f;
				break;
			case 14:
				num3 = 1.8f;
				break;
			case 15:
				num3 = 2f;
				break;
			case 16:
				num3 = 2.2f;
				break;
			case 17:
				num3 = 2.4f;
				break;
			case 18:
				num3 = 2.6f;
				break;
			case 19:
				num3 = 2.8f;
				break;
			case 20:
				num3 = 3f;
				break;
			}
			if ((Object)(object)Main.Instance != (Object)null)
			{
				Main.PopulationCorrectionRate = num3;
				PluginCommonInfo.PopulationCorrectionRate = (int)num3;
				PluginCommonInfo.PopulationCheatRate = Main.PopulationCheatRate;
				ManualLogSource log = Main.Log;
				if (log != null)
				{
					log.LogInfo((object)$"加载存档后修正人口,当前年份:{num}年{num2}月,修正倍率:{Main.PopulationCheatRate},修正比例:{num3}");
				}
				Main.Instance.CorrectPopulation();
			}
		}
		catch (Exception ex)
		{
			if (Main.Log != null)
			{
				ManualLogSource log2 = Main.Log;
				if (log2 != null)
				{
					log2.LogError((object)("读取存档数据后修正人口时发生错误:" + ex.Message));
				}
			}
		}
	}
}