Jump to content

[fixed]->GetPools()->GetPedFromRef((DWORD)1)-> not working


Gamer_Z

Recommended Posts

Hello everyone,

I'm trying to make a simple GTA SA Singleplayer scripting engine thanks to MTA Client Source (extracted game_sa project) but I am having problems.

The setmoney stuff etc works, but now I have this (see ProcessTickMain):

////////////////////////////////////////// 
#include <StdInc.h> 
////////////////////////////////////////// 
#define FUNCTION __declspec(dllexport) 
  
HINSTANCE gl_hThisInstance = NULL; 
HHOOK hHook = NULL; 
  
HANDLE hTimer = NULL; 
HANDLE hTimerQueue = NULL; 
  
HANDLE iTimer = NULL; 
HANDLE iTimerQueue = NULL; 
  
VOID CALLBACK ProcessTickMain(PVOID lpParam, BOOLEAN TimerOrWaitFired); 
VOID CALLBACK InitPlugin(PVOID lpParam, BOOLEAN TimerOrWaitFired); 
LRESULT CALLBACK KeyHit(int code,WPARAM wParam,LPARAM lParam); 
  
#define LocalPed (pGame->GetPools()->GetPedFromRef ( (DWORD)1 )) 
BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) 
{ 
    // to avoid compiler lvl4 warnings  
    LPVOID lpDummy = lpReserved; 
    lpDummy = NULL; 
     
    switch (ul_reason_for_call) 
    { 
        case DLL_PROCESS_ATTACH: 
  
        gl_hThisInstance = (HINSTANCE)hModule; 
        hTimerQueue = CreateTimerQueue(); 
        if (NULL != hTimerQueue) 
        { 
            if(CreateTimerQueueTimer( &iTimer, hTimerQueue, InitPlugin, NULL , 2000, 0, 0)){} 
        } 
        break; 
        case DLL_PROCESS_DETACH:  
            DeleteTimerQueue(hTimerQueue); 
        break; 
        case DLL_THREAD_ATTACH:  break; 
        case DLL_THREAD_DETACH:  break; 
    } 
    return TRUE; 
} 
VOID CALLBACK InitPlugin(PVOID lpParam, BOOLEAN TimerOrWaitFired) 
{ 
        GetGameInterface(g_pCore); 
        pGame->InitLocalPlayer(); 
        if(CreateTimerQueueTimer( &hTimer, hTimerQueue, ProcessTickMain, NULL , 30, 30, 0)){} 
        hHook = SetWindowsHookEx(WH_KEYBOARD, KeyHit, gl_hThisInstance, GetWindowThreadProcessId((HWND)gl_hThisInstance, NULL)); 
} 
  
VOID CALLBACK ProcessTickMain(PVOID lpParam, BOOLEAN TimerOrWaitFired) 
{ 
    //static bool Inited = false; 
    //if(!Inited) 
    //{ 
    //   
    //  Inited = true; 
    //} 
    //if(pGame->IsGameLoaded()) 
    //{ 
        //pGame->GetPlayerInfo()->SetPlayerMoney(100000); 
        if(pGame->GetPools()->GetPedFromRef((DWORD)1)) 
        { 
            pGame->GetPlayerInfo()->SetPlayerMoney((long)pGame->GetPools()->GetPedFromRef((DWORD)1)->GetHealth()); 
        } 
        else 
        { 
            //pGame->InitLocalPlayer(); 
            pGame->GetPlayerInfo()->SetPlayerMoney(0); 
        } 
        //if(0 < Functions::GetPlayerVehicleID() != 0xFFFF) 
        //{ 
        //  Functions::SetVehiclePos(Functions::GetPlayerVehicleID(),0.0f,0.0f,30.0f); 
        //} 
    //} 
} 
  
LRESULT CALLBACK KeyHit(int code,WPARAM wParam,LPARAM lParam) 
{ 
  
    return CallNextHookEx(hHook,code,wParam,lParam); 
} 
  

and it just doesn't want to work.. csh stays at 0 while it should be 100.

What am I doing wrong?

Edit: oh fixed it, was a bug in the CGameSA::InitializeLocalPlayer function.

This is the previous function:

  
BOOL CGameSA::InitLocalPlayer(  ) 
{ 
    DEBUG_TRACE("BOOL CGameSA::InitLocalPlayer(  )"); 
  
    // Added by ChrML - Looks like it isn't safe to call this more than once but mod code might do 
    static bool bAlreadyInited = false; 
    if ( bAlreadyInited ) 
    { 
        return TRUE; 
    } 
            bAlreadyInited = true;//we set this to true, no matter what the return will be 
    CPoolsSA * pools = (CPoolsSA *)this->GetPools (); 
    if ( pools ) 
    { 
        //* HACKED IN HERE FOR NOW *// 
        CPedSAInterface* pInterface = pools->GetPedInterface ( (DWORD)1 ); 
  
        if ( pInterface ) 
        { 
            pools->AddPed ( (DWORD*)pInterface ); 
  
            return TRUE; 
        } 
  
        return FALSE; 
    } 
    return FALSE; 
} 

and this is my current function:

  
BOOL CGameSA::InitLocalPlayer(  ) 
{ 
    DEBUG_TRACE("BOOL CGameSA::InitLocalPlayer(  )"); 
  
    // Added by ChrML - Looks like it isn't safe to call this more than once but mod code might do 
    static bool bAlreadyInited = false; 
    if ( bAlreadyInited ) 
    { 
        return TRUE; 
    } 
  
    CPoolsSA * pools = (CPoolsSA *)this->GetPools (); 
    if ( pools ) 
    { 
        //* HACKED IN HERE FOR NOW *// 
        CPedSAInterface* pInterface = pools->GetPedInterface ( (DWORD)1 ); 
  
        if ( pInterface ) 
        { 
            pools->AddPed ( (DWORD*)pInterface ); 
            bAlreadyInited = true;//only true whem added, right? 
            return TRUE; 
        } 
  
        return FALSE; 
    } 
    return FALSE; 
} 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...