mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Correctly check for changed messages
This commit is contained in:
parent
c1aeaceb47
commit
92f8ad0fd8
2 changed files with 26 additions and 3 deletions
|
|
@ -91,7 +91,7 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
Log.Debug($"HandlePrintMessageDetour {manager} - [{chattype}] [{BitConverter.ToString(message.RawData).Replace("-", " ")}] {message} from {senderName}");
|
||||
// Log.Debug($"Got message bytes {BitConverter.ToString(messageBytes.Bytes).Replace("-", " ")}");
|
||||
|
||||
var originalMessage = message.RawData.Clone();
|
||||
var originalMessageData = (byte[]) message.RawData.Clone();
|
||||
|
||||
// Call events
|
||||
var isHandled = false;
|
||||
|
|
@ -100,10 +100,10 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
var messagePtr = pMessage;
|
||||
OwnedStdString allocatedString = null;
|
||||
|
||||
if (originalMessage != message.RawData) {
|
||||
if (!FastByteArrayCompare(originalMessageData, message.RawData)) {
|
||||
allocatedString = this.dalamud.Framework.Libc.NewString(message.RawData);
|
||||
Log.Debug(
|
||||
$"HandlePrintMessageDetour String modified: {originalMessage}({messagePtr}) -> {message}({allocatedString.Address})");
|
||||
$"HandlePrintMessageDetour String modified: {originalMessageData}({messagePtr}) -> {message}({allocatedString.Address})");
|
||||
messagePtr = allocatedString.Address;
|
||||
}
|
||||
|
||||
|
|
@ -123,6 +123,28 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
// Copyright (c) 2008-2013 Hafthor Stefansson
|
||||
// Distributed under the MIT/X11 software license
|
||||
// Ref: http://www.opensource.org/licenses/mit-license.php.
|
||||
// https://stackoverflow.com/a/8808245
|
||||
static unsafe bool FastByteArrayCompare(byte[] a1, byte[] a2)
|
||||
{
|
||||
if (a1 == a2) return true;
|
||||
if (a1 == null || a2 == null || a1.Length != a2.Length)
|
||||
return false;
|
||||
fixed (byte* p1 = a1, p2 = a2)
|
||||
{
|
||||
byte* x1 = p1, x2 = p2;
|
||||
int l = a1.Length;
|
||||
for (int i = 0; i < l / 8; i++, x1 += 8, x2 += 8)
|
||||
if (*((long*)x1) != *((long*)x2)) return false;
|
||||
if ((l & 4) != 0) { if (*((int*)x1) != *((int*)x2)) return false; x1 += 4; x2 += 4; }
|
||||
if ((l & 2) != 0) { if (*((short*)x1) != *((short*)x2)) return false; x1 += 2; x2 += 2; }
|
||||
if ((l & 1) != 0) if (*((byte*)x1) != *((byte*)x2)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queue a chat message. While method is named as PrintChat, it only add a entry to the queue,
|
||||
/// later to be processed when UpdateQueue() is called.
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ namespace Dalamud.Game.Internal.Gui {
|
|||
public void Enable() {
|
||||
this.iconHook.Enable();
|
||||
this.checkerHook.Enable();
|
||||
Log.Verbose("IconReplacer hooked");
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue