Skip to content

Commit

Permalink
GetAttachment/GetBonePosition: Restore preserved animtime/frame after…
Browse files Browse the repository at this point in the history
… advancing studio entity
  • Loading branch information
s1lentq committed Aug 27, 2024
1 parent 592ebca commit 8c220a7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion reapi/src/reapi_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,20 @@ void GetBonePosition(CBaseEntity *pEntity, int iBone, Vector *pVecOrigin, Vector
if (iBone < 0 || iBone >= pstudiohdr->numbones)
return; // invalid bone

float flFrame = pEdict->v.frame;
float flAnimTime = pEdict->v.animtime;

// force to update frame
StudioFrameAdvanceEnt(pstudiohdr, pEdict);

pEntity->pev->angles.x = -pEntity->pev->angles.x;
GET_BONE_POSITION(pEdict, iBone, vecOrigin, vecAngles);
pEntity->pev->angles.x = -pEntity->pev->angles.x;

// restore the original state for the entity
pEdict->v.frame = flFrame;
pEdict->v.animtime = flAnimTime;

// ReGameDLL already have fixes angles for non-players entities
if (!g_ReGameApi && !pEntity->IsPlayer()) {
FixupAngles(pEdict, vecOrigin);
Expand Down Expand Up @@ -204,11 +211,18 @@ void GetAttachment(CBaseEntity *pEntity, int iAttachment, Vector *pVecOrigin, Ve
if (iAttachment < 0 || iAttachment >= pstudiohdr->numattachments)
return; // invalid attachment

float flFrame = pEdict->v.frame;
float flAnimTime = pEdict->v.animtime;

// force to update frame
StudioFrameAdvanceEnt(pstudiohdr, pEdict);

GET_ATTACHMENT(pEdict, iAttachment, vecOrigin, vecAngles);

// restore the original state for the entity
pEdict->v.frame = flFrame;
pEdict->v.animtime = flAnimTime;

// ReGameDLL already have fixes angles for non-players entities
if (!g_ReGameApi && !pEntity->IsPlayer()) {
FixupAngles(pEdict, vecOrigin);
Expand Down Expand Up @@ -281,7 +295,7 @@ bool GetSequenceInfo2(CBaseEntity *pEntity, int *piFlags, float *pflFrameRate, f
*pflFrameRate = 256.0f;
*pflGroundSpeed = 0.0f;
}
else
else
{
*pflFrameRate = pseqdesc->fps * 256.0f / (pseqdesc->numframes - 1);
*pflGroundSpeed = Q_sqrt(pseqdesc->linearmovement[0] * pseqdesc->linearmovement[0] + pseqdesc->linearmovement[1] * pseqdesc->linearmovement[1] + pseqdesc->linearmovement[2] * pseqdesc->linearmovement[2]);
Expand Down

0 comments on commit 8c220a7

Please sign in to comment.