Skip to content

Commit

Permalink
Small stuff and refactors (#58)
Browse files Browse the repository at this point in the history
* Small changes

* Update ContextMenus.hpp

* Update Self.cpp

* Added warp into vehicle
  • Loading branch information
DayibBaba authored Nov 5, 2023
1 parent f1a8992 commit 50857ce
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 73 deletions.
76 changes: 58 additions & 18 deletions src/game/bigfeatures/ContextMenus.hpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,70 @@
#pragma once
#include "ContextMenu.hpp"
#include "core/commands/Commands.hpp"
#include "game/backend/Players.hpp"
#include "game/commands/PlayerCommand.hpp"
#include "game/features/Features.hpp"
#include "game/rdr/Natives.hpp"
#include "util/teleport.hpp"


namespace YimMenu
{
inline ContextOperationsMenu ContextMenuDefault = ContextOperationsMenu("Default",
{
ContextMenuOperation{"Error",
[&] {

}}
});
inline ContextOperationsMenu ContextMenuDefault = ContextOperationsMenu("Default", {ContextMenuOperation{"Error", [&] {

}}});

inline ContextOperationsMenu ContextMenuPlayers = ContextOperationsMenu("Players",
{
ContextMenuOperation
{"Teleport to player", [&] {
auto playerPos = ENTITY::GET_ENTITY_COORDS(ContextMenu::GetEntityHandle(), false, true);
Teleport::TeleportEntity(Self::PlayerPed, playerPos);
}},
{"Explode", [&] {
auto playerPos = ENTITY::GET_ENTITY_COORDS(ContextMenu::GetEntityHandle(), false, true);
FIRE::ADD_EXPLOSION(playerPos.x, playerPos.y, playerPos.z, 22, 1.0f, true, false, 1.0f);
}},

});
ContextMenuOperation{"Set Selected",
[&] {
for (auto [id, plyr] : YimMenu::Players::GetPlayers())
if (plyr.IsValid() && plyr.GetPed().GetPointer<void*>())
if (ContextMenu::GetEntityHandle() == PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(id))
{
YimMenu::Players::SetSelected(id);
break;
}
}},
{"Teleport to",
[&] {
auto playerPos = ENTITY::GET_ENTITY_COORDS(ContextMenu::GetEntityHandle(), false, true);
Teleport::TeleportEntity(Self::PlayerPed, playerPos, false);
}},
{"Teleport Behind",
[&] {
auto playerCoords = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(ContextMenu::GetEntityHandle(), 0, -10, 0);
if (Teleport::TeleportEntity(Self::PlayerPed, playerCoords, true))
g_Spectating = false;
}},
{"Explode",
[&] {
auto playerPos = ENTITY::GET_ENTITY_COORDS(ContextMenu::GetEntityHandle(), false, true);
FIRE::ADD_EXPLOSION(playerPos.x, playerPos.y, playerPos.z, 22, 1.0f, true, false, 1.0f);
}},
{"Set Defensive",
[&] {
int playerId = -1;
for (auto [id, plyr] : YimMenu::Players::GetPlayers())
if (plyr.IsValid() && plyr.GetPed().GetPointer<void*>())
if (ContextMenu::GetEntityHandle() == PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(id))
{
playerId = id;
break;
}
Commands::GetCommand<PlayerCommand>("defensive"_J)->Call(playerId);
}},
{"Set Offensive",
[&] {
int playerId = -1;
for (auto [id, plyr] : YimMenu::Players::GetPlayers())
if (plyr.IsValid() && plyr.GetPed().GetPointer<void*>())
if (ContextMenu::GetEntityHandle() == PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(id))
{
playerId = id;
break;
}
Commands::GetCommand<PlayerCommand>("offensive"_J)->Call(playerId);
}},
});
}
15 changes: 9 additions & 6 deletions src/game/features/Features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include "game/backend/FiberPool.hpp"
#include "game/backend/Players.hpp"
#include "game/backend/ScriptMgr.hpp"
#include "game/bigfeatures/ContextMenu.hpp"
#include "game/bigfeatures/Esp.hpp"
#include "game/frontend/GUI.hpp"
#include "game/rdr/Enums.hpp"
#include "game/rdr/Natives.hpp"
#include "game/bigfeatures/ContextMenu.hpp"

namespace YimMenu
{
Expand Down Expand Up @@ -40,24 +40,27 @@ namespace YimMenu

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

if (g_Spectating)
{
auto playerPed = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_SpectateId);
CAM::SET_CINEMATIC_MODE_ACTIVE(false);

if (!NETWORK::NETWORK_IS_IN_SPECTATOR_MODE())
if (!NETWORK::NETWORK_IS_IN_SPECTATOR_MODE() && ENTITY::DOES_ENTITY_EXIST(playerPed))
{
NETWORK::NETWORK_SET_IN_SPECTATOR_MODE(true, playerPed);
}

if (!STREAMING::IS_ENTITY_FOCUS(playerPed))
STREAMING::SET_FOCUS_ENTITY(playerPed);
if (GRAPHICS::_ANIMPOSTFX_IS_TAG_PLAYING("SpectateFilter"))
{
GRAPHICS::_ANIMPOSTFX_STOP_TAG("SpectateFilter");
}

if (!Players::GetSelected().IsValid() || !NETWORK::NETWORK_IS_PLAYER_CONNECTED(Players::GetSelected().GetId()))
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/features/self/TpToWaypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace YimMenu::Features
if (MAP::IS_WAYPOINT_ACTIVE())
{
auto waypointCoords = YimMenu::Teleport::GetWaypointCoords();
YimMenu::Teleport::TeleportEntity(Self::PlayerPed, waypointCoords);
YimMenu::Teleport::TeleportEntity(Self::PlayerPed, waypointCoords, true);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/frontend/items/BoolCommandItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace YimMenu
if (ImGui::IsItemHovered())
{
ImGui::SetTooltip(m_Command->GetDescription().data());
if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
if (GetAsyncKeyState(VK_OEM_3) & 0x8000)
ImGui::OpenPopup(std::format("{} Hotkey", m_Command->GetLabel()).data());
}

Expand Down
6 changes: 6 additions & 0 deletions src/game/frontend/items/Items.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#include "core/frontend/manager/UIItem.hpp"
#include "util/Joaat.hpp"
#include "game/frontend/GUI.hpp"

namespace YimMenu
{
class BoolCommand;
class Command;

inline ImVec2 GetListBoxDimensions()
{
return {300, 250};
}

class Button : public UIItem
{
public:
Expand Down
34 changes: 27 additions & 7 deletions src/game/frontend/submenus/Players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,27 @@ namespace YimMenu::Submenus
{
auto main = std::make_shared<Category>("Main");
auto column = std::make_shared<Column>(2);

auto playerOptionsGroup = std::make_shared<Group>("Info", ImVec2(0, 250));
auto teleportGroup = std::make_shared<Group>("Teleport", GetListBoxDimensions());
auto playerOptionsGroup = std::make_shared<Group>("Info", GetListBoxDimensions());

main->AddItem(std::make_shared<ImGuiItem>([] {
drawPlayerList(true);
}));

playerOptionsGroup->AddItem(std::make_shared<ImGuiItem>([] {
ImGui::Text(YimMenu::Players::GetSelected().GetName());
ImGui::Separator();

if (YimMenu::Players::GetSelected().IsValid())
{
ImGui::Checkbox("Spectate", &YimMenu::g_Spectating);
ImGui::Text(YimMenu::Players::GetSelected().GetName());
}
else
{
YimMenu::Players::SetSelected(Self::Id);
}
}));

ImGui::Checkbox("Spectate", &YimMenu::g_Spectating);
teleportGroup->AddItem(std::make_shared<ImGuiItem>([] {
//Button Widget crashes the game, idk why. Changed to regular for now.
if (ImGui::Button("Teleport To"))
{
Expand All @@ -83,7 +92,7 @@ namespace YimMenu::Submenus
PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(YimMenu::Players::GetSelected().GetId()),
true,
true);
if (Teleport::TeleportEntity(Self::PlayerPed, playerCoords))
if (Teleport::TeleportEntity(Self::PlayerPed, playerCoords, false))
g_Spectating = false;
});
}
Expand All @@ -95,14 +104,25 @@ namespace YimMenu::Submenus
0,
-10,
0);
if (Teleport::TeleportEntity(Self::PlayerPed, playerCoords))
if (Teleport::TeleportEntity(Self::PlayerPed, playerCoords, false))
g_Spectating = false;
});
}
if (ImGui::Button("Teleport Into Vehicle"))
{
FiberPool::Push([] {
auto playerVeh = PED::GET_VEHICLE_PED_IS_USING(
PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(YimMenu::Players::GetSelected().GetId()));
if (Teleport::WarpIntoVehicle(Self::PlayerPed, playerVeh))
g_Spectating = false;
});
}
}));

column->AddColumnOffset(1, 160);
column->AddItem(playerOptionsGroup);
column->AddNextColumn();
column->AddItem(teleportGroup);
main->AddItem(column);
AddCategory(std::move(main));
}
Expand Down
66 changes: 60 additions & 6 deletions src/game/frontend/submenus/Self.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,59 @@
#include "Self.hpp"

#include "game/backend/FiberPool.hpp"
#include "game/backend/ScriptMgr.hpp"
#include "game/features/Features.hpp"
#include "game/frontend/items/Items.hpp"
#include "game/rdr/Natives.hpp"

namespace YimMenu::Submenus
{
void RenderAnimationsCategory()
{
static std::string anim, dict;
InputTextWithHint("Dictionary", "Enter Dictionary Name", &dict).Draw();
InputTextWithHint("Animation", "Enter Animation Name", &anim).Draw();

if (ImGui::Button("Play Animation"))
{
FiberPool::Push([=] {
for (int i = 0; i < 250; i++)
{
if (dict.empty() || anim.empty())
break;

if (STREAMING::HAS_ANIM_DICT_LOADED(dict.c_str()))
break;

STREAMING::REQUEST_ANIM_DICT(dict.c_str());
ScriptMgr::Yield();
}

TASK::TASK_PLAY_ANIM(YimMenu::Self::PlayerPed, dict.c_str(), anim.c_str(), 8.0f, -8.0f, -1, 0, 0, false, false, false, "", 0);
});
}
ImGui::SameLine();
if (ImGui::Button("Stop"))
{
FiberPool::Push([=] {
TASK::CLEAR_PED_TASKS(YimMenu::Self::PlayerPed, true, false);
});
}
}

Self::Self() :
Submenu::Submenu("Self")
{
auto main = std::make_shared<Category>("Main");
auto globalsGroup = std::make_shared<Group>("Globals", ImVec2(0, 250));
auto movementGroup = std::make_shared<Group>("Movement", ImVec2(0, 250));
auto toolsGroup = std::make_shared<Group>("Tools", ImVec2(0, 250));
auto globalsGroup = std::make_shared<Group>("Globals", GetListBoxDimensions());
auto movementGroup = std::make_shared<Group>("Movement", GetListBoxDimensions());
auto toolsGroup = std::make_shared<Group>("Tools", GetListBoxDimensions());
auto columns = std::make_shared<Column>(2);

globalsGroup->AddItem(std::make_shared<BoolCommandItem>("godmode"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("noragdoll"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("invis"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("offtheradar"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("noragdoll"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("invis"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("antiafk"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("keepbarsfilled"_J));
Expand All @@ -29,6 +67,12 @@ namespace YimMenu::Submenus

toolsGroup->AddItem(std::make_shared<CommandItem>("suicide"_J));
toolsGroup->AddItem(std::make_shared<CommandItem>("clearcrimes"_J));
toolsGroup->AddItem(std::make_shared<ImGuiItem>([] {
if (ImGui::Button("Unfreeze"))
FiberPool::Push([] {
ENTITY::FREEZE_ENTITY_POSITION(YimMenu::Self::PlayerPed, false);
});
}));

movementGroup->AddItem(std::make_shared<BoolCommandItem>("noclip"_J));

Expand All @@ -40,14 +84,24 @@ namespace YimMenu::Submenus
AddCategory(std::move(main));

auto horse = std::make_shared<Category>("Horse");
auto horseGlobalsGroup = std::make_shared<Group>("Globals");
auto horseColumns = std::make_shared<Column>(2);
auto horseGlobalsGroup = std::make_shared<Group>("Globals", GetListBoxDimensions());
horseGlobalsGroup->AddItem(std::make_shared<BoolCommandItem>("horsegodmode"_J));
horseGlobalsGroup->AddItem(std::make_shared<BoolCommandItem>("horsenoragdoll"_J));
horseGlobalsGroup->AddItem(std::make_shared<BoolCommandItem>("keephorsebarsfilled"_J));
horseGlobalsGroup->AddItem(std::make_shared<BoolCommandItem>("keephorsecoresfilled"_J));
horseGlobalsGroup->AddItem(std::make_shared<BoolCommandItem>("keephorseagitationlow"_J));
horseGlobalsGroup->AddItem(std::make_shared<CommandItem>("tpmounttoself"_J));
horse->AddItem(horseGlobalsGroup);
horseColumns->AddItem(horseGlobalsGroup);
horse->AddItem(horseColumns);
AddCategory(std::move(horse));

auto animations = std::make_shared<Category>("Animations");

animations->AddItem(std::make_shared<ImGuiItem>([] {
RenderAnimationsCategory();
}));

AddCategory(std::move(animations));
}
}
14 changes: 10 additions & 4 deletions src/game/frontend/submenus/Teleport.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "Teleport.hpp"

#include "game/features/Features.hpp"
#include "game/frontend/items/Items.hpp"
#include "game/bigfeatures/CustomTeleport.hpp"
Expand Down Expand Up @@ -157,7 +156,7 @@ namespace YimMenu::Submenus
{
FiberPool::Push([l] {
Vector3 l_ = {l.x, l.y, l.z};
YimMenu::Teleport::TeleportEntity(Self::PlayerPed,l_);
YimMenu::Teleport::TeleportEntity(Self::PlayerPed,l_, false);
});
}
}
Expand Down Expand Up @@ -185,14 +184,21 @@ namespace YimMenu::Submenus
Submenu::Submenu("Teleport")
{
auto main = std::make_shared<Category>("Main");
main->AddItem(std::make_shared<CommandItem>("tptowaypoint"_J));
main->AddItem(std::make_shared<CommandItem>("tptomount"_J));
auto columns = std::make_shared<Column>(2);
auto miscGroup = std::make_shared<Group>("Misc", GetListBoxDimensions());

miscGroup->AddItem(std::make_shared<CommandItem>("tptowaypoint"_J));
miscGroup->AddItem(std::make_shared<CommandItem>("tptomount"_J));

columns->AddItem(miscGroup);
main->AddItem(columns);

auto customteleport = std::make_shared<Category>("Saved");
customteleport->AddItem(std::make_shared<ImGuiItem>([] {
RenderCustomTeleport();
}));


AddCategory(std::move(main));
AddCategory(std::move(customteleport));
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/pointers/Pointers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace YimMenu
using GetNetworkPlayerFromPid = CNetGamePlayer* (*)(uint8_t player);
using WorldToScreen = bool (*)(float* world_coords, float* out_x, float* out_y);
using GetNetObjectById = rage::netObject*(*)(uint16_t id);
using RequestControlOfNetObject = bool (*)(rage::netObject* netId, bool unk);
using RequestControlOfNetObject = bool (*)(rage::netObject** netId, bool unk);
};

struct PointerData
Expand Down
Loading

0 comments on commit 50857ce

Please sign in to comment.