#include "pch.h" #include "Animation.h" #include "Ui.h" #include "Util.h" Animation::Animation() { m_AnimData.m_Json.LoadData(m_AnimData.m_Categories, m_AnimData.m_Selected); m_Cutscene::m_Data.m_Json.LoadData(m_Cutscene::m_Data.m_Categories, m_Cutscene::m_Data.m_Selected); Events::processScriptsEvent += [this] { if (m_Cutscene::m_bRunning) { if (Command()) { Command(); m_Cutscene::m_bRunning = false; m_Cutscene::m_SceneName = ""; CPlayerPed* player = FindPlayerPed(); player->m_nAreaCode = m_Cutscene::m_nInterior; Command(player->m_nAreaCode); m_Cutscene::m_nInterior = 0; TheCamera.Fade(0, 1); } } else { if (m_Cutscene::m_SceneName != "" && Command()) { Command(); m_Cutscene::m_bRunning = true; } } }; } void Animation::PlayCutscene(std::string& rootKey, std::string& cutsceneId, std::string& interior) { if (Util::IsOnCutscene()) { CHud::SetHelpMessage("Another cutscene is running", false, false, false); return; } m_Cutscene::m_SceneName = cutsceneId; Command(cutsceneId.c_str()); CPlayerPed* pPlayer = FindPlayerPed(); m_Cutscene::m_nInterior = pPlayer->m_nAreaCode; pPlayer->m_nAreaCode = std::stoi(interior); Command(pPlayer->m_nAreaCode); } void Animation::Draw() { if (ImGui::BeginTabBar("Animation", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) { ImGui::Spacing(); CPlayerPed* pPlayer = FindPlayerPed(); int hPlayer = CPools::GetPedRef(pPlayer); ImGui::Spacing(); if (ImGui::BeginTabItem("Anims")) { ImGui::Spacing(); if (ImGui::Button("Stop animation", Ui::GetSize())) { if (hPlayer) Command(hPlayer); } ImGui::Spacing(); ImGui::Columns(2, nullptr, false); ImGui::Checkbox("Loop", &m_Loop); Ui::ShowTooltip("Keep playing the animation on repeat"); ImGui::NextColumn(); ImGui::Checkbox("Secondary", &m_bSecondary); Ui::ShowTooltip("Player can move while playing the animation"); ImGui::Columns(1); ImGui::Spacing(); if (ImGui::BeginChild("Anims Child")) { ImGui::Spacing(); Ui::DrawJSON(m_AnimData.m_Json, m_AnimData.m_Categories, m_AnimData.m_Selected, m_AnimData.m_Filter, &PlayAnimation, &RemoveAnimation); ImGui::EndChild(); } ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Misc")) { ImGui::Spacing(); if (Ui::ListBox("Fighting style", m_FightingStyleList, m_nFightingStyle)) { Command(hPlayer, m_nFightingStyle + 4, 6); CHud::SetHelpMessage("Fighting anim set", false, false, false); } if (Ui::ListBoxStr("Walking style", m_WalkingStyleList, m_nWalkingStyle)) { if (m_nWalkingStyle == "default") { patch::Set(0x609A4E, 0x4D48689); patch::Set(0x609A52, 0); } else { patch::Nop(0x609A4E, 6); Command(m_nWalkingStyle.c_str()); Command(); Command(hPlayer, m_nWalkingStyle.c_str()); Command(m_nWalkingStyle.c_str()); } CHud::SetHelpMessage("Walking anim set", false, false, false); } ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Custom")) { ImGui::InputTextWithHint("IFP name", "ped", m_nIfpBuffer, INPUT_BUFFER_SIZE); ImGui::InputTextWithHint("Anim name", "cower", m_nAnimBuffer, INPUT_BUFFER_SIZE); ImGui::Spacing(); if (ImGui::Button("Add animation", Ui::GetSize())) { m_AnimData.m_Json.m_Data["Custom"][m_nAnimBuffer] = ("0, " + std::string(m_nIfpBuffer)); m_AnimData.m_Json.WriteToDisk(); } ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Cutscene")) { ImGui::Spacing(); if (ImGui::Button("Stop cutscene", Ui::GetSize())) { if (m_Cutscene::m_bRunning) { Command(); m_Cutscene::m_bRunning = false; m_Cutscene::m_SceneName = ""; CPlayerPed* player = FindPlayerPed(); player->m_nAreaCode = m_Cutscene::m_nInterior; Command(player->m_nAreaCode); m_Cutscene::m_nInterior = 0; TheCamera.Fade(0, 1); } } ImGui::Spacing(); if (ImGui::BeginChild("Cutscene Child")) { ImGui::Spacing(); Ui::DrawJSON(m_Cutscene::m_Data.m_Json, m_Cutscene::m_Data.m_Categories, m_Cutscene::m_Data.m_Selected, m_Cutscene::m_Data.m_Filter, &PlayCutscene, nullptr); ImGui::EndChild(); } ImGui::EndTabItem(); } ImGui::EndTabBar(); } } void Animation::PlayAnimation(std::string& ifp, std::string& anim, std::string& ifpRepeat) { int hplayer = CPools::GetPedRef(FindPlayerPed()); if (ifp != "PED") { Command(ifp.c_str()); Command(); } Command(hplayer); if (m_bSecondary) Command(hplayer, anim.c_str(), ifp.c_str(), 4.0, m_Loop, 0, 0, 0, -1); else Command(hplayer, anim.c_str(), ifp.c_str(), 4.0, m_Loop, 0, 0, 0, -1); if (ifp != "PED") Command(ifp.c_str()); } void Animation::RemoveAnimation(std::string& ifp, std::string& anim, std::string& ifpRepeat) { if (ifp == "Custom") { m_AnimData.m_Json.m_Data["Custom"].erase(anim); m_AnimData.m_Json.WriteToDisk(); CHud::SetHelpMessage("Animation removed", false, false, false); } else CHud::SetHelpMessage("You can only remove custom anims", false, false, false); }