This module gives you the ability to decide which files you want to download from the downloadables string table. It works in a similar way to the cl_downloadfilter ConVar, except it’s not restricted to just sounds and all/none.
You will need to load your code in the menu environment to access the hook.
Return true or nil to let the download through.
hook.Add(“ShouldDownload”, “DownloadFilter”, function(filename)
local ext = string.GetExtensionFromFilename(filename)
if ((ext != "bsp") && (ext != "dua")) then --Filter out everything except the map and the datapack
[07/06/10, 22:23] - Added Detours/SigScan wrappers to tidy up code a bit
Well, first of all I tried hooking to INetChannel::RequestFile, a function that is exposed publicly. This seemed to work fine, except I ran into a major problem - downloads that were filtered stayed in the queue, therefore rendering it useless. I found a hacky workaround by changing the file name requested to something that didn’t exist on the client, but if the server didn’t have the file it would be spammed with errors + this was pretty dumb anyway.
After that, I tried hooking to the function that processes string table updates (which is also exposed) to prevent filtered files going through. However, I couldn’t find an easy way of doing this as the buffer given in the update function was compressed, therefore useless to me. Technically I could have gone through the update function and worked out how it extracted the data, but this would have been a lot more complex than the final result.
I ended up following the use of the cl_downloadfilter ConVar around as I figured this is where the download queue is processed. Eventually I came into a function which returned 1/0 (true/false) and took a file name as its only argument. This isn’t ideal and I would have preferred the second attempt to have succeeded, but it works in the same way as cl_downloadfilter and gets the job done without any hacky code.
NOTE: if you can’t see it well on my shitty computer’s resolution, to open the menu, go to Extensions in your garrysmod main menu. Also please notify me if I forgot an extension that is important (it allows unknown extensions by default).