Refactor animation, cutscene & particle class

This commit is contained in:
Grinch_ 2022-08-05 09:30:33 +06:00
parent 088f84a981
commit 8db76a2ce7
5 changed files with 135 additions and 96 deletions

Binary file not shown.

View File

@ -9,9 +9,7 @@
#include <CAnimManager.h> #include <CAnimManager.h>
#include "eAnimations.h" #include "eAnimations.h"
#include <CAnimBlendAssociation.h> #include <CAnimBlendAssociation.h>
#elif GTAVC #elif GTAVC
#include "../depend/kiero/minhook/MinHook.h" #include "../depend/kiero/minhook/MinHook.h"
#include <CAnimationStyleDescriptor.h> #include <CAnimationStyleDescriptor.h>
#include <CAnimManager.h> #include <CAnimManager.h>
@ -22,9 +20,18 @@
#ifdef GTASA #ifdef GTASA
#include "overlay.h" #include "overlay.h"
void Cutscene::Init()
{
static CdeclEvent <AddressList<0x5B195F, H_JUMP>, PRIORITY_AFTER, ArgPickNone, void()> skipCutsceneEvent;
skipCutsceneEvent += []()
{
Stop();
};
}
void Cutscene::Play(std::string& rootKey, std::string& cutsceneId, std::string& interior) void Cutscene::Play(std::string& rootKey, std::string& cutsceneId, std::string& interior)
{ {
if (Util::IsOnCutscene()) if (CCutsceneMgr::ms_running)
{ {
Util::SetMessage(TEXT("Animation.CutsceneRunning")); Util::SetMessage(TEXT("Animation.CutsceneRunning"));
return; return;
@ -33,11 +40,10 @@ void Cutscene::Play(std::string& rootKey, std::string& cutsceneId, std::string&
CPlayerPed* pPlayer = FindPlayerPed(); CPlayerPed* pPlayer = FindPlayerPed();
if (pPlayer) if (pPlayer)
{ {
m_SceneName = cutsceneId;
m_pLastVeh = pPlayer->m_nPedFlags.bInVehicle ? pPlayer->m_pVehicle : nullptr; m_pLastVeh = pPlayer->m_nPedFlags.bInVehicle ? pPlayer->m_pVehicle : nullptr;
m_nVehSeat = -1; m_nVehSeat = -1;
if (m_pLastVeh->m_pDriver != pPlayer) if (m_pLastVeh && m_pLastVeh->m_pDriver != pPlayer)
{ {
for (size_t i = 0; i != 8; ++i) for (size_t i = 0; i != 8; ++i)
{ {
@ -48,10 +54,44 @@ void Cutscene::Play(std::string& rootKey, std::string& cutsceneId, std::string&
} }
} }
} }
Command<Commands::LOAD_CUTSCENE>(cutsceneId.c_str()); CCutsceneMgr::LoadCutsceneData(cutsceneId.c_str());
CCutsceneMgr::Update();
m_nInterior = pPlayer->m_nAreaCode; m_nInterior = pPlayer->m_nAreaCode;
pPlayer->m_nAreaCode = std::stoi(interior); pPlayer->m_nAreaCode = std::stoi(interior);
Command<Commands::SET_AREA_VISIBLE>(pPlayer->m_nAreaCode); Command<Commands::SET_AREA_VISIBLE>(pPlayer->m_nAreaCode);
Cutscene::m_bRunning = true;
CCutsceneMgr::StartCutscene();
}
}
void Cutscene::Stop()
{
if (Cutscene::m_bRunning)
{
CPlayerPed *pPlayer = FindPlayerPed();
int hPlayer = CPools::GetPedRef(pPlayer);
CCutsceneMgr::DeleteCutsceneData();
Cutscene::m_bRunning = false;
pPlayer->m_nAreaCode = Cutscene::m_nInterior;
Cutscene::m_nInterior = 0;
Command<Commands::SET_AREA_VISIBLE>(pPlayer->m_nAreaCode);
// handle vehicle
if (Cutscene::m_pLastVeh)
{
int hVeh = CPools::GetVehicleRef(Cutscene::m_pLastVeh);
if (Cutscene::m_nVehSeat == -1)
{
Command<Commands::WARP_CHAR_INTO_CAR>(hPlayer, hVeh);
}
else
{
Command<Commands::WARP_CHAR_INTO_CAR_AS_PASSENGER>(hPlayer, hVeh, Cutscene::m_nVehSeat);
}
}
TheCamera.Fade(0, 1);
} }
} }
@ -64,10 +104,25 @@ void Particle::Play(std::string& cat, std::string& name, std::string& particle)
int handle; int handle;
Command<Commands::CREATE_FX_SYSTEM>(particle.c_str(), pos.x, pos.y, pos.z, 1, &handle); Command<Commands::CREATE_FX_SYSTEM>(particle.c_str(), pos.x, pos.y, pos.z, 1, &handle);
Command<Commands::PLAY_FX_SYSTEM>(handle); Command<Commands::PLAY_FX_SYSTEM>(handle);
m_nParticleList.push_back(handle); m_nList.push_back(handle);
} }
} }
void Particle::RemoveAll()
{
for (int& p : Particle::m_nList)
{
Command<Commands::KILL_FX_SYSTEM>(p);
}
Particle::m_nList.clear();
}
void Particle::RemoveLatest()
{
Command<Commands::KILL_FX_SYSTEM>(Particle::m_nList.back()); // stop if anything is running
Particle::m_nList.pop_back();
}
#elif GTAVC #elif GTAVC
// Thanks to codenulls(https://github.com/codenulls/) // Thanks to codenulls(https://github.com/codenulls/)
@ -178,14 +233,14 @@ void _PlayAnim(RpClump* pClump, int animGroup, int animID, float blend, bool loo
void Animation::Play(std::string& cat, std::string& anim, std::string& ifp) void Animation::Play(std::string& cat, std::string& anim, std::string& ifp)
{ {
CPed *pPed = m_PedAnim ? m_pTarget : FindPlayerPed(); CPed *pPed = m_bPedAnim ? m_pTarget : FindPlayerPed();
if (!pPed) if (!pPed)
{ {
return; return;
} }
#ifdef GTASA #ifdef GTASA
int hped = CPools::GetPedRef(pPed); int hPed = CPools::GetPedRef(pPed);
if (ifp != "PED") if (ifp != "PED")
{ {
@ -193,14 +248,14 @@ void Animation::Play(std::string& cat, std::string& anim, std::string& ifp)
Command<Commands::LOAD_ALL_MODELS_NOW>(); Command<Commands::LOAD_ALL_MODELS_NOW>();
} }
Command<Commands::CLEAR_CHAR_TASKS>(hped); Command<Commands::CLEAR_CHAR_TASKS>(hPed);
if (m_bSecondary) if (m_bSecondary)
{ {
Command<Commands::TASK_PLAY_ANIM_SECONDARY>(hped, anim.c_str(), ifp.c_str(), 4.0, m_Loop, 0, 0, 0, -1); Command<Commands::TASK_PLAY_ANIM_SECONDARY>(hPed, anim.c_str(), ifp.c_str(), 4.0, m_Loop, 0, 0, 0, -1);
} }
else else
{ {
Command<Commands::TASK_PLAY_ANIM>(hped, anim.c_str(), ifp.c_str(), 4.0, m_Loop, 0, 0, 0, -1); Command<Commands::TASK_PLAY_ANIM>(hPed, anim.c_str(), ifp.c_str(), 4.0, m_Loop, 0, 0, 0, -1);
} }
if (ifp != "PED") if (ifp != "PED")
@ -218,32 +273,10 @@ void Animation::Play(std::string& cat, std::string& anim, std::string& ifp)
void Animation::Init() void Animation::Init()
{ {
#ifdef GTASA #ifdef GTASA
Cutscene::Init();
Events::processScriptsEvent += [] Events::processScriptsEvent += []
{ {
CPlayerPed* pPlayer = FindPlayerPed(); CPlayerPed* pPlayer = FindPlayerPed();
if (Cutscene::m_bRunning)
{
if (Command<Commands::HAS_CUTSCENE_FINISHED>())
{
if (!pPlayer)
{
return;
}
pPlayer->m_nAreaCode = Cutscene::m_nInterior;
Command<Commands::SET_AREA_VISIBLE>(pPlayer->m_nAreaCode);
Cutscene::m_nInterior = 0;
TheCamera.Fade(0, 1);
}
}
else
{
if (Cutscene::m_SceneName != "" && Command<Commands::HAS_CUTSCENE_LOADED>())
{
Command<Commands::START_CUTSCENE>();
Cutscene::m_bRunning = true;
}
}
if (pPlayer && pPlayer->m_pPlayerTargettedPed) if (pPlayer && pPlayer->m_pPlayerTargettedPed)
{ {
@ -277,8 +310,6 @@ void Animation::ShowPage()
CPlayerPed* pPlayer = FindPlayerPed(); CPlayerPed* pPlayer = FindPlayerPed();
int hPlayer = CPools::GetPedRef(pPlayer); int hPlayer = CPools::GetPedRef(pPlayer);
ImGui::Spacing();
if (ImGui::BeginTabItem(TEXT("Animation.AnimationTab"))) if (ImGui::BeginTabItem(TEXT("Animation.AnimationTab")))
{ {
ImGui::Spacing(); ImGui::Spacing();
@ -300,12 +331,12 @@ void Animation::ShowPage()
Widget::Checkbox(TEXT("Animation.SecondaryCheckbox"), &m_bSecondary, TEXT("Animation.SecondaryCheckboxText")); Widget::Checkbox(TEXT("Animation.SecondaryCheckbox"), &m_bSecondary, TEXT("Animation.SecondaryCheckboxText"));
ImGui::NextColumn(); ImGui::NextColumn();
#ifdef GTASA #ifdef GTASA
Widget::Checkbox(TEXT("Animation.PedAnim"), &m_PedAnim, TEXT("Animation.PedAnimText")); Widget::Checkbox(TEXT("Animation.PedAnim"), &m_bPedAnim, TEXT("Animation.PedAnimText"));
#endif #endif
ImGui::Columns(1); ImGui::Columns(1);
ImGui::Spacing(); ImGui::Spacing();
if (m_PedAnim && !m_pTarget) if (m_bPedAnim && !m_pTarget)
{ {
ImGui::TextWrapped(TEXT("Animation.NoTarget")); ImGui::TextWrapped(TEXT("Animation.NoTarget"));
} }
@ -343,15 +374,14 @@ void Animation::ShowPage()
ImGui::Spacing(); ImGui::Spacing();
Widget::Checkbox(TEXT("Menu.ShowPedTasks"), &Overlay::m_bPedTasks); Widget::Checkbox(TEXT("Menu.ShowPedTasks"), &Overlay::m_bPedTasks);
ImGui::Spacing(); ImGui::Spacing();
CPlayerPed* player = FindPlayerPed(); if (pPlayer)
if (player)
{ {
ImGui::BeginChild("TasksList"); ImGui::BeginChild("TasksList");
ImGui::Text(TEXT("Animation.PrimaryTasks")); ImGui::Text(TEXT("Animation.PrimaryTasks"));
ImGui::Separator(); ImGui::Separator();
for (size_t i = 0; i != TASK_PRIMARY_MAX; ++i) for (size_t i = 0; i != TASK_PRIMARY_MAX; ++i)
{ {
CTask *pTask = player->m_pIntelligence->m_TaskMgr.m_aPrimaryTasks[i]; CTask *pTask = pPlayer->m_pIntelligence->m_TaskMgr.m_aPrimaryTasks[i];
if (pTask) if (pTask)
{ {
const char *name = taskNames[pTask->GetId()]; const char *name = taskNames[pTask->GetId()];
@ -369,7 +399,7 @@ void Animation::ShowPage()
ImGui::Separator(); ImGui::Separator();
for (size_t i = 0; i != TASK_SECONDARY_MAX; ++i) for (size_t i = 0; i != TASK_SECONDARY_MAX; ++i)
{ {
CTask *pTask = player->m_pIntelligence->m_TaskMgr.m_aSecondaryTasks[i]; CTask *pTask = pPlayer->m_pIntelligence->m_TaskMgr.m_aSecondaryTasks[i];
if (pTask) if (pTask)
{ {
const char *name = taskNames[pTask->GetId()]; const char *name = taskNames[pTask->GetId()];
@ -389,28 +419,7 @@ void Animation::ShowPage()
ImGui::Spacing(); ImGui::Spacing();
if (ImGui::Button(TEXT("Animation.StopCutscene"), Widget::CalcSize())) if (ImGui::Button(TEXT("Animation.StopCutscene"), Widget::CalcSize()))
{ {
if (Cutscene::m_bRunning) Cutscene::Stop();
{
CPlayerPed* player = FindPlayerPed();
int hPlayer = CPools::GetPedRef(player);
int hVeh = CPools::GetVehicleRef(Cutscene::m_pLastVeh);
Command<Commands::CLEAR_CUTSCENE>();
Cutscene::m_bRunning = false;
Cutscene::m_SceneName = "";
player->m_nAreaCode = Cutscene::m_nInterior;
Command<Commands::SET_AREA_VISIBLE>(player->m_nAreaCode);
if (Cutscene::m_nVehSeat == -1)
{
Command<Commands::WARP_CHAR_INTO_CAR>(hPlayer, hVeh);
}
else
{
Command<Commands::WARP_CHAR_INTO_CAR_AS_PASSENGER>(hPlayer, hVeh, Cutscene::m_nVehSeat);
}
Cutscene::m_nInterior = 0;
TheCamera.Fade(0, 1);
}
} }
ImGui::Spacing(); ImGui::Spacing();
@ -427,17 +436,12 @@ void Animation::ShowPage()
ImGui::Spacing(); ImGui::Spacing();
if (ImGui::Button(TEXT("Animation.RemoveAll"), Widget::CalcSize(2))) if (ImGui::Button(TEXT("Animation.RemoveAll"), Widget::CalcSize(2)))
{ {
for (int& p : Particle::m_nParticleList) Particle::RemoveAll();
{
Command<Commands::KILL_FX_SYSTEM>(p);
}
Particle::m_nParticleList.clear();
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(TEXT("Animation.RemoveLatest"), Widget::CalcSize(2))) if (ImGui::Button(TEXT("Animation.RemoveLatest"), Widget::CalcSize(2)))
{ {
Command<Commands::KILL_FX_SYSTEM>(Particle::m_nParticleList.back()); // stop if anything is running Particle::RemoveLatest();
Particle::m_nParticleList.pop_back();
} }
ImGui::Spacing(); ImGui::Spacing();
if (Widget::CheckboxBits(TEXT("Animation.InvisiblePlayer"), pPlayer->m_nPedFlags.bDontRender)) if (Widget::CheckboxBits(TEXT("Animation.InvisiblePlayer"), pPlayer->m_nPedFlags.bDontRender))

View File

@ -2,48 +2,85 @@
#include "pch.h" #include "pch.h"
#ifdef GTASA #ifdef GTASA
/*
Cutscene Player Class for SA
Plays mission cutscenes
*/
class Cutscene class Cutscene
{ {
public: private:
static inline ResourceStore m_Data{ "cutscenes", eResourceType::TYPE_TEXT }; static inline bool m_bRunning; // is cutscene currently running
static inline std::string m_SceneName;
static inline int m_nInterior; // player interior backup
static inline bool m_bRunning;
static inline CVehicle *m_pLastVeh;
static inline int m_nVehSeat;
static void Play(std::string& rootKey, std::string& cutsceneId, std::string& interior); // backup data
static inline int m_nInterior; // interior player was in
static inline CVehicle *m_pLastVeh; // vehicle player was in
static inline int m_nVehSeat; // seat id of player vehicle
public:
static inline ResourceStore m_Data{ "cutscenes", eResourceType::TYPE_TEXT }; // names
Cutscene() = delete;
Cutscene(const Cutscene&) = delete;
// Initializes hooks, vars etc.
static void Init();
// Plays a cutscene
static void Play(std::string& cat, std::string& key, std::string& val);
// Stops a running cutscene
static void Stop();
}; };
/*
Particle Player Class for SA
Spawns particles in the world
*/
class Particle class Particle
{ {
public: private:
static inline ResourceStore m_Data{ "particles", eResourceType::TYPE_TEXT }; static inline std::vector<int> m_nList;
static inline std::vector<int> m_nParticleList;
static void Play(std::string& rootKey, std::string& particle, std::string& dummy); public:
static inline ResourceStore m_Data{ "particles", eResourceType::TYPE_TEXT }; // names
Particle() = delete;
Particle(const Particle&) = delete;
// Plays a particle
static void Play(std::string& cat, std::string& key, std::string& val);
// Removes all spawned particles
static void RemoveAll();
// Removes the most recent spawned particle
static void RemoveLatest();
}; };
#endif #endif
/*
Animation Player Class
Plays animatins on player & peds
*/
class Animation class Animation
{ {
private: private:
static inline ResourceStore m_AnimData{ "animations", eResourceType::TYPE_TEXT }; static inline ResourceStore m_AnimData{ "animations", eResourceType::TYPE_TEXT };
static inline bool m_Loop; // loop animation static inline bool m_Loop; // keep playing animation in a loop
static inline bool m_bSecondary; // play animation as secondary static inline bool m_bSecondary; // play animation alongside another
static inline bool m_PedAnim; static inline bool m_bPedAnim; // play the animation on a target ped
static inline CPed *m_pTarget = nullptr; static inline CPed *m_pTarget = nullptr; // target ped pointer
static void Play(std::string& rootKey, std::string& anim, std::string& ifp); // Plays a particular animation
static void Play(std::string& cat, std::string& key, std::string& val);
#ifdef GTASA
static void DrawPedTasks();
#endif
public: public:
Animation() = delete; Animation() = delete;
Animation(const Animation&) = delete; Animation(const Animation&) = delete;
// Initializes hooks & stuff
static void Init(); static void Init();
// Displays animation menu page
static void ShowPage(); static void ShowPage();
}; };

View File

@ -9,7 +9,7 @@
#define MENU_NAME "Cheat Menu" #define MENU_NAME "Cheat Menu"
#define MENU_VERSION_NUMBER "3.3" #define MENU_VERSION_NUMBER "3.3"
#define MENU_VERSION MENU_VERSION_NUMBER"-beta" #define MENU_VERSION MENU_VERSION_NUMBER"-beta"
#define BUILD_NUMBER "20220721" #define BUILD_NUMBER "20220805"
#define MENU_TITLE MENU_NAME " v" MENU_VERSION #define MENU_TITLE MENU_NAME " v" MENU_VERSION
#ifdef GTASA #ifdef GTASA

View File

@ -11,8 +11,6 @@
void Overlay::Init() void Overlay::Init()
{ {
// TODO: use structs
// Load config data
m_bCoord = gConfig.Get("Overlay.ShowCoordinates", false); m_bCoord = gConfig.Get("Overlay.ShowCoordinates", false);
m_bCpuUsage = gConfig.Get("Overlay.ShowCPUUsage", false); m_bCpuUsage = gConfig.Get("Overlay.ShowCPUUsage", false);
m_bFPS = gConfig.Get("Overlay.ShowFPS", false); m_bFPS = gConfig.Get("Overlay.ShowFPS", false);