[Download] Correctly download maps from lobby servers

This commit is contained in:
momo5502 2017-07-12 19:36:18 +02:00
parent 012384987e
commit 390418e34e
5 changed files with 34 additions and 11 deletions

View File

@ -474,8 +474,8 @@ namespace Components
static std::string mapnamePre;
static json11::Json jsonList;
std::string mapname = Maps::GetUserMap()->getName();
if (!Maps::GetUserMap()->isValid())
std::string mapname = (Party::IsInUserMapLobby() ? Dvar::Var("ui_mapname").get<std::string>() : Maps::GetUserMap()->getName());
if (!Maps::GetUserMap()->isValid() && !Party::IsInUserMapLobby())
{
mapnamePre.clear();
jsonList = std::vector<json11::Json>();
@ -607,7 +607,7 @@ namespace Components
isMap = true;
url = url.substr(4);
std::string mapname = Maps::GetUserMap()->getName();
std::string mapname = (Party::IsInUserMapLobby() ? Dvar::Var("ui_mapname").get<std::string>() : Maps::GetUserMap()->getName());
bool isValidFile = false;
for (int i = 0; i < ARRAYSIZE(Maps::UserMapFiles); ++i)
@ -619,7 +619,7 @@ namespace Components
}
}
if (!Maps::GetUserMap()->isValid() || !isValidFile)
if ((!Maps::GetUserMap()->isValid() && !Party::IsInUserMapLobby()) || !isValidFile)
{
Download::Forbid(nc);
return;

View File

@ -409,7 +409,7 @@ namespace Components
Maps::UserMap.clear();
}
if (Utils::IO::DirectoryExists(Utils::String::VA("usermaps/%s", mapname)) && Utils::IO::FileExists(Utils::String::VA("usermaps/%s/%s.ff", mapname, mapname)))
if (Maps::IsUserMap(mapname))
{
Maps::UserMap = Maps::UserMapContainer(mapname);
Maps::UserMap.loadIwd();
@ -710,6 +710,11 @@ namespace Components
return false;
}
bool Maps::IsUserMap(std::string mapname)
{
return Utils::IO::DirectoryExists(Utils::String::VA("usermaps/%s", mapname.data())) && Utils::IO::FileExists(Utils::String::VA("usermaps/%s/%s.ff", mapname.data(), mapname.data()));
}
Game::XAssetEntry* Maps::GetAssetEntryPool()
{
return *reinterpret_cast<Game::XAssetEntry**>(0x48E6F4);

View File

@ -65,6 +65,7 @@ namespace Components
static Game::XAssetEntry* GetAssetEntryPool();
static bool IsCustomMap();
static bool IsUserMap(std::string mapname);
private:
class DLC

View File

@ -138,6 +138,16 @@ namespace Components
return Utils::Hook::Call<DWORD(char*)>(0x4D5390)(dvar);
}
bool Party::IsInLobby()
{
return (!Dvar::Var("sv_running").get<bool>() && Dvar::Var("party_enable").get<bool>() && Dvar::Var("party_host").get<bool>());
}
bool Party::IsInUserMapLobby()
{
return (Party::IsInLobby() && Maps::IsUserMap(Dvar::Var("ui_mapname").get<const char*>()));
}
Party::Party()
{
static Game::dvar_t* partyEnable = Dvar::Register<bool>("party_enable", Dedicated::IsEnabled(), Game::dvar_flag::DVAR_FLAG_NONE, "Enable party system").get<Game::dvar_t*>();
@ -336,22 +346,26 @@ namespace Components
info.set("securityLevel", Utils::String::VA("%i", Dvar::Var("sv_securityLevel").get<int>()));
info.set("sv_running", (Dvar::Var("sv_running").get<bool>() ? "1" : "0"));
// Ensure mapname is set
if (info.get("mapname").empty() || Party::IsInLobby())
{
info.set("mapname", Dvar::Var("ui_mapname").get<const char*>());
}
if (Maps::GetUserMap()->isValid())
{
info.set("usermaphash", Utils::String::VA("%i", Maps::GetUserMap()->getHash()));
}
else if (Party::IsInUserMapLobby())
{
info.set("usermaphash", Utils::String::VA("%i", Maps::GetUsermapHash(info.get("mapname"))));
}
if (Dedicated::IsEnabled())
{
info.set("sv_motd", Dvar::Var("sv_motd").get<std::string>());
}
// Ensure mapname is set
if (info.get("mapname").empty() || (Dvar::Var("party_enable").get<bool>() && Dvar::Var("party_host").get<bool>() && !Dvar::Var("sv_running").get<bool>()))
{
info.set("mapname", Dvar::Var("ui_mapname").get<const char*>());
}
// Set matchtype
// 0 - No match, connecting not possible
// 1 - Party, use Steam_JoinLobby to connect

View File

@ -19,6 +19,9 @@ namespace Components
static void ConnectError(std::string message);
static bool IsInUserMapLobby();
static bool IsInLobby();
static std::string GetMotd();
private: