Skip to content

Commit db39fd4

Browse files
committed
cabi: pass NWNXCPlugin_InitInfo as pointer + reordered content
1 parent 9634383 commit db39fd4

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

include/nwnx_cplugin.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct NWNXCPlugin_InitInfo {
1212
/// Path to the NWNX4 user directory, where config files are stored and log files should be
1313
/// written.
1414
const char* nwnx_user_path;
15+
/// Path to the NWNX4 user directory, where nwnx4_controller.exe is located.
16+
const char* nwnx_install_path;
1517
/// Path to the NWN2 installation directory, where nwn2server.exe is located.
1618
const char* nwn2_install_path;
1719
/// Path to the NWN2 home folder, usually 'Documents\Neverwinter Nights 2'
@@ -20,8 +22,6 @@ struct NWNXCPlugin_InitInfo {
2022
/// Note: this value depends on the parameters list in nwnx.ini. If the server has not been
2123
/// started with -module or -moduledir, this value is set to NULL.
2224
const char* nwn2_module_path;
23-
/// Path to the NWNX4 user directory, where nwnx4_controller.exe is located.
24-
const char* nwnx_install_path;
2525
/// Function pointers to interact with the nwn2server instance
2626
const struct NWNXCPlugin_NWN2Hooks* nwn2_hooks;
2727
};
@@ -93,7 +93,7 @@ __declspec(dllexport) extern const uint32_t nwnxcplugin_abi_version;
9393
/// @return A user data pointer (to a struct or object) containing the plugin runtime data
9494
/// (prefer storing plugin data inside this struct rather than global variables). NULL if the
9595
/// plugin failed to be initialized.
96-
__declspec(dllexport) void* __cdecl NWNXCPlugin_New(NWNXCPlugin_InitInfo info);
96+
__declspec(dllexport) void* __cdecl NWNXCPlugin_New(const NWNXCPlugin_InitInfo* info);
9797

9898
//
9999
// OPTIONAL FUNCTIONS TO IMPLEMENT:

src/hook/CPlugin.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ CPlugin::CPlugin(HINSTANCE hDLL, const CPlugin::InitInfo& initInfo)
6464

6565
auto newPlugin
6666
= reinterpret_cast<CompatV1::NewPluginFn*>(GetProcAddress(hDLL, "NWNXCPlugin_New"));
67-
m_dll.newPlugin = [newPlugin](InitInfo info) {
67+
m_dll.newPlugin = [newPlugin](const InitInfo* info) {
6868
auto hooks = CompatV1::NWN2Hooks {
6969
.ExecuteScript = CompatV1::ExecuteScript,
7070
.ExecuteScriptEnhanced = CompatV1::ExecuteScriptEnhanced,
71-
.AddScriptParameterInt = info.nwn2_hooks->AddScriptParameterInt,
72-
.AddScriptParameterString = info.nwn2_hooks->AddScriptParameterString,
73-
.AddScriptParameterFloat = info.nwn2_hooks->AddScriptParameterFloat,
74-
.AddScriptParameterObject = info.nwn2_hooks->AddScriptParameterObject,
75-
.ClearScriptParams = info.nwn2_hooks->ClearScriptParams,
71+
.AddScriptParameterInt = info->nwn2_hooks->AddScriptParameterInt,
72+
.AddScriptParameterString = info->nwn2_hooks->AddScriptParameterString,
73+
.AddScriptParameterFloat = info->nwn2_hooks->AddScriptParameterFloat,
74+
.AddScriptParameterObject = info->nwn2_hooks->AddScriptParameterObject,
75+
.ClearScriptParams = info->nwn2_hooks->ClearScriptParams,
7676
};
7777
auto initInfo = CompatV1::InitInfo {
78-
.dll_path = info.dll_path,
79-
.nwnx_user_path = info.nwnx_user_path,
80-
.nwn2_install_path = info.nwn2_install_path,
81-
.nwn2_home_path = info.nwn2_home_path,
82-
.nwn2_module_path = info.nwn2_module_path,
83-
.nwnx_install_path = info.nwnx_install_path,
78+
.dll_path = info->dll_path,
79+
.nwnx_user_path = info->nwnx_user_path,
80+
.nwn2_install_path = info->nwn2_install_path,
81+
.nwn2_home_path = info->nwn2_home_path,
82+
.nwn2_module_path = info->nwn2_module_path,
83+
.nwnx_install_path = info->nwnx_install_path,
8484
.nwn2_hooks = &hooks,
8585
};
8686
return newPlugin(initInfo);
@@ -161,7 +161,7 @@ CPlugin::CPlugin(HINSTANCE hDLL, const CPlugin::InitInfo& initInfo)
161161
}
162162

163163
// Initialize instance
164-
m_instancePtr = m_dll.newPlugin(initInfo);
164+
m_instancePtr = m_dll.newPlugin(&initInfo);
165165
if (m_instancePtr == nullptr) {
166166
logger->Err("NWNXCPlugin_New returned null");
167167
return;

src/hook/CPlugin.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class CPlugin {
2929
struct InitInfo {
3030
const char* dll_path;
3131
const char* nwnx_user_path;
32+
const char* nwnx_install_path;
3233
const char* nwn2_install_path;
3334
const char* nwn2_home_path;
3435
const char* nwn2_module_path;
35-
const char* nwnx_install_path;
3636
const struct NWN2Hooks* nwn2_hooks;
3737
};
3838

@@ -118,7 +118,7 @@ class CPlugin {
118118
void* m_instancePtr = nullptr;
119119

120120
// clang-format off
121-
typedef void* (__cdecl NewPluginFn) (InitInfo info);
121+
typedef void* (__cdecl NewPluginFn) (const InitInfo* info);
122122
typedef void (__cdecl DeletePluginFn)(void* cplugin);
123123
typedef const char* (__cdecl GetInfoFn) ();
124124
typedef const char* (__cdecl GetVersionFn) ();

src/hook/hook.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,10 @@ void loadPlugins()
788788
CPlugin::InitInfo initInfo {
789789
.dll_path = pluginPathStr.c_str(),
790790
.nwnx_user_path = nwnxUserDirStr.c_str(),
791+
.nwnx_install_path = nwnxInstallDirStr.c_str(),
791792
.nwn2_install_path = nwn2InstallDir.c_str(),
792793
.nwn2_home_path = nwn2HomeDir.c_str(),
793794
.nwn2_module_path = nwn2ModulePathCStr,
794-
.nwnx_install_path = nwnxInstallDirStr.c_str(),
795795
.nwn2_hooks = &hooks,
796796
};
797797

0 commit comments

Comments
 (0)