mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
commit
18d6e1f666
@ -130,12 +130,16 @@ namespace Hooks
|
||||
#pragma region Other
|
||||
int MSG_EngineError(char* fmt, va_list args);
|
||||
bool LoadPlaylist(const char* playlist);
|
||||
void CFPSPanel_Paint(void* thisptr);
|
||||
|
||||
using MSG_EngineErrorFn = int(*)(char*, va_list);
|
||||
extern MSG_EngineErrorFn originalMSG_EngineError;
|
||||
|
||||
using LoadPlaylistFn = bool(*)(const char*);
|
||||
extern LoadPlaylistFn originalLoadPlaylist;
|
||||
|
||||
using CFPSPanel_PaintFn = void(*)(void*);
|
||||
extern CFPSPanel_PaintFn originalCFPSPanel_Paint;
|
||||
#pragma endregion
|
||||
|
||||
void InstallHooks();
|
||||
|
33
r5dev/include/logsystem.h
Normal file
33
r5dev/include/logsystem.h
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#define LOGSYSTEM_LINES_TO_SHOW 3
|
||||
|
||||
enum LogType_t
|
||||
{
|
||||
SCRIPT_SERVER,
|
||||
SCRIPT_CLIENT,
|
||||
SCRIPT_UI,
|
||||
SCRIPT_WARNING,
|
||||
NATIVE
|
||||
};
|
||||
|
||||
struct Log
|
||||
{
|
||||
std::string Message = "";
|
||||
int Ticks = 1024;
|
||||
LogType_t Type = LogType_t::NATIVE;
|
||||
};
|
||||
|
||||
class LogSystem
|
||||
{
|
||||
|
||||
public:
|
||||
void AddLog(LogType_t type, std::string text);
|
||||
void Update();
|
||||
|
||||
private:
|
||||
std::array<int, 3> GetLogColorForType(LogType_t type);
|
||||
std::vector<Log> m_vLogs;
|
||||
};
|
||||
|
||||
extern LogSystem g_LogSystem;
|
@ -150,6 +150,11 @@ namespace
|
||||
FUNC_AT_ADDRESS(addr_KeyValues_FindKey, void*(*)(void*, const char*, bool), r5_patterns.PatternSearch("40 56 57 41 57 48 81 EC ?? ?? ?? ?? 45").GetPtr());
|
||||
#pragma endregion
|
||||
|
||||
#pragma region CFPSPanel
|
||||
/*0x14074A230*/
|
||||
FUNC_AT_ADDRESS(addr_CFPSPanel_Paint, void(*)(void*), r5_patterns.PatternSearch("48 8B C4 55 56 41 55 48 8D A8 ? ? ? ?").GetPtr());
|
||||
#pragma endregion
|
||||
|
||||
|
||||
void PrintHAddress() // Test the sigscan results
|
||||
{
|
||||
|
@ -327,6 +327,7 @@ if not EXIST $(SolutionDir)r5net\lib\$(Configuration)\r5net.lib (
|
||||
<ClInclude Include="include\id3dx.h" />
|
||||
<ClInclude Include="include\imgui_stdlib.h" />
|
||||
<ClInclude Include="include\input.h" />
|
||||
<ClInclude Include="include\logsystem.h" />
|
||||
<ClInclude Include="include\opcptc.h" />
|
||||
<ClInclude Include="include\CGameConsole.h" />
|
||||
<ClInclude Include="include\patterns.h" />
|
||||
@ -371,6 +372,7 @@ if not EXIST $(SolutionDir)r5net\lib\$(Configuration)\r5net.lib (
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\shared\utility.cpp" />
|
||||
<ClCompile Include="src\CCompanion.cpp" />
|
||||
<ClCompile Include="src\cfpspanel.cpp" />
|
||||
<ClCompile Include="src\console.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">pch.h</PrecompiledHeaderFile>
|
||||
@ -406,6 +408,7 @@ if not EXIST $(SolutionDir)r5net\lib\$(Configuration)\r5net.lib (
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\gui_utility.cpp" />
|
||||
<ClCompile Include="src\logsystem.cpp" />
|
||||
<ClCompile Include="src\opcptc.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">pch.h</PrecompiledHeaderFile>
|
||||
|
@ -112,6 +112,9 @@
|
||||
<Filter Include="hooks\src\cmatsystemsurface">
|
||||
<UniqueIdentifier>{a2663195-c4f2-4d5f-8d65-cfed54976e4c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="hooks\src\cfpspanel">
|
||||
<UniqueIdentifier>{10a22c13-763e-4054-bf6a-8f4b61697520}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\dllmain.cpp">
|
||||
@ -216,6 +219,12 @@
|
||||
<ClCompile Include="src\hooks\lockcursor.cpp">
|
||||
<Filter>hooks\src\cmatsystemsurface</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cfpspanel.cpp">
|
||||
<Filter>hooks\src\cfpspanel</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\logsystem.cpp">
|
||||
<Filter>r5-sdk\src</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\external\imgui\include\imgui_impl_win32.h">
|
||||
@ -591,6 +600,9 @@
|
||||
<ClInclude Include="include\squirrel.h">
|
||||
<Filter>r5-sdk\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\logsystem.h">
|
||||
<Filter>r5-sdk\include</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="r5dev.def">
|
||||
|
15
r5dev/src/cfpspanel.cpp
Normal file
15
r5dev/src/cfpspanel.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "pch.h"
|
||||
#include "hooks.h"
|
||||
#include "logsystem.h"
|
||||
|
||||
namespace Hooks
|
||||
{
|
||||
CFPSPanel_PaintFn originalCFPSPanel_Paint = nullptr;
|
||||
}
|
||||
|
||||
void Hooks::CFPSPanel_Paint(void* thisptr)
|
||||
{
|
||||
originalCFPSPanel_Paint(thisptr);
|
||||
|
||||
g_LogSystem.Update();
|
||||
}
|
@ -412,6 +412,8 @@ namespace GameGlobals
|
||||
void* ReloadBanListConCommand = CreateCustomConCommand("reloadbanlist", "Reloads the ban list from disk.", 0, CustomCommandVariations::ReloadBanList_Callback, nullptr);
|
||||
void* BanConCommand = CreateCustomConCommand("ban", "Bans a client from the Server via name. | Usage: ban (name)", 0, CustomCommandVariations::Ban_Callback, nullptr);
|
||||
void* BanIDConCommand = CreateCustomConCommand("banid", "Bans a client from the Server via originID, userID or IP | Usage: banid (originID/ipAddress/userID)", 0, CustomCommandVariations::BanID_Callback, nullptr);
|
||||
|
||||
ConVar* DrawConsoleOverlayConVar = CreateCustomConVar("cl_drawconsoleoverlay", "0", 0, "Draw the console overlay at the top of the screen", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void* CreateCustomConCommand(const char* name, const char* helpString, int flags, void* callback, void* callbackAfterExecution)
|
||||
|
@ -59,6 +59,7 @@ void Hooks::InstallHooks()
|
||||
// Hook Utility functions
|
||||
MH_CreateHook(addr_MSG_EngineError, &Hooks::MSG_EngineError, reinterpret_cast<void**>(&originalMSG_EngineError));
|
||||
MH_CreateHook(addr_LoadPlaylist, &Hooks::LoadPlaylist, reinterpret_cast<void**>(&originalLoadPlaylist));
|
||||
MH_CreateHook(addr_CFPSPanel_Paint, &Hooks::CFPSPanel_Paint, reinterpret_cast<void**>(&originalCFPSPanel_Paint));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Hook WinAPI
|
||||
@ -121,6 +122,7 @@ void Hooks::InstallHooks()
|
||||
// Enabled Utility hooks
|
||||
MH_EnableHook(addr_MSG_EngineError);
|
||||
MH_EnableHook(addr_LoadPlaylist);
|
||||
MH_EnableHook(addr_CFPSPanel_Paint);
|
||||
}
|
||||
|
||||
void Hooks::RemoveHooks()
|
||||
@ -156,11 +158,6 @@ void Hooks::RemoveHooks()
|
||||
// Unhook CMatSystemSurface functions
|
||||
MH_RemoveHook(addr_CMatSystemSurface_LockCursor);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Unhook Utility functions
|
||||
MH_RemoveHook(addr_MSG_EngineError);
|
||||
MH_RemoveHook(addr_LoadPlaylist);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Unhook WinAPI
|
||||
if (Module user32dll = Module("user32.dll"); user32dll.GetModuleBase()) // Is user32.dll valid?
|
||||
@ -175,6 +172,12 @@ void Hooks::RemoveHooks()
|
||||
MH_RemoveHook(ShowCursorPtr);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Unhook Utility functions
|
||||
MH_RemoveHook(addr_MSG_EngineError);
|
||||
MH_RemoveHook(addr_LoadPlaylist);
|
||||
MH_RemoveHook(addr_CFPSPanel_Paint);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Unhook CBaseFileSystem functions.
|
||||
//MH_RemoveHook(addr_CBaseFileSystem_FileSystemWarning);
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "hooks.h"
|
||||
#include "logsystem.h"
|
||||
|
||||
namespace Hooks
|
||||
{
|
||||
@ -48,6 +49,8 @@ void Hooks::NET_PrintFunc(const char* fmt, ...)
|
||||
std::string s = oss_print.str();
|
||||
const char* c = s.c_str();
|
||||
|
||||
g_LogSystem.AddLog(LogType_t::NATIVE, s);
|
||||
|
||||
Items.push_back(Strdup((const char*)c));
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "hooks.h"
|
||||
#include "logsystem.h"
|
||||
|
||||
namespace Hooks
|
||||
{
|
||||
@ -62,7 +63,10 @@ void* Hooks::SQVM_Print(void* sqvm, char* fmt, ...)
|
||||
std::string s = oss_print.str();
|
||||
const char* c = s.c_str();
|
||||
|
||||
Items.push_back(Strdup(c));
|
||||
g_LogSystem.AddLog((LogType_t)vmIdx, s);
|
||||
|
||||
Items.push_back(Strdup(c));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -113,6 +117,8 @@ __int64 Hooks::SQVM_Warning(void* sqvm, int a2, int a3, int* stringSize, void**
|
||||
std::string s = oss_warning.str();
|
||||
const char* c = s.c_str();
|
||||
|
||||
g_LogSystem.AddLog((LogType_t)vmIdx, s);
|
||||
|
||||
Items.push_back(Strdup(c));
|
||||
|
||||
return result;
|
||||
|
68
r5dev/src/logsystem.cpp
Normal file
68
r5dev/src/logsystem.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include "pch.h"
|
||||
#include "hooks.h"
|
||||
#include "logsystem.h"
|
||||
|
||||
LogSystem g_LogSystem;
|
||||
|
||||
void LogSystem::Update()
|
||||
{
|
||||
if (m_vLogs.empty())
|
||||
return;
|
||||
|
||||
static void* g_pMatSystemSurface = MemoryAddress(0x14D40B360).RCast<void* (*)()>();
|
||||
|
||||
int fontHeight = 16;
|
||||
|
||||
for (int i = 0; i < m_vLogs.size(); ++i) {
|
||||
if (m_vLogs[i].Ticks >= 0)
|
||||
{
|
||||
if (GameGlobals::Cvar->FindVar("cl_drawconsoleoverlay")->m_iValue < 1)
|
||||
return;
|
||||
|
||||
if (i < LOGSYSTEM_LINES_TO_SHOW) {
|
||||
|
||||
float fadepct = fminf(float(m_vLogs[i].Ticks) / 64.f, 1.0);
|
||||
|
||||
float ptc = (int)ceilf( fadepct * 255.f);
|
||||
int alpha = (int)ptc;
|
||||
|
||||
int y = (10 + (fontHeight * i));
|
||||
|
||||
std::array<int, 3> color = GetLogColorForType(m_vLogs[i].Type);
|
||||
|
||||
MemoryAddress(0x140547900).RCast<void(*)(void*, QWORD, __int64, QWORD, int, int, DWORD, DWORD, DWORD, const char*, ...)>()(g_pMatSystemSurface, 0x13, fontHeight, 10, y, color[0], color[1], color[2], alpha, m_vLogs[i].Message.c_str());
|
||||
}
|
||||
|
||||
m_vLogs[i].Ticks--;
|
||||
}
|
||||
else {
|
||||
m_vLogs.erase(m_vLogs.begin() + i);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void LogSystem::AddLog(LogType_t type, std::string message)
|
||||
{
|
||||
Log log;
|
||||
log.Message = message;
|
||||
log.Type = type;
|
||||
log.Ticks = 1024;
|
||||
if (m_vLogs.size() > LOGSYSTEM_LINES_TO_SHOW-1) {
|
||||
m_vLogs.erase(m_vLogs.begin());
|
||||
}
|
||||
m_vLogs.push_back(log);
|
||||
}
|
||||
|
||||
std::array<int, 3> LogSystem::GetLogColorForType(LogType_t type) {
|
||||
switch(type) {
|
||||
case LogType_t::NATIVE:
|
||||
return { 255, 255, 255 };
|
||||
case LogType_t::SCRIPT_SERVER:
|
||||
return { 190, 183, 240 };
|
||||
case LogType_t::SCRIPT_CLIENT:
|
||||
return { 117, 116, 139 };
|
||||
case LogType_t::SCRIPT_UI:
|
||||
return { 197, 160, 177 };
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user