|
| 1 | +namespace BattlefieldRichPresence.GameReader |
| 2 | +{ |
| 3 | + internal class Chat |
| 4 | + { |
| 5 | + public const int OFFSET_CHAT_LAST_SENDER = 0x138; |
| 6 | + public const int OFFSET_CHAT_LAST_CONTENT = 0x140; |
| 7 | + |
| 8 | + /// <summary> |
| 9 | + /// Determine whether the Battlefield 1 chat box is open |
| 10 | + /// </summary> |
| 11 | + /// <returns></returns> |
| 12 | + public static bool GetChatIsOpen() |
| 13 | + { |
| 14 | + var address = Memory.Read<long>(Memory.GetBaseAddress() + 0x39F1E50); |
| 15 | + if (!Memory.IsValid(address)) |
| 16 | + return false; |
| 17 | + address = Memory.Read<long>(address + 0x08); |
| 18 | + if (!Memory.IsValid(address)) |
| 19 | + return false; |
| 20 | + address = Memory.Read<long>(address + 0x28); |
| 21 | + if (!Memory.IsValid(address)) |
| 22 | + return false; |
| 23 | + address = Memory.Read<long>(address + 0x00); |
| 24 | + if (!Memory.IsValid(address)) |
| 25 | + return false; |
| 26 | + address = Memory.Read<long>(address + 0x20); |
| 27 | + if (!Memory.IsValid(address)) |
| 28 | + return false; |
| 29 | + address = Memory.Read<long>(address + 0x18); |
| 30 | + if (!Memory.IsValid(address)) |
| 31 | + return false; |
| 32 | + address = Memory.Read<long>(address + 0x28); |
| 33 | + if (!Memory.IsValid(address)) |
| 34 | + return false; |
| 35 | + address = Memory.Read<long>(address + 0x38); |
| 36 | + if (!Memory.IsValid(address)) |
| 37 | + return false; |
| 38 | + address = Memory.Read<long>(address + 0x40); |
| 39 | + if (!Memory.IsValid(address)) |
| 40 | + return false; |
| 41 | + |
| 42 | + return Memory.Read<byte>(address + 0x30) == 0x01; |
| 43 | + } |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Get the pointer of the chat box, return the pointer if successful, return 0 if failed |
| 47 | + /// </summary> |
| 48 | + /// <returns></returns> |
| 49 | + public static long ChatMessagePointer() |
| 50 | + { |
| 51 | + var address = Memory.Read<long>(Memory.GetBaseAddress() + 0x3A327E0); |
| 52 | + if (!Memory.IsValid(address)) |
| 53 | + return 0; |
| 54 | + address = Memory.Read<long>(address + 0x20); |
| 55 | + if (!Memory.IsValid(address)) |
| 56 | + return 0; |
| 57 | + address = Memory.Read<long>(address + 0x18); |
| 58 | + if (!Memory.IsValid(address)) |
| 59 | + return 0; |
| 60 | + address = Memory.Read<long>(address + 0x38); |
| 61 | + if (!Memory.IsValid(address)) |
| 62 | + return 0; |
| 63 | + address = Memory.Read<long>(address + 0x08); |
| 64 | + if (!Memory.IsValid(address)) |
| 65 | + return 0; |
| 66 | + address = Memory.Read<long>(address + 0x68); |
| 67 | + if (!Memory.IsValid(address)) |
| 68 | + return 0; |
| 69 | + address = Memory.Read<long>(address + 0xB8); |
| 70 | + if (!Memory.IsValid(address)) |
| 71 | + return 0; |
| 72 | + address = Memory.Read<long>(address + 0x10); |
| 73 | + if (!Memory.IsValid(address)) |
| 74 | + return 0; |
| 75 | + address = Memory.Read<long>(address + 0x10); |
| 76 | + if (!Memory.IsValid(address)) |
| 77 | + return 0; |
| 78 | + else |
| 79 | + return address; |
| 80 | + } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Get the list of chat boxes, return a pointer if successful, return 0 if failed |
| 84 | + /// </summary> |
| 85 | + /// <returns></returns> |
| 86 | + public static long ChatListPointer() |
| 87 | + { |
| 88 | + var address = Memory.Read<long>(Memory.GetBaseAddress() + 0x39F1E50); |
| 89 | + if (!Memory.IsValid(address)) |
| 90 | + return 0; |
| 91 | + address = Memory.Read<long>(address + 0x70); |
| 92 | + if (!Memory.IsValid(address)) |
| 93 | + return 0; |
| 94 | + address = Memory.Read<long>(address + 0x20); |
| 95 | + if (!Memory.IsValid(address)) |
| 96 | + return 0; |
| 97 | + address = Memory.Read<long>(address + 0x18); |
| 98 | + if (!Memory.IsValid(address)) |
| 99 | + return 0; |
| 100 | + address = Memory.Read<long>(address + 0x28); |
| 101 | + if (!Memory.IsValid(address)) |
| 102 | + return 0; |
| 103 | + address = Memory.Read<long>(address + 0x28); |
| 104 | + if (!Memory.IsValid(address)) |
| 105 | + return 0; |
| 106 | + address = Memory.Read<long>(address + 0x38); |
| 107 | + if (!Memory.IsValid(address)) |
| 108 | + return 0; |
| 109 | + address = Memory.Read<long>(address + 0xD8); |
| 110 | + if (!Memory.IsValid(address)) |
| 111 | + return 0; |
| 112 | + address = Memory.Read<long>(address + 0x50); |
| 113 | + if (!Memory.IsValid(address)) |
| 114 | + return 0; |
| 115 | + else |
| 116 | + return address; |
| 117 | + } |
| 118 | + |
| 119 | + public static string GetLastChatSender(out long pSender) |
| 120 | + { |
| 121 | + pSender = 0; |
| 122 | + if (ChatListPointer() != 0) |
| 123 | + { |
| 124 | + pSender = Memory.Read<long>(ChatListPointer() + OFFSET_CHAT_LAST_SENDER); |
| 125 | + return Memory.ReadString(Memory.Read<long>(pSender), 32); |
| 126 | + } |
| 127 | + return string.Empty; |
| 128 | + } |
| 129 | + |
| 130 | + public static string GetLastChatContent(out long pContent) |
| 131 | + { |
| 132 | + pContent = 0; |
| 133 | + if (ChatListPointer() != 0) |
| 134 | + { |
| 135 | + pContent = Memory.Read<long>(ChatListPointer() + OFFSET_CHAT_LAST_CONTENT); |
| 136 | + return Memory.ReadString(Memory.Read<long>(pContent), 256); |
| 137 | + } |
| 138 | + return string.Empty; |
| 139 | + } |
| 140 | + } |
| 141 | +} |
0 commit comments