Quantcast

Jump to content

» «
Photo

[C++|ASM] Alter damage received

30 replies to this topic
FaTony
  • FaTony

    C++ guy

  • Members
  • Joined: 12 Aug 2011

#31

Posted 02 April 2012 - 03:49 AM Edited by FaTony, 03 April 2012 - 01:57 AM.

EDIT: Ok. After quite a few assembly related articles I managed to do this:
CODE
const DWORD GetPlayerPedFuncAddress = 0x008788D0;

typedef void *(__cdecl *GetPlayerPedFunc)(int);

GetPlayerPedFunc GetPlayerPed;

void InstallHooks(void)
{
GetPlayerPed = (GetPlayerPedFunc)(GetPlayerPedFuncAddress + dwLoadOffset);
//Other code
}

__declspec(naked) int __stdcall PedDamageHook(void *attacker, void *victim)
{
_asm
{
 // Function prolog
 // Create new stack frame
 push ebp
 mov  ebp, esp

 // Save relevant registers
 // Save ecx
 push ecx

 // Call C++ function
 // Push damage
 lea  eax, [ecx + 4h]
 push eax
 // Push attacker
 push [ebp + 10h]
 // Push victim
 push [ebp + 14h]
 // Call function
 call OnPedDamage
 // Clean stack
 add  esp, 12

 // Restore relevant registers
 // Restore ecx
 pop  ecx

 // Function epilog
 // Restore previous stack frame
 mov  esp, ebp
 pop  ebp

 // Code from '0x00ABB170', 8 ovewritten bytes
 sub  esp, 10h
 push ebp
 mov  ebp, [esp+1Ch]
 jmp  jmpaddress
}
}

void OnPedDamage(const void *victim, const void *attacker, float &damage)
{
void *player = GetPlayerPed(0);
if (victim == player)
{
 damage *= 0.1f;
}
else if (attacker == player)
{
 damage *= 10.0f;
}
}


The problem is, it looks like all peds have 2 ped classes associated with them. One is the "old school ped" that is used during gun fights and another is "Euphoria ped" with is used with physics and ragdolls. Old school peds have addresses in the range of 5xxxxxx. Euphoria peds have addresses in the range of 6xxxxxx. GetPlayerPed returns old school ped. So, for example, when I throw a molotov and get caught by it's fire, attacker will be my old school ped and victim will be my Euphoria ped. As a result, I will get 10x damage. That's no good.

Can you help me find a function that returns Euphoria peds?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users