Skip to content

Commit

Permalink
fix media folder mp3s not working with ambient_music
Browse files Browse the repository at this point in the history
the mp3 command can't handle ".." pathing
  • Loading branch information
wootguy committed Sep 7, 2024
1 parent 69d4559 commit f0dc072
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,9 @@ void UTIL_EmitAmbientSound( edict_t *entity, const float* vecOrigin, const char
void UTIL_PlayGlobalMp3(const char* path, bool loop, edict_t* target) {
// surround with ; to prevent multiple commands being joined when sent in the same frame(?)
// this fixes music sometimes not loading/starting/stopping
std::string mp3Command = UTIL_VarArgs(";mp3 %s sound/%s;", (loop ? "loop" : "play"), path);

std::string mp3Path = normalize_path(UTIL_VarArgs("sound/%s", path));
std::string mp3Command = UTIL_VarArgs(";mp3 %s %s;", (loop ? "loop" : "play"), mp3Path.c_str());

MESSAGE_BEGIN(target ? MSG_ONE : MSG_ALL, SVC_STUFFTEXT, NULL, target);
WRITE_STRING(mp3Command.c_str());
MESSAGE_END();
Expand Down
2 changes: 2 additions & 0 deletions dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,8 @@ EXPORT uint64_t getFileModifiedTime(const char* path);

EXPORT bool fileExists(const char* path);

EXPORT std::string normalize_path(std::string s);

// searches game directories in order (e.g. valve/path, valve_downloads/path)
// returns an empty string if the file can't be found
EXPORT std::string getGameFilePath(const char* path);
Expand Down

0 comments on commit f0dc072

Please sign in to comment.