From 38f17ce692c8b8f13024ef8c0a1b5e41e2a4572d Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 26 Aug 2019 13:33:08 +1000 Subject: [PATCH] don't use vector for GetPluginOptions (usable with other languages now) --- .../plugins/DivaSound/src/PluginConfigApi.h | 6 ++++++ .../source/plugins/DivaSound/src/dllmain.cpp | 18 +++++++++--------- .../source/plugins/Launcher/PluginConfig.h | 10 +++++++--- .../source/plugins/Launcher/PluginConfigApi.h | 6 ++++++ .../source/plugins/Launcher/framework.h | 2 +- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/source-code/source/plugins/DivaSound/src/PluginConfigApi.h b/source-code/source/plugins/DivaSound/src/PluginConfigApi.h index 3f0923e..d9f6a66 100644 --- a/source-code/source/plugins/DivaSound/src/PluginConfigApi.h +++ b/source-code/source/plugins/DivaSound/src/PluginConfigApi.h @@ -144,4 +144,10 @@ namespace PluginConfig ConfigType cfgType; void* data; }; + + struct PluginConfigArray + { + int len; + PluginConfigOption* options; + }; } \ No newline at end of file diff --git a/source-code/source/plugins/DivaSound/src/dllmain.cpp b/source-code/source/plugins/DivaSound/src/dllmain.cpp index 08356ad..1ab0c2e 100644 --- a/source-code/source/plugins/DivaSound/src/dllmain.cpp +++ b/source-code/source/plugins/DivaSound/src/dllmain.cpp @@ -414,13 +414,13 @@ BOOL APIENTRY DllMain(HMODULE hModule, using namespace PluginConfig; -std::vector config = { - PluginConfigOption{ CONFIG_DROPDOWN_TEXT, new PluginConfigDropdownTextData{L"backend", L"general", CONFIG_FILE, L"Backend:", L"Sets the audio output protocol.", L"WASAPI", std::vector({ L"WASAPI", L"WASAPI_Exclusive" }), true, false } }, - PluginConfigOption{ CONFIG_DROPDOWN_NUMBER, new PluginConfigDropdownNumberData{ L"channels", L"general", CONFIG_FILE, L"Channels:", L"Sets the number of channels.", 2, std::vector({ 2, 4 }), false } }, - PluginConfigOption{ CONFIG_DROPDOWN_NUMBER, new PluginConfigDropdownNumberData{ L"bit_depth", L"general", CONFIG_FILE, L"Bit Depth:", L"Sets the audio sample format.\n(32 uses floating point samples)", 16, std::vector({ 16, 24, 32 }), false } }, - PluginConfigOption{ CONFIG_NUMERIC, new PluginConfigNumericData{ L"buffer_size", L"buffer", CONFIG_FILE, L"Target Buffer Size:", L"Sets the target buffer size in ms.\nWASAPI will often ignore this and adapt to your hardware config automatically.", 10, 1, 100 } }, - PluginConfigOption{ CONFIG_NUMERIC, new PluginConfigNumericData{ L"periods", L"buffer", CONFIG_FILE, L"Buffer Periods:", L"Sets how often the buffer should be filled.\nFewer periods usually allows for lower latency, but lowering this may cause issues.", 2, 1, 8 } }, - PluginConfigOption{ CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"alternate_init", L"general", CONFIG_FILE, L"Use new init", L"Use the full initialisation replacement.\nTry unchecking this if DivaSound seems to cause crashes.", true } }, +PluginConfigOption config[] = { + { CONFIG_DROPDOWN_TEXT, new PluginConfigDropdownTextData{L"backend", L"general", CONFIG_FILE, L"Backend:", L"Sets the audio output protocol.", L"WASAPI", std::vector({ L"WASAPI", L"WASAPI_Exclusive" }), true, false } }, + { CONFIG_DROPDOWN_NUMBER, new PluginConfigDropdownNumberData{ L"channels", L"general", CONFIG_FILE, L"Channels:", L"Sets the number of channels.", 2, std::vector({ 2, 4 }), false } }, + { CONFIG_DROPDOWN_NUMBER, new PluginConfigDropdownNumberData{ L"bit_depth", L"general", CONFIG_FILE, L"Bit Depth:", L"Sets the audio sample format.\n(32 uses floating point samples)", 16, std::vector({ 16, 24, 32 }), false } }, + { CONFIG_NUMERIC, new PluginConfigNumericData{ L"buffer_size", L"buffer", CONFIG_FILE, L"Target Buffer Size:", L"Sets the target buffer size in ms.\nWASAPI will often ignore this and adapt to your hardware config automatically.", 10, 1, 100 } }, + { CONFIG_NUMERIC, new PluginConfigNumericData{ L"periods", L"buffer", CONFIG_FILE, L"Buffer Periods:", L"Sets how often the buffer should be filled.\nFewer periods usually allows for lower latency, but lowering this may cause issues.", 2, 1, 8 } }, + { CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"alternate_init", L"general", CONFIG_FILE, L"Use new init", L"Use the full initialisation replacement.\nTry unchecking this if DivaSound seems to cause crashes.", true } }, }; extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) @@ -433,7 +433,7 @@ extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void) return L"DivaSound Plugin by somewhatlurker\n\nDivaSound replaces the game's original audio output,\nimproving device support and adding configurable options."; } -extern "C" __declspec(dllexport) std::vector GetPluginOptions(void) +extern "C" __declspec(dllexport) PluginConfigArray GetPluginOptions(void) { - return config; + return PluginConfigArray{ _countof(config), config }; } \ No newline at end of file diff --git a/source-code/source/plugins/Launcher/PluginConfig.h b/source-code/source/plugins/Launcher/PluginConfig.h index 5b8fe56..0a3170c 100644 --- a/source-code/source/plugins/Launcher/PluginConfig.h +++ b/source-code/source/plugins/Launcher/PluginConfig.h @@ -40,12 +40,16 @@ namespace PluginConfig } } - std::vector GetConfigOptionVec(std::vector &in) + std::vector GetConfigOptionVec(PluginConfigArray &in) { std::vector outvec; - for (PluginConfigOption &opt : in) + for (int i = 0; i < in.len; i++) { - outvec.push_back(GetConfigOption(opt)); + // basic check for validity + if (in.options[i].data == nullptr) + break; + + outvec.push_back(GetConfigOption(in.options[i])); } return outvec; } diff --git a/source-code/source/plugins/Launcher/PluginConfigApi.h b/source-code/source/plugins/Launcher/PluginConfigApi.h index 3f0923e..d9f6a66 100644 --- a/source-code/source/plugins/Launcher/PluginConfigApi.h +++ b/source-code/source/plugins/Launcher/PluginConfigApi.h @@ -144,4 +144,10 @@ namespace PluginConfig ConfigType cfgType; void* data; }; + + struct PluginConfigArray + { + int len; + PluginConfigOption* options; + }; } \ No newline at end of file diff --git a/source-code/source/plugins/Launcher/framework.h b/source-code/source/plugins/Launcher/framework.h index 95a4613..c82d5cf 100644 --- a/source-code/source/plugins/Launcher/framework.h +++ b/source-code/source/plugins/Launcher/framework.h @@ -303,7 +303,7 @@ std::vector LoadPlugins() auto nameFunc = (LPCWSTR(*)())GetProcAddress(thisplugin.handle, "GetPluginName"); auto descFunc = (LPCWSTR(*)())GetProcAddress(thisplugin.handle, "GetPluginDescription"); - auto optsFunc = (std::vector(*)())GetProcAddress(thisplugin.handle, "GetPluginOptions"); + auto optsFunc = (PluginConfig::PluginConfigArray(*)())GetProcAddress(thisplugin.handle, "GetPluginOptions"); if (nameFunc != NULL) thisplugin.name = nameFunc();