From 2487a099c1b05c50bfa783bddd9a78d3e6ca6472 Mon Sep 17 00:00:00 2001 From: SSSSSSSan Date: Sun, 23 Nov 2025 21:49:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E8=B0=83=E8=AF=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=92=8C=E6=B7=BB=E5=8A=A0=E8=8B=B1=E6=96=87=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除Dustbin.cs中CalcGetSands方法的调试日志输出 - 移除StoragePatch.cs中的调试方法(LogTranspilerInfo, LogReturnValue, LogInserterState) - 移除transpiler中对调试方法的调用 - 为StoragePatch.cs中的所有中文注释添加英文翻译 - 保持修复bug的核心逻辑完整性 --- Dustbin/Dustbin.cs | 19 +--------------- Dustbin/StoragePatch.cs | 48 +++++++++-------------------------------- 2 files changed, 11 insertions(+), 56 deletions(-) diff --git a/Dustbin/Dustbin.cs b/Dustbin/Dustbin.cs index 81f63ea..8d8f1f6 100644 --- a/Dustbin/Dustbin.cs +++ b/Dustbin/Dustbin.cs @@ -61,28 +61,11 @@ public class Dustbin : BaseUnityPlugin, IModCanSave, IMultiplayerMod public static int CalcGetSands(int itemId, int count, int inc) { var sandsPerItem = itemId <= 12000 ? Dustbin.SandsFactors[itemId] : 0; - - // Log item information for debugging - var itemProto = LDB.items.Select(itemId); - if (itemProto != null) - { - Logger.LogInfo($"Item destroyed - ID: {itemId}, Name: {itemProto.name}, Type: {itemProto.Type}, StackSize: {itemProto.StackSize}, Grade: {itemProto.Grade}, Count: {count}, Inc: {inc}"); - } - else - { - Logger.LogInfo($"Item destroyed - ID: {itemId}, Name: Unknown, Count: {count}, Inc: {inc}"); - } - - if (sandsPerItem <= 0) - { - Logger.LogInfo($"No sands generated for item {itemId} (SandsFactor: {sandsPerItem}, Inc: {inc}) - Returning {count} to indicate item destroyed"); - return count; - } + if (sandsPerItem <= 0) return count; var player = GameMain.mainPlayer; var addCount = count * sandsPerItem; player.sandCount += addCount; - Logger.LogInfo($"Sands calculation - ItemID: {itemId}, SandsFactor: {sandsPerItem}, Total sands: {addCount}, Inc: {inc} - Returning {count} to indicate item destroyed"); return count; } diff --git a/Dustbin/StoragePatch.cs b/Dustbin/StoragePatch.cs index 8277f27..248c21e 100644 --- a/Dustbin/StoragePatch.cs +++ b/Dustbin/StoragePatch.cs @@ -148,20 +148,6 @@ public static class StoragePatch _lastStorageId = 0; // Refresh UI to reposition button on client side } - private static void LogTranspilerInfo(string stage, int itemId, int count, int inc, bool isDustbin, bool enteringDustbinLogic) - { - Dustbin.Logger.LogInfo($"Transpiler {stage} - ItemID: {itemId}, Count: {count}, Inc: {inc}, IsDustbin: {isDustbin}, EnteringDustbinLogic: {enteringDustbinLogic}"); - } - - private static void LogReturnValue(int returnValue, string context) - { - Dustbin.Logger.LogInfo($"Return Value - Context: {context}, Value: {returnValue}"); - } - - private static void LogInserterState(string operation, int itemId, int count, int inc, int storageId) - { - Dustbin.Logger.LogInfo($"分拣器状态 - 操作: {operation}, 物品ID: {itemId}, 数量: {count}, 增产剂: {inc}, 储物仓ID: {storageId}"); - } [HarmonyTranspiler] [HarmonyPatch(typeof(StorageComponent), nameof(StorageComponent.AddItem), [typeof(int), typeof(int), typeof(int), typeof(int), typeof(bool)], @@ -172,66 +158,52 @@ public static class StoragePatch var matcher = new CodeMatcher(codes, generator); // 找到方法开始处 + // Find the beginning of the method matcher.Start(); // 定义标签用于跳转 + // Define label for jump var skipDustbinLogic = generator.DefineLabel(); // 在方法开始处插入安全检查 + // Insert safety checks at the beginning of the method matcher.InsertAndAdvance( // 安全检查:确保StorageComponent实例不为null + // Safety check: Ensure StorageComponent instance is not null new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Brfalse, skipDustbinLogic), // 检查是否是垃圾桶 + // Check if it's a dustbin new CodeInstruction(OpCodes.Ldarg_0), new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(StorageComponent), nameof(StorageComponent.IsDustbin))), new CodeInstruction(OpCodes.Brfalse, skipDustbinLogic), // 检查count是否大于0 + // Check if count is greater than 0 new CodeInstruction(OpCodes.Ldarg_2), new CodeInstruction(OpCodes.Ldc_I4_0), new CodeInstruction(OpCodes.Ble, skipDustbinLogic), - // 记录进入垃圾桶处理逻辑 - new CodeInstruction(OpCodes.Ldstr, "Processing Dustbin"), - new CodeInstruction(OpCodes.Ldarg_1), - new CodeInstruction(OpCodes.Ldarg_2), - new CodeInstruction(OpCodes.Ldarg_3), - new CodeInstruction(OpCodes.Ldarg_0), - new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(StorageComponent), nameof(StorageComponent.IsDustbin))), - new CodeInstruction(OpCodes.Ldc_I4_1), - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(StoragePatch), nameof(LogTranspilerInfo))), - - // 记录分拣器状态 - new CodeInstruction(OpCodes.Ldstr, "Before CalcGetSands"), - new CodeInstruction(OpCodes.Ldarg_1), - new CodeInstruction(OpCodes.Ldarg_2), - new CodeInstruction(OpCodes.Ldarg_3), - new CodeInstruction(OpCodes.Ldarg_0), - new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(StorageComponent), nameof(StorageComponent.id))), - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(StoragePatch), nameof(LogInserterState))), - // 调用CalcGetSands处理物品销毁和沙子生成 + // Call CalcGetSands to handle item destruction and sand generation new CodeInstruction(OpCodes.Ldarg_1), new CodeInstruction(OpCodes.Ldarg_2), new CodeInstruction(OpCodes.Ldarg_3), new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Dustbin), nameof(Dustbin.CalcGetSands))), - // 记录返回值 - new CodeInstruction(OpCodes.Dup), - new CodeInstruction(OpCodes.Ldstr, "CalcGetSands Return"), - new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(StoragePatch), nameof(LogReturnValue))), - // 设置remainInc为0(第5个参数,索引4) + // Set remainInc to 0 (5th parameter, index 4) new CodeInstruction(OpCodes.Ldarg, 4), new CodeInstruction(OpCodes.Ldc_I4_0), new CodeInstruction(OpCodes.Stind_I4), // 返回count表示成功销毁 + // Return count to indicate successful destruction new CodeInstruction(OpCodes.Ret), // 跳过垃圾桶逻辑的标签 + // Label to skip dustbin logic new CodeInstruction(OpCodes.Nop).WithLabels(skipDustbinLogic) );