mirror of
https://github.com/PodeCaradox/GalaxyQuest-SteamFrame.git
synced 2026-10-23 19:01:38 +02:00
The sources of Petari (https://github.com/SMGCommunity/Petari), the Super Mario Galaxy decompilation by the SMGCommunity, at commit 0a5c6608dc3b4c44a9aa68c2535d1793dc565f02, unchanged but for LF line endings: LICENSE (as LICENSE-Petari.txt; CC0 1.0), include/, libs/ and src/. Left out: the game data Petari keeps from the original executable, the error message archive (include/Game/System/ ErrorArchive.hpp) and two tables (src/Game/System/GalaxyID.bcsv and StoryEvent.bcsv); GalaxyQuest's converter takes them from the player's own disc. The port's changes follow in the next commit, so `git diff petari-base -- decomp` shows them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
2.0 KiB
C
109 lines
2.0 KiB
C
#include "mbstring.h"
|
|
#include "locale.h"
|
|
#include <cstring>
|
|
|
|
int mbtowc(wchar_t *pDest, const char *s, size_t num) {
|
|
return _current_locale.ctype_cmpt_ptr->decode_mb(pDest, s, num);
|
|
}
|
|
|
|
inline int wctomb(char *pSrc, wchar_t wchar) {
|
|
return _current_locale.ctype_cmpt_ptr->encode_wc(pSrc, wchar);
|
|
}
|
|
|
|
int __mbtowc_noconv(wchar_t *pDest, const char *pSrc, size_t n) {
|
|
if (pSrc == 0) {
|
|
return 0;
|
|
}
|
|
|
|
if (n == 0) {
|
|
return -1;
|
|
}
|
|
|
|
if (pDest) {
|
|
*pDest = (unsigned char)*pSrc;
|
|
}
|
|
|
|
if (!*pSrc) {
|
|
return 0;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
int __wctomb_noconv(char *pSrc, wchar_t cr) {
|
|
if (pSrc == 0) {
|
|
return 0;
|
|
}
|
|
|
|
*pSrc = cr;
|
|
return 1;
|
|
}
|
|
|
|
size_t mbstowcs(wchar_t *pDest, const char *pSrc, size_t num) {
|
|
int res;
|
|
char* src;
|
|
int count;
|
|
size_t src_len;
|
|
|
|
src_len = strlen(pSrc);
|
|
|
|
if (pDest != 0) {
|
|
src = (char*)pSrc;
|
|
|
|
for (count = 0; count < num; count++) {
|
|
if (*src) {
|
|
res = mbtowc(pDest++, src, src_len);
|
|
|
|
if (res > 0) {
|
|
src += res;
|
|
src_len -= res;
|
|
}
|
|
else {
|
|
return -1;
|
|
}
|
|
}
|
|
else {
|
|
*pDest = 0;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
count = 0;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
size_t wcstombs(char *pSrc, const wchar_t *pwcs, size_t n) {
|
|
int chars_written = 0;
|
|
int result;
|
|
char temp[3];
|
|
wchar_t* source;
|
|
|
|
if (!pSrc || !pwcs) {
|
|
return 0;
|
|
}
|
|
|
|
source = (wchar_t*)pwcs;
|
|
|
|
while (chars_written <= n) {
|
|
if (!*source) {
|
|
*(pSrc + chars_written) = '\0';
|
|
break;
|
|
}
|
|
else {
|
|
result = wctomb(temp, *source++);
|
|
|
|
if ((chars_written + result) <= n) {
|
|
strncpy(pSrc + chars_written, temp, result);
|
|
chars_written += result;
|
|
}
|
|
else {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return chars_written;
|
|
} |