Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Release Forum » [Server code] 4.1 patch 2 private chat hook
[Server code] 4.1 patch 2 private chat hook [message #489532] Sun, 05 October 2014 05:20 Go to next message
iRANian is currently offline  iRANian
Messages: 4308
Registered: April 2011
Karma: 0
General (4 Stars)
The previous version stopped working because the prologue of the TT chat code I'm hooking changed, seems to be because 4.1 uses a newer C++ compiler.

int TTChatHookAddress = 0;
int TTChatHookJMPAddress = 0;
int TTPrologueFuncCallAddress = 0;

bool ReadMemory(int Address, void* Buffer, int Size)
{
        bool ret = 1;
        DWORD OldProtect;
        HANDLE Process = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, false, GetCurrentProcessId());
        VirtualProtectEx(Process, (LPVOID)Address, Size, PAGE_EXECUTE_READWRITE, &OldProtect);
        if (!ReadProcessMemory(Process, (LPVOID)Address, Buffer, Size, NULL))
        {
                Console_Output("Reading process memory adress 0x%x failed\n", Address);
                Console_Output("GetLastError() = %d\n", GetLastError());
                ret = 0;
        }
        VirtualProtectEx(Process, (LPVOID)Address, Size, OldProtect, NULL);
        CloseHandle(Process);
        return ret;
}
 
bool WriteMemory(int Address, const void* Buffer, int Size)
{
        bool ret = 1;
        DWORD OldProtect;
        HANDLE Process = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, false, GetCurrentProcessId());
        VirtualProtectEx(Process, (LPVOID)Address, Size, PAGE_EXECUTE_READWRITE, &OldProtect);
        if (!WriteProcessMemory(Process, (LPVOID)Address, Buffer, Size, NULL))
        {
                Console_Output("Hooking address 0x%x failed\n", Address);
                Console_Output("GetLastError() = %d\n", GetLastError());
                ret = 0;
        }
        VirtualProtectEx(Process, (LPVOID)Address, Size, OldProtect, NULL);
        CloseHandle(Process);
        return ret;
}
 
void Install_Hook(char OpCode, int Addr, int Glue, char *Padding)
{
        int HookAddress = Addr;
        int Offset = Glue - HookAddress - 5;
        WriteMemory(HookAddress, &OpCode, 1);
        WriteMemory(HookAddress+1, &Offset, 4);
};
 
int Calculate_Address_From_Displacement(int JMPStartAddress)
{
        char OpCodes[5];
        int Displacement, Address;
 
        ReadMemory(JMPStartAddress, OpCodes, 5);
        Console_Output("BYTES READ: 0x%x 0x%x 0x%x 0x%x 0x%x \n", OpCodes[0], OpCodes[1], OpCodes[2], OpCodes[3], OpCodes[4]);
 
        memcpy(&Displacement, OpCodes+1, sizeof(char)*4); // OpCodeBuffer+1 or we'll also read the JMP opcode
 
        Address = JMPStartAddress + 5 + Displacement;
        return Address;
}

bool _cdecl Private_Chat_Hook(int PlayerID, int Type, wchar_t *Message, int TargetID)
{
	if (TargetID == -2 || Type != 2) { return true; } // Only trigger on valid private chat

	Console_Output("PlayerID = %d, TargetID = %d, type = %d, Message = %S\n", PlayerID, TargetID, Type, Message);

	return false;
}

void _declspec(naked) PrivateChatHook_Glue()
{
	_asm
	{
		push esi		
		mov eax, esi
		mov esi, ecx // save ecx

		push [ecx+06C0h] // arg 4, TargetID
		push [ecx+06BCh] // arg 3, Message
		push [ecx+06B8h] // arg 2, Type
		push [ecx+06B4h] // arg 1, PlayerID
		call Private_Chat_Hook
		add esp, 16;

		mov ecx, esi // restore ecx
		
		test al, al
		jz Block_Private_Chat
		
		call TTPrologueFuncCallAddress
		jmp TTChatHookJMPAddress

Block_Private_Chat:
		pop esi
		retn
	}
}

// install function, OnLoadGlobalINISettings is a good place to install, the plugin constructor doesn't work
void TriggerbotAntiCheat::OnLoadGlobalINISettings(INIClass *SSGMIni)
{
	TTChatHookAddress = Calculate_Address_From_Displacement(0x004B5C10); // Hook from  cCsTextObj::Act(void)
	TTChatHookJMPAddress = TTChatHookAddress+8;
	TTPrologueFuncCallAddress = Calculate_Address_From_Displacement(TTChatHookAddress + 3);

	Install_Hook('\xE9', TTChatHookAddress, (int)&PrivateChatHook_Glue, "");
}


Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases

[Updated on: Sun, 05 October 2014 05:26]

Report message to a moderator

Re: [Server code] 4.1 patch 2 private chat hook [message #489533 is a reply to message #489532] Sun, 05 October 2014 08:29 Go to previous messageGo to next message
raven
Messages: 595
Registered: January 2007
Location: Toronto, Ontario
Karma: 0
Colonel
Thanks for the update In Love

-Jelly Administrator
-Exodus Administrator
Re: [Server code] 4.1 patch 2 private chat hook [message #489541 is a reply to message #489532] Mon, 06 October 2014 02:07 Go to previous messageGo to next message
danpaul88 is currently offline  danpaul88
Messages: 5795
Registered: June 2004
Location: England
Karma: 0
General (5 Stars)
Spying on private chat again? You should apply for a job with the NSA, or the equivalent in your country Sarcasm

http://steamsignature.com/card/1/76561197975867233.png

[Updated on: Mon, 06 October 2014 02:07]

Report message to a moderator

Re: [Server code] 4.1 patch 2 private chat hook [message #489543 is a reply to message #489532] Mon, 06 October 2014 06:12 Go to previous messageGo to next message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

well we just use it to block people from PMing each other when !mute-ed because !mute only blocks public chat by default

not very useful when someone complains about being PM'd mean things about their mother ;>


-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

Re: [Server code] 4.1 patch 2 private chat hook [message #489545 is a reply to message #489532] Mon, 06 October 2014 09:10 Go to previous messageGo to next message
iRANian is currently offline  iRANian
Messages: 4308
Registered: April 2011
Karma: 0
General (4 Stars)
You can use it for keyhooks and checking certain scripts.dll netcode too.

Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases
Re: [Server code] 4.1 patch 2 private chat hook [message #489555 is a reply to message #489532] Wed, 08 October 2014 01:47 Go to previous messageGo to next message
triattack is currently offline  triattack
Messages: 14
Registered: May 2011
Karma: 0
Recruit
which is nice because that way you can mute they keyhook voting Smile in reborn if people spam it.
Re: [Server code] 4.1 patch 2 private chat hook [message #489557 is a reply to message #489532] Wed, 08 October 2014 08:44 Go to previous messageGo to next message
iRANian is currently offline  iRANian
Messages: 4308
Registered: April 2011
Karma: 0
General (4 Stars)
Renegade suffers from that issue too.

Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases
Re: [Server code] 4.1 patch 2 private chat hook [message #489558 is a reply to message #489532] Wed, 08 October 2014 09:08 Go to previous message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

The "!vote yes"/"!vote no" keyhook is actually in both SSGM and Dragonade, you can just manually remove the keyhook entirely or edit it to take out that annoying chat message if you wish.

-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

Previous Topic: MPF Keys.cfg Installer
Next Topic: [SSGM 4.1 Plugin] LuaTT 2 (LuaJIT Update)
Goto Forum:
  


Current Time: Thu Nov 21 07:59:44 MST 2024

Total time taken to generate the page: 0.00692 seconds