Cleanup game
This commit is contained in:
parent
ef39098e28
commit
82270c0b78
@ -2,6 +2,7 @@
|
|||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
|
||||||
|
#include "game/game.hpp"
|
||||||
#include "steam/steam.hpp"
|
#include "steam/steam.hpp"
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
|
|
||||||
@ -479,7 +480,7 @@ namespace arxan
|
|||||||
uint32_t adjust_integrity_checksum(const uint64_t return_address, uint8_t* stack_frame,
|
uint32_t adjust_integrity_checksum(const uint64_t return_address, uint8_t* stack_frame,
|
||||||
const uint32_t current_checksum)
|
const uint32_t current_checksum)
|
||||||
{
|
{
|
||||||
const auto handler_address = reverse_g(return_address - 5);
|
const auto handler_address = game::derelocate(return_address - 5);
|
||||||
const auto* context = search_handler_context(stack_frame, current_checksum);
|
const auto* context = search_handler_context(stack_frame, current_checksum);
|
||||||
|
|
||||||
if (!context)
|
if (!context)
|
||||||
|
@ -124,9 +124,7 @@ namespace console
|
|||||||
|
|
||||||
void sys_create_console_stub(const HINSTANCE h_instance)
|
void sys_create_console_stub(const HINSTANCE h_instance)
|
||||||
{
|
{
|
||||||
// C6262
|
char text[CONSOLE_BUFFER_SIZE]{0};
|
||||||
char text[CONSOLE_BUFFER_SIZE];
|
|
||||||
char clean_console_buffer[CONSOLE_BUFFER_SIZE];
|
|
||||||
|
|
||||||
const auto* class_name = "BOIII WinConsole";
|
const auto* class_name = "BOIII WinConsole";
|
||||||
const auto* window_name = "BOIII Console";
|
const auto* window_name = "BOIII Console";
|
||||||
@ -206,9 +204,8 @@ namespace console
|
|||||||
0);
|
0);
|
||||||
|
|
||||||
SetFocus(*game::s_wcd::hwndInputLine);
|
SetFocus(*game::s_wcd::hwndInputLine);
|
||||||
game::Con_GetTextCopy(text, 0x4000);
|
game::Con_GetTextCopy(text, std::min(0x4000, static_cast<int>(sizeof(text))));
|
||||||
game::Conbuf_CleanText(text, clean_console_buffer);
|
SetWindowTextA(*game::s_wcd::hwndBuffer, text);
|
||||||
SetWindowTextA(*game::s_wcd::hwndBuffer, clean_console_buffer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ namespace exception
|
|||||||
const std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p (0x%p).\n"
|
const std::string error_str = utils::string::va("Fatal error (0x%08X) at 0x%p (0x%p).\n"
|
||||||
"A minidump has been written.\n",
|
"A minidump has been written.\n",
|
||||||
exception_data.code, exception_data.address,
|
exception_data.code, exception_data.address,
|
||||||
reverse_g(reinterpret_cast<uint64_t>(exception_data.address)));
|
game::derelocate(reinterpret_cast<uint64_t>(exception_data.address)));
|
||||||
|
|
||||||
utils::thread::suspend_other_threads();
|
utils::thread::suspend_other_threads();
|
||||||
show_mouse_cursor();
|
show_mouse_cursor();
|
||||||
@ -92,7 +92,7 @@ namespace exception
|
|||||||
"Make sure to update your graphics card drivers and install operating system updates!\n"
|
"Make sure to update your graphics card drivers and install operating system updates!\n"
|
||||||
"Closing or restarting Steam might also help.",
|
"Closing or restarting Steam might also help.",
|
||||||
exception_data.code, exception_data.address,
|
exception_data.code, exception_data.address,
|
||||||
reverse_g(reinterpret_cast<uint64_t>(exception_data.address)));
|
game::derelocate(reinterpret_cast<uint64_t>(exception_data.address)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -139,7 +139,7 @@ namespace exception
|
|||||||
line("Timestamp: "s + get_timestamp());
|
line("Timestamp: "s + get_timestamp());
|
||||||
line(utils::string::va("Exception: 0x%08X", exceptioninfo->ExceptionRecord->ExceptionCode));
|
line(utils::string::va("Exception: 0x%08X", exceptioninfo->ExceptionRecord->ExceptionCode));
|
||||||
line(utils::string::va("Address: 0x%llX", exceptioninfo->ExceptionRecord->ExceptionAddress));
|
line(utils::string::va("Address: 0x%llX", exceptioninfo->ExceptionRecord->ExceptionAddress));
|
||||||
line(utils::string::va("Base: 0x%llX", get_base()));
|
line(utils::string::va("Base: 0x%llX", game::get_base()));
|
||||||
|
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable: 4996)
|
#pragma warning(disable: 4996)
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
|
||||||
|
#include "game/game.hpp"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
#include <utils/concurrency.hpp>
|
#include <utils/concurrency.hpp>
|
||||||
|
@ -1,49 +1,22 @@
|
|||||||
#include <std_include.hpp>
|
#include <std_include.hpp>
|
||||||
|
|
||||||
#include "loader/component_loader.hpp"
|
|
||||||
#include "game.hpp"
|
#include "game.hpp"
|
||||||
|
#include <utils/nt.hpp>
|
||||||
|
|
||||||
namespace game
|
namespace game
|
||||||
{
|
{
|
||||||
// inlined in cod, functionality stolen from https://github.com/id-Software/Quake-III-Arena/blob/master/code/win32/win_syscon.c#L520
|
size_t get_base()
|
||||||
int Conbuf_CleanText(const char* source, char* target)
|
|
||||||
{
|
{
|
||||||
char* b = target;
|
static auto base = []
|
||||||
int i = 0;
|
|
||||||
while (source[i] && ((b - target) < sizeof(target) - 1))
|
|
||||||
{
|
{
|
||||||
if (source[i] == '\n' && source[i + 1] == '\r')
|
const utils::nt::library host{};
|
||||||
|
if (!host || host == utils::nt::library::get_by_address(get_base))
|
||||||
{
|
{
|
||||||
b[0] = '\r';
|
throw std::runtime_error("Invalid host application");
|
||||||
b[1] = '\n';
|
|
||||||
b += 2;
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else if (source[i] == '\r' || source[i] == '\n')
|
|
||||||
{
|
|
||||||
b[0] = '\r';
|
|
||||||
b[1] = '\n';
|
|
||||||
b += 2;
|
|
||||||
}
|
|
||||||
else if (source && source[0] == '^' && source[1] && source[1] != '^' && source[1] >= 48 && source[1] <= 64)
|
|
||||||
// Q_IsColorString
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*b = source[i]; // C6011 here, should we be worried?
|
|
||||||
b++;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
*b = 0;
|
return size_t(host.get_ptr());
|
||||||
return static_cast<int>(b - target);
|
}();
|
||||||
}
|
return base;
|
||||||
|
|
||||||
game::eModes Com_SessionMode_GetMode()
|
|
||||||
{
|
|
||||||
return game::eModes(*reinterpret_cast<uint32_t*>(0x1568EF7F4_g) << 28 >> 28);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "structs.hpp"
|
#include "structs.hpp"
|
||||||
#include "loader/component_loader.hpp"
|
|
||||||
|
|
||||||
namespace game
|
namespace game
|
||||||
{
|
{
|
||||||
#define Com_Error(code, fmt, ...) \
|
size_t get_base();
|
||||||
Com_Error_(__FILE__, __LINE__, code, fmt, ##__VA_ARGS__)
|
|
||||||
|
|
||||||
int Conbuf_CleanText(const char* source, char* target);
|
inline size_t relocate(const size_t val)
|
||||||
game::eModes Com_SessionMode_GetMode();
|
{
|
||||||
|
const auto base = get_base();
|
||||||
|
return base + (val - 0x140000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t derelocate(const size_t val)
|
||||||
|
{
|
||||||
|
const auto base = get_base();
|
||||||
|
return (val - base) + 0x140000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline size_t derelocate(const void* val)
|
||||||
|
{
|
||||||
|
return derelocate(reinterpret_cast<size_t>(val));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class symbol
|
class symbol
|
||||||
@ -22,7 +34,7 @@ namespace game
|
|||||||
|
|
||||||
T* get() const
|
T* get() const
|
||||||
{
|
{
|
||||||
return reinterpret_cast<T*>(get_game_address(this->address_));
|
return reinterpret_cast<T*>(relocate(this->address_));
|
||||||
}
|
}
|
||||||
|
|
||||||
operator T*() const
|
operator T*() const
|
||||||
@ -43,4 +55,9 @@ namespace game
|
|||||||
constexpr auto CMD_MAX_NESTING = 8;
|
constexpr auto CMD_MAX_NESTING = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline size_t operator"" _g(const size_t val)
|
||||||
|
{
|
||||||
|
return game::relocate(val);
|
||||||
|
}
|
||||||
|
|
||||||
#include "symbols.hpp"
|
#include "symbols.hpp"
|
||||||
|
11
src/client/game/symbols.cpp
Normal file
11
src/client/game/symbols.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <std_include.hpp>
|
||||||
|
|
||||||
|
#include "game.hpp"
|
||||||
|
|
||||||
|
namespace game
|
||||||
|
{
|
||||||
|
eModes Com_SessionMode_GetMode()
|
||||||
|
{
|
||||||
|
return eModes(*reinterpret_cast<uint32_t*>(0x1568EF7F4_g) << 28 >> 28);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
namespace game
|
namespace game
|
||||||
{
|
{
|
||||||
|
#define Com_Error(code, fmt, ...) \
|
||||||
|
Com_Error_(__FILE__, __LINE__, code, fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
// CL
|
// CL
|
||||||
WEAK symbol<void(int controllerIndex, XSESSION_INFO* hostInfo, const netadr_t* addr, int numPublicSlots,
|
WEAK symbol<void(int controllerIndex, XSESSION_INFO* hostInfo, const netadr_t* addr, int numPublicSlots,
|
||||||
int numPrivateSlots, const char* mapname, const char* gametype)> CL_ConnectFromLobby
|
int numPrivateSlots, const char* mapname, const char* gametype)> CL_ConnectFromLobby
|
||||||
@ -77,4 +80,7 @@ namespace game
|
|||||||
WEAK symbol<int> windowWidth{0x157E78068};
|
WEAK symbol<int> windowWidth{0x157E78068};
|
||||||
WEAK symbol<WNDPROC> SysInputLineWndProc{0x157E78070};
|
WEAK symbol<WNDPROC> SysInputLineWndProc{0x157E78070};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reimplementations
|
||||||
|
eModes Com_SessionMode_GetMode();
|
||||||
}
|
}
|
||||||
|
@ -163,40 +163,3 @@ namespace component_loader
|
|||||||
throw premature_shutdown_trigger();
|
throw premature_shutdown_trigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t get_base()
|
|
||||||
{
|
|
||||||
static auto base = []
|
|
||||||
{
|
|
||||||
const utils::nt::library host{};
|
|
||||||
if (!host || host == utils::nt::library::get_by_address(get_base))
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid host application");
|
|
||||||
}
|
|
||||||
|
|
||||||
return size_t(host.get_ptr());
|
|
||||||
}();
|
|
||||||
return base;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t get_game_address(const size_t val)
|
|
||||||
{
|
|
||||||
static auto base = get_base();
|
|
||||||
return base + (val - 0x140000000);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t operator"" _g(const size_t val)
|
|
||||||
{
|
|
||||||
return get_game_address(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t reverse_g(const size_t val)
|
|
||||||
{
|
|
||||||
static auto base = get_base();
|
|
||||||
return (val - base) + 0x140000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t reverse_g(const void* val)
|
|
||||||
{
|
|
||||||
return reverse_g(reinterpret_cast<size_t>(val));
|
|
||||||
}
|
|
||||||
|
@ -43,9 +43,3 @@ namespace \
|
|||||||
{ \
|
{ \
|
||||||
static component_loader::installer<name> __component; \
|
static component_loader::installer<name> __component; \
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t get_base();
|
|
||||||
size_t get_game_address(size_t val);
|
|
||||||
size_t operator"" _g(size_t val);
|
|
||||||
size_t reverse_g(size_t val);
|
|
||||||
size_t reverse_g(const void* val);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user