Modding Improvements #18

Closed
HighTechRedNeck wants to merge 2 commits from (deleted):master into master
4 changed files with 79 additions and 3 deletions
Showing only changes of commit b21eba680b - Show all commits

View File

@ -1,5 +1,7 @@
#pragma once
#include "game/game.hpp"
namespace fastfiles
{
void enum_assets(game::XAssetType type, const std::function<void(game::XAssetHeader)>& callback, bool include_override);

View File

@ -0,0 +1,58 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "fastfiles.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
namespace weapon
{
namespace
{
utils::hook::detour g_setup_level_weapon_def_hook;
void g_setup_level_weapon_def_stub()
{
// precache level weapons first
g_setup_level_weapon_def_hook.invoke<void>();
std::vector<game::WeaponCompleteDef*> weapons;
// find all weapons in asset pools
fastfiles::enum_assets(game::ASSET_TYPE_WEAPON, [&weapons](game::XAssetHeader header)
{
weapons.push_back(header.weapon);
}, false);
// sort weapons
std::sort(weapons.begin(), weapons.end(), [](game::WeaponCompleteDef* weapon1, game::WeaponCompleteDef* weapon2)
{
return std::string_view(weapon1->name) <
std::string_view(weapon2->name);
});
// precache items
for (std::size_t i = 0; i < weapons.size(); i++)
{
//console::debug("precaching weapon \"%s\"\n", weapons[i]->name);
game::G_GetWeaponForName(weapons[i]->name);
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (!game::environment::is_sp())
{
// precache all weapons that are loaded in zones
g_setup_level_weapon_def_hook.create(0x1403DA910, g_setup_level_weapon_def_stub);
}
}
};
}
REGISTER_COMPONENT(weapon::component)

View File

@ -0,0 +1,6 @@
#pragma once
namespace weapon
{
}

View File

@ -1955,6 +1955,16 @@ namespace game
weapInventoryType_t inventoryType;
}; // Incomplete
struct WeaponCompleteDef
{
union
{
const char* szInternalName;
const char* name;
};
WeaponDef* weapDef;
};
struct RawFile
{
const char* name;
@ -1998,9 +2008,9 @@ namespace game
menuDef_t *menu;
AnimationClass *animClass;
LocalizeEntry *localize;
WeaponAttachment *attachment;
WeaponCompleteDef *weapon;
SndDriverGlobals *sndDriverGlobals;
WeaponAttachment *attachment;*/
WeaponCompleteDef* weapon;
/*SndDriverGlobals* sndDriverGlobals;
FxEffectDef *fx;
FxImpactTable *impactFx;
SurfaceFxTable *surfaceFx;*/