Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Release Forum » [CODE] Game start auto-team change functions hooks
[CODE] Game start auto-team change functions hooks [message #470387] Sun, 01 July 2012 02:43
iRANian is currently offline  iRANian
Messages: 4300
Registered: April 2011
Karma: 0
General (4 Stars)
These hooks hook 4.0's hooks/replacements of the team change functions that get called when the game starts. You'll have to re-implement all the code for them as I'm too lazy to. The following functions are replaced:

Remix_Team_Sides() -- changes the player type of every in-game player with a shitty rand() call
Rebalance_Team_Sides() -- gets called after Remix_Team_Sides(), it rebalances the team sides as Remix_Team_Sides() just randomly sets the player type of every players
Swap_Team_Sides() -- this function swaps the team of every player, don't think this is called on laddered servers.

Hook *RemixTeamSidesHook = new Hook;
int TTTeamRemixHookAddress = 0;

void Remix_Team_Sides_Replace()
	Console_Output("Remix_Team_Sides_Replace() called\n");

Hook *SwapTeamSidesHook = new Hook;
int TTSwapTeamsHookAddress = 0;

void Swap_Team_Sides_Replace()
	Console_Output("Swap_Team_Sides_Replace() called\n");

Hook *RebalanceTeamSidesHook = new Hook;
int TTRebalanceTeamsHookAddress = 0;

void Rebalance_Team_Sides_Replace()
	Console_Output("Rebalance_Team_Sides_Replace() called\n");

int Calculate_Address_From_Displacement(int JMPStartAddress)
	char OpCodes[5];
	int Displacement, Address;

	Hooking::ReadMemory(JMPStartAddress, OpCodes, 5); // 0x004B4910 is where the JMP opcode (E9) starts, next 4 are the displacement/relative address

	memcpy(&Displacement, OpCodes+1, sizeof(char)*4); // OpCodeBuffer+1 or we'll also read the JMP opcode

	Address = JMPStartAddress + 5 + Displacement;
	return Address;

/* in the installation function add: */

	TTTeamRemixHookAddress = Calculate_Address_From_Displacement(0x00471D60);
	Console_Output("TT Team Remix Hook address = 0x%X\n", TTTeamRemixHookAddress);
	RemixTeamSidesHook->Install('\xE9', TTTeamRemixHookAddress, (int)&Remix_Team_Sides_Replace, "");

	TTSwapTeamsHookAddress = Calculate_Address_From_Displacement(0x00471A10);
	Console_Output("TT Swap Teams Hook address = 0x%X\n", TTSwapTeamsHookAddress);
	SwapTeamSidesHook->Install('\xE9', TTSwapTeamsHookAddress, (int)&Swap_Team_Sides_Replace, "");

	TTRebalanceTeamsHookAddress = Calculate_Address_From_Displacement(0x00471E70);
	Console_Output("TT Rebalance Teams Hook address = 0x%X\n", TTRebalanceTeamsHookAddress);
	RebalanceTeamSidesHook->Install('\xE9', TTRebalanceTeamsHookAddress, (int)&Rebalance_Team_Sides_Replace, "");

/* end installation function */

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, 01 July 2012 02:54]

Report message to a moderator

Previous Topic: [CODE] Vehicle enter hook
Next Topic: [SSGM 4.0 Plugin] RR Client Anti-cheat Messages Support
Goto Forum:

Current Time: Mon Jul 15 21:05:07 MST 2024

Total time taken to generate the page: 0.00628 seconds