2020-12-02 16:19:16 -05:00
|
|
|
#include "pch.h"
|
|
|
|
#include "Animation.h"
|
2021-08-09 14:26:49 -04:00
|
|
|
#ifdef GTASA
|
2021-01-03 06:48:07 -05:00
|
|
|
#include "Ui.h"
|
|
|
|
#include "Util.h"
|
2020-12-02 16:19:16 -05:00
|
|
|
|
2021-06-19 09:00:13 -04:00
|
|
|
Animation::Animation()
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
m_AnimData.m_Json.LoadData(m_AnimData.m_Categories, m_AnimData.m_Selected);
|
2021-06-19 09:00:13 -04:00
|
|
|
m_Cutscene::m_Data.m_Json.LoadData(m_Cutscene::m_Data.m_Categories, m_Cutscene::m_Data.m_Selected);
|
2021-04-25 14:59:14 -04:00
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
Events::processScriptsEvent += [this]
|
2021-04-25 14:59:14 -04:00
|
|
|
{
|
2021-06-19 09:00:13 -04:00
|
|
|
if (m_Cutscene::m_bRunning)
|
2021-04-25 14:59:14 -04:00
|
|
|
{
|
|
|
|
if (Command<Commands::HAS_CUTSCENE_FINISHED>())
|
|
|
|
{
|
|
|
|
Command<Commands::CLEAR_CUTSCENE>();
|
2021-06-19 09:00:13 -04:00
|
|
|
m_Cutscene::m_bRunning = false;
|
|
|
|
m_Cutscene::m_SceneName = "";
|
2021-04-25 14:59:14 -04:00
|
|
|
CPlayerPed* player = FindPlayerPed();
|
2021-06-19 09:00:13 -04:00
|
|
|
player->m_nAreaCode = m_Cutscene::m_nInterior;
|
2021-04-25 14:59:14 -04:00
|
|
|
Command<Commands::SET_AREA_VISIBLE>(player->m_nAreaCode);
|
2021-06-19 09:00:13 -04:00
|
|
|
m_Cutscene::m_nInterior = 0;
|
2021-04-25 14:59:14 -04:00
|
|
|
TheCamera.Fade(0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-19 09:00:13 -04:00
|
|
|
if (m_Cutscene::m_SceneName != "" && Command<Commands::HAS_CUTSCENE_LOADED>())
|
2021-04-25 14:59:14 -04:00
|
|
|
{
|
|
|
|
Command<Commands::START_CUTSCENE>();
|
2021-06-19 09:00:13 -04:00
|
|
|
m_Cutscene::m_bRunning = true;
|
2021-04-25 14:59:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-19 09:00:13 -04:00
|
|
|
void Animation::PlayCutscene(std::string& rootKey, std::string& cutsceneId, std::string& interior)
|
2021-04-25 14:59:14 -04:00
|
|
|
{
|
|
|
|
if (Util::IsOnCutscene())
|
|
|
|
{
|
2021-08-01 21:41:48 -04:00
|
|
|
SetHelpMessage("Another cutscene is running", false, false, false);
|
2021-04-25 14:59:14 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-19 09:00:13 -04:00
|
|
|
m_Cutscene::m_SceneName = cutsceneId;
|
2021-06-18 12:49:11 -04:00
|
|
|
Command<Commands::LOAD_CUTSCENE>(cutsceneId.c_str());
|
|
|
|
CPlayerPed* pPlayer = FindPlayerPed();
|
2021-06-19 09:00:13 -04:00
|
|
|
m_Cutscene::m_nInterior = pPlayer->m_nAreaCode;
|
2021-06-18 12:49:11 -04:00
|
|
|
pPlayer->m_nAreaCode = std::stoi(interior);
|
|
|
|
Command<Commands::SET_AREA_VISIBLE>(pPlayer->m_nAreaCode);
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
|
|
|
|
2021-06-19 09:00:13 -04:00
|
|
|
void Animation::Draw()
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
|
|
|
if (ImGui::BeginTabBar("Animation", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll))
|
|
|
|
{
|
|
|
|
ImGui::Spacing();
|
2021-07-06 05:13:38 -04:00
|
|
|
CPlayerPed* pPlayer = FindPlayerPed();
|
|
|
|
int hPlayer = CPools::GetPedRef(pPlayer);
|
2020-12-02 16:19:16 -05:00
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
if (ImGui::BeginTabItem("Anims"))
|
|
|
|
{
|
|
|
|
ImGui::Spacing();
|
|
|
|
if (ImGui::Button("Stop animation", Ui::GetSize()))
|
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
if (hPlayer)
|
|
|
|
Command<Commands::CLEAR_CHAR_TASKS>(hPlayer);
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
ImGui::Columns(2, nullptr, false);
|
|
|
|
ImGui::Checkbox("Loop", &m_Loop);
|
2021-06-19 09:00:13 -04:00
|
|
|
Ui::ShowTooltip("Keep playing the animation on repeat");
|
2020-12-02 16:19:16 -05:00
|
|
|
ImGui::NextColumn();
|
2021-06-18 12:49:11 -04:00
|
|
|
ImGui::Checkbox("Secondary", &m_bSecondary);
|
2021-06-19 09:00:13 -04:00
|
|
|
Ui::ShowTooltip("Player can move while playing the animation");
|
2020-12-02 16:19:16 -05:00
|
|
|
ImGui::Columns(1);
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
if (ImGui::BeginChild("Anims Child"))
|
|
|
|
{
|
|
|
|
ImGui::Spacing();
|
2021-08-07 12:01:44 -04:00
|
|
|
Ui::DrawJSON(m_AnimData, PlayAnimation, RemoveAnimation);
|
2020-12-02 16:19:16 -05:00
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::BeginTabItem("Misc"))
|
|
|
|
{
|
|
|
|
ImGui::Spacing();
|
2021-06-19 09:00:13 -04:00
|
|
|
if (Ui::ListBox("Fighting style", m_FightingStyleList, m_nFightingStyle))
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
Command<Commands::GIVE_MELEE_ATTACK_TO_CHAR>(hPlayer, m_nFightingStyle + 4, 6);
|
2021-08-01 21:41:48 -04:00
|
|
|
SetHelpMessage("Fighting anim set", false, false, false);
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
2021-06-19 09:00:13 -04:00
|
|
|
if (Ui::ListBoxStr("Walking style", m_WalkingStyleList, m_nWalkingStyle))
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
if (m_nWalkingStyle == "default")
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
2021-07-06 05:13:38 -04:00
|
|
|
patch::Set<DWORD>(0x609A4E, 0x4D48689);
|
|
|
|
patch::Set<WORD>(0x609A52, 0);
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-06 05:13:38 -04:00
|
|
|
patch::Nop(0x609A4E, 6);
|
2021-06-18 12:49:11 -04:00
|
|
|
Command<Commands::REQUEST_ANIMATION>(m_nWalkingStyle.c_str());
|
2020-12-02 16:19:16 -05:00
|
|
|
Command<Commands::LOAD_ALL_MODELS_NOW>();
|
2021-06-18 12:49:11 -04:00
|
|
|
Command<Commands::SET_ANIM_GROUP_FOR_CHAR>(hPlayer, m_nWalkingStyle.c_str());
|
|
|
|
Command<Commands::REMOVE_ANIMATION>(m_nWalkingStyle.c_str());
|
2021-02-24 16:54:45 -05:00
|
|
|
}
|
2021-08-01 21:41:48 -04:00
|
|
|
SetHelpMessage("Walking anim set", false, false, false);
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::BeginTabItem("Custom"))
|
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
ImGui::InputTextWithHint("IFP name", "ped", m_nIfpBuffer, INPUT_BUFFER_SIZE);
|
|
|
|
ImGui::InputTextWithHint("Anim name", "cower", m_nAnimBuffer, INPUT_BUFFER_SIZE);
|
2020-12-02 16:19:16 -05:00
|
|
|
ImGui::Spacing();
|
|
|
|
if (ImGui::Button("Add animation", Ui::GetSize()))
|
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
m_AnimData.m_Json.m_Data["Custom"][m_nAnimBuffer] = ("0, " + std::string(m_nIfpBuffer));
|
|
|
|
m_AnimData.m_Json.WriteToDisk();
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
2021-04-25 14:59:14 -04:00
|
|
|
if (ImGui::BeginTabItem("Cutscene"))
|
|
|
|
{
|
|
|
|
ImGui::Spacing();
|
|
|
|
if (ImGui::Button("Stop cutscene", Ui::GetSize()))
|
|
|
|
{
|
2021-06-19 09:00:13 -04:00
|
|
|
if (m_Cutscene::m_bRunning)
|
2021-04-25 14:59:14 -04:00
|
|
|
{
|
|
|
|
Command<Commands::CLEAR_CUTSCENE>();
|
2021-06-19 09:00:13 -04:00
|
|
|
m_Cutscene::m_bRunning = false;
|
|
|
|
m_Cutscene::m_SceneName = "";
|
2021-04-25 14:59:14 -04:00
|
|
|
CPlayerPed* player = FindPlayerPed();
|
2021-06-19 09:00:13 -04:00
|
|
|
player->m_nAreaCode = m_Cutscene::m_nInterior;
|
2021-04-25 14:59:14 -04:00
|
|
|
Command<Commands::SET_AREA_VISIBLE>(player->m_nAreaCode);
|
2021-06-19 09:00:13 -04:00
|
|
|
m_Cutscene::m_nInterior = 0;
|
2021-04-25 14:59:14 -04:00
|
|
|
TheCamera.Fade(0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
if (ImGui::BeginChild("Cutscene Child"))
|
|
|
|
{
|
|
|
|
ImGui::Spacing();
|
2021-08-07 12:01:44 -04:00
|
|
|
Ui::DrawJSON(m_Cutscene::m_Data, PlayCutscene, nullptr);
|
2021-04-25 14:59:14 -04:00
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
2020-12-02 16:19:16 -05:00
|
|
|
ImGui::EndTabBar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-19 09:00:13 -04:00
|
|
|
void Animation::PlayAnimation(std::string& ifp, std::string& anim, std::string& ifpRepeat)
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
|
|
|
int hplayer = CPools::GetPedRef(FindPlayerPed());
|
|
|
|
|
|
|
|
if (ifp != "PED")
|
|
|
|
{
|
|
|
|
Command<Commands::REQUEST_ANIMATION>(ifp.c_str());
|
|
|
|
Command<Commands::LOAD_ALL_MODELS_NOW>();
|
|
|
|
}
|
|
|
|
|
|
|
|
Command<Commands::CLEAR_CHAR_TASKS>(hplayer);
|
2021-06-18 12:49:11 -04:00
|
|
|
if (m_bSecondary)
|
|
|
|
Command<Commands::TASK_PLAY_ANIM_SECONDARY>(hplayer, anim.c_str(), ifp.c_str(), 4.0, m_Loop, 0, 0, 0, -1);
|
2020-12-02 16:19:16 -05:00
|
|
|
else
|
2021-06-18 12:49:11 -04:00
|
|
|
Command<Commands::TASK_PLAY_ANIM>(hplayer, anim.c_str(), ifp.c_str(), 4.0, m_Loop, 0, 0, 0, -1);
|
2021-02-24 16:54:45 -05:00
|
|
|
|
2020-12-02 16:19:16 -05:00
|
|
|
if (ifp != "PED")
|
|
|
|
Command<Commands::REMOVE_ANIMATION>(ifp.c_str());
|
|
|
|
}
|
|
|
|
|
2021-06-19 09:00:13 -04:00
|
|
|
void Animation::RemoveAnimation(std::string& ifp, std::string& anim, std::string& ifpRepeat)
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
|
|
|
if (ifp == "Custom")
|
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
m_AnimData.m_Json.m_Data["Custom"].erase(anim);
|
|
|
|
m_AnimData.m_Json.WriteToDisk();
|
2021-08-01 21:41:48 -04:00
|
|
|
SetHelpMessage("Animation removed", false, false, false);
|
2021-06-18 12:49:11 -04:00
|
|
|
}
|
|
|
|
else
|
2021-08-01 21:41:48 -04:00
|
|
|
SetHelpMessage("You can only remove custom anims", false, false, false);
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
2021-08-09 14:26:49 -04:00
|
|
|
#endif
|