|
| 1 | +if game.SinglePlayer! |
| 2 | + return |
| 3 | + |
| 4 | +:lower, :Split, :StartsWith, :GetExtensionFromFilename = string |
| 5 | +:Exists, :Find = file |
| 6 | +resource = resource |
| 7 | +ipairs = ipairs |
| 8 | + |
| 9 | +workshopDL = resource.WorkshopDL |
| 10 | +unless istable( workshopDL ) |
| 11 | + workshopDL = {} |
| 12 | + resource.WorkshopDL = workshopDL |
| 13 | + |
| 14 | +-- https://github.com/Facepunch/gmad/blob/master/include/AddonWhiteList.h |
| 15 | +resourceExtensions = { |
| 16 | + -- Models |
| 17 | + "mdl": true |
| 18 | + "vtx": true |
| 19 | + "phy": true |
| 20 | + "ani": true |
| 21 | + "vvd": true |
| 22 | + |
| 23 | + -- Sounds |
| 24 | + "wav": true |
| 25 | + "mp3": true |
| 26 | + "ogg": true |
| 27 | + |
| 28 | + -- Materials & Textures |
| 29 | + "vmt": true |
| 30 | + "vtf": true |
| 31 | + "png": true |
| 32 | + "jpg": true |
| 33 | + "jpeg": true |
| 34 | + "raw": true |
| 35 | + |
| 36 | + -- Fonts |
| 37 | + "ttf": true |
| 38 | + |
| 39 | + -- Animations |
| 40 | + "ani": true |
| 41 | + |
| 42 | + -- Particles |
| 43 | + "pcf": true |
| 44 | + |
| 45 | + -- Scenes |
| 46 | + "vcd": true |
| 47 | + |
| 48 | + -- Localization |
| 49 | + "properties": true |
| 50 | +} |
| 51 | + |
| 52 | +getTag = nil |
| 53 | +do |
| 54 | + |
| 55 | + tagNames = { |
| 56 | + "gamemode": "Gamemode" |
| 57 | + "map": "Map" |
| 58 | + "weapon": "Weapon" |
| 59 | + "vehicle": "Vehicle" |
| 60 | + "npc": "NPC" |
| 61 | + "entity": "Entity" |
| 62 | + "tool": "Tool" |
| 63 | + "effects": "Effect" |
| 64 | + "model": "Model" |
| 65 | + "servercontent": "Server Content" |
| 66 | + } |
| 67 | + |
| 68 | + getTag = ( addon ) -> |
| 69 | + for _, tag in ipairs( Split( addon.tags, "," ) ) |
| 70 | + tag = tagNames[ lower( tag ) ] |
| 71 | + if tag ~= nil |
| 72 | + return tag |
| 73 | + |
| 74 | + return "Addon" |
| 75 | + |
| 76 | +addCWorkshop = resource.AddCWorkshop |
| 77 | +unless addCWorkshop |
| 78 | + addCWorkshop = resource.AddWorkshop |
| 79 | + resource.AddCWorkshop = addCWorkshop |
| 80 | + |
| 81 | +addons = engine.GetAddons! |
| 82 | +addonsCount = #addons |
| 83 | + |
| 84 | +addWorkshop = nil |
| 85 | +do |
| 86 | + |
| 87 | + MsgC = MsgC |
| 88 | + |
| 89 | + color0 = Color( 200, 200, 200 ) |
| 90 | + color1 = Color( 180, 180, 180 ) |
| 91 | + color2 = Color( 20, 150, 240 ) |
| 92 | + |
| 93 | + addWorkshop = ( wsid ) -> |
| 94 | + if workshopDL[ wsid ] |
| 95 | + return |
| 96 | + |
| 97 | + workshopDL[ wsid ] = true |
| 98 | + addCWorkshop( wsid ) |
| 99 | + workshopDL[] = wsid |
| 100 | + |
| 101 | + for index = 1, addonsCount |
| 102 | + if addons[ index ].wsid == wsid |
| 103 | + MsgC( color1, "[", color2, "WorkshopDL", color1, "] + ", color0, getTag( addons[ index ] ) .. ": ", color2, addons[ index ].title, color1, " ( ", color0, wsid, color1, " )\n" ) |
| 104 | + return |
| 105 | + |
| 106 | + MsgC( color1, "[", color2, "WorkshopDL", color1, "] + ", color0, "Addon: ", color2, "unknown", color1, " ( ", color0, wsid, color1, " )\n" ) |
| 107 | + |
| 108 | + resource.AddWorkshop = addWorkshop |
| 109 | + |
| 110 | +scanAddon = ( gamePath, folderPath, result, length ) -> |
| 111 | + if folderPath == nil |
| 112 | + result, length = {}, 0 |
| 113 | + |
| 114 | + files, folders = Find( "*", gamePath ) |
| 115 | + for _, fileName in ipairs( files ) |
| 116 | + length += 1 |
| 117 | + result[ length ] = fileName |
| 118 | + |
| 119 | + for _, folderName in ipairs( folders ) |
| 120 | + scanAddon( gamePath, folderName, result, length ) |
| 121 | + |
| 122 | + return result |
| 123 | + |
| 124 | + files, folders = Find( folderPath .. "/*", gamePath ) |
| 125 | + for _, fileName in ipairs( files ) |
| 126 | + length += 1 |
| 127 | + result[ length ] = folderPath .. "/" .. fileName |
| 128 | + |
| 129 | + for _, folderName in ipairs( folders ) |
| 130 | + scanAddon( gamePath, folderPath .. "/" .. folderName, result, length ) |
| 131 | + |
| 132 | + return result |
| 133 | + |
| 134 | +ignoreOtherMaps = CreateConVar( "awdl_ignore_maps", "1", bit.bor( FCVAR_ARCHIVE, FCVAR_DONTRECORD, FCVAR_NOTIFY ), "If enabled, WorkshopDL will ignore all maps except the current map." ) |
| 135 | +mapName = game.GetMap! |
| 136 | + |
| 137 | +for i = 1, addonsCount |
| 138 | + addon = addons[ i ] |
| 139 | + unless addon.downloaded and addon.mounted |
| 140 | + continue |
| 141 | + |
| 142 | + if mapName ~= nil and Exists( "maps/" .. mapName .. ".bsp", addon.title ) |
| 143 | + addWorkshop( addon.wsid ) |
| 144 | + mapName = nil |
| 145 | + continue |
| 146 | + |
| 147 | + if ignoreOtherMaps\GetBool! and getTag( addon ) == "Map" |
| 148 | + continue |
| 149 | + |
| 150 | + if addon.models > 0 |
| 151 | + addWorkshop( addon.wsid ) |
| 152 | + continue |
| 153 | + |
| 154 | + for _, filePath in ipairs( scanAddon( addon.title ) ) |
| 155 | + if StartsWith( filePath, "data_static/" ) or resourceExtensions[ GetExtensionFromFilename( filePath ) ] |
| 156 | + addWorkshop( addon.wsid ) |
| 157 | + break |
0 commit comments