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

player.enter/exitVehicle API WIP #68

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 35 additions & 2 deletions code/client/src/core/modules/human.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ namespace MafiaMP::Core::Modules {
metadata._sprintSpeed = charController->GetSprintMoveSpeed();
metadata.weaponData.isAiming = tracking.human->GetHumanWeaponController()->IsAiming();

// Try to enter/exit vehicle if an action is pending
if (metadata.carPassenger.pending) {
if (!metadata.carPassenger.carId) {
if (tracking.human->GetOwner()) {
Game::Helpers::Human::RemoveFromCar(tracking.charController, (SDK::C_Car *)tracking.human->GetOwner(), metadata.carPassenger.forced);
}
metadata.carPassenger.pending = false;
}
else {
const auto carEnt = gApplication->GetWorldEngine()->GetEntityByServerID(metadata.carPassenger.carId);
if (carEnt.is_valid()) {
const auto carData = carEnt.get<Core::Modules::Vehicle::Tracking>();
if (carData->car) {
Game::Helpers::Human::PutIntoCar(tracking.charController, carData->car, metadata.carPassenger.seatId, metadata.carPassenger.forced);
metadata.carPassenger.pending = false;
}
}
}
}

// Current state-specific sync data
switch (metadata._charStateHandlerType) {
case SDK::ue::game::humanai::C_CharacterStateHandler::E_SHT_MOVE: {
Expand All @@ -78,6 +98,8 @@ namespace MafiaMP::Core::Modules {
} break;

case SDK::ue::game::humanai::C_CharacterStateHandler::E_SHT_CAR: {
if (metadata.carPassenger.pending)
break;
auto human2CarWrapper = charController->GetCarHandler()->GetHuman2CarWrapper();
// printf("id: %d\n", charController->GetCarHandler()->GetCarState());
if (human2CarWrapper && charController->GetCarHandler()->GetCarState() == 2) /* entering in progress */ {
Expand All @@ -93,7 +115,7 @@ namespace MafiaMP::Core::Modules {
} break;
}

if (metadata._charStateHandlerType != SDK::ue::game::humanai::C_CharacterStateHandler::E_SHT_CAR) {
if (!metadata.carPassenger.pending && metadata._charStateHandlerType != SDK::ue::game::humanai::C_CharacterStateHandler::E_SHT_CAR) {
// not in a vehicle, so make sure data is reset
metadata.carPassenger = {};
}
Expand Down Expand Up @@ -484,7 +506,7 @@ namespace MafiaMP::Core::Modules {
}

auto trackingData = e.get_mut<Core::Modules::Human::Tracking>();
if (trackingData && !trackingData->human) {
if (!trackingData || (trackingData && !trackingData->human)) {
return;
}

Expand All @@ -493,6 +515,17 @@ namespace MafiaMP::Core::Modules {
if (setHealth.HasValue()) {
Game::Helpers::Human::SetHealthPercent(trackingData->human, setHealth());
}

const auto carEnterExitAction = msg->carEnterExitAction;

if (carEnterExitAction.HasValue()) {
const auto data = carEnterExitAction();
auto updateData = e.get_mut<Shared::Modules::HumanSync::UpdateData>();
updateData->carPassenger.carId = data.carId;
updateData->carPassenger.seatId = data.seatId;
updateData->carPassenger.forced = data.forced;
updateData->carPassenger.pending = true;
}
});

net->RegisterGameRPC<Shared::RPC::AddWeapon>([app](SLNet::RakNetGUID guid, Shared::RPC::AddWeapon *msg) {
Expand Down
26 changes: 26 additions & 0 deletions code/client/src/game/helpers/human.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "sdk/entities/c_car.h"
#include "sdk/entities/c_human_2.h"

#include "sdk/c_game.h"

namespace MafiaMP::Game::Helpers {
uint8_t Human::GetHealthPercent(SDK::C_Human2 *human) {
float fHealth = human->GetHumanScript()->GetHealth();
Expand All @@ -23,6 +25,18 @@ namespace MafiaMP::Game::Helpers {
return false;
}

const auto pLocalPlayer = SDK::GetGame()->GetActivePlayer();
if (!pLocalPlayer) {
return false;
}

// Specific code for local player that has no character controller bound
if (!charController || charController->GetCharacter()->GetType() == SDK::E_EntityType::E_ENTITY_PLAYER) {
SDK::ue::C_CntPtr<uintptr_t> syncObject;
reinterpret_cast<SDK::C_Human2 *>(pLocalPlayer)->GetHumanScript()->GetOnVehicle(syncObject, car, seat, true, true, SDK::E_HumanMoveMode::E_HMM_WALK, force);
return true;
}

SDK::C_Actor *act = *(SDK::C_Actor **)((uintptr_t)car + 0xA8);
return charController->TriggerActorAction(act, SDK::E_AA_ENTER_CAR, seat, force, false);
}
Expand All @@ -32,6 +46,18 @@ namespace MafiaMP::Game::Helpers {
return false;
}

const auto pLocalPlayer = SDK::GetGame()->GetActivePlayer();
if (!pLocalPlayer) {
return false;
}

// Specific code for local player that has no character controller bound
if (!charController || charController->GetCharacter()->GetType() == SDK::E_EntityType::E_ENTITY_PLAYER) {
SDK::ue::C_CntPtr<uintptr_t> syncObject;
reinterpret_cast<SDK::C_Human2 *>(pLocalPlayer)->GetHumanScript()->ScrDoAction(syncObject, car, SDK::E_AA_LEAVE_CAR, 0, false, true, SDK::E_HumanMoveMode::E_HMM_WALK, true);
return true;
}

SDK::C_Actor *act = *(SDK::C_Actor **)((uintptr_t)car + 0xA8);
return charController->TriggerActorAction(act, SDK::E_AA_LEAVE_CAR, 0, force, false);
}
Expand Down
75 changes: 75 additions & 0 deletions code/client/src/sdk/entities/e_actor_actions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#pragma once

namespace SDK {
enum E_ActorActions {
E_AA_DUMMY = 0x0,
E_AA_ENTER_CAR = 0x1,
E_AA_LEAVE_CAR = 0x2,
E_AA_OPEN_CAR_TRUNK = 0x3,
E_AA_CLOSE_CAR_TRUNK = 0x4,
E_AA_OPEN_CAR_HOOD = 0x5,
E_AA_CLOSE_CAR_HOOD = 0x6,
E_AA_TRAILER_MOUNT = 0x7,
E_AA_ITEM_PICK_UP = 0x8,
E_AA_USE_LADDER = 0x9,
E_AA_SCRIPT = 0xA,
E_AA_CUSTOMSCRIPT = 0xB,
E_AA_DOOR_OPEN = 0xC,
E_AA_DOOR_KICK = 0xD,
E_AA_DOOR_COMPONENT_OPEN = 0xE,
E_AA_DOOR_COMPONENT_PULL_LOCK = 0xF,
E_AA_DOOR_COMPONENT_KICK = 0x10,
E_AA_SAFEHOUSE_DOOR_ACCESS = 0x11,
E_AA_USE_LIFT = 0x12,
E_AA_ACTOR_SIT = 0x13,
E_AA_ACTOR_LEAVE = 0x14,
E_AA_RADIO = 0x15,
E_AA_JUKEBOX = 0x16,
E_AA_SLOT_MACHINE = 0x17,
E_AA_STEAL_CAR = 0x18,
E_AA_STEAL_CAR_STOP = 0x19,
E_AA_BREAK_IN_CAR = 0x1A,
E_AA_LOCK_PICK_CAR = 0x1B,
E_AA_THROW_FROM_CAR = 0x1C,
E_AA_ENTER_BOAT = 0x1D,
E_AA_LEAVE_BOAT = 0x1E,
E_AA_RESPAWN_BOAT = 0x1F,
E_AA_ENTER_TRAIN = 0x20,
E_AA_LEAVE_TRAIN = 0x21,
E_AA_GET_ON_MOTORCYCLE = 0x22,
E_AA_GET_OFF_MOTORCYCLE = 0x23,
E_AA_THROW_FROM_MOTORCYCLE = 0x24,
E_AA_GARAGE_GET_CAR = 0x25,
E_AA_GARAGE_PARK_CAR = 0x26,
E_AA_GARAGE_SWITCH_CAR = 0x27,
E_AA_ENTER_INNERSPACE = 0x28,
E_AA_LEAVE_INNERSPACE = 0x29,
E_AA_USE_TELEPHONE = 0x2A,
E_AA_USE_STATIC_WEAPON = 0x2B,
E_AA_TV = 0x2C,
E_AA_TAKE_PINUP = 0x2D,
E_AA_DRAG_DEATH_BODY = 0x2E,
E_AA_STEALABLE_WEAPON = 0x2F,
E_AA_STEALABLE_SUIT = 0x30,
E_AA_STEALABLE_FOOD = 0x31,
E_AA_STEALABLE_AMMO = 0x32,
E_AA_OPEN_SHOP = 0x33,
E_AA_USE_MOUNTED_WEAPON = 0x34,
E_AA_LEAVE_MOUNTED_WEAPON = 0x35,
E_AA_OPEN_HEADQUARTERS = 0x36,
E_AA_OPEN_CRIME_BUSINESS = 0x37,
E_AA_TELEPORT = 0x38,
E_AA_BED = 0x39,
E_AA_DEAD_GUY_THROWN_OUT_CAR = 0x3A,
E_AA_BAILOUT_CAR = 0x3B,
E_AA_BAILOUT_MOTORCYCLE = 0x3C,
E_AA_INTERROGATE_IN_CAR = 0x3D,
E_AA_PICKUP_SATCHEL = 0x3E,
E_AA_PICKUP_BODY = 0x3F,
E_AA_PUT_BODY_IN_CAR_TRUNK = 0x40,
E_AA_REMOVE_BODY_FROM_CAR_TRUNK = 0x41,
E_AA_TURRET_MOUNT = 0x42,
E_AA_CAR_TURRET_MOUNT = 0x43,
E_AA_REVIVE = 0x44,
};
}
9 changes: 7 additions & 2 deletions code/client/src/sdk/entities/human/c_human_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ namespace SDK {
}

void C_HumanScript::GetOnVehicle(ue::C_CntPtr<uintptr_t> &outSyncObject, C_Actor *arg1, unsigned int arg2, bool arg3, bool arg4, E_HumanMoveMode moveMode, bool force) {
(*(void(__thiscall *)(C_HumanScript *, ue::C_CntPtr<uintptr_t> &, C_Actor *, unsigned int, bool, bool, E_HumanMoveMode, bool))gPatterns.C_HumanScript__GetOnVehicle)(this, outSyncObject, arg1, arg2, arg3, arg4, moveMode, force);
hook::this_call<void>(gPatterns.C_HumanScript__GetOnVehicle, this, outSyncObject, arg1, arg2, arg3, arg4, moveMode, force);
}

void C_HumanScript::GetOffVehicle(ue::C_CntPtr<uintptr_t> &outSyncObject, C_Actor *arg1, bool arg2, bool arg3) {
(*(void(__thiscall *)(C_HumanScript *, ue::C_CntPtr<uintptr_t> &, C_Actor *, bool, bool))gPatterns.C_HumanScript__GetOffVehicle)(this, outSyncObject, arg1, arg2, arg3);
hook::this_call<void>(gPatterns.C_HumanScript__GetOffVehicle, this, outSyncObject, arg1, arg2, arg3);
}

void C_HumanScript::ScrAim(ue::C_CntPtr<uintptr_t> &syncObject, bool aiming) {
Expand All @@ -66,6 +66,11 @@ namespace SDK {
void C_HumanScript::ScrAttack(C_Entity *ent) {
hook::this_call(gPatterns.C_HumanScript__ScrAttack, this, ent);
}

void C_HumanScript::ScrDoAction(ue::C_CntPtr<uintptr_t>& syncObject, C_Actor* actor, E_ActorActions action, unsigned int arg3, bool arg4, bool arg5, E_HumanMoveMode moveMode, bool force) {
hook::this_call(gPatterns.C_HumanScript__ScrDoAction, this, syncObject, actor, action, arg3, arg4, arg5, moveMode, force);
}

void C_HumanScript::SetStealthMove(bool move) {
hook::this_call(gPatterns.C_HumanScript__SetStealthMove, this, move);
}
Expand Down
3 changes: 3 additions & 0 deletions code/client/src/sdk/entities/human/c_human_script.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "../../ue/c_cnt_ptr.h"
#include "../e_actor_actions.h"

#include "../../ue/sys/math/c_vector.h"

Expand Down Expand Up @@ -34,6 +35,8 @@ namespace SDK {
void ScrAimAt(ue::C_CntPtr<uintptr_t> &, C_Entity *, ue::sys::math::C_Vector const &, bool);
void ScrAttack(C_Entity *);

void ScrDoAction(ue::C_CntPtr<uintptr_t> &, C_Actor *, E_ActorActions, unsigned int, bool, bool, E_HumanMoveMode, bool);

void SetStealthMove(bool);
};
}
18 changes: 18 additions & 0 deletions code/client/src/sdk/entities/human/e_human_move_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

namespace SDK {
enum class E_HumanMoveMode {
E_HMM_NONE = -1,
E_HMM_BREATH = 0,
E_HMM_STEP,
E_HMM_WALK_SLOW,
E_HMM_WALK,
E_HMM_WALK_FAST,
E_HMM_RUN,
E_HMM_SPRINT,
E_HMM_AUTO_SLOW,
E_HMM_AUTO_NORMAL,
E_HMM_AUTO_FAST,
E_HMM_END
};
}
1 change: 1 addition & 0 deletions code/client/src/sdk/patterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ namespace SDK {
gPatterns.C_HumanScript__ScrAim = reinterpret_cast<uint64_t>(hook::get_pattern("48 89 5C 24 ? 55 56 57 48 8B EC 48 83 EC 20 48 8B DA 48 8B F9 48 8B 0D ? ? ? ? 48 8D 55 20 41 0F B6 F0"));
gPatterns.C_HumanScript__ScrAimAt = reinterpret_cast<uint64_t>(hook::get_pattern("48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8B EC 48 83 EC 30 48 8B DA"));
gPatterns.C_HumanScript__ScrAttack = reinterpret_cast<uint64_t>(hook::get_pattern("48 85 D2 0F 84 ? ? ? ? 55 56 41 56"));
gPatterns.C_HumanScript__ScrDoAction = reinterpret_cast<uint64_t>(hook::get_pattern("40 55 53 41 54 41 56 41 57 48 8B EC 48 81 EC"));
gPatterns.C_HumanScript__SetHealth = reinterpret_cast<uint64_t>(hook::get_pattern("48 83 EC ? 48 8B 09 0F 29 74 24 ?"));
gPatterns.C_HumanScript__SetStealthMove = reinterpret_cast<uint64_t>(hook::get_pattern("48 89 5C 24 ? 57 48 83 EC 60 48 8B F9 0F B6 DA"));

Expand Down
1 change: 1 addition & 0 deletions code/client/src/sdk/patterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ namespace SDK {
uint64_t C_HumanScript__ScrAim = 0x0;
uint64_t C_HumanScript__ScrAimAt = 0x0;
uint64_t C_HumanScript__ScrAttack = 0x0;
uint64_t C_HumanScript__ScrDoAction = 0x0;
uint64_t C_HumanScript__SetHealth = 0x0;
uint64_t C_HumanScript__SetStealthMove = 0x0;

Expand Down
89 changes: 2 additions & 87 deletions code/client/src/sdk/ue/game/humainai/c_character_controller.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once

#include <cstdint>
#include "../../../entities/e_actor_actions.h"
#include "../../../entities/c_actor.h"
#include "../../../entities/human/e_human_move_mode.h"
#include "c_character_state_handler.h"

#include "c_character_state_handler_aim.h"
Expand All @@ -12,93 +14,6 @@
namespace SDK {
class C_Human2;

enum class E_HumanMoveMode {
E_HMM_NONE = -1,
E_HMM_BREATH = 0,
E_HMM_STEP,
E_HMM_WALK_SLOW,
E_HMM_WALK,
E_HMM_WALK_FAST,
E_HMM_RUN,
E_HMM_SPRINT,
E_HMM_AUTO_SLOW,
E_HMM_AUTO_NORMAL,
E_HMM_AUTO_FAST,
E_HMM_END
};

enum E_ActorActions {
E_AA_DUMMY = 0x0,
E_AA_ENTER_CAR = 0x1,
E_AA_LEAVE_CAR = 0x2,
E_AA_OPEN_CAR_TRUNK = 0x3,
E_AA_CLOSE_CAR_TRUNK = 0x4,
E_AA_OPEN_CAR_HOOD = 0x5,
E_AA_CLOSE_CAR_HOOD = 0x6,
E_AA_TRAILER_MOUNT = 0x7,
E_AA_ITEM_PICK_UP = 0x8,
E_AA_USE_LADDER = 0x9,
E_AA_SCRIPT = 0xA,
E_AA_CUSTOMSCRIPT = 0xB,
E_AA_DOOR_OPEN = 0xC,
E_AA_DOOR_KICK = 0xD,
E_AA_DOOR_COMPONENT_OPEN = 0xE,
E_AA_DOOR_COMPONENT_PULL_LOCK = 0xF,
E_AA_DOOR_COMPONENT_KICK = 0x10,
E_AA_SAFEHOUSE_DOOR_ACCESS = 0x11,
E_AA_USE_LIFT = 0x12,
E_AA_ACTOR_SIT = 0x13,
E_AA_ACTOR_LEAVE = 0x14,
E_AA_RADIO = 0x15,
E_AA_JUKEBOX = 0x16,
E_AA_SLOT_MACHINE = 0x17,
E_AA_STEAL_CAR = 0x18,
E_AA_STEAL_CAR_STOP = 0x19,
E_AA_BREAK_IN_CAR = 0x1A,
E_AA_LOCK_PICK_CAR = 0x1B,
E_AA_THROW_FROM_CAR = 0x1C,
E_AA_ENTER_BOAT = 0x1D,
E_AA_LEAVE_BOAT = 0x1E,
E_AA_RESPAWN_BOAT = 0x1F,
E_AA_ENTER_TRAIN = 0x20,
E_AA_LEAVE_TRAIN = 0x21,
E_AA_GET_ON_MOTORCYCLE = 0x22,
E_AA_GET_OFF_MOTORCYCLE = 0x23,
E_AA_THROW_FROM_MOTORCYCLE = 0x24,
E_AA_GARAGE_GET_CAR = 0x25,
E_AA_GARAGE_PARK_CAR = 0x26,
E_AA_GARAGE_SWITCH_CAR = 0x27,
E_AA_ENTER_INNERSPACE = 0x28,
E_AA_LEAVE_INNERSPACE = 0x29,
E_AA_USE_TELEPHONE = 0x2A,
E_AA_USE_STATIC_WEAPON = 0x2B,
E_AA_TV = 0x2C,
E_AA_TAKE_PINUP = 0x2D,
E_AA_DRAG_DEATH_BODY = 0x2E,
E_AA_STEALABLE_WEAPON = 0x2F,
E_AA_STEALABLE_SUIT = 0x30,
E_AA_STEALABLE_FOOD = 0x31,
E_AA_STEALABLE_AMMO = 0x32,
E_AA_OPEN_SHOP = 0x33,
E_AA_USE_MOUNTED_WEAPON = 0x34,
E_AA_LEAVE_MOUNTED_WEAPON = 0x35,
E_AA_OPEN_HEADQUARTERS = 0x36,
E_AA_OPEN_CRIME_BUSINESS = 0x37,
E_AA_TELEPORT = 0x38,
E_AA_BED = 0x39,
E_AA_DEAD_GUY_THROWN_OUT_CAR = 0x3A,
E_AA_BAILOUT_CAR = 0x3B,
E_AA_BAILOUT_MOTORCYCLE = 0x3C,
E_AA_INTERROGATE_IN_CAR = 0x3D,
E_AA_PICKUP_SATCHEL = 0x3E,
E_AA_PICKUP_BODY = 0x3F,
E_AA_PUT_BODY_IN_CAR_TRUNK = 0x40,
E_AA_REMOVE_BODY_FROM_CAR_TRUNK = 0x41,
E_AA_TURRET_MOUNT = 0x42,
E_AA_CAR_TURRET_MOUNT = 0x43,
E_AA_REVIVE = 0x44,
};

namespace ue::game::humanai {
class I_CharacterController {
public:
Expand Down
Loading