Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Missing Map Files #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/client/component/fastfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,11 +1187,40 @@ namespace fastfiles
return utils::io::file_exists(utils::string::va("hmw-usermaps\\%s\\%s.ff", name.data(), name.data()));
}

bool is_dlc_map(const std::string& name)
{
const std::vector<std::string> dlc_zone_basenames = {
"carentan",
"broadcast",
"creek",
"killhouse"
};

return std::any_of(dlc_zone_basenames.begin(), dlc_zone_basenames.end(), [&](std::string base) {
return name.contains(base);
});
}

bool is_stock_map(const std::string& name)
{
return fastfiles::exists(name, true);
}

MAP_EXISTS_RESULT map_exists(const std::string& mapname)
{

if (fastfiles::is_dlc_map(mapname) && fastfiles::exists(mapname)) { return MAP_EXISTS_RESULT::DLC; }

// michelin: I'm not a fan of the existing is_stock_map or the fastfiles::exists logic.
// we should NOT be checking if a file is in root/zone to see if a map is a stock map... we should be checking a table of mapnames
// the exists check should be explicit and separate, like I've expressed here
if (fastfiles::is_stock_map(mapname) && fastfiles::exists(mapname)) { return MAP_EXISTS_RESULT::BASE_GAME; }

if (fastfiles::usermap_exists(mapname)) { return MAP_EXISTS_RESULT::USER; }

return MAP_EXISTS_RESULT::MISSING;
}

void enum_asset_entries(const game::XAssetType type, const std::function<void(game::XAssetEntry*)>& callback, bool include_override)
{
constexpr auto max_asset_count = 0x25D78;
Expand Down
11 changes: 11 additions & 0 deletions src/client/component/fastfiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ namespace fastfiles
std::optional<std::string> get_current_usermap();
bool usermap_exists(const std::string& name);
bool is_stock_map(const std::string& name);
bool is_dlc_map(const std::string& name);

enum class MAP_EXISTS_RESULT {
BASE_GAME,
DLC,
USER,
MISSING
};

MAP_EXISTS_RESULT map_exists(const std::string& name);


void enum_asset_entries(const game::XAssetType type, const std::function<void(game::XAssetEntry*)>& callback, bool include_override);
}
74 changes: 57 additions & 17 deletions src/client/component/party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,25 @@ namespace party
command::execute("startentitlements", true);
}

void disconnect()
{
if (!game::VirtualLobby_Loaded())
{
if (game::CL_IsCgameInitialized())
{
// CL_AddReliableCommand
utils::hook::invoke<void>(0x12B810_b, 0, "disconnect");
// CL_WritePacket
utils::hook::invoke<void>(0x13D490_b, 0);
}
// CL_Disconnect
utils::hook::invoke<void>(0x12F080_b, 0);
}
}

void connect_to_party(const game::netadr_s& target, const std::string& mapname, const std::string& gametype)
{

if (game::Live_SyncOnlineDataFlags(0) != 0)
{
// initialize the game after onlinedataflags is 32 (workaround)
Expand Down Expand Up @@ -112,22 +129,6 @@ namespace party
return utils::string::va("%s", server_connection_state.motd.data());
}

void disconnect()
{
if (!game::VirtualLobby_Loaded())
{
if (game::CL_IsCgameInitialized())
{
// CL_AddReliableCommand
utils::hook::invoke<void>(0x12B810_b, 0, "disconnect");
// CL_WritePacket
utils::hook::invoke<void>(0x13D490_b, 0);
}
// CL_Disconnect
utils::hook::invoke<void>(0x12F080_b, 0);
}
}

utils::hook::detour cl_disconnect_hook;

void cl_disconnect_stub(int show_main_menu) // possibly bool
Expand Down Expand Up @@ -430,7 +431,32 @@ namespace party
void set_new_map(const char* mapname, const char* gametype, game::msg_t* msg)
{
utils::hook::invoke<void>(0x27A040_b);


auto map_type = fastfiles::map_exists(mapname);
if (map_type == fastfiles::MAP_EXISTS_RESULT::MISSING)
{
console::error("Failed to find one or more fastfiles for: %s", std::string(mapname).c_str());

command::execute("disconnect");
scheduler::once([]
{
connect(server_connection_state.host);
}, scheduler::pipeline::main);

// remove from virt lobby?
utils::hook::invoke<void>(0x13C9C0_b, 1);

menu_error(
"Missing a required map file.\n"
"If map was a...\n"
"Base Game Map: verify game files.\n"
"DLC Map: verify you have the DLC.\n"
"HMW Map: verify mod files with HMW launcher.\n"
);

return;
}

if (!fastfiles::is_stock_map(mapname))
{
fastfiles::set_usermap(mapname);
Expand Down Expand Up @@ -708,6 +734,20 @@ namespace party
return;
}

auto map_type = fastfiles::map_exists(mapname);
if (map_type == fastfiles::MAP_EXISTS_RESULT::MISSING)
{
console::error("Failed to find fastfile for zone: %s", std::string(mapname).c_str());
menu_error("Missing a required map file.\n"
"If map was a...\n"
"Base Game Map: verify game files.\n"
"DLC Map: verify you have the DLC.\n"
"HMW Map: verify mod files with HMW launcher.\n"
);
connecting_to_server = false;
return;
}

std::string gametype = jsonObject["gametype"];
if (gametype.empty()) {
connecting_to_server = false;
Expand Down
2 changes: 1 addition & 1 deletion src/client/tcp/hmw_tcp_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ namespace hmw_tcp_utils {
void check_download_map_tcp(const nlohmann::json infoJson, std::vector<download::file_t>& files)
{
const std::string mapname = infoJson["mapname"];
if (fastfiles::is_stock_map(mapname))
if (fastfiles::is_stock_map(mapname) || fastfiles::is_dlc_map(mapname))
{
return;
}
Expand Down