1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-22 15:23:01 +01:00

Use standard platform defines

This commit is contained in:
Ted John
2017-06-12 18:00:15 +01:00
parent 25b6c613b9
commit 7e9f7df7d1
19 changed files with 66 additions and 68 deletions

View File

@@ -38,16 +38,16 @@
#endif #endif
// Platform // Platform
#ifdef __WINDOWS__ #ifdef _WIN32
#define OPENRCT2_PLATFORM "Windows" #define OPENRCT2_PLATFORM "Windows"
#endif #endif
#ifdef __LINUX__ #ifdef __linux__
#define OPENRCT2_PLATFORM "Linux" #define OPENRCT2_PLATFORM "Linux"
#endif #endif
#ifdef __MACOSX__ #if (defined(__APPLE__) && defined(__MACH__))
#define OPENRCT2_PLATFORM "macOS" #define OPENRCT2_PLATFORM "macOS"
#endif #endif
#ifdef __FREEBSD__ #ifdef __FreeBSD__
#define OPENRCT2_PLATFORM "FreeBSD" #define OPENRCT2_PLATFORM "FreeBSD"
#endif #endif
#ifndef OPENRCT2_PLATFORM #ifndef OPENRCT2_PLATFORM

View File

@@ -176,7 +176,7 @@ void audio_populate_devices()
} }
} }
#ifndef __LINUX__ #ifndef __linux__
// The first device is always system default on Windows and macOS // The first device is always system default on Windows and macOS
std::string defaultDevice = language_get_string(STR_OPTIONS_SOUND_VALUE_DEFAULT); std::string defaultDevice = language_get_string(STR_OPTIONS_SOUND_VALUE_DEFAULT);
devices.insert(devices.begin(), defaultDevice); devices.insert(devices.begin(), defaultDevice);

View File

@@ -519,7 +519,7 @@ namespace CommandLine
static bool HandleSpecialArgument(const char * argument) static bool HandleSpecialArgument(const char * argument)
{ {
#ifdef __MACOSX__ #ifdef __APPLE__
if (String::Equals(argument, "-NSDocumentRevisionsDebugMode")) if (String::Equals(argument, "-NSDocumentRevisionsDebugMode"))
{ {
return true; return true;

View File

@@ -94,7 +94,7 @@ static exitcode_t HandleCommandJoin(CommandLineArgEnumerator * enumerator);
static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator * enumerator); static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator * enumerator);
static exitcode_t HandleCommandScanObjects(CommandLineArgEnumerator * enumerator); static exitcode_t HandleCommandScanObjects(CommandLineArgEnumerator * enumerator);
#if defined(__WINDOWS__) && !defined(__MINGW32__) #if defined(_WIN32) && !defined(__MINGW32__)
static bool _removeShell = false; static bool _removeShell = false;
@@ -131,7 +131,7 @@ const CommandLineCommand CommandLine::RootCommands[]
DefineCommand("scan-objects", "<path>", StandardOptions, HandleCommandScanObjects), DefineCommand("scan-objects", "<path>", StandardOptions, HandleCommandScanObjects),
DefineCommand("handle-uri", "openrct2://.../", StandardOptions, CommandLine::HandleCommandUri), DefineCommand("handle-uri", "openrct2://.../", StandardOptions, CommandLine::HandleCommandUri),
#if defined(__WINDOWS__) && !defined(__MINGW32__) #if defined(_WIN32) && !defined(__MINGW32__)
DefineCommand("register-shell", "", RegisterShellOptions, HandleCommandRegisterShell), DefineCommand("register-shell", "", RegisterShellOptions, HandleCommandRegisterShell),
#endif #endif
@@ -400,7 +400,7 @@ static exitcode_t HandleCommandScanObjects(CommandLineArgEnumerator * enumerator
return EXITCODE_OK; return EXITCODE_OK;
} }
#if defined(__WINDOWS__) && !defined(__MINGW32__) #if defined(_WIN32) && !defined(__MINGW32__)
static exitcode_t HandleCommandRegisterShell(CommandLineArgEnumerator * enumerator) static exitcode_t HandleCommandRegisterShell(CommandLineArgEnumerator * enumerator)
{ {
exitcode_t result = CommandLine::HandleCommandDefault(); exitcode_t result = CommandLine::HandleCommandDefault();
@@ -419,7 +419,7 @@ static exitcode_t HandleCommandRegisterShell(CommandLineArgEnumerator * enumerat
} }
return EXITCODE_OK; return EXITCODE_OK;
} }
#endif // defined(__WINDOWS__) && !defined(__MINGW32__) #endif // defined(_WIN32) && !defined(__MINGW32__)
static void PrintAbout() static void PrintAbout()
{ {

View File

@@ -17,8 +17,6 @@
#ifndef _COMMON_H_ #ifndef _COMMON_H_
#define _COMMON_H_ #define _COMMON_H_
#include <SDL_platform.h>
#ifndef _USE_MATH_DEFINES #ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#endif #endif
@@ -52,7 +50,7 @@ typedef uint64_t uint64;
typedef char utf8; typedef char utf8;
typedef utf8* utf8string; typedef utf8* utf8string;
typedef const utf8* const_utf8string; typedef const utf8* const_utf8string;
#ifdef __WINDOWS__ #ifdef _WIN32
typedef wchar_t utf16; typedef wchar_t utf16;
typedef utf16* utf16string; typedef utf16* utf16string;
#endif #endif

View File

@@ -16,7 +16,7 @@
#include "../common.h" #include "../common.h"
#ifdef __WINDOWS__ #ifdef _WIN32
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#endif #endif
@@ -26,7 +26,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#elif defined(__WINDOWS__) #elif defined(_WIN32)
extern "C" { extern "C" {
// Windows needs this for widechar <-> utf8 conversion utils // Windows needs this for widechar <-> utf8 conversion utils
#include "../localisation/language.h" #include "../localisation/language.h"
@@ -227,7 +227,7 @@ protected:
}; };
#ifdef __WINDOWS__ #ifdef _WIN32
class FileScannerWindows final : public FileScannerBase class FileScannerWindows final : public FileScannerBase
{ {
@@ -286,7 +286,7 @@ private:
} }
}; };
#endif // __WINDOWS__ #endif // _WIN32
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
@@ -362,7 +362,7 @@ private:
IFileScanner * Path::ScanDirectory(const std::string &pattern, bool recurse) IFileScanner * Path::ScanDirectory(const std::string &pattern, bool recurse)
{ {
#ifdef __WINDOWS__ #ifdef _WIN32
return new FileScannerWindows(pattern, recurse); return new FileScannerWindows(pattern, recurse);
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) #elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
return new FileScannerUnix(pattern, recurse); return new FileScannerUnix(pattern, recurse);

View File

@@ -20,7 +20,7 @@
#include "../common.h" #include "../common.h"
#ifdef __WINDOWS__ #ifdef _WIN32
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#undef GetMessage #undef GetMessage
@@ -50,14 +50,14 @@ namespace Guard
// The default behaviour when an assertion is raised. // The default behaviour when an assertion is raised.
static ASSERT_BEHAVIOUR _assertBehaviour = static ASSERT_BEHAVIOUR _assertBehaviour =
#ifdef __WINDOWS__ #ifdef _WIN32
ASSERT_BEHAVIOUR::MESSAGE_BOX ASSERT_BEHAVIOUR::MESSAGE_BOX
#else #else
ASSERT_BEHAVIOUR::CASSERT ASSERT_BEHAVIOUR::CASSERT
#endif #endif
; ;
#ifdef __WINDOWS__ #ifdef _WIN32
static void GetAssertMessage(char * buffer, size_t bufferSize, const char * formattedMessage); static void GetAssertMessage(char * buffer, size_t bufferSize, const char * formattedMessage);
static void ForceCrash(); static void ForceCrash();
#endif #endif
@@ -107,7 +107,7 @@ namespace Guard
case ASSERT_BEHAVIOUR::CASSERT: case ASSERT_BEHAVIOUR::CASSERT:
assert(false); assert(false);
break; break;
#ifdef __WINDOWS__ #ifdef _WIN32
case ASSERT_BEHAVIOUR::MESSAGE_BOX: case ASSERT_BEHAVIOUR::MESSAGE_BOX:
{ {
// Show message box if we are not building for testing // Show message box if we are not building for testing
@@ -137,7 +137,7 @@ namespace Guard
Assert_VA(false, message, args); Assert_VA(false, message, args);
} }
#ifdef __WINDOWS__ #ifdef _WIN32
static void GetAssertMessage(char * buffer, size_t bufferSize, const char * formattedMessage) static void GetAssertMessage(char * buffer, size_t bufferSize, const char * formattedMessage)
{ {
String::Set(buffer, bufferSize, ASSERTION_MESSAGE); String::Set(buffer, bufferSize, ASSERTION_MESSAGE);

View File

@@ -88,7 +88,7 @@ namespace Path
{ {
lastPathSeperator = ch; lastPathSeperator = ch;
} }
#ifdef __WINDOWS__ #ifdef _WIN32
// Windows also allows forward slashes in paths // Windows also allows forward slashes in paths
else if (*ch == '/') else if (*ch == '/')
{ {
@@ -174,7 +174,7 @@ namespace Path
utf8 * GetAbsolute(utf8 *buffer, size_t bufferSize, const utf8 * relativePath) utf8 * GetAbsolute(utf8 *buffer, size_t bufferSize, const utf8 * relativePath)
{ {
#ifdef __WINDOWS__ #ifdef _WIN32
wchar_t * relativePathW = utf8_to_widechar(relativePath); wchar_t * relativePathW = utf8_to_widechar(relativePath);
wchar_t absolutePathW[MAX_PATH]; wchar_t absolutePathW[MAX_PATH];
DWORD length = GetFullPathNameW(relativePathW, (DWORD)Util::CountOf(absolutePathW), absolutePathW, NULL); DWORD length = GetFullPathNameW(relativePathW, (DWORD)Util::CountOf(absolutePathW), absolutePathW, NULL);
@@ -213,7 +213,7 @@ namespace Path
bool Equals(const utf8 * a, const utf8 * b) bool Equals(const utf8 * a, const utf8 * b)
{ {
bool ignoreCase = false; bool ignoreCase = false;
#ifdef __WINDOWS__ #ifdef _WIN32
ignoreCase = true; ignoreCase = true;
#endif #endif
return String::Equals(a, b, ignoreCase); return String::Equals(a, b, ignoreCase);

View File

@@ -62,7 +62,7 @@ extern "C"
// Linux requires a restart. This could be improved in the future by recreating the window, // Linux requires a restart. This could be improved in the future by recreating the window,
// https://github.com/OpenRCT2/OpenRCT2/issues/2015 // https://github.com/OpenRCT2/OpenRCT2/issues/2015
bool requiresRestart = true; bool requiresRestart = true;
#ifdef __WINDOWS__ #ifdef _WIN32
if (dstEngine != DRAWING_ENGINE_OPENGL) if (dstEngine != DRAWING_ENGINE_OPENGL)
{ {
// Windows is apparently able to switch to hardware rendering on the fly although // Windows is apparently able to switch to hardware rendering on the fly although

View File

@@ -18,12 +18,12 @@
#include <ctype.h> #include <ctype.h>
#ifdef __WINDOWS__ #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else #else
#include <iconv.h> #include <iconv.h>
#include <errno.h> #include <errno.h>
#endif // __WINDOWS__ #endif // _WIN32
#include "../config/Config.h" #include "../config/Config.h"
#include "../game.h" #include "../game.h"
@@ -1328,7 +1328,7 @@ utf8 *win1252_to_utf8_alloc(const char *src, size_t srcMaxSize)
sint32 win1252_to_utf8(utf8string dst, const char *src, size_t srcLength, size_t maxBufferLength) sint32 win1252_to_utf8(utf8string dst, const char *src, size_t srcLength, size_t maxBufferLength)
{ {
#ifdef __WINDOWS__ #ifdef _WIN32
utf16 stackBuffer[256]; utf16 stackBuffer[256];
utf16 *heapBuffer = NULL; utf16 *heapBuffer = NULL;
utf16 *intermediateBuffer = stackBuffer; utf16 *intermediateBuffer = stackBuffer;
@@ -1396,7 +1396,7 @@ sint32 win1252_to_utf8(utf8string dst, const char *src, size_t srcLength, size_t
//log_warning("converted %s of size %d, %d", dst, byte_diff, strlen(dst)); //log_warning("converted %s of size %d, %d", dst, byte_diff, strlen(dst));
sint32 result = byte_diff; sint32 result = byte_diff;
free(buffer_orig); free(buffer_orig);
#endif // __WINDOWS__ #endif // _WIN32
return result; return result;
} }

View File

@@ -54,7 +54,7 @@
#define LAST_SOCKET_ERROR() errno #define LAST_SOCKET_ERROR() errno
#define closesocket close #define closesocket close
#define ioctlsocket ioctl #define ioctlsocket ioctl
#if defined(__LINUX__) #if defined(__linux__)
#define FLAG_NO_PIPE MSG_NOSIGNAL #define FLAG_NO_PIPE MSG_NOSIGNAL
#else #else
#define FLAG_NO_PIPE 0 #define FLAG_NO_PIPE 0
@@ -457,7 +457,7 @@ private:
static bool SetNonBlocking(SOCKET socket, bool on) static bool SetNonBlocking(SOCKET socket, bool on)
{ {
#ifdef __WINDOWS__ #ifdef _WIN32
u_long nonBlocking = on; u_long nonBlocking = on;
return ioctlsocket(socket, FIONBIO, &nonBlocking) == 0; return ioctlsocket(socket, FIONBIO, &nonBlocking) == 0;
#else #else
@@ -479,7 +479,7 @@ ITcpSocket * CreateTcpSocket()
bool InitialiseWSA() bool InitialiseWSA()
{ {
#ifdef __WINDOWS__ #ifdef _WIN32
if (!_wsaInitialised) if (!_wsaInitialised)
{ {
log_verbose("Initialising WSA"); log_verbose("Initialising WSA");
@@ -499,7 +499,7 @@ bool InitialiseWSA()
void DisposeWSA() void DisposeWSA()
{ {
#ifdef __WINDOWS__ #ifdef _WIN32
if (_wsaInitialised) if (_wsaInitialised)
{ {
WSACleanup(); WSACleanup();

View File

@@ -33,7 +33,7 @@ void http_dispose() { }
#include "../core/String.hpp" #include "../core/String.hpp"
#include "../Version.h" #include "../Version.h"
#ifdef __WINDOWS__ #ifdef _WIN32
// cURL includes windows.h, but we don't need all of it. // cURL includes windows.h, but we don't need all of it.
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif

View File

@@ -18,7 +18,7 @@
// Despite the name, this file contains support for more OSs besides Linux, provided the necessary ifdefs remain small. // Despite the name, this file contains support for more OSs besides Linux, provided the necessary ifdefs remain small.
// Otherwise, they should be spun off into their own files. // Otherwise, they should be spun off into their own files.
#if defined(__LINUX__) || defined(__FREEBSD__) #if defined(__linux__) || defined(__FREEBSD__)
#ifdef __FREEBSD__ #ifdef __FREEBSD__
#include <sys/sysctl.h> #include <sys/sysctl.h>
@@ -42,7 +42,7 @@
void platform_get_exe_path(utf8 *outPath, size_t outSize) void platform_get_exe_path(utf8 *outPath, size_t outSize)
{ {
char exePath[MAX_PATH]; char exePath[MAX_PATH];
#ifdef __LINUX__ #ifdef __linux__
ssize_t bytesRead; ssize_t bytesRead;
bytesRead = readlink("/proc/self/exe", exePath, MAX_PATH); bytesRead = readlink("/proc/self/exe", exePath, MAX_PATH);
if (bytesRead == -1) { if (bytesRead == -1) {

View File

@@ -26,7 +26,7 @@ typedef struct rct2_install_info rct2_install_info;
#define MAX_PATH 260 #define MAX_PATH 260
#endif #endif
#ifdef __MACOSX__ #ifdef __APPLE__
#define KEYBOARD_PRIMARY_MODIFIER KMOD_GUI #define KEYBOARD_PRIMARY_MODIFIER KMOD_GUI
#else #else
#define KEYBOARD_PRIMARY_MODIFIER KMOD_CTRL #define KEYBOARD_PRIMARY_MODIFIER KMOD_CTRL
@@ -36,7 +36,7 @@ typedef struct rct2_install_info rct2_install_info;
#define TOUCH_DOUBLE_TIMEOUT 300 #define TOUCH_DOUBLE_TIMEOUT 300
#ifdef __WINDOWS__ #ifdef _WIN32
#define PATH_SEPARATOR "\\" #define PATH_SEPARATOR "\\"
#define PLATFORM_NEWLINE "\r\n" #define PLATFORM_NEWLINE "\r\n"
#else #else
@@ -48,7 +48,7 @@ typedef struct rct2_install_info rct2_install_info;
#define CTRL 0x200 #define CTRL 0x200
#define ALT 0x400 #define ALT 0x400
#define CMD 0x800 #define CMD 0x800
#ifdef __MACOSX__ #ifdef __APPLE__
#define PLATFORM_MODIFIER CMD #define PLATFORM_MODIFIER CMD
#else #else
#define PLATFORM_MODIFIER CTRL #define PLATFORM_MODIFIER CTRL
@@ -155,7 +155,7 @@ datetime64 platform_get_datetime_now_utc();
void core_init(); void core_init();
// Windows specific definitions // Windows specific definitions
#ifdef __WINDOWS__ #ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
@@ -169,14 +169,14 @@ void core_init();
// This function cannot be marked as 'static', even though it may seem to be, // This function cannot be marked as 'static', even though it may seem to be,
// as it requires external linkage, which 'static' prevents // as it requires external linkage, which 'static' prevents
__declspec(dllexport) sint32 StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, sint32 nCmdShow); __declspec(dllexport) sint32 StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, sint32 nCmdShow);
#endif // __WINDOWS__ #endif // _WIN32
#if defined(__LINUX__) || defined(__MACOSX__) || defined(__FREEBSD__) #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
void platform_posix_sub_user_data_path(char *buffer, size_t size, const char *homedir); void platform_posix_sub_user_data_path(char *buffer, size_t size, const char *homedir);
void platform_posix_sub_resolve_openrct_data_path(utf8 *out, size_t size); void platform_posix_sub_resolve_openrct_data_path(utf8 *out, size_t size);
#endif #endif
#ifdef __MACOSX__ #if defined(__APPLE__) && defined(__MACH__)
void macos_disallow_automatic_window_tabbing(); void macos_disallow_automatic_window_tabbing();
utf8* macos_str_decomp_to_precomp(); utf8* macos_str_decomp_to_precomp();
#endif #endif

View File

@@ -374,7 +374,7 @@ sint32 platform_enumerate_files_begin(const utf8 *pattern)
// macOS uses decomposed Unicode strings (e.g. an 'e' and a combining accent) in filenames // macOS uses decomposed Unicode strings (e.g. an 'e' and a combining accent) in filenames
// This causes problems with the sprite font, as the font only contains precomposed characters // This causes problems with the sprite font, as the font only contains precomposed characters
// The block below converts all filename strings to their precomposed form, preventing mojibake // The block below converts all filename strings to their precomposed form, preventing mojibake
#ifdef __MACOSX__ #ifdef __APPLE__
utf8* precomp_path = macos_str_decomp_to_precomp(paths[idx]); utf8* precomp_path = macos_str_decomp_to_precomp(paths[idx]);
size_t precomp_len = sizeof(utf8) * min(MAX_PATH, strnlen(precomp_path, MAX_PATH) + 2); size_t precomp_len = sizeof(utf8) * min(MAX_PATH, strnlen(precomp_path, MAX_PATH) + 2);
paths[idx] = malloc(precomp_len); paths[idx] = malloc(precomp_len);

View File

@@ -22,7 +22,7 @@
#include "../common.h" #include "../common.h"
#ifdef __WINDOWS__ #ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <lmcons.h> #include <lmcons.h>

View File

@@ -18,11 +18,11 @@
#ifndef NO_RCT2 #ifndef NO_RCT2
#ifdef __WINDOWS__ #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else #else
#include <sys/mman.h> #include <sys/mman.h>
#endif // __WINDOWS__ #endif // _WIN32
#include "../platform/platform.h" #include "../platform/platform.h"
#include "hook.h" #include "hook.h"
@@ -154,19 +154,19 @@ static void hookfunc(uintptr_t address, uintptr_t hookAddress, sint32 stacksize)
data[i++] = 0xC3; // retn data[i++] = 0xC3; // retn
#ifdef __WINDOWS__ #ifdef _WIN32
WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, data, i, 0); WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, data, i, 0);
#else #else
// We own the pages with PROT_WRITE | PROT_EXEC, we can simply just memcpy the data // We own the pages with PROT_WRITE | PROT_EXEC, we can simply just memcpy the data
memcpy((void *)address, data, i); memcpy((void *)address, data, i);
#endif // __WINDOWS__ #endif // _WIN32
} }
void addhook(uintptr_t address, hook_function *function) void addhook(uintptr_t address, hook_function *function)
{ {
if (!_hookTableAddress) { if (!_hookTableAddress) {
size_t size = _maxHooks * HOOK_BYTE_COUNT; size_t size = _maxHooks * HOOK_BYTE_COUNT;
#ifdef __WINDOWS__ #ifdef _WIN32
_hookTableAddress = VirtualAllocEx(GetCurrentProcess(), NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); _hookTableAddress = VirtualAllocEx(GetCurrentProcess(), NULL, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
#else #else
_hookTableAddress = mmap(NULL, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); _hookTableAddress = mmap(NULL, size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
@@ -175,7 +175,7 @@ void addhook(uintptr_t address, hook_function *function)
perror("mmap"); perror("mmap");
exit(1); exit(1);
} }
#endif // __WINDOWS__ #endif // _WIN32
} }
if (_hookTableOffset > _maxHooks) { if (_hookTableOffset > _maxHooks) {
return; return;
@@ -189,7 +189,7 @@ void addhook(uintptr_t address, hook_function *function)
i += 4; i += 4;
data[i++] = 0xC3; // retn data[i++] = 0xC3; // retn
#ifdef __WINDOWS__ #ifdef _WIN32
WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, data, i, 0); WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, data, i, 0);
#else #else
// We own the pages with PROT_WRITE | PROT_EXEC, we can simply just memcpy the data // We own the pages with PROT_WRITE | PROT_EXEC, we can simply just memcpy the data
@@ -206,7 +206,7 @@ void addhook(uintptr_t address, hook_function *function)
{ {
perror("mprotect"); perror("mprotect");
} }
#endif // __WINDOWS__ #endif // _WIN32
hookfunc(hookaddress, (uintptr_t)function, 0); hookfunc(hookaddress, (uintptr_t)function, 0);
_hookTableOffset++; _hookTableOffset++;
} }

View File

@@ -18,19 +18,19 @@
#include "../common.h" #include "../common.h"
#if defined(__WINDOWS__) #if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#endif #endif
#if defined(__unix__) || defined(__MACOSX__) #if defined(__unix__) || defined(__APPLE__)
#include <sys/mman.h> #include <sys/mman.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#endif // defined(__unix__) || defined(__MACOSX__) #endif // defined(__unix__) || defined(__APPLE__)
#include "../OpenRCT2.h" #include "../OpenRCT2.h"
#include "../util/sawyercoding.h" #include "../util/sawyercoding.h"
@@ -39,7 +39,7 @@
#include "hook.h" #include "hook.h"
#include "interop.h" #include "interop.h"
#if defined(USE_MMAP) && (defined(__unix__) || defined(__MACOSX__)) && !defined(NO_RCT2) #if defined(USE_MMAP) && (defined(__unix__) || defined(__APPLE__)) && !defined(NO_RCT2)
static sint32 fdData = -1; static sint32 fdData = -1;
#endif #endif
#if !defined(NO_RCT2) #if !defined(NO_RCT2)
@@ -68,7 +68,7 @@ bool rct2_interop_setup_segment()
#if !defined(NO_RCT2) #if !defined(NO_RCT2)
UNUSED(segments); UNUSED(segments);
#endif #endif
#if defined(USE_MMAP) && (defined(__unix__) || defined(__MACOSX__)) && !defined(NO_RCT2) #if defined(USE_MMAP) && (defined(__unix__) || defined(__APPLE__)) && !defined(NO_RCT2)
#define RDATA_OFFSET 0x004A4000 #define RDATA_OFFSET 0x004A4000
#define DATASEG_OFFSET 0x005E2000 #define DATASEG_OFFSET 0x005E2000
@@ -116,7 +116,7 @@ bool rct2_interop_setup_segment()
perror("mmap"); perror("mmap");
return false; return false;
} }
#endif // defined(USE_MMAP) && (defined(__unix__) || defined(__MACOSX__)) #endif // defined(USE_MMAP) && (defined(__unix__) || defined(__APPLE__))
#if defined(__unix__) && !defined(NO_RCT2) #if defined(__unix__) && !defined(NO_RCT2)
sint32 pageSize = getpagesize(); sint32 pageSize = getpagesize();
@@ -128,7 +128,7 @@ bool rct2_interop_setup_segment()
if (err != 0) if (err != 0)
{ {
err = errno; err = errno;
#ifdef __LINUX__ #ifdef __linux__
// On Linux ENOMEM means all requested range is unmapped // On Linux ENOMEM means all requested range is unmapped
if (err != ENOMEM) if (err != ENOMEM)
{ {
@@ -138,7 +138,7 @@ bool rct2_interop_setup_segment()
#else #else
pagesMissing = true; pagesMissing = true;
perror("mincore"); perror("mincore");
#endif // __LINUX__ #endif // __linux__
} else { } else {
for (sint32 i = 0; i < numPages; i++) for (sint32 i = 0; i < numPages; i++)
{ {
@@ -172,7 +172,7 @@ bool rct2_interop_setup_segment()
} }
#endif // defined(__unix__) #endif // defined(__unix__)
#if defined(USE_MMAP) && defined(__WINDOWS__) #if defined(USE_MMAP) && defined(_WIN32)
segments = VirtualAlloc((void *)(GOOD_PLACE_FOR_DATA_SEGMENT), len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); segments = VirtualAlloc((void *)(GOOD_PLACE_FOR_DATA_SEGMENT), len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
if ((uintptr_t)segments != GOOD_PLACE_FOR_DATA_SEGMENT) { if ((uintptr_t)segments != GOOD_PLACE_FOR_DATA_SEGMENT) {
log_error("VirtualAlloc, segments = %p, GetLastError = 0x%x", segments, GetLastError()); log_error("VirtualAlloc, segments = %p, GetLastError = 0x%x", segments, GetLastError());
@@ -195,7 +195,7 @@ bool rct2_interop_setup_segment()
return false; return false;
} }
fclose(file); fclose(file);
#endif // defined(USE_MMAP) && defined(__WINDOWS__) #endif // defined(USE_MMAP) && defined(_WIN32)
#if !defined(NO_RCT2) && defined(USE_MMAP) #if !defined(NO_RCT2) && defined(USE_MMAP)
// Check that the expected data is at various addresses. // Check that the expected data is at various addresses.
@@ -224,7 +224,7 @@ void rct2_interop_setup_hooks()
void rct2_interop_dispose() void rct2_interop_dispose()
{ {
#if defined(USE_MMAP) && (defined(__unix__) || defined(__MACOSX__)) && !defined(NO_RCT2) #if defined(USE_MMAP) && (defined(__unix__) || defined(__APPLE__)) && !defined(NO_RCT2)
munmap(segments, 12079104); munmap(segments, 12079104);
close(fdData); close(fdData);
#endif #endif

View File

@@ -1884,11 +1884,11 @@ static void window_options_paint(rct_window *w, rct_drawpixelinfo *dpi)
audioDeviceStringId = STR_SOUND_NONE; audioDeviceStringId = STR_SOUND_NONE;
} else { } else {
audioDeviceStringId = STR_STRING; audioDeviceStringId = STR_STRING;
#ifndef __LINUX__ #ifndef __linux__
if (gAudioCurrentDevice == 0) { if (gAudioCurrentDevice == 0) {
audioDeviceStringId = STR_OPTIONS_SOUND_VALUE_DEFAULT; audioDeviceStringId = STR_OPTIONS_SOUND_VALUE_DEFAULT;
} }
#endif // __LINUX__ #endif // __linux__
if (audioDeviceStringId == STR_STRING) { if (audioDeviceStringId == STR_STRING) {
audioDeviceName = gAudioDevices[gAudioCurrentDevice].name; audioDeviceName = gAudioDevices[gAudioCurrentDevice].name;
} }