Fixed some non-critical memory address conflicts

Renamed F1EngineBehavior option to Fallout1Behavior.
This commit is contained in:
NovaRain
2019-09-10 06:57:21 +08:00
parent 4afde14f04
commit 66d4db10ad
5 changed files with 33 additions and 34 deletions
+2 -2
View File
@@ -191,10 +191,10 @@ DebugEditorKey=0
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[Misc]
;Changes some of Fallout 2 engine features to Fallout 1 behavior:
;Changes some of Fallout 2 engine functions to Fallout 1 behavior:
;- disables playing the final movie/credits after the endgame slideshow
;- disables halving the weight for power armor items
F1EngineBehavior=0
Fallout1Behavior=0
;Time limit in years. Must be between -3 and 13
;Set to 0 if you want to die the instant you leave arroyo
+6 -4
View File
@@ -60,7 +60,7 @@ static const DWORD anim_set_0[] = {
0x414E48, 0x414EDA, 0x414F5E, 0x414FEE, 0x41505C, 0x4150D0, 0x415158,
0x4151B8, 0x415286, 0x41535C, 0x4153D0, 0x41544A, 0x4154EC, 0x4155EA,
0x4156C0, 0x4156D5, 0x4156F2, 0x41572F, 0x41573E, 0x415B1B, 0x415B56,
0x415BB6, 0x415C7C, 0x415CA3, 0x415DE4,
0x415BB6, 0x415C7C, 0x415CA3, /*0x415DE4, - conflct with 0x415DE2*/
};
static const DWORD anim_set_4[] = {
@@ -153,14 +153,14 @@ static const DWORD sad_28[] = {
0x4173CE, 0x4174C1, 0x4175F1, 0x417730,
};
static DWORD __fastcall AnimCombatFix(DWORD* src, BYTE combatFlag) {
static DWORD __fastcall AnimCombatFix(fo::GameObject* src, BYTE combatFlag) {
DWORD animAddr = animSetAddr;
if (animationLimit > 32) {
animAddr += animRecordSize; // include a dummy
}
if (combatFlag & 2) { // combat flag is set
if (combatFlag & 2) { // combat flag is set
__asm call fo::funcoffs::combat_anim_finished_;
}
return animAddr;
@@ -168,9 +168,11 @@ static DWORD __fastcall AnimCombatFix(DWORD* src, BYTE combatFlag) {
static void __declspec(naked) anim_set_end_hack() {
__asm {
push ecx;
call AnimCombatFix;
mov [eax][esi], ebx;
xor dl, dl; // goto 0x415DF2;
pop ecx;
xor dl, dl; // for goto 0x415DF2;
retn;
}
}
-2
View File
@@ -166,8 +166,6 @@ static const DWORD wmWinWidth[] = {
0x4C4BDF,
// wmDrawCursorStopped_
0x4C42EE, 0x4C43C8, 0x4C445F,
// wmTownMapRefresh_
0x4C4BDF
};
// Right limit of the viewport (450)
+1 -1
View File
@@ -713,7 +713,7 @@ void UseWalkDistancePatch() {
}
void F1EngineBehaviorPatch() {
if (GetConfigInt("Misc", "F1EngineBehavior", 0)) {
if (GetConfigInt("Misc", "Fallout1Behavior", 0)) {
dlog("Applying Fallout 1 engine behavior patch.", DL_INIT);
BlockCall(0x4A4343); // disable playing the final movie/credits after the endgame slideshow
SafeWrite8(0x477C71, 0xEB); // disable halving the weight for power armor items
+24 -25
View File
@@ -16,23 +16,25 @@ std::multimap<long, long> writeAddress;
/* Checking for conflicts requires all options in ddraw.ini to be enabled */
void PrintAddrList() {
unsigned long prev = 0, plen = 0;
bool level = (GetPrivateProfileIntA("Debugging", "Enable", 0, ::sfall::ddrawIni) > 1);
unsigned long pa = 0, pl = 0;
for (const auto &wa : writeAddress) {
unsigned long diff = (prev) ? (wa.first - prev) : -1; // length between two addresses
if (diff == 0 || diff < plen) {
dlog_f("0x%x L:%d [Conflict]\n", DL_MAIN, wa.first, wa.second);
} else if (diff == plen) {
dlog_f("0x%x L:%d [Warning] PL:%d\n", DL_MAIN, wa.first, wa.second, plen);
} else {
unsigned long diff = (pa) ? (wa.first - pa) : -1; // length between two addresses
if (diff == 0) {
dlog_f("0x%x L:%d [Overwriting]\n", DL_MAIN, wa.first, wa.second);
} else if (diff < pl) {
dlog_f("0x%x L:%d [Conflict] with 0x%x L:%d\n", DL_MAIN, wa.first, wa.second, pa, pl);
} else if (level && diff == pl) {
dlog_f("0x%x L:%d [Warning] PL:%d\n", DL_MAIN, wa.first, wa.second, pl);
} else if (level) {
dlog_f("0x%x L:%d\n", DL_MAIN, wa.first, wa.second);
}
prev = wa.first;
plen = wa.second;
pa = wa.first;
pl = wa.second;
}
}
void CheckConflict(DWORD addr, long len) {
writeAddress.begin()->first;
if (writeAddress.find(addr) != writeAddress.cend()) {
char buf[64];
sprintf_s(buf, "Memory writing conflict at address 0x%x.", addr);
@@ -45,12 +47,9 @@ void CheckConflict(DWORD addr, long len) {
void AddrAddToList(DWORD addr, long len) {
writeAddress.emplace(addr, len);
}
#define _CheckConflict(addr, len) CheckConflict(addr, len);
#define _AddrAddToList(addr, len) AddrAddToList(addr, len);
#else
#define _CheckConflict(a, b)
#define _AddrAddToList(a, b)
void CheckConflict(DWORD addr, long len) {}
void AddrAddToList(DWORD addr, long len) {}
#endif
static void _stdcall SafeWriteFunc(BYTE code, DWORD addr, void* func) {
@@ -61,7 +60,7 @@ static void _stdcall SafeWriteFunc(BYTE code, DWORD addr, void* func) {
*((DWORD*)(addr + 1)) = data;
VirtualProtect((void *)addr, 5, oldProtect, &oldProtect);
_CheckConflict(addr, 5);
CheckConflict(addr, 5);
}
static __declspec(noinline) void _stdcall SafeWriteFunc(BYTE code, DWORD addr, void* func, DWORD len) {
@@ -79,7 +78,7 @@ static __declspec(noinline) void _stdcall SafeWriteFunc(BYTE code, DWORD addr, v
}
VirtualProtect((void *)addr, protectLen, oldProtect, &oldProtect);
_CheckConflict(addr, protectLen);
CheckConflict(addr, protectLen);
}
void SafeWriteBytes(DWORD addr, BYTE* data, int count) {
@@ -89,7 +88,7 @@ void SafeWriteBytes(DWORD addr, BYTE* data, int count) {
memcpy((void*)addr, data, count);
VirtualProtect((void *)addr, count, oldProtect, &oldProtect);
_AddrAddToList(addr, count)
AddrAddToList(addr, count);
}
void _stdcall SafeWrite8(DWORD addr, BYTE data) {
@@ -99,7 +98,7 @@ void _stdcall SafeWrite8(DWORD addr, BYTE data) {
*((BYTE*)addr) = data;
VirtualProtect((void *)addr, 1, oldProtect, &oldProtect);
_AddrAddToList(addr, 1)
AddrAddToList(addr, 1);
}
void _stdcall SafeWrite16(DWORD addr, WORD data) {
@@ -109,7 +108,7 @@ void _stdcall SafeWrite16(DWORD addr, WORD data) {
*((WORD*)addr) = data;
VirtualProtect((void *)addr, 2, oldProtect, &oldProtect);
_AddrAddToList(addr, 2)
AddrAddToList(addr, 2);
}
void _stdcall SafeWrite32(DWORD addr, DWORD data) {
@@ -119,7 +118,7 @@ void _stdcall SafeWrite32(DWORD addr, DWORD data) {
*((DWORD*)addr) = data;
VirtualProtect((void *)addr, 4, oldProtect, &oldProtect);
_AddrAddToList(addr, 4)
AddrAddToList(addr, 4);
}
void _stdcall SafeWriteStr(DWORD addr, const char* data) {
@@ -130,13 +129,13 @@ void _stdcall SafeWriteStr(DWORD addr, const char* data) {
strcpy((char *)addr, data);
VirtualProtect((void *)addr, len, oldProtect, &oldProtect);
_AddrAddToList(addr, len)
AddrAddToList(addr, len);
}
void HookCall(DWORD addr, void* func) {
SafeWrite32(addr + 1, (DWORD)func - (addr + 5));
_CheckConflict(addr, 1)
CheckConflict(addr, 1);
}
void MakeCall(DWORD addr, void* func) {
@@ -174,7 +173,7 @@ void SafeMemSet(DWORD addr, BYTE val, int len) {
memset((void*)addr, val, len);
VirtualProtect((void *)addr, len, oldProtect, &oldProtect);
_AddrAddToList(addr, len)
AddrAddToList(addr, len);
}
void BlockCall(DWORD addr) {
@@ -185,7 +184,7 @@ void BlockCall(DWORD addr) {
*((BYTE*)(addr + 4)) = 0x00;
VirtualProtect((void *)addr, 5, oldProtect, &oldProtect);
_CheckConflict(addr, 5)
CheckConflict(addr, 5);
}
}