even more violation checks....
This commit is contained in:
@@ -962,50 +962,68 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
{
|
{
|
||||||
var gameObj = (GameObject*)address;
|
var gameObj = (GameObject*)address;
|
||||||
|
|
||||||
if (gameObj == null || gameObj->ObjectKind == 0)
|
if (gameObj == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!IsGameObjectPresent(address))
|
if (!_objectTable.Any(o => o?.Address == address))
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Character {name} at {addr} no longer present in object table", characterName, address.ToString("X"));
|
_logger.LogDebug("Character {name} at {addr} no longer in object table", characterName, address.ToString("X"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gameObj->ObjectKind == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
var drawObj = gameObj->DrawObject;
|
var drawObj = gameObj->DrawObject;
|
||||||
bool isDrawing = false;
|
bool isDrawing = false;
|
||||||
bool isDrawingChanged = false;
|
bool isDrawingChanged = false;
|
||||||
|
|
||||||
if ((nint)drawObj != IntPtr.Zero)
|
if ((nint)drawObj != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
isDrawing = gameObj->RenderFlags == (VisibilityFlags)0b100000000000;
|
try
|
||||||
|
{
|
||||||
|
isDrawing = gameObj->RenderFlags == (VisibilityFlags)0b100000000000;
|
||||||
|
}
|
||||||
|
catch (AccessViolationException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isDrawing)
|
if (!isDrawing)
|
||||||
{
|
{
|
||||||
var charBase = (CharacterBase*)drawObj;
|
try
|
||||||
if (charBase != null)
|
|
||||||
{
|
{
|
||||||
isDrawing = charBase->HasModelInSlotLoaded != 0;
|
var charBase = (CharacterBase*)drawObj;
|
||||||
if (!isDrawing)
|
if (charBase != null)
|
||||||
{
|
{
|
||||||
isDrawing = charBase->HasModelFilesInSlotLoaded != 0;
|
isDrawing = charBase->HasModelInSlotLoaded != 0;
|
||||||
if (isDrawing && !string.Equals(_lastGlobalBlockPlayer, characterName, StringComparison.Ordinal)
|
if (!isDrawing)
|
||||||
&& !string.Equals(_lastGlobalBlockReason, "HasModelFilesInSlotLoaded", StringComparison.Ordinal))
|
|
||||||
{
|
{
|
||||||
_lastGlobalBlockPlayer = characterName;
|
isDrawing = charBase->HasModelFilesInSlotLoaded != 0;
|
||||||
_lastGlobalBlockReason = "HasModelFilesInSlotLoaded";
|
if (isDrawing && !string.Equals(_lastGlobalBlockPlayer, characterName, StringComparison.Ordinal)
|
||||||
isDrawingChanged = true;
|
&& !string.Equals(_lastGlobalBlockReason, "HasModelFilesInSlotLoaded", StringComparison.Ordinal))
|
||||||
}
|
{
|
||||||
}
|
_lastGlobalBlockPlayer = characterName;
|
||||||
else
|
_lastGlobalBlockReason = "HasModelFilesInSlotLoaded";
|
||||||
{
|
isDrawingChanged = true;
|
||||||
if (!string.Equals(_lastGlobalBlockPlayer, characterName, StringComparison.Ordinal)
|
}
|
||||||
&& !string.Equals(_lastGlobalBlockReason, "HasModelInSlotLoaded", StringComparison.Ordinal))
|
}
|
||||||
{
|
else
|
||||||
_lastGlobalBlockPlayer = characterName;
|
{
|
||||||
_lastGlobalBlockReason = "HasModelInSlotLoaded";
|
if (!string.Equals(_lastGlobalBlockPlayer, characterName, StringComparison.Ordinal)
|
||||||
isDrawingChanged = true;
|
&& !string.Equals(_lastGlobalBlockReason, "HasModelInSlotLoaded", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
_lastGlobalBlockPlayer = characterName;
|
||||||
|
_lastGlobalBlockReason = "HasModelInSlotLoaded";
|
||||||
|
isDrawingChanged = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (AccessViolationException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1028,7 +1046,11 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
}
|
}
|
||||||
catch (AccessViolationException ex)
|
catch (AccessViolationException ex)
|
||||||
{
|
{
|
||||||
_logger.LogWarning(ex, "access violation checking character {name} at {addr}", characterName, address.ToString("X"));
|
_logger.LogDebug(ex, "Memory access violation checking character {name} at {addr}", characterName, address.ToString("X"));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Unexpected error checking character {name} at {addr}", characterName, address.ToString("X"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1057,51 +1079,79 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
|
|||||||
_actorObjectService.RefreshTrackedActors();
|
_actorObjectService.RefreshTrackedActors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CRITICAL: Capture snapshot once to prevent mid-iteration changes
|
||||||
var playerDescriptors = _actorObjectService.PlayerDescriptors;
|
var playerDescriptors = _actorObjectService.PlayerDescriptors;
|
||||||
for (var i = 0; i < playerDescriptors.Count; i++)
|
var descriptorCount = playerDescriptors.Count;
|
||||||
|
|
||||||
|
for (var i = 0; i < descriptorCount; i++)
|
||||||
{
|
{
|
||||||
var actor = playerDescriptors[i];
|
try
|
||||||
|
|
||||||
var playerAddress = actor.Address;
|
|
||||||
if (playerAddress == nint.Zero)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (actor.ObjectIndex >= 200)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (_blockedCharacterHandler.IsCharacterBlocked(playerAddress, actor.ObjectIndex, out bool firstTime) && firstTime)
|
|
||||||
{
|
{
|
||||||
_logger.LogTrace("Skipping character {addr}, blocked/muted", playerAddress.ToString("X"));
|
// Revalidate the count in case collection changed
|
||||||
continue;
|
if (i >= playerDescriptors.Count)
|
||||||
}
|
break;
|
||||||
|
|
||||||
if (!IsAnythingDrawing)
|
var actor = playerDescriptors[i];
|
||||||
{
|
|
||||||
try
|
var playerAddress = actor.Address;
|
||||||
|
if (playerAddress == nint.Zero)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (actor.ObjectIndex >= 200)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (_blockedCharacterHandler.IsCharacterBlocked(playerAddress, actor.ObjectIndex, out bool firstTime) && firstTime)
|
||||||
{
|
{
|
||||||
var gameObj = (GameObject*)playerAddress;
|
_logger.LogTrace("Skipping character {addr}, blocked/muted", playerAddress.ToString("X"));
|
||||||
|
|
||||||
if (gameObj == null || gameObj->ObjectKind == 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var currentName = gameObj->NameString ?? string.Empty;
|
|
||||||
var charaName = string.IsNullOrEmpty(currentName) ? actor.Name : currentName;
|
|
||||||
|
|
||||||
CheckCharacterForDrawing(playerAddress, charaName);
|
|
||||||
|
|
||||||
if (IsAnythingDrawing)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
catch (AccessViolationException ex)
|
|
||||||
{
|
|
||||||
_logger.LogWarning(ex, "Memory access violation reading character at {addr}", playerAddress.ToString("X"));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!IsAnythingDrawing)
|
||||||
|
{
|
||||||
|
// Wrap ALL pointer access in try-catch
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var gameObj = (GameObject*)playerAddress;
|
||||||
|
|
||||||
|
if (gameObj == null || gameObj->ObjectKind == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get name with protection - NameString internally dereferences pointers
|
||||||
|
string currentName;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
currentName = gameObj->NameString ?? string.Empty;
|
||||||
|
}
|
||||||
|
catch (AccessViolationException)
|
||||||
|
{
|
||||||
|
currentName = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var charaName = string.IsNullOrEmpty(currentName) ? actor.Name : currentName;
|
||||||
|
|
||||||
|
CheckCharacterForDrawing(playerAddress, charaName);
|
||||||
|
|
||||||
|
if (IsAnythingDrawing)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (AccessViolationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogDebug(ex, "Access violation on GameObject pointer for actor {index} at {addr}", i, playerAddress.ToString("X"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (AccessViolationException ex)
|
||||||
|
{
|
||||||
|
_logger.LogDebug(ex, "Access violation processing actor {index} - object likely destroyed", i);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Unexpected error processing actor {index}", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!IsAnythingDrawing && !string.IsNullOrEmpty(_lastGlobalBlockPlayer))
|
if (!IsAnythingDrawing && !string.IsNullOrEmpty(_lastGlobalBlockPlayer))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user