diff --git a/sfall/Animations.cpp b/sfall/Animations.cpp index 3891fd03..4983e912 100644 --- a/sfall/Animations.cpp +++ b/sfall/Animations.cpp @@ -163,7 +163,7 @@ static const DWORD sad_28[] = { //////////////////////////////////////////////////////////////////////////////// -long regSlot = -2; +static long appendSlot = -2; /* When the check_registry_ function finds an object for which a new animation @@ -203,10 +203,8 @@ static long __fastcall CopyRegistry(long checkSlot) { // copy the animations of the registered slot to the slot with the existing animations for (long i = 0; i < currRegAnims; i++) { - devlog_f("\n Copy slot: animSet[%d].anim[%d] >> animSet[%d].anim[%d]", 0, currRegSlot, i, checkSlot, lastAnim); + devlog_f("\n copy slot: animSet[%d].anim[%d] >> animSet[%d].anim[%d]", 0, currRegSlot, i, checkSlot, lastAnim); animSet[checkSlot].animations[lastAnim++] = animSet[currRegSlot].animations[i]; - - //std::memset(&animSet[currRegSlot].animations[i], -1, 48); } animSet[checkSlot].flags |= animSet[currRegSlot].flags | e_Append | e_Suspend; // set flags animSet[currRegSlot].flags = 0; @@ -214,7 +212,7 @@ static long __fastcall CopyRegistry(long checkSlot) { *ptr_curr_anim_counter = totalRegAnims; // set the current number of registered animations in the slot *ptr_curr_anim_set = checkSlot; // replace the currently registered slot with a slot with existing registered animations - regSlot = checkSlot; + appendSlot = checkSlot; return lastAnim; } @@ -242,6 +240,7 @@ skip: } } +// sets the counter to the index of the anim_# slot with the added animation static long __fastcall anim_cleanup_sub(long currAnims) { //long currAnims = *ptr_curr_anim_counter; AnimationSet* set = &animSet[*ptr_curr_anim_set]; @@ -271,7 +270,7 @@ static long __fastcall LockAnimSlot(long slot) { return slot; } -static long __fastcall UnlockAnimSlot(long slot) { +static long __fastcall UnlockAnimSlot() { long lockCount = 0; for (std::vector::iterator it = lockAnimSet.begin(); it != lockAnimSet.end(); ++it) { if (*it > 0) { @@ -279,10 +278,7 @@ static long __fastcall UnlockAnimSlot(long slot) { lockCount++; } } - if (lockCount > lockLimit) fo_debug_printf("\n[SFALL] Warning: The number of animated slots in the lock is too large, locked %d of %d", lockCount, animationLimit); - - //if (slot) slot /= sizeof(AnimationSet); - //lockAnimSet[slot] = 0; + if (lockCount >= lockLimit) fo_debug_printf("\n[SFALL] Warning: The number of animated slots in the lock is too large, locked %d of %d", lockCount, animationLimit); return 0; } @@ -290,41 +286,61 @@ static BYTE __fastcall CheckLockAnimSlot(long, long slot) { return lockAnimSet[slot]; } -#ifndef NDEBUG -static void CheckReg() { - long s = regSlot; - regSlot = -2; - if (s != *ptr_curr_anim_set) return; +static void __fastcall CheckAppendReg(long, long totalAnims) { + long slot = appendSlot; + appendSlot = -2; + if (slot != *ptr_curr_anim_set) return; - dlog_f("\nregister_end: anim_set: %d, total_anim: %d", 0, *ptr_curr_anim_set, *ptr_curr_anim_counter); - for (long i = 0; i < *ptr_curr_anim_counter; i++) { - dlog_f("\n anim[%d]: animType:%d, animCode:%d, source:%d (%s), callFunc:%d, callFunc3:%d", 0, i, - animSet[s].animations[i].animType, animSet[s].animations[i].animCode, - animSet[s].animations[i].source, fo_critter_name(animSet[s].animations[i].source), - animSet[s].animations[i].callFunc, animSet[s].animations[i].callFunc3 + //long totalAnims = *ptr_curr_anim_counter; + AnimationSet* set = &animSet[slot]; + + #ifndef NDEBUG + devlog_f("\nregister_end: anim_set: %d, total_anim: %d", 0, slot, totalAnims); + for (long i = 0; i < totalAnims; i++) { + devlog_f("\n anim[%d]: animType:%d, animCode:%d, source:%x (%s), callFunc:%x, callFunc3:%x", 0, i, + set->animations[i].animType, set->animations[i].animCode, + set->animations[i].source, fo_critter_name(set->animations[i].source), + set->animations[i].callFunc, set->animations[i].callFunc3 ); } + #endif + + for (long i = set->totalAnimCount; i < totalAnims; i++) { + if (set->animations[i].animType < 4) { + for (long i = set->totalAnimCount; i < totalAnims; i++) { + // cleanup + long frm = set->animations[i].frmPtr; + if (frm) fo_art_ptr_unlock(frm); + // anim Must_Call + if (set->animations[i].animType == 11 && (DWORD)set->animations[i].callFunc == (DWORD)gsnd_anim_sound_) { + long sfx = (long)set->animations[i].target; + __asm { + mov eax, sfx; + call gsound_delete_sfx_; + } + } + } + return; // exit, do not set the total number of animations in the slot (the value remains the same) + } + } + set->totalAnimCount = totalAnims; } -#endif static void __declspec(naked) register_end_hack_begin() { __asm { - #ifndef NDEBUG - pushadc; - call CheckReg; - popadc; - #endif mov edx, ds:[FO_VAR_curr_anim_counter]; mov esi, animSet; and [esi][eax][0xC], ~e_InUse; // animSet[].flags (unset inUse flag) test word ptr [esi][eax][0xC], e_Append; // animSet[].flags - jnz isAppend; // is set + jnz isAppend; // slot with added animation retn; isAppend: - mov [esi][eax][0x8], edx; // animSet[].totalAnimCount + mov esi, eax; // keep offset to anim_set slot + call CheckAppendReg; + xor ecx, ecx; add esp, 4; mov edx, 0x413D14; - mov esi, eax; // keep offset to anim_set slot + mov eax, esi; jmp edx; } } @@ -332,13 +348,10 @@ isAppend: static void __declspec(naked) register_end_hack_end() { __asm { mov eax, animSet; - mov dx, [eax][esi][0xC]; // animSet[].flags - test dx, e_Append; // slot with added animation? + test word ptr [eax][esi][0xC], e_Append; // slot with added animation? jz skip; - and dx, ~(e_Append | e_Suspend); // unset flags + and word ptr [eax][esi][0xC], ~(e_Append | e_Suspend); // animSet[].flags (unset flags) skip: - mov [eax][esi][0xC], dx; // animSet[].flags - //mov ecx, esi; call UnlockAnimSlot; pop esi; pop edx; @@ -384,11 +397,9 @@ static void __declspec(naked) anim_stop_hack() { } //////////////////////////////////////////////////////////////////////////////// - #ifndef NDEBUG static void __fastcall ClearDataAnimations(long slot) { std::memset(animSet[slot].animations, 0, sizeof(AnimationSet) - 16); - //dlog_f("\nanim_set_end: clear all animations data in slot %d", 0, slot); } #endif @@ -526,9 +537,7 @@ void Animations_Init() { animationLimit = GetConfigInt("Misc", "AnimationsAtOnceLimit", 32); if (animationLimit < 32) animationLimit = 32; if (animationLimit > 32) { - if (animationLimit > 127) { - animationLimit = 127; - } + if (animationLimit > 127) animationLimit = 127; dlog("Applying AnimationsAtOnceLimit patch.", DL_INIT); ApplyAnimationsAtOncePatches(animationLimit); dlogr(" Done", DL_INIT); @@ -550,7 +559,7 @@ void Animations_Init() { MakeCall(0x4186CF, anim_stop_hack); lockAnimSet.resize(animationLimit); - lockLimit = animationLimit / 4; + lockLimit = animationLimit / 2; // Fix for calling anim() functions in combat MakeCall(0x415DE2, anim_set_end_hack, 1); diff --git a/sfall/FalloutFuncOffs_def.h b/sfall/FalloutFuncOffs_def.h index a08f0e58..4aca382b 100644 --- a/sfall/FalloutFuncOffs_def.h +++ b/sfall/FalloutFuncOffs_def.h @@ -244,12 +244,14 @@ FUNC(gmouse_is_scrolling_, 0x44B54C) FUNC(gmouse_set_cursor_, 0x44C840) FUNC(gmovieIsPlaying_, 0x44EB14) FUNC(gmovie_play_, 0x44E690) +FUNC(gsnd_anim_sound_, 0x4514F0) FUNC(gsnd_build_weapon_sfx_name_, 0x451760) FUNC(gsound_background_pause_, 0x450B50) FUNC(gsound_background_restart_last_, 0x450B0C) FUNC(gsound_background_stop_, 0x450AB4) FUNC(gsound_background_unpause_, 0x450B64) FUNC(gsound_background_volume_get_set_, 0x450620) +FUNC(gsound_delete_sfx_, 0x45148C) FUNC(gsound_play_sfx_file_, 0x4519A8) FUNC(gsound_red_butt_press_, 0x451970) FUNC(gsound_red_butt_release_, 0x451978) diff --git a/sfall/InputFuncs.cpp b/sfall/InputFuncs.cpp index 68009b6b..e3f56ded 100644 --- a/sfall/InputFuncs.cpp +++ b/sfall/InputFuncs.cpp @@ -296,7 +296,7 @@ public: KeyPressHook(&dxKey, (state > 0), MapVirtualKeyEx(dxKey, MAPVK_VSC_TO_VK, keyboardLayout)); - if ((signed)dxKey > 0 && dxKey != buf[i].dwOfs) { + if ((long)dxKey > 0 && dxKey != buf[i].dwOfs) { keysDown[buf[i].dwOfs] = oldState; buf[i].dwOfs = dxKey; // Override key keysDown[buf[i].dwOfs] = state; diff --git a/sfall/main.cpp b/sfall/main.cpp index 719c4af6..1494b96e 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -342,7 +342,7 @@ bool __stdcall DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { isDebug = (GetIntDefaultConfig("Debugging", "Enable", 0) != 0); if (isDebug) { LoggingInit(); - if (!ddraw.dll) dlog("Error: Cannot load the original ddraw.dll library.\n", DL_MAIN); + if (!ddraw.dll) dlogr("Error: Cannot load the original ddraw.dll library.", DL_MAIN); } HookCall(0x4DE7D2, &OnExitFunc);