using System; using HarmonyLib; using UnityEngine; namespace NecromancerTome { /// /// Диагностика (23.10.2026): NullReferenceException внутри ItemActionAttack.Hit при попадании стрелы (ProjectileMoveScript.checkCollision) /// - пачками по одной стреле (исключение вылетает раньше, чем стрела сменит состояние, и она «попадает» снова каждый шаг физики). /// Было дважды, рядом с только что догруженными зомби спящих зон. Здесь только запись в лог, во что попала стрела; исключение /// уходит дальше как было. Не больше MaxLogs записей за запуск. Убрать, когда причина найдена. /// [HarmonyPatch(typeof(ItemActionAttack), nameof(ItemActionAttack.Hit))] public static class Patch_ItemActionAttack_Hit_Diag { const int MaxLogs = 5; static int _logged; public static Exception Finalizer(Exception __exception, WorldRayHitInfo hitInfo, int _attackerEntityId, ItemValue damagingItemValue) { if (__exception == null || _logged >= MaxLogs) { return __exception; } _logged++; try { string s = "tag=" + (hitInfo?.tag ?? "null") + ", transform=" + (hitInfo?.transform != null ? hitInfo.transform.name : "NULL") + ", collider=" + (hitInfo?.hitCollider != null ? hitInfo.hitCollider.name : "NULL"); if (hitInfo != null && hitInfo.tag != null && hitInfo.tag.StartsWith("E_")) { Entity e = ItemActionAttack.FindHitEntityNoTagCheck(hitInfo, out string part); s += ", entity=" + (e == null ? "NULL" : e.GetType().Name + " " + EntityClass.list[e.entityClass].entityClassName + " " + e.entityId + (e is EntityAlive ea ? (ea.IsDead() ? " dead" : " alive") + ", emodel " + (ea.emodel != null) : "")) + ", part=" + (part ?? "null"); } Entity atk = GameManager.Instance?.World?.GetEntity(_attackerEntityId); s += ", attacker=" + (atk == null ? "NULL " + _attackerEntityId : atk.GetType().Name + " " + atk.entityId) + ", item=" + (damagingItemValue?.ItemClass?.Name ?? "null"); Debug.Log("[NecromancerTome] HitDiag: исключение в ItemActionAttack.Hit (" + __exception.GetType().Name + "): " + s + "\n" + __exception.StackTrace); } catch (Exception e2) { Debug.Log("[NecromancerTome] HitDiag: не удалось описать попадание - " + e2.Message); } return __exception; } } }