diff --git a/src/audio/mixer.cpp b/src/audio/mixer.cpp
index 77bb987817..0888df65b4 100644
--- a/src/audio/mixer.cpp
+++ b/src/audio/mixer.cpp
@@ -25,6 +25,7 @@ extern "C" {
#include "../config.h"
#include "../platform/platform.h"
#include "audio.h"
+ #include "../localisation/localisation.h"
}
#include "mixer.h"
@@ -46,9 +47,11 @@ bool Sample::Load(const char* filename)
{
log_verbose("Sample::Load(%s)", filename);
+ utf8 utf8filename[512];
+ win1252_to_utf8(utf8filename, filename, sizeof(utf8filename));
+
Unload();
- SDL_ClearError();
- SDL_RWops* rw = SDL_RWFromFile(filename, "rb");
+ SDL_RWops* rw = SDL_RWFromFile(utf8filename, "rb");
if (rw == NULL) {
log_verbose("Error loading %s", filename);
return false;
@@ -74,11 +77,18 @@ bool Sample::Load(const char* filename)
bool Sample::LoadCSS1(const char* filename, unsigned int offset)
{
+ log_verbose("Sample::LoadCSS1(%s, %d)", filename, offset);
+
+ utf8 utf8filename[512];
+ win1252_to_utf8(utf8filename, filename, sizeof(utf8filename));
+
Unload();
- SDL_RWops* rw = SDL_RWFromFile(filename, "rb");
+ SDL_RWops* rw = SDL_RWFromFile(utf8filename, "rb");
if (rw == NULL) {
+ log_verbose("Unable to load %s", filename);
return false;
}
+
Uint32 numsounds;
SDL_RWread(rw, &numsounds, sizeof(numsounds), 1);
if (offset > numsounds) {
diff --git a/src/localisation/localisation.c b/src/localisation/localisation.c
index d659e2ce0d..07021c6dff 100644
--- a/src/localisation/localisation.c
+++ b/src/localisation/localisation.c
@@ -18,6 +18,7 @@
* along with this program. If not, see .
*****************************************************************************/
+#include
#include "../addresses.h"
#include "../config.h"
#include "../game.h"
@@ -700,4 +701,13 @@ int get_string_length(char* buffer)
}
}
return length;
+}
+
+int win1252_to_utf8(utf8string dst, const char *src, int maxBufferLength)
+{
+ utf16 intermediateBuffer[512];
+
+ // TODO this supports only a maximum of 512 characters
+ MultiByteToWideChar(CP_ACP, 0, src, -1, intermediateBuffer, 512);
+ return WideCharToMultiByte(CP_UTF8, 0, intermediateBuffer, -1, dst, maxBufferLength, NULL, NULL);
}
\ No newline at end of file
diff --git a/src/localisation/localisation.h b/src/localisation/localisation.h
index 7d7680156d..cdaa833954 100644
--- a/src/localisation/localisation.h
+++ b/src/localisation/localisation.h
@@ -35,6 +35,8 @@ void user_string_clear_all();
rct_string_id user_string_allocate(int base, const char *text);
void user_string_free(rct_string_id id);
+int win1252_to_utf8(utf8string dst, const char *src, int maxBufferLength);
+
#define MAX_USER_STRINGS 1024
#define USER_STRING_MAX_LENGTH 32
diff --git a/src/rct2.h b/src/rct2.h
index 2252fab915..e87c33f904 100644
--- a/src/rct2.h
+++ b/src/rct2.h
@@ -43,6 +43,11 @@ typedef unsigned short uint16;
typedef unsigned long uint32;
typedef unsigned long long uint64;
+typedef char utf8;
+typedef wchar_t utf16;
+typedef utf8* utf8string;
+typedef utf16* utf16string;
+
#define rol8(x, shift) (((uint8)(x) << (shift)) | ((uint8)(x) >> (8 - (shift))))
#define ror8(x, shift) (((uint8)(x) >> (shift)) | ((uint8)(x) << (8 - (shift))))
#define rol16(x, shift) (((uint16)(x) << (shift)) | ((uint16)(x) >> (16 - (shift))))