1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-27 08:45:00 +01:00

convert Windows-1252 to UTF8 where necessary, fixes #744

This commit is contained in:
IntelOrca
2015-02-05 17:34:51 +00:00
parent 4fc91adce2
commit e4914085ad
4 changed files with 30 additions and 3 deletions

View File

@@ -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) {

View File

@@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include <windows.h>
#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);
}

View File

@@ -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

View File

@@ -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))))