From 6de086e2e076f2c4e7f6e739a66aba07265d0204 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Fri, 15 Sep 2023 16:42:57 +1000 Subject: [PATCH] Support custom func_door and func_plat sounds on Q3A maps This adds FindFileInMapPack(), a very simple version of _MapInfo_FindArenaFile(). --- qcsrc/common/mapobjects/func/door.qc | 16 +++++++++++++++- qcsrc/common/mapobjects/func/plat.qc | 16 +++++++++++++++- qcsrc/server/main.qc | 26 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/qcsrc/common/mapobjects/func/door.qc b/qcsrc/common/mapobjects/func/door.qc index 418bdda9a..ba2e53d27 100644 --- a/qcsrc/common/mapobjects/func/door.qc +++ b/qcsrc/common/mapobjects/func/door.qc @@ -679,14 +679,28 @@ void door_init_shared(entity this) if (q3compat) { - // CPMA adds these fields for overriding the engine sounds + // CPMA adds these fields for overriding the Q3 default sounds string s = GetField_fullspawndata(this, "sound_start", true); string e = GetField_fullspawndata(this, "sound_end", true); if (s) this.noise2 = strzone(s); + else + { + // PK3s supporting Q3A sometimes include custom sounds at Q3 default paths + s = "sound/movers/doors/dr1_strt.wav"; + if (FindFileInMapPack(s)) + this.noise2 = s; + } + if (e) this.noise1 = strzone(e); + else + { + e = "sound/movers/doors/dr1_end.wav"; + if (FindFileInMapPack(e)) + this.noise1 = e; + } } // sound when door stops moving diff --git a/qcsrc/common/mapobjects/func/plat.qc b/qcsrc/common/mapobjects/func/plat.qc index 4e4aa632b..23b9eb5b1 100644 --- a/qcsrc/common/mapobjects/func/plat.qc +++ b/qcsrc/common/mapobjects/func/plat.qc @@ -98,14 +98,28 @@ spawnfunc(func_plat) if (q3compat) { - // CPMA adds these fields for overriding the engine sounds + // CPMA adds these fields for overriding the Q3 default sounds string s = GetField_fullspawndata(this, "sound_start", true); string e = GetField_fullspawndata(this, "sound_end", true); if (s) this.noise = strzone(s); + else + { + // PK3s supporting Q3A sometimes include custom sounds at Q3 default paths + s = "sound/movers/plats/pt1_strt.wav"; + if (FindFileInMapPack(s)) + this.noise = s; + } + if (e) this.noise1 = strzone(e); + else + { + e = "sound/movers/plats/pt1_end.wav"; + if (FindFileInMapPack(e)) + this.noise1 = e; + } } if(this.noise && this.noise != "") diff --git a/qcsrc/server/main.qc b/qcsrc/server/main.qc index 0d36ea47e..bee15d6cc 100644 --- a/qcsrc/server/main.qc +++ b/qcsrc/server/main.qc @@ -468,6 +468,32 @@ string GetField_fullspawndata(entity e, string f, ...) return v; } +/* +============= +FindFileInMapPack + +Returns the first matching VFS file path that exists in the current map's pack. +Returns string_null if no files match or the map isn't packaged. +============= +*/ +string FindFileInMapPack(string pattern) +{ + if (!checkextension("DP_QC_FS_SEARCH_PACKFILE")) + return string_null; + + string base_pack = whichpack(strcat("maps/", mapname, ".bsp")); + if (base_pack == "" || !base_pack) // this map isn't packaged or there was an error + return string_null; + + int glob = search_packfile_begin(pattern, true, true, base_pack); + if (glob < 0) + return string_null; + + string file = search_getfilename(glob, 0); + search_end(glob); + return file; +} + void WarpZone_PostInitialize_Callback() { // create waypoint links for warpzones -- 2.39.2