Decompiled source of BlackBox cn v1.0.5

Blackboxcn.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
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("blackboxcn")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("blackboxcn")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("230de607-2e44-411d-9009-eb84a7543d63")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("BlackBox.Chinese.Patch", "BlackBox Chinese Patch", "1.0.5")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BlackBoxChinesePatch : BaseUnityPlugin
{
	private static readonly Dictionary<string, string> DefaultTextMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
	{
		["DAMAGE DONE TO ITEMS"] = "搞破坏排行榜(疯狂指责)",
		["DESTROYED"] = "被打碎",
		["TOTAL"] = "总计",
		["LEFT"] = "剩余",
		["UNKNOWN"] = "未知",
		["EXTRACTED"] = "已提取",
		["ITEM(S)"] = " 件",
		["LOST"] = "损失",
		["IN VALUE WITH"] = "金钱,其中",
		["DISCOVERED"] = "已发现贵重品",
		["OUT OF"] = "件,总计"
	};

	private static Dictionary<string, string> TextMap;

	public static string ConfigPath => Paths.ConfigPath;

	private void Awake()
	{
		if (InitializeHarmonyPatch())
		{
			InitializeTextMap();
		}
	}

	private void InitializeTextMap()
	{
		TextMap = new Dictionary<string, string>(DefaultTextMap, StringComparer.OrdinalIgnoreCase);
		string path = Path.Combine(ConfigPath, "Translation", "TooRed.txt");
		if (!File.Exists(path))
		{
			return;
		}
		try
		{
			int num = 0;
			string[] array = File.ReadAllLines(path);
			foreach (string text in array)
			{
				if (string.IsNullOrWhiteSpace(text) || text.TrimStart(Array.Empty<char>()).StartsWith("#"))
				{
					continue;
				}
				int num2 = text.IndexOf('=');
				if (num2 > 0 && num2 < text.Length - 1)
				{
					string text2 = text.Substring(0, num2).Trim();
					string value = text.Substring(num2 + 1).Trim();
					if (!string.IsNullOrEmpty(text2) && !TextMap.ContainsKey(text2))
					{
						TextMap.Add(text2, value);
						num++;
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"[BlackBox中文补丁] 成功读取外部汉化文件,新增 {num} 条,字典总条数:{TextMap.Count}");
		}
		catch (Exception)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[BlackBox中文补丁] 读取外部汉化文件失败,仅使用默认字典");
		}
	}

	private bool InitializeHarmonyPatch()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		try
		{
			Type type = Type.GetType("Blackbox.MonitorTest, MonitorTest");
			MethodInfo method = type.GetMethod("setText", BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public, null, new Type[2]
			{
				typeof(string),
				typeof(bool)
			}, null);
			Harmony val = new Harmony("BlackBox.Chinese.Patch");
			HarmonyMethod val2 = new HarmonyMethod(typeof(BlackBoxChinesePatch).GetMethod("SetText_Prefix", BindingFlags.Static | BindingFlags.NonPublic));
			val.Patch((MethodBase)method, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[BlackBox中文补丁] 汉化补丁加载成功!");
			return true;
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("[BlackBox中文补丁] 初始化异常:" + ex.Message + "\n" + ex.StackTrace));
			return false;
		}
	}

	private static bool SetText_Prefix(ref string text)
	{
		if (string.IsNullOrEmpty(text) || TextMap == null)
		{
			return true;
		}
		foreach (KeyValuePair<string, string> item in TextMap)
		{
			text = text.Replace(item.Key, item.Value);
		}
		return true;
	}
}