Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Release Forum » [CODE] Vehicle enter hook
[CODE] Vehicle enter hook [message #470378] Sun, 01 July 2012 01:22
iRANian is currently offline  iRANian
Messages: 4299
Registered: April 2011
Karma: 0
General (4 Stars)
This hook hooks two functions, TransitionInstanceClass::Start() and TransitionInstanceClass::End(). I based this off Hex' hook from his OnOeS regulator bot. This one is a lot hackier so you should check if it doesn't have any issues, I haven't checked if this hook breaks ladder or anything. The Start() function teleports the player into the "thing" he transitions into, like a ladder or vehicle, so the hook needs to teleport him back to his old position in the End() hook if you don't want a guy to enter a vehicle.

Hook *TransitionInstanceClass_End = new Hook;
Matrix3D OldTransform;

bool Vehicle_Enter_Hook(SoldierGameObj *Soldier, ReferencerClass Vehicle)
{
	Console_Output("Soldier = %s, Vehicle = %s\n",
		Commands->Get_Preset_Name(Soldier), Commands->Get_Preset_Name(Vehicle));

	return true;
}

void _stdcall TransitionInstanceClass_Glue(SoldierGameObj *Sender)
{
	VehicleGameObj *Vehicle;
	_asm { mov Vehicle, ecx}

	if (Vehicle_Enter_Hook(Sender, Vehicle) == true)
	{
		_asm
		{
			mov ecx, Vehicle
			push Sender
			mov eax, 0x0067AB20 // call VehicleGameObj::Add_Occupant()
			call eax
		}
	}
	else // If false is returned we need to teleport the player to his old position
	{ // or he will be teleported inside the vehicle
		Set_Transform(Sender, OldTransform);
	}
}

Hook *TransitionInstanceClass_Patch = new Hook;

void _stdcall TransitionInstanceClassPatch(Matrix3D &Transform)
{
	PhysicalGameObj *Sender;
	_asm{ mov Sender, ecx };
	OldTransform = Get_Transform(Sender->As_ScriptableGameObj());
	Set_Transform(Sender->As_ScriptableGameObj(), Transform);
}
/* add the following to the hook installation function: */

	TransitionInstanceClass_End->Install('\xE8', 0x006D47C8, (int)&TransitionInstanceClass_Glue, "");
	TransitionInstanceClass_Patch->Install('\xE8', 0x006D45A3, (int)&TransitionInstanceClassPatch, "");

/* end installation function shit */



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
Previous Topic: [CODE] 4.0 server damage hook
Next Topic: [CODE] Game start auto-team change functions hooks
Goto Forum:
  


Current Time: Fri Apr 19 19:54:47 MST 2024

Total time taken to generate the page: 0.00490 seconds