@@ -49,6 +49,12 @@ struct InitInfo {
49
49
};
50
50
51
51
typedef void *(__cdecl NewPluginFn)(InitInfo info);
52
+ typedef void (__cdecl GetStringFn)(void * cplugin,
53
+ const char * sFunction ,
54
+ const char * sParam1 ,
55
+ int32_t nParam2,
56
+ char * result,
57
+ size_t resultSize);
52
58
53
59
} // namespace CompatV1
54
60
@@ -66,6 +72,8 @@ CPlugin::CPlugin(HINSTANCE hDLL, const CPlugin::InitInfo& initInfo)
66
72
= reinterpret_cast <CompatV1::NewPluginFn*>(GetProcAddress (hDLL, " NWNXCPlugin_New" ));
67
73
m_dll.newPlugin = [newPlugin](const InitInfo* info) {
68
74
auto hooks = CompatV1::NWN2Hooks {
75
+ // v2 added 1 additional parameter for ExecuteScript & ExecuteScriptEnhanced (see
76
+ // commit edc229f)
69
77
.ExecuteScript = CompatV1::ExecuteScript,
70
78
.ExecuteScriptEnhanced = CompatV1::ExecuteScriptEnhanced,
71
79
.AddScriptParameterInt = info->nwn2_hooks ->AddScriptParameterInt ,
@@ -74,6 +82,7 @@ CPlugin::CPlugin(HINSTANCE hDLL, const CPlugin::InitInfo& initInfo)
74
82
.AddScriptParameterObject = info->nwn2_hooks ->AddScriptParameterObject ,
75
83
.ClearScriptParams = info->nwn2_hooks ->ClearScriptParams ,
76
84
};
85
+ // v2 reordered InitInfo members
77
86
auto initInfo = CompatV1::InitInfo {
78
87
.dll_path = info->dll_path ,
79
88
.nwnx_user_path = info->nwnx_user_path ,
@@ -83,9 +92,20 @@ CPlugin::CPlugin(HINSTANCE hDLL, const CPlugin::InitInfo& initInfo)
83
92
.nwnx_install_path = info->nwnx_install_path ,
84
93
.nwn2_hooks = &hooks,
85
94
};
95
+ // v2 is passing initInfo as a const pointer
86
96
return newPlugin (initInfo);
87
97
};
88
98
99
+ // v2 changed NWNXCPlugin_GetString behaviour: now NWNXCPlugin_GetString must return the
100
+ // result string pointer, to avoid unnecessary strcpy from a stored value into `result`
101
+ auto getString = reinterpret_cast <CompatV1::GetStringFn*>(
102
+ GetProcAddress (hDLL, " NWNXCPlugin_GetString" ));
103
+ m_dll.getString = [getString](void * cplugin, const char * sFunction , const char * sParam1 ,
104
+ int32_t nParam2, char * result, size_t resultSize) {
105
+ getString (cplugin, sFunction , sParam1 , nParam2, result, resultSize);
106
+ return result;
107
+ };
108
+
89
109
// clang-format off
90
110
m_dll.deletePlugin = reinterpret_cast <DeletePluginFn*>(GetProcAddress (hDLL, " NWNXCPlugin_Delete" ));
91
111
m_dll.getInfo = reinterpret_cast <GetInfoFn*>( GetProcAddress (hDLL, " NWNXCPlugin_GetInfo" ));
@@ -95,7 +115,6 @@ CPlugin::CPlugin(HINSTANCE hDLL, const CPlugin::InitInfo& initInfo)
95
115
m_dll.setInt = reinterpret_cast <SetIntFn*>( GetProcAddress (hDLL, " NWNXCPlugin_SetInt" ));
96
116
m_dll.getFloat = reinterpret_cast <GetFloatFn*>( GetProcAddress (hDLL, " NWNXCPlugin_GetFloat" ));
97
117
m_dll.setFloat = reinterpret_cast <SetFloatFn*>( GetProcAddress (hDLL, " NWNXCPlugin_SetFloat" ));
98
- m_dll.getString = reinterpret_cast <GetStringFn*>( GetProcAddress (hDLL, " NWNXCPlugin_GetString" ));
99
118
m_dll.setString = reinterpret_cast <SetStringFn*>( GetProcAddress (hDLL, " NWNXCPlugin_SetString" ));
100
119
m_dll.getGFFSize = reinterpret_cast <GetGFFSizeFn*>( GetProcAddress (hDLL, " NWNXCPlugin_GetGFFSize" ));
101
120
m_dll.getGFF = reinterpret_cast <GetGFFFn*>( GetProcAddress (hDLL, " NWNXCPlugin_GetGFF" ));
0 commit comments