Skip to content

Commit

Permalink
Improve spawn elemens filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Drombeys committed Sep 21, 2024
1 parent 3d0e9a2 commit 199ce42
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 20 deletions.
34 changes: 31 additions & 3 deletions src/xrGame/ImUtils/SpawnManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ void InitSections()
continue;

CLASS_ID classId = pSettings->r_clsid(name.data(), "class");

if (pSection->line_exist("visual"))
{
std::string_view visual = pSettings->r_string(name.data(), "visual");
shared_str full_path;

if (visual.find(".ogf") == xr_string::npos)
{
full_path.printf("%s%s%s", FS.get_path("$game_meshes$")->m_Path, visual.data(), ".ogf");
}
else {
full_path.printf("%s%s", FS.get_path("$game_meshes$")->m_Path, visual.data());
}
if(!FS.exist(full_path.c_str()))
{
Msg("! SpawnManager: failed to spawn [%s] visual not found: %s", name.data(), full_path.c_str());
continue;
}
}
else {
continue;
}

bool isInvItem = pSection->line_exist("cost") && pSection->line_exist("inv_weight");
size_t mp_index = name.find("mp_");
Expand All @@ -97,13 +119,19 @@ void InitSections()
}
else if (g_pClsidManager->is_weapon(classId))
{
if (isInvItem)
bool isValidSect = true;
if (pSection->line_exist("parent_section"))
{
const char* parentSection = pSettings->r_string(name.data(), "parent_section");
isValidSect = strcmp(parentSection, name.data()) == 0;
}
if (isInvItem && isValidSect)
{
imgui_spawn_manager.WeaponsSections.Sorted.push_back({ name, pSection });
}
else
{
imgui_spawn_manager.WeaponsSections.Unsorted.push_back({ name, pSection });
{
imgui_spawn_manager.WeaponsSections.Unsorted.push_back({ name, pSection });
}
}
else if (g_pClsidManager->is_item(classId))
Expand Down
68 changes: 51 additions & 17 deletions src/xrGame/console_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,21 @@ class CCC_GiveMoney : public IConsole_Command {

extern bool IsGameTypeSingle();

static bool isValidSection(std::string_view section) {
std::string_view visual = pSettings->r_string(section.data(), "visual");
shared_str full_path;

if (visual.find(".ogf") == xr_string::npos)
{
full_path.printf("%s%s%s", FS.get_path("$game_meshes$")->m_Path, visual.data(), ".ogf");
}
else {
full_path.printf("%s%s", FS.get_path("$game_meshes$")->m_Path, visual.data());
}

return FS.exist(full_path.c_str());
}

class CCC_GSpawn : public IConsole_Command {
public:
CCC_GSpawn(LPCSTR N) : IConsole_Command(N) {
Expand All @@ -1854,21 +1869,21 @@ class CCC_GSpawn : public IConsole_Command {
return;
}

if (!pSettings->section_exist(nameSection)) {
if (!pSettings->section_exist(nameSection))
{
Msg("! Can't find section: %s", nameSection);
return;
}

//if (pSettings->line_exist(nameSection, "visual"))
//{
// shared_str full_path;
// full_path.printf("%s%s", FS.get_path("$game_meshes$")->m_Path, pSettings->r_string( nameSection, "visual" ));
// if(!FS.exist(full_path.c_str()))
// {
// Msg("! Visual not found!");
// return;
// }
//}
if (pSettings->line_exist(nameSection, "visual"))
{
if (!isValidSection(nameSection))
{
std::string_view visual = pSettings->r_string(nameSection, "visual");
Msg("! Failed insert [%s] visual not found", nameSection);
return;
}
}

Fvector3 point = point.mad(Device.vCameraPosition, Device.vCameraDirection, HUD().GetCurrentRayQuery().range);
auto tpGame = smart_cast<game_sv_Single*>(Level().Server->game);
Expand Down Expand Up @@ -1932,15 +1947,19 @@ class CCC_GSpawn : public IConsole_Command {

virtual void fill_tips(vecTips& tips, u32 mode) override {

if (IsGameTypeSingle()) {
if (!ai().get_alife()) {
if (IsGameTypeSingle())
{
if (!ai().get_alife())
{
Msg("! ALife simulator is needed to perform specified command!");
return;
}
}

for (const auto& section : pSettings->sections()) {
if (section->line_exist("class")) {
for (const auto& section : pSettings->sections())
{
if (section->line_exist("class") && section->line_exist("visual") && isValidSection(section->Name.c_str()))
{
tips.push_back(section->Name.c_str());
}
}
Expand Down Expand Up @@ -2136,6 +2155,16 @@ class CCC_GSpawnToInventory : public IConsole_Command {
return;
}

if (pSettings->line_exist(nameSection, "visual"))
{
if (!isValidSection(nameSection))
{
std::string_view visual = pSettings->r_string(nameSection, "visual");
Msg("! Failed insert [%s] visual not found", nameSection);
return;
}
}

auto tpGame = smart_cast<game_sv_Single*>(Level().Server->game);
if (tpGame == nullptr) {
return;
Expand All @@ -2153,8 +2182,13 @@ class CCC_GSpawnToInventory : public IConsole_Command {
return;
}

for (const auto& section : pSettings->sections()) {
if (section->line_exist("cost") && section->line_exist("inv_weight")) {
for (const auto& section : pSettings->sections())
{
if (section->line_exist("visual")
&& isValidSection(section->Name.c_str())
&& section->line_exist("cost")
&& section->line_exist("inv_weight"))
{
tips.push_back(section->Name.c_str());
}
}
Expand Down

0 comments on commit 199ce42

Please sign in to comment.