Skip to content

Commit

Permalink
Fixed correct work without required declared callbacks
Browse files Browse the repository at this point in the history
- Update README
  • Loading branch information
ziggi committed Sep 26, 2016
1 parent 7b1b82e commit b04abb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Discussion in [forum thread](http://forum.sa-mp.com/showthread.php?t=428066). Or
# Usage notes
If you want to see that your scripts will work correctly, you need to declare this callback functions at least in one of your scripts:
- OnPlayerGiveDamage
- OnPlayerTakeDamage
- OnPlayerWeaponShot
- OnPlayerStreamIn
- OnPlayerStreamOut
Expand Down
18 changes: 15 additions & 3 deletions src/CHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern void *pAMXFunctions;
BYTE bytePushCount;
char szPreviousFuncName[32];
bool bHookIsExec;
bool bHookIsPush;
bool bFindPublicIsBlocked;
bool bIsPublicFound;

Expand Down Expand Up @@ -83,8 +84,8 @@ int amx_FindPublic_Hook(AMX *amx, const char *funcname, int *index)
pfn_amx_FindPublic = (amx_FindPublic_t)(subhook_get_trampoline(hookFindPublic));
bytePushCount = 0;

if (bHookIsExec) {
if (!strcmp(funcname, szPreviousFuncName)) {
if (bHookIsExec || !bHookIsPush) {
if (bHookIsExec && !strcmp(funcname, szPreviousFuncName)) {
if (bFindPublicIsBlocked) {
return 1;
} else {
Expand All @@ -93,12 +94,18 @@ int amx_FindPublic_Hook(AMX *amx, const char *funcname, int *index)
} else {
bFindPublicIsBlocked = false;
bHookIsExec = false;
bHookIsPush = false;
bIsPublicFound = false;
szPreviousFuncName[0] = '\0';
bGiveDamage = false;
bTakeDamage = false;
bWeaponShot = false;
bStreamIn = false;
bStreamOut = false;
}
}

if (!bHookIsExec && !bIsPublicFound) {
if (!bHookIsExec && !bHookIsPush && !bIsPublicFound) {
if (!strcmp(funcname, "OnPlayerGiveDamage")) {
bIsPublicFound = true;
bGiveDamage = true;
Expand Down Expand Up @@ -128,6 +135,7 @@ int amx_Push_Hook(AMX *amx, cell value)
{
// Are we retrieving parameters ?
if (bGiveDamage || bTakeDamage) {
bHookIsPush = true;
switch (bytePushCount) {
case 4:
pDamage.wPlayerId = static_cast<WORD>(value);
Expand All @@ -152,6 +160,7 @@ int amx_Push_Hook(AMX *amx, cell value)
// Increase the parameters count
bytePushCount++;
} else if (bWeaponShot) {
bHookIsPush = true;
switch (bytePushCount) {
case 6:
pWeaponShot.wPlayerId = static_cast<WORD>(value);
Expand Down Expand Up @@ -184,6 +193,7 @@ int amx_Push_Hook(AMX *amx, cell value)
// Increase the parameters count
bytePushCount++;
} else if (bStreamIn) {
bHookIsPush = true;
switch (bytePushCount) {
case 1:
pStream.wPlayerId = static_cast<WORD>(value);
Expand All @@ -196,6 +206,7 @@ int amx_Push_Hook(AMX *amx, cell value)
// Increase the parameters count
bytePushCount++;
} else if (bStreamOut) {
bHookIsPush = true;
switch (bytePushCount) {
case 1:
pStream.wPlayerId = static_cast<WORD>(value);
Expand Down Expand Up @@ -308,6 +319,7 @@ void CHooks::InstallHooks()
{
// Reset public flag
bHookIsExec = false;
bHookIsPush = false;
bFindPublicIsBlocked = false;
bIsPublicFound = false;
bGiveDamage = false;
Expand Down

0 comments on commit b04abb9

Please sign in to comment.