Skip to content

Commit

Permalink
Fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnvdwerf committed Jan 21, 2018
1 parent 9d367b3 commit 0f000a1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
24 changes: 19 additions & 5 deletions src/openloco/log.cpp → src/openloco/console.cpp
@@ -1,21 +1,35 @@
#include "log.h"
#include <stdarg.h>
#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, ...)
Expand Down
1 change: 1 addition & 0 deletions src/openloco/log.h → src/openloco/console.h
Expand Up @@ -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();
Expand Down
37 changes: 15 additions & 22 deletions src/openloco/interop/hooks.cpp
@@ -1,7 +1,9 @@
#include <assert.h>
#include <cstring>
#include <cstdio>
#ifndef _WIN32
#include <sys/mman.h>
#include <unistd.h>
#endif
#include "../environment.h"
#include "../graphics/gfx.h"
Expand All @@ -13,7 +15,7 @@
#include "../windowmgr.h"
#include "interop.hpp"
#include "../platform/platform.h"
#include "../log.h"
#include "../console.h"

using namespace openloco;

Expand Down Expand Up @@ -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);
Expand All @@ -403,7 +403,7 @@ enum {
DSERR_NODRIVER = 0x88780078,
};

uint32_t
static uint32_t
STDCALL
lib_DirectSoundCreate(void* lpGuid, void*ppDS, void*pUnkOuter)
{
Expand All @@ -412,23 +412,23 @@ 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)
{
console::log("CreateRectRgn(%d, %d, %d, %d)", x1, y1, x2, y2);
return 0;
}

uint
static uint
STDCALL
lib_GetUpdateRgn(uintptr_t hWnd, uintptr_t hRgn, bool bErase)
{
console::log("GetUpdateRgn(%lx, %lx, %d)", hWnd, hRgn, bErase);
return 0;
}

void *
static void *
STDCALL
lib_OpenMutexA(uint32_t dwDesiredAccess, bool bInheritHandle, char *lpName)
{
Expand All @@ -437,7 +437,7 @@ lib_OpenMutexA(uint32_t dwDesiredAccess, bool bInheritHandle, char *lpName)
return nullptr;
}

bool
static bool
STDCALL
lib_DeleteFileA(char *lpFileName)
{
Expand All @@ -446,7 +446,7 @@ lib_DeleteFileA(char *lpFileName)
return false;
}

bool
static bool
STDCALL
lib_WriteFile(
FILE *hFile,
Expand All @@ -460,7 +460,7 @@ lib_WriteFile(
return true;
}

void *
static void *
STDCALL
FORCE_ALIGN_ARG_POINTER
lib_CreateFileA(
Expand All @@ -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)
Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/openloco/interop/interop.cpp
@@ -1,6 +1,6 @@
#include <cstring>
#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
Expand Down
3 changes: 3 additions & 0 deletions src/openloco/openloco.cpp
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <vector>
#include <setjmp.h>
#include <cstring>

#ifdef _WIN32
// timeGetTime is unavailable if we use lean and mean
Expand Down Expand Up @@ -81,10 +82,12 @@ namespace openloco
return glpCmdLine;
}

#ifndef _WIN32
void lpCmdLine(const char * path)
{
glpCmdLine = strdup(path);
}
#endif

bool is_editor_mode()
{
Expand Down

0 comments on commit 0f000a1

Please sign in to comment.