Hello. I'm making a tool for SAMP and now I needed to make a function to write something to the chat.
This is what I have so far, but it won't work and I don't know what's wrong. I dont fully understand how to call the function and pass the message to write to it.
When I call the function nothing won't appear in the chat box.
Thanks.
This is what I have so far, but it won't work and I don't know what's wrong. I dont fully understand how to call the function and pass the message to write to it.
Code:
[...]
struct DataToSend {
int address;
int data;
};
bool addChatMessage(HANDLE *gtaProc, DWORD *sampBaseAddress, char *msg) {
if(*gtaProc == NULL || *sampBaseAddress == 0x0 || sampBaseAddress == NULL)
return false;
DWORD sampChatInfoAddress;
DWORD msgMemory;
int result = ReadProcessMemory(*gtaProc, (LPVOID)(*sampBaseAddress + ADDR_SAMP_CHATMSG_PTR), &sampChatInfoAddress, sizeof(sampChatInfoAddress), NULL);
if(!result || sampChatInfoAddress == 0x0)
return false;
msgMemory = (DWORD)VirtualAllocEx(*gtaProc, 0, 4096, 0x1000 | 0x2000, 0x40);
WriteProcessMemory(*gtaProc, (LPVOID)msgMemory, msg, 256, NULL);
DataToSend mydata = { (int)sampChatInfoAddress, (int)msgMemory };
WriteProcessMemory(*gtaProc, (LPVOID)(*sampBaseAddress + ADDR_SAMP_FUNC_ADDCHATMSG), (LPVOID)&mydata, sizeof(mydata), NULL);
return true;
}
[...]
When I call the function nothing won't appear in the chat box.
Thanks.