Хук directx в GTA SA

Статус
В этой теме нельзя размещать новые ответы.

Jack_Savage

Участник
Автор темы
150
17
Может есть где то пример как отрендерить что то в игре ?
Используя IDirect3DDevice9
Нашел был такое:

Код:
typedef IDirect3DDevice9 *(*RwD3D9GetCurrentD3DDevicePtr)();

RwD3D9GetCurrentD3DDevicePtr fpRwD3D9GetCurrentD3DDevice = (RwD3D9GetCurrentD3DDevicePtr)0x007F9D90;

void InitRender() 
{
    IDirect3DDevice9 *pDevice = fpRwD3D9GetCurrentD3DDevice();

    if (pDevice)
    {
        pDevice->ShowCursor(1);
        Debug("Cursor");
    }
}
Но игра вылетает почему то.

Еще нашел такой способ:
Код:
typedef void (*Render2dStuffPtr)();

// Pointer to Render2dStuff function
Render2dStuffPtr fpRender2dStuff = (Render2dStuffPtr)0x0053E230;

// This function will be called by SA after hook is installed
void MyDrawFunction()
{
// first draw SA's 2d stuff
fpRender2dStuff();

// draw own stuff here using d3d device or SA functions
}

// This function should typically be called in DllMain
void SetupMyDrawFunctionHook()
{
DWORD oldProtect;
DWORD *workAddress = (DWORD *)0x0053EB13; // Pointer to the call to Render2dStuff

// change protection/permissions to allow modification to instructions
VirtualProtect(workAddress, 4, PAGE_READWRITE, &oldProtect);

// modify instruction with a pointer to our draw function
*workAddress = (DWORD)&MyDrawFunction - (DWORD)(workAddress + 1);

// restore original protection/permissions to allow code to be executed again
VirtualProtect(workAddress, 4, oldProtect, NULL);
}
Но тут нет даже IDirect3DDevice9.
Помогите пожалуйста
 

Jack_Savage

Участник
Автор темы
150
17
А что делает
Код:
HRESULT D3DHook::Reset(D3DPRESENT_PARAMETERS *pPresentationParameters)
{

    // new PROPER reset code
    //
    // return for the reset
    HRESULT hRes_orig_Reset;

    // this should always be done if a reset is requested
    // and we have assets initialized on the proxy device
    while (bD3DRenderInit)
        proxyID3DDevice9_UnInitOurShit();
    
    // always attempt to reset orig device if we are asked to
    // since GTA is getting the state of the original device
    hRes_orig_Reset = origIDirect3DDevice9->Reset(pPresentationParameters);
    if (*(bool*)0xBA67A4)
        return hRes_orig_Reset;

    // handle the return from original Reset()
    if (hRes_orig_Reset == D3D_OK)
    {
        // variable for checking the pointers
        short    badPointerCount_g_pGTAPresent = 0;
        bool    badPointerBreak_g_pGTAPresent = false;
        short    badPointerCount_pPresentationParameters = 0;
        bool    badPointerBreak_pPresentationParameters = false;
        while (isBadPtr_writeAny(g_pGTAPresent, sizeof(D3DPRESENT_PARAMETERS)) && !badPointerBreak_g_pGTAPresent)
        {
            badPointerCount_g_pGTAPresent++;
            if (badPointerCount_g_pGTAPresent < 50)
            {
                Sleep(100);
            }
            else
            {
                Log("During D3D9 Reset(), g_pGTAPresent was bad for over 5 seconds. Continuing anyways.");
                badPointerBreak_g_pGTAPresent = true;
            }
        }

        while
            (
                isBadPtr_writeAny(pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS))
                && !badPointerBreak_pPresentationParameters
                )
        {
            badPointerCount_pPresentationParameters++;
            if (badPointerCount_pPresentationParameters < 50)
            {
                Sleep(100);
            }
            else
            {
                Log("During D3D9 Reset(), pPresentationParameters was bad for over 5 seconds. Continuing anyways.");
                badPointerBreak_pPresentationParameters = true;
            }
        }

        // init our shit
        while (!bD3DRenderInit)
        {
            proxyID3DDevice9_InitOurShit(pPresentationParameters);
            if (!bD3DRenderInit)
                Sleep(100);
        }

        // init our window mode
        proxyID3DDevice9_InitWindowMode(pPresentationParameters);

        // update the global Present Param struct AFTER original reset, only if it's ok
        pPresentParam = *pPresentationParameters;

        // Update our data.
        pD3DData->StoreViewport(0, 0, pPresentationParameters->BackBufferWidth,
            pPresentationParameters->BackBufferHeight);
    }

    // reporting problems is about all we can do here.
    // we would normally just end the application gracefully right
    // now, but GTA should be handling this on its own, so whatever.
    else if (hRes_orig_Reset == D3DERR_DEVICELOST)
    {
        Log("origIDirect3DDevice9::Reset() returned D3DERR_DEVICELOST");
    }
    else if (hRes_orig_Reset == D3DERR_DRIVERINTERNALERROR)
    {
        Log("WTF: origIDirect3DDevice9::Reset() returned D3DERR_DRIVERINTERNALERROR");
    }
    else if (hRes_orig_Reset == D3DERR_OUTOFVIDEOMEMORY)
    {
        Log("WTF: origIDirect3DDevice9::Reset() returned D3DERR_OUTOFVIDEOMEMORY");
    }
    else
    {
        Log("WTF: origIDirect3DDevice9::Reset() returned value %d", hRes_orig_Reset);
    }

    // bai
    return hRes_orig_Reset;
}
А то у меня на нее ошибок куча
 
Последнее редактирование:

Jack_Savage

Участник
Автор темы
150
17
Какой то не рабочий хук
Present вызывается, игра не крашится но почему то не появляется зеленый квадрат :С
Код:
HRESULT D3DHook::Present(CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride,
    CONST RGNDATA *pDirtyRegion)
{
    origIDirect3DDevice9->BeginScene();
    origIDirect3DDevice9->Clear(0, &re, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
    origIDirect3DDevice9->EndScene();
    return origIDirect3DDevice9->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
}
 

Jack_Savage

Участник
Автор темы
150
17
:facepalm:
Тебе ж сказали что метод clear чистит фон. Дык убери строчку
C++:
origIDirect3DDevice9->Clear(0, &re, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
А теперь самый идиотский вопрос.
А какой командой тогда рисовать ?
 

BlackKnigga

Известный
BH Team
922
445
  • Нравится
Реакции: Jack_Savage

Jack_Savage

Участник
Автор темы
150
17
VVMRgaO.jpg

УУУрррряя... Работает :3
SR_team и BlackKnigga спасибо вам огромное.
Еще если бы кто сказал как картинку (прямоугольник) дравить... Ну ладно и так класно :3
Спасибо огромное :333
 

AWRage

Активный
642
141
C++:
typedef HRESULT(__stdcall *tPresent)(IDirect3DDevice9 *, CONST RECT *, CONST RECT *, HWND, CONST RGNDATA *);
typedef HRESULT(__stdcall *tReset)(IDirect3DDevice9 *, D3DPRESENT_PARAMETERS *);

tReset                    gOriginalReset        = nullptr;
tPresent                gOriginalPresent    = nullptr;
D3DPRESENT_PARAMETERS*    gPresentParams        = nullptr;

HRESULT __stdcall hkdReset(IDirect3DDevice9 *d3dDev, D3DPRESENT_PARAMETERS *presentParams)
{
   
    HRESULT hRes = gOriginalReset(d3dDev, presentParams);

    return hRes;
}

HRESULT __stdcall hkdPresent(IDirect3DDevice9 *d3dDev, CONST RECT *srcRect, CONST RECT *destRect, HWND destWindow, CONST RGNDATA *dirtyRegion)
{

    HRESULT hRes = gOriginalPresent(d3dDev, srcRect, destRect, destWindow, dirtyRegion);

    return hRes;
}

DWORD FindDevice(DWORD dwLen)
{
    DWORD dwObjBase = (DWORD)LoadLibraryA("d3d9.dll");

    if (dwObjBase == 0x0)
        return 0x0;

    while (dwObjBase++ < dwObjBase + dwLen)
    {
        if ((*(WORD*)(dwObjBase + 0x00)) == 0x06C7 && (*(WORD*)(dwObjBase + 0x06)) == 0x8689 && (*(WORD*)(dwObjBase + 0x0C)) == 0x8689)
        {
            dwObjBase += 2;
            break;
        }
    }

    return dwObjBase;
};

bool initD3DRes()
{
    DWORD* VTable;
    *(DWORD*)&VTable = *(DWORD *)FindDevice(0x128000);

    DWORD VP16, VP17;

    VirtualProtect((LPVOID)&VTable[16], 4, PAGE_READWRITE, &VP16);
    VirtualProtect((LPVOID)&VTable[17], 4, PAGE_READWRITE, &VP17);

    gOriginalReset = (tReset)VTable[16];
    gOriginalPresent = (tPresent)VTable[17];

    VTable[16] = (DWORD)hkdReset;
    VTable[17] = (DWORD)hkdPresent;

    VirtualProtect((LPVOID)&VTable[16], 4, VP16, &VP16);
    VirtualProtect((LPVOID)&VTable[17], 4, VP17, &VP17);

    return true;
}

void destD3DRes()
{
    DWORD* VTable;
    *(DWORD*)&VTable = *(DWORD*)FindDevice(0x128000);

    DWORD VP16, VP17;

    VirtualProtect((LPVOID)&VTable[16], 4, PAGE_READWRITE, &VP16);
    VirtualProtect((LPVOID)&VTable[17], 4, PAGE_READWRITE, &VP17);

    VTable[16] = (DWORD)gOriginalReset;
    VTable[17] = (DWORD)gOriginalPresent;

    VirtualProtect((LPVOID)&VTable[16], 4, VP16, &VP16);
    VirtualProtect((LPVOID)&VTable[17], 4, VP17, &VP17);
}
 
Статус
В этой теме нельзя размещать новые ответы.