experiments pt7

This commit is contained in:
quaK 2022-09-27 05:17:44 +03:00
parent 5d058f79c5
commit 6dc1b222e6
5 changed files with 127 additions and 89 deletions

View File

@ -24,55 +24,24 @@ namespace dedicated
void init_dedicated_server()
{
printf("init called...\n");
// R_RegisterDvars
utils::hook::invoke<void>(0xDF62C0_b);
// R_RegisterCmds
utils::hook::invoke<void>(0xDD7E50_b);
// RB_Tonemap_RegisterDvars
utils::hook::invoke<void>(0x4B1320_b);
static bool initialized = false;
if (initialized) return;
initialized = true;
// R_RegisterDvars
//utils::hook::invoke<void>(0xDF62C0_b);
// R_RegisterCmds
//utils::hook::invoke<void>(0xDD7E50_b);
// R_LoadGraphicsAssets
utils::hook::invoke<void>(0xE06220_b);
}
utils::hook::detour dvar_set_float_from_source_hook;
void dvar_set_float_from_source_stub(const game::dvar_t* dvar, double value, game::DvarSetSource source)
{
if (dvar)
{
printf("%s\n", dvars::dvar_get_name(dvar).data());
}
else
{
printf("fuck\n");
return;
}
dvar_set_float_from_source_hook.invoke<void>(dvar, value, source);
}
utils::hook::detour cmd_add_client_command_list_hook;
void cmd_add_client_command_list_stub(game::SvCommandInfo* cmds, unsigned int size)
{
printf("add: %p, %d\n", cmds, size);
for (auto i = 0u; i < size; i++)
{
/*printf("cmd[%d]: name: %s, func: %p, svvar.name: %s, svvar.func: %p, svvar.next: %p\n",
i,
cmds[i].name,
cmds[i].function,
cmds[i].svvar.name,
cmds[i].svvar.function,
cmds[i].svvar.next);*/
//memset(&cmds[i].svvar, 0, sizeof(game::cmd_function_s));
}
cmd_add_client_command_list_hook.invoke<void>(cmds, size);
}
}
DWORD __stdcall wait_for_single_object_stub(HANDLE handle, DWORD ms)
@ -119,11 +88,7 @@ namespace dedicated
#ifdef DEBUG
printf("Starting dedicated server\n");
#endif
dvar_set_float_from_source_hook.create(0xCECD00_b, dvar_set_float_from_source_stub);
cmd_add_client_command_list_hook.create(0xB7C840_b, cmd_add_client_command_list_stub);
//utils::hook::set<uint8_t>(0xB7C840_b, 0xC3);
// Register dedicated dvar
game::Dvar_RegisterBool("dedicated", true, game::DVAR_FLAG_READ, "Dedicated server");
@ -136,11 +101,11 @@ namespace dedicated
// Disable shader preload
dvars::override::register_bool("r_preloadShaders", false, game::DVAR_FLAG_READ);
// Disable renderer
// Disable load for renderer
dvars::override::register_bool("r_loadForRenderer", false, game::DVAR_FLAG_READ);
// Preload game mode fastfiles on launch
dvars::override::register_bool("fastfilePreloadGamemode", true, game::DVAR_FLAG_NONE);
//dvars::override::register_bool("fastfilePreloadGamemode", true, game::DVAR_FLAG_NONE);
dvars::override::register_bool("intro", false, game::DVAR_FLAG_READ);
@ -160,7 +125,7 @@ namespace dedicated
utils::hook::set<uint8_t>(0x3471A0_b, 0xC3); // called from Com_Frame, seems to do renderer stuff // done CL_Screen_Update
utils::hook::set<uint8_t>(0x9AA9A0_b, 0xC3); // CL_CheckForResend, which tries to connect to the local server constantly // done CL_MainMP_CheckForResend
//utils::hook::set<uint8_t>(0x67ADCE_b, 0x00); // r_loadForRenderer default to 0 // done via dvar override
utils::hook::set<uint8_t>(0xD2EBB0_b, 0xC3); // recommended settings check // done
//utils::hook::set<uint8_t>(0xD2EBB0_b, 0xC3); // recommended settings check // done
//utils::hook::set<uint8_t>(0x5BE850_b, 0xC3); // some mixer-related function called on shutdown // not needed, only called from Voice_Init
//utils::hook::set<uint8_t>(0x4DEA50_b, 0xC3); // dont load ui gametype stuff // don't add this for now
@ -233,7 +198,7 @@ namespace dedicated
utils::hook::set<uint8_t>(0xE05E20_b, 0xC3); // ^ buffer
utils::hook::set<uint8_t>(0xE11270_b, 0xC3); // ^
utils::hook::set<uint8_t>(0xDD3C50_b, 0xC3); // ^
utils::hook::set<uint8_t>(0x0C1210_b, 0xC3); // ^ idk
utils::hook::set(0x0C1210_b, 0xC3C033); //utils::hook::set<uint8_t>(0x0C1210_b, 0xC3); // ^ idk
utils::hook::set<uint8_t>(0x0C12B0_b, 0xC3); // ^ idk
utils::hook::set<uint8_t>(0xE423A0_b, 0xC3); // directx
utils::hook::set<uint8_t>(0xE04680_b, 0xC3); // ^
@ -252,21 +217,30 @@ namespace dedicated
utils::hook::set<uint8_t>(0x5F0820_b, 0xC3); // ^
utils::hook::set<uint8_t>(0x5F0790_b, 0xC3); // ^
utils::hook::set<uint8_t>(0x3B9E72_b, 0xEB); // skip R_GetFrameIndex check in DB_LoadLevelXAssets
// r_loadForRenderer
utils::hook::set<uint8_t>(0xE114A0_b, 0xC3); // ^
utils::hook::set<uint8_t>(0xE11380_b, 0xC3); // ^
utils::hook::set<uint8_t>(0xE113D0_b, 0xC3); // ^
utils::hook::set<uint8_t>(0xE476F0_b, 0xC3); // ^
utils::hook::set<uint8_t>(0xE11420_b, 0xC3); // ^
utils::hook::set<uint8_t>(0xDD2300_b, 0xC3); // ^
utils::hook::set<uint8_t>(0xDD2610_b, 0xC3); // ^
utils::hook::set<uint8_t>(0xE11F40_b, 0xC3); // ^
// release buffer
// skip R_GetFrameIndex check in DB_LoadLevelXAssets
utils::hook::set<uint8_t>(0x3B9E72_b, 0xEB);
// don't release buffer
utils::hook::set<uint8_t>(0xDD4430_b, 0xEB);
// R_LoadWorld
utils::hook::set<uint8_t>(0xDD14C0_b, 0xC3);
scheduler::loop([]() // maybe not needed
{
// snd_enabled
*reinterpret_cast<DWORD*>(0x7201A88_b) = 0;
// vls shit
utils::hook::set<uint8_t>(0xD02CB0_b, 0xC3);
}, scheduler::pipeline::async);
// renderer
utils::hook::set<uint8_t>(0xDD4370_b, 0xC3);
command::add("startserver", []()
{

View File

@ -6,6 +6,7 @@
#include "game/game.hpp"
#include "console.hpp"
#include "dvars.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
@ -77,7 +78,11 @@ namespace network
}
sockaddr s = {};
game::NetadrToSockadr(to, &s);
return sendto(*game::query_socket, data, length, 0, &s, sizeof(sockaddr)) >= 0;
if (to->type == game::NA_IP)
{
//printf("sendto: size: %i\n", length);
}
return sendto(*game::query_socket, data, length, 0, &s, sizeof(sockaddr));
}
int dw_recv_from_stub(game::netadr_s* from, char* data, int maxsize)
@ -89,12 +94,12 @@ namespace network
ret = recvfrom(*game::query_socket, data, maxsize, 0, &s, &slen);
if (ret == SOCKET_ERROR)
{
return 0;
return -2;
}
sockadr_to_netadr(&s, from);
if (from->type == game::NA_IP)
{
//printf("recv: %s, size: %i\n", std::string(data, ret).data(), ret);
//printf("recv: size: %i\n", ret);
}
datalen = ret;
if (!datalen)
@ -312,6 +317,7 @@ namespace network
// handle xuid without secure connection
utils::hook::nop(0xC53315_b, 2);
utils::hook::nop(0xC55EC7_b, 6);
utils::hook::jump(game::NET_CompareAdr, net_compare_address);
utils::hook::jump(game::NET_CompareBaseAdr, net_compare_base_address);
@ -341,11 +347,11 @@ namespace network
utils::hook::set<uint8_t>(0x9B6F91_b, 0xEB);
// ignore dw handle in SvClientMP::FindClientAtAddress
//utils::hook::set<uint8_t>(0xC58B2B_b, 0xEB); // DO NOT USE
utils::hook::set<uint8_t>(0xC58B2B_b, 0xEB);
// ignore dw handle in SV_DirectConnect
//utils::hook::set<uint8_t>(0xC4EE1A_b, 0xEB); ^
//utils::hook::set<uint8_t>(0xC4F0FB_b, 0xEB); ^
utils::hook::nop(0xC4EE1A_b, 2);
utils::hook::nop(0xC4F0FB_b, 6);
// ignore impure client
utils::hook::jump(0xC500C8_b, 0xC500DE_b); // maybe add sv_pure dvar?
@ -361,25 +367,31 @@ namespace network
utils::hook::nop(0xC4F03C_b, 4); // this crashes when reconnecting for some reason
// increase allowed packet size
//const auto max_packet_size = 0x20000;
//utils::hook::set<int>(0x0, max_packet_size);
//utils::hook::set<int>(0x0, max_packet_size);
//utils::hook::set<int>(0x0, max_packet_size);
//utils::hook::set<int>(0x0, max_packet_size);
const auto max_packet_size = 0x20000;
utils::hook::set<int>(0xBB4F01_b, max_packet_size);
utils::hook::set<int>(0xBB4F31_b, max_packet_size);
utils::hook::set<int>(0xBB4E22_b, max_packet_size);
utils::hook::set<int>(0xBB4F31_b, max_packet_size);
// increase cl_maxpackets
//dvars::override::register_int("cl_maxpackets", 1000, 1, 1000, game::DVAR_FLAG_SAVED);
dvars::override::register_int("cl_maxpackets", 1000, 1, 1000, game::DVAR_FLAG_SAVED);
// increase snaps
//dvars::override::register_int("sv_remote_client_snapshot_msec", 33, 33, 100, game::DVAR_FLAG_NONE);
dvars::override::register_int("sv_timeout", 1800, 0, 1800, game::DVAR_FLAG_NONE); // no work
dvars::override::register_int("sv_connectTimeout", 1800, 0, 1800, game::DVAR_FLAG_NONE); // ^
//dvars::override::register_int("sv_zombietime", 1800, 0, 1800, game::DVAR_FLAG_NONE); // ^
dvars::override::register_int("pt_connectTimeout", 60000, 0, 60000, game::DVAR_FLAG_READ);
// ignore built in "print" oob command and add in our own
utils::hook::set<uint8_t>(0x9B0326_b, 0xEB);
network::on("print", [](const game::netadr_s&, const std::string_view& data)
{
const std::string message{ data };
console::info(message.data());
});
//utils::hook::set<uint8_t>(0x9B0326_b, 0xEB);
//network::on("print", [](const game::netadr_s&, const std::string_view& data)
//{
// const std::string message{ data };
// console::info(message.data());
//});
// Use our own socket since the game's socket doesn't work with non localhost addresses
// why? no idea

View File

@ -32,8 +32,8 @@ namespace party
{
command::execute("onlinegame 1", true);
command::execute("xblive_privatematch 1", true);
command::execute("xstartprivateparty", true);
//command::execute("xstartprivatematch", true);
//command::execute("xstartprivateparty", true);
command::execute("xstartprivatematch", true);
}
void connect_to_party(const game::netadr_s& target, const std::string& mapname, const std::string& gametype)
@ -70,9 +70,6 @@ namespace party
perform_game_initialization();
// shutdown frontend
game::Com_FrontEndScene_ShutdownAndDisable();
// connect
char session_info[0x100] = {};
game::CL_MainMP_ConnectAndPreloadMap(0, reinterpret_cast<void*>(session_info), &target, mapname.data(), gametype.data());
@ -120,13 +117,17 @@ namespace party
auto* private_clients = game::Dvar_FindVar("ui_privateClients");
auto* hardcore = game::Dvar_FindVar("ui_hardcore");
//game::Com_FrontEndScene_Shutdown();
//if (!game::environment::is_dedi() && !game::Com_FrontEndScene_IsActive())
//{
// game::Com_Shutdown("EXE_ENDOFGAME");
//}
//utils::hook::invoke<void>(0x9D6F40_b, game::Lobby_GetPartyData(), mapname->current.string, gametype->current.string);
game::Com_FrontEndScene_ShutdownAndDisable();
if (!game::environment::is_dedi() && !game::Com_FrontEndScene_IsActive())
{
game::Com_Shutdown("EXE_ENDOFGAME");
}
game::SV_CmdsMP_StartMapForParty(
mapname->current.string,
gametype->current.string,
@ -166,7 +167,7 @@ namespace party
auto* current_mapname = game::Dvar_FindVar("mapname");
command::execute((dev ? "set sv_cheats 1" : "set sv_cheats 0"), true);
command::execute((dev ? "seta sv_cheats 1" : "seta sv_cheats 0"), true);
if (current_mapname && utils::string::to_lower(current_mapname->current.string) ==
utils::string::to_lower(mapname) && (game::SV_Loaded() && !game::Com_FrontEndScene_IsActive()))
@ -237,6 +238,11 @@ namespace party
console::info("%d\n", game::Live_SyncOnlineDataFlags(0));
});
command::add("connstate", []()
{
console::info("%d\n", game::clientUIActives[0].connectionState);
});
static const char* a1 = "map_sp";
static const char* a2 = "map_restart_sp";
static const char* a3 = "fast_restart_sp";

View File

@ -491,6 +491,46 @@ namespace game
}
using namespace entity;
namespace party
{
enum PartyPreloadMapStage : std::uint32_t
{
PRELOAD_MAP_IDLE = 0x0,
PRELOAD_MAP_INITIATED = 0x1,
PRELOAD_MAP_STARTED = 0x2,
PRELOAD_MAP_COUNT = 0x3,
};
struct PartyData
{
char __pad0[11444];
PartyPreloadMapStage preloadingMapStage;
};
static_assert(offsetof(PartyData, preloadingMapStage) == 11444);
}
using namespace party;
namespace sv
{
struct SvServerInitSettings
{
char mapName[64];
char gameType[64];
char serverHostName[64];
bool hardcoreMode;
unsigned int maxClientCount;
unsigned int maxAgentCount;
bool isMapPreloaded;
bool isSaveGame;
bool isRestart;
bool isFrontEnd;
}; //static_assert(sizeof(SvServerInitSettings) == 212);
static_assert(offsetof(SvServerInitSettings, maxClientCount) == 196);
static_assert(offsetof(SvServerInitSettings, isMapPreloaded) == 204);
static_assert(offsetof(SvServerInitSettings, isFrontEnd) == 207);
}
using namespace sv;
namespace assets
{
enum XAssetType : std::int32_t

View File

@ -13,8 +13,10 @@ namespace game
WEAK symbol<void()> Com_Quit_f{ 0xBADC90 };
WEAK symbol<bool()> Com_FrontEnd_IsInFrontEnd{ 0x5AE6C0 };
WEAK symbol<void()> Com_FrontEnd_ExitFrontEnd{ 0x5AE4F0 };
WEAK symbol<bool()> Com_FrontEndScene_IsActive{ 0x5AEBA0 };
WEAK symbol<void()> Com_FrontEndScene_ShutdownAndDisable{ 0x5AEFB0 };
WEAK symbol<void()> Com_FrontEndScene_Shutdown{ 0x5AED00 };
WEAK symbol<void(GameModeType)> Com_GameMode_SetDesiredGameMode{ 0x5AFDA0 };
WEAK symbol<GameModeType()> Com_GameMode_GetActiveGameMode{ 0x5AFD50 };
@ -25,6 +27,8 @@ namespace game
WEAK symbol<void(const char* localizedMessage, const char* localizedTitle)> Com_SetLocalizedErrorMessage{ 0xBAF300 };
WEAK symbol<void()> Com_SyncThreads{ 0xBB02D0 };
WEAK symbol<void(const char* finalmsg)> Com_Shutdown{ 0xBAFEA0 };
WEAK symbol<void(int localClientNum, const char* text)> Cbuf_AddText{ 0xB7C290 };
@ -102,6 +106,8 @@ namespace game
WEAK symbol<int(netadr_s a, netadr_s b)> NET_CompareAdr{ 0xBB49B0 };
WEAK symbol<int(netadr_s a, netadr_s b)> NET_CompareBaseAdr{ 0xBB4A00 };
WEAK symbol<PartyData* ()> Lobby_GetPartyData{ 0x9C3E20 };
WEAK symbol<GfxFont* (const char* font, int size)> R_RegisterFont{ 0xDFC670 };
WEAK symbol<int(const char* text, int maxChars, GfxFont* font)> R_TextWidth{ 0xDFC770 };
WEAK symbol<int(void* font)> R_GetFontHeight{ 0x12727B0 };