Skip to content

Commit

Permalink
Small changes & features (#42)
Browse files Browse the repository at this point in the history
* Fixed spectating

* Added some features

* Animated notifications

* Temporary colors for notifications

* Added TpMountToSelf
  • Loading branch information
DayibBaba authored Oct 14, 2023
1 parent a5a1ec2 commit ac6ebd9
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 134 deletions.
56 changes: 40 additions & 16 deletions src/core/frontend/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,47 @@ namespace YimMenu
static void DrawNotification(Notification& notification, int position)
{
float y_pos = position * 100;
ImVec2 cardSize(350, 100);
float x_pos = 10;
ImVec2 cardSize(m_CardSizeX, m_CardSizeY);

ImGui::SetNextWindowSize(cardSize, ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(10, y_pos + 10), ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(x_pos + notification.m_AnimationOffset, y_pos + 10), ImGuiCond_Always);

std::string windowTitle = "Notification " + std::to_string(position + 1);
ImGui::Begin(windowTitle.c_str(), nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);

auto timeElapsed = (float)std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - notification.m_created_on)
.count();
auto timeElapsed =
(float)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - notification.m_created_on)
.count();

auto depletionProgress = 1.0f - (timeElapsed / (float)notification.m_Duration);

auto depletionProgress = 1.0f - ( timeElapsed / (float) notification.m_Duration);

ImGui::ProgressBar(depletionProgress, ImVec2(-1, 1), "");

// TODO: Add icon for type
auto style = ImGui::GetStyle();
// TODO: Add icon for type instead of colored text
if (notification.m_Type == NotificationType::Info)
ImGui::Text("Info: %s", notification.m_Title.c_str());
{
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::Text(notification.m_Title.c_str());
}
else if (notification.m_Type == NotificationType::Success)
ImGui::Text("Success: %s", notification.m_Title.c_str());
{
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 1.0f, 0.0f, 1.0f));
ImGui::Text(notification.m_Title.c_str());
}
else if (notification.m_Type == NotificationType::Warning)
ImGui::Text("Warning: %s", notification.m_Title.c_str());
{
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.5f, 0.0f, 1.0f));
ImGui::Text(notification.m_Title.c_str());
}
else if (notification.m_Type == NotificationType::Error)
ImGui::Text("Error: %s", notification.m_Title.c_str());
{
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
ImGui::Text(notification.m_Title.c_str());
}

ImGui::PopStyleColor();

ImGui::Separator();

Expand All @@ -70,7 +86,6 @@ namespace YimMenu
if (notification.m_context_function)
{
ImGui::Spacing();
ImGui::Separator();
if (ImGui::Selectable(notification.m_context_function_name.c_str()))
FiberPool::Push([notification] {
notification.m_context_function();
Expand All @@ -82,17 +97,26 @@ namespace YimMenu

void Notifications::DrawImpl()
{
int position = 0;
int position = 0;

for (auto& [id, notification] : m_Notifications)
{
DrawNotification(notification, position);
position++;


if(notification.m_AnimationOffset < 0)
notification.m_AnimationOffset += m_CardAnimationSpeed;

//Need this to account for changes in card size (x dimension), custom increments might result in odd numbers
if(notification.m_AnimationOffset > 0)
notification.m_AnimationOffset = 0.f;

if ((float)std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - notification.m_created_on)
.count()
>= notification.m_Duration)
m_Notifications.erase(id);

position++;
}
}
}
5 changes: 5 additions & 0 deletions src/core/frontend/Notifications.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace YimMenu
{
static inline float m_CardSizeX = 350.f;
static inline float m_CardSizeY = 100.f;
static inline float m_CardAnimationSpeed = 50.f;

enum class NotificationType
{
Info,
Expand All @@ -19,6 +23,7 @@ namespace YimMenu
int m_Duration;
std::function<void()> m_context_function;
std::string m_context_function_name;
float m_AnimationOffset = -m_CardSizeX;

std::string GetIdentifier()
{
Expand Down
25 changes: 25 additions & 0 deletions src/game/features/Features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "game/frontend/GUI.hpp"
#include "game/rdr/Enums.hpp"
#include "game/backend/Players.hpp"
#include "core/frontend/Notifications.hpp"

namespace YimMenu
{
Expand All @@ -29,6 +30,29 @@ namespace YimMenu
Self::Mount = 0;
}

void SpectateTick()
{
if(g_SpectateId != Players::GetSelected().GetId() && g_Spectating)
{
g_SpectateId = Players::GetSelected().GetId();
NETWORK::NETWORK_SET_IN_SPECTATOR_MODE(true, PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(Players::GetSelected().GetId()));
}

if(g_Spectating)
{
if(!NETWORK::NETWORK_IS_IN_SPECTATOR_MODE())
NETWORK::NETWORK_SET_IN_SPECTATOR_MODE(true, PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(Players::GetSelected().GetId()));

if(!Players::GetSelected().IsValid() || !NETWORK::NETWORK_IS_PLAYER_CONNECTED(Players::GetSelected().GetId()))
NETWORK::NETWORK_SET_IN_SPECTATOR_MODE(false, PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(Players::GetSelected().GetId())), g_Spectating = false, Notifications::Show("Spectate", "Player is no longer in the session.\nSpectate mode disabled.", NotificationType::Warning);
}
else
{
if(NETWORK::NETWORK_IS_IN_SPECTATOR_MODE())
NETWORK::NETWORK_SET_IN_SPECTATOR_MODE(false, PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(Players::GetSelected().GetId()));
}
}

void FeatureLoop()
{
while (true)
Expand All @@ -38,6 +62,7 @@ namespace YimMenu
*Pointers.RageSecurityInitialized = false;
Commands::RunLoopedCommands();
g_HotkeySystem.FeatureCommandsHotkeyLoop();
SpectateTick();
ScriptMgr::Yield();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/game/features/Features.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ namespace YimMenu
inline Ped Mount;
}

inline bool g_Spectating = false;
inline int g_SpectateId = -1;

void FeatureLoop();
void BlockControlsForUI();
void SpectateTick();
}
1 change: 1 addition & 0 deletions src/game/features/mount/HorseNoRagdoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace YimMenu::Features
PED::SET_PED_CAN_RAGDOLL(Self::Mount, false);
}

//Doesn't work
virtual void OnDisable() override
{
PED::SET_PED_CAN_RAGDOLL(Self::Mount, true);
Expand Down
27 changes: 27 additions & 0 deletions src/game/features/self/AntiHogtie.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "core/commands/LoopedCommand.hpp"
#include "game/rdr/Natives.hpp"
#include "game/rdr/Enums.hpp"
#include "game/features/Features.hpp"

namespace YimMenu::Features
{
//Needs testing
class AntiHogtie : public LoopedCommand
{
using LoopedCommand::LoopedCommand;

virtual void OnTick() override
{
ENTITY::_SET_ENTITY_CARRYING_FLAG(Self::PlayerPed, (int) eCarryingFlags::CARRYING_FLAG_CAN_BE_HOGTIED, false);

}

//Doesn't work
virtual void OnDisable() override
{
ENTITY::_SET_ENTITY_CARRYING_FLAG(Self::PlayerPed, (int) eCarryingFlags::CARRYING_FLAG_CAN_BE_HOGTIED, true);
}
};

static AntiHogtie _AntiHogtie{"antihogtie", "Anti Hogtie", "Avoid getting hogtied'd by other players"};
}
32 changes: 32 additions & 0 deletions src/game/features/self/AntiLasso.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "core/commands/LoopedCommand.hpp"
#include "game/rdr/Natives.hpp"
#include "game/rdr/Enums.hpp"
#include "game/features/Features.hpp"

namespace YimMenu::Features
{
//Needs testing
class AntiLasso : public LoopedCommand
{
using LoopedCommand::LoopedCommand;

virtual void OnTick() override
{
PED::SET_PED_LASSO_HOGTIE_FLAG(Self::PlayerPed, (int) eLassoFlags::LHF_CAN_BE_LASSOED, false);
PED::SET_PED_LASSO_HOGTIE_FLAG(Self::PlayerPed, (int) eLassoFlags::LHF_CAN_BE_LASSOED_BY_FRIENDLY_AI, false);
PED::SET_PED_LASSO_HOGTIE_FLAG(Self::PlayerPed, (int) eLassoFlags::LHF_CAN_BE_LASSOED_BY_FRIENDLY_PLAYERS, false);
PED::SET_PED_LASSO_HOGTIE_FLAG(Self::PlayerPed, (int) eLassoFlags::LHF_DISABLE_IN_MP, true);
}

//Doesn't work
virtual void OnDisable() override
{
PED::SET_PED_LASSO_HOGTIE_FLAG(Self::PlayerPed, (int) eLassoFlags::LHF_CAN_BE_LASSOED, true);
PED::SET_PED_LASSO_HOGTIE_FLAG(Self::PlayerPed, (int) eLassoFlags::LHF_CAN_BE_LASSOED_BY_FRIENDLY_AI, true);
PED::SET_PED_LASSO_HOGTIE_FLAG(Self::PlayerPed, (int) eLassoFlags::LHF_CAN_BE_LASSOED_BY_FRIENDLY_PLAYERS, true);
PED::SET_PED_LASSO_HOGTIE_FLAG(Self::PlayerPed, (int) eLassoFlags::LHF_DISABLE_IN_MP, false);
}
};

static AntiLasso _AntiLasso{"antilasso", "Anti Lasso", "Avoid getting lasso'd by other players"};
}
26 changes: 26 additions & 0 deletions src/game/features/self/TpMountToSelf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "core/commands/Command.hpp"
#include "game/rdr/Natives.hpp"
#include "game/features/Features.hpp"
#include "core/frontend/Notifications.hpp"

namespace YimMenu::Features
{
class TpToMountToSelf : public Command
{
using Command::Command;

virtual void OnCall() override
{
if(ENTITY::DOES_ENTITY_EXIST(Self::Mount))
if(PED::GET_MOUNT(Self::PlayerPed) != Self::Mount)
ENTITY::SET_ENTITY_COORDS(Self::Mount, Self::Pos.x, Self::Pos.y, Self::Pos.z, true, false, false, true);
else
Notifications::Show("Teleport", "Already on mount", NotificationType::Warning);

else
Notifications::Show("Teleport", "No current mount found", NotificationType::Error);
}
};

static TpToMountToSelf _TpToMountToSelf{"tpmounttoself", "Bring Horse", "Teleport your last horse to you"};
}
10 changes: 7 additions & 3 deletions src/game/features/self/TpToMount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ namespace YimMenu::Features

virtual void OnCall() override
{
if(ENTITY::DOES_ENTITY_EXIST(Self::Mount) && PED::GET_MOUNT(Self::PlayerPed) != Self::Mount)
PED::SET_PED_ONTO_MOUNT(Self::PlayerPed, Self::Mount, -1, true);
if(ENTITY::DOES_ENTITY_EXIST(Self::Mount))
if(PED::GET_MOUNT(Self::PlayerPed) != Self::Mount)
PED::SET_PED_ONTO_MOUNT(Self::PlayerPed, Self::Mount, -1, true);
else
Notifications::Show("Teleport", "Already on mount", NotificationType::Warning);

else
Notifications::Show("Teleport", "No current mount found", NotificationType::Warning);
Notifications::Show("Teleport", "No current mount found", NotificationType::Error);
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/game/features/self/TpToWaypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ namespace YimMenu::Features
{
if (MAP::IS_WAYPOINT_ACTIVE())
{
auto waypointCoords = Teleport::GetWaypointCoords();
Teleport::TeleportEntity(Self::PlayerPed, waypointCoords);
auto waypointCoords = YimMenu::Teleport::GetWaypointCoords();
YimMenu::Teleport::TeleportEntity(Self::PlayerPed, waypointCoords);
}
else
{
Notifications::Show("Waypoint", "You don't have a waypoint set", NotificationType::Warning);
Notifications::Show("Waypoint", "You don't have a waypoint set", NotificationType::Error);
}
}
};
Expand Down
28 changes: 17 additions & 11 deletions src/game/frontend/submenus/Players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include "game/backend/FiberPool.hpp"
#include "game/backend/Players.hpp"
#include "game/commands/PlayerCommand.hpp"
#include "game/features/Features.hpp"
#include "game/frontend/items/Items.hpp"
#include "game/rdr/Natives.hpp"
#include "util/spectate.hpp"
#include "util/teleport.hpp"

namespace YimMenu::Submenus
{
Expand All @@ -15,16 +16,15 @@ namespace YimMenu::Submenus
{
if (external)
{
ImGui::SetNextWindowPos(ImVec2(ImGui::GetWindowPos().x + ImGui::GetWindowSize().x + offset, ImGui::GetWindowPos().y));
ImGui::SetNextWindowPos(
ImVec2(ImGui::GetWindowPos().x + ImGui::GetWindowSize().x + offset, ImGui::GetWindowPos().y));
ImGui::SetNextWindowSize(ImVec2(150, ImGui::GetWindowSize().y));
ImGui::Begin("Player List", nullptr, ImGuiWindowFlags_NoDecoration);
ImGui::Begin("Player List", nullptr, ImGuiWindowFlags_NoDecoration);
for (auto& [id, player] : YimMenu::Players::GetPlayers())
{
if (ImGui::Selectable(player.GetName(), (YimMenu::Players::GetSelected() == player)))
{
YimMenu::Players::SetSelected(id);
if (YimMenu::g_Spectating)
YimMenu::SpectatePlayer(player);
}
}
ImGui::End();
Expand All @@ -36,8 +36,6 @@ namespace YimMenu::Submenus
if (ImGui::Selectable(player.GetName(), (YimMenu::Players::GetSelected() == player)))
{
YimMenu::Players::SetSelected(id);
if (YimMenu::g_Spectating)
YimMenu::SpectatePlayer(player);
}
}
}
Expand All @@ -62,11 +60,16 @@ namespace YimMenu::Submenus
ImGui::Text(YimMenu::Players::GetSelected().GetName());
ImGui::Separator();

if(ImGui::Checkbox("Spectate", &YimMenu::g_Spectating))
ImGui::Checkbox("Spectate", &YimMenu::g_Spectating);

//Button Widget crashes the game, idk why. Changed to regular for now.
if(ImGui::Button("Teleport To"))
{
YimMenu::SpectatePlayer(YimMenu::Players::GetSelected());
FiberPool::Push([]{
auto playerCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(YimMenu::Players::GetSelected().GetId()), true, true);
Teleport::TeleportEntity(Self::PlayerPed, playerCoords);
});
}

}));

column->AddColumnOffset(1, 160);
Expand Down Expand Up @@ -107,7 +110,10 @@ namespace YimMenu::Submenus
if (ImGui::Button("Explode"))
{
FiberPool::Push([] {
auto playerCoords = ENTITY::GET_ENTITY_COORDS(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(YimMenu::Players::GetSelected().GetId()), true, true);
auto playerCoords = ENTITY::GET_ENTITY_COORDS(
PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(YimMenu::Players::GetSelected().GetId()),
true,
true);


FIRE::ADD_EXPLOSION(playerCoords.x, playerCoords.y, playerCoords.z, 22, 1.0f, true, false, 1.0f);
Expand Down
3 changes: 3 additions & 0 deletions src/game/frontend/submenus/Self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace YimMenu::Submenus
main->AddItem(std::make_shared<BoolCommandItem>("infiniteclip"_J));
main->AddItem(std::make_shared<BoolCommandItem>("keepclean"_J));
main->AddItem(std::make_shared<BoolCommandItem>("noclip"_J));
main->AddItem(std::make_shared<BoolCommandItem>("antilasso"_J));
main->AddItem(std::make_shared<BoolCommandItem>("antihogtie"_J));
main->AddItem(std::make_shared<BoolCommandItem>("voicechatoverride"_J)); // TODO: move this to spoofing or network
AddCategory(std::move(main));

Expand All @@ -26,6 +28,7 @@ namespace YimMenu::Submenus
horse->AddItem(std::make_shared<BoolCommandItem>("keephorsebarsfilled"_J));
horse->AddItem(std::make_shared<BoolCommandItem>("keephorsecoresfilled"_J));
horse->AddItem(std::make_shared<BoolCommandItem>("keephorseagitationlow"_J));
horse->AddItem(std::make_shared<CommandItem>("tpmounttoself"_J));
AddCategory(std::move(horse));
}
}
Loading

0 comments on commit ac6ebd9

Please sign in to comment.