diff options
author | aap <aap@papnet.eu> | 2020-04-09 20:50:24 +0200 |
---|---|---|
committer | aap <aap@papnet.eu> | 2020-04-09 20:50:24 +0200 |
commit | 34349c4df2683fca35be37ec626aaa8eef2ddaee (patch) | |
tree | 6a86b547819f30ab784d00891ee99b8924580093 /src/text | |
parent | Merge remote-tracking branch 'Fire-Head/master' (diff) | |
download | re3-34349c4df2683fca35be37ec626aaa8eef2ddaee.tar re3-34349c4df2683fca35be37ec626aaa8eef2ddaee.tar.gz re3-34349c4df2683fca35be37ec626aaa8eef2ddaee.tar.bz2 re3-34349c4df2683fca35be37ec626aaa8eef2ddaee.tar.lz re3-34349c4df2683fca35be37ec626aaa8eef2ddaee.tar.xz re3-34349c4df2683fca35be37ec626aaa8eef2ddaee.tar.zst re3-34349c4df2683fca35be37ec626aaa8eef2ddaee.zip |
Diffstat (limited to '')
-rw-r--r-- | src/text/Messages.cpp | 1670 | ||||
-rw-r--r-- | src/text/Pager.cpp | 386 | ||||
-rw-r--r-- | src/text/Pager.h | 54 | ||||
-rw-r--r-- | src/text/Text.cpp | 648 |
4 files changed, 1379 insertions, 1379 deletions
diff --git a/src/text/Messages.cpp b/src/text/Messages.cpp index db5b9036..9896a8e0 100644 --- a/src/text/Messages.cpp +++ b/src/text/Messages.cpp @@ -1,835 +1,835 @@ -#define DIRECTINPUT_VERSION 0x0800
-#include "dinput.h"
-
-#include "common.h"
-#include "patcher.h"
-#include "Messages.h"
-#include "RwHelper.h"
-#include "Hud.h"
-#include "User.h"
-#include "Timer.h"
-#include "Text.h"
-
-#include "ControllerConfig.h"
-
-tMessage(&CMessages::BriefMessages)[NUMBRIEFMESSAGES] = *(tMessage(*)[NUMBRIEFMESSAGES])*(uintptr*)0x8786E0;
-tPreviousBrief(&CMessages::PreviousBriefs)[NUMPREVIOUSBRIEFS] = *(tPreviousBrief(*)[NUMPREVIOUSBRIEFS])*(uintptr*)0x713C08;
-tBigMessage(&CMessages::BIGMessages)[NUMBIGMESSAGES] = *(tBigMessage(*)[NUMBIGMESSAGES])*(uintptr*)0x773628;
-char CMessages::PreviousMissionTitle[16]; // unused
-
-void
-CMessages::Init()
-{
- ClearMessages();
-
- for (int32 i = 0; i < NUMPREVIOUSBRIEFS; i++) {
- PreviousBriefs[i].m_pText = nil;
- PreviousBriefs[i].m_pString = nil;
- }
-}
-
-uint16
-CMessages::GetWideStringLength(wchar *src)
-{
- uint16 length = 0;
- while (*(src++)) length++;
- return length;
-}
-
-void
-CMessages::WideStringCopy(wchar *dst, wchar *src, uint16 size)
-{
- int32 i = 0;
- if (src) {
- while (i < size - 1) {
- if (!src[i]) break;
- dst[i] = src[i];
- i++;
- }
- } else {
- while (i < size - 1)
- dst[i++] = '\0';
- }
- dst[i] = '\0';
-}
-
-bool
-CMessages::WideStringCompare(wchar *str1, wchar *str2, uint16 size)
-{
- uint16 len1 = GetWideStringLength(str1);
- uint16 len2 = GetWideStringLength(str2);
- if (len1 != len2 && (len1 < size || len2 < size))
- return false;
-
- for (int32 i = 0; i < size; i++) {
- if (!str1[i])
- break;
-
- if (str1[i] != str2[i])
- return false;
- }
- return true;
-}
-
-void
-CMessages::Process()
-{
- for (int32 style = 0; style < 6; style++) {
- if (BIGMessages[style].m_Stack[0].m_pText != nil && CTimer::GetTimeInMilliseconds() > BIGMessages[style].m_Stack[0].m_nTime + BIGMessages[style].m_Stack[0].m_nStartTime) {
- BIGMessages[style].m_Stack[0].m_pText = nil;
-
- int32 i = 0;
- while (i < 3) {
- if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) break;
- BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1];
- i++;
- }
-
- BIGMessages[style].m_Stack[i].m_pText = nil;
- BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- }
- }
-
- if (BriefMessages[0].m_pText != nil && CTimer::GetTimeInMilliseconds() > BriefMessages[0].m_nTime + BriefMessages[0].m_nStartTime) {
- BriefMessages[0].m_pText = nil;
- int32 i = 0;
- while (i < NUMBRIEFMESSAGES-1) {
- if (BriefMessages[i + 1].m_pText == nil)
- break;
-
- BriefMessages[i] = BriefMessages[i + 1];
- i++;
- }
- CMessages::BriefMessages[i].m_pText = nil;
- CMessages::BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- if (BriefMessages[0].m_pText != nil)
- AddToPreviousBriefArray(
- BriefMessages[0].m_pText,
- BriefMessages[0].m_nNumber[0],
- BriefMessages[0].m_nNumber[1],
- BriefMessages[0].m_nNumber[2],
- BriefMessages[0].m_nNumber[3],
- BriefMessages[0].m_nNumber[4],
- BriefMessages[0].m_nNumber[5],
- BriefMessages[0].m_pString);
- }
-}
-
-void
-CMessages::Display()
-{
- wchar outstr[256];
-
- DefinedState();
-
- for (int32 i = 0; i < NUMBIGMESSAGES; i++) {
- InsertNumberInString(
- BIGMessages[i].m_Stack[0].m_pText,
- BIGMessages[i].m_Stack[0].m_nNumber[0],
- BIGMessages[i].m_Stack[0].m_nNumber[1],
- BIGMessages[i].m_Stack[0].m_nNumber[2],
- BIGMessages[i].m_Stack[0].m_nNumber[3],
- BIGMessages[i].m_Stack[0].m_nNumber[4],
- BIGMessages[i].m_Stack[0].m_nNumber[5],
- outstr);
- InsertStringInString(outstr, BIGMessages[i].m_Stack[0].m_pString);
- InsertPlayerControlKeysInString(outstr);
- CHud::SetBigMessage(outstr, i);
- }
-
- InsertNumberInString(
- BriefMessages[0].m_pText,
- BriefMessages[0].m_nNumber[0],
- BriefMessages[0].m_nNumber[1],
- BriefMessages[0].m_nNumber[2],
- BriefMessages[0].m_nNumber[3],
- BriefMessages[0].m_nNumber[4],
- BriefMessages[0].m_nNumber[5],
- outstr);
- InsertStringInString(outstr, BriefMessages[0].m_pString);
- InsertPlayerControlKeysInString(outstr);
- CHud::SetMessage(outstr);
-}
-
-void
-CMessages::AddMessage(wchar *msg, uint32 time, uint16 flag)
-{
- wchar outstr[512]; // unused
- WideStringCopy(outstr, msg, 256);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- int32 i = 0;
- while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText != nil)
- i++;
- if (i >= NUMBRIEFMESSAGES) return;
-
- BriefMessages[i].m_pText = msg;
- BriefMessages[i].m_nFlag = flag;
- BriefMessages[i].m_nTime = time;
- BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[i].m_nNumber[0] = -1;
- BriefMessages[i].m_nNumber[1] = -1;
- BriefMessages[i].m_nNumber[2] = -1;
- BriefMessages[i].m_nNumber[3] = -1;
- BriefMessages[i].m_nNumber[4] = -1;
- BriefMessages[i].m_nNumber[5] = -1;
- BriefMessages[i].m_pString = nil;
- if (i == 0)
- AddToPreviousBriefArray(
- BriefMessages[0].m_pText,
- BriefMessages[0].m_nNumber[0],
- BriefMessages[0].m_nNumber[1],
- BriefMessages[0].m_nNumber[2],
- BriefMessages[0].m_nNumber[3],
- BriefMessages[0].m_nNumber[4],
- BriefMessages[0].m_nNumber[5],
- BriefMessages[0].m_pString);
-}
-
-void
-CMessages::AddMessageJumpQ(wchar *msg, uint32 time, uint16 flag)
-{
- wchar outstr[512]; // unused
- WideStringCopy(outstr, msg, 256);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- BriefMessages[0].m_pText = msg;
- BriefMessages[0].m_nFlag = flag;
- BriefMessages[0].m_nTime = time;
- BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[0].m_nNumber[0] = -1;
- BriefMessages[0].m_nNumber[1] = -1;
- BriefMessages[0].m_nNumber[2] = -1;
- BriefMessages[0].m_nNumber[3] = -1;
- BriefMessages[0].m_nNumber[4] = -1;
- BriefMessages[0].m_nNumber[5] = -1;
- BriefMessages[0].m_pString = nil;
- AddToPreviousBriefArray(msg, -1, -1, -1, -1, -1, -1, 0);
-}
-
-void
-CMessages::AddMessageSoon(wchar *msg, uint32 time, uint16 flag)
-{
- wchar outstr[512]; // unused
- WideStringCopy(outstr, msg, 256);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- if (BriefMessages[0].m_pText != nil) {
- for (int i = NUMBRIEFMESSAGES-1; i > 1; i--)
- BriefMessages[i] = BriefMessages[i-1];
-
- BriefMessages[1].m_pText = msg;
- BriefMessages[1].m_nFlag = flag;
- BriefMessages[1].m_nTime = time;
- BriefMessages[1].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[1].m_nNumber[0] = -1;
- BriefMessages[1].m_nNumber[1] = -1;
- BriefMessages[1].m_nNumber[2] = -1;
- BriefMessages[1].m_nNumber[3] = -1;
- BriefMessages[1].m_nNumber[4] = -1;
- BriefMessages[1].m_nNumber[5] = -1;
- BriefMessages[1].m_pString = nil;
- }else{
- BriefMessages[0].m_pText = msg;
- BriefMessages[0].m_nFlag = flag;
- BriefMessages[0].m_nTime = time;
- BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[0].m_nNumber[0] = -1;
- BriefMessages[0].m_nNumber[1] = -1;
- BriefMessages[0].m_nNumber[2] = -1;
- BriefMessages[0].m_nNumber[3] = -1;
- BriefMessages[0].m_nNumber[4] = -1;
- BriefMessages[0].m_nNumber[5] = -1;
- BriefMessages[0].m_pString = nil;
- AddToPreviousBriefArray(msg, -1, -1, -1, -1, -1, -1, nil);
- }
-}
-
-void
-CMessages::ClearMessages()
-{
- for (int32 i = 0; i < NUMBIGMESSAGES; i++) {
- for (int32 j = 0; j < 4; j++) {
- BIGMessages[i].m_Stack[j].m_pText = nil;
- BIGMessages[i].m_Stack[j].m_pString = nil;
- }
- }
- ClearSmallMessagesOnly();
-}
-
-void
-CMessages::ClearSmallMessagesOnly()
-{
- for (int32 i = 0; i < NUMBRIEFMESSAGES; i++) {
- BriefMessages[i].m_pText = nil;
- BriefMessages[i].m_pString = nil;
- }
-}
-
-void
-CMessages::AddBigMessage(wchar *msg, uint32 time, uint16 style)
-{
- wchar outstr[512]; // unused
- WideStringCopy(outstr, msg, 256);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- BIGMessages[style].m_Stack[0].m_pText = msg;
- BIGMessages[style].m_Stack[0].m_nFlag = 0;
- BIGMessages[style].m_Stack[0].m_nTime = time;
- BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BIGMessages[style].m_Stack[0].m_nNumber[0] = -1;
- BIGMessages[style].m_Stack[0].m_nNumber[1] = -1;
- BIGMessages[style].m_Stack[0].m_nNumber[2] = -1;
- BIGMessages[style].m_Stack[0].m_nNumber[3] = -1;
- BIGMessages[style].m_Stack[0].m_nNumber[4] = -1;
- BIGMessages[style].m_Stack[0].m_nNumber[5] = -1;
- BIGMessages[style].m_Stack[0].m_pString = nil;
-}
-void
-CMessages::AddBigMessageQ(wchar *msg, uint32 time, uint16 style)
-{
- wchar outstr[512]; // unused
- WideStringCopy(outstr, msg, 256);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- int32 i = 0;
- while (i < 4 && BIGMessages[style].m_Stack[i].m_pText != nil)
- i++;
-
- if (i >= 4) return;
-
- BIGMessages[style].m_Stack[i].m_pText = msg;
- BIGMessages[style].m_Stack[i].m_nFlag = 0;
- BIGMessages[style].m_Stack[i].m_nTime = time;
- BIGMessages[style].m_Stack[i].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BIGMessages[style].m_Stack[i].m_nNumber[0] = -1;
- BIGMessages[style].m_Stack[i].m_nNumber[1] = -1;
- BIGMessages[style].m_Stack[i].m_nNumber[2] = -1;
- BIGMessages[style].m_Stack[i].m_nNumber[3] = -1;
- BIGMessages[style].m_Stack[i].m_nNumber[4] = -1;
- BIGMessages[style].m_Stack[i].m_nNumber[5] = -1;
- BIGMessages[style].m_Stack[i].m_pString = nil;
-}
-
-void
-CMessages::AddToPreviousBriefArray(wchar *text, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, wchar *string)
-{
- int32 i = 0;
- while (i < NUMPREVIOUSBRIEFS) {
- if (PreviousBriefs[i].m_pText == nil)
- break;
- if (PreviousBriefs[i].m_nNumber[0] == n1
- && PreviousBriefs[i].m_nNumber[1] == n2
- && PreviousBriefs[i].m_nNumber[2] == n3
- && PreviousBriefs[i].m_nNumber[3] == n4
- && PreviousBriefs[i].m_nNumber[4] == n5
- && PreviousBriefs[i].m_nNumber[5] == n6
- && PreviousBriefs[i].m_pText == text
- && PreviousBriefs[i].m_pString == string)
- return;
-
- i++;
- }
-
- if (i != 0) {
- if (i == NUMPREVIOUSBRIEFS) i -= 2;
- else i--;
-
- while (i >= 0) {
- PreviousBriefs[i + 1] = PreviousBriefs[i];
- i--;
- }
- }
- PreviousBriefs[0].m_pText = text;
- PreviousBriefs[0].m_nNumber[0] = n1;
- PreviousBriefs[0].m_nNumber[1] = n2;
- PreviousBriefs[0].m_nNumber[2] = n3;
- PreviousBriefs[0].m_nNumber[3] = n4;
- PreviousBriefs[0].m_nNumber[4] = n5;
- PreviousBriefs[0].m_nNumber[5] = n6;
- PreviousBriefs[0].m_pString = string;
-}
-
-void
-CMessages::InsertNumberInString(wchar *str, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, wchar *outstr)
-{
- char numStr[10];
- wchar wNumStr[10];
-
- if (str == nil) {
- *outstr = '\0';
- return;
- }
-
- int32 size = GetWideStringLength(str);
-
- int32 i = 0;
-
- for (int32 c = 0; c < size;) {
- if (str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~') {
- switch (i) {
- case 0: sprintf(numStr, "%d", n1); break;
- case 1: sprintf(numStr, "%d", n2); break;
- case 2: sprintf(numStr, "%d", n3); break;
- case 3: sprintf(numStr, "%d", n4); break;
- case 4: sprintf(numStr, "%d", n5); break;
- case 5: sprintf(numStr, "%d", n6); break;
- }
- i++;
- AsciiToUnicode(numStr, wNumStr);
-
- int j = 0;
- while (wNumStr[j] != '\0')
- *(outstr++) = wNumStr[j++];
-
- c += 3;
- } else {
- *(outstr++) = str[c++];
- }
- }
- *outstr = '\0';
-}
-
-void
-CMessages::InsertStringInString(wchar *str1, wchar *str2)
-{
- wchar tempstr[256];
-
- if (!str1 || !str2) return;
-
- int32 str1_size = GetWideStringLength(str1);
- int32 str2_size = GetWideStringLength(str2);
- int32 total_size = str1_size + str2_size;
-
- wchar *_str1 = str1;
- uint16 i;
- for (i = 0; i < total_size; ) {
- if (*_str1 == '~' && *(_str1 + 1) == 'a' && *(_str1 + 2) == '~') {
- _str1 += 3;
- for (int j = 0; j < str2_size; j++) {
- tempstr[i++] = str2[j];
- }
- } else {
- tempstr[i++] = *(_str1++);
- }
- }
- tempstr[i] = '\0';
-
- for (i = 0; i < total_size; i++)
- str1[i] = tempstr[i];
-
- while (i < 256)
- str1[i++] = '\0';
-}
-
-void
-CMessages::InsertPlayerControlKeysInString(wchar *str)
-{
- uint16 i;
- wchar outstr[256];
- wchar keybuf[256];
-
- if (!str) return;
- uint16 strSize = GetWideStringLength(str);
- memset(keybuf, 0, 256*sizeof(wchar));
-
- wchar *_outstr = outstr;
- for (i = 0; i < strSize;) {
- if (str[i] == '~' && str[i + 1] == 'k' && str[i + 2] == '~') {
- i += 4;
- for (int32 cont = 0; cont < MAX_CONTROLLERACTIONS; cont++) {
- uint16 contSize = GetWideStringLength(ControlsManager.m_aActionNames[cont]);
- if (contSize != 0) {
- if (WideStringCompare(&str[i], ControlsManager.m_aActionNames[cont], contSize)) {
- ControlsManager.GetWideStringOfCommandKeys(cont, keybuf, 256);
- uint16 keybuf_size = GetWideStringLength(keybuf);
- for (uint16 j = 0; j < keybuf_size; j++) {
- *(_outstr++) = keybuf[j];
- keybuf[j] = '\0';
- }
- i += contSize + 1;
- }
- }
- }
- } else {
- *(_outstr++) = str[i++];
- }
- }
- *_outstr = '\0';
-
- for (i = 0; i < GetWideStringLength(outstr); i++)
- str[i] = outstr[i];
-
- while (i < 256)
- str[i++] = '\0';
-}
-
-void
-CMessages::AddMessageWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6)
-{
- wchar outstr[512]; // unused
- InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- uint16 i = 0;
- while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText)
- i++;
-
- if (i >= NUMBRIEFMESSAGES) return;
-
- BriefMessages[i].m_pText = str;
- BriefMessages[i].m_nFlag = flag;
- BriefMessages[i].m_nTime = time;
- BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[i].m_nNumber[0] = n1;
- BriefMessages[i].m_nNumber[1] = n2;
- BriefMessages[i].m_nNumber[2] = n3;
- BriefMessages[i].m_nNumber[3] = n4;
- BriefMessages[i].m_nNumber[4] = n5;
- BriefMessages[i].m_nNumber[5] = n6;
- BriefMessages[i].m_pString = nil;
- if (i == 0)
- AddToPreviousBriefArray(
- BriefMessages[0].m_pText,
- BriefMessages[0].m_nNumber[0],
- BriefMessages[0].m_nNumber[1],
- BriefMessages[0].m_nNumber[2],
- BriefMessages[0].m_nNumber[3],
- BriefMessages[0].m_nNumber[4],
- BriefMessages[0].m_nNumber[5],
- BriefMessages[0].m_pString);
-}
-
-void
-CMessages::AddMessageJumpQWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6)
-{
- wchar outstr[512]; // unused
- InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- BriefMessages[0].m_pText = str;
- BriefMessages[0].m_nFlag = flag;
- BriefMessages[0].m_nTime = time;
- BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[0].m_nNumber[0] = n1;
- BriefMessages[0].m_nNumber[1] = n2;
- BriefMessages[0].m_nNumber[2] = n3;
- BriefMessages[0].m_nNumber[3] = n4;
- BriefMessages[0].m_nNumber[4] = n5;
- BriefMessages[0].m_nNumber[5] = n6;
- BriefMessages[0].m_pString = nil;
- AddToPreviousBriefArray(str, n1, n2, n3, n4, n5, n6, nil);
-}
-
-void
-CMessages::AddMessageSoonWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6)
-{
- wchar outstr[512]; // unused
- InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- if (BriefMessages[0].m_pText != nil) {
- for (int32 i = NUMBRIEFMESSAGES-1; i > 1; i--)
- BriefMessages[i] = BriefMessages[i-1];
-
- BriefMessages[1].m_pText = str;
- BriefMessages[1].m_nFlag = flag;
- BriefMessages[1].m_nTime = time;
- BriefMessages[1].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[1].m_nNumber[0] = n1;
- BriefMessages[1].m_nNumber[1] = n2;
- BriefMessages[1].m_nNumber[2] = n3;
- BriefMessages[1].m_nNumber[3] = n4;
- BriefMessages[1].m_nNumber[4] = n5;
- BriefMessages[1].m_nNumber[5] = n6;
- BriefMessages[1].m_pString = nil;
- } else {
- BriefMessages[0].m_pText = str;
- BriefMessages[0].m_nFlag = flag;
- BriefMessages[0].m_nTime = time;
- BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[0].m_nNumber[0] = n1;
- BriefMessages[0].m_nNumber[1] = n2;
- BriefMessages[0].m_nNumber[2] = n3;
- BriefMessages[0].m_nNumber[3] = n4;
- BriefMessages[0].m_nNumber[4] = n5;
- BriefMessages[0].m_nNumber[5] = n6;
- BriefMessages[0].m_pString = nil;
- AddToPreviousBriefArray(str, n1, n2, n3, n4, n5, n6, nil);
- }
-}
-
-void
-CMessages::AddBigMessageWithNumber(wchar *str, uint32 time, uint16 style, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6)
-{
- wchar outstr[512]; // unused
- InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- BIGMessages[style].m_Stack[0].m_pText = str;
- BIGMessages[style].m_Stack[0].m_nFlag = 0;
- BIGMessages[style].m_Stack[0].m_nTime = time;
- BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BIGMessages[style].m_Stack[0].m_nNumber[0] = n1;
- BIGMessages[style].m_Stack[0].m_nNumber[1] = n2;
- BIGMessages[style].m_Stack[0].m_nNumber[2] = n3;
- BIGMessages[style].m_Stack[0].m_nNumber[3] = n4;
- BIGMessages[style].m_Stack[0].m_nNumber[4] = n5;
- BIGMessages[style].m_Stack[0].m_nNumber[5] = n6;
- BIGMessages[style].m_Stack[0].m_pString = nil;
-}
-
-void
-CMessages::AddBigMessageWithNumberQ(wchar *str, uint32 time, uint16 style, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6)
-{
- wchar outstr[512]; // unused
- InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- int32 i = 0;
-
- while (i < 4 && BIGMessages[style].m_Stack[i].m_pText != nil)
- i++;
-
- if (i >= 4) return;
-
- BIGMessages[style].m_Stack[i].m_pText = str;
- BIGMessages[style].m_Stack[i].m_nFlag = 0;
- BIGMessages[style].m_Stack[i].m_nTime = time;
- BIGMessages[style].m_Stack[i].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BIGMessages[style].m_Stack[i].m_nNumber[0] = n1;
- BIGMessages[style].m_Stack[i].m_nNumber[1] = n2;
- BIGMessages[style].m_Stack[i].m_nNumber[2] = n3;
- BIGMessages[style].m_Stack[i].m_nNumber[3] = n4;
- BIGMessages[style].m_Stack[i].m_nNumber[4] = n5;
- BIGMessages[style].m_Stack[i].m_nNumber[5] = n6;
- BIGMessages[style].m_Stack[i].m_pString = nil;
-}
-
-void
-CMessages::AddMessageWithString(wchar *text, uint32 time, uint16 flag, wchar *str)
-{
- wchar outstr[512]; // unused
- WideStringCopy(outstr, text, 256);
- InsertStringInString(outstr, str);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- int32 i = 0;
- while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText != nil)
- i++;
-
- if (i >= NUMBRIEFMESSAGES) return;
-
- BriefMessages[i].m_pText = text;
- BriefMessages[i].m_nFlag = flag;
- BriefMessages[i].m_nTime = time;
- BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[i].m_nNumber[0] = -1;
- BriefMessages[i].m_nNumber[1] = -1;
- BriefMessages[i].m_nNumber[2] = -1;
- BriefMessages[i].m_nNumber[3] = -1;
- BriefMessages[i].m_nNumber[4] = -1;
- BriefMessages[i].m_nNumber[5] = -1;
- BriefMessages[i].m_pString = str;
- if (i == 0)
- AddToPreviousBriefArray(
- BriefMessages[0].m_pText,
- BriefMessages[0].m_nNumber[0],
- BriefMessages[0].m_nNumber[1],
- BriefMessages[0].m_nNumber[2],
- BriefMessages[0].m_nNumber[3],
- BriefMessages[0].m_nNumber[4],
- BriefMessages[0].m_nNumber[5],
- BriefMessages[0].m_pString);
-}
-
-void
-CMessages::AddMessageJumpQWithString(wchar *text, uint32 time, uint16 flag, wchar *str)
-{
- wchar outstr[512]; // unused
- WideStringCopy(outstr, text, 256);
- InsertStringInString(outstr, str);
- InsertPlayerControlKeysInString(outstr);
- GetWideStringLength(outstr);
-
- BriefMessages[0].m_pText = text;
- BriefMessages[0].m_nFlag = flag;
- BriefMessages[0].m_nTime = time;
- BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- BriefMessages[0].m_nNumber[0] = -1;
- BriefMessages[0].m_nNumber[1] = -1;
- BriefMessages[0].m_nNumber[2] = -1;
- BriefMessages[0].m_nNumber[3] = -1;
- BriefMessages[0].m_nNumber[4] = -1;
- BriefMessages[0].m_nNumber[5] = -1;
- BriefMessages[0].m_pString = str;
- AddToPreviousBriefArray(text, -1, -1, -1, -1, -1, -1, str);
-}
-
-inline bool
-FastWideStringComparison(wchar *str1, wchar *str2)
-{
- while (*str1 == *str2) {
- ++str1;
- ++str2;
- if (!*str1 && !*str2) return true;
- }
- return false;
-}
-
-void
-CMessages::ClearThisPrint(wchar *str)
-{
- bool equal;
-
- do {
- equal = false;
- uint16 i = 0;
- while (i < NUMBRIEFMESSAGES) {
- if (BriefMessages[i].m_pText == nil)
- break;
-
- equal = FastWideStringComparison(str, BriefMessages[i].m_pText);
-
- if (equal) break;
- i++;
- }
-
- if (equal) {
- if (i != 0) {
- BriefMessages[i].m_pText = nil;
- while (i < NUMBRIEFMESSAGES-1) {
- if (BriefMessages[i + 1].m_pText == nil)
- break;
-
- BriefMessages[i] = BriefMessages[i + 1];
- i++;
- }
- BriefMessages[i].m_pText = nil;
- } else {
- BriefMessages[0].m_pText = nil;
- while (i < NUMBRIEFMESSAGES-1) {
- if (BriefMessages[i + 1].m_pText == nil)
- break;
- BriefMessages[i] = BriefMessages[i + 1];
- i++;
- }
- BriefMessages[i].m_pText = nil;
- BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- if (BriefMessages[0].m_pText == nil)
- AddToPreviousBriefArray(
- BriefMessages[0].m_pText,
- BriefMessages[0].m_nNumber[0],
- BriefMessages[0].m_nNumber[1],
- BriefMessages[0].m_nNumber[2],
- BriefMessages[0].m_nNumber[3],
- BriefMessages[0].m_nNumber[4],
- BriefMessages[0].m_nNumber[5],
- BriefMessages[0].m_pString);
- }
- }
- } while (equal);
-}
-
-void
-CMessages::ClearThisBigPrint(wchar *str)
-{
- bool equal;
-
- do {
- uint16 i = 0;
- equal = false;
- uint16 style = 0;
- while (style < NUMBIGMESSAGES)
- {
- if (i >= 4)
- break;
-
- if (CMessages::BIGMessages[style].m_Stack[i].m_pText == nil || equal)
- break;
-
- equal = FastWideStringComparison(str, BIGMessages[style].m_Stack[i].m_pText);
-
- if (!equal && ++i == 4) {
- i = 0;
- style++;
- }
- }
- if (equal) {
- if (i != 0) {
- BIGMessages[style].m_Stack[i].m_pText = nil;
- while (i < 3) {
- if (BIGMessages[style].m_Stack[i + 1].m_pText == nil)
- break;
- BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1];
- i++;
- }
- BIGMessages[style].m_Stack[i].m_pText = nil;
- } else {
- BIGMessages[style].m_Stack[0].m_pText = 0;
- i = 0;
- while (i < 3) {
- if (BIGMessages[style].m_Stack[i + 1].m_pText == nil)
- break;
- BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1];
- i++;
- }
- BIGMessages[style].m_Stack[i].m_pText = nil;
- BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds();
- }
- }
- } while (equal);
-}
-
-void
-CMessages::ClearAllMessagesDisplayedByGame()
-{
- ClearMessages();
- for (int32 i = 0; i < NUMPREVIOUSBRIEFS; i++) {
- PreviousBriefs[i].m_pText = nil;
- PreviousBriefs[i].m_pString = nil;
- }
- CHud::GetRidOfAllHudMessages();
- CUserDisplay::Pager.ClearMessages();
-}
-
-STARTPATCHES
- InjectHook(0x529310, CMessages::Init, PATCH_JUMP);
- InjectHook(0x529490, CMessages::GetWideStringLength, PATCH_JUMP);
- InjectHook(0x5294B0, CMessages::WideStringCopy, PATCH_JUMP);
- InjectHook(0x529510, CMessages::WideStringCompare, PATCH_JUMP);
- InjectHook(0x529580, CMessages::Process, PATCH_JUMP);
- InjectHook(0x529800, CMessages::Display, PATCH_JUMP);
- InjectHook(0x529900, CMessages::AddMessage, PATCH_JUMP);
- InjectHook(0x529A10, CMessages::AddMessageJumpQ, PATCH_JUMP);
- InjectHook(0x529AF0, CMessages::AddMessageSoon, PATCH_JUMP);
- InjectHook(0x529CE0, CMessages::ClearMessages, PATCH_JUMP);
- InjectHook(0x529E00, CMessages::ClearSmallMessagesOnly, PATCH_JUMP);
- InjectHook(0x529EB0, CMessages::AddBigMessage, PATCH_JUMP);
- InjectHook(0x529F60, CMessages::AddBigMessageQ, PATCH_JUMP);
- InjectHook(0x52A040, CMessages::AddToPreviousBriefArray, PATCH_JUMP);
- InjectHook(0x52A1A0, CMessages::InsertNumberInString, PATCH_JUMP);
- InjectHook(0x52A300, CMessages::InsertStringInString, PATCH_JUMP);
- InjectHook(0x52A490, CMessages::InsertPlayerControlKeysInString, PATCH_JUMP);
- InjectHook(0x52A850, CMessages::AddMessageWithNumber, PATCH_JUMP);
- InjectHook(0x52A9A0, CMessages::AddMessageJumpQWithNumber, PATCH_JUMP);
- InjectHook(0x52AAC0, CMessages::AddMessageSoonWithNumber, PATCH_JUMP);
- InjectHook(0x52AD10, CMessages::AddBigMessageWithNumber, PATCH_JUMP);
- InjectHook(0x52AE00, CMessages::AddBigMessageWithNumberQ, PATCH_JUMP);
- InjectHook(0x52AF30, CMessages::AddMessageWithString, PATCH_JUMP);
- InjectHook(0x52B050, CMessages::AddMessageJumpQWithString, PATCH_JUMP);
- InjectHook(0x52B140, CMessages::ClearThisPrint, PATCH_JUMP);
- InjectHook(0x52B3C0, CMessages::ClearThisBigPrint, PATCH_JUMP);
- InjectHook(0x52B670, CMessages::ClearAllMessagesDisplayedByGame, PATCH_JUMP);
-ENDPATCHES
+#define DIRECTINPUT_VERSION 0x0800 +#include "dinput.h" + +#include "common.h" +#include "patcher.h" +#include "Messages.h" +#include "RwHelper.h" +#include "Hud.h" +#include "User.h" +#include "Timer.h" +#include "Text.h" + +#include "ControllerConfig.h" + +tMessage(&CMessages::BriefMessages)[NUMBRIEFMESSAGES] = *(tMessage(*)[NUMBRIEFMESSAGES])*(uintptr*)0x8786E0; +tPreviousBrief(&CMessages::PreviousBriefs)[NUMPREVIOUSBRIEFS] = *(tPreviousBrief(*)[NUMPREVIOUSBRIEFS])*(uintptr*)0x713C08; +tBigMessage(&CMessages::BIGMessages)[NUMBIGMESSAGES] = *(tBigMessage(*)[NUMBIGMESSAGES])*(uintptr*)0x773628; +char CMessages::PreviousMissionTitle[16]; // unused + +void +CMessages::Init() +{ + ClearMessages(); + + for (int32 i = 0; i < NUMPREVIOUSBRIEFS; i++) { + PreviousBriefs[i].m_pText = nil; + PreviousBriefs[i].m_pString = nil; + } +} + +uint16 +CMessages::GetWideStringLength(wchar *src) +{ + uint16 length = 0; + while (*(src++)) length++; + return length; +} + +void +CMessages::WideStringCopy(wchar *dst, wchar *src, uint16 size) +{ + int32 i = 0; + if (src) { + while (i < size - 1) { + if (!src[i]) break; + dst[i] = src[i]; + i++; + } + } else { + while (i < size - 1) + dst[i++] = '\0'; + } + dst[i] = '\0'; +} + +bool +CMessages::WideStringCompare(wchar *str1, wchar *str2, uint16 size) +{ + uint16 len1 = GetWideStringLength(str1); + uint16 len2 = GetWideStringLength(str2); + if (len1 != len2 && (len1 < size || len2 < size)) + return false; + + for (int32 i = 0; i < size; i++) { + if (!str1[i]) + break; + + if (str1[i] != str2[i]) + return false; + } + return true; +} + +void +CMessages::Process() +{ + for (int32 style = 0; style < 6; style++) { + if (BIGMessages[style].m_Stack[0].m_pText != nil && CTimer::GetTimeInMilliseconds() > BIGMessages[style].m_Stack[0].m_nTime + BIGMessages[style].m_Stack[0].m_nStartTime) { + BIGMessages[style].m_Stack[0].m_pText = nil; + + int32 i = 0; + while (i < 3) { + if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) break; + BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1]; + i++; + } + + BIGMessages[style].m_Stack[i].m_pText = nil; + BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + } + } + + if (BriefMessages[0].m_pText != nil && CTimer::GetTimeInMilliseconds() > BriefMessages[0].m_nTime + BriefMessages[0].m_nStartTime) { + BriefMessages[0].m_pText = nil; + int32 i = 0; + while (i < NUMBRIEFMESSAGES-1) { + if (BriefMessages[i + 1].m_pText == nil) + break; + + BriefMessages[i] = BriefMessages[i + 1]; + i++; + } + CMessages::BriefMessages[i].m_pText = nil; + CMessages::BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + if (BriefMessages[0].m_pText != nil) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); + } +} + +void +CMessages::Display() +{ + wchar outstr[256]; + + DefinedState(); + + for (int32 i = 0; i < NUMBIGMESSAGES; i++) { + InsertNumberInString( + BIGMessages[i].m_Stack[0].m_pText, + BIGMessages[i].m_Stack[0].m_nNumber[0], + BIGMessages[i].m_Stack[0].m_nNumber[1], + BIGMessages[i].m_Stack[0].m_nNumber[2], + BIGMessages[i].m_Stack[0].m_nNumber[3], + BIGMessages[i].m_Stack[0].m_nNumber[4], + BIGMessages[i].m_Stack[0].m_nNumber[5], + outstr); + InsertStringInString(outstr, BIGMessages[i].m_Stack[0].m_pString); + InsertPlayerControlKeysInString(outstr); + CHud::SetBigMessage(outstr, i); + } + + InsertNumberInString( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + outstr); + InsertStringInString(outstr, BriefMessages[0].m_pString); + InsertPlayerControlKeysInString(outstr); + CHud::SetMessage(outstr); +} + +void +CMessages::AddMessage(wchar *msg, uint32 time, uint16 flag) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + int32 i = 0; + while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText != nil) + i++; + if (i >= NUMBRIEFMESSAGES) return; + + BriefMessages[i].m_pText = msg; + BriefMessages[i].m_nFlag = flag; + BriefMessages[i].m_nTime = time; + BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[i].m_nNumber[0] = -1; + BriefMessages[i].m_nNumber[1] = -1; + BriefMessages[i].m_nNumber[2] = -1; + BriefMessages[i].m_nNumber[3] = -1; + BriefMessages[i].m_nNumber[4] = -1; + BriefMessages[i].m_nNumber[5] = -1; + BriefMessages[i].m_pString = nil; + if (i == 0) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); +} + +void +CMessages::AddMessageJumpQ(wchar *msg, uint32 time, uint16 flag) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BriefMessages[0].m_pText = msg; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = -1; + BriefMessages[0].m_nNumber[1] = -1; + BriefMessages[0].m_nNumber[2] = -1; + BriefMessages[0].m_nNumber[3] = -1; + BriefMessages[0].m_nNumber[4] = -1; + BriefMessages[0].m_nNumber[5] = -1; + BriefMessages[0].m_pString = nil; + AddToPreviousBriefArray(msg, -1, -1, -1, -1, -1, -1, 0); +} + +void +CMessages::AddMessageSoon(wchar *msg, uint32 time, uint16 flag) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + if (BriefMessages[0].m_pText != nil) { + for (int i = NUMBRIEFMESSAGES-1; i > 1; i--) + BriefMessages[i] = BriefMessages[i-1]; + + BriefMessages[1].m_pText = msg; + BriefMessages[1].m_nFlag = flag; + BriefMessages[1].m_nTime = time; + BriefMessages[1].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[1].m_nNumber[0] = -1; + BriefMessages[1].m_nNumber[1] = -1; + BriefMessages[1].m_nNumber[2] = -1; + BriefMessages[1].m_nNumber[3] = -1; + BriefMessages[1].m_nNumber[4] = -1; + BriefMessages[1].m_nNumber[5] = -1; + BriefMessages[1].m_pString = nil; + }else{ + BriefMessages[0].m_pText = msg; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = -1; + BriefMessages[0].m_nNumber[1] = -1; + BriefMessages[0].m_nNumber[2] = -1; + BriefMessages[0].m_nNumber[3] = -1; + BriefMessages[0].m_nNumber[4] = -1; + BriefMessages[0].m_nNumber[5] = -1; + BriefMessages[0].m_pString = nil; + AddToPreviousBriefArray(msg, -1, -1, -1, -1, -1, -1, nil); + } +} + +void +CMessages::ClearMessages() +{ + for (int32 i = 0; i < NUMBIGMESSAGES; i++) { + for (int32 j = 0; j < 4; j++) { + BIGMessages[i].m_Stack[j].m_pText = nil; + BIGMessages[i].m_Stack[j].m_pString = nil; + } + } + ClearSmallMessagesOnly(); +} + +void +CMessages::ClearSmallMessagesOnly() +{ + for (int32 i = 0; i < NUMBRIEFMESSAGES; i++) { + BriefMessages[i].m_pText = nil; + BriefMessages[i].m_pString = nil; + } +} + +void +CMessages::AddBigMessage(wchar *msg, uint32 time, uint16 style) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BIGMessages[style].m_Stack[0].m_pText = msg; + BIGMessages[style].m_Stack[0].m_nFlag = 0; + BIGMessages[style].m_Stack[0].m_nTime = time; + BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BIGMessages[style].m_Stack[0].m_nNumber[0] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[1] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[2] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[3] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[4] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[5] = -1; + BIGMessages[style].m_Stack[0].m_pString = nil; +} +void +CMessages::AddBigMessageQ(wchar *msg, uint32 time, uint16 style) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + int32 i = 0; + while (i < 4 && BIGMessages[style].m_Stack[i].m_pText != nil) + i++; + + if (i >= 4) return; + + BIGMessages[style].m_Stack[i].m_pText = msg; + BIGMessages[style].m_Stack[i].m_nFlag = 0; + BIGMessages[style].m_Stack[i].m_nTime = time; + BIGMessages[style].m_Stack[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BIGMessages[style].m_Stack[i].m_nNumber[0] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[1] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[2] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[3] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[4] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[5] = -1; + BIGMessages[style].m_Stack[i].m_pString = nil; +} + +void +CMessages::AddToPreviousBriefArray(wchar *text, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, wchar *string) +{ + int32 i = 0; + while (i < NUMPREVIOUSBRIEFS) { + if (PreviousBriefs[i].m_pText == nil) + break; + if (PreviousBriefs[i].m_nNumber[0] == n1 + && PreviousBriefs[i].m_nNumber[1] == n2 + && PreviousBriefs[i].m_nNumber[2] == n3 + && PreviousBriefs[i].m_nNumber[3] == n4 + && PreviousBriefs[i].m_nNumber[4] == n5 + && PreviousBriefs[i].m_nNumber[5] == n6 + && PreviousBriefs[i].m_pText == text + && PreviousBriefs[i].m_pString == string) + return; + + i++; + } + + if (i != 0) { + if (i == NUMPREVIOUSBRIEFS) i -= 2; + else i--; + + while (i >= 0) { + PreviousBriefs[i + 1] = PreviousBriefs[i]; + i--; + } + } + PreviousBriefs[0].m_pText = text; + PreviousBriefs[0].m_nNumber[0] = n1; + PreviousBriefs[0].m_nNumber[1] = n2; + PreviousBriefs[0].m_nNumber[2] = n3; + PreviousBriefs[0].m_nNumber[3] = n4; + PreviousBriefs[0].m_nNumber[4] = n5; + PreviousBriefs[0].m_nNumber[5] = n6; + PreviousBriefs[0].m_pString = string; +} + +void +CMessages::InsertNumberInString(wchar *str, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, wchar *outstr) +{ + char numStr[10]; + wchar wNumStr[10]; + + if (str == nil) { + *outstr = '\0'; + return; + } + + int32 size = GetWideStringLength(str); + + int32 i = 0; + + for (int32 c = 0; c < size;) { + if (str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~') { + switch (i) { + case 0: sprintf(numStr, "%d", n1); break; + case 1: sprintf(numStr, "%d", n2); break; + case 2: sprintf(numStr, "%d", n3); break; + case 3: sprintf(numStr, "%d", n4); break; + case 4: sprintf(numStr, "%d", n5); break; + case 5: sprintf(numStr, "%d", n6); break; + } + i++; + AsciiToUnicode(numStr, wNumStr); + + int j = 0; + while (wNumStr[j] != '\0') + *(outstr++) = wNumStr[j++]; + + c += 3; + } else { + *(outstr++) = str[c++]; + } + } + *outstr = '\0'; +} + +void +CMessages::InsertStringInString(wchar *str1, wchar *str2) +{ + wchar tempstr[256]; + + if (!str1 || !str2) return; + + int32 str1_size = GetWideStringLength(str1); + int32 str2_size = GetWideStringLength(str2); + int32 total_size = str1_size + str2_size; + + wchar *_str1 = str1; + uint16 i; + for (i = 0; i < total_size; ) { + if (*_str1 == '~' && *(_str1 + 1) == 'a' && *(_str1 + 2) == '~') { + _str1 += 3; + for (int j = 0; j < str2_size; j++) { + tempstr[i++] = str2[j]; + } + } else { + tempstr[i++] = *(_str1++); + } + } + tempstr[i] = '\0'; + + for (i = 0; i < total_size; i++) + str1[i] = tempstr[i]; + + while (i < 256) + str1[i++] = '\0'; +} + +void +CMessages::InsertPlayerControlKeysInString(wchar *str) +{ + uint16 i; + wchar outstr[256]; + wchar keybuf[256]; + + if (!str) return; + uint16 strSize = GetWideStringLength(str); + memset(keybuf, 0, 256*sizeof(wchar)); + + wchar *_outstr = outstr; + for (i = 0; i < strSize;) { + if (str[i] == '~' && str[i + 1] == 'k' && str[i + 2] == '~') { + i += 4; + for (int32 cont = 0; cont < MAX_CONTROLLERACTIONS; cont++) { + uint16 contSize = GetWideStringLength(ControlsManager.m_aActionNames[cont]); + if (contSize != 0) { + if (WideStringCompare(&str[i], ControlsManager.m_aActionNames[cont], contSize)) { + ControlsManager.GetWideStringOfCommandKeys(cont, keybuf, 256); + uint16 keybuf_size = GetWideStringLength(keybuf); + for (uint16 j = 0; j < keybuf_size; j++) { + *(_outstr++) = keybuf[j]; + keybuf[j] = '\0'; + } + i += contSize + 1; + } + } + } + } else { + *(_outstr++) = str[i++]; + } + } + *_outstr = '\0'; + + for (i = 0; i < GetWideStringLength(outstr); i++) + str[i] = outstr[i]; + + while (i < 256) + str[i++] = '\0'; +} + +void +CMessages::AddMessageWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + uint16 i = 0; + while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText) + i++; + + if (i >= NUMBRIEFMESSAGES) return; + + BriefMessages[i].m_pText = str; + BriefMessages[i].m_nFlag = flag; + BriefMessages[i].m_nTime = time; + BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[i].m_nNumber[0] = n1; + BriefMessages[i].m_nNumber[1] = n2; + BriefMessages[i].m_nNumber[2] = n3; + BriefMessages[i].m_nNumber[3] = n4; + BriefMessages[i].m_nNumber[4] = n5; + BriefMessages[i].m_nNumber[5] = n6; + BriefMessages[i].m_pString = nil; + if (i == 0) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); +} + +void +CMessages::AddMessageJumpQWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BriefMessages[0].m_pText = str; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = n1; + BriefMessages[0].m_nNumber[1] = n2; + BriefMessages[0].m_nNumber[2] = n3; + BriefMessages[0].m_nNumber[3] = n4; + BriefMessages[0].m_nNumber[4] = n5; + BriefMessages[0].m_nNumber[5] = n6; + BriefMessages[0].m_pString = nil; + AddToPreviousBriefArray(str, n1, n2, n3, n4, n5, n6, nil); +} + +void +CMessages::AddMessageSoonWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + if (BriefMessages[0].m_pText != nil) { + for (int32 i = NUMBRIEFMESSAGES-1; i > 1; i--) + BriefMessages[i] = BriefMessages[i-1]; + + BriefMessages[1].m_pText = str; + BriefMessages[1].m_nFlag = flag; + BriefMessages[1].m_nTime = time; + BriefMessages[1].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[1].m_nNumber[0] = n1; + BriefMessages[1].m_nNumber[1] = n2; + BriefMessages[1].m_nNumber[2] = n3; + BriefMessages[1].m_nNumber[3] = n4; + BriefMessages[1].m_nNumber[4] = n5; + BriefMessages[1].m_nNumber[5] = n6; + BriefMessages[1].m_pString = nil; + } else { + BriefMessages[0].m_pText = str; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = n1; + BriefMessages[0].m_nNumber[1] = n2; + BriefMessages[0].m_nNumber[2] = n3; + BriefMessages[0].m_nNumber[3] = n4; + BriefMessages[0].m_nNumber[4] = n5; + BriefMessages[0].m_nNumber[5] = n6; + BriefMessages[0].m_pString = nil; + AddToPreviousBriefArray(str, n1, n2, n3, n4, n5, n6, nil); + } +} + +void +CMessages::AddBigMessageWithNumber(wchar *str, uint32 time, uint16 style, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BIGMessages[style].m_Stack[0].m_pText = str; + BIGMessages[style].m_Stack[0].m_nFlag = 0; + BIGMessages[style].m_Stack[0].m_nTime = time; + BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BIGMessages[style].m_Stack[0].m_nNumber[0] = n1; + BIGMessages[style].m_Stack[0].m_nNumber[1] = n2; + BIGMessages[style].m_Stack[0].m_nNumber[2] = n3; + BIGMessages[style].m_Stack[0].m_nNumber[3] = n4; + BIGMessages[style].m_Stack[0].m_nNumber[4] = n5; + BIGMessages[style].m_Stack[0].m_nNumber[5] = n6; + BIGMessages[style].m_Stack[0].m_pString = nil; +} + +void +CMessages::AddBigMessageWithNumberQ(wchar *str, uint32 time, uint16 style, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + int32 i = 0; + + while (i < 4 && BIGMessages[style].m_Stack[i].m_pText != nil) + i++; + + if (i >= 4) return; + + BIGMessages[style].m_Stack[i].m_pText = str; + BIGMessages[style].m_Stack[i].m_nFlag = 0; + BIGMessages[style].m_Stack[i].m_nTime = time; + BIGMessages[style].m_Stack[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BIGMessages[style].m_Stack[i].m_nNumber[0] = n1; + BIGMessages[style].m_Stack[i].m_nNumber[1] = n2; + BIGMessages[style].m_Stack[i].m_nNumber[2] = n3; + BIGMessages[style].m_Stack[i].m_nNumber[3] = n4; + BIGMessages[style].m_Stack[i].m_nNumber[4] = n5; + BIGMessages[style].m_Stack[i].m_nNumber[5] = n6; + BIGMessages[style].m_Stack[i].m_pString = nil; +} + +void +CMessages::AddMessageWithString(wchar *text, uint32 time, uint16 flag, wchar *str) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, text, 256); + InsertStringInString(outstr, str); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + int32 i = 0; + while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText != nil) + i++; + + if (i >= NUMBRIEFMESSAGES) return; + + BriefMessages[i].m_pText = text; + BriefMessages[i].m_nFlag = flag; + BriefMessages[i].m_nTime = time; + BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[i].m_nNumber[0] = -1; + BriefMessages[i].m_nNumber[1] = -1; + BriefMessages[i].m_nNumber[2] = -1; + BriefMessages[i].m_nNumber[3] = -1; + BriefMessages[i].m_nNumber[4] = -1; + BriefMessages[i].m_nNumber[5] = -1; + BriefMessages[i].m_pString = str; + if (i == 0) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); +} + +void +CMessages::AddMessageJumpQWithString(wchar *text, uint32 time, uint16 flag, wchar *str) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, text, 256); + InsertStringInString(outstr, str); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BriefMessages[0].m_pText = text; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = -1; + BriefMessages[0].m_nNumber[1] = -1; + BriefMessages[0].m_nNumber[2] = -1; + BriefMessages[0].m_nNumber[3] = -1; + BriefMessages[0].m_nNumber[4] = -1; + BriefMessages[0].m_nNumber[5] = -1; + BriefMessages[0].m_pString = str; + AddToPreviousBriefArray(text, -1, -1, -1, -1, -1, -1, str); +} + +inline bool +FastWideStringComparison(wchar *str1, wchar *str2) +{ + while (*str1 == *str2) { + ++str1; + ++str2; + if (!*str1 && !*str2) return true; + } + return false; +} + +void +CMessages::ClearThisPrint(wchar *str) +{ + bool equal; + + do { + equal = false; + uint16 i = 0; + while (i < NUMBRIEFMESSAGES) { + if (BriefMessages[i].m_pText == nil) + break; + + equal = FastWideStringComparison(str, BriefMessages[i].m_pText); + + if (equal) break; + i++; + } + + if (equal) { + if (i != 0) { + BriefMessages[i].m_pText = nil; + while (i < NUMBRIEFMESSAGES-1) { + if (BriefMessages[i + 1].m_pText == nil) + break; + + BriefMessages[i] = BriefMessages[i + 1]; + i++; + } + BriefMessages[i].m_pText = nil; + } else { + BriefMessages[0].m_pText = nil; + while (i < NUMBRIEFMESSAGES-1) { + if (BriefMessages[i + 1].m_pText == nil) + break; + BriefMessages[i] = BriefMessages[i + 1]; + i++; + } + BriefMessages[i].m_pText = nil; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + if (BriefMessages[0].m_pText == nil) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); + } + } + } while (equal); +} + +void +CMessages::ClearThisBigPrint(wchar *str) +{ + bool equal; + + do { + uint16 i = 0; + equal = false; + uint16 style = 0; + while (style < NUMBIGMESSAGES) + { + if (i >= 4) + break; + + if (CMessages::BIGMessages[style].m_Stack[i].m_pText == nil || equal) + break; + + equal = FastWideStringComparison(str, BIGMessages[style].m_Stack[i].m_pText); + + if (!equal && ++i == 4) { + i = 0; + style++; + } + } + if (equal) { + if (i != 0) { + BIGMessages[style].m_Stack[i].m_pText = nil; + while (i < 3) { + if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) + break; + BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1]; + i++; + } + BIGMessages[style].m_Stack[i].m_pText = nil; + } else { + BIGMessages[style].m_Stack[0].m_pText = 0; + i = 0; + while (i < 3) { + if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) + break; + BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1]; + i++; + } + BIGMessages[style].m_Stack[i].m_pText = nil; + BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + } + } + } while (equal); +} + +void +CMessages::ClearAllMessagesDisplayedByGame() +{ + ClearMessages(); + for (int32 i = 0; i < NUMPREVIOUSBRIEFS; i++) { + PreviousBriefs[i].m_pText = nil; + PreviousBriefs[i].m_pString = nil; + } + CHud::GetRidOfAllHudMessages(); + CUserDisplay::Pager.ClearMessages(); +} + +STARTPATCHES + InjectHook(0x529310, CMessages::Init, PATCH_JUMP); + InjectHook(0x529490, CMessages::GetWideStringLength, PATCH_JUMP); + InjectHook(0x5294B0, CMessages::WideStringCopy, PATCH_JUMP); + InjectHook(0x529510, CMessages::WideStringCompare, PATCH_JUMP); + InjectHook(0x529580, CMessages::Process, PATCH_JUMP); + InjectHook(0x529800, CMessages::Display, PATCH_JUMP); + InjectHook(0x529900, CMessages::AddMessage, PATCH_JUMP); + InjectHook(0x529A10, CMessages::AddMessageJumpQ, PATCH_JUMP); + InjectHook(0x529AF0, CMessages::AddMessageSoon, PATCH_JUMP); + InjectHook(0x529CE0, CMessages::ClearMessages, PATCH_JUMP); + InjectHook(0x529E00, CMessages::ClearSmallMessagesOnly, PATCH_JUMP); + InjectHook(0x529EB0, CMessages::AddBigMessage, PATCH_JUMP); + InjectHook(0x529F60, CMessages::AddBigMessageQ, PATCH_JUMP); + InjectHook(0x52A040, CMessages::AddToPreviousBriefArray, PATCH_JUMP); + InjectHook(0x52A1A0, CMessages::InsertNumberInString, PATCH_JUMP); + InjectHook(0x52A300, CMessages::InsertStringInString, PATCH_JUMP); + InjectHook(0x52A490, CMessages::InsertPlayerControlKeysInString, PATCH_JUMP); + InjectHook(0x52A850, CMessages::AddMessageWithNumber, PATCH_JUMP); + InjectHook(0x52A9A0, CMessages::AddMessageJumpQWithNumber, PATCH_JUMP); + InjectHook(0x52AAC0, CMessages::AddMessageSoonWithNumber, PATCH_JUMP); + InjectHook(0x52AD10, CMessages::AddBigMessageWithNumber, PATCH_JUMP); + InjectHook(0x52AE00, CMessages::AddBigMessageWithNumberQ, PATCH_JUMP); + InjectHook(0x52AF30, CMessages::AddMessageWithString, PATCH_JUMP); + InjectHook(0x52B050, CMessages::AddMessageJumpQWithString, PATCH_JUMP); + InjectHook(0x52B140, CMessages::ClearThisPrint, PATCH_JUMP); + InjectHook(0x52B3C0, CMessages::ClearThisBigPrint, PATCH_JUMP); + InjectHook(0x52B670, CMessages::ClearAllMessagesDisplayedByGame, PATCH_JUMP); +ENDPATCHES diff --git a/src/text/Pager.cpp b/src/text/Pager.cpp index 9e484c29..5c6b3ee2 100644 --- a/src/text/Pager.cpp +++ b/src/text/Pager.cpp @@ -1,194 +1,194 @@ -#include "common.h"
-#include "patcher.h"
-#include "Pager.h"
-#include "Timer.h"
-#include "Messages.h"
-#include "Hud.h"
-#include "Camera.h"
-
-void
-CPager::Init()
-{
- ClearMessages();
- m_nNumDisplayLetters = 8;
-}
-
-void
-CPager::Process()
-{
- if (m_messages[0].m_pText != nil && m_messages[0].m_nCurrentPosition >= (int32)m_messages[0].m_nStringLength) {
- m_messages[0].m_pText = nil;
- uint16 i = 0;
- while (i < NUMPAGERMESSAGES-1) {
- if (m_messages[i + 1].m_pText == nil) break;
- m_messages[i] = m_messages[i + 1];
- i++;
- }
- m_messages[i].m_pText = nil;
- if (m_messages[0].m_pText != nil)
- CMessages::AddToPreviousBriefArray(
- m_messages[0].m_pText,
- m_messages[0].m_nNumber[0],
- m_messages[0].m_nNumber[1],
- m_messages[0].m_nNumber[2],
- m_messages[0].m_nNumber[3],
- m_messages[0].m_nNumber[4],
- m_messages[0].m_nNumber[5],
- 0);
- }
- Display();
- if (m_messages[0].m_pText != nil) {
- if (TheCamera.m_WideScreenOn || !CHud::m_Wants_To_Draw_Hud || CHud::m_BigMessage[0][0] || CHud::m_BigMessage[2][0]) {
- RestartCurrentMessage();
- } else {
- if (CTimer::GetTimeInMilliseconds() > m_messages[0].m_nTimeToChangePosition) {
- m_messages[0].m_nCurrentPosition++;
- m_messages[0].m_nTimeToChangePosition = CTimer::GetTimeInMilliseconds() + m_messages[0].m_nSpeedMs;
- }
- }
- }
-}
-
-void
-CPager::Display()
-{
- wchar outstr1[256];
- wchar outstr2[260];
-
- wchar *pText = m_messages[0].m_pText;
- uint16 i = 0;
- if (pText != nil) {
- CMessages::InsertNumberInString(
- pText,
- m_messages[0].m_nNumber[0],
- m_messages[0].m_nNumber[1],
- m_messages[0].m_nNumber[2],
- m_messages[0].m_nNumber[3],
- m_messages[0].m_nNumber[4],
- m_messages[0].m_nNumber[5],
- outstr1);
- for (; i < m_nNumDisplayLetters; i++) {
- int pos = m_messages[0].m_nCurrentPosition + i;
- if (pos >= 0) {
- if (!outstr1[pos]) break;
-
- outstr2[i] = outstr1[pos];
- } else {
- outstr2[i] = ' ';
- }
- }
- }
- outstr2[i] = '\0';
- CHud::SetPagerMessage(outstr2);
-}
-
-void
-CPager::AddMessage(wchar *str, uint16 speed, uint16 priority, uint16 a5)
-{
- uint16 size = CMessages::GetWideStringLength(str);
- for (int32 i = 0; i < NUMPAGERMESSAGES; i++) {
- if (m_messages[i].m_pText) {
- if (m_messages[i].m_nPriority >= priority)
- continue;
-
- for (int j = NUMPAGERMESSAGES-1; j > i; j--)
- m_messages[j] = m_messages[j-1];
-
- }
- m_messages[i].m_pText = str;
- m_messages[i].m_nSpeedMs = speed;
- m_messages[i].m_nPriority = priority;
- m_messages[i].field_10 = a5;
- m_messages[i].m_nCurrentPosition = -(m_nNumDisplayLetters + 10);
- m_messages[i].m_nTimeToChangePosition = CTimer::GetTimeInMilliseconds() + speed;
- m_messages[i].m_nStringLength = size;
- m_messages[i].m_nNumber[0] = -1;
- m_messages[i].m_nNumber[1] = -1;
- m_messages[i].m_nNumber[2] = -1;
- m_messages[i].m_nNumber[3] = -1;
- m_messages[i].m_nNumber[4] = -1;
- m_messages[i].m_nNumber[5] = -1;
-
- if (i == 0)
- CMessages::AddToPreviousBriefArray(
- m_messages[0].m_pText,
- m_messages[0].m_nNumber[0],
- m_messages[0].m_nNumber[1],
- m_messages[0].m_nNumber[2],
- m_messages[0].m_nNumber[3],
- m_messages[0].m_nNumber[4],
- m_messages[0].m_nNumber[5],
- nil);
- return;
- }
-}
-
-void
-CPager::AddMessageWithNumber(wchar *str, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, uint16 speed, uint16 priority, uint16 a11)
-{
- wchar nstr[520];
-
- CMessages::InsertNumberInString(str, n1, n2, n3, n4, n5, n6, nstr);
- uint16 size = CMessages::GetWideStringLength(nstr);
- for (int32 i = 0; i < NUMPAGERMESSAGES; i++) {
- if (m_messages[i].m_pText) {
- if (m_messages[i].m_nPriority >= priority)
- continue;
-
- for (int j = NUMPAGERMESSAGES-1; j > i; j--)
- m_messages[j] = m_messages[j - 1];
-
- }
- m_messages[i].m_pText = str;
- m_messages[i].m_nSpeedMs = speed;
- m_messages[i].m_nPriority = priority;
- m_messages[i].field_10 = a11;
- m_messages[i].m_nCurrentPosition = -(m_nNumDisplayLetters + 10);
- m_messages[i].m_nTimeToChangePosition = CTimer::GetTimeInMilliseconds() + speed;
- m_messages[i].m_nStringLength = size;
- m_messages[i].m_nNumber[0] = n1;
- m_messages[i].m_nNumber[1] = n2;
- m_messages[i].m_nNumber[2] = n3;
- m_messages[i].m_nNumber[3] = n4;
- m_messages[i].m_nNumber[4] = n5;
- m_messages[i].m_nNumber[5] = n6;
-
- if (i == 0)
- CMessages::AddToPreviousBriefArray(
- m_messages[0].m_pText,
- m_messages[0].m_nNumber[0],
- m_messages[0].m_nNumber[1],
- m_messages[0].m_nNumber[2],
- m_messages[0].m_nNumber[3],
- m_messages[0].m_nNumber[4],
- m_messages[0].m_nNumber[5],
- nil);
- return;
- }
-}
-
-void
-CPager::ClearMessages()
-{
- for (int32 i = 0; i < NUMPAGERMESSAGES; i++)
- m_messages[i].m_pText = nil;
-}
-
-void
-CPager::RestartCurrentMessage()
-{
- if (m_messages[0].m_pText != nil) {
- m_messages[0].m_nCurrentPosition = -(m_nNumDisplayLetters + 10);
- m_messages[0].m_nTimeToChangePosition = CTimer::GetTimeInMilliseconds() + m_messages[0].m_nSpeedMs;
- }
-}
-
-STARTPATCHES
- InjectHook(0x52B6F0, &CPager::Init, PATCH_JUMP);
- InjectHook(0x52B740, &CPager::Process, PATCH_JUMP);
- InjectHook(0x52B890, &CPager::Display, PATCH_JUMP);
- InjectHook(0x52B940, &CPager::AddMessage, PATCH_JUMP);
- InjectHook(0x52BB50, &CPager::AddMessageWithNumber, PATCH_JUMP);
- InjectHook(0x52BE50, &CPager::RestartCurrentMessage, PATCH_JUMP);
- InjectHook(0x52BE00, &CPager::ClearMessages, PATCH_JUMP);
+#include "common.h" +#include "patcher.h" +#include "Pager.h" +#include "Timer.h" +#include "Messages.h" +#include "Hud.h" +#include "Camera.h" + +void +CPager::Init() +{ + ClearMessages(); + m_nNumDisplayLetters = 8; +} + +void +CPager::Process() +{ + if (m_messages[0].m_pText != nil && m_messages[0].m_nCurrentPosition >= (int32)m_messages[0].m_nStringLength) { + m_messages[0].m_pText = nil; + uint16 i = 0; + while (i < NUMPAGERMESSAGES-1) { + if (m_messages[i + 1].m_pText == nil) break; + m_messages[i] = m_messages[i + 1]; + i++; + } + m_messages[i].m_pText = nil; + if (m_messages[0].m_pText != nil) + CMessages::AddToPreviousBriefArray( + m_messages[0].m_pText, + m_messages[0].m_nNumber[0], + m_messages[0].m_nNumber[1], + m_messages[0].m_nNumber[2], + m_messages[0].m_nNumber[3], + m_messages[0].m_nNumber[4], + m_messages[0].m_nNumber[5], + 0); + } + Display(); + if (m_messages[0].m_pText != nil) { + if (TheCamera.m_WideScreenOn || !CHud::m_Wants_To_Draw_Hud || CHud::m_BigMessage[0][0] || CHud::m_BigMessage[2][0]) { + RestartCurrentMessage(); + } else { + if (CTimer::GetTimeInMilliseconds() > m_messages[0].m_nTimeToChangePosition) { + m_messages[0].m_nCurrentPosition++; + m_messages[0].m_nTimeToChangePosition = CTimer::GetTimeInMilliseconds() + m_messages[0].m_nSpeedMs; + } + } + } +} + +void +CPager::Display() +{ + wchar outstr1[256]; + wchar outstr2[260]; + + wchar *pText = m_messages[0].m_pText; + uint16 i = 0; + if (pText != nil) { + CMessages::InsertNumberInString( + pText, + m_messages[0].m_nNumber[0], + m_messages[0].m_nNumber[1], + m_messages[0].m_nNumber[2], + m_messages[0].m_nNumber[3], + m_messages[0].m_nNumber[4], + m_messages[0].m_nNumber[5], + outstr1); + for (; i < m_nNumDisplayLetters; i++) { + int pos = m_messages[0].m_nCurrentPosition + i; + if (pos >= 0) { + if (!outstr1[pos]) break; + + outstr2[i] = outstr1[pos]; + } else { + outstr2[i] = ' '; + } + } + } + outstr2[i] = '\0'; + CHud::SetPagerMessage(outstr2); +} + +void +CPager::AddMessage(wchar *str, uint16 speed, uint16 priority, uint16 a5) +{ + uint16 size = CMessages::GetWideStringLength(str); + for (int32 i = 0; i < NUMPAGERMESSAGES; i++) { + if (m_messages[i].m_pText) { + if (m_messages[i].m_nPriority >= priority) + continue; + + for (int j = NUMPAGERMESSAGES-1; j > i; j--) + m_messages[j] = m_messages[j-1]; + + } + m_messages[i].m_pText = str; + m_messages[i].m_nSpeedMs = speed; + m_messages[i].m_nPriority = priority; + m_messages[i].field_10 = a5; + m_messages[i].m_nCurrentPosition = -(m_nNumDisplayLetters + 10); + m_messages[i].m_nTimeToChangePosition = CTimer::GetTimeInMilliseconds() + speed; + m_messages[i].m_nStringLength = size; + m_messages[i].m_nNumber[0] = -1; + m_messages[i].m_nNumber[1] = -1; + m_messages[i].m_nNumber[2] = -1; + m_messages[i].m_nNumber[3] = -1; + m_messages[i].m_nNumber[4] = -1; + m_messages[i].m_nNumber[5] = -1; + + if (i == 0) + CMessages::AddToPreviousBriefArray( + m_messages[0].m_pText, + m_messages[0].m_nNumber[0], + m_messages[0].m_nNumber[1], + m_messages[0].m_nNumber[2], + m_messages[0].m_nNumber[3], + m_messages[0].m_nNumber[4], + m_messages[0].m_nNumber[5], + nil); + return; + } +} + +void +CPager::AddMessageWithNumber(wchar *str, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, uint16 speed, uint16 priority, uint16 a11) +{ + wchar nstr[520]; + + CMessages::InsertNumberInString(str, n1, n2, n3, n4, n5, n6, nstr); + uint16 size = CMessages::GetWideStringLength(nstr); + for (int32 i = 0; i < NUMPAGERMESSAGES; i++) { + if (m_messages[i].m_pText) { + if (m_messages[i].m_nPriority >= priority) + continue; + + for (int j = NUMPAGERMESSAGES-1; j > i; j--) + m_messages[j] = m_messages[j - 1]; + + } + m_messages[i].m_pText = str; + m_messages[i].m_nSpeedMs = speed; + m_messages[i].m_nPriority = priority; + m_messages[i].field_10 = a11; + m_messages[i].m_nCurrentPosition = -(m_nNumDisplayLetters + 10); + m_messages[i].m_nTimeToChangePosition = CTimer::GetTimeInMilliseconds() + speed; + m_messages[i].m_nStringLength = size; + m_messages[i].m_nNumber[0] = n1; + m_messages[i].m_nNumber[1] = n2; + m_messages[i].m_nNumber[2] = n3; + m_messages[i].m_nNumber[3] = n4; + m_messages[i].m_nNumber[4] = n5; + m_messages[i].m_nNumber[5] = n6; + + if (i == 0) + CMessages::AddToPreviousBriefArray( + m_messages[0].m_pText, + m_messages[0].m_nNumber[0], + m_messages[0].m_nNumber[1], + m_messages[0].m_nNumber[2], + m_messages[0].m_nNumber[3], + m_messages[0].m_nNumber[4], + m_messages[0].m_nNumber[5], + nil); + return; + } +} + +void +CPager::ClearMessages() +{ + for (int32 i = 0; i < NUMPAGERMESSAGES; i++) + m_messages[i].m_pText = nil; +} + +void +CPager::RestartCurrentMessage() +{ + if (m_messages[0].m_pText != nil) { + m_messages[0].m_nCurrentPosition = -(m_nNumDisplayLetters + 10); + m_messages[0].m_nTimeToChangePosition = CTimer::GetTimeInMilliseconds() + m_messages[0].m_nSpeedMs; + } +} + +STARTPATCHES + InjectHook(0x52B6F0, &CPager::Init, PATCH_JUMP); + InjectHook(0x52B740, &CPager::Process, PATCH_JUMP); + InjectHook(0x52B890, &CPager::Display, PATCH_JUMP); + InjectHook(0x52B940, &CPager::AddMessage, PATCH_JUMP); + InjectHook(0x52BB50, &CPager::AddMessageWithNumber, PATCH_JUMP); + InjectHook(0x52BE50, &CPager::RestartCurrentMessage, PATCH_JUMP); + InjectHook(0x52BE00, &CPager::ClearMessages, PATCH_JUMP); ENDPATCHES
\ No newline at end of file diff --git a/src/text/Pager.h b/src/text/Pager.h index 1719e726..a628be6f 100644 --- a/src/text/Pager.h +++ b/src/text/Pager.h @@ -1,28 +1,28 @@ -#pragma once
-
-struct PagerMessage {
- wchar *m_pText;
- uint16 m_nSpeedMs;
- int16 m_nCurrentPosition;
- uint16 m_nStringLength;
- uint16 m_nPriority;
- uint32 m_nTimeToChangePosition;
- int16 field_10;
- int32 m_nNumber[6];
-};
-
-#define NUMPAGERMESSAGES 8
-
-class CPager
-{
- int16 m_nNumDisplayLetters;
- PagerMessage m_messages[NUMPAGERMESSAGES];
-public:
- void Init();
- void Process();
- void Display();
- 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 ClearMessages();
- void RestartCurrentMessage();
+#pragma once + +struct PagerMessage { + wchar *m_pText; + uint16 m_nSpeedMs; + int16 m_nCurrentPosition; + uint16 m_nStringLength; + uint16 m_nPriority; + uint32 m_nTimeToChangePosition; + int16 field_10; + int32 m_nNumber[6]; +}; + +#define NUMPAGERMESSAGES 8 + +class CPager +{ + int16 m_nNumDisplayLetters; + PagerMessage m_messages[NUMPAGERMESSAGES]; +public: + void Init(); + void Process(); + void Display(); + 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 ClearMessages(); + void RestartCurrentMessage(); };
\ No newline at end of file diff --git a/src/text/Text.cpp b/src/text/Text.cpp index d0cdb310..5fc19f12 100644 --- a/src/text/Text.cpp +++ b/src/text/Text.cpp @@ -1,324 +1,324 @@ -#include "common.h"
-#include "patcher.h"
-#include "FileMgr.h"
-#include "Frontend.h"
-#include "Messages.h"
-#include "Text.h"
-
-static wchar WideErrorString[25];
-
-CText &TheText = *(CText*)0x941520;
-
-CText::CText(void)
-{
- encoding = 'e';
- memset(WideErrorString, 0, sizeof(WideErrorString));
-}
-
-void
-CText::Load(void)
-{
- uint8 *filedata;
- char filename[32], type[4];
- int length;
- int offset, sectlen;
-
- Unload();
- filedata = new uint8[0x40000];
-
- CFileMgr::SetDir("TEXT");
- switch(CMenuManager::m_PrefsLanguage){
- case LANGUAGE_AMERICAN:
- sprintf(filename, "AMERICAN.GXT");
- break;
- case LANGUAGE_FRENCH:
- sprintf(filename, "FRENCH.GXT");
- break;
- case LANGUAGE_GERMAN:
- sprintf(filename, "GERMAN.GXT");
- break;
- case LANGUAGE_ITALIAN:
- sprintf(filename, "ITALIAN.GXT");
- break;
- case LANGUAGE_SPANISH:
- sprintf(filename, "SPANISH.GXT");
- break;
-#ifdef MORE_LANGUAGES
- case LANGUAGE_RUSSIAN:
- sprintf(filename, "RUSSIAN.GXT");
- break;
-#endif
- }
-
- length = CFileMgr::LoadFile(filename, filedata, 0x40000, "rb");
- CFileMgr::SetDir("");
-
- offset = 0;
- while(offset < length){
- type[0] = filedata[offset++];
- type[1] = filedata[offset++];
- type[2] = filedata[offset++];
- type[3] = filedata[offset++];
- sectlen = (int)filedata[offset+3]<<24 | (int)filedata[offset+2]<<16 |
- (int)filedata[offset+1]<<8 | (int)filedata[offset+0];
- offset += 4;
- if(sectlen != 0){
- if(strncmp(type, "TKEY", 4) == 0)
- keyArray.Load(sectlen, filedata, &offset);
- else if(strncmp(type, "TDAT", 4) == 0)
- data.Load(sectlen, filedata, &offset);
- else
- offset += sectlen;
- }
- }
-
- keyArray.Update(data.chars);
-
- delete[] filedata;
-}
-
-void
-CText::Unload(void)
-{
- CMessages::ClearAllMessagesDisplayedByGame();
- data.Unload();
- keyArray.Unload();
-}
-
-wchar*
-CText::Get(const char *key)
-{
- return keyArray.Search(key);
-}
-
-wchar UpperCaseTable[128] = {
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
- 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
- 150, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
- 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
- 149, 173, 173, 175, 176, 177, 178, 179, 180, 181, 182,
- 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
- 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204,
- 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
- 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226,
- 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
- 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248,
- 249, 250, 251, 252, 253, 254, 255
-};
-
-wchar FrenchUpperCaseTable[128] = {
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
- 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
- 150, 65, 65, 65, 65, 132, 133, 69, 69, 69, 69, 73, 73,
- 73, 73, 79, 79, 79, 79, 85, 85, 85, 85, 173, 173, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186,
- 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
- 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208,
- 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
- 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230,
- 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241,
- 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
- 253, 254, 255
-};
-
-wchar
-CText::GetUpperCase(wchar c)
-{
- switch (encoding)
- {
- case 'e':
- if (c >= 'a' && c <= 'z')
- return c - 32;
- break;
- case 'f':
- if (c >= 'a' && c <= 'z')
- return c - 32;
-
- if (c >= 128 && c <= 255)
- return FrenchUpperCaseTable[c-128];
- break;
- case 'g':
- case 'i':
- case 's':
- if (c >= 'a' && c <= 'z')
- return c - 32;
-
- if (c >= 128 && c <= 255)
- return UpperCaseTable[c-128];
- break;
- default:
- break;
- }
- return c;
-}
-
-void
-CText::UpperCase(wchar *s)
-{
- while(*s){
- *s = GetUpperCase(*s);
- s++;
- }
-}
-
-
-void
-CKeyArray::Load(uint32 length, uint8 *data, int *offset)
-{
- uint32 i;
- uint8 *rawbytes;
-
- numEntries = length / sizeof(CKeyEntry);
- entries = new CKeyEntry[numEntries];
- rawbytes = (uint8*)entries;
-
- for(i = 0; i < length; i++)
- rawbytes[i] = data[(*offset)++];
-}
-
-void
-CKeyArray::Unload(void)
-{
- delete[] entries;
- entries = nil;
- numEntries = 0;
-}
-
-void
-CKeyArray::Update(wchar *chars)
-{
- int i;
- for(i = 0; i < numEntries; i++)
- entries[i].value = (wchar*)((uint8*)chars + (uintptr)entries[i].value);
-}
-
-CKeyEntry*
-CKeyArray::BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 high)
-{
- int mid;
- int diff;
-
- if(low > high)
- return nil;
-
- mid = (low + high)/2;
- diff = strcmp(key, entries[mid].key);
- if(diff == 0)
- return &entries[mid];
- if(diff < 0)
- return BinarySearch(key, entries, low, mid-1);
- if(diff > 0)
- return BinarySearch(key, entries, mid+1, high);
- return nil;
-}
-
-wchar*
-CKeyArray::Search(const char *key)
-{
- CKeyEntry *found;
- char errstr[25];
- int i;
-
- found = BinarySearch(key, entries, 0, numEntries-1);
- if(found)
- return found->value;
- sprintf(errstr, "%s missing", key);
- for(i = 0; i < 25; i++)
- WideErrorString[i] = errstr[i];
- return WideErrorString;
-}
-
-
-void
-CData::Load(uint32 length, uint8 *data, int *offset)
-{
- uint32 i;
- uint8 *rawbytes;
-
- numChars = length / sizeof(wchar);
- chars = new wchar[numChars];
- rawbytes = (uint8*)chars;
-
- for(i = 0; i < length; i++)
- rawbytes[i] = data[(*offset)++];
-}
-
-void
-CData::Unload(void)
-{
- delete[] chars;
- chars = nil;
- numChars = 0;
-}
-
-void
-AsciiToUnicode(const char *src, wchar *dst)
-{
- while((*dst++ = *src++) != '\0');
-}
-
-char*
-UnicodeToAscii(wchar *src)
-{
- static char aStr[256];
- int len;
- for(len = 0; *src != '\0' && len < 256-1; len++, src++)
- if(*src < 128)
- aStr[len] = *src;
- else
- aStr[len] = '#';
- aStr[len] = '\0';
- return aStr;
-}
-
-char*
-UnicodeToAsciiForSaveLoad(wchar *src)
-{
- static char aStr[256];
- int len;
- for(len = 0; *src != '\0' && len < 256-1; len++, src++)
- if(*src < 256)
- aStr[len] = *src;
- else
- aStr[len] = '#';
- aStr[len] = '\0';
- return aStr;
-}
-
-void
-UnicodeStrcpy(wchar *dst, const wchar *src)
-{
- while((*dst++ = *src++) != '\0');
-}
-
-int
-UnicodeStrlen(const wchar *str)
-{
- int len;
- for(len = 0; *str != '\0'; len++, str++);
- return len;
-}
-
-void
-TextCopy(wchar *dst, const wchar *src)
-{
- while((*dst++ = *src++) != '\0');
-}
-
-
-STARTPATCHES
- InjectHook(0x52C3C0, &CText::Load, PATCH_JUMP);
- InjectHook(0x52C580, &CText::Unload, PATCH_JUMP);
- InjectHook(0x52C5A0, &CText::Get, PATCH_JUMP);
- InjectHook(0x52C220, &CText::GetUpperCase, PATCH_JUMP);
- InjectHook(0x52C2C0, &CText::UpperCase, PATCH_JUMP);
-
- InjectHook(0x52BE70, &CKeyArray::Load, PATCH_JUMP);
- InjectHook(0x52BF60, &CKeyArray::Unload, PATCH_JUMP);
- InjectHook(0x52BF80, &CKeyArray::Update, PATCH_JUMP);
- InjectHook(0x52C060, &CKeyArray::BinarySearch, PATCH_JUMP);
- InjectHook(0x52BFB0, &CKeyArray::Search, PATCH_JUMP);
-
- InjectHook(0x52C120, &CData::Load, PATCH_JUMP);
- InjectHook(0x52C200, &CData::Unload, PATCH_JUMP);
-ENDPATCHES
+#include "common.h" +#include "patcher.h" +#include "FileMgr.h" +#include "Frontend.h" +#include "Messages.h" +#include "Text.h" + +static wchar WideErrorString[25]; + +CText &TheText = *(CText*)0x941520; + +CText::CText(void) +{ + encoding = 'e'; + memset(WideErrorString, 0, sizeof(WideErrorString)); +} + +void +CText::Load(void) +{ + uint8 *filedata; + char filename[32], type[4]; + int length; + int offset, sectlen; + + Unload(); + filedata = new uint8[0x40000]; + + CFileMgr::SetDir("TEXT"); + switch(CMenuManager::m_PrefsLanguage){ + case LANGUAGE_AMERICAN: + sprintf(filename, "AMERICAN.GXT"); + break; + case LANGUAGE_FRENCH: + sprintf(filename, "FRENCH.GXT"); + break; + case LANGUAGE_GERMAN: + sprintf(filename, "GERMAN.GXT"); + break; + case LANGUAGE_ITALIAN: + sprintf(filename, "ITALIAN.GXT"); + break; + case LANGUAGE_SPANISH: + sprintf(filename, "SPANISH.GXT"); + break; +#ifdef MORE_LANGUAGES + case LANGUAGE_RUSSIAN: + sprintf(filename, "RUSSIAN.GXT"); + break; +#endif + } + + length = CFileMgr::LoadFile(filename, filedata, 0x40000, "rb"); + CFileMgr::SetDir(""); + + offset = 0; + while(offset < length){ + type[0] = filedata[offset++]; + type[1] = filedata[offset++]; + type[2] = filedata[offset++]; + type[3] = filedata[offset++]; + sectlen = (int)filedata[offset+3]<<24 | (int)filedata[offset+2]<<16 | + (int)filedata[offset+1]<<8 | (int)filedata[offset+0]; + offset += 4; + if(sectlen != 0){ + if(strncmp(type, "TKEY", 4) == 0) + keyArray.Load(sectlen, filedata, &offset); + else if(strncmp(type, "TDAT", 4) == 0) + data.Load(sectlen, filedata, &offset); + else + offset += sectlen; + } + } + + keyArray.Update(data.chars); + + delete[] filedata; +} + +void +CText::Unload(void) +{ + CMessages::ClearAllMessagesDisplayedByGame(); + data.Unload(); + keyArray.Unload(); +} + +wchar* +CText::Get(const char *key) +{ + return keyArray.Search(key); +} + +wchar UpperCaseTable[128] = { + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, + 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, + 149, 173, 173, 175, 176, 177, 178, 179, 180, 181, 182, + 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, + 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, + 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, + 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, + 249, 250, 251, 252, 253, 254, 255 +}; + +wchar FrenchUpperCaseTable[128] = { + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 65, 65, 65, 65, 132, 133, 69, 69, 69, 69, 73, 73, + 73, 73, 79, 79, 79, 79, 85, 85, 85, 85, 173, 173, 175, + 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, + 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, + 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, + 253, 254, 255 +}; + +wchar +CText::GetUpperCase(wchar c) +{ + switch (encoding) + { + case 'e': + if (c >= 'a' && c <= 'z') + return c - 32; + break; + case 'f': + if (c >= 'a' && c <= 'z') + return c - 32; + + if (c >= 128 && c <= 255) + return FrenchUpperCaseTable[c-128]; + break; + case 'g': + case 'i': + case 's': + if (c >= 'a' && c <= 'z') + return c - 32; + + if (c >= 128 && c <= 255) + return UpperCaseTable[c-128]; + break; + default: + break; + } + return c; +} + +void +CText::UpperCase(wchar *s) +{ + while(*s){ + *s = GetUpperCase(*s); + s++; + } +} + + +void +CKeyArray::Load(uint32 length, uint8 *data, int *offset) +{ + uint32 i; + uint8 *rawbytes; + + numEntries = length / sizeof(CKeyEntry); + entries = new CKeyEntry[numEntries]; + rawbytes = (uint8*)entries; + + for(i = 0; i < length; i++) + rawbytes[i] = data[(*offset)++]; +} + +void +CKeyArray::Unload(void) +{ + delete[] entries; + entries = nil; + numEntries = 0; +} + +void +CKeyArray::Update(wchar *chars) +{ + int i; + for(i = 0; i < numEntries; i++) + entries[i].value = (wchar*)((uint8*)chars + (uintptr)entries[i].value); +} + +CKeyEntry* +CKeyArray::BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 high) +{ + int mid; + int diff; + + if(low > high) + return nil; + + mid = (low + high)/2; + diff = strcmp(key, entries[mid].key); + if(diff == 0) + return &entries[mid]; + if(diff < 0) + return BinarySearch(key, entries, low, mid-1); + if(diff > 0) + return BinarySearch(key, entries, mid+1, high); + return nil; +} + +wchar* +CKeyArray::Search(const char *key) +{ + CKeyEntry *found; + char errstr[25]; + int i; + + found = BinarySearch(key, entries, 0, numEntries-1); + if(found) + return found->value; + sprintf(errstr, "%s missing", key); + for(i = 0; i < 25; i++) + WideErrorString[i] = errstr[i]; + return WideErrorString; +} + + +void +CData::Load(uint32 length, uint8 *data, int *offset) +{ + uint32 i; + uint8 *rawbytes; + + numChars = length / sizeof(wchar); + chars = new wchar[numChars]; + rawbytes = (uint8*)chars; + + for(i = 0; i < length; i++) + rawbytes[i] = data[(*offset)++]; +} + +void +CData::Unload(void) +{ + delete[] chars; + chars = nil; + numChars = 0; +} + +void +AsciiToUnicode(const char *src, wchar *dst) +{ + while((*dst++ = *src++) != '\0'); +} + +char* +UnicodeToAscii(wchar *src) +{ + static char aStr[256]; + int len; + for(len = 0; *src != '\0' && len < 256-1; len++, src++) + if(*src < 128) + aStr[len] = *src; + else + aStr[len] = '#'; + aStr[len] = '\0'; + return aStr; +} + +char* +UnicodeToAsciiForSaveLoad(wchar *src) +{ + static char aStr[256]; + int len; + for(len = 0; *src != '\0' && len < 256-1; len++, src++) + if(*src < 256) + aStr[len] = *src; + else + aStr[len] = '#'; + aStr[len] = '\0'; + return aStr; +} + +void +UnicodeStrcpy(wchar *dst, const wchar *src) +{ + while((*dst++ = *src++) != '\0'); +} + +int +UnicodeStrlen(const wchar *str) +{ + int len; + for(len = 0; *str != '\0'; len++, str++); + return len; +} + +void +TextCopy(wchar *dst, const wchar *src) +{ + while((*dst++ = *src++) != '\0'); +} + + +STARTPATCHES + InjectHook(0x52C3C0, &CText::Load, PATCH_JUMP); + InjectHook(0x52C580, &CText::Unload, PATCH_JUMP); + InjectHook(0x52C5A0, &CText::Get, PATCH_JUMP); + InjectHook(0x52C220, &CText::GetUpperCase, PATCH_JUMP); + InjectHook(0x52C2C0, &CText::UpperCase, PATCH_JUMP); + + InjectHook(0x52BE70, &CKeyArray::Load, PATCH_JUMP); + InjectHook(0x52BF60, &CKeyArray::Unload, PATCH_JUMP); + InjectHook(0x52BF80, &CKeyArray::Update, PATCH_JUMP); + InjectHook(0x52C060, &CKeyArray::BinarySearch, PATCH_JUMP); + InjectHook(0x52BFB0, &CKeyArray::Search, PATCH_JUMP); + + InjectHook(0x52C120, &CData::Load, PATCH_JUMP); + InjectHook(0x52C200, &CData::Unload, PATCH_JUMP); +ENDPATCHES |