Improved the message box for CRC mismatch

Changed SkipCompatModeCheck to not require sfall debugging mode.
Minor code edits.
This commit is contained in:
NovaRain
2021-12-28 12:44:20 +08:00
parent 74455db5a9
commit 921db36478
7 changed files with 43 additions and 26 deletions
+1
View File
@@ -852,6 +852,7 @@ AllowUnsafeScripting=0
;ExtraCRC=0x00000000,0x00000000
;Set to 1 to skip the compatibility mode check
;Does not require sfall debugging mode
SkipCompatModeCheck=0
;Fallout 2 Debug Patch
+20 -12
View File
@@ -74,7 +74,7 @@ static const DWORD CRC_table[256] = {
0x1886B265, 0x12D9FF10, 0x0C38288F, 0x066765FA, 0x0C435932, 0x061C1447, 0x18FDC3D8, 0x12A28EAD
};
static DWORD crcInternal(BYTE* data, DWORD size) {
static DWORD CalcCRCInternal(BYTE* data, DWORD size) {
DWORD crc = 0xFFFFFFFF;
for (DWORD i = 0; i < size; i++) {
crc = CRC_table[(((BYTE)(crc)) ^ data[i])] ^ (crc >> 8);
@@ -82,6 +82,17 @@ static DWORD crcInternal(BYTE* data, DWORD size) {
return crc ^ 0xFFFFFFFF;
}
static bool CheckExtraCRC(DWORD crc) {
auto extraCrcList = IniReader::GetListDefaultConfig("Debugging", "ExtraCRC", "", 512, ',');
if (!extraCrcList.empty()) {
return std::any_of(extraCrcList.begin(), extraCrcList.end(), [crc](const std::string& testCrcStr) {
auto testedCrc = strtoul(testCrcStr.c_str(), 0, 16);
return testedCrc && crc == testedCrc; // return for lambda
});
}
return false;
}
bool CRC(const char* filepath) {
char buf[512];
@@ -98,30 +109,27 @@ bool CRC(const char* filepath) {
ReadFile(h, bytes, size, &crc, 0);
CloseHandle(h);
crc = crcInternal(bytes, size);
crc = CalcCRCInternal(bytes, size);
delete[] bytes;
for (int i = 0; i < sizeof(ExpectedCRC) / 4; i++) {
if (crc == ExpectedCRC[i]) return true;
}
bool matchedCRC = false;
auto extraCrcList = IniReader::GetListDefaultConfig("Debugging", "ExtraCRC", "", 512, ',');
if (!extraCrcList.empty()) {
matchedCRC = std::any_of(extraCrcList.begin(), extraCrcList.end(), [crc](const std::string& testCrcStr) {
auto testedCrc = strtoul(testCrcStr.c_str(), 0, 16);
return testedCrc && crc == testedCrc; // return for lambda
});
}
Retry:
bool matchedCRC = CheckExtraCRC(crc);
if (!matchedCRC) {
sprintf_s(buf, "You're trying to use sfall with an incompatible version of Fallout.\n"
"Was expecting '" TARGETVERSION "'.\n\n"
"%s has an unexpected CRC.\nExpected 0x%x but got 0x%x.", filepath, ExpectedCRC[0], crc);
if (size == ExpectedSize) {
if (MessageBoxA(0, buf, "CRC mismatch", MB_TASKMODAL | MB_ICONWARNING | MB_ABORTRETRYIGNORE) != IDIGNORE) {
switch (MessageBoxA(0, buf, "CRC Mismatch", MB_TASKMODAL | MB_ICONWARNING | MB_ABORTRETRYIGNORE)) {
case IDABORT:
ExitProcess(1);
break;
case IDRETRY:
goto Retry;
}
return true;
}
+9 -2
View File
@@ -66,6 +66,10 @@ int IniReader::GetIntDefaultConfig(const char* section, const char* setting, int
return getInt(section, setting, defaultValue, ddrawIni);
}
std::string IniReader::GetStringDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize) {
return getString(section, setting, defaultValue, bufSize, ddrawIni);
}
std::vector<std::string> IniReader::GetListDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter) {
return getList(section, setting, defaultValue, bufSize, delimiter, ddrawIni);
}
@@ -105,8 +109,11 @@ std::vector<std::string> IniReader::GetList(const char* section, const char* set
int IniReader::SetConfigInt(const char* section, const char* setting, int value) {
char buf[33];
_itoa_s(value, buf, 33, 10);
int result = WritePrivateProfileStringA(section, setting, buf, ini);
return result;
return WritePrivateProfileStringA(section, setting, buf, ini);
}
int IniReader::SetDefaultConfigString(const char* section, const char* setting, const char* value) {
return WritePrivateProfileStringA(section, setting, value, ddrawIni);
}
void IniReader::init() {
+4
View File
@@ -34,6 +34,8 @@ public:
// Gets the integer value from the default config (i.e. ddraw.ini)
static int GetIntDefaultConfig(const char* section, const char* setting, int defaultValue);
static std::string GetStringDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize);
// Gets a list of values separated by the delimiter from the default config (i.e. ddraw.ini)
static std::vector<std::string> GetListDefaultConfig(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter);
@@ -62,6 +64,8 @@ public:
static std::vector<std::string> GetList(const char* section, const char* setting, const char* defaultValue, size_t bufSize, char delimiter, const char* iniFile);
static int SetConfigInt(const char* section, const char* setting, int value);
static int SetDefaultConfigString(const char* section, const char* setting, const char* value);
};
}
+7 -10
View File
@@ -706,13 +706,12 @@ bool FileSystem::IsEmpty() {
////////////////////////////////////////////////////////////////////////////////
static const DWORD __set_errno_ = 0x4E11F5;
static void __stdcall OpenFail() {
MessageBoxA(0, "Failed to open file.\nToo many open files.", 0, MB_TASKMODAL | MB_ICONERROR);
}
static void __declspec(naked) sopen_hook() {
static const DWORD __set_errno_ = 0x4E11F5;
__asm {
call __set_errno_;
jmp OpenFail;
@@ -720,16 +719,14 @@ static void __declspec(naked) sopen_hook() {
}
#ifndef NDEBUG
long openfiles = 0; // current number of open files
static long openfiles = 0; // current number of open files
void __stdcall OpenLog(const char* file, long id) {
openfiles++;
dlog_f(">> Open %s(%d) [%d]\n", 0, file, id, openfiles);
static void __stdcall OpenLog(const char* file, long id) {
dlog_f(">> Open %s(%d) [%d]\n", 0, file, id, ++openfiles);
}
void __stdcall CloseLog(long id) {
dlog_f("<< Close id:%d [%d]\n", 0, id, openfiles);
openfiles--;
static void __stdcall CloseLog(long id) {
dlog_f("<< Close id:%d [%d]\n", 0, id, openfiles--);
}
static void __declspec(naked) OpenFileLog() {
@@ -769,7 +766,7 @@ void FileSystem::init() {
BlockCall(0x4DEF12);
BlockCall(0x4DEF84);
// Debug message "Failed to open file"
// Error message "Failed to open file"
HookCall(0x4EE0EC, sopen_hook);
// DEV Testing: Check open/close file descriptors
+1 -1
View File
@@ -547,7 +547,7 @@ static void SfallResourceFile() {
void LoadOrder::AddResourcePatches(std::string &dat, std::string &patches) {
if (!dat.empty()) sfPatchFiles.push_back(std::move(dat));
if (!patches.empty()) sfPatchFiles.push_back(std::move(trim(patches)));
if (!patches.empty()) sfPatchFiles.push_back(std::move(patches));
}
void LoadOrder::init() {
+1 -1
View File
@@ -219,7 +219,7 @@ static HMODULE SfallInit() {
WinProc::init();
}
if (!isDebug || IniReader::GetIntDefaultConfig("Debugging", "SkipCompatModeCheck", 0) == 0) {
if (IniReader::GetIntDefaultConfig("Debugging", "SkipCompatModeCheck", 0) == 0) {
int is64bit;
typedef int (__stdcall *chk64bitproc)(HANDLE, int*);
HMODULE h = LoadLibrary("Kernel32.dll");