From 0f000a196e56bbbcce3470dc8510c4d7990d2f3b Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Sun, 21 Jan 2018 14:12:39 +0100 Subject: [PATCH] Fix compilation --- src/openloco/{log.cpp => console.cpp} | 24 +++++++++++++---- src/openloco/{log.h => console.h} | 1 + src/openloco/interop/hooks.cpp | 37 +++++++++++---------------- src/openloco/interop/interop.cpp | 2 +- src/openloco/openloco.cpp | 3 +++ 5 files changed, 39 insertions(+), 28 deletions(-) rename src/openloco/{log.cpp => console.cpp} (62%) rename src/openloco/{log.h => console.h} (78%) diff --git a/src/openloco/log.cpp b/src/openloco/console.cpp similarity index 62% rename from src/openloco/log.cpp rename to src/openloco/console.cpp index 0c4c9e6a8a..c731dd2198 100644 --- a/src/openloco/log.cpp +++ b/src/openloco/console.cpp @@ -1,21 +1,35 @@ -#include "log.h" +#include +#include "console.h" #include "utility/string.hpp" namespace openloco::console { static int _group = 0; - void log(const char *format, ...) + static void vwrite(FILE * buffer, const char *format, va_list args) { for (int i = 0; i < _group; i++) { - printf(" "); + fprintf(buffer, " "); } + vprintf(format, args); + fprintf(buffer, "\n"); + } + + void log(const char *format, ...) + { va_list args; va_start(args, format); - vprintf(format, args); + vwrite(stdout, format, args); + va_end(args); + } + + void error(const char *format, ...) + { + va_list args; + va_start(args, format); + vwrite(stderr, format, args); va_end(args); - printf("\n"); } void group(const char *format, ...) diff --git a/src/openloco/log.h b/src/openloco/console.h similarity index 78% rename from src/openloco/log.h rename to src/openloco/console.h index 5dbbd77ea0..78b4de7310 100644 --- a/src/openloco/log.h +++ b/src/openloco/console.h @@ -3,6 +3,7 @@ namespace openloco::console { void log(const char* format, ...); + void error(const char* format, ...); void group(const char* format, ...); void group_end(); diff --git a/src/openloco/interop/hooks.cpp b/src/openloco/interop/hooks.cpp index 1729140265..8cb4a0c5bf 100644 --- a/src/openloco/interop/hooks.cpp +++ b/src/openloco/interop/hooks.cpp @@ -1,7 +1,9 @@ +#include #include #include #ifndef _WIN32 #include +#include #endif #include "../environment.h" #include "../graphics/gfx.h" @@ -13,7 +15,7 @@ #include "../windowmgr.h" #include "interop.hpp" #include "../platform/platform.h" -#include "../log.h" +#include "../console.h" using namespace openloco; @@ -389,10 +391,8 @@ fn_free(void * block) return free(block); } - - +static void STDCALL -void fn_dump(uint32_t address) { console::log("Missing hook: 0x%x", address); @@ -403,7 +403,7 @@ enum { DSERR_NODRIVER = 0x88780078, }; -uint32_t +static uint32_t STDCALL lib_DirectSoundCreate(void* lpGuid, void*ppDS, void*pUnkOuter) { @@ -412,7 +412,7 @@ lib_DirectSoundCreate(void* lpGuid, void*ppDS, void*pUnkOuter) return DSERR_NODRIVER; } -uint32_t +static uint32_t STDCALL lib_CreateRectRgn(int x1, int y1, int x2, int y2) { @@ -420,7 +420,7 @@ lib_CreateRectRgn(int x1, int y1, int x2, int y2) return 0; } -uint +static uint STDCALL lib_GetUpdateRgn(uintptr_t hWnd, uintptr_t hRgn, bool bErase) { @@ -428,7 +428,7 @@ lib_GetUpdateRgn(uintptr_t hWnd, uintptr_t hRgn, bool bErase) return 0; } -void * +static void * STDCALL lib_OpenMutexA(uint32_t dwDesiredAccess, bool bInheritHandle, char *lpName) { @@ -437,7 +437,7 @@ lib_OpenMutexA(uint32_t dwDesiredAccess, bool bInheritHandle, char *lpName) return nullptr; } -bool +static bool STDCALL lib_DeleteFileA(char *lpFileName) { @@ -446,7 +446,7 @@ lib_DeleteFileA(char *lpFileName) return false; } -bool +static bool STDCALL lib_WriteFile( FILE *hFile, @@ -460,7 +460,7 @@ lib_WriteFile( return true; } -void * +static void * STDCALL FORCE_ALIGN_ARG_POINTER lib_CreateFileA( @@ -477,7 +477,7 @@ lib_CreateFileA( return fopen(lpFileName, "r"); } -bool +static bool STDCALL FORCE_ALIGN_ARG_POINTER lib_SetFileAttributesA(char *lpFileName, uint32_t dwFileAttributes) @@ -497,7 +497,7 @@ lib_SetFileAttributesA(char *lpFileName, uint32_t dwFileAttributes) return false; } -void * +static void * STDCALL lib_CreateMutexA(uintptr_t lmMutexAttributes, bool bInitialOwner, char *lpName) { @@ -506,14 +506,14 @@ lib_CreateMutexA(uintptr_t lmMutexAttributes, bool bInitialOwner, char *lpName) return nullptr; } -void +static void STDCALL lib_CloseHandle(int a0) { console::log("CloseHandle(%d)", a0); } -void +static void STDCALL FORCE_ALIGN_ARG_POINTER lib_PostQuitMessage(int32_t exitCode) @@ -522,13 +522,6 @@ lib_PostQuitMessage(int32_t exitCode) exit(exitCode); } -void -STDCALL -lib_4(int div, int addr, int a0, int a1, int a2, int a3) -{ - console::log("::::::::::::::::::: %x: %x %x %x %x", addr, a0, a1, a2, a3); -} - static void register_no_win32_hooks() { using namespace openloco::interop; diff --git a/src/openloco/interop/interop.cpp b/src/openloco/interop/interop.cpp index 46a41b7c31..ba06b3588a 100644 --- a/src/openloco/interop/interop.cpp +++ b/src/openloco/interop/interop.cpp @@ -1,6 +1,6 @@ #include #include "interop.hpp" -#include "../log.h" +#include "../console.h" #pragma warning(disable : 4731) // frame pointer register 'ebp' modified by inline assembly code #define PLATFORM_X86 diff --git a/src/openloco/openloco.cpp b/src/openloco/openloco.cpp index 7ad6569ba1..d496f6a23f 100644 --- a/src/openloco/openloco.cpp +++ b/src/openloco/openloco.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #ifdef _WIN32 // timeGetTime is unavailable if we use lean and mean @@ -81,10 +82,12 @@ namespace openloco return glpCmdLine; } +#ifndef _WIN32 void lpCmdLine(const char * path) { glpCmdLine = strdup(path); } +#endif bool is_editor_mode() {