HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. PRECACHE KIT - Annoying 512 Precache Limit? You have the control now!
  3. https://forums.alliedmods.net/showthread.php?t=259880
  4.  
  5. - Description:
  6. . This plugin allows you to check how many files are precached per map and per type (Sounds/Models/Generic)
  7. You can also check wich files are precached.
  8. . Another tool that this plugin has is UnPrecache utility, wich allows you to unprecache any file that you want.
  9. Yet, be careful. If you unprecache one file that is used (for example models/v_knife.mdl), the server will crash.
  10.  
  11. - Requirements:
  12. . Orpheu -> There isn't any other efficient way to do all of this.
  13.  
  14. - Credits:
  15. . Hornet -> for orpheu signatures for precache counting and base plugin.
  16. . Arkshine -> scripting help
  17.  
  18. - Commands:
  19. . precache_view -> Prints a message to the admin's console with precache information
  20.  
  21. . precache_viewfull -> Log all the names of precached files at the map
  22. (You can add this command at amxx.cfg if you want to generate the log at each map start)
  23.  
  24. - ChangeLogs:
  25. . v0.0.1 at 14/03/2015 - First Release
  26. . v0.0.2 at 15/03/2015 - Minor Fixes
  27. */
  28.  
  29. #include <amxmodx>
  30. #include <amxmisc>
  31. #include <orpheu>
  32. #include <orpheu_stocks>
  33.  
  34. new const Version[] = "0.0.2"
  35.  
  36. enum PrecacheData
  37. {
  38. Sound,
  39. Model,
  40. Generic
  41. }
  42.  
  43. new g_iPrecacheCount[PrecacheData]
  44.  
  45. new g_szMapName[32], g_szLogsDir[70]
  46.  
  47. new Trie:g_tUnPrecache, Trie:g_tSound, Trie:g_tModel, Trie:g_tGeneric
  48.  
  49. public plugin_init() {
  50. register_plugin("Precache Kit", Version, "Jhob94")
  51.  
  52. register_cvar("precache_kit", Version, FCVAR_SPONLY|FCVAR_SERVER)
  53. set_cvar_string("precache_kit", Version)
  54.  
  55. get_mapname(g_szMapName, charsmax(g_szMapName))
  56. get_basedir(g_szLogsDir, charsmax(g_szLogsDir))
  57. add(g_szLogsDir, charsmax(g_szLogsDir), "/logs/Precache")
  58.  
  59. register_concmd("precache_view", "View", ADMIN_RCON, ": View the amount of the precached files")
  60. register_concmd("precache_viewfull", "ViewFull", ADMIN_RCON, ": Log the amount and names of the precached files")
  61. }
  62.  
  63. public plugin_precache()
  64. {
  65. g_tUnPrecache = TrieCreate()
  66. g_tSound = TrieCreate()
  67. g_tModel = TrieCreate()
  68. g_tGeneric = TrieCreate()
  69.  
  70. UnPrecache_Prepare()
  71.  
  72. OrpheuRegisterHook(OrpheuGetEngineFunction("pfnPrecacheSound", "PrecacheSound"), "PrecacheSound")
  73. OrpheuRegisterHook(OrpheuGetEngineFunction("pfnPrecacheModel", "PrecacheModel"), "PrecacheModel")
  74. OrpheuRegisterHook(OrpheuGetEngineFunction("pfnPrecacheGeneric", "PrecacheGeneric"), "PrecacheGeneric")
  75. }
  76.  
  77. public OrpheuHookReturn:PrecacheSound(const szSound[])
  78. {
  79. if(TrieKeyExists(g_tUnPrecache, szSound))
  80. return OrpheuSupercede
  81.  
  82. g_iPrecacheCount[Sound]++
  83.  
  84. new szNameTKey[6]
  85. num_to_str(g_iPrecacheCount[Sound], szNameTKey, charsmax(szNameTKey))
  86.  
  87. TrieSetString(g_tSound, szNameTKey, szSound)
  88. return OrpheuIgnored
  89. }
  90.  
  91. public OrpheuHookReturn:PrecacheModel(const szModel[])
  92. {
  93. if(TrieKeyExists(g_tUnPrecache, szModel))
  94. return OrpheuSupercede
  95.  
  96. g_iPrecacheCount[Model]++
  97.  
  98. new szNameTKey[6]
  99. num_to_str(g_iPrecacheCount[Model], szNameTKey, charsmax(szNameTKey))
  100.  
  101. TrieSetString(g_tModel, szNameTKey, szModel)
  102. return OrpheuIgnored
  103. }
  104.  
  105. public OrpheuHookReturn:PrecacheGeneric(const szGeneric[])
  106. {
  107. if(TrieKeyExists(g_tUnPrecache, szGeneric))
  108. return OrpheuSupercede
  109.  
  110. g_iPrecacheCount[Generic]++
  111.  
  112. new szNameTKey[6]
  113. num_to_str(g_iPrecacheCount[Generic], szNameTKey, charsmax(szNameTKey))
  114.  
  115. TrieSetString(g_tGeneric, szNameTKey, szGeneric)
  116. return OrpheuIgnored
  117. }
  118.  
  119. public View(id, lvl, cid)
  120. {
  121. if(!cmd_access(id, lvl, cid, 1))
  122. return PLUGIN_HANDLED
  123.  
  124. console_print(id, "*Jelenlegi Map: %s ^n*Osszes Precachelt: %i ^n*Precachelt Hangok: %i ^n*Precachelt Modellek: %i ^n*Precachelt Mapfajlok: %i",
  125. g_szMapName, g_iPrecacheCount[Sound] + g_iPrecacheCount[Model] + g_iPrecacheCount[Generic],
  126. g_iPrecacheCount[Sound], g_iPrecacheCount[Model], g_iPrecacheCount[Generic])
  127.  
  128. return PLUGIN_HANDLED
  129. }
  130.  
  131. public ViewFull(id, lvl, cid)
  132. {
  133. if(!cmd_access(id, lvl, cid, 1))
  134. return PLUGIN_HANDLED
  135.  
  136. new szNameTKey[6], szSound[101], szModel[101], szGeneric[101]
  137. DevotionLog("***** INITIALIZING VIEWFULL AT: %s *****", g_szMapName)
  138.  
  139. DevotionLog("* SOUND PRECACHE ( %i Files ) *", g_iPrecacheCount[Sound])
  140. for(new i=1; i<=g_iPrecacheCount[Sound]; i++)
  141. {
  142. num_to_str(i, szNameTKey, charsmax(szNameTKey))
  143.  
  144. if(TrieGetString(g_tSound, szNameTKey, szSound, charsmax(szSound)))
  145. DevotionLog("%s", szSound)
  146. }
  147.  
  148. DevotionLog("* MODEL PRECACHE ( %i Files ) *", g_iPrecacheCount[Model])
  149. for(new i=1; i<=g_iPrecacheCount[Model]; i++)
  150. {
  151. num_to_str(i, szNameTKey, charsmax(szNameTKey))
  152.  
  153. if(TrieGetString(g_tModel, szNameTKey, szModel, charsmax(szModel)))
  154. DevotionLog("%s", szModel)
  155. }
  156.  
  157. DevotionLog("* GENERIC PRECACHE ( %i Files ) *", g_iPrecacheCount[Generic])
  158. for(new i=1; i<=g_iPrecacheCount[Generic]; i++)
  159. {
  160. num_to_str(i, szNameTKey, charsmax(szNameTKey))
  161.  
  162. if(TrieGetString(g_tGeneric, szNameTKey, szGeneric, charsmax(szGeneric)))
  163. DevotionLog("%s", szGeneric)
  164. }
  165.  
  166. console_print(id, "[ Precache Kit ] Precache log letrehozva.")
  167. return PLUGIN_HANDLED
  168. }
  169.  
  170. UnPrecache_Prepare()
  171. {
  172. new szFile[70]
  173. get_configsdir(szFile, charsmax(szFile))
  174. format(szFile, charsmax(szFile), "%s/unprecacher.ini", szFile)
  175.  
  176. new File = fopen(szFile, "rt")
  177.  
  178. if(File)
  179. {
  180. new Data[70]
  181.  
  182. while(!feof(File))
  183. {
  184. fgets(File, Data, charsmax(Data))
  185. trim(Data)
  186.  
  187. if(!Data[0] || Data[0] == ';')
  188. continue
  189.  
  190. if(!file_exists(Data))
  191. {
  192. log_amx("[ PRECACHE KIT ] %s NEM TALALT", Data)
  193. continue
  194. }
  195.  
  196. if(containi(Data, ".wav") != -1)
  197. replace(Data, charsmax(Data), "sound/", "")
  198.  
  199. TrieSetCell(g_tUnPrecache, Data, 1)
  200. }
  201.  
  202. fclose(File)
  203. }
  204. }
  205.  
  206. DevotionLog(const MessageToLog[], any:...)
  207. {
  208. new Message[101], File[96]
  209. vformat(Message, charsmax(Message), MessageToLog, 2)
  210. format(File, charsmax(File), "%s/%s.log", g_szLogsDir, g_szMapName)
  211.  
  212. log_to_file(File, "%s", Message)
  213. }