DeathChaos25

L4D1 sound restore

Mar 28th, 2015
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.38 KB | None | 0 0
  1. /* Includes */
  2. #include <sourcemod>
  3. #include <sdktools>
  4.  
  5. /* Plugin Information */
  6. public Plugin:myinfo =  {
  7.     name = "[L4D2] L4D1 sounds restore",
  8.     author = "DeathChaos25",
  9.     description = "Restores L4D1 sounds when playing a L4D1 campaign on L4D2 survivor set",
  10.     version = "1.0",
  11.     url = "1337H4X"
  12. }
  13.  
  14. /* Globals */
  15. #define DEBUG 1
  16. #define DEBUG_TAG "L4D1 Sound Restore"
  17. #define DEBUG_PRINT_FORMAT "[%s] %s"
  18.  
  19. new Handle:g_SoundsTrie
  20.  
  21. /* Plugin Functions */
  22. public OnPluginStart()
  23. {
  24.     g_SoundsTrie = CreateTrie()
  25.     SetupSoundReplacements()
  26.     AddNormalSoundHook(L4D1Sounds_SoundHook);
  27. }
  28.  
  29. // public OnMapStart()
  30. // Map check coming soon tm
  31. SetupSoundReplacements()
  32. {
  33.     /* music sounds */
  34.     SetTrieString(g_SoundsTrie, "music/undeath/death", "music/undeath/death_l4d1")
  35.     SetTrieString(g_SoundsTrie, "music/undeath/leftfordeath", "music/undeath/leftfordeath_l4d1")
  36.     SetTrieString(g_SoundsTrie, "music/terror/iamsocold", "music/terror/iamsocold_l4d1")
  37.     SetTrieString(g_SoundsTrie, "music/terror/puddleofyou", "music/terror/puddleofyou_l4d1")
  38.     SetTrieString(g_SoundsTrie, "music/terror/theend", "music/terror/theend_l4d1")
  39.     SetTrieString(g_SoundsTrie, "music/safe/themonsterwithout", "music/safe/themonsterwithout_l4d1")
  40.     SetTrieString(g_SoundsTrie, "music/safe/themonsterwithout_s", "music/safe/themonsterwithout_l4d1")
  41.     SetTrieString(g_SoundsTrie, "music/tags/iamsocoldhit", "music/tags/iamsocoldhit_l4d1")
  42.     SetTrieString(g_SoundsTrie, "music/tags/leftfordeathhit", "music/tags/leftfordeathhit_l4d1")
  43.     SetTrieString(g_SoundsTrie, "music/tags/puddleofyouhit", "music/tags/puddleofyouhit_l4d1")
  44.    
  45.     SetTrieString(g_SoundsTrie, "music/the_end/skinonourteeth", "music/the_end/skinonourteeth_l4d1")
  46.     SetTrieString(g_SoundsTrie, "music/the_end/snowballinhell", "music/the_end/snowballinhell_l4d1")
  47.     SetTrieString(g_SoundsTrie, "music/unalive/themonsterwithin", "music/unalive/themonsterwithin_l4d1")
  48.     SetTrieString(g_SoundsTrie, "music/zombat/slayer/lectric/slayer_01a", "music/zombat/slayer/hordeslayer_01")
  49.     SetTrieString(g_SoundsTrie, "music/terror/theend", "music/terror/theend_l4d1")
  50.     SetTrieString(g_SoundsTrie, "music/glimpse/aglimpsofdeath_01", "music/glimpse/aglimpsofhell_01")
  51.     SetTrieString(g_SoundsTrie, "music/glimpse/aglimpsofdeath_02", "music/glimpse/aglimpsofhell_02")
  52.     SetTrieString(g_SoundsTrie, "music/glimpse/aglimpsofdeath_03", "music/glimpse/aglimpsofhell_03")
  53. }
  54.  
  55. public Action:L4D1Sounds_SoundHook(clients[64], &numClients, String:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
  56. {
  57.     if (StrContains(sample, "music", false) != -1)
  58.     {
  59.         decl String:newSample[PLATFORM_MAX_PATH];
  60.        
  61.         if (!GetTrieString(g_SoundsTrie, sample, newSample, sizeof(newSample)))
  62.         {
  63.             #if DEBUG
  64.             Debug_PrintText("Not replacing sound (\"%s\") as no replacement sound can be found in trie.", sample, newSample)
  65.             #endif
  66.             return Plugin_Continue
  67.         }
  68.         new Handle:pack = CreateDataPack();
  69.         WritePackCell(pack, entity);
  70.         WritePackCell(pack, level);
  71.         WritePackCell(pack, channel);
  72.         WritePackCell(pack, flags);
  73.         WritePackCell(pack, pitch);
  74.         WritePackFloat(pack, volume);
  75.         WritePackString(pack, fileSample);
  76.         CreateTimer(0.0, SoundReplace_Timer, pack, TIMER_FLAG_NO_MAPCHANGE | TIMER_DATA_HNDL_CLOSE);
  77.        
  78.         volume = 0.0;
  79.         return Plugin_Changed;
  80.     }
  81.     return Plugin_Continue;
  82. }
  83.  
  84. public Action:SoundReplace_Timer(Handle:timer, Handle:pack)
  85. {
  86.     ResetPack(pack);
  87.     new entity = ReadPackCell(pack);
  88.     new level = ReadPackCell(pack);
  89.     new channel = ReadPackCell(pack);
  90.     new flags = ReadPackCell(pack);
  91.     new pitch = ReadPackCell(pack);
  92.     new Float:volume = ReadPackFloat(pack);
  93.     decl String:sample[PLATFORM_MAX_PATH];
  94.     ReadPackString(pack, sample, PLATFORM_MAX_PATH);
  95.    
  96.     if (!IsSoundPrecached(sample))
  97.     {
  98.         PrecacheSound(sample, true);
  99.     }
  100.    
  101.     EmitSoundToAll(sample, entity, channel, level, flags, volume, pitch);
  102.     return Plugin_Stop;
  103. }
  104.  
  105. #if DEBUG
  106. stock Debug_PrintText(const String:format[], any:...)
  107. {
  108.     decl String:buffer[256]
  109.     VFormat(buffer, sizeof(buffer), format, 2)
  110.    
  111.     LogMessage(buffer)
  112.    
  113.     new AdminId:adminId
  114.     for (new client = 1; client <= MaxClients; client++) {
  115.         if (!IsClientInGame(client) || IsFakeClient(client)) {
  116.             continue
  117.         }
  118.        
  119.         adminId = GetUserAdmin(client)
  120.         if (adminId == INVALID_ADMIN_ID || !GetAdminFlag(adminId, Admin_Root)) {
  121.             continue
  122.         }
  123.        
  124.         PrintToChat(client, DEBUG_PRINT_FORMAT, DEBUG_TAG, buffer)
  125.     }
  126. }
  127. #endif
Advertisement
Add Comment
Please, Sign In to add comment