Fix Text n Pager

This commit is contained in:
Sergeanur 2020-03-28 04:58:58 +02:00
parent c953230237
commit cd913404a3
2 changed files with 285 additions and 285 deletions

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
struct PagerMessage { struct PagerMessage {
wchar *m_pText; wchar *m_pText;
uint16 m_nSpeedMs; uint16 m_nSpeedMs;
@ -9,20 +9,20 @@ struct PagerMessage {
uint32 m_nTimeToChangePosition; uint32 m_nTimeToChangePosition;
int16 field_10; int16 field_10;
int32 m_nNumber[6]; int32 m_nNumber[6];
}; };
#define NUMPAGERMESSAGES 8 #define NUMPAGERMESSAGES 8
class CPager class CPager
{ {
int16 m_nNumDisplayLetters; int16 m_nNumDisplayLetters;
PagerMessage m_messages[NUMPAGERMESSAGES]; PagerMessage m_messages[NUMPAGERMESSAGES];
public: public:
void Init(); void Init();
void Process(); void Process();
void Display(); void Display();
void AddMessage(wchar*, uint16, uint16, uint16); void AddMessage(wchar*, uint16, uint16, uint16);
void AddMessageWithNumber(wchar *str, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, uint16 speed, uint16 priority, uint16 a11); void AddMessageWithNumber(wchar *str, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, uint16 speed, uint16 priority, uint16 a11);
void ClearMessages(); void ClearMessages();
void RestartCurrentMessage(); void RestartCurrentMessage();
}; };

View File

@ -1,92 +1,92 @@
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
#include "FileMgr.h" #include "FileMgr.h"
#include "Frontend.h" #include "Frontend.h"
#include "Messages.h" #include "Messages.h"
#include "Text.h" #include "Text.h"
static wchar WideErrorString[25]; static wchar WideErrorString[25];
CText &TheText = *(CText*)0x941520; CText &TheText = *(CText*)0x941520;
CText::CText(void) CText::CText(void)
{ {
encoding = 'e'; encoding = 'e';
memset(WideErrorString, 0, sizeof(WideErrorString)); memset(WideErrorString, 0, sizeof(WideErrorString));
} }
void void
CText::Load(void) CText::Load(void)
{ {
uint8 *filedata; uint8 *filedata;
char filename[32], type[4]; char filename[32], type[4];
int length; int length;
int offset, sectlen; int offset, sectlen;
Unload(); Unload();
filedata = new uint8[0x40000]; filedata = new uint8[0x40000];
CFileMgr::SetDir("TEXT"); CFileMgr::SetDir("TEXT");
switch(CMenuManager::m_PrefsLanguage){ switch(CMenuManager::m_PrefsLanguage){
case LANGUAGE_AMERICAN: case LANGUAGE_AMERICAN:
sprintf(filename, "AMERICAN.GXT"); sprintf(filename, "AMERICAN.GXT");
break; break;
case LANGUAGE_FRENCH: case LANGUAGE_FRENCH:
sprintf(filename, "FRENCH.GXT"); sprintf(filename, "FRENCH.GXT");
break; break;
case LANGUAGE_GERMAN: case LANGUAGE_GERMAN:
sprintf(filename, "GERMAN.GXT"); sprintf(filename, "GERMAN.GXT");
break; break;
case LANGUAGE_ITALIAN: case LANGUAGE_ITALIAN:
sprintf(filename, "ITALIAN.GXT"); sprintf(filename, "ITALIAN.GXT");
break; break;
case LANGUAGE_SPANISH: case LANGUAGE_SPANISH:
sprintf(filename, "SPANISH.GXT"); sprintf(filename, "SPANISH.GXT");
break; break;
} }
length = CFileMgr::LoadFile(filename, filedata, 0x40000, "rb"); length = CFileMgr::LoadFile(filename, filedata, 0x40000, "rb");
CFileMgr::SetDir(""); CFileMgr::SetDir("");
offset = 0; offset = 0;
while(offset < length){ while(offset < length){
type[0] = filedata[offset++]; type[0] = filedata[offset++];
type[1] = filedata[offset++]; type[1] = filedata[offset++];
type[2] = filedata[offset++]; type[2] = filedata[offset++];
type[3] = filedata[offset++]; type[3] = filedata[offset++];
sectlen = (int)filedata[offset+3]<<24 | (int)filedata[offset+2]<<16 | sectlen = (int)filedata[offset+3]<<24 | (int)filedata[offset+2]<<16 |
(int)filedata[offset+1]<<8 | (int)filedata[offset+0]; (int)filedata[offset+1]<<8 | (int)filedata[offset+0];
offset += 4; offset += 4;
if(sectlen != 0){ if(sectlen != 0){
if(strncmp(type, "TKEY", 4) == 0) if(strncmp(type, "TKEY", 4) == 0)
keyArray.Load(sectlen, filedata, &offset); keyArray.Load(sectlen, filedata, &offset);
else if(strncmp(type, "TDAT", 4) == 0) else if(strncmp(type, "TDAT", 4) == 0)
data.Load(sectlen, filedata, &offset); data.Load(sectlen, filedata, &offset);
else else
offset += sectlen; offset += sectlen;
} }
} }
keyArray.Update(data.chars); keyArray.Update(data.chars);
delete[] filedata; delete[] filedata;
} }
void void
CText::Unload(void) CText::Unload(void)
{ {
CMessages::ClearAllMessagesDisplayedByGame(); CMessages::ClearAllMessagesDisplayedByGame();
data.Unload(); data.Unload();
keyArray.Unload(); keyArray.Unload();
} }
wchar* wchar*
CText::Get(const char *key) CText::Get(const char *key)
{ {
return keyArray.Search(key); return keyArray.Search(key);
} }
wchar UpperCaseTable[128] = { wchar UpperCaseTable[128] = {
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 150, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
@ -98,10 +98,10 @@ wchar UpperCaseTable[128] = {
216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248,
249, 250, 251, 252, 253, 254, 255 249, 250, 251, 252, 253, 254, 255
}; };
wchar FrenchUpperCaseTable[128] = { wchar FrenchUpperCaseTable[128] = {
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
150, 65, 65, 65, 65, 132, 133, 69, 69, 69, 69, 73, 73, 150, 65, 65, 65, 65, 132, 133, 69, 69, 69, 69, 73, 73,
@ -113,11 +113,11 @@ wchar FrenchUpperCaseTable[128] = {
220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230,
231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
253, 254, 255 253, 254, 255
}; };
wchar wchar
CText::GetUpperCase(wchar c) CText::GetUpperCase(wchar c)
{ {
switch (encoding) switch (encoding)
{ {
@ -144,176 +144,176 @@ CText::GetUpperCase(wchar c)
default: default:
break; break;
} }
return c; return c;
} }
void void
CText::UpperCase(wchar *s) CText::UpperCase(wchar *s)
{ {
while(*s){ while(*s){
*s = GetUpperCase(*s); *s = GetUpperCase(*s);
s++; s++;
} }
} }
void void
CKeyArray::Load(uint32 length, uint8 *data, int *offset) CKeyArray::Load(uint32 length, uint8 *data, int *offset)
{ {
uint32 i; uint32 i;
uint8 *rawbytes; uint8 *rawbytes;
numEntries = length / sizeof(CKeyEntry); numEntries = length / sizeof(CKeyEntry);
entries = new CKeyEntry[numEntries]; entries = new CKeyEntry[numEntries];
rawbytes = (uint8*)entries; rawbytes = (uint8*)entries;
for(i = 0; i < length; i++) for(i = 0; i < length; i++)
rawbytes[i] = data[(*offset)++]; rawbytes[i] = data[(*offset)++];
} }
void void
CKeyArray::Unload(void) CKeyArray::Unload(void)
{ {
delete[] entries; delete[] entries;
entries = nil; entries = nil;
numEntries = 0; numEntries = 0;
} }
void void
CKeyArray::Update(wchar *chars) CKeyArray::Update(wchar *chars)
{ {
int i; int i;
for(i = 0; i < numEntries; i++) for(i = 0; i < numEntries; i++)
entries[i].value = (wchar*)((uint8*)chars + (uintptr)entries[i].value); entries[i].value = (wchar*)((uint8*)chars + (uintptr)entries[i].value);
} }
CKeyEntry* CKeyEntry*
CKeyArray::BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 high) CKeyArray::BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 high)
{ {
int mid; int mid;
int diff; int diff;
if(low > high) if(low > high)
return nil; return nil;
mid = (low + high)/2; mid = (low + high)/2;
diff = strcmp(key, entries[mid].key); diff = strcmp(key, entries[mid].key);
if(diff == 0) if(diff == 0)
return &entries[mid]; return &entries[mid];
if(diff < 0) if(diff < 0)
return BinarySearch(key, entries, low, mid-1); return BinarySearch(key, entries, low, mid-1);
if(diff > 0) if(diff > 0)
return BinarySearch(key, entries, mid+1, high); return BinarySearch(key, entries, mid+1, high);
return nil; return nil;
} }
wchar* wchar*
CKeyArray::Search(const char *key) CKeyArray::Search(const char *key)
{ {
CKeyEntry *found; CKeyEntry *found;
char errstr[25]; char errstr[25];
int i; int i;
found = BinarySearch(key, entries, 0, numEntries-1); found = BinarySearch(key, entries, 0, numEntries-1);
if(found) if(found)
return found->value; return found->value;
sprintf(errstr, "%s missing", key); sprintf(errstr, "%s missing", key);
for(i = 0; i < 25; i++) for(i = 0; i < 25; i++)
WideErrorString[i] = errstr[i]; WideErrorString[i] = errstr[i];
return WideErrorString; return WideErrorString;
} }
void void
CData::Load(uint32 length, uint8 *data, int *offset) CData::Load(uint32 length, uint8 *data, int *offset)
{ {
uint32 i; uint32 i;
uint8 *rawbytes; uint8 *rawbytes;
numChars = length / sizeof(wchar); numChars = length / sizeof(wchar);
chars = new wchar[numChars]; chars = new wchar[numChars];
rawbytes = (uint8*)chars; rawbytes = (uint8*)chars;
for(i = 0; i < length; i++) for(i = 0; i < length; i++)
rawbytes[i] = data[(*offset)++]; rawbytes[i] = data[(*offset)++];
} }
void void
CData::Unload(void) CData::Unload(void)
{ {
delete[] chars; delete[] chars;
chars = nil; chars = nil;
numChars = 0; numChars = 0;
} }
void void
AsciiToUnicode(const char *src, wchar *dst) AsciiToUnicode(const char *src, wchar *dst)
{ {
while((*dst++ = *src++) != '\0'); while((*dst++ = *src++) != '\0');
} }
char* char*
UnicodeToAscii(wchar *src) UnicodeToAscii(wchar *src)
{ {
static char aStr[256]; static char aStr[256];
int len; int len;
for(len = 0; *src != '\0' && len < 256-1; len++, src++) for(len = 0; *src != '\0' && len < 256-1; len++, src++)
if(*src < 128) if(*src < 128)
aStr[len] = *src; aStr[len] = *src;
else else
aStr[len] = '#'; aStr[len] = '#';
aStr[len] = '\0'; aStr[len] = '\0';
return aStr; return aStr;
} }
char* char*
UnicodeToAsciiForSaveLoad(wchar *src) UnicodeToAsciiForSaveLoad(wchar *src)
{ {
static char aStr[256]; static char aStr[256];
int len; int len;
for(len = 0; *src != '\0' && len < 256-1; len++, src++) for(len = 0; *src != '\0' && len < 256-1; len++, src++)
if(*src < 256) if(*src < 256)
aStr[len] = *src; aStr[len] = *src;
else else
aStr[len] = '#'; aStr[len] = '#';
aStr[len] = '\0'; aStr[len] = '\0';
return aStr; return aStr;
} }
void void
UnicodeStrcpy(wchar *dst, const wchar *src) UnicodeStrcpy(wchar *dst, const wchar *src)
{ {
while((*dst++ = *src++) != '\0'); while((*dst++ = *src++) != '\0');
} }
int int
UnicodeStrlen(const wchar *str) UnicodeStrlen(const wchar *str)
{ {
int len; int len;
for(len = 0; *str != '\0'; len++, str++); for(len = 0; *str != '\0'; len++, str++);
return len; return len;
} }
void void
TextCopy(wchar *dst, const wchar *src) TextCopy(wchar *dst, const wchar *src)
{ {
while((*dst++ = *src++) != '\0'); while((*dst++ = *src++) != '\0');
} }
STARTPATCHES STARTPATCHES
InjectHook(0x52C3C0, &CText::Load, PATCH_JUMP); InjectHook(0x52C3C0, &CText::Load, PATCH_JUMP);
InjectHook(0x52C580, &CText::Unload, PATCH_JUMP); InjectHook(0x52C580, &CText::Unload, PATCH_JUMP);
InjectHook(0x52C5A0, &CText::Get, PATCH_JUMP); InjectHook(0x52C5A0, &CText::Get, PATCH_JUMP);
InjectHook(0x52C220, &CText::GetUpperCase, PATCH_JUMP); InjectHook(0x52C220, &CText::GetUpperCase, PATCH_JUMP);
InjectHook(0x52C2C0, &CText::UpperCase, PATCH_JUMP); InjectHook(0x52C2C0, &CText::UpperCase, PATCH_JUMP);
InjectHook(0x52BE70, &CKeyArray::Load, PATCH_JUMP); InjectHook(0x52BE70, &CKeyArray::Load, PATCH_JUMP);
InjectHook(0x52BF60, &CKeyArray::Unload, PATCH_JUMP); InjectHook(0x52BF60, &CKeyArray::Unload, PATCH_JUMP);
InjectHook(0x52BF80, &CKeyArray::Update, PATCH_JUMP); InjectHook(0x52BF80, &CKeyArray::Update, PATCH_JUMP);
InjectHook(0x52C060, &CKeyArray::BinarySearch, PATCH_JUMP); InjectHook(0x52C060, &CKeyArray::BinarySearch, PATCH_JUMP);
InjectHook(0x52BFB0, &CKeyArray::Search, PATCH_JUMP); InjectHook(0x52BFB0, &CKeyArray::Search, PATCH_JUMP);
InjectHook(0x52C120, &CData::Load, PATCH_JUMP); InjectHook(0x52C120, &CData::Load, PATCH_JUMP);
InjectHook(0x52C200, &CData::Unload, PATCH_JUMP); InjectHook(0x52C200, &CData::Unload, PATCH_JUMP);
ENDPATCHES ENDPATCHES