Adds precaching of weapons in loaded zones because normal precache doesn't work for custom weapons. Reload mod after level is loaded. #19
@ -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);
|
||||
|
@ -150,6 +150,9 @@ namespace mods
|
||||
|
||||
// Load mod.ff
|
||||
utils::hook::call(0x1405E7113, db_load_x_assets_stub); // R_LoadGraphicsAssets According to myself but I don't remember where I got it from
|
||||
|
||||
//Reload mod.ff after map is loaded
|
||||
utils::hook::call(0x140320ED1, db_load_x_assets_stub); // DB_LoadLevelXAssets
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
58
src/client/component/weapon.cpp
Normal file
58
src/client/component/weapon.cpp
Normal 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)
|
6
src/client/component/weapon.hpp
Normal file
6
src/client/component/weapon.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace weapon
|
||||
{
|
||||
|
||||
}
|
@ -1955,6 +1955,15 @@ namespace game
|
||||
weapInventoryType_t inventoryType;
|
||||
}; // Incomplete
|
||||
|
||||
struct WeaponCompleteDef
|
||||
{
|
||||
union
|
||||
{
|
||||
const char* szInternalName;
|
||||
const char* name;
|
||||
};
|
||||
};
|
||||
|
||||
struct RawFile
|
||||
{
|
||||
const char* name;
|
||||
@ -1998,9 +2007,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;*/
|
||||
|
Reference in New Issue
Block a user
BTW I left this part out completely because this is subject to further investigation.
The reason is that reloading a mod after a map (or before) has caused issues on another clients.
Mainly on pluto, on piw5 the mod.ff is always loaded twice in a similar manner (need to double check) and is known to kill to stock maps for some reason.