Removed some redundant code

This commit is contained in:
NovaRain
2020-07-19 08:56:42 +08:00
parent e0f0ee0f7d
commit 74d3cb9707
6 changed files with 30 additions and 26 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ PathNode** ptr_master_db_handle = reinterpret_cast<PathNode**>(_master_db_
DWORD* ptr_master_volume = reinterpret_cast<DWORD*>(_master_volume);
DWORD* ptr_max = reinterpret_cast<DWORD*>(_max);
long* ptr_maxScriptNum = reinterpret_cast<long*>(_maxScriptNum);
DWORD* ptr_Meet_Frank_Horrigan = reinterpret_cast<DWORD*>(_Meet_Frank_Horrigan);
bool* ptr_Meet_Frank_Horrigan = reinterpret_cast<bool*>(_Meet_Frank_Horrigan);
const char** ptr_movie_list = reinterpret_cast<const char**>(_movie_list); // array of 17 char*
DWORD* ptr_mouse_hotx = reinterpret_cast<DWORD*>(_mouse_hotx);
DWORD* ptr_mouse_hoty = reinterpret_cast<DWORD*>(_mouse_hoty);
+1 -1
View File
@@ -410,7 +410,7 @@ extern PathNode** ptr_master_db_handle;
extern DWORD* ptr_master_volume;
extern DWORD* ptr_max;
extern long* ptr_maxScriptNum;
extern DWORD* ptr_Meet_Frank_Horrigan;
extern bool* ptr_Meet_Frank_Horrigan;
extern const char** ptr_movie_list; // array of 17 char*
extern DWORD* ptr_mouse_hotx;
extern DWORD* ptr_mouse_hoty;
+3 -4
View File
@@ -236,6 +236,7 @@ errorLoad:
static void __stdcall LoadGame_After() {
CritLoad();
*ptr_Meet_Frank_Horrigan = disableHorrigan;
LoadGlobalScripts();
gameLoaded = true;
}
@@ -317,6 +318,7 @@ static void NewGame2() {
CritLoad();
SetNewCharAppearanceGlobals();
LoadHeroAppearance();
*ptr_Meet_Frank_Horrigan = disableHorrigan;
LoadGlobalScripts();
dlogr("New Game started.", DL_MAIN);
@@ -328,8 +330,6 @@ static void __declspec(naked) NewGame() {
__asm {
pushad;
call NewGame2;
mov al, disableHorrigan;
mov byte ptr ds:[_Meet_Frank_Horrigan], al;
popad;
jmp main_game_loop_;
}
@@ -628,13 +628,12 @@ void LoadGameHookInit() {
pipBoyAvailableAtGameStart = true;
break;
case 2:
SafeWrite8(0x497011, 0xEB); // skip the vault suit movie check
SafeWrite8(0x497011, CODETYPE_JumpShort); // skip the vault suit movie check
break;
}
if (GetConfigInt("Misc", "DisableHorrigan", 0)) {
disableHorrigan = true;
SafeWrite8(0x4C06D8, 0xEB); // skip the Horrigan encounter check
}
// 4.x backport
+10 -8
View File
@@ -472,20 +472,22 @@ void MoviesInit() {
if (*((DWORD*)0x00518DA0) != 0x00503300) {
dlog("Error: The value at address 0x001073A0 is not equal to 0x00503300.", DL_INIT);
}
char optName[8] = "Movie";
for (int i = 0; i < MaxMovies; i++) {
MoviePtrs[i] = (DWORD)&MoviePaths[65 * i];
MoviePaths[i * 65 + 64] = 0;
char ininame[8];
strcpy_s(ininame, "Movie");
_itoa_s(i + 1, &ininame[5], 3, 10);
int index = 65 * i;
MoviePtrs[i] = (DWORD)&MoviePaths[index];
MoviePaths[index + 64] = '\0';
_itoa_s(i + 1, &optName[5], 3, 10);
if (i < 17) {
GetConfigString("Misc", ininame, ptr_movie_list[i], &MoviePaths[i * 65], 65);
GetConfigString("Misc", optName, ptr_movie_list[i], &MoviePaths[index], 65);
} else {
GetConfigString("Misc", ininame, "", &MoviePaths[i * 65], 65);
GetConfigString("Misc", optName, "", &MoviePaths[index], 65);
}
}
dlog(".", DL_INIT);
const DWORD movieListAddr[] = {0x44E6AE, 0x44E721, 0x44E75E, 0x44E78A};
const DWORD movieListAddr[] = {0x44E6AE, 0x44E721, 0x44E75E, 0x44E78A}; // gmovie_play_
SafeWriteBatch<DWORD>((DWORD)MoviePtrs, movieListAddr);
dlog(".", DL_INIT);
+6 -12
View File
@@ -1,10 +1,4 @@
#include "main.h"
enum CodeType : BYTE {
CODE_Call = 0xE8,
CODE_Jump = 0xE9,
CODE_Nop = 0x90
};
#include "SafeWrite.h"
static void __stdcall SafeWriteFunc(BYTE code, DWORD addr, void* func) {
DWORD oldProtect, data = (DWORD)func - (addr + 5);
@@ -26,7 +20,7 @@ static __declspec(noinline) void __stdcall SafeWriteFunc(BYTE code, DWORD addr,
*((DWORD*)(addr + 1)) = data;
for (unsigned int i = 0; i < len; i++) {
*((BYTE*)(addrMem + i)) = CODE_Nop;
*((BYTE*)(addrMem + i)) = CODETYPE_Nop;
}
VirtualProtect((void *)addr, protectLen, oldProtect, &oldProtect);
}
@@ -77,19 +71,19 @@ void HookCall(DWORD addr, void* func) {
}
void MakeCall(DWORD addr, void* func) {
SafeWriteFunc(CODE_Call, addr, func);
SafeWriteFunc(CODETYPE_Call, addr, func);
}
void MakeCall(DWORD addr, void* func, int len) {
SafeWriteFunc(CODE_Call, addr, func, len);
SafeWriteFunc(CODETYPE_Call, addr, func, len);
}
void MakeJump(DWORD addr, void* func) {
SafeWriteFunc(CODE_Jump, addr, func);
SafeWriteFunc(CODETYPE_Jump, addr, func);
}
void MakeJump(DWORD addr, void* func, int len) {
SafeWriteFunc(CODE_Jump, addr, func, len);
SafeWriteFunc(CODETYPE_Jump, addr, func, len);
}
void SafeMemSet(DWORD addr, BYTE val, int len) {
+9
View File
@@ -1,5 +1,14 @@
#pragma once
enum CodeType : BYTE {
CODETYPE_Call = 0xE8,
CODETYPE_Jump = 0xE9,
CODETYPE_Nop = 0x90,
CODETYPE_JumpShort = 0xEB, // 0xEB [jmp short ...]
CODETYPE_JumpNZ = 0x75, // 0x75 [jnz short ...]
CODETYPE_JumpZ = 0x74, // 0x74 [jz short ...]
};
template <typename T>
void __stdcall SafeWrite(DWORD addr, T data) {
DWORD oldProtect;