private void *PrintMessageDetour(RaptureLogModule *raptureLogModule, XivChatType xivChatType, IntPtr senderName, IntPtr message, uint senderId, byte param) { try { if (chatTypes.Contains(xivChatType)) { // Need to hook it manually to handle changing the name until API4 var stdSender = StdString.ReadFromPointer(senderName); var parsedSender = SeString.Parse(stdSender.RawData); if (Parse(ref parsedSender)) { stdSender.RawData = parsedSender.Encode(); var allocatedString = Service.LibcFunction.NewString(stdSender.RawData); var retVal = printChatHook.Original(raptureLogModule, xivChatType, allocatedString.Address, message, senderId, param); allocatedString.Dispose(); return(retVal); } } } catch (Exception ex) { SimpleLog.Error(ex); } return(printChatHook.Original(raptureLogModule, xivChatType, senderName, message, senderId, param)); }
private IntPtr HandlePrintMessageDetour(IntPtr manager, XivChatType chattype, IntPtr pSenderName, IntPtr pMessage, uint senderid, IntPtr parameter) { IntPtr retVal = IntPtr.Zero; try { var senderName = StdString.ReadFromPointer(pSenderName); var message = StdString.ReadFromPointer(pMessage); Log.Debug($"HandlePrintMessageDetour {manager} - [{chattype}] [{BitConverter.ToString(message.RawData).Replace("-", " ")}] {message.Value} from {senderName.Value}"); // Log.Debug($"Got message bytes {BitConverter.ToString(messageBytes.Bytes).Replace("-", " ")}"); var originalMessageData = (byte[])message.RawData.Clone(); // Call events var isHandled = false; OnChatMessage?.Invoke(chattype, senderid, ref senderName, ref message, ref isHandled); var messagePtr = pMessage; OwnedStdString allocatedString = null; if (!FastByteArrayCompare(originalMessageData, message.RawData)) { allocatedString = this.dalamud.Framework.Libc.NewString(message.RawData); Log.Debug( $"HandlePrintMessageDetour String modified: {originalMessageData}({messagePtr}) -> {message}({allocatedString.Address})"); messagePtr = allocatedString.Address; } // Print the original chat if it's handled. if (!isHandled) { retVal = this.printMessageHook.Original(manager, chattype, pSenderName, messagePtr, senderid, parameter); } if (this.baseAddress == IntPtr.Zero) { this.baseAddress = manager; } allocatedString?.Dispose(); } catch (Exception ex) { Log.Error(ex, "Exception on OnChatMessage hook."); retVal = this.printMessageHook.Original(manager, chattype, pSenderName, pMessage, senderid, parameter); } return(retVal); }
private IntPtr HandlePrintMessageDetour(IntPtr manager, XivChatType chattype, IntPtr pSenderName, IntPtr pMessage, uint senderid, IntPtr parameter) { var retVal = IntPtr.Zero; try { var sender = StdString.ReadFromPointer(pSenderName); var message = StdString.ReadFromPointer(pMessage); var parsedSender = this.dalamud.SeStringManager.Parse(sender.RawData); var parsedMessage = this.dalamud.SeStringManager.Parse(message.RawData); Log.Verbose("[CHATGUI][{0}][{1}]", parsedSender.TextValue, parsedMessage.TextValue); //Log.Debug($"HandlePrintMessageDetour {manager} - [{chattype}] [{BitConverter.ToString(message.RawData).Replace("-", " ")}] {message.Value} from {senderName.Value}"); var originalMessageData = (byte[])message.RawData.Clone(); var oldEdited = parsedMessage.Encode(); // Call events var isHandled = false; OnCheckMessageHandled?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled); if (!isHandled) { OnChatMessage?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled); OnChatMessageRaw?.Invoke(chattype, senderid, ref sender, ref message, ref isHandled); } var newEdited = parsedMessage.Encode(); if (!FastByteArrayCompare(oldEdited, newEdited)) { Log.Verbose("SeString was edited, taking precedence over StdString edit."); message.RawData = newEdited; Log.Debug($"\nOLD: {BitConverter.ToString(originalMessageData)}\nNEW: {BitConverter.ToString(newEdited)}"); } var messagePtr = pMessage; OwnedStdString allocatedString = null; if (!FastByteArrayCompare(originalMessageData, message.RawData)) { allocatedString = this.dalamud.Framework.Libc.NewString(message.RawData); Log.Debug( $"HandlePrintMessageDetour String modified: {originalMessageData}({messagePtr}) -> {message}({allocatedString.Address})"); messagePtr = allocatedString.Address; } // Print the original chat if it's handled. if (isHandled) { OnChatMessageHandled?.Invoke(chattype, senderid, parsedSender, parsedMessage); } else { retVal = this.printMessageHook.Original(manager, chattype, pSenderName, messagePtr, senderid, parameter); OnChatMessageUnhandled?.Invoke(chattype, senderid, parsedSender, parsedMessage); } if (this.baseAddress == IntPtr.Zero) { this.baseAddress = manager; } allocatedString?.Dispose(); } catch (Exception ex) { Log.Error(ex, "Exception on OnChatMessage hook."); retVal = this.printMessageHook.Original(manager, chattype, pSenderName, pMessage, senderid, parameter); } return(retVal); }
/// <summary> /// Read the wrapped StdString. /// </summary> /// <returns>The StdString.</returns> public StdString Read() => StdString.ReadFromPointer(this.Address);