diff options
author | Kissaki <kissaki@gmx.de> | 2013-11-25 02:18:29 +0400 |
---|---|---|
committer | Kissaki <kissaki@gmx.de> | 2013-11-25 02:18:29 +0400 |
commit | cd4e8350a5d2b128197804e02d7c711d11b6e72a (patch) | |
tree | 478ccb5e8218a15779ad78c3d4173c86221557a9 /overlay | |
parent | dfbc1b927934471db3ae006353b5a15617cadcdf (diff) |
Overlay: Changes as per PR-comments
* Use sizeof() rather then size constant where possible
Diffstat (limited to 'overlay')
-rw-r--r-- | overlay/d3d10.cpp | 13 | ||||
-rw-r--r-- | overlay/d3d9.cpp | 6 | ||||
-rw-r--r-- | overlay/dxgi.cpp | 9 | ||||
-rw-r--r-- | overlay/lib.cpp | 15 | ||||
-rw-r--r-- | overlay/lib.h | 5 |
5 files changed, 24 insertions, 24 deletions
diff --git a/overlay/d3d10.cpp b/overlay/d3d10.cpp index 340cc1549..b21f699d0 100644 --- a/overlay/d3d10.cpp +++ b/overlay/d3d10.cpp @@ -575,9 +575,8 @@ void hookD3D10(HMODULE hD3D10, bool preonly) { bHooked = true; - const int modulenamesize = MODULEFILEPATH_BUFLEN; - wchar_t modulename[modulenamesize]; - GetModuleFileNameW(hD3D10, modulename, modulenamesize); + wchar_t modulename[MODULEFILEPATH_BUFLEN]; + GetModuleFileNameW(hD3D10, modulename, ARRAY_NUM_ELEMENTS(modulename)); if (_wcsicmp(d3d10->wcFileName, modulename) == 0) { unsigned char *raw = (unsigned char *) hD3D10; @@ -658,7 +657,7 @@ void PrepareDXGI10(IDXGIAdapter1 *pAdapter, bool initializeDXGIData) { void ***vtbl = (void ***) pSwapChain; void *pPresent = (*vtbl)[8]; - int offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pPresent), dxgi->wcFileName, "D3D10", "Present"); + int offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pPresent), dxgi->wcFileName, ARRAY_NUM_ELEMENTS(dxgi->wcFileName), "D3D10", "Present"); if (offset >= 0) { if (initializeDXGIData) { dxgi->iOffsetPresent = offset; @@ -673,7 +672,7 @@ void PrepareDXGI10(IDXGIAdapter1 *pAdapter, bool initializeDXGIData) { } void *pResize = (*vtbl)[13]; - offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pResize), dxgi->wcFileName, "D3D10", "ResizeBuffers"); + offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pResize), dxgi->wcFileName, ARRAY_NUM_ELEMENTS(dxgi->wcFileName), "D3D10", "ResizeBuffers"); if (offset >= 0) { if (initializeDXGIData) { dxgi->iOffsetResize = offset; @@ -690,14 +689,14 @@ void PrepareDXGI10(IDXGIAdapter1 *pAdapter, bool initializeDXGIData) { vtbl = (void ***) pDevice; void *pAddRef = (*vtbl)[1]; - offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pAddRef), d3d10->wcFileName, "D3D10", "AddRef"); + offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pAddRef), d3d10->wcFileName, ARRAY_NUM_ELEMENTS(d3d10->wcFileName), "D3D10", "AddRef"); if (offset >= 0) { d3d10->iOffsetAddRef = offset; ods("D3D10: Successfully found AddRef offset: %ls: %d", d3d10->wcFileName, d3d10->iOffsetAddRef); } void *pRelease = (*vtbl)[2]; - offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pRelease), d3d10->wcFileName, "D3D10", "Release"); + offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pRelease), d3d10->wcFileName, ARRAY_NUM_ELEMENTS(d3d10->wcFileName), "D3D10", "Release"); if (offset >= 0) { d3d10->iOffsetRelease = offset; ods("D3D10: Successfully found Release offset: %ls: %d", d3d10->wcFileName, d3d10->iOffsetRelease); diff --git a/overlay/d3d9.cpp b/overlay/d3d9.cpp index 238b85851..1ccfa89f8 100644 --- a/overlay/d3d9.cpp +++ b/overlay/d3d9.cpp @@ -915,7 +915,7 @@ void checkD3D9Hook(bool preonly) { static void hookD3D9(HMODULE hD3D, bool preonly) { char procname[MODULEFILEPATH_BUFLEN]; - GetModuleFileName(NULL, procname, MODULEFILEPATH_BUFLEN); + GetModuleFileName(NULL, procname, ARRAY_NUM_ELEMENTS(procname)); ods("D3D9: hookD3D9 in App '%s'", procname); // Add a ref to ourselves; we do NOT want to get unloaded directly from this process. @@ -926,7 +926,7 @@ static void hookD3D9(HMODULE hD3D, bool preonly) { // Can we use the prepatch data? wchar_t modulename[MODULEFILEPATH_BUFLEN]; - GetModuleFileNameW(hD3D, modulename, MODULEFILEPATH_BUFLEN); + GetModuleFileNameW(hD3D, modulename, ARRAY_NUM_ELEMENTS(modulename)); if (_wcsicmp(d3dd->wcFileName, modulename) == 0) { // The module seems to match the one we prepared d3dd for. @@ -1010,7 +1010,7 @@ extern "C" __declspec(dllexport) void __cdecl PrepareD3D9() { if (hD3D != NULL) { - GetModuleFileNameW(hD3D, d3dd->wcFileName, MODULEFILEPATH_BUFLEN); + GetModuleFileNameW(hD3D, d3dd->wcFileName, ARRAY_NUM_ELEMENTS(d3dd->wcFileName)); std::string d3d9FnName("Direct3DCreate9"); pDirect3DCreate9 d3dcreate9 = reinterpret_cast<pDirect3DCreate9>(GetProcAddress(hD3D, d3d9FnName.c_str())); diff --git a/overlay/dxgi.cpp b/overlay/dxgi.cpp index 69a1b8c93..f959f9c88 100644 --- a/overlay/dxgi.cpp +++ b/overlay/dxgi.cpp @@ -128,9 +128,8 @@ void checkDXGIHook(bool preonly) { /// @param hDXGI must be a valid module handle. void hookDXGI(HMODULE hDXGI, bool preonly) { - const int modulenamesize = MODULEFILEPATH_BUFLEN; - wchar_t modulename[modulenamesize]; - GetModuleFileNameW(NULL, modulename, modulenamesize); + wchar_t modulename[MODULEFILEPATH_BUFLEN]; + GetModuleFileNameW(NULL, modulename, ARRAY_NUM_ELEMENTS(modulename)); ods("DXGI: hookDXGI in App '%ls'", modulename); // Add a ref to ourselves; we do NOT want to get unloaded directly from this process. @@ -140,7 +139,7 @@ void hookDXGI(HMODULE hDXGI, bool preonly) { bHooked = true; // Can we use the prepatch data? - GetModuleFileNameW(hDXGI, modulename, modulenamesize); + GetModuleFileNameW(hDXGI, modulename, ARRAY_NUM_ELEMENTS(modulename)); if (_wcsicmp(dxgi->wcFileName, modulename) == 0) { // The module seems to match the one we prepared d3dd for. @@ -185,7 +184,7 @@ extern "C" __declspec(dllexport) void __cdecl PrepareDXGI() { HMODULE hDXGI = LoadLibrary("DXGI.DLL"); if (hDXGI != NULL) { - GetModuleFileNameW(hDXGI, dxgi->wcFileName, MODULEFILEPATH_BUFLEN); + GetModuleFileNameW(hDXGI, dxgi->wcFileName, ARRAY_NUM_ELEMENTS(dxgi->wcFileName)); CreateDXGIFactory1Type pCreateDXGIFactory1 = reinterpret_cast<CreateDXGIFactory1Type>(GetProcAddress(hDXGI, "CreateDXGIFactory1")); ods("DXGI: Got CreateDXGIFactory1 at %p", pCreateDXGIFactory1); diff --git a/overlay/lib.cpp b/overlay/lib.cpp index 54e4420f1..1a53b3297 100644 --- a/overlay/lib.cpp +++ b/overlay/lib.cpp @@ -749,10 +749,10 @@ static void dllmainThreadAttach() { extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) { char procname[PROCNAMEFILEPATH_EXTENDED_BUFFER_BUFLEN]; - GetModuleFileNameA(NULL, procname, PROCNAMEFILEPATH_BUFLEN); + GetModuleFileNameA(NULL, procname, ARRAY_NUM_ELEMENTS(procname)); // Fix for windows XP; on length nSize does not include null-termination // @see http://msdn.microsoft.com/en-us/library/windows/desktop/ms683197%28v=vs.85%29.aspx - procname[1023] = '\0'; + procname[PROCNAMEFILEPATH_BUFLEN - 1] = '\0'; switch (fdwReason) { case DLL_PROCESS_ATTACH: @@ -783,15 +783,14 @@ bool IsFnInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::string &log if (!success) { ods((logPrefix + ": Failed to get module for " + fnName).c_str()); } else { - const int modulenamesize = MODULEFILEPATH_BUFLEN; - wchar_t modulename[modulenamesize]; - GetModuleFileNameW(hModule, modulename, modulenamesize); + wchar_t modulename[MODULEFILEPATH_BUFLEN]; + GetModuleFileNameW(hModule, modulename, ARRAY_NUM_ELEMENTS(modulename)); return _wcsicmp(modulename, refmodulepath) == 0; } return false; } -int GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::string &logPrefix, const std::string &fnName) { +int GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, unsigned int refmodulepathLen, const std::string &logPrefix, const std::string &fnName) { HMODULE hModule = NULL; @@ -802,10 +801,10 @@ int GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::strin const bool bInit = refmodulepath[0] == '\0'; if (bInit) { - GetModuleFileNameW(hModule, refmodulepath, MODULEFILEPATH_BUFLEN); + GetModuleFileNameW(hModule, refmodulepath, refmodulepathLen); } else { wchar_t modulename[MODULEFILEPATH_BUFLEN]; - GetModuleFileNameW(hModule, modulename, MODULEFILEPATH_BUFLEN); + GetModuleFileNameW(hModule, modulename, ARRAY_NUM_ELEMENTS(modulename)); if (_wcsicmp(modulename, refmodulepath) != 0) { ods((logPrefix + ": " + fnName + " functions module path does not match previously found. Now: '%ls', Previously: '%ls'").c_str(), modulename, refmodulepath); return -2; diff --git a/overlay/lib.h b/overlay/lib.h index f8fff5d64..ac5a1aa01 100644 --- a/overlay/lib.h +++ b/overlay/lib.h @@ -47,6 +47,9 @@ #define lround(x) static_cast<long int>((x) + (((x) >= 0.0) ? 0.5 : -0.5)) +#define ARRAY_SIZE_BYTES(x) sizeof(x) +#define ARRAY_NUM_ELEMENTS(x) (sizeof(x)/sizeof((x)[0])) + using namespace std; void __cdecl ods(const char *format, ...); @@ -162,6 +165,6 @@ extern bool IsFnInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::stri /// Checks fnptr is in a loaded module with module path refmodulepath. /// /// @return Offset as int or < 0 on failure. -extern int GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::string &logPrefix, const std::string &fnName); +extern int GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, unsigned int refmodulepathLen, const std::string &logPrefix, const std::string &fnName); #endif |