Skip to content

Commit

Permalink
Merge branch 'master' into Train-&-Object-Spawner
Browse files Browse the repository at this point in the history
  • Loading branch information
Rxann authored Jul 22, 2024
2 parents bd70bed + 094174a commit 43c52f2
Show file tree
Hide file tree
Showing 71 changed files with 1,208 additions and 267 deletions.
2 changes: 1 addition & 1 deletion src/core/frontend/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace YimMenu

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

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

auto style = ImGui::GetStyle();
// TODO: Add icon for type instead of colored text
Expand Down
2 changes: 2 additions & 0 deletions src/core/hooking/Hooking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace YimMenu
BaseHook::Add<Hooks::Protections::SerializeServerRPC>(new DetourHook("SerializeServerRPC", Pointers.SerializeServerRPC, Hooks::Protections::SerializeServerRPC));
BaseHook::Add<Hooks::Protections::ReceiveServerMessage>(new DetourHook("ReceiveServerMessage", Pointers.ReceiveServerMessage, Hooks::Protections::ReceiveServerMessage));
BaseHook::Add<Hooks::Protections::ReceiveArrayUpdate>(new DetourHook("ReceiveArrayUpdate", Pointers.ReceiveArrayUpdate, Hooks::Protections::ReceiveArrayUpdate));

BaseHook::Add<Hooks::Protections::CreatePoolItem>(new DetourHook("CreatePoolItem", Pointers.CreatePoolItem, Hooks::Protections::CreatePoolItem));

BaseHook::Add<Hooks::Voice::EnumerateAudioDevices>(new DetourHook("EnumerateAudioDevices", Pointers.EnumerateAudioDevices, Hooks::Voice::EnumerateAudioDevices));
Expand All @@ -65,6 +66,7 @@ namespace YimMenu

BaseHook::Add<Hooks::Spoofing::WritePlayerHealthData>(new DetourHook("WritePlayerHealthData", Pointers.WritePlayerHealthData, Hooks::Spoofing::WritePlayerHealthData));
BaseHook::Add<Hooks::Spoofing::SendNetInfoToLobby>(new DetourHook("SendNetInfoToLobby", Pointers.SendNetInfoToLobby, Hooks::Spoofing::SendNetInfoToLobby));
BaseHook::Add<Hooks::Spoofing::WriteVPMData>(new DetourHook("WriteVehicleProximityMigrationData", Pointers.WriteVPMData, Hooks::Spoofing::WriteVPMData));

BaseHook::Add<Hooks::Toxic::BroadcastNetArray>(new DetourHook("BroadcastNetArray", Pointers.BroadcastNetArray, Hooks::Toxic::BroadcastNetArray));
}
Expand Down
20 changes: 19 additions & 1 deletion src/core/logger/ExceptionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,25 @@ namespace YimMenu
LOG(FATAL) << "Cannot resume execution, crashing";
return EXCEPTION_CONTINUE_SEARCH;
}
exception_info->ContextRecord->Rip += opcode.len;

if (opcode.opcode == 0xFF && opcode.modrm_reg == 4) // JMP (FF /4)
{
auto return_address_ptr = (uint64_t*)exception_info->ContextRecord->Rsp;
if (IsBadReadPtr(reinterpret_cast<void*>(return_address_ptr), 8))
{
LOG(FATAL) << "Cannot resume execution, crashing";
return EXCEPTION_CONTINUE_SEARCH;
}
else
{
exception_info->ContextRecord->Rip = *return_address_ptr;
exception_info->ContextRecord->Rsp += 8;
}
}
else
{
exception_info->ContextRecord->Rip += opcode.len;
}
}

return EXCEPTION_CONTINUE_EXECUTION;
Expand Down
72 changes: 55 additions & 17 deletions src/core/logger/StackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ namespace YimMenu

m_ExceptionInfo = exception_info;

Clear();

m_Dump << ExceptionCodeToString(exception_info->ExceptionRecord->ExceptionCode) << '\n';

DumpModuleInfo();
DumpRegisters();
DumpStacktrace();
DumpCPPExceptionInfo();
DumpExceptionInfo();

m_Dump << "\n--------End of exception--------\n";
}
Expand All @@ -42,6 +44,12 @@ namespace YimMenu
return m_Dump.str();
}

void StackTrace::Clear()
{
m_Dump.str("");
m_Dump.clear();
}

// I'd prefer to make some sort of global instance that cache all modules once instead of doing this every time
void StackTrace::DumpModuleInfo()
{
Expand Down Expand Up @@ -71,8 +79,7 @@ namespace YimMenu
{
auto mod_info = ModuleInfo(table_entry->FullDllName.Buffer, table_entry->DllBase);

m_Dump << mod_info.m_Path.filename().string() << " Base Address: " << HEX(mod_info.m_Base)
<< " Size: " << mod_info.m_Size << '\n';
m_Dump << mod_info.m_Name << " Base Address: " << HEX(mod_info.m_Base) << " Size: " << mod_info.m_Size << '\n';

m_Modules.emplace_back(std::move(mod_info));
}
Expand Down Expand Up @@ -122,39 +129,70 @@ namespace YimMenu

for (size_t i = 0; i < m_FramePointers.size() && m_FramePointers[i]; ++i)
{
const auto addr = m_FramePointers[i];
const auto addr = m_FramePointers[i];
const auto module_info = GetModuleByAddress(addr);

m_Dump << "\n[" << i << "]\t";
if (SymFromAddr(GetCurrentProcess(), addr, &displacement64, symbol))
{
if (SymGetLineFromAddr64(GetCurrentProcess(), addr, &displacement, &line))
{
m_Dump << line.FileName << " L: " << line.LineNumber << " " << std::string_view(symbol->Name, symbol->NameLen);
m_Dump << line.FileName << " L: " << line.LineNumber << ' ' << std::string_view(symbol->Name, symbol->NameLen);

continue;
}

if (module_info)
{
m_Dump << module_info->m_Name << ' ' << std::string_view(symbol->Name, symbol->NameLen) << " ("
<< module_info->m_Name << '+' << HEX(addr - module_info->m_Base) << ')';

continue;
}
const auto module_info = GetModuleByAddress(addr);

if (module_info->m_Base == (uint64_t)GetModuleHandle(0))
m_Dump << module_info->m_Path.filename().string() << " " << std::string_view(symbol->Name, symbol->NameLen) << " ("
<< module_info->m_Path.filename().string() << "+" << HEX(addr - module_info->m_Base) << ")";
else
m_Dump << module_info->m_Path.filename().string() << " " << std::string_view(symbol->Name, symbol->NameLen);
m_Dump << HEX(addr) << ' ' << std::string_view(symbol->Name, symbol->NameLen);

continue;
}
const auto module_info = GetModuleByAddress(addr);
m_Dump << module_info->m_Path.filename().string() << "+" << HEX(addr - module_info->m_Base) << " " << HEX(addr);

if (module_info)
{
m_Dump << module_info->m_Name << '+' << HEX(addr - module_info->m_Base) << ' ' << HEX(addr);

continue;
}

m_Dump << HEX(addr);
}
}

void StackTrace::DumpCPPExceptionInfo()
void StackTrace::DumpExceptionInfo()
{
DWORD exception_code = m_ExceptionInfo->ExceptionRecord->ExceptionCode;

constexpr DWORD msvc_exception_code = 0xe06d7363;
if (m_ExceptionInfo->ExceptionRecord->ExceptionCode == msvc_exception_code)
if (exception_code == msvc_exception_code)
{
m_Dump << '\n'
<< reinterpret_cast<const std::exception*>(m_ExceptionInfo->ExceptionRecord->ExceptionInformation[1])->what() << '\n';
}
else if (exception_code == EXCEPTION_ACCESS_VIOLATION || exception_code == EXCEPTION_IN_PAGE_ERROR)
{
m_Dump
<< reinterpret_cast<const std::exception*>(m_ExceptionInfo->ExceptionRecord->ExceptionInformation[1])->what() << '\n';
const auto flag = m_ExceptionInfo->ExceptionRecord->ExceptionInformation[0];
const auto addr = m_ExceptionInfo->ExceptionRecord->ExceptionInformation[1];

switch (flag)
{
case EXCEPTION_READ_FAULT: m_Dump << '\n' << "Attempted to read from " << HEX(addr) << '\n'; break;
case EXCEPTION_WRITE_FAULT: m_Dump << '\n' << "Attempted to write to " << HEX(addr) << '\n'; break;
case EXCEPTION_EXECUTE_FAULT: m_Dump << '\n' << "DEP at " << HEX(addr) << '\n'; break;
default: m_Dump << '\n' << "Inaccessible data at " << HEX(addr) << '\n';
}

if (exception_code == EXCEPTION_IN_PAGE_ERROR)
{
m_Dump << "NTSTATUS code " << HEX(m_ExceptionInfo->ExceptionRecord->ExceptionInformation[2]) << '\n';
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/core/logger/StackTrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace YimMenu
const std::vector<uint64_t>& GetFramePointers();
void NewStackTrace(EXCEPTION_POINTERS* exception_info);
std::string GetString() const;
void Clear();

friend std::ostream& operator<<(std::ostream& os, const StackTrace& st);
friend std::ostream& operator<<(std::ostream& os, const StackTrace* st);
Expand All @@ -19,7 +20,7 @@ namespace YimMenu
struct ModuleInfo
{
ModuleInfo(std::filesystem::path path, void* base) :
m_Path(path),
m_Name(path.filename().string()),
m_Base(reinterpret_cast<uintptr_t>(base))
{
const auto dos_header = reinterpret_cast<IMAGE_DOS_HEADER*>(base);
Expand All @@ -28,7 +29,7 @@ namespace YimMenu
m_Size = nt_header->OptionalHeader.SizeOfCode;
}

std::filesystem::path m_Path;
std::string m_Name;
uintptr_t m_Base;
size_t m_Size;
};
Expand All @@ -37,7 +38,7 @@ namespace YimMenu
void DumpModuleInfo();
void DumpRegisters();
void DumpStacktrace();
void DumpCPPExceptionInfo();
void DumpExceptionInfo();
void GrabStacktrace();
const ModuleInfo* GetModuleByAddress(uint64_t addr) const;

Expand Down
2 changes: 1 addition & 1 deletion src/core/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace YimMenu
for (auto& serializer : m_StateSerializers)
LoadComponentImpl(serializer);

LOG(VERBOSE) << "Initial Settings Load Completed";
LOG(VERBOSE) << "All settings loaded";
m_InitialLoadDone = true;
}

Expand Down
1 change: 0 additions & 1 deletion src/game/backend/NativeHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ namespace YimMenu
{
if (scp->m_NameHash == script || script == ALL_SCRIPTS)
{
LOG(VERBOSE) << "Applying native hook on existing script";
program->Apply(Hook(index, hook));
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/game/backend/Players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,36 @@

namespace YimMenu
{
void Players::TickImpl()
Players::Players()
{
const auto& playerMgr = Pointers.NetworkPlayerMgr;
if (!playerMgr || !g_Running)
if (!playerMgr)
return;

for (uint8_t idx = 0; idx < 32u; idx++)
{
if (const auto& netPlayer = playerMgr->m_PlayerList[idx];
netPlayer && (Pointers.GetNetPlayerFromPid(idx) == netPlayer /*game also does this*/) && netPlayer->IsValid())
netPlayer && (Pointers.GetNetPlayerFromPid(idx) == netPlayer) && netPlayer->IsValid())
{
m_Players[idx] = Player(idx);
if (!m_PlayerDatas.contains(idx))
m_PlayerDatas[idx] = PlayerData();
}
else
{
m_Players.erase(idx);
m_PlayerDatas.erase(idx);
}
}
}

void Players::OnPlayerJoinImpl(CNetGamePlayer* player)
{
m_Players[player->m_PlayerIndex] = Player(player);
m_PlayerDatas[player->m_PlayerIndex] = PlayerData();
}

void Players::OnPlayerLeaveImpl(CNetGamePlayer* player)
{
m_Players.erase(player->m_PlayerIndex);
m_PlayerDatas.erase(player->m_PlayerIndex);
}

Player Players::GetByRIDImpl(uint64_t rid)
{
for (auto& [idx, player] : Players::GetPlayers())
Expand Down
14 changes: 11 additions & 3 deletions src/game/backend/Players.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ namespace YimMenu
Player m_SelectedPlayer = Player((uint8_t)0);

public:
static void Tick()
static void OnPlayerJoin(CNetGamePlayer* player)
{
GetInstance().TickImpl();
GetInstance().OnPlayerJoinImpl(player);
}

static void OnPlayerLeave(CNetGamePlayer* player)
{
GetInstance().OnPlayerLeaveImpl(player);
}

static Player GetSelected()
Expand Down Expand Up @@ -61,13 +66,16 @@ namespace YimMenu
}

private:
Players();

static Players& GetInstance()
{
static Players Instance;
return Instance;
}

void TickImpl();
void OnPlayerJoinImpl(CNetGamePlayer* player);
void OnPlayerLeaveImpl(CNetGamePlayer* player);
Player GetByRIDImpl(uint64_t rid);
Player GetByHostTokenImpl(uint64_t token);
};
Expand Down
7 changes: 4 additions & 3 deletions src/game/backend/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ namespace YimMenu
m_ChildFiber = CreateFiber(
0,
[](void* param) {
auto this_script = static_cast<Script*>(param);
this_script->m_Done = true;
auto this_script = static_cast<Script*>(param);
this_script->m_Callback();
this_script->m_Done = true;
SwitchToFiber(this_script->m_MainFiber);
},
this);
}
Expand All @@ -29,7 +30,7 @@ namespace YimMenu
void Script::Tick()
{
m_MainFiber = GetCurrentFiber();
if (!m_WakeTime.has_value() || m_WakeTime.value() <= std::chrono::high_resolution_clock::now())
if ((!m_WakeTime.has_value() || m_WakeTime.value() <= std::chrono::high_resolution_clock::now()) && !m_Done)
{
SwitchToFiber(m_ChildFiber);
}
Expand Down
Loading

0 comments on commit 43c52f2

Please sign in to comment.