Skip to content

Commit 0e02f2e

Browse files
committed
fix ncl_upload_file for sounds by listing t_sound resources relative to the sound path
1 parent 1c3a544 commit 0e02f2e

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

nextclient/engine_mini/src/client/cl_private_resources.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,49 @@
1616
#include "download.h"
1717
#include "cl_private_resources.h"
1818

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)
2025
{
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())
2328
{
2429
return rt_max;
2530
}
2631

2732
resourcetype_t resource_type = rt_max;
2833

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());
3035

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")))
3338
{
3439
resource_type = t_generic;
3540
}
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")))
3843
{
3944
resource_type = t_sound;
4045
}
4146

4247
return resource_type;
4348
}
4449

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+
4562
static void AddPrivateResource(bool client_only, const std::string& filename, const std::string& download_path, CRC32_t server_crc, int size)
4663
{
4764
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)
200217
continue;
201218
}
202219

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+
203227
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);
205229
res->type = resource_type;
206230
res->nDownloadSize = res_descriptor.get_download_size();
207231

0 commit comments

Comments
 (0)