|
16 | 16 | #include "download.h" |
17 | 17 | #include "cl_private_resources.h" |
18 | 18 |
|
19 | | -static resourcetype_t ValidateClientResourceAndGetType(const ResourceDescriptor& resource_descriptor) |
| 19 | +namespace |
| 20 | +{ |
| 21 | + constexpr std::string_view kSoundPath = DEFAULT_SOUNDPATH; |
| 22 | +} |
| 23 | + |
| 24 | +static resourcetype_t GetResourceTypeByPath(const std::string& filepath) |
20 | 25 | { |
21 | | - std::filesystem::path download_path = resource_descriptor.get_download_path(); |
22 | | - if (!download_path.has_extension() || !download_path.has_filename()) |
| 26 | + std::filesystem::path path = filepath; |
| 27 | + if (!path.has_extension() || !path.has_filename()) |
23 | 28 | { |
24 | 29 | return rt_max; |
25 | 30 | } |
26 | 31 |
|
27 | 32 | resourcetype_t resource_type = rt_max; |
28 | 33 |
|
29 | | - std::string dl_path_lower = nitro_utils::to_lower_copy(download_path.string()); |
| 34 | + std::string path_lower = nitro_utils::to_lower_copy(path.string()); |
30 | 35 |
|
31 | | - if (dl_path_lower.starts_with("sprites/") && |
32 | | - (dl_path_lower.ends_with(".spr") || dl_path_lower.ends_with(".txt"))) |
| 36 | + if (path_lower.starts_with("sprites/") && |
| 37 | + (path_lower.ends_with(".spr") || path_lower.ends_with(".txt"))) |
33 | 38 | { |
34 | 39 | resource_type = t_generic; |
35 | 40 | } |
36 | | - else if (dl_path_lower.starts_with("sound/") && |
37 | | - (dl_path_lower.ends_with(".wav") || dl_path_lower.ends_with(".flac") || dl_path_lower.ends_with(".ogg") || dl_path_lower.ends_with(".mp3"))) |
| 41 | + else if (path_lower.starts_with(kSoundPath) && |
| 42 | + (path_lower.ends_with(".wav") || path_lower.ends_with(".mp3"))) |
38 | 43 | { |
39 | 44 | resource_type = t_sound; |
40 | 45 | } |
41 | 46 |
|
42 | 47 | return resource_type; |
43 | 48 | } |
44 | 49 |
|
| 50 | +static resourcetype_t ValidateClientResourceAndGetType(const ResourceDescriptor& resource_descriptor) |
| 51 | +{ |
| 52 | + resourcetype_t download_type = GetResourceTypeByPath(resource_descriptor.get_download_path()); |
| 53 | + |
| 54 | + if (download_type != GetResourceTypeByPath(resource_descriptor.get_filename())) |
| 55 | + { |
| 56 | + return rt_max; |
| 57 | + } |
| 58 | + |
| 59 | + return download_type; |
| 60 | +} |
| 61 | + |
45 | 62 | static void AddPrivateResource(bool client_only, const std::string& filename, const std::string& download_path, CRC32_t server_crc, int size) |
46 | 63 | { |
47 | 64 | client_stateex.privateResources.try_emplace(filename, ResourceDescriptor { filename, download_path, server_crc, size, client_only }); |
@@ -200,8 +217,15 @@ void PrivateRes_AddClientOnlyResources(resource_t* list) |
200 | 217 | continue; |
201 | 218 | } |
202 | 219 |
|
| 220 | + // resource list keeps t_sound paths relative to DEFAULT_SOUNDPATH, while a private resource is keyed by the full client path |
| 221 | + const char* resource_name = filepath.c_str(); |
| 222 | + if (resource_type == t_sound) |
| 223 | + { |
| 224 | + resource_name += kSoundPath.size(); |
| 225 | + } |
| 226 | + |
203 | 227 | auto* res = (resource_t*)Mem_ZeroMalloc(sizeof(resource_t)); |
204 | | - V_strcpy_safe(res->szFileName, filepath.c_str()); |
| 228 | + V_strcpy_safe(res->szFileName, resource_name); |
205 | 229 | res->type = resource_type; |
206 | 230 | res->nDownloadSize = res_descriptor.get_download_size(); |
207 | 231 |
|
|
0 commit comments