From c635638fd17adc66a1eda9e2dac0ddfe96828726 Mon Sep 17 00:00:00 2001 From: Christian Hammacher Date: Tue, 16 Oct 2007 20:59:57 +0000 Subject: [PATCH] implemented amb773 - now precaches sounds from speech.ini, can be disabled via compiler switch --- plugins/cmdmenu.sma | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/plugins/cmdmenu.sma b/plugins/cmdmenu.sma index 0ddcec09..67d64c22 100755 --- a/plugins/cmdmenu.sma +++ b/plugins/cmdmenu.sma @@ -35,6 +35,9 @@ #include #include +// Precache sounds from speech.ini - comment this line to disable +#define PRECACHE_SPEECHINI + /* Commands Menus */ #define MAX_CMDS_LAYERS 3 @@ -121,6 +124,83 @@ public plugin_init() g_coloredMenus = colored_menus() } +#if defined PRECACHE_SPEECHINI +public plugin_precache( ) +{ + new configsDir[64], config[64]; + get_configsdir( configsDir, 63 ); + formatex( config, 63, "%s/%s", configsDir, "speech.ini" ); + + new fp = fopen( config, "rt" ); // Read file as text + + if ( ! fp ) // File doesn't exists + return 0; + + new szText[256]; + new line = 0; + new szName[32], szSound[128], sndExt[5]; + new field1[32], field2[64], field3[64]; + new fieldNums = 0; + + while ( line < MAX_CMDS && ! feof( fp ) ) // Loop till MAX_CMDS or EOF + { + fgets( fp, szText, 255 ); // Store line content + + /* Strips newline */ + new len = strlen( szText ); + if ( len != 0 && szText[len-1] == '^n' ) // len != 0 because if the last line of the file is empty, there's no newline + szText[--len] = 0; + + if ( len == 0 || szText[0] == ';' || szText[0] == '/' ) // Line is empty or a comment + continue; + + parse( szText, szName, 31, szSound, 127 ); + fieldNums = parse( szSound, field1, 31, field2, 63, field3, 63 ); + if ( fieldNums == 2 && field1[0] == 's' ) // .wav (spk) + { + copy( szSound, 127, field2 ); + copy( sndExt, 4, ".wav" ); + } + else if ( fieldNums == 3 && field1[0] == 'm' && ( field2[0] == 'p' || field2[0] == 'l' ) ) // .mp3 (mp3 play | mp3 loop) + { + copy( szSound, 127, field3 ); + copy( sndExt, 4, ".mp3" ); + } + else // WTH is this sound, drop it. + continue; + + replace_all( szSound, 127, "\'", "" ); // Strips all ugly (and sometimes useless) \' + + if ( szSound[0] == '/' ) + replace( szSound, 127, "/", "" ); // Strip leading slash + + if ( sndExt[1] == 'm' || ( ! equali( szSound, "vox", 3 ) && ! equali( szSound, "fvox", 4 ) && ! equali( szSound, "barney", 6 ) && ! equali( szSound, "hgrunt", 6 ) ) ) + { + // SzSound is a mp3, or a custom wav (not a vox, fvox, or default sound from HL pak) + if ( !equali( szSound[strlen(szSound)-4], sndExt ) ) + add( szSound, 127, sndExt ); // Add filetype extension if it isn't already specified + if ( sndExt[1] == 'w' ) + format( szSound, 127, "sound/%s", szSound ); // spk basedir is $moddir/sound, but mp3 play is $moddir, fix this for the file_exists check + if ( file_exists( szSound ) ) + { + if ( sndExt[1] == 'm') + { + precache_generic( szSound ); // mp3 + } + else + { + replace( szSound, 127, "sound/", "" ); // wav, strip the leading sound/ we added for our file_exists check + precache_sound( szSound ); + } + } + } + line++ + } + fclose( fp ); // Close file + return line; +} +#endif + /* Commands menu */ public actionCmdMenu(id, key)