Results 1 to 10 of 28

Thread: Pro tips for hooking up the function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #26
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Ok, watching a bit longer the pointer logic going on here, I just realized my if's were total useless, they actually can't check anything. They basically add a number to 0 or greater and test if that number is still 0.

    Lets name that function getWeaponStruct_80E9270 (based on Mitch's comment in the Server Crash thread).

    Lets dissect:

    PHP Code:
    int __cdecl getWeaponStruct_80E9270(int a1)
    {
      return 
    dword_8576160[a1];

    The [] is basically syntax sugar for:

    PHP Code:
    int __cdecl getWeaponStruct_80E9270(int a1)
    {
      return *((
    int *)0x8576160 a1);

    Same game here, this function just cannot fail. It will always point to a valid array element address, implying your debug-printed a1 values of 111 and 211. It could only fail with very large numbers (either positive or negative).

    The only reason you don't see the printf after that line, is because you dereference v3 in the next printf:

    PHP Code:
    printf("hook_BG_IsWeaponValid -- Last weapon used: %s\n", *(char**)(v3 0)); 
    And I guess that's the whole problem here, getWeaponStruct() probably returns 0.

    So the only thing you need to check for in hook_BG_IsWeaponValid() should be:
    PHP Code:
        if ( ! v3)
        {
            
    printf("Warning: getWeaponStruct(%d) returned 0!\n"a2);
            return 
    0;
        } 
    timescale 0.01

  2. The Following 3 Users Say Thank You to kung foo man For This Useful Post:

    kubislav23 (10th May 2016),voron00 (12th May 2016),Whiskas (10th May 2016)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •