Minor edits to Message.cpp and define_extra.h.

This commit is contained in:
NovaRain
2019-08-17 20:56:48 +08:00
parent 07ff16af75
commit 99bc47e3f8
4 changed files with 50 additions and 53 deletions
+1 -1
View File
@@ -31,7 +31,7 @@
#define WEAPON_BIGGUN 256 // 0x00000100 - Big Gun
#define WEAPON_2HAND 512 // 0x00000200 - 2Hnd (weapon is two-handed)
#define WEAPON_ENERGYWEAPON 1024 // 0x00000400 - Energy Weapon (forces weapon to use Energy Weapons skill)
#define WEAPON_ENERGY 1024 // 0x00000400 - Energy Weapon (forces weapon to use Energy Weapons skill)
#define ATKMODE_PRI_NONE 0
#define ATKMODE_PRI_PUNCH 1 // 0001
+2 -1
View File
@@ -347,7 +347,7 @@ static void __declspec(naked) GameCloseHook() {
static void __declspec(naked) WorldMapHook() {
__asm {
or InLoop, WORLDMAP;
xor eax, eax;
xor eax, eax; // unused
call wmWorldMapFunc_;
and InLoop, (-1 ^ WORLDMAP);
retn;
@@ -561,6 +561,7 @@ void LoadGameHookInit() {
HookCall(0x480CA7, GameCloseHook); // gnw_main_
//HookCall(0x480D45, GameCloseHook); // main_exit_system_ (never called)
// game modes
HookCall(0x483668, WorldMapHook);
HookCall(0x4A4073, WorldMapHook);
HookCall(0x4C4855, WorldMapHook2);
+33 -36
View File
@@ -24,58 +24,56 @@
ExtraGameMessageListsMap gExtraGameMsgLists;
int LoadMsgList(MSGList *MsgList, char *MsgFilePath) {
int LoadMsgList(MSGList *msgList, const char *msgFilePath) {
int retVal;
__asm {
mov edx, MsgFilePath;
mov eax, MsgList;
mov edx, msgFilePath;
mov eax, msgList;
call message_load_;
mov retVal, eax;
}
return retVal;
}
int DestroyMsgList(MSGList *MsgList) {
int DestroyMsgList(MSGList *msgList) {
int retVal;
__asm {
mov eax, MsgList;
mov eax, msgList;
call message_exit_;
mov retVal, eax;
}
return retVal;
}
MSGNode *GetMsgNode(MSGList *MsgList, DWORD msgRef) {
if (MsgList == nullptr) return nullptr;
if (MsgList->numMsgs <= 0) return nullptr;
MSGNode *GetMsgNode(MSGList *msgList, int msgRef) {
if (msgList != nullptr && msgList->numMsgs > 0) {
MSGNode *MsgNode = msgList->nodes;
long last = msgList->numMsgs - 1;
long first = 0;
long mid;
MSGNode *MsgNode = (MSGNode*)MsgList->MsgNodes;
long last = MsgList->numMsgs - 1;
long first = 0;
long mid;
//Use Binary Search to find msg
while (first <= last) {
mid = (first + last) / 2;
if (msgRef > MsgNode[mid].ref)
first = mid + 1;
else if (msgRef < MsgNode[mid].ref)
last = mid - 1;
else
return &MsgNode[mid];
//Use Binary Search to find msg
while (first <= last) {
mid = (first + last) / 2;
if (msgRef > MsgNode[mid].number)
first = mid + 1;
else if (msgRef < MsgNode[mid].number)
last = mid - 1;
else
return &MsgNode[mid];
}
}
return nullptr;
}
char* GetMsg(MSGList *MsgList, DWORD msgRef, int msgNum) {
MSGNode *MsgNode = GetMsgNode(MsgList, msgRef);
if (MsgNode) {
if (msgNum == 2)
return MsgNode->msg2;
else if (msgNum == 1)
return MsgNode->msg1;
char* GetMsg(MSGList *msgList, int msgRef, int msgNum) {
MSGNode *msgNode = GetMsgNode(msgList, msgRef);
if (msgNode) {
if (msgNum == 2) {
return msgNode->message;
} else if (msgNum == 1) {
return msgNode->audio;
}
}
return nullptr;
}
@@ -90,8 +88,7 @@ void ReadExtraGameMsgFiles() {
(LPSTR)names.data(), names.size(), ini)) == names.size() - 1)
names.resize(names.size() + 256);
if (names.empty())
return;
if (names.empty()) return;
names.resize(names.find_first_of('\0'));
names.append(",");
@@ -107,11 +104,11 @@ void ReadExtraGameMsgFiles() {
if (length > 0) {
std::string path = "game\\" + names.substr(begin, length) + ".msg";
MSGList* list = new MSGList;
if (LoadMsgList(list, (char*)path.data()) == 1)
if (LoadMsgList(list, path.c_str()) == 1) {
gExtraGameMsgLists.insert(std::make_pair(0x2000 + number, list));
else
} else {
delete list;
}
}
if (++number == 4096) break;
+14 -15
View File
@@ -23,26 +23,26 @@
//for holding a message
typedef struct MSGNode {
DWORD ref;
DWORD a;
char *msg1; //unused
char *msg2;
long number;
long flags;
char *audio; //unused
char *message;
MSGNode() {
ref = 0;
a = 0;
msg1 = nullptr;
msg2 = nullptr;
number = 0;
flags = 0;
audio = nullptr;
message = nullptr;
}
} MSGNode;
//for holding msg array
typedef struct MSGList {
long numMsgs;
void *MsgNodes;
MSGNode *nodes;
MSGList() {
MsgNodes = nullptr;
nodes = nullptr;
numMsgs = 0;
}
} MSGList;
@@ -50,10 +50,9 @@ typedef struct MSGList {
typedef std::tr1::unordered_map<int, MSGList*> ExtraGameMessageListsMap;
extern ExtraGameMessageListsMap gExtraGameMsgLists;
int LoadMsgList(MSGList *MsgList, char *MsgFilePath);
int DestroyMsgList(MSGList *MsgList);
//bool GetMsg(MSGList *MsgList, MSGNode *MsgNode, DWORD msgRef);
MSGNode *GetMsgNode(MSGList *MsgList, DWORD msgRef);
char* GetMsg(MSGList *MsgList, DWORD msgRef, int msgNum);
int LoadMsgList(MSGList *msgList, const char *msgFilePath);
int DestroyMsgList(MSGList *msgList);
MSGNode *GetMsgNode(MSGList *msgList, int msgRef);
char* GetMsg(MSGList *msgList, int msgRef, int msgNum);
void ReadExtraGameMsgFiles();
void ClearReadExtraGameMsgFiles();