Advertisement
Guest User

ns2 crossfire fix source

a guest
Sep 4th, 2013
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.00 KB | None | 0 0
  1. //=============================
  2. //defs.def (to give the exports the correct name and ordinals)
  3. EXPORTS
  4. D3DPERF_BeginEvent=__E__0__ @1
  5. D3DPERF_EndEvent=__E__1__ @2
  6. D3DPERF_GetStatus=__E__2__ @3
  7. D3DPERF_QueryRepeatFrame=__E__3__ @4
  8. D3DPERF_SetMarker=__E__4__ @5
  9. D3DPERF_SetOptions=__E__5__ @6
  10. D3DPERF_SetRegion=__E__6__ @7
  11. Direct3DCreate9=__E__7__ @8
  12.  
  13.  
  14. //=============================
  15. //dllmain.cpp (where the stuff is done)
  16.  
  17. #include <windows.h>
  18. #include <windowsx.h>
  19. #include <d3d9.h>
  20. #include "stdafx.h"
  21. #include <stdio.h>
  22. #include <string.h>
  23.  
  24. #pragma comment(lib, "detours.lib")
  25. #include <detours.h>
  26.  
  27. #pragma pack(1)
  28.  
  29.  
  30. HINSTANCE hLThis = 0;
  31. HINSTANCE hL = 0;
  32. FARPROC p[8] = {0};
  33.  
  34. typedef IDirect3D9 *(WINAPI* D3D9_Type)(UINT SDKVersion);
  35.  
  36.  
  37. typedef HRESULT (WINAPI*D3D9_CreateDevice) (int *lixo,UINT Adapter,D3DDEVTYPE DeviceType,HWND hFocusWindow,DWORD BehaviorFlags,
  38.   D3DPRESENT_PARAMETERS *pPresentationParameters,
  39.   IDirect3DDevice9 **ppReturnedDeviceInterface);
  40.  
  41.  
  42. D3D9_Type D3DCreate9_fn;
  43. D3D9_CreateDevice CreateDevice_Real;
  44.  
  45.  
  46.  
  47. BOOL WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID)
  48.     {
  49.     if (reason == DLL_PROCESS_ATTACH)
  50.         {
  51.         hLThis = hInst;
  52.  
  53.         char pasta_w[256];
  54.  
  55.         GetSystemDirectoryA(pasta_w,256);
  56.         strcat(pasta_w,"\\d3d9.dll");
  57.  
  58.         hL = LoadLibraryA(pasta_w);
  59.         if (!hL) return false;
  60.  
  61.         p[0] = GetProcAddress(hL,"D3DPERF_BeginEvent");
  62.         p[1] = GetProcAddress(hL,"D3DPERF_EndEvent");
  63.         p[2] = GetProcAddress(hL,"D3DPERF_GetStatus");
  64.         p[3] = GetProcAddress(hL,"D3DPERF_QueryRepeatFrame");
  65.         p[4] = GetProcAddress(hL,"D3DPERF_SetMarker");
  66.         p[5] = GetProcAddress(hL,"D3DPERF_SetOptions");
  67.         p[6] = GetProcAddress(hL,"D3DPERF_SetRegion");
  68.         p[7] = GetProcAddress(hL,"Direct3DCreate9");
  69.  
  70.         D3DCreate9_fn = (D3D9_Type) GetProcAddress(hL, "Direct3DCreate9");
  71.  
  72.         }
  73.     if (reason == DLL_PROCESS_DETACH)
  74.         {
  75.         FreeLibrary(hL);
  76.         }
  77.  
  78.     return 1;
  79.     }
  80.  
  81. // D3DPERF_BeginEvent
  82. extern "C" __declspec(naked) void __stdcall __E__0__()
  83.     {
  84.  
  85.         __asm
  86.         {
  87.         jmp p[0*4];
  88.         }
  89.     }
  90.  
  91. // D3DPERF_EndEvent
  92. extern "C" __declspec(naked) void __stdcall __E__1__()
  93.     {
  94.  
  95.        
  96.         __asm
  97.         {
  98.         jmp p[1*4];
  99.         }
  100.        
  101.     }
  102.  
  103. // D3DPERF_GetStatus
  104. extern "C" __declspec(naked) void __stdcall __E__2__()
  105.     {
  106.  
  107.    
  108.     __asm
  109.         {
  110.         jmp p[2*4];
  111.         }
  112.        
  113.     }
  114.  
  115. // D3DPERF_QueryRepeatFrame
  116. extern "C" __declspec(naked) void __stdcall __E__3__()
  117.     {
  118.  
  119.    
  120.     __asm
  121.         {
  122.         jmp p[3*4];
  123.         }
  124.        
  125.     }
  126.  
  127. // D3DPERF_SetMarker
  128. extern "C" __declspec(naked) void __stdcall __E__4__()
  129.     {
  130.  
  131.    
  132.     __asm
  133.         {
  134.         jmp p[4*4];
  135.         }
  136.        
  137.     }
  138.  
  139. // D3DPERF_SetOptions
  140. extern "C" __declspec(naked) void __stdcall __E__5__()
  141.     {
  142.  
  143.    
  144.     __asm
  145.         {
  146.         jmp p[5*4];
  147.         }
  148.        
  149.     }
  150.  
  151. // D3DPERF_SetRegion
  152. extern "C" __declspec(naked) void __stdcall __E__6__()
  153.     {
  154.    
  155.     __asm
  156.         {
  157.         jmp p[6*4];
  158.         }
  159.        
  160.     }
  161.  
  162.  
  163.  
  164.  
  165. HRESULT CreateDevice_alt___(UINT Adapter, D3DDEVTYPE DeviceType,HWND hFocusWindow, DWORD BehaviorFlags,D3DPRESENT_PARAMETERS *pPresentationParameters,IDirect3DDevice9 **ppReturnedDeviceInterface)
  166. {
  167.     /*
  168.    IDirect3DDevice9* pDirect3DDevice9;
  169.    HRESULT hRes = Direct3D9->CreateDevice( Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, &pDirect3DDevice9 );
  170.    *ppReturnedDeviceInterface = new Direct3DDevice9Wrapper( pDirect3DDevice9, this, pPresentationParameters );
  171.    return hRes;
  172.    */
  173.     return 0;
  174. }
  175.  
  176.  
  177.  
  178. HRESULT __stdcall CreateDevice_alt(int *Lixo,
  179.     UINT Adapter,//0=primera gpu?
  180.     D3DDEVTYPE DeviceType,//1=hal
  181.     HWND hFocusWindow,//é uma janela
  182.     DWORD BehaviorFlags,
  183.     D3DPRESENT_PARAMETERS *pPresentationParameters,
  184.     IDirect3DDevice9 **ppReturnedDeviceInterface)
  185. {
  186.     RECT res;
  187.     char podre[256];
  188.  
  189.     GetWindowRect(GetDesktopWindow(),&res);
  190.  
  191.     //the "fix" for the device creation
  192.     pPresentationParameters->Windowed=false;
  193.     pPresentationParameters->BackBufferWidth=res.right;
  194.     pPresentationParameters->BackBufferHeight=res.bottom;
  195.    
  196.  
  197.     sprintf(podre,"Windowed: %s\nRes:%d,%d\nBbufferCnt:%d\nMSAA type:%d quality:%d\nSwapEffect:%d",
  198.     (pPresentationParameters->Windowed)?"true":"false",
  199.     pPresentationParameters->BackBufferWidth,
  200.     pPresentationParameters->BackBufferHeight,
  201.     pPresentationParameters->BackBufferCount,
  202.     pPresentationParameters->MultiSampleType,
  203.     pPresentationParameters->MultiSampleQuality,
  204.     pPresentationParameters->SwapEffect
  205.     );
  206.  
  207.     //MessageBoxA(0,podre,"Yay",0);
  208.  
  209.     return CreateDevice_Real(Lixo,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ppReturnedDeviceInterface);
  210. }
  211.  
  212.  
  213. // Direct3DCreate9
  214. extern "C" IDirect3D9* __stdcall __E__7__(UINT SDKVersion)
  215. {
  216.  
  217.  
  218.     IDirect3D9 * pDirect3D = D3DCreate9_fn( SDKVersion );
  219.  
  220.  
  221.     UINT_PTR* pVTable = (UINT_PTR*)(*((UINT_PTR*)pDirect3D));
  222.     CreateDevice_Real = (D3D9_CreateDevice) pVTable[16];
  223.  
  224.    
  225.     DetourTransactionBegin();
  226.     DetourUpdateThread(GetCurrentThread());
  227.     DetourAttach(&(PVOID&)CreateDevice_Real, CreateDevice_alt);
  228.     if (DetourTransactionCommit() != ERROR_SUCCESS)
  229.     {
  230.         //MessageBox(0, L"failed to create createdev hook", L"", 0);
  231.     }
  232.    
  233.     return pDirect3D;
  234.    
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement