Fixed a crash bug in FadeBackgroundMusic

(when trying to mute the master audio volume in the preferences screen)

Minor code edits.
This commit is contained in:
NovaRain
2021-12-10 09:58:22 +08:00
parent 0a42db619d
commit 7553b7bfc0
7 changed files with 33 additions and 15 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ static const DWORD ExpectedSize = 0x00122800;
static const DWORD ExpectedCRC[] = {0xe1680293, 0xef34f989};
static void inline MessageFail(const char* a) {
MessageBoxA(0, a, "Error", MB_TASKMODAL | MB_ICONERROR);
MessageBoxA(0, a, 0, MB_TASKMODAL | MB_ICONERROR);
ExitProcess(1);
}
+2
View File
@@ -58,6 +58,7 @@
#define FO_VAR_currentWindow 0x51DCB8
#define FO_VAR_cursor_line 0x664514
#define FO_VAR_debug_func 0x51DF04
#define FO_VAR_deviceInit 0x668164 // sound
#define FO_VAR_dialog_red_button_down_buf 0x58F4A4
#define FO_VAR_dialog_red_button_down_key 0x58F4BC
#define FO_VAR_dialog_red_button_up_buf 0x58F4AC
@@ -179,6 +180,7 @@
#define FO_VAR_mapEntranceTileNum 0x51955C
#define FO_VAR_master_db_handle 0x58E948
#define FO_VAR_master_volume 0x518E84
#define FO_VAR_masterVol 0x668154
#define FO_VAR_max 0x56FB50 // always equal 100
#define FO_VAR_max_disp 0x56FB40
#define FO_VAR_maxScriptNum 0x51C7CC
+3 -3
View File
@@ -1262,12 +1262,12 @@ void Graphics::init() {
HMODULE h = LoadLibraryEx(_DLL_NAME, 0, LOAD_LIBRARY_AS_DATAFILE);
if (!h) {
MessageBoxA(0, "You have selected DirectX graphics mode, but " _DLL_NAME " is missing.\n"
"Switch back to mode 0, or install an up to date version of DirectX.", "Error", MB_TASKMODAL | MB_ICONERROR);
"Switch back to mode 0, or install an up to date version of DirectX 9.0c.", 0, MB_TASKMODAL | MB_ICONERROR);
#undef _DLL_NAME
ExitProcess(-1);
} else {
FreeLibrary(h);
}
FreeLibrary(h);
SafeWrite8(0x50FB6B, '2'); // Set call DirectDrawCreate2
HookCall(0x44260C, game_init_hook);
+1 -5
View File
@@ -560,10 +560,6 @@ static __declspec(naked) void LostFocus() {
void Movies::init() {
dlog("Applying movie patch.", DL_INIT);
//if (*((DWORD*)0x00518DA0) != 0x00503300) {
// dlog("Error: The value at address 0x001073A0 is not equal to 0x00503300.", DL_INIT);
//}
// Pause and resume movie/sound playback when the game loses focus
fo::func::set_focus_func(LostFocus);
@@ -596,7 +592,7 @@ void Movies::init() {
Graphics::AviMovieWidthFit = (allowDShowMovies >= 2);
MakeJump(0x44E690, gmovie_play_hack);
HookCall(0x44E993, gmovie_play_hook_stop);
/* NOTE: At this address 0x487781, HRP changes the callback procedure to display mve frames. */
/* NOTE: At this address 0x487781 (movieStart_), HRP changes the callback procedure to display mve frames. */
}
}
dlogr(" Done", DL_INIT);
+17
View File
@@ -975,6 +975,19 @@ static void __declspec(naked) sfxl_init_hook() {
}
}
static void __declspec(naked) internalSoundFade_hack() {
__asm {
cmp dword ptr ds:[FO_VAR_masterVol], 0;
je stop;
mov ebp, ds:[FO_VAR_deviceInit];
retn;
stop:
add esp, 4;
mov eax, 0x4AE9AA; // error result
jmp eax;
}
}
constexpr int SampleRate = 44100; // 44.1kHz
void Sound::init() {
@@ -1025,6 +1038,8 @@ void Sound::init() {
HookCall(0x447B68, gdialog_bk_hook);
MakeCall(0x4450C5, gdialogFreeSpeech_hack, 2);
// Prepare
LoadLibraryA("quartz.dll");
CreateSndWnd();
}
@@ -1061,6 +1076,8 @@ void Sound::init() {
SafeMemSet(0x45020C, CodeType::Nop, 6); // gsound_reset_
SafeWrite32(0x45212C, 250); // delay start
SafeWrite32(0x450ADE, 500); // delay stop
MakeCall(0x4AE991, internalSoundFade_hack, 1);
LoadGameHook::OnAfterGameInit() += []() {
fo::var::setInt(FO_VAR_gsound_background_fade) = 1;
};
+5 -4
View File
@@ -139,7 +139,7 @@ void WindowRender::DestroyOverlaySurface(fo::Window* win) {
////////////////////////////////////////////////////////////////////////////////
static double fadeMulti;
static float fadeMulti;
static __declspec(naked) void palette_fade_to_hook() {
__asm {
@@ -153,11 +153,12 @@ static __declspec(naked) void palette_fade_to_hook() {
}
void WindowRender::init() {
fadeMulti = IniReader::GetConfigInt("Graphics", "FadeMultiplier", 100);
if (fadeMulti != 100) {
int multi = IniReader::GetConfigInt("Graphics", "FadeMultiplier", 100);
if (multi != 100) {
dlog("Applying fade patch.", DL_INIT);
HookCall(0x493B16, palette_fade_to_hook);
fadeMulti = ((double)fadeMulti) / 100.0;
if (multi <= 0) multi = 1;
fadeMulti = multi / 100.0f;
dlogr(" Done", DL_INIT);
}
+4 -2
View File
@@ -202,7 +202,7 @@ static void CompatModeCheck(HKEY root, const char* filepath, int extra) {
MessageBoxA(0, "Fallout appears to be running in compatibility mode.\n" //, and sfall was not able to disable it.\n"
"Please check the compatibility tab of fallout2.exe, and ensure that the following settings are unchecked:\n"
"Run this program in compatibility mode for..., run in 256 colours, and run in 640x480 resolution.\n"
"If these options are disabled, click the 'change settings for all users' button and see if that enables them.", "Error", MB_TASKMODAL | MB_ICONERROR);
"If these options are disabled, click the 'change settings for all users' button and see if that enables them.", 0, MB_TASKMODAL | MB_ICONERROR);
ExitProcess(-1);
}
@@ -225,10 +225,12 @@ static void SfallInit() {
if (!CRC(filepath)) return;
LoggingInit();
if (!ddraw.dll) dlog("Error: Cannot load the original ddraw.dll library.\n");
// enabling debugging features
isDebug = (IniReader::GetIntDefaultConfig("Debugging", "Enable", 0) != 0);
if (!ddraw.dll) dlog("Error: Cannot load the original ddraw.dll library.\n");
if (!isDebug || !IniReader::GetIntDefaultConfig("Debugging", "SkipCompatModeCheck", 0)) {
int is64bit;
typedef int (__stdcall *chk64bitproc)(HANDLE, int*);