Skip to content

Commit

Permalink
uypdate
Browse files Browse the repository at this point in the history
  • Loading branch information
meow6969 committed May 2, 2023
2 parents c07dff4 + a551cac commit 325d157
Show file tree
Hide file tree
Showing 16 changed files with 527 additions and 324 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- Release
steps:
- name: Check out files
uses: actions/checkout@v3.3.0
uses: actions/checkout@v3.5.2
with:
submodules: true
fetch-depth: 0
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
path: data

- name: Install SSH key
uses: shimataro/[email protected].0
uses: shimataro/[email protected].1
with:
key: ${{ secrets.BOIII_MASTER_SSH_PRIVATE_KEY }}
known_hosts: "just-a-placeholder-so-we-dont-get-errors"
Expand Down
53 changes: 53 additions & 0 deletions src/client/component/auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace auth
{
namespace
{
const game::dvar_t* password;

std::array<uint64_t, 18> client_xuids{};

std::string get_hdd_serial()
Expand Down Expand Up @@ -106,6 +108,11 @@ namespace auth
std::string serialize_connect_data(const char* data, const int length)
{
utils::byte_buffer buffer{};
buffer.write_string(get_key().serialize(PK_PUBLIC));

const std::string challenge(reinterpret_cast<const char*>(0x15A8A7F10_g), 32);
buffer.write_string(utils::cryptography::ecc::sign_message(get_key(), challenge));

profile_infos::get_profile_info().value_or(profile_infos::profile_info{}).serialize(buffer);

buffer.write_string(data, static_cast<size_t>(length));
Expand Down Expand Up @@ -210,6 +217,24 @@ namespace auth
void dispatch_connect_packet(const game::netadr_t& target, const std::string& data)
{
utils::byte_buffer buffer(data);

utils::cryptography::ecc::key key{};
key.deserialize(buffer.read_string());

std::string challenge{};
challenge.resize(32);

const auto get_challenge = reinterpret_cast<void(*)(const game::netadr_t*, void*, size_t)>(game::select(
0x1412E15E0, 0x14016DDC0));
get_challenge(&target, challenge.data(), challenge.size());

if (!utils::cryptography::ecc::verify_message(key, challenge, buffer.read_string()) && target.type !=
game::NA_LOOPBACK)
{
network::send(target, "error", "Bad signature");
return;
}

const profile_infos::profile_info info(buffer);

const auto connect_data = buffer.read_string();
Expand All @@ -224,6 +249,11 @@ namespace auth

const utils::info_string info_string(params[1]);
const auto xuid = strtoull(info_string.get("xuid").data(), nullptr, 16);
if (xuid != key.get_hash())
{
network::send(target, "error", "Bad XUID");
return;
}

profile_infos::add_and_distribute_profile_info(target, xuid, info);

Expand Down Expand Up @@ -324,6 +354,22 @@ namespace auth
}
}

void info_set_value_for_key_stub(char* s, const char* key, const char* value)
{
game::Info_SetValueForKey(s, key, value);

if (password && *password->current.value.string)
{
game::Info_SetValueForKey(s, "password", password->current.value.string);
}

const auto* clan_abbrev = game::LiveStats_GetClanTagText(0);
if (*clan_abbrev)
{
game::Info_SetValueForKey(s, "clanAbbrev", clan_abbrev);
}
}

struct component final : generic_component
{
void post_unpack() override
Expand All @@ -336,6 +382,11 @@ namespace auth
// Intercept SV_DirectConnect in SV_AddTestClient
utils::hook::call(game::select(0x1422490DC, 0x14052E582), direct_connect_bots_stub);

scheduler::once([]
{
password = game::register_dvar_string("password", "", game::DVAR_USERINFO, "password");
}, scheduler::pipeline::main);

// Patch steam id bit check
std::vector<std::pair<size_t, size_t>> patches{};
const auto p = [&patches](const size_t a, const size_t b)
Expand Down Expand Up @@ -383,6 +434,8 @@ namespace auth

utils::hook::call(0x14134BF7D_g, send_connect_data_stub);

utils::hook::call(0x14134BEFE_g, info_set_value_for_key_stub);

// Fix crash
utils::hook::set<uint8_t>(0x14134B970_g, 0xC3);
}
Expand Down
1 change: 1 addition & 0 deletions src/client/component/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ namespace console
if (!game::is_server())
{
utils::hook::set<uint8_t>(0x14133D2FE_g, 0xEB); // Always enable ingame console
utils::hook::jump(0x141344E44_g, 0x141344E2E_g); // Remove the need to type '\' or '/' to send a console command

if (utils::nt::is_wine() && !utils::flags::has_flag("console"))
{
Expand Down
2 changes: 1 addition & 1 deletion src/client/component/dvars_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace dvars_patches
{
void patch_dvars()
{
game::register_sessionmode_dvar_bool("com_pauseSupported", !game::is_server(), game::DVAR_SERVERINFO, "Whether is pause is ever supported by the game mode");
(void)game::register_sessionmode_dvar_bool("com_pauseSupported", !game::is_server(), game::DVAR_SERVERINFO, "Whether is pause is ever supported by the game mode");
}

void patch_flags()
Expand Down
17 changes: 11 additions & 6 deletions src/client/component/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,28 +304,33 @@ namespace network
{
scheduler::loop(game::fragment_handler::clean, scheduler::async, 5s);

utils::hook::nop(game::select(0x1423322B6, 0x140596DF6), 4);
// don't increment data pointer to optionally skip socket byte
utils::hook::call(game::select(0x142332283, 0x140596DC3), read_socket_byte_stub);
utils::hook::nop(game::select(0x1423322B6, 0x140596DF6), 4);

// optionally read socket byte
utils::hook::call(game::select(0x1423322C1, 0x140596E01), verify_checksum_stub);
utils::hook::call(game::select(0x142332283, 0x140596DC3), read_socket_byte_stub);

// skip checksum verification
utils::hook::set<uint8_t>(game::select(0x14233249E, 0x140596F2E), 0); // don't add checksum to packet
utils::hook::call(game::select(0x1423322C1, 0x140596E01), verify_checksum_stub);

// don't add checksum to packet
utils::hook::set<uint8_t>(game::select(0x14233249E, 0x140596F2E), 0);

// Recreate NET_SendPacket to increase max packet size
//utils::hook::jump(game::select(0x1423323B0, 0x140596E40), net_sendpacket_stub);

utils::hook::set<uint32_t>(game::select(0x14134C6E0, 0x14018E574), 5);
// set initial connection state to challenging
utils::hook::set<uint32_t>(game::select(0x14134C6E0, 0x14018E574), 4);

// intercept command handling
utils::hook::call(game::select(0x14134D146, 0x14018EED0), utils::hook::assemble(handle_command_stub));

utils::hook::set<uint8_t>(game::select(0x14224DEAD, 0x1405315F9), 0xEB);
// don't kick clients without dw handle
utils::hook::set<uint8_t>(game::select(0x14224DEAD, 0x1405315F9), 0xEB);

// Skip DW stuff in NetAdr_ToString
utils::hook::set<uint8_t>(game::select(0x142172EF2, 0x140515881), 0xEB);

// NA_IP -> NA_RAWIP in NetAdr_ToString
utils::hook::set<uint8_t>(game::select(0x142172ED4, 0x140515864), game::NA_RAWIP);

Expand Down
13 changes: 6 additions & 7 deletions src/client/component/patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
#include "loader/component_loader.hpp"

#include <game/game.hpp>
#include <game/utils.hpp>

#include "network.hpp"
#include "scheduler.hpp"

#include <utils/hook.hpp>

Expand Down Expand Up @@ -46,6 +44,12 @@ namespace patches
{
void post_unpack() override
{
// print hexadecimal xuids in status command
utils::hook::copy_string(game::select(0x143050560, 0x140E85B00), "%12llx ");

// print hexadecimal xuids in chat game log command
utils::hook::set<char>(game::select(0x142FD9362, 0x140E16FA2), 'x');

// don't make script errors fatal error
utils::hook::call(game::select(0x1412CAC4D, 0x140158EB2), script_errors_stub);

Expand All @@ -56,11 +60,6 @@ namespace patches

// make sure client's reliableAck are not negative
sv_execute_client_messages_hook.create(game::select(0x14224A460, 0x14052F840), sv_execute_client_messages_stub);

scheduler::once([]
{
game::register_dvar_string("password", "", game::DVAR_USERINFO, "password");
}, scheduler::pipeline::main);
}
};
}
Expand Down
46 changes: 44 additions & 2 deletions src/client/component/rcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
#include "scheduler.hpp"

#include <utils/finally.hpp>
#include <utils/string.hpp>

#include <game/utils.hpp>

namespace rcon
{
namespace
{
const game::dvar_t* rcon_timeout;

std::unordered_map<game::netadr_t, int> rate_limit_map;

std::optional<std::string> get_and_validate_rcon_command(const std::string& data)
{
const command::params params{data.data()};
const command::params params{data};

if (params.size() <= 1)
{
Expand Down Expand Up @@ -52,8 +55,45 @@ namespace rcon
network::send(target, "print", console_buffer);
}

bool rate_limit_check(const game::netadr_t& address, const int time)
{
const auto last_time = rate_limit_map[address];

if (last_time && (time - last_time) < rcon_timeout->current.value.integer)
{
return false; // Flooding
}

rate_limit_map[address] = time;
return true;
}

void rate_limit_cleanup(const int time)
{
for (auto i = rate_limit_map.begin(); i != rate_limit_map.end();)
{
// No longer at risk of flooding, remove
if ((time - i->second) > rcon_timeout->current.value.integer)
{
i = rate_limit_map.erase(i);
}
else
{
++i;
}
}
}

void rcon_handler(const game::netadr_t& target, const network::data_view& data)
{
const auto time = game::Sys_Milliseconds();
if (!rate_limit_check(target, time))
{
return;
}

rate_limit_cleanup(time);

auto str_data = std::string(reinterpret_cast<const char*>(data.data()), data.size());
scheduler::once([target, s = std::move(str_data)]
{
Expand All @@ -67,6 +107,8 @@ namespace rcon
void post_unpack() override
{
network::on("rcon", rcon_handler);

rcon_timeout = game::register_dvar_int("rcon_timeout", 500, 100, 10000, game::DVAR_NONE, "");
}
};
}
Expand Down
74 changes: 37 additions & 37 deletions src/client/component/server_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,20 @@ namespace server_list
void request_servers(callback callback)
{
master_state.access([&callback](state& s)
{
game::netadr_t addr{};
if (!get_master_server(addr))
{
game::netadr_t addr{};
if (!get_master_server(addr))
{
return;
}
return;
}

s.requesting = true;
s.address = addr;
s.callback = std::move(callback);
s.query_start = std::chrono::high_resolution_clock::now();
s.requesting = true;
s.address = addr;
s.callback = std::move(callback);
s.query_start = std::chrono::high_resolution_clock::now();

network::send(s.address, "getservers", utils::string::va("T7 %i full empty", PROTOCOL));
});
network::send(s.address, "getservers", utils::string::va("T7 %i full empty", PROTOCOL));
});
}

void add_favorite_server(game::netadr_t addr)
Expand Down Expand Up @@ -194,33 +194,33 @@ namespace server_list
void post_unpack() override
{
network::on("getServersResponse", [](const game::netadr_t& target, const network::data_view& data)
{
master_state.access([&](state& s)
{
master_state.access([&](state& s)
{
handle_server_list_response(target, data, s);
});
handle_server_list_response(target, data, s);
});
});

scheduler::loop([]
{
master_state.access([](state& s)
{
master_state.access([](state& s)
{
if (!s.requesting)
{
return;
}

const auto now = std::chrono::high_resolution_clock::now();
if ((now - s.query_start) < 2s)
{
return;
}

s.requesting = false;
s.callback(false, {});
s.callback = {};
});
}, scheduler::async, 200ms);
if (!s.requesting)
{
return;
}

const auto now = std::chrono::high_resolution_clock::now();
if ((now - s.query_start) < 2s)
{
return;
}

s.requesting = false;
s.callback(false, {});
s.callback = {};
});
}, scheduler::async, 200ms);

lua_serverinfo_to_table_hook.create(0x141F1FD10_g, lua_serverinfo_to_table_stub);

Expand All @@ -233,10 +233,10 @@ namespace server_list
void pre_destroy() override
{
master_state.access([](state& s)
{
s.requesting = false;
s.callback = {};
});
{
s.requesting = false;
s.callback = {};
});
}
};
}
Expand Down
Loading

0 comments on commit 325d157

Please sign in to comment.