CheatMenuSA/src/Animation.cpp

197 lines
5.6 KiB
C++
Raw Normal View History

2020-12-02 16:19:16 -05:00
#include "pch.h"
#include "Animation.h"
#include "Ui.h"
#include "Util.h"
2020-12-02 16:19:16 -05: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);
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
{
if (m_Cutscene::m_bRunning)
2021-04-25 14:59:14 -04:00
{
if (Command<Commands::HAS_CUTSCENE_FINISHED>())
{
Command<Commands::CLEAR_CUTSCENE>();
m_Cutscene::m_bRunning = false;
m_Cutscene::m_SceneName = "";
2021-04-25 14:59:14 -04:00
CPlayerPed* player = FindPlayerPed();
player->m_nAreaCode = m_Cutscene::m_nInterior;
2021-04-25 14:59:14 -04:00
Command<Commands::SET_AREA_VISIBLE>(player->m_nAreaCode);
m_Cutscene::m_nInterior = 0;
2021-04-25 14:59:14 -04:00
TheCamera.Fade(0, 1);
}
}
else
{
if (m_Cutscene::m_SceneName != "" && Command<Commands::HAS_CUTSCENE_LOADED>())
2021-04-25 14:59:14 -04:00
{
Command<Commands::START_CUTSCENE>();
m_Cutscene::m_bRunning = true;
2021-04-25 14:59:14 -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())
{
CHud::SetHelpMessage("Another cutscene is running", false, false, false);
return;
}
m_Cutscene::m_SceneName = cutsceneId;
2021-06-18 12:49:11 -04:00
Command<Commands::LOAD_CUTSCENE>(cutsceneId.c_str());
CPlayerPed* pPlayer = FindPlayerPed();
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
}
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);
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);
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-06-18 12:49:11 -04:00
Ui::DrawJSON(m_AnimData.m_Json, m_AnimData.m_Categories, m_AnimData.m_Selected, m_AnimData.m_Filter, &PlayAnimation,
&RemoveAnimation);
2020-12-02 16:19:16 -05:00
ImGui::EndChild();
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Misc"))
{
ImGui::Spacing();
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-02-24 16:54:45 -05:00
CHud::SetHelpMessage("Fighting anim set", false, false, false);
2020-12-02 16:19:16 -05: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
}
2020-12-02 16:19:16 -05:00
CHud::SetHelpMessage("Walking anim set", false, false, false);
}
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()))
{
if (m_Cutscene::m_bRunning)
2021-04-25 14:59:14 -04:00
{
Command<Commands::CLEAR_CUTSCENE>();
m_Cutscene::m_bRunning = false;
m_Cutscene::m_SceneName = "";
2021-04-25 14:59:14 -04:00
CPlayerPed* player = FindPlayerPed();
player->m_nAreaCode = m_Cutscene::m_nInterior;
2021-04-25 14:59:14 -04:00
Command<Commands::SET_AREA_VISIBLE>(player->m_nAreaCode);
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();
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);
2021-04-25 14:59:14 -04:00
ImGui::EndChild();
}
ImGui::EndTabItem();
}
2020-12-02 16:19:16 -05:00
ImGui::EndTabBar();
}
}
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());
}
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();
2020-12-02 16:19:16 -05:00
CHud::SetHelpMessage("Animation removed", false, false, false);
2021-06-18 12:49:11 -04:00
}
else
2021-03-08 07:09:50 -05:00
CHud::SetHelpMessage("You can only remove custom anims", false, false, false);
2020-12-02 16:19:16 -05:00
}