From 0760dab6579fac1c4e149f6c41b57e2ee6f53785 Mon Sep 17 00:00:00 2001 From: Matthias Lanzinger Date: Sun, 27 Apr 2014 13:04:45 +0200 Subject: [PATCH] decompile get_system_info() --- src/addresses.h | 19 ++++++++++++++ src/rct2.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++- src/rct2.h | 1 + 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/addresses.h b/src/addresses.h index f37957a7f4..c18a2c488e 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -68,6 +68,8 @@ #define RCT2_ADDRESS_SCREEN_DPI 0x009ABDC8 #define RCT2_ADDRESS_SCREEN_WIDTH 0x009ABDD8 #define RCT2_ADDRESS_SCREEN_HEIGHT 0x009ABDDA +#define RCT2_ADDRESS_SCREEN_CAP_BPP 0x01423C10 +#define RCT2_ADDRESS_SCREEN_CAP_RASTER_STRETCH 0x01423C14 #define RCT2_ADDRESS_DIRTY_BLOCK_WIDTH 0x009ABDE4 #define RCT2_ADDRESS_DIRTY_BLOCK_HEIGHT 0x009ABDE6 @@ -188,6 +190,23 @@ #define RCT2_ADDRESS_OS_TIME_YEAR 0x01424320 #define RCT2_ADDRESS_OS_TIME_DAYOFWEEK 0x01423B20 +#define RCT2_ADDRESS_OS_PLATFORM_ID 0x01423B40 +#define RCT2_ADDRESS_OS_MAJOR_VERSION 0x01423B44 +#define RCT2_ADDRESS_OS_MINOR_VERSION 0x01423B48 +#define RCT2_ADDRESS_OS_BUILD_NUMBER 0x01423B4C +#define RCT2_ADDRESS_OS_USER_NAME 0x01423B68 +#define RCT2_ADDRESS_OS_COMPUTER_NAME 0x01423BB8 + +#define RCT2_ADDRESS_SYS_OEM_ID 0x01423B50 +#define RCT2_ADDRESS_SYS_CPU_LEVEL 0x01423B52 +#define RCT2_ADDRESS_SYS_CPU_REVISION 0x01423B54 +#define RCT2_ADDRESS_SYS_CPU_NUMBER 0x01423B58 + +#define RCT2_ADDRESS_MEM_TOTAL_PHYSICAL 0x01423B5C +#define RCT2_ADDRESS_MEM_TOTAL_PAGEFILE 0x01423B60 +#define RCT2_ADDRESS_MEM_TOTAL_VIRTUAL 0x01423B64 + + static void RCT2_CALLPROC_EBPSAFE(int address) { __asm push ebp diff --git a/src/rct2.c b/src/rct2.c index b85514bfaa..cc97b65254 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -66,7 +66,7 @@ __declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInsta { RCT2_GLOBAL(0x01423A08, HINSTANCE) = hInstance; RCT2_GLOBAL(RCT2_ADDRESS_CMDLINE, LPSTR) = lpCmdLine; - RCT2_CALLPROC(0x004076B1); // get_system_info() + get_system_info(); RCT2_CALLPROC(0x0040502E); // get_dsound_devices() rct2_init(); @@ -240,6 +240,72 @@ char *get_file_path(int pathId) return (char*)ebx; } +/** + * Obtains basic system versions and capabilities. + * rct2: 0x004076B1 + */ +void get_system_info() +{ + OSVERSIONINFO versionInfo; + SYSTEM_INFO sysInfo; + MEMORYSTATUS memInfo; + + versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + if (GetVersionEx(&versionInfo)){ + RCT2_GLOBAL(RCT2_ADDRESS_OS_PLATFORM_ID, uint32) = versionInfo.dwPlatformId; + RCT2_GLOBAL(RCT2_ADDRESS_OS_MAJOR_VERSION, uint32) = versionInfo.dwMajorVersion; + RCT2_GLOBAL(RCT2_ADDRESS_OS_MINOR_VERSION, uint32) = versionInfo.dwMinorVersion; + RCT2_GLOBAL(RCT2_ADDRESS_OS_BUILD_NUMBER, uint32) = versionInfo.dwBuildNumber; + } + else{ + RCT2_GLOBAL(RCT2_ADDRESS_OS_PLATFORM_ID, uint32) = -1; + RCT2_GLOBAL(RCT2_ADDRESS_OS_MAJOR_VERSION, uint32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_OS_MINOR_VERSION, uint32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_OS_BUILD_NUMBER, uint32) = 0; + } + + GetSystemInfo(&sysInfo); + // RCT2 only has 2 bytes reserved for OEM_ID even though it should be a DWORD + RCT2_GLOBAL(RCT2_ADDRESS_SYS_OEM_ID, uint16) = sysInfo.dwOemId; + RCT2_GLOBAL(RCT2_ADDRESS_SYS_CPU_LEVEL, uint16) = sysInfo.wProcessorLevel; + RCT2_GLOBAL(RCT2_ADDRESS_SYS_CPU_REVISION, uint16) = sysInfo.wProcessorRevision; + RCT2_GLOBAL(RCT2_ADDRESS_SYS_CPU_NUMBER, uint32) = sysInfo.dwNumberOfProcessors; + + GlobalMemoryStatus(&memInfo); + RCT2_GLOBAL(RCT2_ADDRESS_MEM_TOTAL_PHYSICAL, uint32) = memInfo.dwTotalPhys; + RCT2_GLOBAL(RCT2_ADDRESS_MEM_TOTAL_PAGEFILE, uint32) = memInfo.dwTotalPageFile; + RCT2_GLOBAL(RCT2_ADDRESS_MEM_TOTAL_VIRTUAL, uint32) = memInfo.dwTotalVirtual; + + uint32 size = 80; + GetUserName(RCT2_ADDRESS_OS_USER_NAME, &size); + size = 80; + GetComputerName(RCT2_ADDRESS_OS_COMPUTER_NAME, &size); + + // Screen Display Width/Height but RCT_ADDRESS_SCREEN_HEIGHT/WIDTH already taken? + RCT2_GLOBAL(0x01423C08, sint32) = GetSystemMetrics(SM_CXSCREEN); + RCT2_GLOBAL(0x01423C0C, sint32) = GetSystemMetrics(SM_CYSCREEN); + + HDC screenHandle = GetDC(NULL); + if (screenHandle){ + RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_CAP_BPP, sint32) = GetDeviceCaps(screenHandle, BITSPIXEL); + RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_CAP_RASTER_STRETCH, sint32) = GetDeviceCaps(screenHandle, RASTERCAPS) >> 8; + ReleaseDC(NULL, screenHandle); + } + else{ + RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_CAP_BPP, sint32) = 0; + RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_CAP_RASTER_STRETCH, sint32) = 0; + } + + RCT2_GLOBAL(0x01423C1C, uint32) = (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_CAP_BPP, sint32) >= 8); + if (RCT2_GLOBAL(RCT2_ADDRESS_OS_MAJOR_VERSION, uint32) < 4 || RCT2_GLOBAL(0x1423C10, sint32) < 4) + RCT2_GLOBAL(0x1423C18, sint32) = 0; + else + RCT2_GLOBAL(0x1423C18, sint32) = 1; + + RCT2_GLOBAL(0x01423C20, uint32) = RCT2_CALLFUNC(0x406993, uint32); // cpu_has_mmx() +} + + /** * Obtains os system time (day, month, year and day of the week). * rct2: 0x00407671 diff --git a/src/rct2.h b/src/rct2.h index 795893d846..59dd74dcf3 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -128,6 +128,7 @@ enum { void rct2_endupdate(); char *get_file_path(int pathId); +void get_system_info(); void get_system_time(); void *rct2_malloc(size_t numBytes); void *rct2_realloc(void *block, size_t numBytes);