Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast Train & Object Spawner #171

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/game/features/players/toxic/CagePlayerLarge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace YimMenu::Features

virtual void OnCall(Player player) override
{
auto coords = player.GetPed().GetPosition();
coords.z -= 1.0f;
SpawnObject(0x99C0CFCF, coords);
Vector3 coords = ENTITY::GET_ENTITY_COORDS(player.GetPed().GetHandle(), true, true);
Deadlineem marked this conversation as resolved.
Show resolved Hide resolved
coords.z = coords.z - 1.0f;
SpawnObject(0x99C0CFCF, coords, 0, 0, 0, true, true, false, false, true);
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/game/features/players/toxic/CagePlayerSmall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace YimMenu::Features

virtual void OnCall(Player player) override
{
auto coords = player.GetPed().GetPosition();
coords.z -= 1.0f;
SpawnObject(0xF3D580D3, coords);
Vector3 coords = ENTITY::GET_ENTITY_COORDS(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player.GetId()), true, true);
Deadlineem marked this conversation as resolved.
Show resolved Hide resolved
coords.z = coords.z - 1.0f;
SpawnObject(0xF3D580D3, coords, 0, 0, 0, true, true, false, false, true);
}
};

Expand Down
42 changes: 42 additions & 0 deletions src/game/features/vehicle/FastTrain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "core/commands/LoopedCommand.hpp"
#include "core/frontend/Notifications.hpp"
#include "game/features/Features.hpp"
#include "game/rdr/Enums.hpp"
#include "game/rdr/Natives.hpp"
#include "game/backend/Self.hpp"

namespace YimMenu::Features
{
class FastTrain : public LoopedCommand
{
using LoopedCommand::LoopedCommand;

virtual void OnTick() override
{
Vehicle vehicle = PED::GET_VEHICLE_PED_IS_USING(Self::GetPed().GetHandle());
Deadlineem marked this conversation as resolved.
Show resolved Hide resolved
Hash vehicleModelHash = ENTITY::GET_ENTITY_MODEL(vehicle);

if (VEHICLE::IS_THIS_MODEL_A_TRAIN(vehicleModelHash))
{
VEHICLE::SET_TRAIN_SPEED(vehicle, 1000.0);
VEHICLE::SET_TRAIN_CRUISE_SPEED(vehicle, 1000.0);
VEHICLE::_SET_TRAIN_MAX_SPEED(vehicle, 1000.0);
}
}

virtual void OnDisable() override
{
Vehicle vehicle = PED::GET_VEHICLE_PED_IS_USING(Self::GetPed().GetHandle());
Deadlineem marked this conversation as resolved.
Show resolved Hide resolved
Hash vehicleModelHash = ENTITY::GET_ENTITY_MODEL(vehicle);

if (VEHICLE::IS_THIS_MODEL_A_TRAIN(vehicleModelHash))
{
VEHICLE::SET_TRAIN_SPEED(vehicle, 0.0);
VEHICLE::SET_TRAIN_CRUISE_SPEED(vehicle, 0.0);
VEHICLE::_SET_TRAIN_MAX_SPEED(vehicle, 0.0);
}
}
};

static FastTrain _FastTrain{"fasttrain", "Fast Train", "Makes the train much faster than normal. Instantly stops it when disabled."};
}
7 changes: 6 additions & 1 deletion src/game/frontend/submenus/Self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ namespace YimMenu::Submenus

auto vehicle = std::make_shared<Category>("Vehicle");
auto vehicleGlobalsGroup = std::make_shared<Group>("Globals");
auto vehicleFunGroup = std::make_shared<Group>("Fun");
auto vehicleFunGroup = std::make_shared<Group>("Fun");
auto trainGroup = std::make_shared<Group>("Train");

vehicleGlobalsGroup->AddItem(std::make_shared<BoolCommandItem>("vehiclegodmode"_J));
vehicleGlobalsGroup->AddItem(std::make_shared<CommandItem>("repairvehicle"_J));
Expand All @@ -214,8 +215,12 @@ namespace YimMenu::Submenus
vehicleFunGroup->AddItem(std::make_shared<ConditionalItem>("superdrive"_J, std::make_shared<BoolCommandItem>("superdrivedirectional"_J, "Directional")));
vehicleFunGroup->AddItem(std::make_shared<ConditionalItem>("superdrive"_J, std::make_shared<IntCommandItem>("superdriveforce"_J, "Force")));
vehicleFunGroup->AddItem(std::make_shared<BoolCommandItem>("superbrake"_J));

trainGroup->AddItem(std::make_shared<BoolCommandItem>("fasttrain"_J));

vehicle->AddItem(vehicleGlobalsGroup);
vehicle->AddItem(vehicleFunGroup);
vehicle->AddItem(trainGroup);
AddCategory(std::move(vehicle));

auto animations = std::make_shared<Category>("Animations");
Expand Down
16 changes: 13 additions & 3 deletions src/game/frontend/submenus/World.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "World.hpp"

#include "World/PedSpawner.hpp"
#include "World/ObjectSpawner.hpp"
#include "World/Shows.hpp"
#include "World/VehicleSpawner.hpp"
#include "World/Weather.hpp"
Expand All @@ -11,6 +12,10 @@
#include "game/backend/ScriptMgr.hpp"
#include "game/backend/Self.hpp"
#include "game/frontend/items/Items.hpp"
#include "game/rdr/Ped.hpp"
#include "game/rdr/data/PedModels.hpp"
#include "game/rdr/data/ObjModels.hpp"

#include "util/VehicleSpawner.hpp"

#include <game/rdr/Natives.hpp>
Expand Down Expand Up @@ -76,20 +81,25 @@ namespace YimMenu::Submenus
}
}));


auto spawners = std::make_shared<Category>("Spawners");
auto pedSpawnerGroup = std::make_shared<Group>("Ped Spawner");
auto spawners = std::make_shared<Category>("Spawners");
auto pedSpawnerGroup = std::make_shared<Group>("Ped Spawner");
auto objSpawnerGroup = std::make_shared<Group>("Object Spawner");
auto vehicleSpawnerGroup = std::make_shared<Group>("Vehicle Spawner");

pedSpawnerGroup->AddItem(std::make_shared<ImGuiItem>([] {
RenderPedSpawnerMenu();
}));

objSpawnerGroup->AddItem(std::make_shared<ImGuiItem>([] {
RenderObjectSpawnerMenu();
}));

vehicleSpawnerGroup->AddItem(std::make_shared<ImGuiItem>([] {
RenderVehicleSpawnerMenu();
}));

spawners->AddItem(pedSpawnerGroup);
spawners->AddItem(objSpawnerGroup);
spawners->AddItem(vehicleSpawnerGroup);

auto killPeds = std::make_shared<Group>("", 1);
Expand Down
158 changes: 158 additions & 0 deletions src/game/frontend/submenus/World/ObjectSpawner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#include "core/commands/Command.hpp"
#include "game/backend/FiberPool.hpp"
#include "game/backend/NativeHooks.hpp"
#include "game/backend/ScriptMgr.hpp"
#include "game/backend/Self.hpp"
#include "game/frontend/items/Items.hpp"
#include "game/rdr/Natives.hpp"
#include "game/rdr/data/ObjModels.hpp"
#include "ObjectSpawner.hpp"
#include "util/SpawnObject.hpp"

namespace YimMenu::Submenus
{
static bool IsObjectModelInList(const std::string& model)
{
for (const auto& objModel : YimMenu::Data::g_ObjModels)
{
if (objModel.model == model)
return true;
}
return false;
}

static int ObjectSpawnerInputCallback(ImGuiInputTextCallbackData* data)
{
if (data->EventFlag == ImGuiInputTextFlags_CallbackCompletion)
{
std::string newText;
std::string inputLower = data->Buf;
std::transform(inputLower.begin(), inputLower.end(), inputLower.begin(), ::tolower);

for (const auto& objModel : YimMenu::Data::g_ObjModels)
{
std::string modelLower = objModel.model;
std::transform(modelLower.begin(), modelLower.end(), modelLower.begin(), ::tolower);
if (modelLower.find(inputLower) != std::string::npos)
{
newText = objModel.model;
break;
}
}

if (!newText.empty())
{
data->DeleteChars(0, data->BufTextLen);
data->InsertChars(0, newText.c_str());
}

return 1;
}
return 0;
}

void RenderObjectSpawnerMenu()
{
static std::string objectModelBuffer;
static float positionOffsetX = 5.0f;
static float positionOffsetY = 5.0f;
static float positionOffsetZ = 0.0f;
static float pitch = 0.0f;
static float yaw = 0.0f;
static float roll = 0.0f;
static float alpha = 125.0f;
static bool onGround = false;
static bool isFrozen = false;
static bool isBurning = false;
static bool isPickup = false;
static bool showPreview = false;
static bool hasCollision = false;
static int modelHash = 0;

Vector3 playerCoords = ENTITY::GET_ENTITY_COORDS(Self::GetPed().GetHandle(), true, true);
Deadlineem marked this conversation as resolved.
Show resolved Hide resolved
Vector3 forwardVector = ENTITY::GET_ENTITY_FORWARD_VECTOR(Self::GetPed().GetHandle());

Vector3 spawnPosition;
spawnPosition.x = playerCoords.x + forwardVector.x * positionOffsetX;
spawnPosition.y = playerCoords.y + forwardVector.y * positionOffsetY;
spawnPosition.z = playerCoords.z + positionOffsetZ;

char buffer[256];
strncpy(buffer, objectModelBuffer.c_str(), sizeof(buffer));

ImGui::InputTextWithHint("##objectmodel", "Object Model", buffer, sizeof(buffer), ImGuiInputTextFlags_CallbackCompletion, ObjectSpawnerInputCallback);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the frontend item InputTextWithHint. Make sure to call .Draw() if you choose to go this route, you probably should though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity Code Description Project File Line Suppression State Details
Error C2440 '': cannot convert from 'initializer list' to 'YimMenu::InputTextWithHint'

InputTextWithHint("##objectmodel", "Object Model", &buffer, ImGuiInputTextFlags_CallbackCompletion, nullptr, ObjectSpawnerInputCallback)
.Draw();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buffer has to be a string, not a char.


objectModelBuffer = buffer;

if (ImGui::IsItemHovered())
ImGui::SetTooltip("Press Tab to auto-fill");

if (!objectModelBuffer.empty() && !IsObjectModelInList(objectModelBuffer))
{
ImGui::BeginListBox("##objectmodels", ImVec2(250, 100));

std::string bufferLower = objectModelBuffer;
std::transform(bufferLower.begin(), bufferLower.end(), bufferLower.begin(), ::tolower);
for (const auto& objModel : YimMenu::Data::g_ObjModels)
{
std::string objModelLower = objModel.model;
std::transform(objModelLower.begin(), objModelLower.end(), objModelLower.begin(), ::tolower);
if (objModelLower.find(bufferLower) != std::string::npos && ImGui::Selectable(objModel.model.c_str()))
{
objectModelBuffer = objModel.model;
modelHash = Joaat(objectModelBuffer.c_str());
STREAMING::REQUEST_MODEL(modelHash, false);
while (!STREAMING::HAS_MODEL_LOADED(modelHash))
{
return;
}
}
}

ImGui::EndListBox();
}

ImGui::SliderFloat("Offset X", &positionOffsetX, -25.0f, 25.0f);
ImGui::SliderFloat("Offset Y", &positionOffsetY, -25.0f, 25.0f);
ImGui::SliderFloat("Offset Z", &positionOffsetZ, -10.0f, 10.0f);
ImGui::SliderFloat("Pitch", &pitch, -180.0f, 180.0f);
ImGui::SliderFloat("Yaw", &yaw, -180.0f, 180.0f);
ImGui::SliderFloat("Roll", &roll, -180.0f, 180.0f);
ImGui::SliderFloat("Transparency", &alpha, 0.0f, 255.0f);

ImGui::Checkbox("Place on Ground", &onGround);
ImGui::SameLine();
ImGui::Checkbox("Freeze Position", &isFrozen);
ImGui::SameLine();
ImGui::Checkbox("Set on Fire", &isBurning);
ImGui::SameLine();
ImGui::Checkbox("Set as Pickup", &isPickup);

ImGui::Checkbox("Set Collision", &hasCollision);
ImGui::SameLine();
ImGui::Checkbox("Show Preview", &showPreview);

if (ImGui::Button("Spawn Object"))
{
int modelHash = Joaat(objectModelBuffer.c_str());
SpawnObject(modelHash, spawnPosition, pitch, yaw, roll, onGround, isFrozen, isBurning, isPickup, hasCollision);
}
ImGui::SameLine();
if (ImGui::Button("Reset Sliders"))
{
positionOffsetX = 5.0f;
positionOffsetY = 5.0f;
positionOffsetZ = 0.0f;
pitch = 0.0f;
yaw = 0.0f;
roll = 0.0f;
alpha = 125.0f;
}

if (showPreview == true)
Deadlineem marked this conversation as resolved.
Show resolved Hide resolved
{
int modelHash = Joaat(objectModelBuffer.c_str());
PreviewObject(modelHash, spawnPosition, pitch, yaw, roll, alpha, showPreview);
}
}
}
6 changes: 6 additions & 0 deletions src/game/frontend/submenus/World/ObjectSpawner.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

namespace YimMenu::Submenus
{
void RenderObjectSpawnerMenu();
}
Loading