Skip to content

Commit

Permalink
Update net code to not continue to send fire when holding, Add hook f…
Browse files Browse the repository at this point in the history
…or weapon modification
  • Loading branch information
pnill committed Jan 13, 2020
1 parent 99b00f4 commit cc715d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions T4MP/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,16 @@ int __stdcall HoldFire(DMPlayer* pDMPlayer, float HeldTime, int a2)
}


/* Triggered when using alternate fire mode (right mouse click) */
typedef int(__stdcall *tModifyWeapon)(DMPlayer* pDMPlayer);
tModifyWeapon pModifyWeapon;

int __stdcall ModifyWeapon(DMPlayer* pDMPlayer)
{

return pModifyWeapon(pDMPlayer);
}


/*
These are engine functions used for switching weapons and checking if a weapon is available before attempting to switch to it.
Expand Down Expand Up @@ -1056,6 +1066,9 @@ void TurokEngine::SetModHooks()
VirtualProtect(pReleaseFire, 4, PAGE_EXECUTE_READWRITE, &dwBack);

pHoldFire = (tHoldFire)DetourClassFunc((BYTE*)0x4D6DF0, (BYTE*)HoldFire, 11);

pModifyWeapon = (tModifyWeapon)DetourClassFunc((BYTE*)0x004C65C0, (BYTE*)ModifyWeapon, 12);
VirtualProtect(pModifyWeapon, 4, PAGE_EXECUTE_READWRITE, &dwBack);

VirtualProtect(pHoldFire, 4, PAGE_EXECUTE_READWRITE, &dwBack);

Expand Down
6 changes: 3 additions & 3 deletions T4MP/t4net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void T4Network::ProcessPlayerSnap(const PlayerSnap &pPlayerSnap,u_long pIP, u_sh
if (pPlayerSnap.jump())
pPlayer->jump(0, 1.0f);

if (pPlayerSnap.fire())
if (pPlayerSnap.fire() && !pPlayerSnap.fire_hold()) // attempt to fix holding fire.
{
//printf("Player Fired\r\n");
pPlayer->fire_weapon(0, 0);
Expand Down Expand Up @@ -1039,7 +1039,7 @@ void T4Network::ProcessServerSnap(const ServerSnap &pSeverSnap)

/*
Weapon Switch - Important to do this BEFORE firing as they could have changed weapons!, be sure to update weapon slot first so we switch appropriately
Should really find a better way to update the weapon being held this is too inacurate, there's a high chance for desync.
Should really find a better way to update the weapon being held this is too inaccurate, there's a high chance for desync.
*/

pDMPlayer->Weapon_switch_time = player.weapon_switch_time(); // how long to wait before performing the switch
Expand All @@ -1062,7 +1062,7 @@ void T4Network::ProcessServerSnap(const ServerSnap &pSeverSnap)


/* Firing Checks - important to do this AFTER position and other actions */
if (player.fire())
if (player.fire() && !player.fire_hold()) // try to fix the holding not working properly.
{
if(!local_player)
pDMPlayer->fire_weapon(0, 0); // again have no idea what the params are for, should determine if they need to be synced.
Expand Down

0 comments on commit cc715d4

Please sign in to comment.