WulaFallenEmpireSettings.cs - 添加了 public bool enableDebugLogs = false; 字段和保存配置

 WulaLog.cs - 修改了DebugEnabled属性,仅检查enableDebugLogs设置(不检查DevMode)
 WulaFallenEmpireMod.cs - 在DoSettingsWindowContents中添加了UI复选框,显示"Enable Debug Logs"选项
 替换了所有848个Log.Message/Error/Warning调用为WulaLog.Debug()
This commit is contained in:
2025-12-15 13:05:50 +08:00
parent 9bdcd8e308
commit 98a0400c78
134 changed files with 1000 additions and 1019 deletions

View File

@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using RimWorld.Planet;
using System.Linq;
using Verse;
@@ -27,7 +27,7 @@ namespace WulaFallenEmpire
if (isBeingObserved)
{
// 如果地图正在被监测,阻止地图被移除
Log.Message($"[MapObserver] 阻止地图移除: {__instance.Label} 正在被监测");
WulaLog.Debug($"[MapObserver] 阻止地图移除: {__instance.Label} 正在被监测");
return false;
}
@@ -36,14 +36,14 @@ namespace WulaFallenEmpire
{
if (shuttle != null && shuttle.PocketMapGenerated && shuttle.PocketMap != null && shuttle.PocketMap.mapPawns.AnyPawnBlockingMapRemoval)
{
Log.Message($"[WULA] 阻止地图移除: 穿梭机 '{shuttle.Label}' 的口袋维度中仍有生物");
WulaLog.Debug($"[WULA] 阻止地图移除: 穿梭机 '{shuttle.Label}' 的口袋维度中仍有生物");
return false;
}
}
}
catch (System.Exception ex)
{
Log.Error($"[MapObserver] MapParent_CheckRemoveMapNow_Patch 错误: {ex}");
WulaLog.Debug($"[MapObserver] MapParent_CheckRemoveMapNow_Patch 错误: {ex}");
}
// 如果没有找到需要保护的情况,允许原方法继续执行

View File

@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using RimWorld;
using RimWorld.Planet;
using Verse;
@@ -25,7 +25,7 @@ namespace WulaFallenEmpire.HarmonyPatches
{
if (item is Building_ArmedShuttle armedShuttle)
{
Log.Message($"[WULA] Harmony Patch: Found Building_ArmedShuttle ({armedShuttle.Label}) in caravan inventory. Setting as __result.");
WulaLog.Debug($"[WULA] Harmony Patch: Found Building_ArmedShuttle ({armedShuttle.Label}) in caravan inventory. Setting as __result.");
// We need to cast our Building_ArmedShuttle to Building_PassengerShuttle
// This is safe because Building_ArmedShuttle is designed to be compatible with Building_PassengerShuttle's interface for caravan purposes.
__result = (Building_PassengerShuttle)armedShuttle;

View File

@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using RimWorld;
using RimWorld.Planet;
using System.Collections.Generic;
@@ -26,7 +26,7 @@ namespace WulaFallenEmpire
if (autonomousMechs.Any())
{
widget.AddSection("WULA_AutonomousMechsSection".Translate(), autonomousMechs);
Log.Message($"[WULA] Postfix: Added 'Autonomous Mechs' section with {autonomousMechs.Count} mechs.");
WulaLog.Debug($"[WULA] Postfix: Added 'Autonomous Mechs' section with {autonomousMechs.Count} mechs.");
}
}
}

View File

@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
@@ -46,7 +46,7 @@ namespace WulaFallenEmpire.HarmonyPatches
{
if (!occupiedCell.InBounds(map))
{
Log.Warning($"[WULA] Harmony Patch: SkyfallerCanLandAt - Occupied cell {occupiedCell} for WULA_ArmedShuttle (size: {size}) is out of map bounds. Preventing landing.");
WulaLog.Debug($"[WULA] Harmony Patch: SkyfallerCanLandAt - Occupied cell {occupiedCell} for WULA_ArmedShuttle (size: {size}) is out of map bounds. Preventing landing.");
__result = false;
return false; // 阻止原方法执行,并返回 false
}

View File

@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using RimWorld;
using Verse;
@@ -14,7 +14,7 @@ namespace WulaFallenEmpire
var interceptorComp = __instance.TryGetComp<CompDamageInterceptor>();
if (interceptorComp != null)
{
Log.Message($"[DamageInterceptor] {__instance.LabelShort} 即将受到 {dinfo.Amount} 点伤害,拦截组件激活");
WulaLog.Debug($"[DamageInterceptor] {__instance.LabelShort} 即将受到 {dinfo.Amount} 点伤害,拦截组件激活");
// 让拦截组件处理伤害
return interceptorComp.PreApplyDamage(ref dinfo);
@@ -34,7 +34,7 @@ namespace WulaFallenEmpire
var interceptorComp = __instance.TryGetComp<CompDamageInterceptor>();
if (interceptorComp != null && totalDamageDealt == 0f)
{
Log.Message($"[DamageInterceptor] {__instance.LabelShort} 成功拦截所有伤害实际承受0点伤害");
WulaLog.Debug($"[DamageInterceptor] {__instance.LabelShort} 成功拦截所有伤害实际承受0点伤害");
}
}
}

View File

@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
@@ -51,7 +51,7 @@ namespace WulaFallenEmpire.HarmonyPatches
}
catch (Exception ex)
{
Log.Error($"Error in Projectile_Impact_Patch: {ex}");
WulaLog.Debug($"Error in Projectile_Impact_Patch: {ex}");
return true;
}
}
@@ -76,7 +76,7 @@ namespace WulaFallenEmpire.HarmonyPatches
}
catch (Exception ex)
{
Log.Error($"Error in GetInterceptorsOnPawn: {ex}");
WulaLog.Debug($"Error in GetInterceptorsOnPawn: {ex}");
}
return result;

View File

@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using RimWorld;
using System.Collections.Generic;
using System.Reflection;
@@ -74,18 +74,18 @@ namespace WulaFallenEmpire
false, // canTransfer
Faction.OfPlayer // faction
});
Log.Message("[WULA] Successfully called DropThingGroupsNear with faction parameter via reflection");
WulaLog.Debug("[WULA] Successfully called DropThingGroupsNear with faction parameter via reflection");
}
else
{
Log.Error("[WULA] Could not find 11-parameter DropThingGroupsNear method");
WulaLog.Debug("[WULA] Could not find 11-parameter DropThingGroupsNear method");
}
// 返回 false 来跳过原方法的执行
return false;
}
catch (System.Exception ex)
{
Log.Error($"[WULA] Error in DoDropPods prefix: {ex}");
WulaLog.Debug($"[WULA] Error in DoDropPods prefix: {ex}");
// 如果出错,让原方法继续执行
return true;
}

View File

@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using RimWorld;
using RimWorld.Planet; // 关键修复
using System.Collections.Generic;
@@ -17,7 +17,7 @@ namespace WulaFallenEmpire
return;
}
Log.Message("[WULA] Patch_CaravanFormingUtility_AllSendablePawns Postfix - Start checking for autonomous mechs...");
WulaLog.Debug("[WULA] Patch_CaravanFormingUtility_AllSendablePawns Postfix - Start checking for autonomous mechs...");
// 遍历地图上所有的Pawn
foreach (Pawn pawn in map.mapPawns.AllPawns)
@@ -29,17 +29,17 @@ namespace WulaFallenEmpire
var comp = pawn.GetComp<CompAutonomousMech>();
bool canBeAutonomous = comp != null && comp.CanBeAutonomous;
Log.Message($"[WULA] Checking Mech: {pawn.LabelCap}, Already in list: {alreadyInList}, Has CompAutonomousMech: {comp != null}, CanBeAutonomous: {canBeAutonomous}");
WulaLog.Debug($"[WULA] Checking Mech: {pawn.LabelCap}, Already in list: {alreadyInList}, Has CompAutonomousMech: {comp != null}, CanBeAutonomous: {canBeAutonomous}");
// 如果它是一个可以自主行动的机械体,但没有被原版方法包含,我们就添加它
if (!alreadyInList && canBeAutonomous)
{
__result.Add(pawn);
Log.Message($"[WULA] -> Added {pawn.LabelCap} to the list.");
WulaLog.Debug($"[WULA] -> Added {pawn.LabelCap} to the list.");
}
}
}
Log.Message("[WULA] Patch_CaravanFormingUtility_AllSendablePawns Postfix - Finished.");
WulaLog.Debug("[WULA] Patch_CaravanFormingUtility_AllSendablePawns Postfix - Finished.");
}
}
}

View File

@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using RimWorld;
using System.Collections.Generic;
using System.Linq;
@@ -30,7 +30,7 @@ namespace WulaFallenEmpire
{
if (corpseDef == null) return;
Log.Message($"[WulaSpecies] Starting corpse modification for WulaSpecies");
WulaLog.Debug($"[WulaSpecies] Starting corpse modification for WulaSpecies");
// 1. 移除腐烂组件(如果存在)
RemoveCompProperties(corpseDef, typeof(CompProperties_Rottable));
@@ -42,13 +42,13 @@ namespace WulaFallenEmpire
if (corpseDef.ingestible != null)
{
corpseDef.ingestible.preferability = FoodPreferability.NeverForNutrition;
Log.Message($"[WulaSpecies] Set ingestible preferability to NeverForNutrition");
WulaLog.Debug($"[WulaSpecies] Set ingestible preferability to NeverForNutrition");
}
// 4. 移除 HarbingerTreeConsumable 组件(如果存在)
RemoveCompProperties(corpseDef, typeof(CompProperties), "CompHarbingerTreeConsumable");
Log.Message($"[WulaSpecies] Completed corpse modification for WulaSpecies");
WulaLog.Debug($"[WulaSpecies] Completed corpse modification for WulaSpecies");
}
/// <summary>
@@ -65,19 +65,19 @@ namespace WulaFallenEmpire
if (comp.GetType() == compType)
{
compsToRemove.Add(comp);
Log.Message($"[WulaSpecies] Found and will remove component: {comp.GetType().Name}");
WulaLog.Debug($"[WulaSpecies] Found and will remove component: {comp.GetType().Name}");
}
else if (!string.IsNullOrEmpty(compClassName) && comp.compClass?.Name == compClassName)
{
compsToRemove.Add(comp);
Log.Message($"[WulaSpecies] Found and will remove component by class name: {compClassName}");
WulaLog.Debug($"[WulaSpecies] Found and will remove component by class name: {compClassName}");
}
}
foreach (var comp in compsToRemove)
{
thingDef.comps.Remove(comp);
Log.Message($"[WulaSpecies] Removed component: {comp.GetType().Name}");
WulaLog.Debug($"[WulaSpecies] Removed component: {comp.GetType().Name}");
}
}
}