public stock const PluginName[] = "Sound Precacher";
public stock const PluginVersion[] = "2024.09.15";
public stock const PluginAuthor[] = "Ragamafona";
public stock const PluginURL[] = "https://t.me/nikolaygaus";
public stock const PluginDescription[] = "Auto-precache sound from the list.";
//
#include <amxmodx>
#if !defined MAX_CONFIG_PATH_LEN
const MAX_CONFIG_PATH_LEN = 128;
#endif
#if !defined MAX_RESOURCE_PATH_LEN
const MAX_RESOURCE_PATH_LEN = 128;
#endif
#define DEBUG_MODE 1
//
public plugin_precache() {
register_plugin(PluginName, PluginVersion, PluginAuthor);
new szConfigFile[MAX_CONFIG_PATH_LEN];
get_localinfo("amxx_configsdir", szConfigFile, charsmax(szConfigFile));
strcat(szConfigFile, "/plugins/auto_precache_sound.ini", charsmax(szConfigFile));
new hFileList = fopen(szConfigFile, "rt");
if(hFileList)
{
new szLine[MAX_RESOURCE_PATH_LEN];
new hFileModel;
new szSoundPath[MAX_RESOURCE_PATH_LEN];
new iNumSeq;
new iSeqIndex;
new iEvent;
new iNumEvents;
new iEventIndex;
new i;
new k;
while(!feof(hFileList))
{
fgets(hFileList, szLine, charsmax(szLine));
trim(szLine);
if(!szLine[0] || szLine[0] == ';' || szLine[0] == '/')
{
continue;
}
hFileModel = fopen(szLine, "rt");
if(hFileModel)
{
DEBUG_MODE && server_print("| read model: '%s'", szLine);
fseek(hFileModel, 164, SEEK_SET);
fread(hFileModel, iNumSeq, BLOCK_INT);
fread(hFileModel, iSeqIndex, BLOCK_INT);
for(i = 0; i < iNumSeq; i++)
{
fseek(hFileModel, iSeqIndex + 48 + 176 * i, SEEK_SET);
fread(hFileModel, iNumEvents, BLOCK_INT);
fread(hFileModel, iEventIndex, BLOCK_INT);
fseek(hFileModel, iEventIndex + 176 * i, SEEK_SET);
for(k = 0; k < iNumEvents; k++)
{
fseek(hFileModel, iEventIndex + 4 + 76 * k, SEEK_SET);
fread(hFileModel, iEvent, BLOCK_INT);
fseek(hFileModel, 4, SEEK_CUR);
if(iEvent != 5004)
{
continue;
}
fread_blocks(hFileModel, szSoundPath, charsmax(szSoundPath), BLOCK_CHAR);
if(strlen(szSoundPath))
{
precache_generic(fmt("sound/%s", szSoundPath));
DEBUG_MODE && server_print("| > [%9s] precache sound: 'sound/%s'", file_exists(fmt("sound/%s", szSoundPath), true) ? "success" : "not found", szSoundPath);
}
}
}
fclose(hFileModel);
}
}
fclose(hFileList);
}
}