diff options
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/AnimBlendAssocGroup.cpp | 29 | ||||
-rw-r--r-- | src/animation/AnimBlendAssociation.cpp | 36 | ||||
-rw-r--r-- | src/animation/AnimBlendClumpData.cpp | 19 | ||||
-rw-r--r-- | src/animation/AnimBlendClumpData.h | 4 | ||||
-rw-r--r-- | src/animation/AnimBlendHierarchy.cpp | 14 | ||||
-rw-r--r-- | src/animation/AnimBlendNode.cpp | 12 | ||||
-rw-r--r-- | src/animation/AnimBlendSequence.cpp | 8 | ||||
-rw-r--r-- | src/animation/AnimManager.cpp | 40 | ||||
-rw-r--r-- | src/animation/AnimManager.h | 192 | ||||
-rw-r--r-- | src/animation/AnimationId.h | 180 | ||||
-rw-r--r-- | src/animation/Bones.cpp | 52 | ||||
-rw-r--r-- | src/animation/Bones.h | 24 | ||||
-rw-r--r-- | src/animation/CutsceneMgr.cpp | 47 | ||||
-rw-r--r-- | src/animation/CutsceneMgr.h | 27 | ||||
-rw-r--r-- | src/animation/FrameUpdate.cpp | 251 | ||||
-rw-r--r-- | src/animation/RpAnimBlend.cpp | 141 | ||||
-rw-r--r-- | src/animation/RpAnimBlend.h | 9 |
17 files changed, 655 insertions, 430 deletions
diff --git a/src/animation/AnimBlendAssocGroup.cpp b/src/animation/AnimBlendAssocGroup.cpp index ecdebd29..bdcca2f8 100644 --- a/src/animation/AnimBlendAssocGroup.cpp +++ b/src/animation/AnimBlendAssocGroup.cpp @@ -1,5 +1,7 @@ #include "common.h" -#include "patcher.h" + +#include "ctype.h" + #include "General.h" #include "ModelInfo.h" #include "AnimManager.h" @@ -75,12 +77,21 @@ strcmpIgnoringDigits(const char *s1, const char *s2) c2 = *s2; if(c1) s1++; if(c2) s2++; - if(c1 == '\0' && c2 == '\0') - return true; + if(c1 == '\0' && c2 == '\0') return true; +#if defined _WIN32 && !defined __MINGW32__ if(__ascii_iswdigit(c1) && __ascii_iswdigit(c2)) +#else + if(iswdigit(c1) && iswdigit(c2)) +#endif continue; +#if defined _WIN32 && !defined __MINGW32__ c1 = __ascii_toupper(c1); c2 = __ascii_toupper(c2); +#else + c1 = toupper(c1); + c2 = toupper(c2); +#endif + if(c1 != c2) return false; } @@ -148,15 +159,3 @@ CAnimBlendAssocGroup::CreateAssociations(const char *blockName, RpClump *clump, } numAssociations = numAssocs; } - - - -STARTPATCHES - InjectHook(0x4012D0, &CAnimBlendAssocGroup::DestroyAssociations, PATCH_JUMP); - InjectHook(0x4013D0, (CAnimBlendAssociation *(CAnimBlendAssocGroup::*)(uint32))&CAnimBlendAssocGroup::GetAnimation, PATCH_JUMP); - InjectHook(0x401300, (CAnimBlendAssociation *(CAnimBlendAssocGroup::*)(const char*))&CAnimBlendAssocGroup::GetAnimation, PATCH_JUMP); - InjectHook(0x401420, (CAnimBlendAssociation *(CAnimBlendAssocGroup::*)(uint32))&CAnimBlendAssocGroup::CopyAnimation, PATCH_JUMP); - InjectHook(0x4013E0, (CAnimBlendAssociation *(CAnimBlendAssocGroup::*)(const char*))&CAnimBlendAssocGroup::CopyAnimation, PATCH_JUMP); - InjectHook(0x401130, (void (CAnimBlendAssocGroup::*)(const char*))&CAnimBlendAssocGroup::CreateAssociations, PATCH_JUMP); - InjectHook(0x401220, (void (CAnimBlendAssocGroup::*)(const char*, RpClump*, const char**, int))&CAnimBlendAssocGroup::CreateAssociations, PATCH_JUMP); -ENDPATCHES diff --git a/src/animation/AnimBlendAssociation.cpp b/src/animation/AnimBlendAssociation.cpp index 246322ba..daca7d68 100644 --- a/src/animation/AnimBlendAssociation.cpp +++ b/src/animation/AnimBlendAssociation.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "AnimBlendHierarchy.h" #include "AnimBlendClumpData.h" #include "RpAnimBlend.h" @@ -185,7 +185,7 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount <= 0.0f && blendDelta < 0.0f){ // We're faded out and are not fading in blendAmount = 0.0f; - blendDelta = max(0.0f, blendDelta); + blendDelta = Max(0.0f, blendDelta); if(flags & ASSOC_DELETEFADEDOUT){ if(callbackType == CB_FINISH || callbackType == CB_DELETE) callback(this, callbackArg); @@ -197,38 +197,8 @@ CAnimBlendAssociation::UpdateBlend(float timeDelta) if(blendAmount > 1.0f){ // Maximally faded in, clamp values blendAmount = 1.0f; - blendDelta = min(0.0f, blendDelta); + blendDelta = Min(0.0f, blendDelta); } return true; } - -#include <new> - -class CAnimBlendAssociation_ : public CAnimBlendAssociation -{ -public: - CAnimBlendAssociation *ctor1(void) { return ::new (this) CAnimBlendAssociation(); } - CAnimBlendAssociation *ctor2(CAnimBlendAssociation &other) { return ::new (this) CAnimBlendAssociation(other); } - void dtor(void) { this->CAnimBlendAssociation::~CAnimBlendAssociation(); } -}; - -STARTPATCHES - InjectHook(0x4016A0, &CAnimBlendAssociation::AllocateAnimBlendNodeArray, PATCH_JUMP); - InjectHook(0x4016F0, &CAnimBlendAssociation::FreeAnimBlendNodeArray, PATCH_JUMP); - InjectHook(0x4017B0, &CAnimBlendAssociation::GetNode, PATCH_JUMP); - InjectHook(0x401560, (void (CAnimBlendAssociation::*)(RpClump*, CAnimBlendHierarchy*))&CAnimBlendAssociation::Init, PATCH_JUMP); - InjectHook(0x401620, (void (CAnimBlendAssociation::*)(CAnimBlendAssociation&))&CAnimBlendAssociation::Init, PATCH_JUMP); - InjectHook(0x4017E0, &CAnimBlendAssociation::SetBlend, PATCH_JUMP); - InjectHook(0x401820, &CAnimBlendAssociation::SetFinishCallback, PATCH_JUMP); - InjectHook(0x401800, &CAnimBlendAssociation::SetDeleteCallback, PATCH_JUMP); - InjectHook(0x401700, &CAnimBlendAssociation::SetCurrentTime, PATCH_JUMP); - InjectHook(0x401780, &CAnimBlendAssociation::SyncAnimation, PATCH_JUMP); - InjectHook(0x4017D0, &CAnimBlendAssociation::Start, PATCH_JUMP); - InjectHook(0x4031F0, &CAnimBlendAssociation::UpdateTime, PATCH_JUMP); - InjectHook(0x4032B0, &CAnimBlendAssociation::UpdateBlend, PATCH_JUMP); - - InjectHook(0x401460, &CAnimBlendAssociation_::ctor1, PATCH_JUMP); - InjectHook(0x4014C0, &CAnimBlendAssociation_::ctor2, PATCH_JUMP); - InjectHook(0x401520, &CAnimBlendAssociation_::dtor, PATCH_JUMP); -ENDPATCHES diff --git a/src/animation/AnimBlendClumpData.cpp b/src/animation/AnimBlendClumpData.cpp index cc4281d6..d40e8357 100644 --- a/src/animation/AnimBlendClumpData.cpp +++ b/src/animation/AnimBlendClumpData.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "AnimBlendClumpData.h" #include "RwHelper.h" @@ -35,20 +35,3 @@ CAnimBlendClumpData::ForAllFrames(void (*cb)(AnimBlendFrameData*, void*), void * for(i = 0; i < numFrames; i++) cb(&frames[i], arg); } - -#include <new> - -class CAnimBlendClumpData_ : public CAnimBlendClumpData -{ -public: - CAnimBlendClumpData *ctor(void) { return ::new (this) CAnimBlendClumpData(); } - void dtor(void) { this->CAnimBlendClumpData::~CAnimBlendClumpData(); } -}; - - -STARTPATCHES - InjectHook(0x401880, &CAnimBlendClumpData_::ctor, PATCH_JUMP); - InjectHook(0x4018B0, &CAnimBlendClumpData_::dtor, PATCH_JUMP); - InjectHook(0x4018F0, &CAnimBlendClumpData::SetNumberOfFrames, PATCH_JUMP); - InjectHook(0x401930, &CAnimBlendClumpData::ForAllFrames, PATCH_JUMP); -ENDPATCHES diff --git a/src/animation/AnimBlendClumpData.h b/src/animation/AnimBlendClumpData.h index 1c8c391d..a537425a 100644 --- a/src/animation/AnimBlendClumpData.h +++ b/src/animation/AnimBlendClumpData.h @@ -18,7 +18,7 @@ struct AnimBlendFrameData #ifdef PED_SKIN union { RwFrame *frame; - RpHAnimStdKeyFrame *hanimframe; + RpHAnimStdKeyFrame *hanimFrame; }; int32 nodeID; #else @@ -50,4 +50,6 @@ public: #endif void ForAllFrames(void (*cb)(AnimBlendFrameData*, void*), void *arg); }; +#ifndef PED_SKIN static_assert(sizeof(CAnimBlendClumpData) == 0x14, "CAnimBlendClumpData: error"); +#endif diff --git a/src/animation/AnimBlendHierarchy.cpp b/src/animation/AnimBlendHierarchy.cpp index e4bcdc69..feeaca3d 100644 --- a/src/animation/AnimBlendHierarchy.cpp +++ b/src/animation/AnimBlendHierarchy.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "AnimBlendSequence.h" #include "AnimBlendHierarchy.h" @@ -36,7 +36,7 @@ CAnimBlendHierarchy::CalcTotalTime(void) float seqTime = 0.0f; for(j = 0; j < sequences[i].numFrames; j++) seqTime += sequences[i].GetKeyFrame(j)->deltaTime; - totalTime = max(totalTime, seqTime); + totalTime = Max(totalTime, seqTime); } totalLength = totalTime; } @@ -72,13 +72,3 @@ CAnimBlendHierarchy::RemoveUncompressedData(void) // useless compressed = 1; } - -STARTPATCHES - InjectHook(0x4019A0, &CAnimBlendHierarchy::Shutdown, PATCH_JUMP); - InjectHook(0x4019C0, &CAnimBlendHierarchy::SetName, PATCH_JUMP); - InjectHook(0x4019E0, &CAnimBlendHierarchy::CalcTotalTime, PATCH_JUMP); - InjectHook(0x401A80, &CAnimBlendHierarchy::RemoveQuaternionFlips, PATCH_JUMP); - InjectHook(0x401AB0, &CAnimBlendHierarchy::RemoveAnimSequences, PATCH_JUMP); - InjectHook(0x401AD0, &CAnimBlendHierarchy::Uncompress, PATCH_JUMP); - InjectHook(0x401B00, &CAnimBlendHierarchy::RemoveUncompressedData, PATCH_JUMP); -ENDPATCHES diff --git a/src/animation/AnimBlendNode.cpp b/src/animation/AnimBlendNode.cpp index be5fcc9c..193e9176 100644 --- a/src/animation/AnimBlendNode.cpp +++ b/src/animation/AnimBlendNode.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "AnimBlendAssociation.h" #include "AnimBlendNode.h" @@ -158,13 +158,3 @@ CAnimBlendNode::GetEndTranslation(CVector &trans, float weight) trans = kf->translation * blend; } } - -STARTPATCHES - InjectHook(0x401B10, &CAnimBlendNode::Init, PATCH_JUMP); - InjectHook(0x401B30, &CAnimBlendNode::Update, PATCH_JUMP); - InjectHook(0x401DC0, &CAnimBlendNode::NextKeyFrame, PATCH_JUMP); - InjectHook(0x4021B0, &CAnimBlendNode::FindKeyFrame, PATCH_JUMP); - InjectHook(0x401E70, &CAnimBlendNode::CalcDeltas, PATCH_JUMP); - InjectHook(0x401FE0, &CAnimBlendNode::GetCurrentTranslation, PATCH_JUMP); - InjectHook(0x402110, &CAnimBlendNode::GetEndTranslation, PATCH_JUMP); -ENDPATCHES diff --git a/src/animation/AnimBlendSequence.cpp b/src/animation/AnimBlendSequence.cpp index 4b675774..4578ec50 100644 --- a/src/animation/AnimBlendSequence.cpp +++ b/src/animation/AnimBlendSequence.cpp @@ -1,5 +1,5 @@ #include "common.h" -#include "patcher.h" + #include "AnimBlendSequence.h" CAnimBlendSequence::CAnimBlendSequence(void) @@ -60,9 +60,3 @@ CAnimBlendSequence::RemoveQuaternionFlips(void) last = frame->rotation; } } - -STARTPATCHES - InjectHook(0x402330, &CAnimBlendSequence::SetName, PATCH_JUMP); - InjectHook(0x402350, &CAnimBlendSequence::SetNumFrames, PATCH_JUMP); - InjectHook(0x4023A0, &CAnimBlendSequence::RemoveQuaternionFlips, PATCH_JUMP); -ENDPATCHES diff --git a/src/animation/AnimManager.cpp b/src/animation/AnimManager.cpp index e5721bdf..ebd2e1fb 100644 --- a/src/animation/AnimManager.cpp +++ b/src/animation/AnimManager.cpp @@ -1,6 +1,7 @@ #include "common.h" -#include "patcher.h" + #include "General.h" +#include "RwHelper.h" #include "ModelInfo.h" #include "ModelIndices.h" #include "FileMgr.h" @@ -10,12 +11,12 @@ #include "AnimBlendAssocGroup.h" #include "AnimManager.h" -CAnimBlock *CAnimManager::ms_aAnimBlocks = (CAnimBlock*)0x6F01A0; -CAnimBlendHierarchy *CAnimManager::ms_aAnimations = (CAnimBlendHierarchy*)0x70F430; -int32 &CAnimManager::ms_numAnimBlocks = *(int32*)0x885AF8; -int32 &CAnimManager::ms_numAnimations = *(int32*)0x8E2DD4; -CAnimBlendAssocGroup *&CAnimManager::ms_aAnimAssocGroups = *(CAnimBlendAssocGroup**)0x8F583C; -CLinkList<CAnimBlendHierarchy*> &CAnimManager::ms_animCache = *(CLinkList<CAnimBlendHierarchy*>*)0x9414DC; +CAnimBlock CAnimManager::ms_aAnimBlocks[2]; +CAnimBlendHierarchy CAnimManager::ms_aAnimations[250]; +int32 CAnimManager::ms_numAnimBlocks; +int32 CAnimManager::ms_numAnimations; +CAnimBlendAssocGroup *CAnimManager::ms_aAnimAssocGroups; +CLinkList<CAnimBlendHierarchy*> CAnimManager::ms_animCache; AnimAssocDesc aStdAnimDescs[] = { { ANIM_WALK, ASSOC_REPEAT | ASSOC_MOVEMENT | ASSOC_HAS_TRANSLATION | ASSOC_FLAG80 }, @@ -754,6 +755,11 @@ CAnimManager::LoadAnimFiles(void) group->CreateAssociations(def->blockName, clump, def->animNames, def->numAnims); for(j = 0; j < group->numAssociations; j++) group->GetAnimation(j)->flags |= def->animDescs[j].flags; +#ifdef PED_SKIN + // forgot on xbox/android + if(IsClumpSkinned(clump)) + RpClumpForAllAtomics(clump, AtomicRemoveAnimFromSkinCB, nil); +#endif RpClumpDestroy(clump); } } @@ -909,23 +915,3 @@ CAnimManager::RemoveLastAnimFile(void) for(i = 0; i < ms_aAnimBlocks[ms_numAnimBlocks].numAnims; i++) ms_aAnimations[ms_aAnimBlocks[ms_numAnimBlocks].firstIndex + i].RemoveAnimSequences(); } - - -STARTPATCHES - InjectHook(0x403380, CAnimManager::Initialise, PATCH_JUMP); - InjectHook(0x4033B0, CAnimManager::Shutdown, PATCH_JUMP); - InjectHook(0x403410, CAnimManager::UncompressAnimation, PATCH_JUMP); - InjectHook(0x4034A0, CAnimManager::GetAnimationBlock, PATCH_JUMP); - InjectHook(0x4034F0, (CAnimBlendHierarchy *(*)(const char*, CAnimBlock*))CAnimManager::GetAnimation, PATCH_JUMP); - InjectHook(0x4035B0, CAnimManager::GetAnimGroupName, PATCH_JUMP); - InjectHook(0x4035C0, CAnimManager::CreateAnimAssociation, PATCH_JUMP); - InjectHook(0x4035E0, (CAnimBlendAssociation *(*)(AssocGroupId, AnimationId))CAnimManager::GetAnimAssociation, PATCH_JUMP); - InjectHook(0x403600, (CAnimBlendAssociation *(*)(AssocGroupId, const char*))CAnimManager::GetAnimAssociation, PATCH_JUMP); - InjectHook(0x403620, CAnimManager::AddAnimation, PATCH_JUMP); - InjectHook(0x4036A0, CAnimManager::AddAnimationAndSync, PATCH_JUMP); - InjectHook(0x403710, CAnimManager::BlendAnimation, PATCH_JUMP); - InjectHook(0x4038F0, CAnimManager::LoadAnimFiles, PATCH_JUMP); - InjectHook(0x403A10, (void (*)(const char *))CAnimManager::LoadAnimFile, PATCH_JUMP); - InjectHook(0x403A40, (void (*)(int, bool))CAnimManager::LoadAnimFile, PATCH_JUMP); - InjectHook(0x404320, CAnimManager::RemoveLastAnimFile, PATCH_JUMP); -ENDPATCHES diff --git a/src/animation/AnimManager.h b/src/animation/AnimManager.h index 0d4e17fe..1b333b60 100644 --- a/src/animation/AnimManager.h +++ b/src/animation/AnimManager.h @@ -1,6 +1,7 @@ #pragma once #include "AnimBlendHierarchy.h" +#include "AnimationId.h" enum AssocGroupId { @@ -33,185 +34,6 @@ enum AssocGroupId NUM_ANIM_ASSOC_GROUPS }; -enum AnimationId -{ - ANIM_WALK, - ANIM_RUN, - ANIM_SPRINT, - ANIM_IDLE_STANCE, - ANIM_WALK_START, - ANIM_RUN_STOP, - ANIM_RUN_STOP_R, - ANIM_IDLE_CAM, - ANIM_IDLE_HBHB, - ANIM_IDLE_TIRED, - ANIM_IDLE_ARMED, - ANIM_IDLE_CHAT, - ANIM_IDLE_TAXI, - ANIM_KO_SHOT_FRONT1, - ANIM_KO_SHOT_FRONT2, - ANIM_KO_SHOT_FRONT3, - ANIM_KO_SHOT_FRONT4, - ANIM_KO_SHOT_FACE, - ANIM_KO_SHOT_STOM, - ANIM_KO_SHOT_ARML, - ANIM_KO_SHOT_ARMR, - ANIM_KO_SHOT_LEGL, - ANIM_KO_SHOT_LEGR, - ANIM_KD_LEFT, - ANIM_KD_RIGHT, - ANIM_KO_SKID_FRONT, - ANIM_KO_SPIN_R, // named left in VC - ANIM_KO_SKID_BACK, - ANIM_KO_SPIN_L, // named right in VC - ANIM_SHOT_FRONT_PARTIAL, - ANIM_SHOT_LEFT_PARTIAL, - ANIM_SHOT_BACK_PARTIAL, - ANIM_SHOT_RIGHT_PARTIAL, - ANIM_HIT_FRONT, - ANIM_HIT_LEFT, - ANIM_HIT_BACK, - ANIM_HIT_RIGHT, - ANIM_FLOOR_HIT, - ANIM_HIT_BODYBLOW, - ANIM_HIT_CHEST, - ANIM_HIT_HEAD, - ANIM_HIT_WALK, - ANIM_HIT_WALL, - ANIM_FLOOR_HIT_F, - ANIM_HIT_BEHIND, - ANIM_PUNCH_R, - ANIM_KICK_FLOOR, - ANIM_WEAPON_BAT_H, - ANIM_WEAPON_BAT_V, - ANIM_WEAPON_HGUN_BODY, - ANIM_WEAPON_AK_BODY, - ANIM_WEAPON_PUMP, - ANIM_WEAPON_SNIPER, - ANIM_WEAPON_THROW, - ANIM_WEAPON_THROWU, - ANIM_WEAPON_START_THROW, - ANIM_BOMBER, - ANIM_HGUN_RELOAD, - ANIM_AK_RELOAD, - ANIM_FPS_PUNCH, - ANIM_FPS_BAT, - ANIM_FPS_UZI, - ANIM_FPS_PUMP, - ANIM_FPS_AK, - ANIM_FPS_M16, - ANIM_FPS_ROCKET, - ANIM_FIGHT_IDLE, - ANIM_FIGHT2_IDLE, - ANIM_FIGHT_SH_F, - ANIM_FIGHT_BODYBLOW, - ANIM_FIGHT_HEAD, - ANIM_FIGHT_KICK, - ANIM_FIGHT_KNEE, - ANIM_FIGHT_LHOOK, - ANIM_FIGHT_PUNCH, - ANIM_FIGHT_ROUNDHOUSE, - ANIM_FIGHT_LONGKICK, - ANIM_FIGHT_PPUNCH, - ANIM_CAR_JACKED_RHS, - ANIM_CAR_LJACKED_RHS, - ANIM_CAR_JACKED_LHS, - ANIM_CAR_LJACKED_LHS, - ANIM_CAR_QJACK, - ANIM_CAR_QJACKED, - ANIM_CAR_ALIGN_LHS, - ANIM_CAR_ALIGNHI_LHS, - ANIM_CAR_OPEN_LHS, - ANIM_CAR_DOORLOCKED_LHS, - ANIM_CAR_PULLOUT_LHS, - ANIM_CAR_PULLOUT_LOW_LHS, - ANIM_CAR_GETIN_LHS, - ANIM_CAR_GETIN_LOW_LHS, - ANIM_CAR_CLOSEDOOR_LHS, - ANIM_CAR_CLOSEDOOR_LOW_LHS, - ANIM_CAR_ROLLDOOR, - ANIM_CAR_ROLLDOOR_LOW, - ANIM_CAR_GETOUT_LHS, - ANIM_CAR_GETOUT_LOW_LHS, - ANIM_CAR_CLOSE_LHS, - ANIM_CAR_ALIGN_RHS, - ANIM_CAR_ALIGNHI_RHS, - ANIM_CAR_OPEN_RHS, - ANIM_CAR_DOORLOCKED_RHS, - ANIM_CAR_PULLOUT_RHS, - ANIM_CAR_PULLOUT_LOW_RHS, - ANIM_CAR_GETIN_RHS, - ANIM_CAR_GETIN_LOW_RHS, - ANIM_CAR_CLOSEDOOR_RHS, - ANIM_CAR_CLOSEDOOR_LOW_RHS, - ANIM_CAR_SHUFFLE_RHS, - ANIM_CAR_LSHUFFLE_RHS, - ANIM_CAR_SIT, - ANIM_CAR_LSIT, - ANIM_CAR_SITP, - ANIM_CAR_SITPLO, - ANIM_DRIVE_L, - ANIM_DRIVE_R, - ANIM_DRIVE_LOW_L, - ANIM_DRIVE_LOW_R, - ANIM_DRIVEBY_L, - ANIM_DRIVEBY_R, - ANIM_CAR_LB, - ANIM_DRIVE_BOAT, - ANIM_CAR_GETOUT_RHS, - ANIM_CAR_GETOUT_LOW_RHS, - ANIM_CAR_CLOSE_RHS, - ANIM_CAR_HOOKERTALK, - ANIM_COACH_OPEN_L, - ANIM_COACH_OPEN_R, - ANIM_COACH_IN_L, - ANIM_COACH_IN_R, - ANIM_COACH_OUT_L, - ANIM_TRAIN_GETIN, - ANIM_TRAIN_GETOUT, - ANIM_CAR_CRAWLOUT_RHS, - ANIM_CAR_CRAWLOUT_RHS2, - ANIM_VAN_OPEN_L, - ANIM_VAN_GETIN_L, - ANIM_VAN_CLOSE_L, - ANIM_VAN_GETOUT_L, - ANIM_VAN_OPEN, - ANIM_VAN_GETIN, - ANIM_VAN_CLOSE, - ANIM_VAN_GETOUT, - ANIM_GETUP1, - ANIM_GETUP2, - ANIM_GETUP3, - ANIM_GETUP_FRONT, - ANIM_JUMP_LAUNCH, - ANIM_JUMP_GLIDE, - ANIM_JUMP_LAND, - ANIM_FALL_FALL, - ANIM_FALL_GLIDE, - ANIM_FALL_LAND, - ANIM_FALL_COLLAPSE, - ANIM_EV_STEP, - ANIM_EV_DIVE, - ANIM_XPRESS_SCRATCH, - ANIM_ROAD_CROSS, - ANIM_TURN_180, - ANIM_ARREST_GUN, - ANIM_DROWN, - ANIM_CPR, - ANIM_DUCK_DOWN, - ANIM_DUCK_LOW, - ANIM_RBLOCK_CSHOOT, - ANIM_WEAPON_THROWU2, - ANIM_HANDSUP, - ANIM_HANDSCOWER, - ANIM_FUCKU, - ANIM_PHONE_IN, - ANIM_PHONE_OUT, - ANIM_PHONE_TALK, - - NUM_ANIMS -}; - class CAnimBlendAssociation; class CAnimBlendAssocGroup; @@ -242,12 +64,12 @@ struct AnimAssocDefinition class CAnimManager { static const AnimAssocDefinition ms_aAnimAssocDefinitions[NUM_ANIM_ASSOC_GROUPS]; - static CAnimBlock *ms_aAnimBlocks; //[2] - static CAnimBlendHierarchy *ms_aAnimations; //[250] - static int32 &ms_numAnimBlocks; - static int32 &ms_numAnimations; - static CAnimBlendAssocGroup *&ms_aAnimAssocGroups; - static CLinkList<CAnimBlendHierarchy*> &ms_animCache; + static CAnimBlock ms_aAnimBlocks[2]; + static CAnimBlendHierarchy ms_aAnimations[250]; + static int32 ms_numAnimBlocks; + static int32 ms_numAnimations; + static CAnimBlendAssocGroup *ms_aAnimAssocGroups; + static CLinkList<CAnimBlendHierarchy*> ms_animCache; public: static void Initialise(void); diff --git a/src/animation/AnimationId.h b/src/animation/AnimationId.h new file mode 100644 index 00000000..82fed8bd --- /dev/null +++ b/src/animation/AnimationId.h @@ -0,0 +1,180 @@ +#pragma once + +enum AnimationId +{ + ANIM_WALK, + ANIM_RUN, + ANIM_SPRINT, + ANIM_IDLE_STANCE, + ANIM_WALK_START, + ANIM_RUN_STOP, + ANIM_RUN_STOP_R, + ANIM_IDLE_CAM, + ANIM_IDLE_HBHB, + ANIM_IDLE_TIRED, + ANIM_IDLE_ARMED, + ANIM_IDLE_CHAT, + ANIM_IDLE_TAXI, + ANIM_KO_SHOT_FRONT1, + ANIM_KO_SHOT_FRONT2, + ANIM_KO_SHOT_FRONT3, + ANIM_KO_SHOT_FRONT4, + ANIM_KO_SHOT_FACE, + ANIM_KO_SHOT_STOM, + ANIM_KO_SHOT_ARML, + ANIM_KO_SHOT_ARMR, + ANIM_KO_SHOT_LEGL, + ANIM_KO_SHOT_LEGR, + ANIM_KD_LEFT, + ANIM_KD_RIGHT, + ANIM_KO_SKID_FRONT, + ANIM_KO_SPIN_R, // named left in VC + ANIM_KO_SKID_BACK, + ANIM_KO_SPIN_L, // named right in VC + ANIM_SHOT_FRONT_PARTIAL, + ANIM_SHOT_LEFT_PARTIAL, + ANIM_SHOT_BACK_PARTIAL, + ANIM_SHOT_RIGHT_PARTIAL, + ANIM_HIT_FRONT, + ANIM_HIT_LEFT, + ANIM_HIT_BACK, + ANIM_HIT_RIGHT, + ANIM_FLOOR_HIT, + ANIM_HIT_BODYBLOW, + ANIM_HIT_CHEST, + ANIM_HIT_HEAD, + ANIM_HIT_WALK, + ANIM_HIT_WALL, + ANIM_FLOOR_HIT_F, + ANIM_HIT_BEHIND, + ANIM_PUNCH_R, + ANIM_KICK_FLOOR, + ANIM_WEAPON_BAT_H, + ANIM_WEAPON_BAT_V, + ANIM_WEAPON_HGUN_BODY, + ANIM_WEAPON_AK_BODY, + ANIM_WEAPON_PUMP, + ANIM_WEAPON_SNIPER, + ANIM_WEAPON_THROW, + ANIM_WEAPON_THROWU, + ANIM_WEAPON_START_THROW, + ANIM_BOMBER, + ANIM_HGUN_RELOAD, + ANIM_AK_RELOAD, + ANIM_FPS_PUNCH, + ANIM_FPS_BAT, + ANIM_FPS_UZI, + ANIM_FPS_PUMP, + ANIM_FPS_AK, + ANIM_FPS_M16, + ANIM_FPS_ROCKET, + ANIM_FIGHT_IDLE, + ANIM_FIGHT2_IDLE, + ANIM_FIGHT_SH_F, + ANIM_FIGHT_BODYBLOW, + ANIM_FIGHT_HEAD, + ANIM_FIGHT_KICK, + ANIM_FIGHT_KNEE, + ANIM_FIGHT_LHOOK, + ANIM_FIGHT_PUNCH, + ANIM_FIGHT_ROUNDHOUSE, + ANIM_FIGHT_LONGKICK, + ANIM_FIGHT_PPUNCH, + ANIM_CAR_JACKED_RHS, + ANIM_CAR_LJACKED_RHS, + ANIM_CAR_JACKED_LHS, + ANIM_CAR_LJACKED_LHS, + ANIM_CAR_QJACK, + ANIM_CAR_QJACKED, + ANIM_CAR_ALIGN_LHS, + ANIM_CAR_ALIGNHI_LHS, + ANIM_CAR_OPEN_LHS, + ANIM_CAR_DOORLOCKED_LHS, + ANIM_CAR_PULLOUT_LHS, + ANIM_CAR_PULLOUT_LOW_LHS, + ANIM_CAR_GETIN_LHS, + ANIM_CAR_GETIN_LOW_LHS, + ANIM_CAR_CLOSEDOOR_LHS, + ANIM_CAR_CLOSEDOOR_LOW_LHS, + ANIM_CAR_ROLLDOOR, + ANIM_CAR_ROLLDOOR_LOW, + ANIM_CAR_GETOUT_LHS, + ANIM_CAR_GETOUT_LOW_LHS, + ANIM_CAR_CLOSE_LHS, + ANIM_CAR_ALIGN_RHS, + ANIM_CAR_ALIGNHI_RHS, + ANIM_CAR_OPEN_RHS, + ANIM_CAR_DOORLOCKED_RHS, + ANIM_CAR_PULLOUT_RHS, + ANIM_CAR_PULLOUT_LOW_RHS, + ANIM_CAR_GETIN_RHS, + ANIM_CAR_GETIN_LOW_RHS, + ANIM_CAR_CLOSEDOOR_RHS, + ANIM_CAR_CLOSEDOOR_LOW_RHS, + ANIM_CAR_SHUFFLE_RHS, + ANIM_CAR_LSHUFFLE_RHS, + ANIM_CAR_SIT, + ANIM_CAR_LSIT, + ANIM_CAR_SITP, + ANIM_CAR_SITPLO, + ANIM_DRIVE_L, + ANIM_DRIVE_R, + ANIM_DRIVE_LOW_L, + ANIM_DRIVE_LOW_R, + ANIM_DRIVEBY_L, + ANIM_DRIVEBY_R, + ANIM_CAR_LB, + ANIM_DRIVE_BOAT, + ANIM_CAR_GETOUT_RHS, + ANIM_CAR_GETOUT_LOW_RHS, + ANIM_CAR_CLOSE_RHS, + ANIM_CAR_HOOKERTALK, + ANIM_COACH_OPEN_L, + ANIM_COACH_OPEN_R, + ANIM_COACH_IN_L, + ANIM_COACH_IN_R, + ANIM_COACH_OUT_L, + ANIM_TRAIN_GETIN, + ANIM_TRAIN_GETOUT, + ANIM_CAR_CRAWLOUT_RHS, + ANIM_CAR_CRAWLOUT_RHS2, + ANIM_VAN_OPEN_L, + ANIM_VAN_GETIN_L, + ANIM_VAN_CLOSE_L, + ANIM_VAN_GETOUT_L, + ANIM_VAN_OPEN, + ANIM_VAN_GETIN, + ANIM_VAN_CLOSE, + ANIM_VAN_GETOUT, + ANIM_GETUP1, + ANIM_GETUP2, + ANIM_GETUP3, + ANIM_GETUP_FRONT, + ANIM_JUMP_LAUNCH, + ANIM_JUMP_GLIDE, + ANIM_JUMP_LAND, + ANIM_FALL_FALL, + ANIM_FALL_GLIDE, + ANIM_FALL_LAND, + ANIM_FALL_COLLAPSE, + ANIM_EV_STEP, + ANIM_EV_DIVE, + ANIM_XPRESS_SCRATCH, + ANIM_ROAD_CROSS, + ANIM_TURN_180, + ANIM_ARREST_GUN, + ANIM_DROWN, + ANIM_CPR, + ANIM_DUCK_DOWN, + ANIM_DUCK_LOW, + ANIM_RBLOCK_CSHOOT, + ANIM_WEAPON_THROWU2, + ANIM_HANDSUP, + ANIM_HANDSCOWER, + ANIM_FUCKU, + ANIM_PHONE_IN, + ANIM_PHONE_OUT, + ANIM_PHONE_TALK, + + NUM_ANIMS +};
\ No newline at end of file diff --git a/src/animation/Bones.cpp b/src/animation/Bones.cpp new file mode 100644 index 00000000..1608449d --- /dev/null +++ b/src/animation/Bones.cpp @@ -0,0 +1,52 @@ +#include "common.h" +#include "PedModelInfo.h" +#include "Bones.h" + +#ifdef PED_SKIN + +int +ConvertPedNode2BoneTag(int node) +{ + switch(node){ + case PED_TORSO: return BONE_waist; + case PED_MID: return BONE_torso; // this is what Xbox/Mobile use + // return BONE_mid; // this is what PS2/PC use + case PED_HEAD: return BONE_head; + case PED_UPPERARML: return BONE_upperarml; + case PED_UPPERARMR: return BONE_upperarmr; + case PED_HANDL: return BONE_Lhand; + case PED_HANDR: return BONE_Rhand; + case PED_UPPERLEGL: return BONE_upperlegl; + case PED_UPPERLEGR: return BONE_upperlegr; + case PED_FOOTL: return BONE_footl; + case PED_FOOTR: return BONE_footr; + case PED_LOWERLEGR: return BONE_lowerlegl; + } + return -1; +} + +const char* +ConvertBoneTag2BoneName(int tag) +{ + switch(tag){ + case BONE_waist: return "Swaist"; + case BONE_upperlegr: return "Supperlegr"; + case BONE_lowerlegr: return "Slowerlegr"; + case BONE_footr: return "Sfootr"; + case BONE_upperlegl: return "Supperlegl"; + case BONE_lowerlegl: return "Slowerlegl"; + case BONE_footl: return "Sfootl"; + case BONE_mid: return "Smid"; + case BONE_torso: return "Storso"; + case BONE_head: return "Shead"; + case BONE_upperarmr: return "Supperarmr"; + case BONE_lowerarmr: return "Slowerarmr"; + case BONE_Rhand: return "SRhand"; + case BONE_upperarml: return "Supperarml"; + case BONE_lowerarml: return "Slowerarml"; + case BONE_Lhand: return "SLhand"; + } + return nil; +} + +#endif diff --git a/src/animation/Bones.h b/src/animation/Bones.h new file mode 100644 index 00000000..38d91ba3 --- /dev/null +++ b/src/animation/Bones.h @@ -0,0 +1,24 @@ +#pragma once + +enum BoneTag +{ + BONE_waist, + BONE_upperlegr, + BONE_lowerlegr, + BONE_footr, + BONE_upperlegl, + BONE_lowerlegl, + BONE_footl, + BONE_mid, + BONE_torso, + BONE_head, + BONE_upperarmr, + BONE_lowerarmr, + BONE_Rhand, + BONE_upperarml, + BONE_lowerarml, + BONE_Lhand, +}; + +int ConvertPedNode2BoneTag(int node); +const char *ConvertBoneTag2BoneName(int tag); diff --git a/src/animation/CutsceneMgr.cpp b/src/animation/CutsceneMgr.cpp index 6f8e9790..334fe471 100644 --- a/src/animation/CutsceneMgr.cpp +++ b/src/animation/CutsceneMgr.cpp @@ -1,6 +1,5 @@ -#define WITHWINDOWS // just for VK_SPACE #include "common.h" -#include "patcher.h" + #include "General.h" #include "CutsceneMgr.h" #include "Directory.h" @@ -117,19 +116,19 @@ FindCutsceneAudioTrackId(const char *szCutsceneName) return -1; } -bool &CCutsceneMgr::ms_running = *(bool*)0x95CCF5; -bool &CCutsceneMgr::ms_cutsceneProcessing = *(bool*)0x95CD9F; -CDirectory *&CCutsceneMgr::ms_pCutsceneDir = *(CDirectory**)0x8F5F88; -CCutsceneObject *(&CCutsceneMgr::ms_pCutsceneObjects)[NUMCUTSCENEOBJECTS] = *(CCutsceneObject*(*)[NUMCUTSCENEOBJECTS]) *(uintptr*) 0x862170; -int32 &CCutsceneMgr::ms_numCutsceneObjs = *(int32*)0x942FA4; -bool &CCutsceneMgr::ms_loaded = *(bool*)0x95CD95; -bool &CCutsceneMgr::ms_animLoaded = *(bool*)0x95CDA0; -bool &CCutsceneMgr::ms_useLodMultiplier = *(bool*)0x95CD74; -char(&CCutsceneMgr::ms_cutsceneName)[CUTSCENENAMESIZE] = *(char(*)[CUTSCENENAMESIZE]) *(uintptr*)0x70D9D0; -CAnimBlendAssocGroup &CCutsceneMgr::ms_cutsceneAssociations = *(CAnimBlendAssocGroup*)0x709C58; -CVector &CCutsceneMgr::ms_cutsceneOffset = *(CVector*)0x8F2C0C; -float &CCutsceneMgr::ms_cutsceneTimer = *(float*)0x941548; -uint32 &CCutsceneMgr::ms_cutsceneLoadStatus = *(uint32*)0x95CB40; +bool CCutsceneMgr::ms_running; +bool CCutsceneMgr::ms_cutsceneProcessing; +CDirectory *CCutsceneMgr::ms_pCutsceneDir; +CCutsceneObject *CCutsceneMgr::ms_pCutsceneObjects[NUMCUTSCENEOBJECTS]; +int32 CCutsceneMgr::ms_numCutsceneObjs; +bool CCutsceneMgr::ms_loaded; +bool CCutsceneMgr::ms_animLoaded; +bool CCutsceneMgr::ms_useLodMultiplier; +char CCutsceneMgr::ms_cutsceneName[CUTSCENENAMESIZE]; +CAnimBlendAssocGroup CCutsceneMgr::ms_cutsceneAssociations; +CVector CCutsceneMgr::ms_cutsceneOffset; +float CCutsceneMgr::ms_cutsceneTimer; +uint32 CCutsceneMgr::ms_cutsceneLoadStatus; RpAtomic * CalculateBoundingSphereRadiusCB(RpAtomic *atomic, void *data) @@ -416,26 +415,10 @@ CCutsceneMgr::Update(void) || (CGame::playingIntro && CPad::GetPad(0)->GetStartJustDown()) || CPad::GetPad(0)->GetLeftMouseJustDown() || CPad::GetPad(0)->GetEnterJustDown() - || CPad::GetPad(0)->GetCharJustDown(VK_SPACE)) + || CPad::GetPad(0)->GetCharJustDown(' ')) FinishCutscene(); } } bool CCutsceneMgr::HasCutsceneFinished(void) { return TheCamera.GetPositionAlongSpline() == 1.0f; } -STARTPATCHES - InjectHook(0x4045D0, &CCutsceneMgr::Initialise, PATCH_JUMP); - InjectHook(0x404630, &CCutsceneMgr::Shutdown, PATCH_JUMP); - InjectHook(0x404650, &CCutsceneMgr::LoadCutsceneData, PATCH_JUMP); - InjectHook(0x405140, &CCutsceneMgr::FinishCutscene, PATCH_JUMP); - InjectHook(0x404D80, &CCutsceneMgr::SetHeadAnim, PATCH_JUMP); - InjectHook(0x404DC0, &CCutsceneMgr::SetupCutsceneToStart, PATCH_JUMP); - InjectHook(0x404D20, &CCutsceneMgr::SetCutsceneAnim, PATCH_JUMP); - InjectHook(0x404CD0, &CCutsceneMgr::AddCutsceneHead, PATCH_JUMP); - InjectHook(0x404BE0, &CCutsceneMgr::CreateCutsceneObject, PATCH_JUMP); - InjectHook(0x4048E0, &CCutsceneMgr::DeleteCutsceneData, PATCH_JUMP); - InjectHook(0x404EE0, &CCutsceneMgr::Update, PATCH_JUMP); - InjectHook(0x4051B0, &CCutsceneMgr::GetCutsceneTimeInMilleseconds, PATCH_JUMP); - InjectHook(0x4051F0, &CCutsceneMgr::HasCutsceneFinished, PATCH_JUMP); - InjectHook(0x404B40, &CalculateBoundingSphereRadiusCB, PATCH_JUMP); -ENDPATCHES
\ No newline at end of file diff --git a/src/animation/CutsceneMgr.h b/src/animation/CutsceneMgr.h index 3c915eea..bfdcdb57 100644 --- a/src/animation/CutsceneMgr.h +++ b/src/animation/CutsceneMgr.h @@ -9,25 +9,26 @@ class CCutsceneHead; class CCutsceneMgr { - static bool &ms_running; - static CCutsceneObject *(&ms_pCutsceneObjects)[NUMCUTSCENEOBJECTS]; + static bool ms_running; + static CCutsceneObject *ms_pCutsceneObjects[NUMCUTSCENEOBJECTS]; - static int32 &ms_numCutsceneObjs; - static bool &ms_loaded; - static bool &ms_animLoaded; - static bool &ms_useLodMultiplier; + static int32 ms_numCutsceneObjs; + static bool ms_loaded; + static bool ms_animLoaded; + static bool ms_useLodMultiplier; - static char(&ms_cutsceneName)[CUTSCENENAMESIZE]; - static CAnimBlendAssocGroup &ms_cutsceneAssociations; - static CVector &ms_cutsceneOffset; - static float &ms_cutsceneTimer; - static bool &ms_cutsceneProcessing; + static char ms_cutsceneName[CUTSCENENAMESIZE]; + static CAnimBlendAssocGroup ms_cutsceneAssociations; + static CVector ms_cutsceneOffset; + static float ms_cutsceneTimer; + static bool ms_cutsceneProcessing; public: - static CDirectory *&ms_pCutsceneDir; - static uint32 &ms_cutsceneLoadStatus; + static CDirectory *ms_pCutsceneDir; + static uint32 ms_cutsceneLoadStatus; static void StartCutsceneProcessing() { ms_cutsceneProcessing = true; } static bool IsRunning(void) { return ms_running; } + static bool HasLoaded(void) { return ms_loaded; } static bool IsCutsceneProcessing(void) { return ms_cutsceneProcessing; } static bool UseLodMultiplier(void) { return ms_useLodMultiplier; } static CCutsceneObject* GetCutsceneObject(int id) { return ms_pCutsceneObjects[id]; } diff --git a/src/animation/FrameUpdate.cpp b/src/animation/FrameUpdate.cpp index dcb71944..a1121282 100644 --- a/src/animation/FrameUpdate.cpp +++ b/src/animation/FrameUpdate.cpp @@ -1,19 +1,25 @@ #include "common.h" -#include "patcher.h" + #include "NodeName.h" #include "VisibilityPlugins.h" #include "AnimBlendClumpData.h" #include "AnimBlendAssociation.h" #include "RpAnimBlend.h" -CAnimBlendClumpData *&gpAnimBlendClump = *(CAnimBlendClumpData**)0x621000; +CAnimBlendClumpData *gpAnimBlendClump; + +// PS2 names without "NonSkinned" +void FrameUpdateCallBackNonSkinned(AnimBlendFrameData *frame, void *arg); +void FrameUpdateCallBackWithVelocityExtractionNonSkinned(AnimBlendFrameData *frame, void *arg); +void FrameUpdateCallBackWith3dVelocityExtractionNonSkinned(AnimBlendFrameData *frame, void *arg); + +void FrameUpdateCallBackSkinned(AnimBlendFrameData *frame, void *arg); +void FrameUpdateCallBackWithVelocityExtractionSkinned(AnimBlendFrameData *frame, void *arg); +void FrameUpdateCallBackWith3dVelocityExtractionSkinned(AnimBlendFrameData *frame, void *arg); -void FrameUpdateCallBack(AnimBlendFrameData *frame, void *arg); -void FrameUpdateCallBackWithVelocityExtraction(AnimBlendFrameData *frame, void *arg); -void FrameUpdateCallBackWith3dVelocityExtraction(AnimBlendFrameData *frame, void *arg); void -FrameUpdateCallBack(AnimBlendFrameData *frame, void *arg) +FrameUpdateCallBackNonSkinned(AnimBlendFrameData *frame, void *arg) { CVector vec, pos(0.0f, 0.0f, 0.0f); CQuaternion q, rot(0.0f, 0.0f, 0.0f, 0.0f); @@ -25,9 +31,9 @@ FrameUpdateCallBack(AnimBlendFrameData *frame, void *arg) if(frame->flag & AnimBlendFrameData::VELOCITY_EXTRACTION && gpAnimBlendClump->velocity){ if(frame->flag & AnimBlendFrameData::VELOCITY_EXTRACTION_3D) - FrameUpdateCallBackWith3dVelocityExtraction(frame, arg); + FrameUpdateCallBackWith3dVelocityExtractionNonSkinned(frame, arg); else - FrameUpdateCallBackWithVelocityExtraction(frame, arg); + FrameUpdateCallBackWithVelocityExtractionNonSkinned(frame, arg); return; } @@ -48,12 +54,7 @@ FrameUpdateCallBack(AnimBlendFrameData *frame, void *arg) if((frame->flag & AnimBlendFrameData::IGNORE_ROTATION) == 0){ RwMatrixSetIdentity(mat); - - float norm = rot.MagnitudeSqr(); - if(norm == 0.0f) - rot.w = 1.0f; - else - rot *= 1.0f/Sqrt(norm); + rot.Normalise(); rot.Get(mat); } @@ -69,7 +70,7 @@ FrameUpdateCallBack(AnimBlendFrameData *frame, void *arg) } void -FrameUpdateCallBackWithVelocityExtraction(AnimBlendFrameData *frame, void *arg) +FrameUpdateCallBackWithVelocityExtractionNonSkinned(AnimBlendFrameData *frame, void *arg) { CVector vec, pos(0.0f, 0.0f, 0.0f); CQuaternion q, rot(0.0f, 0.0f, 0.0f, 0.0f); @@ -122,12 +123,7 @@ FrameUpdateCallBackWithVelocityExtraction(AnimBlendFrameData *frame, void *arg) if((frame->flag & AnimBlendFrameData::IGNORE_ROTATION) == 0){ RwMatrixSetIdentity(mat); - - float norm = rot.MagnitudeSqr(); - if(norm == 0.0f) - rot.w = 1.0f; - else - rot *= 1.0f/Sqrt(norm); + rot.Normalise(); rot.Get(mat); } @@ -154,7 +150,7 @@ FrameUpdateCallBackWithVelocityExtraction(AnimBlendFrameData *frame, void *arg) // original code uses do loops? void -FrameUpdateCallBackWith3dVelocityExtraction(AnimBlendFrameData *frame, void *arg) +FrameUpdateCallBackWith3dVelocityExtractionNonSkinned(AnimBlendFrameData *frame, void *arg) { CVector vec, pos(0.0f, 0.0f, 0.0f); CQuaternion q, rot(0.0f, 0.0f, 0.0f, 0.0f); @@ -201,12 +197,7 @@ FrameUpdateCallBackWith3dVelocityExtraction(AnimBlendFrameData *frame, void *arg if((frame->flag & AnimBlendFrameData::IGNORE_ROTATION) == 0){ RwMatrixSetIdentity(mat); - - float norm = rot.MagnitudeSqr(); - if(norm == 0.0f) - rot.w = 1.0f; - else - rot *= 1.0f/Sqrt(norm); + rot.Normalise(); rot.Get(mat); } @@ -221,8 +212,202 @@ FrameUpdateCallBackWith3dVelocityExtraction(AnimBlendFrameData *frame, void *arg RwMatrixUpdate(mat); } -STARTPATCHES - InjectHook(0x4025F0, FrameUpdateCallBack, PATCH_JUMP); - InjectHook(0x4028B0, FrameUpdateCallBackWithVelocityExtraction, PATCH_JUMP); - InjectHook(0x402D40, FrameUpdateCallBackWith3dVelocityExtraction, PATCH_JUMP); -ENDPATCHES +#ifdef PED_SKIN + +void +FrameUpdateCallBackSkinned(AnimBlendFrameData *frame, void *arg) +{ + CVector vec, pos(0.0f, 0.0f, 0.0f); + CQuaternion q, rot(0.0f, 0.0f, 0.0f, 0.0f); + float totalBlendAmount = 0.0f; + RpHAnimStdKeyFrame *xform = frame->hanimFrame; + CAnimBlendNode **node; + AnimBlendFrameUpdateData *updateData = (AnimBlendFrameUpdateData*)arg; + + if(frame->flag & AnimBlendFrameData::VELOCITY_EXTRACTION && + gpAnimBlendClump->velocity){ + if(frame->flag & AnimBlendFrameData::VELOCITY_EXTRACTION_3D) + FrameUpdateCallBackWith3dVelocityExtractionSkinned(frame, arg); + else + FrameUpdateCallBackWithVelocityExtractionSkinned(frame, arg); + return; + } + + if(updateData->foobar) + for(node = updateData->nodes; *node; node++) + if((*node)->sequence && (*node)->association->IsPartial()) + totalBlendAmount += (*node)->association->blendAmount; + + for(node = updateData->nodes; *node; node++){ + if((*node)->sequence){ + (*node)->Update(vec, q, 1.0f-totalBlendAmount); + if((*node)->sequence->HasTranslation()) + pos += vec; + rot += q; + } + ++*node; + } + + if((frame->flag & AnimBlendFrameData::IGNORE_ROTATION) == 0){ + rot.Normalise(); + xform->q.imag.x = rot.x; + xform->q.imag.y = rot.y; + xform->q.imag.z = rot.z; + xform->q.real = rot.w; + } + + if((frame->flag & AnimBlendFrameData::IGNORE_TRANSLATION) == 0){ + xform->t.x = pos.x; + xform->t.y = pos.y; + xform->t.z = pos.z; + xform->t.x += frame->resetPos.x; + xform->t.y += frame->resetPos.y; + xform->t.z += frame->resetPos.z; + } +} + +void +FrameUpdateCallBackWithVelocityExtractionSkinned(AnimBlendFrameData *frame, void *arg) +{ + CVector vec, pos(0.0f, 0.0f, 0.0f); + CQuaternion q, rot(0.0f, 0.0f, 0.0f, 0.0f); + float totalBlendAmount = 0.0f; + float transx = 0.0f, transy = 0.0f; + float curx = 0.0f, cury = 0.0f; + float endx = 0.0f, endy = 0.0f; + bool looped = false; + RpHAnimStdKeyFrame *xform = frame->hanimFrame; + CAnimBlendNode **node; + AnimBlendFrameUpdateData *updateData = (AnimBlendFrameUpdateData*)arg; + + if(updateData->foobar) + for(node = updateData->nodes; *node; node++) + if((*node)->sequence && (*node)->association->IsPartial()) + totalBlendAmount += (*node)->association->blendAmount; + + for(node = updateData->nodes; *node; node++) + if((*node)->sequence && (*node)->sequence->HasTranslation()){ + if((*node)->association->HasTranslation()){ + (*node)->GetCurrentTranslation(vec, 1.0f-totalBlendAmount); + cury += vec.y; + if((*node)->association->HasXTranslation()) + curx += vec.x; + } + } + + for(node = updateData->nodes; *node; node++){ + if((*node)->sequence){ + bool nodelooped = (*node)->Update(vec, q, 1.0f-totalBlendAmount); + rot += q; + if((*node)->sequence->HasTranslation()){ + pos += vec; + if((*node)->association->HasTranslation()){ + transy += vec.y; + if((*node)->association->HasXTranslation()) + transx += vec.x; + looped |= nodelooped; + if(nodelooped){ + (*node)->GetEndTranslation(vec, 1.0f-totalBlendAmount); + endy += vec.y; + if((*node)->association->HasXTranslation()) + endx += vec.x; + } + } + } + } + ++*node; + } + + if((frame->flag & AnimBlendFrameData::IGNORE_ROTATION) == 0){ + rot.Normalise(); + xform->q.imag.x = rot.x; + xform->q.imag.y = rot.y; + xform->q.imag.z = rot.z; + xform->q.real = rot.w; + } + + if((frame->flag & AnimBlendFrameData::IGNORE_TRANSLATION) == 0){ + gpAnimBlendClump->velocity->x = transx - curx; + gpAnimBlendClump->velocity->y = transy - cury; + if(looped){ + gpAnimBlendClump->velocity->x += endx; + gpAnimBlendClump->velocity->y += endy; + } + xform->t.x = pos.x - transx; + xform->t.y = pos.y - transy; + xform->t.z = pos.z; + if(xform->t.z >= -0.8f) + if(xform->t.z < -0.4f) + xform->t.z += (2.5f * xform->t.z + 2.0f) * frame->resetPos.z; + else + xform->t.z += frame->resetPos.z; + xform->t.x += frame->resetPos.x; + xform->t.y += frame->resetPos.y; + } +} + +void +FrameUpdateCallBackWith3dVelocityExtractionSkinned(AnimBlendFrameData *frame, void *arg) +{ + CVector vec, pos(0.0f, 0.0f, 0.0f); + CQuaternion q, rot(0.0f, 0.0f, 0.0f, 0.0f); + float totalBlendAmount = 0.0f; + CVector trans(0.0f, 0.0f, 0.0f); + CVector cur(0.0f, 0.0f, 0.0f); + CVector end(0.0f, 0.0f, 0.0f); + bool looped = false; + RpHAnimStdKeyFrame *xform = frame->hanimFrame; + CAnimBlendNode **node; + AnimBlendFrameUpdateData *updateData = (AnimBlendFrameUpdateData*)arg; + + if(updateData->foobar) + for(node = updateData->nodes; *node; node++) + if((*node)->sequence && (*node)->association->IsPartial()) + totalBlendAmount += (*node)->association->blendAmount; + + for(node = updateData->nodes; *node; node++) + if((*node)->sequence && (*node)->sequence->HasTranslation()){ + if((*node)->association->HasTranslation()){ + (*node)->GetCurrentTranslation(vec, 1.0f-totalBlendAmount); + cur += vec; + } + } + + for(node = updateData->nodes; *node; node++){ + if((*node)->sequence){ + bool nodelooped = (*node)->Update(vec, q, 1.0f-totalBlendAmount); + rot += q; + if((*node)->sequence->HasTranslation()){ + pos += vec; + if((*node)->association->HasTranslation()){ + trans += vec; + looped |= nodelooped; + if(nodelooped){ + (*node)->GetEndTranslation(vec, 1.0f-totalBlendAmount); + end += vec; + } + } + } + } + ++*node; + } + + if((frame->flag & AnimBlendFrameData::IGNORE_ROTATION) == 0){ + rot.Normalise(); + xform->q.imag.x = rot.x; + xform->q.imag.y = rot.y; + xform->q.imag.z = rot.z; + xform->q.real = rot.w; + } + + if((frame->flag & AnimBlendFrameData::IGNORE_TRANSLATION) == 0){ + *gpAnimBlendClump->velocity = trans - cur; + if(looped) + *gpAnimBlendClump->velocity += end; + xform->t.x = (pos - trans).x + frame->resetPos.x; + xform->t.y = (pos - trans).y + frame->resetPos.y; + xform->t.z = (pos - trans).z + frame->resetPos.z; + } +} + +#endif diff --git a/src/animation/RpAnimBlend.cpp b/src/animation/RpAnimBlend.cpp index 9c847139..d3e10889 100644 --- a/src/animation/RpAnimBlend.cpp +++ b/src/animation/RpAnimBlend.cpp @@ -1,14 +1,19 @@ #include "common.h" -#include "patcher.h" + +#include "RwHelper.h" #include "General.h" #include "NodeName.h" #include "VisibilityPlugins.h" +#include "Bones.h" #include "AnimBlendClumpData.h" #include "AnimBlendHierarchy.h" #include "AnimBlendAssociation.h" #include "RpAnimBlend.h" +#ifdef PED_SKIN +#include "PedModelInfo.h" +#endif -RwInt32 &ClumpOffset = *(RwInt32*)0x8F1B84; +RwInt32 ClumpOffset; enum { @@ -122,19 +127,59 @@ FrameForAllChildrenFillFrameArrayCallBack(RwFrame *frame, void *data) return frame; } +// FrameInitCallBack on PS2 void -FrameInitCallBack(AnimBlendFrameData *frameData, void*) +FrameInitCBnonskin(AnimBlendFrameData *frameData, void*) { frameData->flag = 0; frameData->resetPos = *RwMatrixGetPos(RwFrameGetMatrix(frameData->frame)); } void -RpAnimBlendClumpInit(RpClump *clump) +FrameInitCBskin(AnimBlendFrameData *frameData, void*) { + frameData->flag = 0; +} + #ifdef PED_SKIN - TODO -#else +void +RpAnimBlendClumpInitSkinned(RpClump *clump) +{ + int i; + RwV3d boneTab[64]; + CAnimBlendClumpData *clumpData; + RpAtomic *atomic; + RpSkin *skin; + RpHAnimHierarchy *hier; + int numBones; + + RpAnimBlendAllocateData(clump); + clumpData = *RPANIMBLENDCLUMPDATA(clump); + atomic = IsClumpSkinned(clump); + assert(atomic); + skin = RpSkinGeometryGetSkin(RpAtomicGetGeometry(atomic)); + assert(skin); + numBones = RpSkinGetNumBones(skin); + clumpData->SetNumberOfBones(numBones); + hier = GetAnimHierarchyFromSkinClump(clump); + assert(hier); + memset(boneTab, 0, sizeof(boneTab)); + SkinGetBonePositionsToTable(clump, boneTab); + + AnimBlendFrameData *frames = clumpData->frames; + for(i = 0; i < numBones; i++){ + frames[i].nodeID = HIERNODEID(hier, i); + frames[i].resetPos = boneTab[i]; + frames[i].hanimFrame = (RpHAnimStdKeyFrame*)rpHANIMHIERARCHYGETINTERPFRAME(hier, i); + } + clumpData->ForAllFrames(FrameInitCBskin, nil); + clumpData->frames[0].flag |= AnimBlendFrameData::VELOCITY_EXTRACTION; +} +#endif + +void +RpAnimBlendClumpInitNotSkinned(RpClump *clump) +{ int numFrames = 0; CAnimBlendClumpData *clumpData; RwFrame *root; @@ -147,9 +192,19 @@ RpAnimBlendClumpInit(RpClump *clump) clumpData->SetNumberOfFrames(numFrames); frames = clumpData->frames; RwFrameForAllChildren(root, FrameForAllChildrenFillFrameArrayCallBack, &frames); - clumpData->ForAllFrames(FrameInitCallBack, nil); + clumpData->ForAllFrames(FrameInitCBnonskin, nil); clumpData->frames[0].flag |= AnimBlendFrameData::VELOCITY_EXTRACTION; +} + +void +RpAnimBlendClumpInit(RpClump *clump) +{ +#ifdef PED_SKIN + if(IsClumpSkinned(clump)) + RpAnimBlendClumpInitSkinned(clump); + else #endif + RpAnimBlendClumpInitNotSkinned(clump); } bool @@ -298,42 +353,68 @@ RpAnimBlendClumpGetFirstAssociation(RpClump *clump) return CAnimBlendAssociation::FromLink(clumpData->link.next); } +// FillFrameArrayCallBack on PS2 void -FillFrameArrayCallBack(AnimBlendFrameData *frame, void *arg) +FillFrameArrayCBnonskin(AnimBlendFrameData *frame, void *arg) { AnimBlendFrameData **frames = (AnimBlendFrameData**)arg; frames[CVisibilityPlugins::GetFrameHierarchyId(frame->frame)] = frame; } +#ifdef PED_SKIN +void +RpAnimBlendClumpFillFrameArraySkin(RpClump *clump, AnimBlendFrameData **frames) +{ + int i; + CAnimBlendClumpData *clumpData = *RPANIMBLENDCLUMPDATA(clump); + RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(clump); + for(i = PED_MID; i < PED_NODE_MAX; i++) + frames[i] = &clumpData->frames[RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(i))]; +} +#endif + void RpAnimBlendClumpFillFrameArray(RpClump *clump, AnimBlendFrameData **frames) { #ifdef PED_SKIN - TODO -#else - (*RPANIMBLENDCLUMPDATA(clump))->ForAllFrames(FillFrameArrayCallBack, frames); + if(IsClumpSkinned(clump)) + RpAnimBlendClumpFillFrameArraySkin(clump, frames); + else #endif + (*RPANIMBLENDCLUMPDATA(clump))->ForAllFrames(FillFrameArrayCBnonskin, frames); } AnimBlendFrameData *pFrameDataFound; +// FrameFindCallBack on PS2 void -FrameFindCallBack(AnimBlendFrameData *frame, void *arg) +FrameFindByNameCBnonskin(AnimBlendFrameData *frame, void *arg) { char *nodename = GetFrameNodeName(frame->frame); if(!CGeneral::faststricmp(nodename, (char*)arg)) pFrameDataFound = frame; } +#ifdef PED_SKIN +void +FrameFindByNameCBskin(AnimBlendFrameData *frame, void *arg) +{ + const char *name = ConvertBoneTag2BoneName(frame->nodeID); + if(name && CGeneral::faststricmp(name, (char*)arg) == 0) + pFrameDataFound = frame; +} +#endif + AnimBlendFrameData* RpAnimBlendClumpFindFrame(RpClump *clump, const char *name) { pFrameDataFound = nil; #ifdef PED_SKIN - TODO -#else - (*RPANIMBLENDCLUMPDATA(clump))->ForAllFrames(FrameFindCallBack, (void*)name); + if(IsClumpSkinned(clump)) + (*RPANIMBLENDCLUMPDATA(clump))->ForAllFrames(FrameFindByNameCBskin, (void*)name); + else #endif + (*RPANIMBLENDCLUMPDATA(clump))->ForAllFrames(FrameFindByNameCBnonskin, (void*)name); return pFrameDataFound; } @@ -369,7 +450,12 @@ RpAnimBlendClumpUpdateAnimations(RpClump *clump, float timeDelta) } updateData.nodes[i] = nil; - clumpData->ForAllFrames(FrameUpdateCallBack, &updateData); +#ifdef PED_SKIN + if(IsClumpSkinned(clump)) + clumpData->ForAllFrames(FrameUpdateCallBackSkinned, &updateData); + else +#endif + clumpData->ForAllFrames(FrameUpdateCallBackNonSkinned, &updateData); for(link = clumpData->link.next; link; link = link->next){ CAnimBlendAssociation *assoc = CAnimBlendAssociation::FromLink(link); @@ -378,26 +464,3 @@ RpAnimBlendClumpUpdateAnimations(RpClump *clump, float timeDelta) } RwFrameUpdateObjects(RpClumpGetFrame(clump)); } - - -STARTPATCHES - InjectHook(0x4052D0, RpAnimBlendPluginAttach, PATCH_JUMP); - InjectHook(0x4052A0, RpAnimBlendAllocateData, PATCH_JUMP); - InjectHook(0x405780, (CAnimBlendAssociation *(*)(CAnimBlendAssociation*))RpAnimBlendGetNextAssociation, PATCH_JUMP); - InjectHook(0x4057A0, (CAnimBlendAssociation *(*)(CAnimBlendAssociation*,uint32))RpAnimBlendGetNextAssociation, PATCH_JUMP); - - InjectHook(0x405520, RpAnimBlendClumpSetBlendDeltas, PATCH_JUMP); - InjectHook(0x405560, RpAnimBlendClumpRemoveAllAssociations, PATCH_JUMP); - InjectHook(0x405570, RpAnimBlendClumpRemoveAssociations, PATCH_JUMP); - InjectHook(0x405480, RpAnimBlendClumpInit, PATCH_JUMP); - InjectHook(0x405500, RpAnimBlendClumpIsInitialized, PATCH_JUMP); - InjectHook(0x4055C0, RpAnimBlendClumpGetAssociation, PATCH_JUMP); - InjectHook(0x4055F0, RpAnimBlendClumpGetMainAssociation, PATCH_JUMP); - InjectHook(0x405680, RpAnimBlendClumpGetMainPartialAssociation, PATCH_JUMP); - InjectHook(0x4056D0, RpAnimBlendClumpGetMainAssociation_N, PATCH_JUMP); - InjectHook(0x405710, RpAnimBlendClumpGetMainPartialAssociation_N, PATCH_JUMP); - InjectHook(0x405750, (CAnimBlendAssociation *(*)(RpClump*, uint32))RpAnimBlendClumpGetFirstAssociation, PATCH_JUMP); - InjectHook(0x4031B0, (CAnimBlendAssociation *(*)(RpClump*))RpAnimBlendClumpGetFirstAssociation, PATCH_JUMP); - InjectHook(0x405460, RpAnimBlendClumpFillFrameArray, PATCH_JUMP); - InjectHook(0x4024B0, RpAnimBlendClumpUpdateAnimations, PATCH_JUMP); -ENDPATCHES diff --git a/src/animation/RpAnimBlend.h b/src/animation/RpAnimBlend.h index 55a4456b..838c8816 100644 --- a/src/animation/RpAnimBlend.h +++ b/src/animation/RpAnimBlend.h @@ -7,11 +7,11 @@ struct AnimBlendFrameData; struct AnimBlendFrameUpdateData { - int foobar; + int foobar; // TODO: figure out what this actually means CAnimBlendNode *nodes[16]; }; -extern RwInt32 &ClumpOffset; +extern RwInt32 ClumpOffset; #define RPANIMBLENDCLUMPDATA(o) (RWPLUGINOFFSET(CAnimBlendClumpData*, o, ClumpOffset)) bool RpAnimBlendPluginAttach(void); @@ -37,5 +37,6 @@ CAnimBlendAssociation *RpAnimBlendClumpGetFirstAssociation(RpClump *clump); void RpAnimBlendClumpUpdateAnimations(RpClump* clump, float timeDelta); -extern CAnimBlendClumpData *&gpAnimBlendClump; -void FrameUpdateCallBack(AnimBlendFrameData *frame, void *arg); +extern CAnimBlendClumpData *gpAnimBlendClump; +void FrameUpdateCallBackNonSkinned(AnimBlendFrameData *frame, void *arg); +void FrameUpdateCallBackSkinned(AnimBlendFrameData *frame, void *arg); |