Skip to content

Commit

Permalink
Merge branch 'develop' into native_rumble_support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rackover authored Oct 1, 2024
2 parents da92389 + 14171bc commit dae27cb
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/Components/Modules/AssetInterfaces/IMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,35 @@ namespace Assets

buffer->popBlock();
}

IMaterial::IMaterial()
{
Components::Command::Add("hashName", [](const Components::Command::Params* params)
{
if (params->size() < 2) return;

for (int i = 1; i < params->size(); i++)
{
Components::Logger::Print("{} => {}\n", params->get(i), Game::R_HashString(params->get(i)));
}
});

Components::Command::Add("dumpMaterial", [](const Components::Command::Params* params)
{
if (params->size() < 2) return;

std::string material = params->get(1);

const auto header = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, material.data());
if (header.data)
{
Components::ZoneBuilder::RefreshExporterWorkDirectory();
Components::ZoneBuilder::GetExporter()->write(Game::XAssetType::ASSET_TYPE_MATERIAL, header.data);
}
else
{
Components::Logger::Print("Could not find material {}!\n", material);
}
});
}
}
2 changes: 2 additions & 0 deletions src/Components/Modules/AssetInterfaces/IMaterial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ namespace Assets
void load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) override;
void loadFromDisk(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder);
void loadNative(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder);

IMaterial();
};
}
50 changes: 49 additions & 1 deletion src/Components/Modules/Download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ namespace Components
fileEntry.name = name;
fileEntry.hash = hash;
fileEntry.size = size;
fileEntry.isMap = download->isMap_;

if (!fileEntry.name.empty())
if (!fileEntry.name.empty() && fileEntry.allowed())
{
download->files_.push_back(fileEntry);
download->totalBytes_ += fileEntry.size;
Expand All @@ -139,6 +140,8 @@ namespace Components

auto file = download->files_[index];

assert(file.allowed());

auto path = download->mod_ + "/" + file.name;
if (download->isMap_)
{
Expand Down Expand Up @@ -884,4 +887,49 @@ namespace Components
CLDownload.clear();
}
}

bool Download::ClientDownload::File::allowed() const
{
if (Utils::String::Contains(name, "..") || Utils::String::Contains(name, ":"))
{
return false;
}

if (Utils::String::Contains(name, "\\") || Utils::String::Contains(name, "/"))
{
return false;
}

if (isMap)
{
if (name.ends_with(".arena"))
{
return true;
}

if (name.ends_with(".iwd"))
{
return true;
}

if (name.ends_with(".ff"))
{
return true;
}
}
else
{
// Plain and simple
if (name == "mod.ff")
{
return true;
}
if (name.ends_with(".iwd"))
{
return true;
}
}

return false;
}
}
3 changes: 3 additions & 0 deletions src/Components/Modules/Download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ namespace Components
std::string name;
std::string hash;
std::size_t size;
bool isMap;

bool allowed() const;
};

std::vector<File> files_;
Expand Down
10 changes: 10 additions & 0 deletions src/Utils/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ namespace Utils::String
return std::equal(needle.rbegin(), needle.rend(), haystack.rbegin());
}

bool Contains(const std::string& haystack, const std::string& needle)
{
if (haystack.find(needle) != std::string::npos)
{
return true;
}

return false;
}

bool IsNumber(const std::string& str)
{
return !str.empty() && std::find_if(str.begin(), str.end(), [](unsigned char input)
Expand Down
1 change: 1 addition & 0 deletions src/Utils/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ namespace Utils::String

[[nodiscard]] bool StartsWith(const std::string& haystack, const std::string& needle);
[[nodiscard]] bool EndsWith(const std::string& haystack, const std::string& needle);
[[nodiscard]] bool Contains(const std::string& haystack, const std::string& needle);

[[nodiscard]] bool IsNumber(const std::string& str);

Expand Down

0 comments on commit dae27cb

Please sign in to comment.