Skip to content

Commit

Permalink
Reimplement CBaseAnimating::SequenceDuration
Browse files Browse the repository at this point in the history
Replace sig with Studio_Duration signature
Fetch m_flPoseParameter array member
  • Loading branch information
KitRifty committed Feb 17, 2024
1 parent c36f2fe commit 9e13516
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
10 changes: 6 additions & 4 deletions extension/sourcesdk/baseanimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
FCall<int, CStudioHdr*, const char*> fStudio_LookupSequence;
FCall<int, const CStudioHdr*, const char*> fStudio_FindAttachment;
FCall<int, CStudioHdr*, int, int> fStudio_SelectWeightedSequence;
FCall<float, CStudioHdr*, int, const float*> fStudio_Duration;

int CBaseAnimating::offset_HandleAnimEvent = 0;

VCall<void> CBaseAnimating::vStudioFrameAdvance;
VCall<void, CBaseAnimating*> CBaseAnimating::vDispatchAnimEvents;
VCall< bool, int, matrix3x4_t& > CBaseAnimating::vGetAttachment;
MCall<float, CStudioHdr*, int> CBaseAnimating::mSequenceDuration;
MCall<void, int> CBaseAnimating::mResetSequence;
MCall<int, CStudioHdr*, const char*> CBaseAnimating::mLookupPoseParameter;
MCall<float, int> CBaseAnimating::mGetPoseParameter;
Expand All @@ -25,6 +25,7 @@ DEFINEVAR(CBaseAnimating, m_pStudioHdr);
DEFINEVAR(CBaseAnimating, m_OnIgnite);
DEFINEVAR(CBaseAnimating, m_nSequence);
DEFINEVAR(CBaseAnimating, m_flModelScale);
DEFINEVAR(CBaseAnimating, m_flPoseParameter);

bool CBaseAnimating::Init(SourceMod::IGameConfig* config, char* error, size_t maxlength)
{
Expand All @@ -33,8 +34,8 @@ bool CBaseAnimating::Init(SourceMod::IGameConfig* config, char* error, size_t ma
fStudio_LookupSequence.Init(config, "Studio_LookupSequence");
fStudio_FindAttachment.Init(config, "Studio_FindAttachment");
fStudio_SelectWeightedSequence.Init(config, "Studio_SelectWeightedSequence");
fStudio_Duration.Init(config, "Studio_Duration");

mSequenceDuration.Init(config, "CBaseAnimating::SequenceDuration");
mResetSequence.Init(config, "CBaseAnimating::ResetSequence");
mLookupPoseParameter.Init(config, "CBaseAnimating::LookupPoseParameter");
mSetPoseParameter.Init(config, "CBaseAnimating::SetPoseParameter");
Expand Down Expand Up @@ -64,6 +65,7 @@ bool CBaseAnimating::Init(SourceMod::IGameConfig* config, char* error, size_t ma
OFFSETVAR_SEND(CBaseAnimating, m_flModelScale);
// m_pStudioHdr is in front of m_OnIgnite
VAR_OFFSET_SET(m_pStudioHdr, VAR_OFFSET(m_OnIgnite) + sizeof(COutputEvent));
OFFSETVAR_SEND(CBaseAnimating, m_flPoseParameter);
END_VAR;

void* aVal = nullptr;
Expand Down Expand Up @@ -135,9 +137,9 @@ float CBaseAnimating::GetPoseParameter(const char* name)
return GetPoseParameter(LookupPoseParameter(name));
}

float CBaseAnimating::SequenceDuration(CStudioHdr* studio, int sequence)
float CBaseAnimating::SequenceDuration(CStudioHdr* pStudioHdr, int iSequence)
{
return mSequenceDuration(this, studio, sequence);
return fStudio_Duration(pStudioHdr, iSequence, GetPoseParameterArray());
}

void CBaseAnimating::ResetSequence(int sequence)
Expand Down
4 changes: 3 additions & 1 deletion extension/sourcesdk/baseanimating.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class CBaseAnimating : public CBaseEntity

float GetPoseParameter(const char* name);

const float* GetPoseParameterArray() { return m_flPoseParameter(); }

static int offset_HandleAnimEvent;

static VCall<void> vStudioFrameAdvance;
Expand All @@ -42,7 +44,6 @@ class CBaseAnimating : public CBaseEntity
static VCall<void, CBaseAnimating*> vDispatchAnimEvents;
void DispatchAnimEvents(CBaseAnimating*);

static MCall<float, CStudioHdr*, int> mSequenceDuration;
float SequenceDuration(CStudioHdr*, int);

static MCall<void, int> mResetSequence;
Expand All @@ -67,6 +68,7 @@ class CBaseAnimating : public CBaseEntity
DECLAREVAR(CStudioHdr*, m_pStudioHdr);
DECLAREVAR(int, m_nSequence);
DECLAREVAR(float, m_flModelScale);
DECLAREVAR(float, m_flPoseParameter);
};

inline float CBaseAnimating::GetModelScale() const
Expand Down
24 changes: 10 additions & 14 deletions gamedata/cbasenpc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@
"linux" "@_Z21Studio_FindAttachmentPK10CStudioHdrPKc"
"linux64" "@_Z21Studio_FindAttachmentPK10CStudioHdrPKc"
}
// Look up data xrefs to string "CBaseAnimating::SequenceDuration( %d ) NULL pstudiohdr on %s!\n"
// Find call that takes 3 parameters
"Studio_Duration"
{
"library" "server"
"windows" "\x55\x8B\xEC\xFF\x75\x2A\x8B\x4D\x2A\xE8\x2A\x2A\x2A\x2A\xFF\x75"
"windows64" "\x48\x89\x5C\x24\x2A\x48\x89\x74\x24\x2A\x57\x48\x83\xEC\x20\x49\x8B\xD8\x8B\xFA"
"linux" "@_Z15Studio_DurationPK10CStudioHdriPKf"
"linux64" "@_Z15Studio_DurationPK10CStudioHdriPKf"
}
// Bytes sequence search "00 00 C0 00", go to the only subroutine that uses that number with 'and' & 'cmp'
"SimThink_EntityChanged"
{
Expand Down Expand Up @@ -433,20 +443,6 @@
"linux" "@_ZN14CBaseAnimating19LookupPoseParameterEP10CStudioHdrPKc"
"linux64" "@_ZN14CBaseAnimating19LookupPoseParameterEP10CStudioHdrPKc"
}
// Look up data xrefs to string "CBaseAnimating::SequenceDuration( %d ) NULL pstudiohdr on %s!\n"
// One of them is CBaseAnimating::GetSequenceCycleRate, is referenced by CBaseAnimating::DispatchAnimEvents
// One of them is CBaseAnimating::GetSequenceGroundSpeed, it's a virtual function
// One of them is CBaseAnimating::ScriptGetSequenceDuration, has xref to a VScript init function which has a xref to string "GetAttachmentBone"
// One of them divides the final result
// The last xref left should be CBaseAnimating::SequenceDuration
"CBaseAnimating::SequenceDuration"
{
"library" "server"
"windows" "\x55\x8B\xEC\x56\x8B\x75\x08\x57\x8B\xF9\x85\xF6\x75\x2A\x8B\x47\x5C"
"windows64" "\x48\x89\x5C\x24\x2A\x48\x89\x74\x24\x2A\x57\x48\x83\xEC\x20\x41\x8B\xD8\x48\x8B\xFA\x48\x8B\xF1\x48\x85\xD2\x75\x2A\x48\x8B\x81\x2A\x2A\x2A\x2A\x4C\x8D\x0D\x2A\x2A\x2A\x2A\x48\x85\xC0\x48\x8D\x15\x2A\x2A\x2A\x2A\x8D\x4F\x2A\x4C\x0F\x45\xC8\xFF\x15\x2A\x2A\x2A\x2A\xEB\x2A\x48\x8B\xCF\xE8\x2A\x2A\x2A\x2A\x84\xC0\x74\x2A\x48\x8B\xCF\xE8\x2A\x2A\x2A\x2A\x3B\xD8\x7D\x2A\x85\xDB\x78\x2A\x4C\x8D\x86\x2A\x2A\x2A\x2A\x8B\xD3\x48\x8B\xCF\x48\x8B\x5C\x24"
"linux" "@_ZN14CBaseAnimating16SequenceDurationEP10CStudioHdri"
"linux64" "@_ZN14CBaseAnimating16SequenceDurationEP10CStudioHdri"
}
// Go to data xref of string "ResetSequence : %s: %s -> %s\n"
"CBaseAnimating::ResetSequence"
{
Expand Down

0 comments on commit 9e13516

Please sign in to comment.