Skip to content

Commit

Permalink
Merge pull request #714 from h1-mod/develop
Browse files Browse the repository at this point in the history
Release v2.0.1
  • Loading branch information
mjkzy authored Jan 6, 2024
2 parents 2e83156 + 572e61d commit cf5aa2a
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 40 deletions.
74 changes: 67 additions & 7 deletions data/cdata/scripts/mp/team_balance.gsc
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
init()
main()
{
// define the auto balance string in the game array (referenced in gsc dump, but not defined past IW6?)
precachestring(&"MP_AUTOBALANCE_NOW");
game["strings"]["autobalance"] = &"MP_AUTOBALANCE_NOW";

// define onteamselection callback function used in balanceteams()
level.onteamselection = ::set_team;
// use player's score to balance instead player's time on team
replacefunc(maps\mp\gametypes\_teams::balanceteams, ::balance_teams_stub);
}

balance_teams_stub()
{
iprintlnbold(&"MP_AUTOBALANCE_NOW");

allied_players = get_valid_team_array("allies");
axis_players = get_valid_team_array("axis");
while (is_team_bigger_than(allied_players, axis_players) || is_team_bigger_than(axis_players, allied_players))
{
if (is_team_bigger_than(allied_players, axis_players))
{
handle_lowest_score_player(allied_players, "axis");
}
else if (is_team_bigger_than(axis_players, allied_players))
{
handle_lowest_score_player(axis_players, "allies");
}

// refresh array for loop
allied_players = get_valid_team_array("allies");
axis_players = get_valid_team_array("axis");
}
}

get_valid_team_array(team)
{
team_array = [];
players = level.players;
for (i = 0; i < players.size; i++)
{
if (!isdefined(players[i].pers["score"])) // was teamTime
continue;

if (isdefined(players[i].pers["team"]) && players[i].pers["team"] == team)
team_array[team_array.size] = players[i];
}
return team_array;
}

is_team_bigger_than(team_one, team_two)
{
return (team_one.size > (team_two.size + 1));
}

handle_lowest_score_player(team, new_team)
{
lowest_score_player = undefined;

// move the player that has the lowest score (highest teamTime value)
for (i = 0; i < team.size; i++)
{
if (isdefined(team[i].dont_auto_balance))
continue;

if (!isdefined(lowest_score_player))
lowest_score_player = team[i];
else if (team[i].pers["score"] < lowest_score_player.pers["score"])
lowest_score_player = team[i];
}

lowest_score_player set_team(new_team);
}

set_team(team)
Expand All @@ -22,6 +82,6 @@ set_team(team)
self suicide();
}

maps\mp\gametypes\_menus::addtoteam(team);
maps\mp\gametypes\_menus::endrespawnnotify();
self maps\mp\gametypes\_menus::addtoteam(team);
self maps\mp\gametypes\_menus::endrespawnnotify();
}
7 changes: 2 additions & 5 deletions src/client/component/branding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,15 @@ namespace branding
class component final : public component_interface
{
public:
void post_start() override
{
scheduler::loop(draw_branding, scheduler::pipeline::renderer);
}

void post_unpack() override
{
if (game::environment::is_dedi())
{
return;
}

scheduler::loop(draw_branding, scheduler::pipeline::renderer);

ui_get_formatted_build_number_hook.create(
SELECT_VALUE(0x406EC0_b, 0x1DF300_b), ui_get_formatted_build_number_stub);
}
Expand Down
46 changes: 27 additions & 19 deletions src/client/component/fastfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace fastfiles

namespace
{
utils::hook::detour db_init_load_x_file_hook;
utils::hook::detour db_try_load_x_file_internal_hook;
utils::hook::detour db_find_xasset_header_hook;

Expand All @@ -31,9 +32,14 @@ namespace fastfiles
utils::concurrency::container<std::vector<HANDLE>> fastfile_handles;
bool is_mod_pre_gfx = false;

void db_init_load_x_file_stub(game::DBFile* file, std::uint64_t offset)
{
console::info("Loading fastfile %s\n", file->name);
return db_init_load_x_file_hook.invoke<void>(file, offset);
}

void db_try_load_x_file_internal(const char* zone_name, const int flags)
{
console::info("Loading fastfile %s\n", zone_name);
is_mod_pre_gfx = zone_name == "mod_pre_gfx"s;
current_fastfile.access([&](std::string& fastfile)
{
Expand Down Expand Up @@ -74,30 +80,32 @@ namespace fastfiles
dump_gsc_script(name, result);
}

const std::string override_asset_name = "override/"s + name;

if (type == game::XAssetType::ASSET_TYPE_RAWFILE)
{
if (result.rawfile)
const std::string override_asset_name = "override/"s + name;

if (type == game::XAssetType::ASSET_TYPE_RAWFILE)
{
const auto override_rawfile = db_find_xasset_header_hook.invoke<game::XAssetHeader>(type, override_asset_name.data(), 0);
if (override_rawfile.rawfile)
if (result.rawfile)
{
result.rawfile = override_rawfile.rawfile;
console::debug("using override asset for rawfile: \"%s\"\n", name);
const auto override_rawfile = db_find_xasset_header_hook.invoke<game::XAssetHeader>(type, override_asset_name.data(), 0);
if (override_rawfile.rawfile)
{
result.rawfile = override_rawfile.rawfile;
console::debug("using override asset for rawfile: \"%s\"\n", name);
}
}
}
}

if (type == game::XAssetType::ASSET_TYPE_STRINGTABLE)
{
if (result.stringTable)
if (type == game::XAssetType::ASSET_TYPE_STRINGTABLE)
{
const auto override_stringtable = db_find_xasset_header_hook.invoke<game::XAssetHeader>(type, override_asset_name.data(), 0);
if (override_stringtable.stringTable)
if (result.stringTable)
{
result.stringTable = override_stringtable.stringTable;
console::debug("using override asset for stringtable: \"%s\"\n", name);
const auto override_stringtable = db_find_xasset_header_hook.invoke<game::XAssetHeader>(type, override_asset_name.data(), 0);
if (override_stringtable.stringTable)
{
result.stringTable = override_stringtable.stringTable;
console::debug("using override asset for stringtable: \"%s\"\n", name);
}
}
}
}
Expand Down Expand Up @@ -1193,8 +1201,8 @@ namespace fastfiles
public:
void post_unpack() override
{
db_try_load_x_file_internal_hook.create(
SELECT_VALUE(0x1F5700_b, 0x39A620_b), &db_try_load_x_file_internal);
db_try_load_x_file_internal_hook.create(SELECT_VALUE(0x1F5700_b, 0x39A620_b), db_try_load_x_file_internal);
db_init_load_x_file_hook.create(SELECT_VALUE(0x1C46E0_b, 0x3681E0_b), db_init_load_x_file_stub);
db_find_xasset_header_hook.create(game::DB_FindXAssetHeader, db_find_xasset_header_stub);

db_unload_x_zones_hook.create(SELECT_VALUE(0x1F6040_b,
Expand Down
2 changes: 1 addition & 1 deletion src/client/component/gsc/script_loading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace gsc
std::unordered_map<std::string, std::uint32_t> init_handles;

utils::memory::allocator scriptfile_allocator;
std::unordered_map<const char*, game::ScriptFile*> loaded_scripts;
std::unordered_map<std::string, game::ScriptFile*> loaded_scripts;

struct
{
Expand Down
4 changes: 3 additions & 1 deletion src/client/component/imagefiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ namespace imagefiles
}

void* pakfile_open_stub(void* /*handles*/, unsigned int count, int is_imagefile,
unsigned int index, int is_localized)
unsigned int index, short is_localized)
{
console::debug("Opening %s%d.pak (localized:%d)\n", is_imagefile ? "imagefile" : "soundfile", index, is_localized);

if (index != CUSTOM_IMAGE_FILE_INDEX)
{
return utils::hook::invoke<void*>(
Expand Down
5 changes: 5 additions & 0 deletions src/client/component/lui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ namespace lui
public:
void post_unpack() override
{
if (game::environment::is_dedi())
{
return;
}

if (game::environment::is_mp())
{
// Patch game message overflow
Expand Down
13 changes: 7 additions & 6 deletions src/client/component/party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,15 @@ namespace party
return;
}

server_connection_state.base_url = info.get("sv_wwwBaseUrl");

if (download_files(target, info, false))
{
return;
}

server_connection_state.motd = info.get("sv_motd");
server_connection_state.max_clients = std::stoi(info.get("sv_maxclients"));
server_connection_state.base_url = info.get("sv_wwwBaseUrl");

discord_information discord_info{};
discord_info.image = info.get("sv_discordImageUrl");
Expand All @@ -1156,11 +1162,6 @@ namespace party
server_discord_info.emplace(discord_info);
}

if (download_files(target, info, false))
{
return;
}

connect_to_party(target, mapname, gametype);
});
}
Expand Down
6 changes: 6 additions & 0 deletions src/client/game/structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,12 @@ namespace game
DB_AuthSignature signature;
};

struct DBFile
{
char __pad0[32];
char name[64];
};

namespace hks
{
struct lua_State;
Expand Down
1 change: 0 additions & 1 deletion src/client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ FARPROC load_binary(const launcher::mode mode, uint64_t* base_address)
void remove_crash_file()
{
utils::io::remove_file("__h1Exe");
utils::io::remove_file("h1-mod\\h1_mp64_ship.exe"); // remove this at some point
}

void enable_dpi_awareness()
Expand Down

0 comments on commit cf5aa2a

Please sign in to comment.