diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index 3c8b7b8a..55e84b26 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -278,11 +278,11 @@ if (get_flags(obj2) bwand FLAG_MULTIHEX) then distance-- -/* sfall metalure3 function macros */ -#define SET_HORRIGAN_ENCOUNTER (200) - +/* sfall metarule3 function macros */ // sets the number of days (range 1...127) for the Frank Horrigan encounter, or disable the encounter if days is set to 0 -#define set_horrigan_days(day) metarule3(SET_HORRIGAN_ENCOUNTER, day, 0, 0) +#define set_horrigan_days(day) metarule3(200, day, 0, 0) +// clears the keyboard input buffer, use it in the HOOK_KEYPRESS hook to clear keyboard events before calling script functions that accept key input +#define clear_keyboard_buffer metarule3(201, 0, 0, 0) /* sfall_funcX macros */ diff --git a/sfall/Modules/MetaruleExtender.cpp b/sfall/Modules/MetaruleExtender.cpp index 78b081c9..006cb16e 100644 --- a/sfall/Modules/MetaruleExtender.cpp +++ b/sfall/Modules/MetaruleExtender.cpp @@ -34,6 +34,7 @@ static bool HorriganEncounterDisabled = false; enum class MetaruleFunction : long { SET_HORRIGAN_ENCOUNTER = 200, // sets the number of days for the Frank Horrigan encounter or disable encounter + CLEAR_KEYBOARD_BUFFER = 201, // clears the keyboard input buffer, should be used in the HOOK_KEYPRESS hook to clear keyboard events in some cases }; /* @@ -57,6 +58,9 @@ static long __fastcall op_metarule3_ext(long metafunc, long* args) { } break; } + case MetaruleFunction::CLEAR_KEYBOARD_BUFFER: + __asm call fo::funcoffs::kb_clear_; + break; default: fo::func::debug_printf("\nOPCODE ERROR: metarule3(%d, ...) - metarule function number does not exist.\n > Script: %s, procedure %s.", metafunc, fo::var::currentProgram->fileName, fo::func::findCurrentProc(fo::var::currentProgram)); diff --git a/sfall/Modules/Movies.cpp b/sfall/Modules/Movies.cpp index e78c4c58..dd89770f 100644 --- a/sfall/Modules/Movies.cpp +++ b/sfall/Modules/Movies.cpp @@ -107,7 +107,9 @@ private: //} if (d3d9Device->CreateTexture(lpAllocInfo->dwWidth, lpAllocInfo->dwHeight, 1, 0, lpAllocInfo->Format, D3DPOOL_DEFAULT, &mTex, nullptr) != D3D_OK) { - dlog(" Failed to create movie texture!", DL_INIT); + dlogr(" Failed to create movie texture!", DL_INIT); + } else { + dlogr(" OK!", DL_INIT); } return S_OK; } @@ -470,6 +472,8 @@ skip: /////////////////////////////////////////////////////////////////////////////// +#define DEFAULT_MOVIES 17 // max vanilla movies + char MoviePaths[MaxMovies * 65]; static DWORD Artimer1DaysCheckTimer; @@ -485,6 +489,25 @@ less: } } +static void __declspec(naked) gmovie_play_hack_subpal() { + __asm { + xor eax, eax; + lea edx, [ebp * 4]; + cmp ebp, DEFAULT_MOVIES; + cmovb eax, edx; + retn; + } +} + +static void __declspec(naked) op_play_gmovie_hack() { + __asm { + mov edx, 0xB; // default play mode flags + cmp ecx, DEFAULT_MOVIES; + cmovb edx, eax; + retn; + } +} + void SkipOpeningMoviesPatch() { int skipOpening = GetConfigInt("Misc", "SkipOpeningMovies", 0); if (skipOpening) { @@ -509,7 +532,7 @@ void Movies::init() { MoviePaths[index + 64] = '\0'; _itoa_s(i + 1, &optName[5], 3, 10); - if (i < 17) { + if (i < DEFAULT_MOVIES) { GetConfigString("Misc", optName, fo::var::movie_list[i], &MoviePaths[index], 65); } else { GetConfigString("Misc", optName, "", &MoviePaths[index], 65); @@ -517,6 +540,8 @@ void Movies::init() { } dlog(".", DL_INIT); SafeWriteBatch((DWORD)MoviePtrs, {0x44E6AE, 0x44E721, 0x44E75E, 0x44E78A}); // gmovie_play_ + MakeCall(0x44E896, gmovie_play_hack_subpal, 2); + MakeCall(0x45A1C9, op_play_gmovie_hack); dlog(".", DL_INIT); /* diff --git a/sfall/Modules/Movies.h b/sfall/Modules/Movies.h index 94c30dc6..a6d002dd 100644 --- a/sfall/Modules/Movies.h +++ b/sfall/Modules/Movies.h @@ -30,7 +30,7 @@ public: void exit() override; }; -static const int MaxMovies = 32; +static constexpr int MaxMovies = 32; extern char MoviePaths[MaxMovies * 65]; } diff --git a/sfall/Modules/Sound.cpp b/sfall/Modules/Sound.cpp index 4f7ce746..a30e9ab9 100644 --- a/sfall/Modules/Sound.cpp +++ b/sfall/Modules/Sound.cpp @@ -336,6 +336,7 @@ static const wchar_t *SoundExtensions[] = { L"wav", L"mp3", L"wma" }; /* TODO: For sfx sounds in wav format, playback must be performed using the game functions (DirectSound) because there is a small delay (~50-100ms) when using DirectShow + sfx - environment effects must set their volume relative to the location from the player (see gsound_compute_relative_volume_) */ static bool __fastcall SoundFileLoad(PlayType playType, const char* path) { if (!path) return false;