Code:
#include <amxmodx>
public plugin_precache()
{
precacheList( retrieveEventSounds( "models/v_infinity.mdl" ) );
}
precacheList( Array:list )
{
if( list != Invalid_Array )
{
new count = ArraySize( list );
if( count )
{
const maxSoundLength = 64;
new const soundDir[] = "sound/";
new sound[ maxSoundLength + sizeof soundDir ];
for( new i = 0; i < count; i++ )
{
formatex( sound, charsmax( sound ), "%s%a", soundDir, ArrayGetStringHandle( list, i ) );
if( file_exists( sound ) )
{
//log_amx( "Found = %s", sound[ charsmax( soundDir ) ] );
precache_sound( sound[ charsmax( soundDir ) ] );
}
}
}
ArrayDestroy( list );
}
}
Array:retrieveEventSounds( const model[] )
{
new Array:arrayEventsSounds = Invalid_Array;
new Trie:trieEventsSounds = Invalid_Trie;
new f = fopen( model, "rb" );
if( f )
{
const studioHeaderNumSeq = 164;
const mstudioseqdescSize = 176;
new sequenceIndex;
new sequenceCount;
const studioSeqHeaderNumEvents = 48;
const mstudioeventSize = 76;
const studioEventOptionIndex = 12;
new eventIndex;
new eventCount;
new eventOption[64];
fseek( f, studioHeaderNumSeq, SEEK_SET );
{
fread( f, sequenceCount, BLOCK_INT );
fread( f, sequenceIndex, BLOCK_INT );
}
fseek( f, sequenceIndex, SEEK_SET );
arrayEventsSounds = ArrayCreate( sizeof eventOption );
trieEventsSounds = TrieCreate();
new last = sequenceIndex;
for( new i = 0; i < sequenceCount; i++ )
{
fseek( f, studioSeqHeaderNumEvents, SEEK_CUR );
fread( f, eventCount, BLOCK_INT );
if( eventCount )
{
fread( f, eventIndex, BLOCK_INT );
fseek( f, eventIndex, SEEK_SET );
for( new j = 0; j < eventCount; j++ )
{
fseek( f, studioEventOptionIndex, SEEK_CUR );
fread_blocks( f, eventOption, sizeof eventOption, BLOCK_CHAR );
if( containi( eventOption, ".wav" ) > 0 && !TrieKeyExists( trieEventsSounds, eventOption ) )
{
log_amx( "%s", eventOption );
ArrayPushString( arrayEventsSounds, eventOption );
TrieSetCell( trieEventsSounds, eventOption, true );
}
fseek( f, mstudioeventSize - ( sizeof eventOption + studioEventOptionIndex ), SEEK_CUR );
}
}
fseek( f, last += mstudioseqdescSize, SEEK_SET );
}
TrieDestroy( trieEventsSounds );
fclose( f );
}
return arrayEventsSounds;
}