Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of JJJ FixPack v1.1.0
EpicLootTabFontFix.dll
Decompiled 13 hours agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using EpicLoot.Compendium; using EpicLoot_UnityLib; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")] [assembly: AssemblyCompany("EpicLootTabFontFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("EpicLootTabFontFix")] [assembly: AssemblyTitle("EpicLootTabFontFix")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace EpicLootTabFontFix { [BepInPlugin("jun.fix.epiclootfontfix", "EpicLootTabFontFix", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class EpicLootTabFontFixPlugin : BaseUnityPlugin { public const string PluginGuid = "jun.fix.epiclootfontfix"; public const string PluginName = "EpicLootTabFontFix"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("jun.fix.epiclootfontfix"); _harmony.PatchAll(typeof(EnchantingTableTabFontPatches)); Log.LogInfo((object)"EpicLootTabFontFix v1.0.0 已成功加载:附魔台侧边标签页中文字体自动补齐已就绪(纯生命周期事件触发,零冗余开销)。"); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class EnchantingTableTabFontPatches { private static TMP_FontAsset _cachedTargetFont; private static Material _cachedTargetMaterial; private static bool _hasLoggedFont; private static void EnsureTargetFont(EnchantingTableUI ui) { if ((Object)(object)_cachedTargetFont != (Object)null) { return; } try { TMP_FontData tMPFont = MagicFontManager.GetTMPFont((TMP_FontOptions)3); if (tMPFont != null && (Object)(object)tMPFont.font != (Object)null) { _cachedTargetFont = tMPFont.font; _cachedTargetMaterial = tMPFont.material; } } catch { } if ((Object)(object)_cachedTargetFont == (Object)null) { try { TMP_FontData tMPFont2 = MagicFontManager.GetTMPFont((TMP_FontOptions)5); if (tMPFont2 != null && (Object)(object)tMPFont2.font != (Object)null) { _cachedTargetFont = tMPFont2.font; _cachedTargetMaterial = tMPFont2.material; } } catch { } } if ((Object)(object)_cachedTargetFont == (Object)null && (Object)(object)ui != (Object)null && (Object)(object)ui.Root != (Object)null) { TMP_Text[] componentsInChildren = ui.Root.GetComponentsInChildren<TMP_Text>(true); foreach (TMP_Text val in componentsInChildren) { if ((Object)(object)val != (Object)null && (Object)(object)val.font != (Object)null && !string.IsNullOrEmpty(((Object)val.font).name) && !((Object)val.font).name.Contains("AveriaSansLibre-Bold") && !((Object)val.font).name.Contains("LiberationSans")) { _cachedTargetFont = val.font; _cachedTargetMaterial = val.fontSharedMaterial; break; } } } if ((Object)(object)_cachedTargetFont == (Object)null) { TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>(); foreach (TMP_FontAsset val2 in array) { if ((Object)(object)val2 != (Object)null && !string.IsNullOrEmpty(((Object)val2).name) && (((Object)val2).name == "Valheim-AveriaSerifLibre" || ((Object)val2).name == "Valheim-AveriaSansLibre" || (((Object)val2).name.Contains("Averia") && !((Object)val2).name.Contains("AveriaSansLibre-Bold")))) { _cachedTargetFont = val2; _cachedTargetMaterial = ((TMP_Asset)val2).material; break; } } } if ((Object)(object)_cachedTargetFont != (Object)null && !_hasLoggedFont) { _hasLoggedFont = true; EpicLootTabFontFixPlugin.Log.LogInfo((object)("已捕获附魔台可用中文字体:" + ((Object)_cachedTargetFont).name)); } } public static void FixAllMissingFonts(EnchantingTableUI ui) { if ((Object)(object)ui == (Object)null) { ui = EnchantingTableUI.instance; } if ((Object)(object)ui == (Object)null) { return; } EnsureTargetFont(ui); if ((Object)(object)_cachedTargetFont == (Object)null) { return; } int num = 0; if ((Object)(object)ui.TabHandler != (Object)null && ui.TabHandler.m_tabs != null) { foreach (Tab tab in ui.TabHandler.m_tabs) { if (tab == null || (Object)(object)tab.m_button == (Object)null) { continue; } TMP_Text[] componentsInChildren = ((Component)tab.m_button).GetComponentsInChildren<TMP_Text>(true); foreach (TMP_Text val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && NeedsFontFix(val)) { ApplyFont(val); num++; } } } } if ((Object)(object)ui.Root != (Object)null) { TMP_Text[] componentsInChildren = ui.Root.GetComponentsInChildren<TMP_Text>(true); foreach (TMP_Text val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null) && NeedsFontFix(val2)) { ApplyFont(val2); num++; } } } if (num > 0) { EpicLootTabFontFixPlugin.Log.LogInfo((object)$"[生命周期事件] 已单次修正附魔台 {num} 处文本字体,中文正常显示。"); } } private static bool NeedsFontFix(TMP_Text tmp) { if ((Object)(object)tmp.font == (Object)null) { return true; } string name = ((Object)tmp.font).name; if (!name.Contains("AveriaSansLibre-Bold")) { return name.Contains("LiberationSans"); } return true; } private static void ApplyFont(TMP_Text tmp) { tmp.font = _cachedTargetFont; if ((Object)(object)_cachedTargetMaterial != (Object)null) { tmp.fontSharedMaterial = _cachedTargetMaterial; } ((Graphic)tmp).SetAllDirty(); } [HarmonyPatch(typeof(EnchantingTableUI), "SetupTabs")] [HarmonyPostfix] public static void SetupTabs_Postfix(EnchantingTableUI __instance) { FixAllMissingFonts(__instance); } [HarmonyPatch(typeof(EnchantingTableUI), "Show")] [HarmonyPostfix] public static void Show_Postfix(EnchantingTable source) { FixAllMissingFonts(EnchantingTableUI.instance); } } }
RespawnAreaFix.dll
Decompiled 13 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("RespawnAreaFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("RespawnAreaFix")] [assembly: AssemblyTitle("RespawnAreaFix")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace RespawnAreaFix { [BepInPlugin("jjj.fix.respawnareafix", "RespawnAreaFix", "1.0.0")] public class RespawnAreaFixPlugin : BaseUnityPlugin { public const string PluginGuid = "jjj.fix.respawnareafix"; public const string PluginName = "RespawnAreaFix"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("jjj.fix.respawnareafix"); _harmony.PatchAll(typeof(Patches)); Log.LogInfo((object)"RespawnAreaFix v1.0.0 已加载:死锁自愈与重生区域诊断监控已启用。"); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class Patches { private const float NormalSweepInterval = 2f; private const float RespawnSweepInterval = 0.5f; private const float DiagnosticInterval = 2.5f; private const float StallGraceSeconds = 5f; private const float MinStallThresholdSeconds = 13f; private const float LoadingUnstuckSeconds = 26f; private const int MaxDetailedBlockersPerPass = 25; private static readonly int MbParentIdHash = StringExtensionMethods.GetStableHashCode("MBParentId"); private static readonly int SwivelParentIdHash = StringExtensionMethods.GetStableHashCode("SwivelParentId"); private static readonly FieldRef<ZNetScene, Dictionary<ZDO, ZNetView>> ZNetSceneInstancesRef = AccessTools.FieldRefAccess<ZNetScene, Dictionary<ZDO, ZNetView>>("m_instances"); private static readonly FieldRef<Game, float> GameRespawnWaitRef = AccessTools.FieldRefAccess<Game, float>("m_respawnWait"); private static readonly FieldRef<Game, float> GameRespawnLoadDurationRef = AccessTools.FieldRefAccess<Game, float>("m_respawnLoadDuration"); private static readonly FieldRef<Game, bool> GameRespawnAfterDeathRef = AccessTools.FieldRefAccess<Game, bool>("m_respawnAfterDeath"); private static readonly FieldRef<Game, PlayerProfile> GamePlayerProfileRef = AccessTools.FieldRefAccess<Game, PlayerProfile>("m_playerProfile"); private static readonly FieldRef<Game, string> GameStartLocationRef = AccessTools.FieldRefAccess<Game, string>("m_StartLocation"); private static readonly FieldRef<ZoneSystem, Dictionary<Vector2s, List<ZDO>>> ZoneLoadingObjectsRef = AccessTools.FieldRefAccess<ZoneSystem, Dictionary<Vector2s, List<ZDO>>>("m_loadingObjectsInZones"); private static readonly FieldRef<ZoneSystem, SimulationDistance> ZoneSimDistanceRef = AccessTools.FieldRefAccess<ZoneSystem, SimulationDistance>("m_simulationDistance"); private static readonly FieldInfo ZoneSystemZonesField = AccessTools.Field(typeof(ZoneSystem), "m_zones"); private static readonly PropertyInfo ZdoCreatedProp = AccessTools.Property(typeof(ZDO), "Created"); private static readonly Func<ZDO, bool> GetZdoCreatedDel = CreatePropGetDelegate<Func<ZDO, bool>>(ZdoCreatedProp); private static readonly Action<ZDO, bool> SetZdoCreatedDel = CreatePropSetDelegate<Action<ZDO, bool>>(ZdoCreatedProp); private static readonly Func<ZoneSystem, Vector2s, bool> PokeLocalZoneDel = CreateDelegate<Func<ZoneSystem, Vector2s, bool>>(typeof(ZoneSystem), "PokeLocalZone", new Type[1] { typeof(Vector2s) }); private static readonly Func<ZNetScene, ZDO, bool> IsPrefabZdoValidDel = CreateDelegate<Func<ZNetScene, ZDO, bool>>(typeof(ZNetScene), "IsPrefabZDOValid", new Type[1] { typeof(ZDO) }); private static readonly FieldInfo ValheimVehiclesDisableCreateDestroyField = ResolveValheimVehiclesDisableFlag(); private static readonly List<ZDO> DeadZdoBuffer = new List<ZDO>(); private static readonly List<ZDO> SectorZdoBuffer = new List<ZDO>(); private static readonly HashSet<ZDOID> ReportedDeadUids = new HashSet<ZDOID>(); private static readonly HashSet<string> LoggedStallKeys = new HashSet<string>(); private static readonly Dictionary<string, int> LoadingStuckSeenCounts = new Dictionary<string, int>(); private static float _nextSweepTime; private static float _nextDiagnosticTime; private static int _stalledPasses; private static bool _wasWaitingForRespawn; private static T CreateDelegate<T>(Type targetType, string methodName, params Type[] paramTypes) where T : Delegate { MethodInfo methodInfo = AccessTools.Method(targetType, methodName, paramTypes, (Type[])null); if (!(methodInfo != null)) { return null; } return (T)Delegate.CreateDelegate(typeof(T), methodInfo); } private static T CreatePropGetDelegate<T>(PropertyInfo prop) where T : Delegate { MethodInfo methodInfo = prop?.GetGetMethod(nonPublic: true); if (!(methodInfo != null)) { return null; } return (T)Delegate.CreateDelegate(typeof(T), methodInfo); } private static T CreatePropSetDelegate<T>(PropertyInfo prop) where T : Delegate { MethodInfo methodInfo = prop?.GetSetMethod(nonPublic: true); if (!(methodInfo != null)) { return null; } return (T)Delegate.CreateDelegate(typeof(T), methodInfo); } private static FieldInfo ResolveValheimVehiclesDisableFlag() { try { Type type = AccessTools.TypeByName("ValheimVehicles.Patches.PatchSharedData"); if (type != null) { return AccessTools.Field(type, "m_disableCreateDestroy"); } } catch { } return null; } [HarmonyPatch(typeof(ZNetScene), "RemoveObjects", new Type[] { typeof(List<ZDO>), typeof(List<ZDO>) })] [HarmonyPostfix] [HarmonyPriority(0)] private static void ZNetScene_RemoveObjects_Postfix(ZNetScene __instance) { if ((Object)(object)Game.instance == (Object)null || !Game.instance.WaitingForRespawn()) { return; } try { if (Object.op_Implicit((Object)(object)__instance)) { float unscaledTime = Time.unscaledTime; if (!(unscaledTime < _nextSweepTime)) { _nextSweepTime = unscaledTime + 0.5f; SweepDeadInstances(__instance, "RemoveObjects(重生期)"); } } } catch (Exception arg) { ManualLogSource log = RespawnAreaFixPlugin.Log; if (log != null) { log.LogError((object)$"[RespawnAreaFix] RemoveObjects Postfix 异常: {arg}"); } } } [HarmonyPatch(typeof(ZNetScene), "CreateObject", new Type[] { typeof(ZDO) })] [HarmonyFinalizer] private static Exception ZNetScene_CreateObject_Finalizer(Exception __exception, ZNetScene __instance, ZDO zdo) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (__exception != null) { try { string text = DescribePrefab(__instance, zdo); string text2 = ((zdo != null) ? ((object)Unsafe.As<ZDOID, ZDOID>(ref zdo.m_uid)/*cast due to .constrained prefix*/).ToString() : "<null>"); object obj; if (zdo == null) { obj = "<null>"; } else { Vector3 position = zdo.GetPosition(); obj = ((Vector3)(ref position)).ToString("F1"); } string text3 = (string)obj; ManualLogSource log = RespawnAreaFixPlugin.Log; if (log != null) { log.LogError((object)$"[RespawnAreaFix][CreateObject异常] prefab={text}, uid={text2}, pos={text3}, ex={__exception}"); } } catch { } } return __exception; } [HarmonyPatch(typeof(Game), "UpdateRespawn", new Type[] { typeof(float) })] [HarmonyPostfix] private static void Game_UpdateRespawn_Postfix(Game __instance) { try { if ((Object)(object)__instance == (Object)null) { return; } if (!__instance.WaitingForRespawn()) { if (!_wasWaitingForRespawn) { return; } if (_stalledPasses > 0) { ManualLogSource log = RespawnAreaFixPlugin.Log; if (log != null) { log.LogMessage((object)$"[RespawnAreaFix] 重生/加载已完成,本次共执行了 {_stalledPasses} 轮卡死诊断与自愈。"); } } ResetRespawnTracking(); return; } _wasWaitingForRespawn = true; float num = GameRespawnWaitRef.Invoke(__instance); float num2 = GameRespawnLoadDurationRef.Invoke(__instance); float num3 = Mathf.Max(num2 + 5f, 13f); if (!(num < num3)) { float unscaledTime = Time.unscaledTime; if (!(unscaledTime < _nextDiagnosticTime)) { _nextDiagnosticTime = unscaledTime + 2.5f; _stalledPasses++; RunRespawnDiagnosticAndRepair(__instance, num, num2); } } } catch (Exception arg) { ManualLogSource log2 = RespawnAreaFixPlugin.Log; if (log2 != null) { log2.LogError((object)$"[RespawnAreaFix] UpdateRespawn Postfix 异常: {arg}"); } } } private static void ResetRespawnTracking() { _wasWaitingForRespawn = false; _stalledPasses = 0; _nextDiagnosticTime = 0f; LoggedStallKeys.Clear(); LoadingStuckSeenCounts.Clear(); } private static int SweepDeadInstances(ZNetScene scene, string source) { //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)scene)) { return 0; } Dictionary<ZDO, ZNetView> dictionary = ZNetSceneInstancesRef.Invoke(scene); if (dictionary == null || dictionary.Count == 0) { return 0; } DeadZdoBuffer.Clear(); foreach (KeyValuePair<ZDO, ZNetView> item in dictionary) { if (!Object.op_Implicit((Object)(object)item.Value)) { DeadZdoBuffer.Add(item.Key); } } if (DeadZdoBuffer.Count == 0) { return 0; } int num = 0; foreach (ZDO item2 in DeadZdoBuffer) { dictionary.Remove(item2); num++; if (item2 == null || ((ZDOID)(ref item2.m_uid)).IsNone()) { continue; } if (item2.Persistent && item2.GetPrefab() != 0 && item2.GetPrefab() != -1 && GetZdoCreated(item2)) { SetZdoCreated(item2, value: false); } if (ReportedDeadUids.Add(item2.m_uid)) { string text = DescribePrefab(scene, item2); int num2 = item2.GetInt(MbParentIdHash, 0); int num3 = item2.GetInt(SwivelParentIdHash, 0); ManualLogSource log = RespawnAreaFixPlugin.Log; if (log != null) { log.LogWarning((object)$"[RespawnAreaFix][清理已销毁残留实例:{source}] prefab={text}, uid={item2.m_uid}, pos={item2.GetPosition():F1}, sector={item2.GetSector()}, valid={item2.IsValid()}, owner={item2.GetOwner()}, MBParentId={num2}, SwivelParentId={num3}"); } } } if (num > 1) { ManualLogSource log2 = RespawnAreaFixPlugin.Log; if (log2 != null) { log2.LogWarning((object)$"[RespawnAreaFix] 本次({source})共清理 {num} 个已销毁但仍残留在 m_instances 中的 ZNetView 条目。"); } } DeadZdoBuffer.Clear(); return num; } private static void RunRespawnDiagnosticAndRepair(Game game, float respawnWait, float loadDuration) { //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02fc: Unknown result type (might be due to invalid IL or missing references) //IL_03ab: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) //IL_0328: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_0384: Unknown result type (might be due to invalid IL or missing references) //IL_0367: Unknown result type (might be due to invalid IL or missing references) //IL_048f: Unknown result type (might be due to invalid IL or missing references) //IL_0494: Unknown result type (might be due to invalid IL or missing references) //IL_0497: Unknown result type (might be due to invalid IL or missing references) //IL_04a1: Unknown result type (might be due to invalid IL or missing references) //IL_04a5: Unknown result type (might be due to invalid IL or missing references) //IL_0512: Unknown result type (might be due to invalid IL or missing references) //IL_04e1: Unknown result type (might be due to invalid IL or missing references) //IL_05c1: Unknown result type (might be due to invalid IL or missing references) //IL_05d0: Unknown result type (might be due to invalid IL or missing references) //IL_05dd: Unknown result type (might be due to invalid IL or missing references) //IL_04fb: Unknown result type (might be due to invalid IL or missing references) ZNetScene instance = ZNetScene.instance; ZoneSystem instance2 = ZoneSystem.instance; ZDOMan instance3 = ZDOMan.instance; ZNet instance4 = ZNet.instance; if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance2) || instance3 == null || !Object.op_Implicit((Object)(object)instance4)) { ManualLogSource log = RespawnAreaFixPlugin.Log; if (log != null) { log.LogWarning((object)$"[RespawnAreaFix] 第 {_stalledPasses} 轮诊断({respawnWait:F1}s):核心管理器尚为空 (scene={(Object)(object)instance != (Object)null}, zoneSys={(Object)(object)instance2 != (Object)null}, zdoMan={instance3 != null}, znet={(Object)(object)instance4 != (Object)null})"); } return; } if (!TryGetExpectedTargetPoint(game, instance2, out var point, out var source)) { ManualLogSource log2 = RespawnAreaFixPlugin.Log; if (log2 != null) { log2.LogWarning((object)$"[RespawnAreaFix] 第 {_stalledPasses} 轮诊断({respawnWait:F1}s):无法获取目标重生点 ({source})。"); } return; } if (ValheimVehiclesDisableCreateDestroyField != null) { try { object value = ValheimVehiclesDisableCreateDestroyField.GetValue(null); bool flag = default(bool); int num; if (value is bool) { flag = (bool)value; num = 1; } else { num = 0; } if (((uint)num & (flag ? 1u : 0u)) != 0) { ValheimVehiclesDisableCreateDestroyField.SetValue(null, false); ManualLogSource log3 = RespawnAreaFixPlugin.Log; if (log3 != null) { log3.LogError((object)"[RespawnAreaFix] 检测到 ValheimVehicles.Patches.PatchSharedData.m_disableCreateDestroy == true,已强制重置为 false!"); } } } catch { } } int num2 = SweepDeadInstances(instance, $"重生卡死第{_stalledPasses}轮"); Vector2s zone = ZoneSystem.GetZone(point); bool flag2 = instance2.IsZoneLoaded(zone); bool flag3 = instance2.IsActiveAreaLoaded(); bool flag4 = instance.IsAreaReady(point); Vector3 referencePosition = instance4.GetReferencePosition(); ManualLogSource log4 = RespawnAreaFixPlugin.Log; if (log4 != null) { log4.LogWarning((object)$"[RespawnAreaFix] 复活等待异常 ({respawnWait:F1}s / {loadDuration:F1}s) 第{_stalledPasses}轮 | 来源={source} | 目标点={point:F1} | 中心区块={zone} | RefPos={referencePosition:F1} | IsZoneLoaded(中心)={flag2} | IsActiveAreaLoaded={flag3} | IsAreaReady={flag4} | 本轮清理死实例={num2}"); } Vector3 val = referencePosition - point; if (((Vector3)(ref val)).sqrMagnitude > 4f) { ManualLogSource log5 = RespawnAreaFixPlugin.Log; if (log5 != null) { log5.LogWarning((object)$"[RespawnAreaFix] 注意:ZNet.ReferencePosition({referencePosition:F1}) 与目标重生点({point:F1}) 存在偏差!"); } } IDictionary dictionary = ZoneSystemZonesField?.GetValue(instance2) as IDictionary; Dictionary<Vector2s, List<ZDO>> loadingDict = ZoneLoadingObjectsRef.Invoke(instance2); Vector2s z = default(Vector2s); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { ((Vector2s)(ref z))..ctor(zone.x + j, zone.y + i); InspectAndRepairZone(instance, instance2, dictionary, loadingDict, z, respawnWait, "重生3x3"); } } if (!flag3 && dictionary != null) { SimulationDistance val2 = ZoneSimDistanceRef.Invoke(instance2); Vector2s zone2 = ZoneSystem.GetZone(referencePosition); int nearSimulationDistance = ((SimulationDistance)(ref val2)).NearSimulationDistance; Vector2s val3 = default(Vector2s); for (int k = zone2.y - nearSimulationDistance; k <= zone2.y + nearSimulationDistance; k++) { for (int l = zone2.x - nearSimulationDistance; l <= zone2.x + nearSimulationDistance; l++) { ((Vector2s)(ref val3))..ctor(l, k); if (dictionary.Contains(val3)) { continue; } string item = $"activeMissing:{val3}"; if (LoggedStallKeys.Add(item)) { ManualLogSource log6 = RespawnAreaFixPlugin.Log; if (log6 != null) { log6.LogWarning((object)$"[RespawnAreaFix] ActiveArea 缺少区块 {val3},尝试调用 PokeLocalZone。"); } } PokeLocalZoneDel?.Invoke(instance2, val3); } } } SectorZdoBuffer.Clear(); instance3.FindSectorObjects(zone, new SimulationDistance(1, 0, false), SectorZdoBuffer, (List<ZDO>)null); Dictionary<ZDO, ZNetView> dictionary2 = ZNetSceneInstancesRef.Invoke(instance); int count = SectorZdoBuffer.Count; int num3 = 0; int num4 = 0; int num5 = 0; int num6 = 0; int num7 = 0; for (int m = 0; m < SectorZdoBuffer.Count; m++) { ZDO val4 = SectorZdoBuffer[m]; if (val4 == null || IsPrefabZdoValidDel == null || !IsPrefabZdoValidDel(instance, val4)) { continue; } num3++; if (Object.op_Implicit((Object)(object)instance.FindInstance(val4))) { continue; } num4++; ZNetView value2 = null; bool flag5 = dictionary2?.TryGetValue(val4, out value2) ?? false; bool flag6 = flag5 && !Object.op_Implicit((Object)(object)value2); bool zdoCreated = GetZdoCreated(val4); Vector2s sector = val4.GetSector(); bool flag7 = instance2.IsZoneLoaded(sector); bool flag8 = instance2.IsZoneReadyForType(sector, val4.Type); if (flag6) { dictionary2.Remove(val4); num6++; } if (zdoCreated) { SetZdoCreated(val4, value: false); num5++; } if (!flag7 && dictionary != null && !dictionary.Contains(sector)) { PokeLocalZoneDel?.Invoke(instance2, sector); } string item2 = $"zdo:{val4.m_uid}:{zdoCreated}:{flag6}:{flag7}:{flag8}"; if (LoggedStallKeys.Add(item2) && num7 < 25) { num7++; string text = DescribePrefab(instance, val4); int num8 = val4.GetInt(MbParentIdHash, 0); int num9 = val4.GetInt(SwivelParentIdHash, 0); ManualLogSource log7 = RespawnAreaFixPlugin.Log; if (log7 != null) { log7.LogWarning((object)$"[RespawnAreaFix][阻塞IsAreaReady #{num4}] prefab={text}, uid={val4.m_uid}, pos={val4.GetPosition():F1}, sector={sector}, valid={val4.IsValid()}, owner={val4.GetOwner()}, persistent={val4.Persistent}, wasCreated={zdoCreated}, inInstances={flag5}, deadUnityView={flag6}, sectorLoaded={flag7}, readyForType={flag8}, MBParentId={num8}, SwivelParentId={num9}"); } } } ManualLogSource log8 = RespawnAreaFixPlugin.Log; if (log8 != null) { log8.LogMessage((object)$"[RespawnAreaFix] 第{_stalledPasses}轮扫描汇总:3x3总ZDO={count}, 有效预制体={num3}, 未就绪阻塞数={num4}, 本轮移除死实例={num6}, 本轮重置Created={num5}"); } SectorZdoBuffer.Clear(); } private static void InspectAndRepairZone(ZNetScene scene, ZoneSystem zoneSys, IDictionary zonesDict, Dictionary<Vector2s, List<ZDO>> loadingDict, Vector2s z, float respawnWait, string tag) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) if (zonesDict != null && !zonesDict.Contains(z)) { string item = $"missingZone:{z}"; if (LoggedStallKeys.Add(item)) { ManualLogSource log = RespawnAreaFixPlugin.Log; if (log != null) { log.LogWarning((object)$"[RespawnAreaFix][{tag}] 区块 {z} 不在 m_zones 中,调用 PokeLocalZone。"); } } PokeLocalZoneDel?.Invoke(zoneSys, z); } if (loadingDict == null || !loadingDict.TryGetValue(z, out var value) || value == null || value.Count <= 0) { return; } for (int num = value.Count - 1; num >= 0; num--) { ZDO val = value[num]; string text = ((val != null) ? ((object)Unsafe.As<ZDOID, ZDOID>(ref val.m_uid)/*cast due to .constrained prefix*/).ToString() : "<null>"); string key = $"loading:{z}:{text}"; LoadingStuckSeenCounts.TryGetValue(key, out var value2); value2++; LoadingStuckSeenCounts[key] = value2; if (value2 == 1) { string text2 = DescribePrefab(scene, val); object obj; if (val == null) { obj = "<null>"; } else { Vector3 position = val.GetPosition(); obj = ((Vector3)(ref position)).ToString("F1"); } string text3 = (string)obj; bool flag = val != null && val.IsValid(); ManualLogSource log2 = RespawnAreaFixPlugin.Log; if (log2 != null) { log2.LogWarning((object)$"[RespawnAreaFix][{tag}] 区块 {z} 存在 m_loadingObjectsInZones 阻塞对象: prefab={text2}, uid={text}, pos={text3}, valid={flag}"); } } if (val == null || !val.IsValid() || (respawnWait >= 26f && value2 >= 3)) { string text4 = DescribePrefab(scene, val); ManualLogSource log3 = RespawnAreaFixPlugin.Log; if (log3 != null) { log3.LogError((object)$"[RespawnAreaFix][{tag}] 清理长期卡死的异步加载锁定项: zone={z}, prefab={text4}, uid={text}, wait={respawnWait:F1}s, seen={value2}"); } value.RemoveAt(num); } } if (value.Count == 0) { loadingDict.Remove(z); } } private static bool TryGetExpectedTargetPoint(Game game, ZoneSystem zoneSys, out Vector3 point, out string source) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) point = Vector3.zero; source = "未知"; bool flag = GameRespawnAfterDeathRef.Invoke(game); PlayerProfile val = GamePlayerProfileRef.Invoke(game); if (val == null) { source = "PlayerProfile为空"; return false; } if (!flag && val.HaveLogoutPoint()) { point = val.GetLogoutPoint(); source = "LogoutPoint(上线位置)"; return true; } if (val.HaveCustomSpawnPoint()) { point = val.GetCustomSpawnPoint(); source = "CustomSpawnPoint(床位)"; return true; } string text = GameStartLocationRef.Invoke(game); Vector3 val2 = default(Vector3); if (!string.IsNullOrEmpty(text) && zoneSys.GetLocationIcon(text, ref val2)) { point = val2 + Vector3.up * 2f; source = "StartLocation(" + text + ")"; return true; } source = "无LogoutPoint/CustomSpawnPoint/StartLocation"; return false; } private static bool GetZdoCreated(ZDO zdo) { if (zdo != null && GetZdoCreatedDel != null) { return GetZdoCreatedDel(zdo); } return false; } private static void SetZdoCreated(ZDO zdo, bool value) { if (zdo != null) { SetZdoCreatedDel?.Invoke(zdo, value); } } private static string DescribePrefab(ZNetScene scene, ZDO zdo) { if (zdo == null) { return "<null-zdo>"; } int prefab = zdo.GetPrefab(); if (prefab == 0) { return "<hash-0>"; } if (!Object.op_Implicit((Object)(object)scene)) { return $"hash:{prefab}"; } GameObject prefab2 = scene.GetPrefab(prefab); if (!Object.op_Implicit((Object)(object)prefab2)) { return $"<missing-prefab:{prefab}>"; } return ((Object)prefab2).name; } } }
修复大船浮力爆发.dll
Decompiled 13 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("修复大船浮力爆发")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("修复大船浮力爆发")] [assembly: AssemblyTitle("修复大船浮力爆发")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ShipBuoyancyPopFix { [BepInPlugin("jjj.fix.shipbuoyancypopfix", "修复大船浮力爆发", "1.0.2")] public class ShipBuoyancyPopFixPlugin : BaseUnityPlugin { public const string PluginGuid = "jjj.fix.shipbuoyancypopfix"; public const string PluginName = "修复大船浮力爆发"; public const string PluginVersion = "1.0.2"; internal static ManualLogSource Log; internal static ConfigEntry<bool> EnableFreeze; internal static ConfigEntry<float> FreezeDuration; internal static ConfigEntry<bool> StabilizeOnSpawn; internal static ConfigEntry<bool> DampRockSpikesWhenAnchored; private Harmony? _harmony; private void Awake() { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; EnableFreeze = ((BaseUnityPlugin)this).Config.Bind<bool>("通用设置", "EnableFreeze", true, "是否启用传送后大船物理保护"); FreezeDuration = ((BaseUnityPlugin)this).Config.Bind<float>("通用设置", "FreezeDuration", 2.5f, "传送后大船物理保护时长(秒)"); StabilizeOnSpawn = ((BaseUnityPlugin)this).Config.Bind<bool>("通用设置", "StabilizeOnSpawn", true, "大船刚在区块生成加载时,是否执行物理平稳初始化"); DampRockSpikesWhenAnchored = ((BaseUnityPlugin)this).Config.Bind<bool>("船锚保护", "DampRockSpikesWhenAnchored", true, "大船在下锚状态下若检测到速度突变立即阻尼"); _harmony = new Harmony("jjj.fix.shipbuoyancypopfix"); PatchSafe(typeof(Player_UpdateTeleport_Patch)); PatchSafe(typeof(Game_SpawnPlayer_Patch)); PatchSafe(typeof(Ship_Awake_Patch)); PatchSafe(typeof(Ship_CustomFixedUpdate_Patch)); Log.LogInfo((object)"修复大船浮力爆发 v1.0.2 已成功加载:动量彻底清除、PhysX休眠消解、解冻软着陆阻尼减震就绪。"); } private void PatchSafe(Type patchType) { try { Harmony? harmony = _harmony; if (harmony != null) { harmony.PatchAll(patchType); } Log.LogInfo((object)("成功注入补丁: " + patchType.Name)); } catch (Exception ex) { Log.LogError((object)("注入补丁 " + patchType.Name + " 失败: " + ex.Message)); } } private void OnDestroy() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void FixedUpdate() { ShipFreezeManager.UpdateFrozenBodies(); } } internal static class ShipFreezeManager { private class BodyStateRecord { public Rigidbody Body; public float UnfreezeTime; public float SoftLandingEndTime; public bool OriginalKinematic; public string ShipName = "大船"; } private static readonly Dictionary<Rigidbody, BodyStateRecord> s_records = new Dictionary<Rigidbody, BodyStateRecord>(); private static readonly List<Rigidbody> s_keysToRemove = new List<Rigidbody>(); private static readonly FieldRef<List<Ship>>? CurrentShipsRef = AccessTools.StaticFieldRefAccess<List<Ship>>(AccessTools.Field(typeof(Ship), "s_currentShips")); public static void FreezeShip(GameObject shipObj, float duration, string reason) { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) if (!ShipBuoyancyPopFixPlugin.EnableFreeze.Value || (Object)(object)shipObj == (Object)null) { return; } Rigidbody val = shipObj.GetComponent<Rigidbody>() ?? shipObj.GetComponentInParent<Rigidbody>(); if ((Object)(object)val == (Object)null) { return; } float num = Time.time + duration; float softLandingEndTime = num + 2.5f; if (s_records.TryGetValue(val, out BodyStateRecord value)) { if (num > value.UnfreezeTime) { value.UnfreezeTime = num; value.SoftLandingEndTime = softLandingEndTime; } return; } BodyStateRecord bodyStateRecord = new BodyStateRecord { Body = val, UnfreezeTime = num, SoftLandingEndTime = softLandingEndTime, OriginalKinematic = val.isKinematic, ShipName = ((Object)shipObj).name }; val.isKinematic = true; val.velocity = Vector3.zero; val.angularVelocity = Vector3.zero; s_records[val] = bodyStateRecord; ShipBuoyancyPopFixPlugin.Log.LogInfo((object)$"[修复大船浮力爆发] 已为大船【{bodyStateRecord.ShipName}】施加动量清零与物理保护(冷冻 {duration:F1}s,软着陆减震 2.5s,触发源: {reason})。"); } public static void FreezeAllNearbyShips(Vector3 center, float radius, float duration, string reason) { //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) if (!ShipBuoyancyPopFixPlugin.EnableFreeze.Value) { return; } try { List<Ship> list = ((CurrentShipsRef != null) ? CurrentShipsRef.Invoke() : null); if (list != null) { for (int i = 0; i < list.Count; i++) { Ship val = list[i]; if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null && Vector3.Distance(((Component)val).transform.position, center) <= radius) { FreezeShip(((Component)val).gameObject, duration, reason); } } } } catch { } try { MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>(); if (array == null) { return; } foreach (MonoBehaviour val2 in array) { if ((Object)(object)val2 == (Object)null) { continue; } switch (((object)val2).GetType().Name) { case "VehicleMovementController": case "ShipKeel": case "MoveableBaseRoot": if (Vector3.Distance(((Component)val2).transform.position, center) <= radius) { FreezeShip(((Component)val2).gameObject, duration, reason); } break; } } } catch { } } public static void UpdateFrozenBodies() { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) if (s_records.Count == 0) { return; } float time = Time.time; s_keysToRemove.Clear(); foreach (KeyValuePair<Rigidbody, BodyStateRecord> s_record in s_records) { Rigidbody key = s_record.Key; BodyStateRecord value = s_record.Value; if ((Object)(object)key == (Object)null || (Object)(object)((Component)key).gameObject == (Object)null) { s_keysToRemove.Add(key); } else if (time < value.UnfreezeTime) { key.isKinematic = true; key.velocity = Vector3.zero; key.angularVelocity = Vector3.zero; } else if (time < value.SoftLandingEndTime) { if (key.isKinematic) { key.isKinematic = value.OriginalKinematic; key.velocity = Vector3.zero; key.angularVelocity = Vector3.zero; key.Sleep(); ShipBuoyancyPopFixPlugin.Log.LogInfo((object)("[修复大船浮力爆发] 大船【" + value.ShipName + "】冷冻期结束,已清空积蓄动量并激活物理休眠,进入软着陆阻尼期。")); } if (key.velocity.y > 1.2f) { Vector3 velocity = key.velocity; velocity.y = 0.2f; key.velocity = velocity; key.angularVelocity = Vector3.zero; } Vector3 velocity2 = key.velocity; if (((Vector3)(ref velocity2)).sqrMagnitude > 4f) { key.velocity = Vector3.ClampMagnitude(key.velocity, 1f); key.angularVelocity = Vector3.zero; } } else { s_keysToRemove.Add(key); ShipBuoyancyPopFixPlugin.Log.LogInfo((object)("[修复大船浮力爆发] 大船【" + value.ShipName + "】物理缓冲期平稳结束,已完全恢复自主航行。")); } } for (int i = 0; i < s_keysToRemove.Count; i++) { s_records.Remove(s_keysToRemove[i]); } } } [HarmonyPatch(typeof(Player), "UpdateTeleport")] internal static class Player_UpdateTeleport_Patch { private static bool s_wasTeleporting; [HarmonyPostfix] public static void Postfix(Player __instance) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { bool flag = ((Character)__instance).IsTeleporting(); if (s_wasTeleporting && !flag) { Vector3 position = ((Component)__instance).transform.position; float value = ShipBuoyancyPopFixPlugin.FreezeDuration.Value; ShipFreezeManager.FreezeAllNearbyShips(position, 200f, value, "传送门到达"); } s_wasTeleporting = flag; } } } [HarmonyPatch(typeof(Game), "SpawnPlayer")] internal static class Game_SpawnPlayer_Patch { [HarmonyPostfix] public static void Postfix(Player __result) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__result != (Object)null && (Object)(object)__result == (Object)(object)Player.m_localPlayer) { float value = ShipBuoyancyPopFixPlugin.FreezeDuration.Value; ShipFreezeManager.FreezeAllNearbyShips(((Component)__result).transform.position, 200f, value, "玩家重生/登录入场"); } } } [HarmonyPatch(typeof(Ship), "Awake")] internal static class Ship_Awake_Patch { [HarmonyPostfix] public static void Postfix(Ship __instance) { if (ShipBuoyancyPopFixPlugin.StabilizeOnSpawn.Value && !((Object)(object)__instance == (Object)null)) { ShipFreezeManager.FreezeShip(((Component)__instance).gameObject, 2.5f, "船只区块生成加载"); } } } [HarmonyPatch(typeof(Ship), "CustomFixedUpdate")] internal static class Ship_CustomFixedUpdate_Patch { [HarmonyPostfix] public static void Postfix(Ship __instance) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || !ShipBuoyancyPopFixPlugin.DampRockSpikesWhenAnchored.Value) { return; } Rigidbody component = ((Component)__instance).GetComponent<Rigidbody>(); if ((Object)(object)component == (Object)null || component.isKinematic) { return; } bool flag = false; Component component2 = ((Component)__instance).GetComponent("VehicleMovementController"); if ((Object)(object)component2 != (Object)null) { PropertyInfo property = ((object)component2).GetType().GetProperty("isAnchored", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null) { try { flag = (bool)property.GetValue(component2); } catch { } } } if (flag) { Vector3 velocity = component.velocity; if (((Vector3)(ref velocity)).sqrMagnitude > 2f) { component.velocity = Vector3.ClampMagnitude(component.velocity, 0.2f); component.angularVelocity = Vector3.zero; } } } } }
幽灵对象清理.dll
Decompiled 13 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("幽灵对象清理")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("幽灵对象清理")] [assembly: AssemblyTitle("幽灵对象清理")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace GhostZDOFix { [BepInPlugin("jjj.fix.ghostzdofix", "幽灵对象清理与预防", "1.0.7")] public class GhostZDOFixPlugin : BaseUnityPlugin { public const string PluginGuid = "jjj.fix.ghostzdofix"; public const string PluginName = "幽灵对象清理与预防"; public const string PluginVersion = "1.0.7"; internal static ManualLogSource Log; internal static GhostZDOFixPlugin Instance; private Harmony? _harmony; private void Awake() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("jjj.fix.ghostzdofix"); PatchSafe(typeof(Patch_ZDOMan_AddToSector)); PatchSafe(typeof(Patch_ZDOMan_DestroyZDO)); PatchSafe(typeof(Patch_ZNetScene_CreateObjects)); PatchSafe(typeof(Patch_ZNetScene_CreateObject)); PatchSafe(typeof(Patch_ZNetScene_RemoveObjects)); PatchSafe(typeof(Patch_ZDOMan_HandleDestroyedZDO)); PatchSafe(typeof(Patch_ZDOMan_ConnectPortals)); PatchSafe(typeof(Patch_Game_Start)); PatchSafe(typeof(Patch_Player_OnSpawned)); PatchSafe(typeof(Patch_Chat_InputText)); Log.LogInfo((object)"幽灵对象清理与预防 v1.0.7 加载完毕:角色安全、0:0连接/销毁防火墙、联机双向RPC广播与全局重叠门去重已就绪。"); } private void PatchSafe(Type patchType) { try { Harmony? harmony = _harmony; if (harmony != null) { harmony.PatchAll(patchType); } Log.LogInfo((object)("成功注入补丁: " + patchType.Name)); } catch (Exception ex) { Log.LogError((object)("注入补丁 " + patchType.Name + " 失败: " + ex.Message)); } } private void OnDestroy() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } internal void DelayedAutoClean() { ((MonoBehaviour)this).StartCoroutine(AutoCleanRoutine()); } private IEnumerator AutoCleanRoutine() { yield return (object)new WaitForSeconds(6f); if ((Object)(object)Player.m_localPlayer == (Object)null || ((Character)Player.m_localPlayer).IsDead()) { yield break; } GhostZDOPatches.CleanAllInvalidZdosFromAllSectors(); PortalCleanResult portalCleanResult = GhostZDOPatches.CleanGhostPortals(); if (portalCleanResult.Total > 0) { string text = $"<color=green>[幽灵对象清理]</color> 自动净化完成!已清理 <color=yellow>{portalCleanResult.RemovedWaterGhosts}</color> 个海面断连孤立门,并将 <color=yellow>{portalCleanResult.DeduplicatedPortals}</color> 个重叠堆积的传送门安全合并。"; Log.LogInfo((object)text); if ((Object)(object)Chat.instance != (Object)null) { ((Terminal)Chat.instance).AddString(text); } BroadcastCleanPortals(); } } internal static void BroadcastCleanPortals() { try { if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.InvokeRoutedRPC(0L, "JJJ_CleanPortals", Array.Empty<object>()); } } catch { } } } public struct PortalCleanResult { public int RemovedWaterGhosts; public int DeduplicatedPortals; public int Total => RemovedWaterGhosts + DeduplicatedPortals; } [HarmonyPatch(typeof(ZDOMan), "AddToSector")] internal static class Patch_ZDOMan_AddToSector { [HarmonyPrefix] public static bool Prefix(ZDO zdo, SectorIndex sectorIndex) { if (zdo == null || ((ZDOID)(ref zdo.m_uid)).IsNone()) { return false; } return true; } } [HarmonyPatch(typeof(ZDOMan), "DestroyZDO", new Type[] { typeof(ZDO) })] internal static class Patch_ZDOMan_DestroyZDO { [HarmonyPrefix] public static bool Prefix(ZDO zdo) { if (zdo == null) { return false; } if (((ZDOID)(ref zdo.m_uid)).IsNone()) { GhostZDOPatches.PurgeDeadZdoDirect(zdo); return false; } return true; } } [HarmonyPatch(typeof(ZNetScene), "CreateObjects")] internal static class Patch_ZNetScene_CreateObjects { [HarmonyPrefix] public static void Prefix(List<ZDO> currentNearObjects, List<ZDO> currentDistantObjects) { PurgeDeadList(currentNearObjects); PurgeDeadList(currentDistantObjects); } private static void PurgeDeadList(List<ZDO>? list) { if (list == null || list.Count == 0) { return; } for (int num = list.Count - 1; num >= 0; num--) { ZDO val = list[num]; if (val == null || ((ZDOID)(ref val.m_uid)).IsNone()) { list.RemoveAt(num); if (val != null) { GhostZDOPatches.PurgeDeadZdoDirect(val); } } } } } [HarmonyPatch(typeof(ZNetScene), "CreateObject")] internal static class Patch_ZNetScene_CreateObject { [HarmonyPrefix] public static bool Prefix(ZDO zdo, ref GameObject? __result) { if (zdo == null || ((ZDOID)(ref zdo.m_uid)).IsNone()) { __result = null; return false; } return true; } } [HarmonyPatch(typeof(ZNetScene), "RemoveObjects")] internal static class Patch_ZNetScene_RemoveObjects { private static readonly FieldRef<ZNetScene, Dictionary<ZDO, ZNetView>> InstancesRef = AccessTools.FieldRefAccess<ZNetScene, Dictionary<ZDO, ZNetView>>("m_instances"); [HarmonyPrefix] [HarmonyPriority(600)] public static void Prefix(ZNetScene __instance) { if ((Object)(object)__instance == (Object)null) { return; } Dictionary<ZDO, ZNetView> dictionary = InstancesRef.Invoke(__instance); if (dictionary == null) { return; } List<ZDO> list = null; foreach (KeyValuePair<ZDO, ZNetView> item in dictionary) { ZNetView value = item.Value; if (!Object.op_Implicit((Object)(object)value) || (Object)(object)value == (Object)null || (Object)(object)((Component)value).gameObject == (Object)null) { if (list == null) { list = new List<ZDO>(); } list.Add(item.Key); continue; } ZDO zDO = value.GetZDO(); if (zDO == null || ((ZDOID)(ref zDO.m_uid)).IsNone()) { if (list == null) { list = new List<ZDO>(); } list.Add(item.Key); } } if (list != null) { for (int i = 0; i < list.Count; i++) { dictionary.Remove(list[i]); } } GhostZDOPatches.CheckPeriodicSweep(); } } [HarmonyPatch(typeof(ZDOMan), "HandleDestroyedZDO")] internal static class Patch_ZDOMan_HandleDestroyedZDO { [HarmonyPrefix] public static bool Prefix(ZDOID uid) { return !((ZDOID)(ref uid)).IsNone(); } } [HarmonyPatch(typeof(ZDOMan), "ConnectPortals")] internal static class Patch_ZDOMan_ConnectPortals { [HarmonyPrefix] public static void Prefix(ZDOMan __instance) { if (__instance == null) { return; } List<ZDO> portalList = __instance.GetPortalList(); if (portalList == null || portalList.Count == 0) { return; } for (int num = portalList.Count - 1; num >= 0; num--) { ZDO val = portalList[num]; if (val == null || ((ZDOID)(ref val.m_uid)).IsNone() || ((ZDOID)(ref val.m_uid)).ID == 0 || val.GetPrefab() == 0) { portalList.RemoveAt(num); } } } } [HarmonyPatch(typeof(Game), "Start")] internal static class Patch_Game_Start { [HarmonyPostfix] public static void Postfix() { if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.Register("JJJ_CleanPortals", (Action<long>)OnRPC_CleanPortals); GhostZDOFixPlugin.Log.LogInfo((object)"成功注册联机全房间传送门同步净化 RPC: JJJ_CleanPortals"); } } private static void OnRPC_CleanPortals(long sender) { GhostZDOFixPlugin.Log.LogInfo((object)$"[幽灵对象清理] 收到来自玩家({sender})的联机全图传送门同步清理广播,正在同步净化本地缓存..."); PortalCleanResult portalCleanResult = GhostZDOPatches.CleanGhostPortals(); if (portalCleanResult.Total > 0 && (Object)(object)Chat.instance != (Object)null) { ((Terminal)Chat.instance).AddString($"<color=green>[幽灵对象清理]</color> 联机同步净化:已清理本地 <color=yellow>{portalCleanResult.RemovedWaterGhosts}</color> 个幽灵门,合并去重 <color=yellow>{portalCleanResult.DeduplicatedPortals}</color> 个重叠门。"); } } } [HarmonyPatch(typeof(Player), "OnSpawned")] internal static class Patch_Player_OnSpawned { private static bool s_hasAutoCleanedForSession; [HarmonyPostfix] public static void Postfix() { if (!s_hasAutoCleanedForSession) { s_hasAutoCleanedForSession = true; GhostZDOPatches.CleanAllInvalidZdosFromAllSectors(); GhostZDOFixPlugin.Instance?.DelayedAutoClean(); } } } [HarmonyPatch(typeof(Chat), "InputText")] internal static class Patch_Chat_InputText { [HarmonyPrefix] public static bool Prefix(Chat __instance, TMP_InputField ___m_input) { if ((Object)(object)___m_input == (Object)null || string.IsNullOrWhiteSpace(___m_input.text)) { return true; } string text = ___m_input.text.Trim(); if (text.Equals("/fixportals", StringComparison.OrdinalIgnoreCase) || text.Equals("/cleanportals", StringComparison.OrdinalIgnoreCase)) { ___m_input.text = ""; PortalCleanResult portalCleanResult = GhostZDOPatches.CleanGhostPortals(); if ((Object)(object)__instance != (Object)null) { ((Terminal)__instance).AddString($"<color=green>[幽灵对象清理]</color> 净化扫描完成!已清理 <color=yellow>{portalCleanResult.RemovedWaterGhosts}</color> 个海面孤立门,合并去重 <color=yellow>{portalCleanResult.DeduplicatedPortals}</color> 个堆叠重叠传送门!大地图与传送列表已恢复清爽。"); } GhostZDOFixPlugin.BroadcastCleanPortals(); return false; } return true; } } internal static class GhostZDOPatches { private class PortalInfo { public ZDO Zdo; public Vector3 Pos; public string Tag = ""; public int MBParentId; public ZNetView? View; public bool HasPhysical; } private static readonly FieldRef<ZDOMan, List<ZDO>[]> ObjectsBySectorRef = AccessTools.FieldRefAccess<ZDOMan, List<ZDO>[]>("m_objectsBySector"); private static float s_lastSweepTime = 0f; private const float SweepInterval = 30f; public static PortalCleanResult CleanGhostPortals() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_04ec: Unknown result type (might be due to invalid IL or missing references) //IL_04f3: Unknown result type (might be due to invalid IL or missing references) PortalCleanResult result = default(PortalCleanResult); if (ZDOMan.instance == null) { return result; } List<ZDO> portalList = ZDOMan.instance.GetPortalList(); if (portalList == null || portalList.Count == 0) { return result; } float num = (((Object)(object)ZoneSystem.instance != (Object)null) ? ZoneSystem.instance.m_waterLevel : 30f); HashSet<ZDO> hashSet = new HashSet<ZDO>(); ZDOID val = ZDOID.None; if ((Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).GetZDOID() != ZDOID.None) { val = ((Character)Player.m_localPlayer).GetZDOID(); } List<PortalInfo> list = new List<PortalInfo>(portalList.Count); for (int i = 0; i < portalList.Count; i++) { ZDO val2 = portalList[i]; if (val2 == null) { continue; } if (((ZDOID)(ref val2.m_uid)).IsNone() || val2.GetPrefab() == 0 || val2.m_uid == val) { if (val2.m_uid != val) { hashSet.Add(val2); } continue; } string tag = val2.GetString("tag", ""); int mBParentId = val2.GetInt("MBParentId", 0); Vector3 position = val2.GetPosition(); ZNetView val3 = null; if ((Object)(object)ZNetScene.instance != (Object)null) { val3 = ZNetScene.instance.FindInstance(val2); } list.Add(new PortalInfo { Zdo = val2, Pos = position, Tag = tag, MBParentId = mBParentId, View = val3, HasPhysical = ((Object)(object)val3 != (Object)null && (Object)(object)((Component)val3).gameObject != (Object)null) }); } bool[] array = new bool[list.Count]; for (int j = 0; j < list.Count; j++) { if (array[j]) { continue; } PortalInfo portalInfo = list[j]; List<int> list2 = new List<int> { j }; for (int k = j + 1; k < list.Count; k++) { if (!array[k]) { PortalInfo portalInfo2 = list[k]; bool num2 = portalInfo.MBParentId != 0 && portalInfo.MBParentId == portalInfo2.MBParentId; float num3 = (portalInfo.Pos.x - portalInfo2.Pos.x) * (portalInfo.Pos.x - portalInfo2.Pos.x) + (portalInfo.Pos.z - portalInfo2.Pos.z) * (portalInfo.Pos.z - portalInfo2.Pos.z); float num4 = Mathf.Abs(portalInfo.Pos.y - portalInfo2.Pos.y); bool flag = num3 <= 16f && num4 <= 5f; bool flag2 = string.Equals(portalInfo.Tag, portalInfo2.Tag, StringComparison.OrdinalIgnoreCase); if ((num2 && (flag2 || flag)) || (flag && flag2)) { list2.Add(k); } } } if (list2.Count <= 1) { continue; } int num5 = list2[0]; for (int l = 1; l < list2.Count; l++) { int num6 = list2[l]; PortalInfo portalInfo3 = list[num6]; PortalInfo portalInfo4 = list[num5]; if (portalInfo3.HasPhysical && !portalInfo4.HasPhysical) { num5 = num6; } else if (portalInfo3.HasPhysical == portalInfo4.HasPhysical && ((ZDOID)(ref portalInfo3.Zdo.m_uid)).ID > ((ZDOID)(ref portalInfo4.Zdo.m_uid)).ID) { num5 = num6; } } for (int m = 0; m < list2.Count; m++) { int num7 = list2[m]; array[num7] = true; if (num7 == num5) { continue; } PortalInfo portalInfo5 = list[num7]; hashSet.Add(portalInfo5.Zdo); result.DeduplicatedPortals++; if (!((Object)(object)portalInfo5.View != (Object)null) || !((Object)(object)((Component)portalInfo5.View).gameObject != (Object)null)) { continue; } try { ZNetScene instance = ZNetScene.instance; if (instance != null) { instance.Destroy(((Component)portalInfo5.View).gameObject); } } catch { } } } for (int n = 0; n < list.Count; n++) { PortalInfo portalInfo6 = list[n]; if (hashSet.Contains(portalInfo6.Zdo) || !(portalInfo6.Pos.y <= num + 3.5f) || portalInfo6.HasPhysical) { continue; } bool flag3 = false; try { FieldRef<List<Ship>> obj2 = AccessTools.StaticFieldRefAccess<List<Ship>>(AccessTools.Field(typeof(Ship), "s_currentShips")); List<Ship> list3 = ((obj2 != null) ? obj2.Invoke() : null); if (list3 != null) { for (int num8 = 0; num8 < list3.Count; num8++) { if ((Object)(object)list3[num8] != (Object)null && Vector3.Distance(((Component)list3[num8]).transform.position, portalInfo6.Pos) < 15f) { flag3 = true; break; } } } } catch { } if (!flag3 || (portalInfo6.MBParentId == 0 && string.IsNullOrWhiteSpace(portalInfo6.Tag))) { hashSet.Add(portalInfo6.Zdo); result.RemovedWaterGhosts++; } } for (int num9 = portalList.Count - 1; num9 >= 0; num9--) { ZDO val4 = portalList[num9]; if (val4 == null || hashSet.Contains(val4)) { portalList.RemoveAt(num9); } } foreach (ZDO item in hashSet) { if (item != null) { try { ZDOMan.instance.DestroyZDO(item); } catch { } PurgeDeadZdoDirect(item); } } return result; } public static void PurgeDeadZdoDirect(ZDO? zdo) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) if (zdo == null || ZDOMan.instance == null) { return; } try { ZDOMan.instance.RemoveFromSector(zdo, zdo.GetSectorIndex()); } catch { } try { List<ZDO>[] array = ObjectsBySectorRef.Invoke(ZDOMan.instance); if (array != null) { for (int i = 0; i < array.Length && (array[i] == null || !array[i].Remove(zdo)); i++) { } } } catch { } } public static void CheckPeriodicSweep() { if (!(Time.unscaledTime - s_lastSweepTime < 30f)) { s_lastSweepTime = Time.unscaledTime; CleanAllInvalidZdosFromAllSectors(); } } public static void CleanAllInvalidZdosFromAllSectors() { ZDOMan instance = ZDOMan.instance; if (instance == null) { return; } try { List<ZDO>[] array = ObjectsBySectorRef.Invoke(instance); if (array == null) { return; } int num = 0; foreach (List<ZDO> list in array) { if (list == null || list.Count == 0) { continue; } for (int num2 = list.Count - 1; num2 >= 0; num2--) { ZDO val = list[num2]; if (val == null || ((ZDOID)(ref val.m_uid)).IsNone()) { list.RemoveAt(num2); num++; } } } if (num > 0) { GhostZDOFixPlugin.Log.LogInfo((object)$"[幽灵对象清理] 巡检安全移除了 {num} 个滞留在区块列表中的死引用条目。"); } } catch { } } } }
联机地图迷雾修复.dll
Decompiled 13 hours agousing System; using System.Collections; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using ServerSideMap; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("联机地图迷雾修复")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("联机地图迷雾修复")] [assembly: AssemblyTitle("联机地图迷雾修复")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ServerSideMapFix { [BepInPlugin("jjj.fix.serversidemapfix", "联机地图迷雾修复与防护", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class ServerSideMapFixPlugin : BaseUnityPlugin { public const string PluginGuid = "jjj.fix.serversidemapfix"; public const string PluginName = "联机地图迷雾修复与防护"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; private Harmony? _harmony; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("jjj.fix.serversidemapfix"); try { _harmony.PatchAll(typeof(ServerSideMapPatches)); Log.LogInfo((object)"联机地图迷雾修复与防护 v1.0.0 加载成功:客户端迷雾自愈、服务端全图污染拦截防火墙与指令系统已就绪。"); } catch (Exception arg) { Log.LogError((object)$"[联机地图迷雾修复] 初始化补丁失败: {arg}"); } } private void OnDestroy() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class ServerSideMapPatches { private static readonly FieldRef<Minimap, BitArray> MinimapExploredRef = AccessTools.FieldRefAccess<Minimap, BitArray>("m_explored"); private static readonly Action<ZRpc, int>? SendChunkToClientFunc = AccessTools.MethodDelegate<Action<ZRpc, int>>(AccessTools.Method(typeof(InitialMapSync), "SendChunkToClient", new Type[2] { typeof(ZRpc), typeof(int) }, (Type[])null), (object)null, true); [HarmonyPatch(typeof(InitialMapSync), "OnClientInitialData")] [HarmonyPrefix] public static bool OnClientInitialData_Prefix(ZRpc client, ZPackage mapData) { if (!Store.IsSharingMap()) { return true; } try { int pos = mapData.GetPos(); mapData.SetPos(0); int num = mapData.ReadInt(); int num2 = 65536; bool[] array = ExplorationDatabase.UnpackBoolArray(mapData, num2); mapData.SetPos(pos); int num3 = 0; for (int i = 0; i < array.Length; i++) { if (array[i]) { num3++; } } if (num3 > 25000 || (float)num3 / (float)num2 > 0.4f) { ManualLogSource log = ServerSideMapFixPlugin.Log; object[] array2 = new object[4]; object obj; if (client == null) { obj = null; } else { ISocket socket = client.GetSocket(); obj = ((socket != null) ? socket.GetHostName() : null); } if (obj == null) { obj = "Unknown"; } array2[0] = obj; array2[1] = num; array2[2] = num3; array2[3] = num2; log.LogWarning((object)string.Format("[联机地图迷雾修复] 拦截到客户端 (RPC: {0}) 上传的异常大范围探索数据 (Chunk {1}, 点数 {2}/{3}),已阻止合并至服务端,防止全图迷雾全开!", array2)); SendChunkToClientFunc?.Invoke(client, num + 1); return false; } } catch (Exception ex) { ServerSideMapFixPlugin.Log.LogWarning((object)("[联机地图迷雾修复] 检查客户端 Chunk 数据时异常: " + ex.Message)); } return true; } [HarmonyPatch(typeof(ExplorationDatabase), "MergeExplorationArray")] [HarmonyPrefix] public static bool MergeExplorationArray_Prefix(bool[] arr, int startIndex, int size) { if (arr == null) { return false; } int num = 0; for (int i = 0; i < size && i < arr.Length; i++) { if (arr[i]) { num++; } } if (size > 1000 && ((float)num / (float)size > 0.4f || num > 25000)) { ServerSideMapFixPlugin.Log.LogWarning((object)$"[联机地图迷雾修复] 拦截到大面积探索合并请求 (探索像素: {num}/{size}),已拒绝合并!"); return false; } return true; } [HarmonyPatch(typeof(InitialMapSync), "OnReceiveMapDataInitial")] [HarmonyPrefix] public static void OnReceiveMapDataInitial_Prefix(ZRpc client, ZPackage mapData) { if (!Store.IsSharingMap()) { return; } try { int pos = mapData.GetPos(); mapData.SetPos(0); int num = mapData.ReadInt(); mapData.SetPos(pos); if (num != 0) { return; } Minimap instance = Minimap.instance; if (!((Object)(object)instance != (Object)null)) { return; } BitArray bitArray = MinimapExploredRef.Invoke(instance); if (bitArray == null || bitArray.Length <= 0) { return; } int num2 = 0; for (int i = 0; i < bitArray.Length; i++) { if (bitArray.Get(i)) { num2++; } } float num3 = (float)num2 / (float)bitArray.Length; if (num3 > 0.8f) { ServerSideMapFixPlugin.Log.LogWarning((object)$"[联机地图迷雾修复] 检测到本地客户端小地图全图被污染开图 (探索率: {num3:P1})!正在重置迷雾并从服务端重新同步..."); instance.Reset(); ServerSideMapFixPlugin.Log.LogInfo((object)"[联机地图迷雾修复] 本地小地图迷雾重置成功,正在拉取服务端的真实探索进度。"); } } catch (Exception ex) { ServerSideMapFixPlugin.Log.LogWarning((object)("[联机地图迷雾修复] 客户端自愈检查异常: " + ex.Message)); } } [HarmonyPatch(typeof(Chat), "InputText")] [HarmonyPrefix] public static bool Chat_InputText_Prefix(Chat __instance, TMP_InputField ___m_input) { if ((Object)(object)___m_input == (Object)null || string.IsNullOrWhiteSpace(___m_input.text)) { return true; } string text = ___m_input.text.Trim(); if (!text.StartsWith("/fixmap", StringComparison.OrdinalIgnoreCase)) { return true; } ___m_input.text = string.Empty; string[] array = text.Split(' '); switch ((array.Length > 1) ? array[1].ToLower() : "info") { case "reset": if ((Object)(object)Minimap.instance != (Object)null) { Minimap.instance.Reset(); ShowChatMessage(__instance, "<color=green>[联机地图修复]</color> 本地小地图迷雾已重置!"); } break; case "reload": if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer()) { ReloadServerMap(__instance); } else { ShowChatMessage(__instance, "<color=red>[联机地图修复]</color> 仅限房主或专用服务端可执行 /fixmap reload 指令。"); } break; default: ShowMapInfo(__instance); break; } return false; } private static void ShowMapInfo(Chat chat) { int num = 4194304; int num2 = 0; bool[] explored = ExplorationDatabase.Explored; if (explored != null) { for (int i = 0; i < explored.Length; i++) { if (explored[i]) { num2++; } } } int num3 = 0; if ((Object)(object)Minimap.instance != (Object)null) { BitArray bitArray = MinimapExploredRef.Invoke(Minimap.instance); if (bitArray != null) { for (int j = 0; j < bitArray.Length; j++) { if (bitArray.Get(j)) { num3++; } } } } string message = "<color=yellow>[联机地图迷雾统计]</color>\n" + $"服务端探索点数: {num2:N0} / {num:N0} ({(float)num2 / (float)num:P2})\n" + $"本地客户端探索: {num3:N0} / {num:N0} ({(float)num3 / (float)num:P2})\n" + "指令说明: /fixmap reset (重置本地迷雾) | /fixmap reload (服务端重载存档)"; ShowChatMessage(chat, message); } private static void ReloadServerMap(Chat chat) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown try { World value = Traverse.Create(typeof(ZNet)).Field("m_world").GetValue<World>(); if (value == null) { ShowChatMessage(chat, "<color=red>[联机地图修复]</color> 未能获取当前世界信息。"); return; } string text = Path.ChangeExtension(value.GetDBPath(), null) + ".mod.serversidemap.explored"; if (!File.Exists(text)) { ShowChatMessage(chat, "<color=red>[联机地图修复]</color> 文件不存在: " + text); return; } ExplorationDatabase.SetMapData(new ZPackage(File.ReadAllBytes(text))); int num = 0; bool[] explored = ExplorationDatabase.Explored; if (explored != null) { for (int i = 0; i < explored.Length; i++) { if (explored[i]) { num++; } } } ShowChatMessage(chat, $"<color=green>[联机地图修复]</color> 服务端地图数据已成功从磁盘重新加载!当前探索点数: {num:N0} ({(float)num / 4194304f:P2})"); } catch (Exception ex) { ShowChatMessage(chat, "<color=red>[联机地图修复]</color> 重载失败: " + ex.Message); } } private static void ShowChatMessage(Chat chat, string message) { if ((Object)(object)chat != (Object)null) { ((Terminal)chat).AddString(message); } ServerSideMapFixPlugin.Log.LogInfo((object)message); } } }
高度图火源修复.dll
Decompiled 13 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("高度图火源修复")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("高度图火源修复")] [assembly: AssemblyTitle("高度图火源修复")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace HeightmapFireplaceFix { [BepInPlugin("jun.fix.heightmapfireplacefix", "高度图火源修复", "1.0.0")] public class HeightmapFireplaceFixPlugin : BaseUnityPlugin { public const string PluginGuid = "jun.fix.heightmapfireplacefix"; public const string PluginName = "高度图火源修复"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; private Harmony? _harmony; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("jun.fix.heightmapfireplacefix"); _harmony.PatchAll(typeof(HeightmapSafetyPatches)); Log.LogInfo((object)"高度图火源修复 v1.0.0 已成功加载:高度图越界防御与火源检测防护已就绪(极简修复,零冗余开销)。"); } private void OnDestroy() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class HeightmapSafetyPatches { private static readonly FieldRef<Heightmap, List<float>> HeightsRef = AccessTools.FieldRefAccess<Heightmap, List<float>>("m_heights"); [HarmonyPatch(typeof(Heightmap), "GetWorldHeight")] [HarmonyPrefix] public static bool Heightmap_GetWorldHeight_Prefix(Heightmap __instance, Vector3 worldPos, out float height, ref bool __result) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) List<float> list = HeightsRef.Invoke(__instance); if (list == null || list.Count == 0) { height = 0f; __result = false; return false; } int num = default(int); int num2 = default(int); __instance.WorldToVertex(worldPos, ref num, ref num2); int num3 = __instance.m_width + 1; if (num < 0 || num2 < 0 || num >= num3 || num2 >= num3) { height = 0f; __result = false; return false; } int num4 = num2 * num3 + num; if (num4 < 0 || num4 >= list.Count) { height = 0f; __result = false; return false; } height = (float)((double)list[num4] + (double)((Component)__instance).transform.position.y); __result = true; return false; } [HarmonyPatch(typeof(Heightmap), "GetHeight", new Type[] { typeof(int), typeof(int) })] [HarmonyPrefix] public static bool Heightmap_GetHeight_IntInt_Prefix(Heightmap __instance, int x, int y, ref float __result) { List<float> list = HeightsRef.Invoke(__instance); if (list == null || list.Count == 0) { __result = 0f; return false; } int num = __instance.m_width + 1; if (x < 0 || y < 0 || x >= num || y >= num) { __result = 0f; return false; } int num2 = y * num + x; if (num2 < 0 || num2 >= list.Count) { __result = 0f; return false; } __result = list[num2]; return false; } } }
汉化\ValheimModChineseLocalization.dll
Decompiled 13 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ValheimModChineseLocalization")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ValheimModChineseLocalization")] [assembly: AssemblyTitle("ValheimModChineseLocalization")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ValheimModChineseLocalization { [BepInPlugin("valheim.mod.chinese.localization", "Valheim Mod Chinese Localization", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string ModGUID = "valheim.mod.chinese.localization"; public const string ModName = "Valheim Mod Chinese Localization"; public const string ModVersion = "1.0.0"; internal static ManualLogSource Log; internal static Dictionary<string, string> Translations = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); internal static string PluginPath; private static readonly MethodInfo AddWordMethod = AccessTools.Method(typeof(Localization), "AddWord", new Type[2] { typeof(string), typeof(string) }, (Type[])null); private static readonly FieldInfo TranslationsField = AccessTools.Field(typeof(Localization), "m_translations"); private void Awake() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; PluginPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); Log.LogInfo((object)"Valheim Mod Chinese Localization v1.0.0 initializing..."); LoadTranslations(); new Harmony("valheim.mod.chinese.localization").PatchAll(); Log.LogInfo((object)"Valheim Mod Chinese Localization patches successfully applied."); } public static void LoadTranslations() { try { string text = Path.Combine(PluginPath, "translations.json"); if (!File.Exists(text)) { text = Path.Combine(Paths.PluginPath, "修复", "汉化", "translations.json"); } if (File.Exists(text)) { Dictionary<string, string> dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(text, Encoding.UTF8)); if (dictionary != null) { foreach (KeyValuePair<string, string> item in dictionary) { if (!string.IsNullOrEmpty(item.Key) && !string.IsNullOrEmpty(item.Value)) { Translations[item.Key] = item.Value; } } } Log.LogInfo((object)$"Loaded {Translations.Count} translations from {text}"); } else { Log.LogWarning((object)("translations.json not found at " + text)); } } catch (Exception arg) { Log.LogError((object)$"Error loading translations.json: {arg}"); } } public static bool TryGetTranslation(string key, out string translation) { if (string.IsNullOrEmpty(key)) { translation = null; return false; } if (Translations.TryGetValue(key, out translation)) { return true; } if (key.StartsWith("$") && Translations.TryGetValue(key.Substring(1), out translation)) { return true; } string key2 = "$" + key; if (Translations.TryGetValue(key2, out translation)) { return true; } translation = null; return false; } public static void AddWord(Localization loc, string key, string text) { if (loc == null) { return; } if (AddWordMethod != null) { try { AddWordMethod.Invoke(loc, new object[2] { key, text }); return; } catch { } } if (!(TranslationsField != null)) { return; } try { if (TranslationsField.GetValue(loc) is Dictionary<string, string> dictionary) { dictionary[key] = text; } } catch { } } public static void ApplyTranslationsToLocalization(Localization loc) { if (loc == null || Translations.Count == 0) { return; } int num = 0; foreach (KeyValuePair<string, string> translation in Translations) { AddWord(loc, translation.Key, translation.Value); if (!translation.Key.StartsWith("$")) { AddWord(loc, "$" + translation.Key, translation.Value); } num++; } Log.LogInfo((object)$"Injected {num} custom words into Localization.instance"); } } [HarmonyPatch(typeof(Localization), "SetupLanguage")] public static class Patch_Localization_SetupLanguage { [HarmonyPostfix] public static void Postfix(Localization __instance, string language) { if (!string.IsNullOrEmpty(language) && (language.IndexOf("Chinese", StringComparison.OrdinalIgnoreCase) >= 0 || language.IndexOf("Mandarin", StringComparison.OrdinalIgnoreCase) >= 0)) { Plugin.ApplyTranslationsToLocalization(__instance); } } } [HarmonyPatch(typeof(Localization), "Translate")] public static class Patch_Localization_Translate { [HarmonyPostfix] public static void Postfix(string word, ref string __result) { string translation2; if (Plugin.TryGetTranslation(word, out var translation)) { __result = translation; } else if (!string.IsNullOrEmpty(__result) && Plugin.TryGetTranslation(__result, out translation2)) { __result = translation2; } } } [HarmonyPatch(typeof(Localization), "Localize", new Type[] { typeof(string) })] public static class Patch_Localization_Localize { [HarmonyPostfix] public static void Postfix(string text, ref string __result) { if (string.IsNullOrEmpty(__result)) { return; } string translation2; if (Plugin.TryGetTranslation(__result, out var translation)) { __result = translation; } else if (!string.IsNullOrEmpty(text) && Plugin.TryGetTranslation(text, out translation2)) { __result = translation2; } else if (__result.StartsWith("Ready in ")) { __result = "成熟剩余时间: " + __result.Substring(9); } else if (__result.StartsWith("Replant as: <color=green>")) { int num = __result.IndexOf('>'); int num2 = __result.IndexOf('<', num + 1); if (num != -1 && num2 != -1 && Plugin.TryGetTranslation(__result.Substring(num + 1, num2 - num - 1), out var translation3)) { __result = "自动补种为: <color=green>" + translation3 + "</color>"; } } } } [HarmonyPatch(typeof(Character), "GetHoverName")] public static class Patch_Character_GetHoverName { [HarmonyPostfix] public static void Postfix(ref string __result) { if (!string.IsNullOrEmpty(__result) && Plugin.TryGetTranslation(__result, out var translation)) { __result = translation; } } } [HarmonyPatch(typeof(Character), "GetHoverText")] public static class Patch_Character_GetHoverText { [HarmonyPostfix] public static void Postfix(ref string __result) { if (!string.IsNullOrEmpty(__result) && Plugin.TryGetTranslation(__result, out var translation)) { __result = translation; } } } [HarmonyPatch(typeof(Piece), "Awake")] public static class Patch_Piece_Awake { [HarmonyPostfix] public static void Postfix(Piece __instance) { if (!((Object)(object)__instance == (Object)null)) { if (!string.IsNullOrEmpty(__instance.m_name) && Plugin.TryGetTranslation(__instance.m_name, out var translation)) { __instance.m_name = translation; } if (!string.IsNullOrEmpty(__instance.m_description) && Plugin.TryGetTranslation(__instance.m_description, out var translation2)) { __instance.m_description = translation2; } } } } [HarmonyPatch(typeof(ObjectDB), "Awake")] public static class Patch_ObjectDB_Awake { [HarmonyPostfix] public static void Postfix(ObjectDB __instance) { ObjectDBUpdater.UpdateObjectDB(__instance); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] public static class Patch_ObjectDB_CopyOtherDB { [HarmonyPostfix] public static void Postfix(ObjectDB __instance) { ObjectDBUpdater.UpdateObjectDB(__instance); } } public static class ObjectDBUpdater { public static void UpdateObjectDB(ObjectDB db) { if ((Object)(object)db == (Object)null) { return; } if (db.m_items != null) { foreach (GameObject item in db.m_items) { if ((Object)(object)item == (Object)null) { continue; } ItemDrop component = item.GetComponent<ItemDrop>(); if (!((Object)(object)component == (Object)null) && component.m_itemData != null && component.m_itemData.m_shared != null) { SharedData shared = component.m_itemData.m_shared; if (!string.IsNullOrEmpty(shared.m_name) && Plugin.TryGetTranslation(shared.m_name, out var translation)) { shared.m_name = translation; } if (!string.IsNullOrEmpty(shared.m_description) && Plugin.TryGetTranslation(shared.m_description, out var translation2)) { shared.m_description = translation2; } } } } if (db.m_StatusEffects == null) { return; } foreach (StatusEffect statusEffect in db.m_StatusEffects) { if (!((Object)(object)statusEffect == (Object)null) && !string.IsNullOrEmpty(statusEffect.m_name) && Plugin.TryGetTranslation(statusEffect.m_name, out var translation3)) { statusEffect.m_name = translation3; } } } } [HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(ItemData), typeof(int), typeof(bool), typeof(float), typeof(int), typeof(bool) })] public static class Patch_ItemData_GetTooltip { [HarmonyPostfix] public static void Postfix(ItemData item, ref string __result) { if (item != null && !string.IsNullOrEmpty(__result) && item.m_shared != null && !string.IsNullOrEmpty(item.m_shared.m_description) && Plugin.TryGetTranslation(item.m_shared.m_description, out var translation)) { __result = __result.Replace(item.m_shared.m_description, translation); } } } }