#include <amxmodx>
#include <fakemeta>
#define PLUGIN "Autoprecache Sound Models"
#define VERSION "1.0"
#define AUTHOR "MayroN"
new const list_models_v[][] =
{
"models/custom/v_ak47.mdl",
"models/custom/v_m4a1.mdl",
"models/custom/v_awp.mdl",
"models/custom/v_deagle.mdl"
}
public plugin_precache()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
for(new i = 0; i < sizeof list_models_v; i++)
UTIL_PrecacheSoundsFromModel(list_models_v[i]);
}
stock UTIL_PrecacheSoundsFromModel(const szModelPath[])
{
new iFile;
if ((iFile = fopen(szModelPath, "rt")))
{
new szSoundPath[64];
new iNumSeq, iSeqIndex;
new iEvent, iNumEvents, iEventIndex;
fseek(iFile, 164, SEEK_SET);
fread(iFile, iNumSeq, BLOCK_INT);
fread(iFile, iSeqIndex, BLOCK_INT);
for (new k, i = 0; i < iNumSeq; i++)
{
fseek(iFile, iSeqIndex + 48 + 176 * i, SEEK_SET);
fread(iFile, iNumEvents, BLOCK_INT);
fread(iFile, iEventIndex, BLOCK_INT);
fseek(iFile, iEventIndex + 176 * i, SEEK_SET);
for (k = 0; k < iNumEvents; k++)
{
fseek(iFile, iEventIndex + 4 + 76 * k, SEEK_SET);
fread(iFile, iEvent, BLOCK_INT);
fseek(iFile, 4, SEEK_CUR);
if (iEvent != 5004)
continue;
fread_blocks(iFile, szSoundPath, 64, BLOCK_CHAR);
if (strlen(szSoundPath))
{
strtolower(szSoundPath);
engfunc(EngFunc_PrecacheSound, szSoundPath);
}
}
}
}
fclose(iFile);
}