Im working on a project on a existing flightsimulator where i need to find the textures that are mapped to a particular model, and do my own rendering on them. The idea is to replace the glass instrument drawing system provided by the SDK as it is too framerate intensive for some applications (it uses GDI/GDI+).
I successfully hooked into the IDirect3DDevice9 instance using this code:
[source lang="cpp"] void HookIntoD3D(){//Create a temporary direct 3D object and get its IDirect3DDevice9 interface. This is a different//"instance," but the virtual table will point to the function within d3d9.dll also used by FSX's//instance.LPDIRECT3D9 p = Direct3DCreate9(D3D_SDK_VERSION);if (!p) return;D3DPRESENT_PARAMETERS presParams;ZeroMemory(&presParams,sizeof(presParams));presParams.Windowed = TRUE;presParams.SwapEffect = D3DSWAPEFFECT_DISCARD;IDirect3DDevice9 *pI = NULL;HRESULT hr;hr = p->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &presParams, &pI);if (!pI){ p->Release(); return;}//Get the pointer to the virtual table for IDirect3DDevice9 (pI is a pointer to a pointer to the Vtable)PVOID* pVTable = (PVOID*)*((DWORD*)pI);//Set permissions so we can read it (117 = size of whole table)DWORD dwOldProtect;VirtualProtect(pVTable, sizeof(void *) * 117, PAGE_READWRITE, &dwOldProtect); //Get the address to the (real) Present function (17th function listed, starting at 0 -- see definition//of IDirect3DDevice9).RealPresent = (RealPresentFuncType)pVTable[17];//Calculate the offset from the real function to our hooked function. Constant 5 is because JMP//offset is from start of next instruction (5 bytes later)DWORD offset =(DWORD)Present - (DWORD)RealPresent - 5; //Create the patch code: JMP assembly instruction (0xE9) followed by relative offsetg_PatchCode[0] = 0xE9;*((DWORD*) &g_PatchCode[1]) = offset;g_pPatchAddr = (unsigned char*)RealPresent;//Set permission to allow reading/write/executeVirtualProtect(g_pPatchAddr, 8, PAGE_EXECUTE_READWRITE, &dwOldProtect);//Save out the original bytesfor (int i = 0; i < 5; i++) g_OrigCode[i] = *(g_pPatchAddr + i);//Copy in our patch codeApplyPatch();//Delete dummy D3D objectspI->Release();p->Release();return;}//Our hooked function. FSX calls this thinking it's calling IDirect3DDevice9::PresentHRESULT _stdcall Present(void *pThis, const RECT* pSourceRect,const RECT* pDestRect, HWND hDestWindowOverride, const RGNDATA* pDirtyRegion){IDirect3DDevice9 *pI = (IDirect3DDevice9 *)pThis;if(gD3D != pI){ gD3D = pI; gD3D->CreateOffscreenPlainSurface(512, 400, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &gSurf, NULL);}//Call our main class//g_GUI.OnFSXPresent(pI);//Call the real "Present"RemovePatch(); HRESULT hr = RealPresent(pThis, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);ApplyPatch();return hr;}//Modify d3d9.dll Present function to call ours insteadvoid ApplyPatch(){for (int i = 0; i < 5; i++) *(g_pPatchAddr + i) = g_PatchCode[i];//FlushInstructionCache(GetCurrentProcess(), g_pPatchAddr, 5); //apparently not necessary on x86 and x64 CPU's?return;}//Restore d3d9.dll's Present function to its original codevoid RemovePatch(){for (int i = 0; i < 5; i++) *(g_pPatchAddr + i) = g_OrigCode[i];//FlushInstructionCache(GetCurrentProcess(), g_pPatchAddr, 5);return;} [/source]
My problem now is to find the relevant textures. There has to be a table or something somewhere....Can someone give me some clues on how to find it and what to look for?
Thanks
JB
Edited by Naruto-kun, 15 October 2012 - 11:07 AM.






