Skip to content

Commit

Permalink
dedi fixes and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Joelrau committed Jul 12, 2024
1 parent 2878336 commit 76770c4
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 26 deletions.
15 changes: 15 additions & 0 deletions src/client/component/dedicated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ namespace dedicated

const game::dvar_t* sv_lanOnly;

const char* sv_get_game_type_stub()
{
return game::Dvar_FindVar("g_gametype")->current.string;
}

bool sv_is_hardcore_mode_stub()
{
return game::Dvar_FindVar("g_hardcore")->current.enabled;
}

void kill_server()
{
game::SV_MainMP_KillLocalServer();
Expand Down Expand Up @@ -257,6 +267,11 @@ namespace dedicated
// delay startup commands until the initialization is done
utils::hook::call(0x140B8D20F, execute_startup_command);

utils::hook::set<uint32_t>(0x140B21107 + 2, 0x482); // g_gametype flags
utils::hook::set<uint32_t>(0x140B21137 + 2, 0x480); // g_hardcore flags
utils::hook::jump(0x140C12400, sv_get_game_type_stub);
utils::hook::jump(0x140C12660, sv_is_hardcore_mode_stub);

utils::hook::nop(0x140CDD5D3, 5); // don't load config file
utils::hook::nop(0x140B7CE46, 5); // ^
utils::hook::set<uint8_t>(0x140BB0930, 0xC3); // don't save config file
Expand Down
1 change: 0 additions & 1 deletion src/client/component/fov.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "game/game.hpp"
#include "game/dvars.hpp"

#include "scheduler.hpp"
#include "dvars.hpp"

#include <utils/hook.hpp>
Expand Down
144 changes: 144 additions & 0 deletions src/client/component/logprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "game/dvars.hpp"

#include "scheduler.hpp"
#include "console/console.hpp"

#include "gsc/script_extension.hpp"

Expand All @@ -15,6 +16,9 @@ namespace logprint
namespace
{
utils::hook::detour g_say_hook;
utils::hook::detour scr_player_killed_hook;
utils::hook::detour scr_player_damage_hook;

void g_say_stub(game::gentity_s* ent, game::gentity_s* target, int mode, const char* chat_text)
{
const char* cmd = mode == game::SAY_TEAM ? "say_team" : "say";
Expand All @@ -38,6 +42,142 @@ namespace logprint
game::G_LogPrintf(buffer, guid, ent_number, name, weapon_name);
game::LUI_Interface_DebugPrint(buffer, guid, ent_number, name, weapon_name);
}

std::string get_weapon_name(unsigned short* weapon, bool isAlternate)
{
char output[1024] = { 0 };
game::BG_GetWeaponNameComplete(weapon, isAlternate, output, 1024);
return output;
}

std::string convert_mod(const int meansOfDeath)
{
const auto value = reinterpret_cast<game::scr_string_t**>(0x14196AA40)[meansOfDeath];
const auto string = game::SL_ConvertToString(*value);
return string;
}

void scr_player_damage_stub(game::gentity_s* self, game::gentity_s* inflictor, game::gentity_s* attacker, int damage, int damageFlags,
unsigned int meansOfDeath, unsigned short* weapon, bool isAlternate, const float* vPoint, const float* vDir,
game::hitLocation_t hitLoc, int timeOffset, int modelIndex, game::scr_string_t partName)
{
auto hit_location = game::g_HitLocNames[hitLoc];
const auto mod = convert_mod(meansOfDeath);
const auto weapon_name = get_weapon_name(weapon, isAlternate);

scheduler::once([=]()
{
try
{
const scripting::entity self_{ game::Scr_GetEntityId(self->s.number, 0) };
assert(self, "self must be defined in Scr_PlayerDamage");

Check warning on line 73 in src/client/component/logprint.cpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

too many arguments for function-like macro invocation 'assert' [D:\a\iw7-mod\iw7-mod\build\client.vcxproj]

Check failure on line 73 in src/client/component/logprint.cpp

View workflow job for this annotation

GitHub Actions / Build binaries (Release)

the following warning is treated as an error [D:\a\iw7-mod\iw7-mod\build\client.vcxproj]

Check warning on line 73 in src/client/component/logprint.cpp

View workflow job for this annotation

GitHub Actions / Build binaries (Release)

too many arguments for function-like macro invocation 'assert' [D:\a\iw7-mod\iw7-mod\build\client.vcxproj]

int lpselfnum = self_.call("getentitynumber").as<int>();
std::string lpselfname = self_.get("name").as<std::string>();
std::string lpselfteam = self_.get("team").as<std::string>();
std::string lpselfGuid = self_.call("getxuid").as<std::string>();

int lpattacknum = -1;
std::string lpattackname = "";
std::string lpattackGuid = "";
std::string lpattackerteam = "world";

if (attacker)
{
const scripting::entity attacker_{ game::Scr_GetEntityId(attacker->s.number, 0) };
if (scripting::call("isplayer", { attacker_ }).as<bool>())
{
lpattacknum = attacker_.call("getentitynumber").as<int>();
lpattackname = attacker_.get("name").as<std::string>();
lpattackerteam = attacker_.get("team").as<std::string>();
lpattackGuid = attacker_.call("getxuid").as<std::string>();
}
}

game::G_LogPrintf("D;%s;%d;%s;%s;%s;%d;%s;%s;%s;%d;%s;%s\n",
lpselfGuid.data(),
lpselfnum,
lpselfteam.data(),
lpselfname.data(),
lpattackGuid.data(),
lpattacknum,
lpattackerteam.data(),
lpattackname.data(),
weapon_name.data(),
damage,
mod.data(),
hit_location);
}
catch (std::exception err)
{
console::error("%s\n", err.what());
}
}, scheduler::pipeline::server);

return scr_player_damage_hook.invoke<void>(self, inflictor, attacker, damage, damageFlags,
meansOfDeath, weapon, isAlternate, vPoint, vDir, hitLoc, timeOffset, modelIndex, partName);
}

void scr_player_killed_stub(game::gentity_s* self, game::gentity_s* inflictor, game::gentity_s* attacker, int damage, int damageFlags,
unsigned int meansOfDeath, unsigned short* weapon, bool isAlternate, const float* vDir,
game::hitLocation_t hitLoc, int timeOffset, int deathAnimDuration)
{
auto hit_location = game::g_HitLocNames[hitLoc];
const auto mod = convert_mod(meansOfDeath);
const auto weapon_name = get_weapon_name(weapon, isAlternate);

scheduler::once([=]()
{
try
{
const scripting::entity self_{ game::Scr_GetEntityId(self->s.number, 0) };
assert(self, "self must be defined in Scr_PlayerKilled");

Check warning on line 134 in src/client/component/logprint.cpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

too many arguments for function-like macro invocation 'assert' [D:\a\iw7-mod\iw7-mod\build\client.vcxproj]

Check warning on line 134 in src/client/component/logprint.cpp

View workflow job for this annotation

GitHub Actions / Build binaries (Release)

too many arguments for function-like macro invocation 'assert' [D:\a\iw7-mod\iw7-mod\build\client.vcxproj]

int lpselfnum = self_.call("getentitynumber").as<int>();
std::string lpselfname = self_.get("name").as<std::string>();
std::string lpselfteam = self_.get("team").as<std::string>();
std::string lpselfGuid = self_.call("getxuid").as<std::string>();

int lpattacknum = -1;
std::string lpattackname = "";
std::string lpattackGuid = "";
std::string lpattackerteam = "world";

if (attacker)
{
const scripting::entity attacker_{ game::Scr_GetEntityId(attacker->s.number, 0) };
if (scripting::call("isplayer", { attacker_ }).as<bool>())
{
lpattacknum = attacker_.call("getentitynumber").as<int>();
lpattackname = attacker_.get("name").as<std::string>();
lpattackerteam = attacker_.get("team").as<std::string>();
lpattackGuid = attacker_.call("getxuid").as<std::string>();
}
}

game::G_LogPrintf("K;%s;%d;%s;%s;%s;%d;%s;%s;%s;%d;%s;%s\n",
lpselfGuid.data(),
lpselfnum,
lpselfteam.data(),
lpselfname.data(),
lpattackGuid.data(),
lpattacknum,
lpattackerteam.data(),
lpattackname.data(),
weapon_name.data(),
damage,
mod.data(),
hit_location);
}
catch (std::exception err)
{
console::error("%s\n", err.what());
}
}, scheduler::pipeline::server);

return scr_player_killed_hook.invoke<void>(self, inflictor, attacker, damage, damageFlags,
meansOfDeath, weapon, isAlternate, vDir, hitLoc, timeOffset, deathAnimDuration);
}
}

class component final : public component_interface
Expand Down Expand Up @@ -72,6 +212,10 @@ namespace logprint

// Hook LUI_Interface_DebugPrint call in GItemsMP::TouchLogPickup
utils::hook::call(0x140448F1D, touch_log_pickup_stub);

// Hook player damage and player death so we can logprint them
scr_player_damage_hook.create(0x140B5E7D0, scr_player_damage_stub);
scr_player_killed_hook.create(0x140B5E9E0, scr_player_killed_stub);
}
};
}
Expand Down
9 changes: 9 additions & 0 deletions src/client/component/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ namespace network
utils::hook::set<int>(0x140BB4E22, max_packet_size);
utils::hook::set<int>(0x140BB4F31, max_packet_size);

// increase cl_maxpackets
dvars::override::register_int("cl_maxpackets", 1000, 1, 1000, game::DVAR_FLAG_NONE);

// increase snaps
dvars::override::register_int("sv_remote_client_snapshot_msec", 33, -1, 100, game::DVAR_FLAG_NONE);

// disable snapshot default values overriding the actual values every time the server starts
utils::hook::set<uint8_t>(0x140C56780, 0xC3); // SV_SnapshotMP_InitRuntime

// ignore built in "print" oob command and add in our own
utils::hook::set<uint8_t>(0x1409B0326, 0xEB);

Expand Down
9 changes: 9 additions & 0 deletions src/client/component/party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ namespace party
command::execute(utils::string::va("ui_gametype %s", gametype->current.string), true);
}

auto* hardcore = game::Dvar_FindVar("g_hardcore");
if (hardcore)
{
command::execute(utils::string::va("ui_hardcore %s", hardcore->current.enabled), true);
}

perform_game_initialization();

console::info("Starting map: %s\n", mapname.data());
Expand Down Expand Up @@ -415,6 +421,9 @@ namespace party
// enable custom kick reason in GScr_KickPlayer
utils::hook::set<uint8_t>(0x140B5377E, 0xEB);

// disable this, maybe causes no issues, but fixes Session unregister on map change/restart
utils::hook::set<uint8_t>(0x140851B50, 0xC3); // CG_ServerCmdMP_ParsePlayerInfos

command::add("map", [](const command::params& args)
{
if (args.size() != 2)
Expand Down
11 changes: 6 additions & 5 deletions src/client/component/ranked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ namespace ranked
public:
void post_unpack() override
{
// This must be registered as 'true' to avoid crash when starting a private match
dvars::override::register_bool("xblive_privatematch", true, game::DVAR_FLAG_REPLICATED);

if (game::environment::is_dedi() && !utils::flags::has_flag("unranked"))
if (game::environment::is_dedi())
{
dvars::override::register_bool("xblive_privatematch", false, game::DVAR_FLAG_REPLICATED | game::DVAR_FLAG_WRITE); // DVAR_FLAG_REPLICATED needed?
dvars::override::register_bool("xblive_privatematch", false, game::DVAR_FLAG_REPLICATED | game::DVAR_FLAG_WRITE);

game::Dvar_RegisterBool("onlinegame", true, game::DVAR_FLAG_READ, "Current game is an online game with stats, custom classes, unlocks");

// Fix sessionteam always returning none (SV_ClientMP_HasAssignedTeam_Internal)
utils::hook::set(0x140C50BC0, 0xC300B0);
}
else
{
dvars::override::register_bool("xblive_privatematch", true, game::DVAR_FLAG_REPLICATED);
}
}

component_priority priority() override
Expand Down
5 changes: 0 additions & 5 deletions src/client/component/weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@ namespace weapon
public:
void post_unpack() override
{
if (game::environment::is_dedi())
{
return;
}

#ifdef DEBUG
command::add("setWeaponFieldFloat", [](const command::params& params)
{
Expand Down
14 changes: 7 additions & 7 deletions src/client/game/scripting/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace scripting
return;
}

const auto value = game::scr_VarGlob->childVariableValue[this->id_ + 0xFA00 * (this->parent_id_ & 3)];
const auto value = game::scr_VarGlob->childVariableValue[this->id_ + 0xA000 * (this->parent_id_ & 3)];
game::VariableValue variable;
variable.u = value.u.u;
variable.type = value.type;
Expand All @@ -31,7 +31,7 @@ namespace scripting

const auto value = _value.get_raw();

const auto variable = &game::scr_VarGlob->childVariableValue[this->id_ + 0xFA00 * (this->parent_id_ & 3)];
const auto variable = &game::scr_VarGlob->childVariableValue[this->id_ + 0xA000 * (this->parent_id_ & 3)];
game::AddRefToValue(value.type, value.u);
game::RemoveRefToValue(variable->type, variable->u.u);

Expand Down Expand Up @@ -131,7 +131,7 @@ namespace scripting
{
std::vector<script_value> result;

const auto offset = 0xFA00 * (this->id_ & 3);
const auto offset = 0xA000 * (this->id_ & 3);
auto current = game::scr_VarGlob->objectVariableChildren[this->id_].firstChild;

for (auto i = offset + current; current; i = offset + current)
Expand Down Expand Up @@ -224,7 +224,7 @@ namespace scripting
return {};
}

const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)];
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xA000 * (this->id_ & 3)];
game::VariableValue variable;
variable.u = value.u.u;
variable.type = value.type;
Expand All @@ -241,7 +241,7 @@ namespace scripting
return {};
}

const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)];
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xA000 * (this->id_ & 3)];
game::VariableValue variable;
variable.u = value.u.u;
variable.type = value.type;
Expand Down Expand Up @@ -271,7 +271,7 @@ namespace scripting
return;
}

const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)];
const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xA000 * (this->id_ & 3)];

game::AddRefToValue(value.type, value.u);
game::RemoveRefToValue(variable->type, variable->u.u);
Expand All @@ -290,7 +290,7 @@ namespace scripting
return;
}

const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xFA00 * (this->id_ & 3)];
const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xA000 * (this->id_ & 3)];

game::AddRefToValue(value.type, value.u);
game::RemoveRefToValue(variable->type, variable->u.u);
Expand Down
4 changes: 2 additions & 2 deletions src/client/game/scripting/execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ namespace scripting

void set_object_variable(const unsigned int parent_id, const unsigned int id, const script_value& value)
{
const auto offset = 0xFA00 * (parent_id & 3);
const auto offset = 0xA000 * (parent_id & 3);
const auto variable_id = game::GetVariable(parent_id, id);
const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + offset];
const auto& raw_value = value.get_raw();
Expand All @@ -228,7 +228,7 @@ namespace scripting

script_value get_object_variable(const unsigned int parent_id, const unsigned int id)
{
const auto offset = 0xFA00 * (parent_id & 3);
const auto offset = 0xA000 * (parent_id & 3);
const auto variable_id = game::FindVariable(parent_id, id);
if (!variable_id)
{
Expand Down
1 change: 1 addition & 0 deletions src/client/game/structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ namespace game
static_assert(offsetof(cg_s, cubemapSize) == 19164);
static_assert(offsetof(cg_s, viewModelAxis) == 324368);
static_assert(offsetof(cg_s, renderScreen) == 492892);
static_assert(offsetof(cg_s, spectatingThirdPerson) == 492908);
static_assert(offsetof(cg_s, renderingThirdPerson) == 492912);
static_assert(offsetof(cg_s, m_deathCameraFailsafeLock) == 553708);

Expand Down
Loading

0 comments on commit 76770c4

Please sign in to comment.