Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/core/hooking/Hooking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace YimMenu
BaseHook::Add<Hooks::Matchmaking::MatchmakingUpdate>(new DetourHook("MatchmakingUpdate", Pointers.MatchmakingUpdate, Hooks::Matchmaking::MatchmakingUpdate));

BaseHook::Add<Hooks::Misc::AssistedAimShouldReleaseEntity>(new DetourHook("AssistedAimShouldReleaseEntity", Pointers.AssistedAimShouldReleaseEntity, Hooks::Misc::AssistedAimShouldReleaseEntity));
BaseHook::Add<Hooks::Misc::GetLabelText>(new DetourHook("GetLabelText", Pointers.GetLabelText, Hooks::Misc::GetLabelText));
BaseHook::Add<Hooks::Misc::GetLabelTextInternal>(new DetourHook("GetLabelTextInternal", Pointers.GetLabelTextInternal, Hooks::Misc::GetLabelTextInternal));
}

Hooking::~Hooking()
Expand Down
11 changes: 5 additions & 6 deletions src/core/memory/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace YimMenu
IMAGE_NT_HEADERS* GetNtHeader() const;

private:
template<typename R = void*, Symbol T>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Revert the changes to this file.

template<typename R, typename T>
R GetExportImpl(const T symbol) const;

private:
Expand Down Expand Up @@ -127,7 +127,7 @@ namespace YimMenu
return GetExportImpl<void*, decltype(ordinal)>(ordinal) != nullptr;
}

template<typename R, Symbol T>
template<typename R, typename T>
inline R Module::GetExportImpl(const T symbol) const
{
const auto ntHeader = GetNtHeader();
Expand All @@ -142,24 +142,23 @@ namespace YimMenu

for (std::size_t i = 0; i < exportDirectory->NumberOfNames; i++)
{
if constexpr (std::is_convertible_v<T, int>)
if constexpr (std::is_integral_v<T>)
{
if (exportDirectory->Base + ordinalOffsets[i] != symbol)
continue;

return m_Base.Add(funcOffsets[ordinalOffsets[i]]).As<R>();
}
else if constexpr (std::is_convertible_v<T, std::string_view>)
{
const auto functionName = m_Base.Add(namesOffsets[i]).As<const char*>();
if (strcmp(functionName, symbol.data()))
continue;

return m_Base.Add(funcOffsets[ordinalOffsets[i]]).As<R>();
}
else
{
static_assert(false, "Unsupported symbol type");
static_assert(std::is_integral_v<T> || std::is_convertible_v<T, std::string_view>,
"Unsupported symbol type");
}
}

Expand Down
39 changes: 39 additions & 0 deletions src/game/backend/CustomLabelText.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "CustomLabelText.hpp"

namespace YimMenu
{
void CustomLabelText::InitImpl()
{
AddLabelImpl(0x1B2EA75B, "YimMenu Story"); // Title Story Mode
AddLabelImpl(0xABB00DEB, "YimMenu"); // Title Pause Menu
AddLabelImpl(Joaat("PM_ENTER_MP"), "Play GTA Online with YimMenu");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use _J instead of Joaat. Also, I suggest you to remove all of these and add overrides for only these labels for now:

"HUD_BE_RESTART_EF_DISABLED_WITH_BE": "GTA Online requires BattlEye to be disabled. Please restart Grand Theft Auto V to disable BattlEye.",
"HUD_BE_RESTART_EF_ENABLED_NO_BE": "BattlEye is required to play GTA Online. Please restart Grand Theft Auto V to enable BattlEye.",
"HUD_BE_RESTART_SERVICE_NOT_RUNNING": "BattlEye is required to play GTA Online. Please restart Grand Theft Auto V to enable BattlEye.",

AddLabelImpl(Joaat("PM_EXIT_GAME"), "Quit GTA V with YimMenu");
AddLabelImpl(Joaat("PM_GO"), "Play with YimMenu");
AddLabelImpl(Joaat("HUD_MPREENTER"), "Joining a new session with YimMenu");
AddLabelImpl(Joaat("PM_FRIEND_FM"), "Closed Friend Session with YimMenu");
AddLabelImpl(Joaat("PM_INF_EXIT"), "Quit to desktop with YimMenu");
AddLabelImpl(Joaat("PM_CREWS"), "Join a Crew Only Session with YimMenu");
AddLabelImpl(Joaat("PM_INF_PGOT"), "Online with YimMenu");
AddLabelImpl(Joaat("PM_INVO_FM"), "Join an Invite Only Session with YimMenu");
AddLabelImpl(Joaat("LOADING_SPLAYER_L"), "Loading Story Mode with YimMenu");
AddLabelImpl(Joaat("PM_NCREW_FM"), "Join a Crew Session with YimMenu");
AddLabelImpl(Joaat("PM_CREW_FM"), "Join a Closed Crew Session with YimMenu");
AddLabelImpl(Joaat("PM_SOLO_FM"), "Join a Solo Session with YimMenu");
AddLabelImpl(Joaat("PM_FRESES"), "Join a Friends Only Session with YimMenu");
AddLabelImpl(Joaat("PM_CHOOSE_CHAR"), "Choose your personnage with YimMenu");
AddLabelImpl(Joaat("PM_INF_PGOT"), "Online with YimMenu");
}

bool CustomLabelText::AddLabelImpl(joaat_t hash, const std::string_view text)
{
const auto size = text.size() + 1;
auto buffer = std::make_unique<char[]>(size);
memcpy(buffer.get(), text.data(), size);
return m_LabelOverwrites.insert({hash, std::move(buffer)}).second;
}

bool CustomLabelText::AddLabelImpl(joaat_t hash, CustomLabelText_t&& cb)
{
return m_Labels.insert({hash, std::move(cb)}).second;
}
}
79 changes: 79 additions & 0 deletions src/game/backend/CustomLabelText.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#pragma once
#include "core/util/Joaat.hpp"

namespace YimMenu
{
using CustomLabelText_t = std::function<const char*(const char*)>;
class CustomLabelText
{
static CustomLabelText& GetInstance()
{
static CustomLabelText instance;
return instance;
}
public:
static uint64_t ComputeHash(const char* str)
{
return Joaat(str);
}
static uint64_t ComputeHash(uint64_t value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove these two.

{
return value;
}

static void Init()
{
return GetInstance().InitImpl();
}

static bool AddLabel(joaat_t hash, const std::string_view text)
{
return GetInstance().AddLabelImpl(hash, text);
}

static bool AddLabel(joaat_t hash, CustomLabelText_t&& cb)
{
return GetInstance().AddLabelImpl(hash, std::move(cb));
}

template<typename T>
static const char* GetText(const T& label)
{
return GetInstance().GetTextImpl(label);
}
private:
bool AddLabelImpl(joaat_t hash, const std::string_view text);
bool AddLabelImpl(joaat_t hash, CustomLabelText_t&& cb);

void InitImpl();

template<typename T>
const char* GetTextImpl(const T& label) const
Copy link
Collaborator

Choose a reason for hiding this comment

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

Only accept uint32_t.

{
uint64_t hash;

if constexpr (std::is_same_v<T, const char*>)
hash = ComputeHash(label);
else if constexpr (std::is_same_v<T, uint32_t>)
hash = ComputeHash(label);
else
static_assert(sizeof(T) == 0, "Label type Unsupported");

if (const auto& it = m_Labels.find(hash); it != m_Labels.end())
{
if constexpr (std::is_same_v<T, const char*>)
return it->second(label);
else
return it->second(nullptr);
}

if (const auto& it = m_LabelOverwrites.find(hash); it != m_LabelOverwrites.end())
return it->second.get();

return nullptr;
}

std::unordered_map<uint64_t, std::function<const char*(const char*)>> m_Labels;
std::unordered_map<joaat_t, std::unique_ptr<char[]>> m_LabelOverwrites;
};
}
2 changes: 2 additions & 0 deletions src/game/hooks/Hooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,7 @@ namespace YimMenu::Hooks
namespace Misc
{
extern bool AssistedAimShouldReleaseEntity(__int64 a1);
extern const char* GetLabelText(void* unk, const char* label);
extern const char* GetLabelTextInternal(void* this_, uint32_t label_hash);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need GetLabelText as it just calls the other one anyway. Remove it and rename GetLabelTextInternal to GetLabelText.

}
}
14 changes: 14 additions & 0 deletions src/game/hooks/Misc/GetLabelText.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "core/hooking/DetourHook.hpp"
#include "game/hooks/Hooks.hpp"
#include "game/backend/CustomLabelText.hpp"

namespace YimMenu::Hooks
{
const char* Misc::GetLabelText(void* unk, const char* label)
{
if (const auto text = CustomLabelText::GetText<const char*>(label); text)
return text;

return BaseHook::Get<Misc::GetLabelText, DetourHook<decltype(&Misc::GetLabelText)>>()->Original()(unk, label);
}
}
14 changes: 14 additions & 0 deletions src/game/hooks/Misc/GetLabelTextInternal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "core/hooking/DetourHook.hpp"
#include "game/hooks/Hooks.hpp"
#include "game/backend/CustomLabelText.hpp"

namespace YimMenu::Hooks
{
const char* Misc::GetLabelTextInternal(void* this_, uint32_t label_hash)
{
if (const auto text = CustomLabelText::GetText<uint32_t>(label_hash); text)
return text;

return BaseHook::Get<Misc::GetLabelTextInternal, DetourHook<decltype(&Misc::GetLabelTextInternal)>>()->Original()(this_, label_hash);
}
}
7 changes: 6 additions & 1 deletion src/game/pointers/Pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,17 @@ namespace YimMenu
scanner.Add(matchmakingSessionDetailSendResponsePtrn, [this](PointerCalculator addr) {
MatchmakingSessionDetailSendResponse = addr.Add(0x2F).Rip().As<PVOID>();
});

static constexpr auto gameSkeletonUpdatePtrn = Pattern<"56 48 83 EC 20 48 8B 81 40 01 00 00 48 85 C0">("GameSkeletonUpdate");
scanner.Add(gameSkeletonUpdatePtrn, [this](PointerCalculator addr) {
GameSkeletonUpdate = addr.As<PVOID>();
});

static constexpr auto getLabelTextPtrn = Pattern<"56 48 83 EC 20 48 85 D2 74 25 0F B6 02 A8 DF 74 23 48 89 CE 48 89 D1 31 D2 E8 ? ? ? ? 48 89 F1 89 C2 E8 ? ? ? ?">("GetLabelText&GetLabelTextInternal");
scanner.Add(getLabelTextPtrn, [this](PointerCalculator addr) {
GetLabelText = addr.As<PVOID>();
GetLabelTextInternal = addr.Add(36).Rip().As<PVOID>();
});

if (!scanner.Scan())
{
LOG(FATAL) << "Some patterns could not be found, unloading.";
Expand Down
2 changes: 2 additions & 0 deletions src/game/pointers/Pointers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ namespace YimMenu
PVOID MatchmakingUnadvertise;
PVOID MatchmakingSessionDetailSendResponse;
PVOID GameSkeletonUpdate;
PVOID GetLabelText;
PVOID GetLabelTextInternal;
};

struct Pointers : PointerData
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "game/features/vehicle/SavePersonalVehicle.hpp"
#include "game/features/self/OpenGunLocker.hpp"
#include "game/features/recovery/DailyActivities.hpp"
#include "game/backend/CustomLabelText.hpp"

namespace YimMenu
{
Expand Down Expand Up @@ -83,6 +84,8 @@ namespace YimMenu
if (!Pointers.LateInit())
LOG(WARNING) << "Socialclub patterns failed to load";

CustomLabelText::Init();

Notifications::Show("YimMenuV2", "Loaded succesfully", NotificationType::Success);

if (InWine().value_or(false))
Expand Down