Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- unsigned long BaseAddress = NULL; // Hold Battlefield 3's Base Address
- // credits: raiders
- ID3D11PixelShader* psRed = NULL;
- // raiders posted this here - http://www.unknowncheats.me/forum/direct3d/65135-directx-10-generateshader.html
- HRESULT GenerateShader(ID3D11Device* pD3DDevice, ID3D11PixelShader** pShader, float r, float g, float b)
- {
- char szCast[] = "struct VS_OUT"
- "{"
- " float4 Position : SV_Position;"
- " float4 Color : COLOR0;"
- "};"
- "float4 main( VS_OUT input ) : SV_Target"
- "{"
- " float4 fake;"
- " fake.a = 1.0;"
- " fake.r = %f;"
- " fake.g = %f;"
- " fake.b = %f;"
- " return fake;"
- "}";
- ID3D10Blob* pBlob;
- char szPixelShader[1000];
- sprintf(szPixelShader, szCast, r, g, b);
- HRESULT hr = D3DX11CompileFromMemory(szPixelShader, sizeof(szPixelShader), "shader", NULL, NULL, "main", "ps_4_0", NULL, NULL, NULL, &pBlob, NULL, NULL);
- if(FAILED(hr))
- return hr;
- hr = pD3DDevice->CreatePixelShader((DWORD*)pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, pShader);
- if(FAILED(hr))
- return hr;
- return S_OK;
- }
- HRESULT WINAPI hkCreateVertexShader( ID3D11Device * This, const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D11ClassLinkage *pClassLinkage, ID3D11VertexShader **ppVertexShader )
- {
- __asm NOP;
- return oCreateVertexShader( This, pShaderBytecode, BytecodeLength, pClassLinkage, ppVertexShader);
- }
- HRESULT WINAPI hkPresent( IDXGISwapChain * This, UINT SyncInterval, UINT Flags )
- {
- __asm NOP;
- if ( !pFont )
- if ( ppDevice && ppDeviceContext )
- pFontFactory->CreateFontWrapper( ppDevice , L"Arial", &pFont );
- if ( pFont )
- {
- wchar_t wa[256];
- swprintf( wa, 256, L"VertexCount: %i", vertexCount );
- pFont->DrawString( ppDeviceContext, wa, 8.f, 10.f, 10.f, ((logVertexCount == true) ? 0xFF00FF00 : 0xFF0000FF), 0 );
- swprintf( wa, 256, L"StartVertexLocation: %i", startVertexLocation );
- pFont->DrawString( ppDeviceContext, wa, 8.f, 10.f, 20.f, ((logStartVertexLocation == true) ? 0xFF00FF00 : 0xFF0000FF), 0 );
- // Check if our Shader got generated or not.
- swprintf( wa, 256, L"psRed: %s", ((psRed == NULL) ? L"NULL" : L"FILLED" ) );
- pFont->DrawString( ppDeviceContext, wa, 8.f, 10.f, 30.f, 0xFF00FF00, 0 );
- /*swprintf( wa, 256, L"IndexCount: %i", indexCount );
- pFont->DrawString( ppDeviceContext, wa, 8.0f, 10.f, 10.f, ((logIndexCount == true) ? 0xFF00FF00 : 0xFF0000FF), 0 );// Text color, 0xAaBbGgRr
- swprintf( wa, 256, L"StartIndexLocation: %i", startIndex );
- pFont->DrawString( ppDeviceContext, wa, 8.f, 10.f, 20.f, ((logStartIndex == true) ? 0xFF00FF00 : 0xFF0000FF), 0 );
- swprintf( wa, 256, L"BaseVertexLocation %i", baseVertex );
- pFont->DrawString( ppDeviceContext, wa, 8.f, 10.f, 30.f, ((logBaseVertex == true) ? 0xFF00FF00 : 0xFF0000FF), 0 );
- // Check if our Shader got generated or not.
- swprintf( wa, 256, L"psRed: %s", ((psRed == NULL) ? L"NULL" : L"FILLED" ) );
- pFont->DrawString( ppDeviceContext, wa, 8.f, 10.f, 40.f, 0xFF00FF00, 0 );*/
- }
- return oPresent( This, SyncInterval, Flags );
- }
- HRESULT WINAPI hkCreatePixelShader ( ID3D11Device * This, const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D11ClassLinkage *pClassLinkage, ID3D11PixelShader **ppPixelShader )
- {
- __asm NOP;
- return oCreatePixelShader( This, pShaderBytecode, BytecodeLength, pClassLinkage, ppPixelShader );
- }
- HRESULT WINAPI hkCreateGeometryShader( ID3D11Device * This, const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D11ClassLinkage *pClassLinkage, ID3D11GeometryShader **ppGeometryShader )
- {
- __asm NOP;
- return oCreateGeometryShader( This, pShaderBytecode, BytecodeLength, pClassLinkage, ppGeometryShader );
- }
- HRESULT WINAPI hkCreateTexture2D( ID3D11Device * This, const D3D11_TEXTURE2D_DESC *pDesc, void* Unknown, const D3D11_SUBRESOURCE_DATA *pInitialData, ID3D11Texture2D **ppTexture2D)
- {
- __asm INT 3;
- //add_log( "This: %X, D3D11_TEXTURE2D_DESC: %X, D3D11_SUBRESOURCE_DATA: %X, ID3D11Texture2D: %X", This, pDesc, pInitialData, ppTexture2D );
- return oCreateTexture2D( This, pDesc, Unknown, pInitialData, ppTexture2D );
- }
- HRESULT WINAPI hkDrawIndexed( ID3D11DeviceContext * This, UINT IndexCount, UINT StartIndexLocation, INT BaseVertexLocation )
- {
- __asm NOP;
- if ( !psRed ) // Probably shouldn't do this here but whatevz'
- GenerateShader( ppDevice, &psRed, 1.0f, 0.0f, 0.0f );
- /*if (psRed)
- This->PSSetShader( psRed, NULL, NULL );
- if ( logIndexCount && !logStartIndex && !logBaseVertex )
- if ( indexCount == IndexCount )
- This->PSSetShader( psRed, NULL, NULL );
- else if ( logIndexCount && logStartIndex && !logBaseVertex )
- if ( indexCount == IndexCount && startIndex == startIndex )
- This->PSSetShader( psRed, NULL, NULL );
- else if ( logIndexCount && logStartIndex && logBaseVertex )
- if ( indexCount == IndexCount && startIndex == startIndex && baseVertex == baseVertex )
- This->PSSetShader( psRed, NULL, NULL );
- else if ( !logIndexCount && logStartIndex && !logBaseVertex )
- if ( startIndex == startIndex )
- This->PSSetShader( psRed, NULL, NULL );
- else if ( !logIndexCount && logStartIndex && logBaseVertex )
- if ( startIndex == startIndex )
- This->PSSetShader( psRed, NULL, NULL );
- else if ( !logIndexCount && !logStartIndex && logBaseVertex )
- if ( baseVertex == baseVertex )
- This->PSSetShader( psRed, NULL, NULL );
- else if ( logIndexCount && !logStartIndex && logBaseVertex )
- if ( indexCount == IndexCount && baseVertex == baseVertex )
- This->PSSetShader( psRed, NULL, NULL );*/
- return oDrawIndexed( This, IndexCount, StartIndexLocation, BaseVertexLocation );
- }
- HRESULT WINAPI hkVSSetConstantBuffers(ID3D11DeviceContext* pDevice,UINT StartSlot, UINT NumBuffers,ID3D11Buffer *const *ppConstantBuffers)
- {
- __asm nop;
- return oVSSetConstantBuffers(pDevice ,StartSlot, NumBuffers,ppConstantBuffers);
- }
- HRESULT WINAPI hkMap(ID3D11DeviceContext* pDevice, ID3D11Resource *pResource, UINT Subresource, D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE *pMappedResource)
- {
- __asm NOP;
- // Could do this elsewhere but whatever, I already have it hooked for other testing
- if ( !ppDevice || !ppDeviceContext )
- {
- ppDeviceContext = pDevice;
- ppDeviceContext->GetDevice( &ppDevice );
- }
- return oMap(pDevice,pResource,Subresource,MapType,MapFlags,pMappedResource);
- }
- bool ye = false;
- HRESULT WINAPI hkPSSetShaderResources(ID3D11DeviceContext * This, UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView *const *ppShaderResourceViews)
- {
- __asm NOP;
- /*if ( StartSlot == 7 && ye)
- return D3D_OK;*/
- return oPSSetShaderResources( This, StartSlot, NumViews, ppShaderResourceViews );
- }
- void WINAPI hkDrawInstanced(UINT VertexCountPerInstance, UINT InstanceCount, UINT StartVertexLocation, UINT StartInstanceLocation)
- {
- }
- HRESULT WINAPI hkDraw( ID3D11DeviceContext * This, UINT VertexCount, UINT StartVertexLocation )
- {
- __asm NOP;
- if ( !ppDevice )
- This->GetDevice( &ppDevice );
- if ( !ppDeviceContext )
- ppDevice->GetImmediateContext( &ppDeviceContext );
- if ( !psRed ) // Probably shouldn't do this here but whatevz'
- GenerateShader( ppDevice, &psRed, 1.0f, 0.0f, 0.0f );
- //if (psRed)
- // This->PSSetShader( psRed, NULL, NULL );
- if ( logVertexCount && !logStartVertexLocation )
- if ( vertexCount == VertexCount )
- return D3D_OK;
- //This->PSSetShader( psRed, NULL, NULL );
- else if ( !logVertexCount && logStartVertexLocation )
- if ( startVertexLocation == StartVertexLocation )
- This->PSSetShader( psRed, NULL, NULL );
- else if ( logVertexCount && logStartVertexLocation )
- if ( vertexCount == VertexCount && startVertexLocation == StartVertexLocation )
- This->PSSetShader( psRed, NULL, NULL );
- return oDraw( This, VertexCount, StartVertexLocation );
- }
- // Logging Input
- DWORD WINAPI StartInput( LPVOID )
- {
- for ( ;; )
- {
- // DrawIndexed
- /*if ( GetAsyncKeyState( VK_F1 ) & 0x8000 )
- if ( indexCount > 0 )
- indexCount--;
- if ( GetAsyncKeyState( VK_F2 ) & 0x8000 )
- indexCount++;
- if ( GetAsyncKeyState( VK_F3 ) & 0x8000 )
- if ( startIndex > 0 )
- startIndex--;
- if ( GetAsyncKeyState( VK_F4 ) & 0x8000 )
- startIndex++;
- if ( GetAsyncKeyState( VK_F5 ) & 0x8000 )
- if ( baseVertex > 0 )
- baseVertex--;
- if ( GetAsyncKeyState( VK_F6 ) & 0x8000 )
- baseVertex++;
- if ( GetAsyncKeyState( VK_F7 ) & 0x8000 )
- logIndexCount = !logIndexCount;
- if ( GetAsyncKeyState( VK_F8 ) & 0x8000 )
- logStartIndex = !logStartIndex;
- if ( GetAsyncKeyState( VK_F9 ) & 0x8000 )
- logBaseVertex = !logBaseVertex;*/
- if ( GetAsyncKeyState( VK_F1 ) & 0x8000 )
- if ( vertexCount > 0 )
- vertexCount--;
- if ( GetAsyncKeyState( VK_F2 ) & 0x8000 )
- vertexCount++;
- if ( GetAsyncKeyState( VK_F3 ) & 0x8000 )
- if ( startVertexLocation > 0 )
- startVertexLocation--;
- if ( GetAsyncKeyState( VK_F4 ) & 0x8000 )
- startVertexLocation++;
- if ( GetAsyncKeyState( VK_F5 ) & 0x8000 )
- logVertexCount = !logVertexCount;
- if ( GetAsyncKeyState( VK_F6 ) & 0x8000 )
- logStartVertexLocation = !logStartVertexLocation;
- if ( GetAsyncKeyState( VK_F1 ) & 0x8000 )
- ye = !ye;
- Sleep( 75 );
- }
- return 0;
- }
- DWORD WINAPI StartRev( LPVOID )
- {
- BaseAddress = (DWORD)GetModuleHandle( NULL );
- /*while ( GetModuleHandle( "d3d11.dll" ) == NULL )
- Sleep( 250 );*/
- unsigned long D3DPtr = *(unsigned long*)(BaseAddress + BF3D3DPTR); // Device Pointer Offset
- while ( D3DPtr == NULL )
- {
- D3DPtr = *(unsigned long*)(BaseAddress + BF3D3DPTR);
- Sleep( 250 );
- }
- // g_dxRenderer = 0xD8
- unsigned long D3DDevice = *(unsigned long*)(D3DPtr + 0xD8);
- unsigned long DeviceVTable = *(unsigned long*)D3DDevice;
- // 0xDC DeviceContext
- // but the context function are func+1
- unsigned long DXGISwapChainDevice = *(unsigned long*)(D3DPtr + 0xF4);
- unsigned long SwapChainVTable = *(unsigned long*)DXGISwapChainDevice;
- unsigned long DeviceContext = *(unsigned long*)(D3DPtr + 0xDC);
- unsigned long DeviceContextVTable = *(unsigned long*)DeviceContext;
- DWORD* devicePVTable = (DWORD*)(DeviceVTable); // The Address + sizeof(IUnknown)
- DWORD* swapChainPVTable = (DWORD*)(SwapChainVTable);
- DWORD* deviceContextPVTable = (DWORD*)(DeviceContextVTable);
- mFile.open("Battlefield_Reversing.log");
- if ( mFile.is_open() )
- {
- HRESULT hRet = FW1CreateFactory( FW1_VERSION, &pFontFactory );
- add_log("Started Hooking Functions...");
- //oCreateVertexShader = (tCreateVertexShader)DetourFunction( (PBYTE)devicePVTable[12], (PBYTE)hkCreateVertexShader );
- //oCreateGeometryShader = (tCreateGeometryShader)DetourFunction( (PBYTE)devicePVTable[13], (PBYTE)hkCreateGeometryShader );
- //oCreatePixelShader = (tCreatePixelShader)DetourFunction( (PBYTE)devicePVTable[15], (PBYTE)hkCreatePixelShader );
- oMap = (tMap)DetourFunction( (PBYTE)deviceContextPVTable[14], (PBYTE)hkMap );
- //oVSSetConstantBuffers = (tVSSetConstantBuffers)DetourFunction( (PBYTE)deviceContextPVTable[7], (PBYTE)hkVSSetConstantBuffers );
- oPresent = (tPresent)DetourFunction( (PBYTE)swapChainPVTable[8], (PBYTE)hkPresent );
- oDrawIndexed = (tDrawIndexed)DetourFunction( (PBYTE)deviceContextPVTable[12], (PBYTE)hkDrawIndexed );
- //oCreateTexture2D = (tCreateTexture2D)DetourFunction( (PBYTE)devicePVTable[5], (PBYTE)hkCreateTexture2D ); // ask fatboy help
- //oPSSetShaderResources = (tPSSetShaderResources)DetourFunction( (PBYTE)deviceContextPVTable[8], (PBYTE)hkPSSetShaderResources );
- oDraw = (tDraw) DetourFunction( (PBYTE)deviceContextPVTable[13], (PBYTE)hkDraw );
- add_log("All Functions Hooked!");
- }
- return 0;
- }
- BOOL WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpvReserved )
- {
- if ( dwReason == DLL_PROCESS_ATTACH )
- {
- CreateThread( 0, 0, StartRev, 0, 0, 0 );
- CreateThread( 0, 0, StartInput, 0, 0, 0 );
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment