Пример #1
0
//
// getsysmemsize() -- gets the amount of system memory in the machine
//
unsigned int Bgetsysmemsize(void)
{
#ifdef _WIN32
    unsigned int siz = 0x7fffffff;
	HMODULE lib;
	WINBASEAPI BOOL WINAPI (*aGlobalMemoryStatusEx)(LPMEMORYSTATUSEX) = 0;
	
	lib = LoadLibrary("KERNEL32.DLL");
	if (lib) aGlobalMemoryStatusEx = (void *)GetProcAddress(lib, "GlobalMemoryStatusEx");
	
	if (aGlobalMemoryStatusEx) {
        //WinNT
        MEMORYSTATUSEX memst;
        memst.dwLength = sizeof(MEMORYSTATUSEX);
        if (aGlobalMemoryStatusEx(&memst)) {
            siz = (unsigned int)min(longlong(0x7fffffff), memst.ullTotalPhys);
        }
	} else {
        //Win9x
        MEMORYSTATUS memst;
        GlobalMemoryStatus(&memst);
        siz = (unsigned int)memst.dwTotalPhys;
	}
	
	if (lib) FreeLibrary(lib);
	
	return siz;
#elif (defined(_SC_PAGE_SIZE) || defined(_SC_PAGESIZE)) && defined(_SC_PHYS_PAGES)
	unsigned int siz = 0x7fffffff;
	long scpagesiz, scphyspages;

#ifdef _SC_PAGE_SIZE
	scpagesiz = sysconf(_SC_PAGE_SIZE);
#else
	scpagesiz = sysconf(_SC_PAGESIZE);
#endif
	scphyspages = sysconf(_SC_PHYS_PAGES);
	if (scpagesiz >= 0 && scphyspages >= 0)
		siz = (unsigned int)min(longlong(0x7fffffff), (int64)scpagesiz * (int64)scphyspages);

	//initprintf("Bgetsysmemsize(): %d pages of %d bytes, %d bytes of system memory\n",
	//		scphyspages, scpagesiz, siz);

	return siz;
#else
	return 0x7fffffff;
#endif
}
#include "tools/func_hook.hpp"

#include "MyDirectDrawSw.hpp"

template<typename FUNC>
struct HookInfo
{
    const char* moduleName = nullptr;
    const char* funcName   = nullptr;
    FUNC* original         = nullptr;
    const FUNC* hook       = nullptr;
    HookInfo(const char* m, const char* f, const FUNC* h):
        moduleName(m), funcName(f), hook(h) {}
};

auto GetCursorPosHook   = HookInfo<BOOL WINAPI(LPPOINT)>      ("User32.dll", "GetCursorPos",   &MyGetCursorPos);
auto ClientToScreenHook = HookInfo<BOOL WINAPI(HWND ,LPPOINT)>("User32.dll", "ClientToScreen", &MyClientToScreen);

auto Hooks = std::make_tuple(&GetCursorPosHook,
                             &ClientToScreenHook);

template<typename FUNC>
bool InitHook(HookInfo<FUNC>& hook, logger* mLog, HMODULE module)
{
    const char* moduleName = hook.moduleName;
    const char* funcName   = hook.funcName;
    if(nullptr == hook.original)
    {
        const HRESULT hr = func_hook::PatchIat(module,
                                               moduleName,
                                               funcName,