Skip to content

Commit 822fda3

Browse files
committed
bass: load plugins if they exist
1 parent b32df51 commit 822fda3

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

source/detours.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ namespace Detour
105105
}
106106

107107
#ifdef SYSTEM_LINUX
108+
#define DLL_PREEXTENSION "lib"
109+
#define LIBRARY_EXTENSION ".so"
108110
#if ARCHITECTURE_IS_X86
109111
#define DLL_EXTENSION "_srv.so"
110112
#define DETOUR_SYMBOL_ID 0
@@ -113,7 +115,9 @@ namespace Detour
113115
#define DETOUR_SYMBOL_ID 1
114116
#endif
115117
#else
118+
#define DLL_PREEXTENSION ""
116119
#define DLL_EXTENSION ".dll"
120+
#define LIBRARY_EXTENSION ".dll"
117121
#if ARCHITECTURE_IS_X86
118122
#define DETOUR_SYMBOL_ID 2
119123
#else

source/modules/bass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ void CBassModule::Init(CreateInterfaceFn* appfn, CreateInterfaceFn* gamefn)
426426

427427
gGModAudio = g_pGModAudio;
428428
gGModAudio->Init(*appfn);
429+
gGModAudio->LoadPlugin("bassenc");
430+
gGModAudio->LoadPlugin("bassenc_opus");
431+
gGModAudio->LoadPlugin("bassenc_mp3");
432+
gGModAudio->LoadPlugin("bassenc_ogg");
429433
// Always use our own Interface to not create funnies with the engine.
430434
}
431435

source/sourcesdk/IGmod_Audio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ abstract_class IGMod_Audio
9696
virtual const char* GetErrorString( int ) = 0;
9797
// HolyLib specific ones
9898
virtual unsigned long GetVersion() = 0; // Returns bass version
99+
virtual bool LoadPlugin(const char* pluginName) = 0;
99100
};
100101

101102
#undef CALLBACK // Solves another error with minwindef.h

source/sourcesdk/cgmod_audio.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
#include <tier2/tier2.h>
88
#include <filesystem.h>
99
#include "Platform.hpp"
10+
#include <detours.h>
1011

1112
// memdbgon must be the last include file in a .cpp file!!!
1213
#include "tier0/memdbgon.h"
1314

15+
// Set on interface init allowing us to possibly use newer features if available
16+
static bool g_bUsesLatestBass = false;
17+
1418
const char* g_BASSErrorStrings[] = {
1519
"BASS_OK",
1620
"BASS_ERROR_MEM",
@@ -206,7 +210,6 @@ CGMod_Audio::~CGMod_Audio()
206210

207211
}
208212

209-
static bool g_bUsesLatestBass = false;
210213
bool CGMod_Audio::Init(CreateInterfaceFn interfaceFactory)
211214
{
212215
ConnectTier1Libraries( &interfaceFactory, 1 );
@@ -265,6 +268,10 @@ bool CGMod_Audio::Init(CreateInterfaceFn interfaceFactory)
265268

266269
const char* CGMod_Audio::GetErrorString(int id)
267270
{
271+
constexpr int totalErrors = sizeof(g_BASSErrorStrings) / sizeof(const char*);
272+
if (0 > id || id >= totalErrors)
273+
return "BASS_ERROR_UNKNOWN";
274+
268275
const char* error = g_BASSErrorStrings[id];
269276
if (error) {
270277
return error;
@@ -452,6 +459,43 @@ IGModAudioChannel* CGMod_Audio::PlayFile(const char* filePath, const char* flags
452459
return (IGModAudioChannel*)new CGModAudioChannel(stream, true, filePath);
453460
}
454461

462+
bool CGMod_Audio::LoadPlugin(const char* pluginName)
463+
{
464+
if (m_pLoadedPlugins.find(pluginName) != m_pLoadedPlugins.end())
465+
return true;
466+
467+
char pLibraryFolder[MAX_PATH];
468+
g_pFullFileSystem->RelativePathToFullPath("bin/", "BASE_PATH", pLibraryFolder, sizeof(pLibraryFolder));
469+
470+
Msg("Bass Path: %s\n", (const char*)BASS_GetConfigPtr(BASS_CONFIG_FILENAME));
471+
Msg("Base path: %s\n", pLibraryFolder);
472+
473+
std::string pPluginPath = pLibraryFolder;
474+
pPluginPath.append(DLL_PREEXTENSION);
475+
pPluginPath.append(pluginName);
476+
pPluginPath.append(LIBRARY_EXTENSION);
477+
478+
Msg("Plugin path: %s\n", pPluginPath.c_str());
479+
480+
HPLUGIN plugin = BASS_PluginLoad(pPluginPath.c_str(), 0);
481+
if (!plugin)
482+
{
483+
int nError = BASS_ErrorGetCode();
484+
if (nError != BASS_ERROR_FILEOPEN) {
485+
Warning(PROJECT_NAME " CGMod_Audio: Failed to load plugin %s (%s)\n", pluginName, GetErrorString(nError));
486+
} else {
487+
DevMsg(PROJECT_NAME " CGMod_Audio: Skipping plugin load %s since it was never installed\n", pluginName);
488+
}
489+
490+
return false;
491+
}
492+
493+
m_pLoadedPlugins[pluginName] = plugin;
494+
DevMsg(PROJECT_NAME " CGMod_Audio: Successfully loaded plugin %s\n", pluginName);
495+
496+
return true;
497+
}
498+
455499
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CGMod_Audio, IGMod_Audio, "IGModAudio001", g_CGMod_Audio);
456500

457501

source/sourcesdk/cgmod_audio.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "vaudio/ivaudio.h"
77
#include "IGmod_Audio.h"
88
#include "bass.h"
9+
#include <unordered_map>
910

1011
class CBassAudioStream : IBassAudioStream
1112
{
@@ -98,6 +99,9 @@ class CGMod_Audio : public IGMod_Audio
9899
virtual const char* GetErrorString( int );
99100
// HolyLib
100101
virtual unsigned long GetVersion();
102+
virtual bool LoadPlugin(const char* pluginName);
103+
private:
104+
std::unordered_map<std::string, HPLUGIN> m_pLoadedPlugins;
101105
};
102106

103107
extern const char* g_BASSErrorStrings[];

0 commit comments

Comments
 (0)