Skip to content

Commit

Permalink
Fix a bug where sometimes MiddleFrame could be reset
Browse files Browse the repository at this point in the history
  • Loading branch information
ZivDero committed Mar 11, 2025
1 parent f895297 commit e5d735e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
8 changes: 8 additions & 0 deletions src/extensions/anim/animext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@ DECLARE_PATCH(_AnimClass_AI_Beginning_Patch)
animtype = this_ptr->Class;
animtypeext = Extension::Fetch<AnimTypeClassExtension>(animtype);

/**
* We have flagged that this animation's type needs to have
* its biggest frame recalculated, do that.
*/
if (animtype->Biggest == -1) {
animtypeext->Set_Biggest_Frame();
}

/**
* Stolen bytes/code.
*/
Expand Down
11 changes: 5 additions & 6 deletions src/extensions/animtype/animtypeext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ AnimTypeClassExtension::AnimTypeClassExtension(const AnimTypeClass *this_ptr) :
EndAnimsMinimum(),
EndAnimsMaximum(),
EndAnimsDelay(),
MiddleFrame(-2)
MiddleFrame(-1)
{
//if (this_ptr) EXT_DEBUG_TRACE("AnimTypeClassExtension::AnimTypeClassExtension - Name: %s (0x%08X)\n", Name(), (uintptr_t)(This()));

Expand Down Expand Up @@ -402,7 +402,7 @@ bool AnimTypeClassExtension::Read_INI(CCINIClass &ini)
/**
* #issue-883
*
* The "biggest" frame of a animation is frame which should hide all cosmetic
* The "biggest" frame of an animation is frame which should hide all cosmetic
* changes to the underlaying ground (e.g. craters) that the animation causes,
* so these effects are delayed until this frame is reached. TibSun calculates
* this by scanning the entire shape file to find the largest visible frame, but
Expand All @@ -414,7 +414,7 @@ bool AnimTypeClassExtension::Read_INI(CCINIClass &ini)
* of the shape file. This behavior was observed in Red Alert 2.
*/
if (This()->Image && This()->Image->Get_Frame_Count() > 0) {
MiddleFrame = ini.Get_Int_Clamp(ini_name, "MiddleFrame", -2, This()->Image->Get_Frame_Count() - 1, MiddleFrame);
MiddleFrame = ini.Get_Int_Clamp(ini_name, "MiddleFrame", -1, This()->Image->Get_Frame_Count() - 1, MiddleFrame);
}

IsInitialized = true;
Expand All @@ -430,10 +430,9 @@ bool AnimTypeClassExtension::Read_INI(CCINIClass &ini)
*/
void AnimTypeClassExtension::Set_Biggest_Frame()
{
if (MiddleFrame == -1 && This()->Image && This()->Image->Get_Frame_Count() >= 2) {
if (MiddleFrame < 0 && This()->Image && This()->Image->Get_Frame_Count() >= 2) {
This()->Biggest = This()->Image->Get_Frame_Count() / 2;
}
else if (MiddleFrame != -2) {
} else {
This()->Biggest = MiddleFrame;
}
}
Expand Down
24 changes: 10 additions & 14 deletions src/extensions/animtype/animtypeext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,19 @@ DECLARE_PATCH(_AnimTypeClass_Get_Image_Data_Assertion_Patch)


/**
* Sets the biggest frame with our override after Init because it reloads the image.
* Set Biggest to -2 to flag that it needs to be recalculated.
* Ideally, this would be done now, but this is sometimes hit before the extension is
* constructed, and we need it.
*
* @author: ZivDero
*/
DECLARE_PATCH(_AnimTypeClass_Init_MiddleFrame_Patch)
DECLARE_PATCH(_AnimTypeClass_Load_Image_Biggest_Patch)
{
AnimTypeClassExtension::All_Set_Biggest_Frame();

// Reconstruct the epilogue
_asm
{
pop esi
pop ebp
add esp, 0x204
retn
}
GET_REGISTER_STATIC(AnimTypeClass*, this_ptr, esi);

this_ptr->Biggest = -1;

JMP(0x00418B99);
}


Expand All @@ -148,6 +145,5 @@ void AnimTypeClassExtension_Hooks()
Patch_Jump(0x00419B40, &AnimTypeClassExt::_Free_Image);
Patch_Jump(0x004187DB, &_AnimTypeClass_DTOR_Free_Image_Patch);
Patch_Jump(0x00419C0B, &_AnimTypeClass_SDDTOR_Free_Image_Patch);
Patch_Jump(0x004188E6, &_AnimTypeClass_Init_MiddleFrame_Patch);
Patch_Jump(0x004189C9, &_AnimTypeClass_Init_MiddleFrame_Patch);
Patch_Jump(0x00418B15, &_AnimTypeClass_Load_Image_Biggest_Patch);
}

0 comments on commit e5d735e

Please sign in to comment.