Skip to content

Commit b5dfc27

Browse files
committed
Format
1 parent 17dcb96 commit b5dfc27

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

include/nwnx_cplugin.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ struct NWNXCPlugin_InitInfo {
3131
/// has been successfully executed.
3232
/// @param bReplaceCNWSMsg If true, the CNWSMessage will be switched for this call
3333
/// avoiding issues if used during message construction
34-
typedef void(ExecuteScriptFn)(const char* sScript, uint32_t oTarget, bool* outExecuted, bool bReplaceCNWSMsg);
34+
typedef void(ExecuteScriptFn)(const char* sScript,
35+
uint32_t oTarget,
36+
bool* outExecuted,
37+
bool bReplaceCNWSMsg);
3538
/// Bound to NWScript ExecuteScriptEnhanced function
3639
/// @param outExecuted If not null, the bool will be set to true if the script
3740
/// has been successfully executed. This is used to differenciate between a

src/hook/scriptManagement.cpp

+25-26
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <cstring>
66
#include <string>
77

8-
#include "nwn2heap.h"
98
#include "../misc/log.h"
9+
#include "nwn2heap.h"
1010
extern std::unique_ptr<LogNWNX> logger;
1111

1212
constexpr uint32_t NWN_DEFAULT_EXECUTESCRIPT_ENH_PARAMS_LEN = 32;
@@ -85,8 +85,8 @@ static int OriginalCNWSMsgAddr = 0;
8585
int* GetPtrToCNWSMessage()
8686
{
8787
int ptr = *(int*)OFFS_g_pAppManager;
88-
ptr = *(int*)(ptr + 4);
89-
ptr = *(int*)(ptr + 4);
88+
ptr = *(int*)(ptr + 4);
89+
ptr = *(int*)(ptr + 4);
9090
return (int*)(ptr + 0x10020);
9191
}
9292

@@ -97,14 +97,13 @@ void ApplyScriptCNWSMessage()
9797
static unsigned char* scriptCNWSMsg;
9898
static bool isInit = false;
9999

100-
if (!isInit)
101-
{
102-
OriginalCNWSMsgAddr = *ptrToCNWSMessage;
103-
NWN2_HeapMgr *pHeapMgr = NWN2_HeapMgr::Instance();
104-
NWN2_Heap *pHeap = pHeapMgr->GetDefaultHeap();
105-
scriptCNWSMsg = (unsigned char*)pHeap->Allocate(0x58);
106-
unsigned char* Msg1 = (unsigned char*)pHeap->Allocate(0x80);
107-
unsigned char* Msg2 = (unsigned char*)pHeap->Allocate(0x80);
100+
if (!isInit) {
101+
OriginalCNWSMsgAddr = *ptrToCNWSMessage;
102+
NWN2_HeapMgr* pHeapMgr = NWN2_HeapMgr::Instance();
103+
NWN2_Heap* pHeap = pHeapMgr->GetDefaultHeap();
104+
scriptCNWSMsg = (unsigned char*)pHeap->Allocate(0x58);
105+
unsigned char* Msg1 = (unsigned char*)pHeap->Allocate(0x80);
106+
unsigned char* Msg2 = (unsigned char*)pHeap->Allocate(0x80);
108107

109108
scriptCNWSMsg[0] = 0xC0;
110109
scriptCNWSMsg[1] = 0x42;
@@ -118,44 +117,44 @@ void ApplyScriptCNWSMessage()
118117
((uint32_t*)scriptCNWSMsg)[2] = 0x80;
119118
((uint32_t*)scriptCNWSMsg)[3] = 0x0;
120119

121-
122120
((uint32_t*)scriptCNWSMsg)[4] = (int)Msg2;
123121
((uint32_t*)scriptCNWSMsg)[5] = 0x80;
124122
((uint32_t*)scriptCNWSMsg)[6] = 0;
125123
((uint32_t*)scriptCNWSMsg)[7] = 0;
126124

127125
scriptCNWSMsg[0x20] = 0;
128126

129-
130-
((uint32_t*)scriptCNWSMsg)[9] = 0x0;
127+
((uint32_t*)scriptCNWSMsg)[9] = 0x0;
131128
((uint32_t*)scriptCNWSMsg)[0xa] = 0x0;
132129
((uint32_t*)scriptCNWSMsg)[0xb] = 0x0;
133130
((uint32_t*)scriptCNWSMsg)[0xc] = 0x0;
134131

135-
((uint32_t*)scriptCNWSMsg)[0xd] = 0x0;
136-
((uint32_t*)scriptCNWSMsg)[0xe] = 0x0;
137-
((uint32_t*)scriptCNWSMsg)[0xf] = 0x0;
132+
((uint32_t*)scriptCNWSMsg)[0xd] = 0x0;
133+
((uint32_t*)scriptCNWSMsg)[0xe] = 0x0;
134+
((uint32_t*)scriptCNWSMsg)[0xf] = 0x0;
138135
((uint32_t*)scriptCNWSMsg)[0x10] = 0x0;
139-
scriptCNWSMsg[0x44] = 0x0;
140-
scriptCNWSMsg[0x45] = 0x0;
141-
isInit = true;
136+
scriptCNWSMsg[0x44] = 0x0;
137+
scriptCNWSMsg[0x45] = 0x0;
138+
isInit = true;
142139
}
143140

144-
if(scriptCNWSMsg != NULL)
141+
if (scriptCNWSMsg != NULL)
145142
*ptrToCNWSMessage = (int)(scriptCNWSMsg);
146143
}
147144

148145
void RestoreOriginalCNWSMessage()
149146
{
150-
//Be sure to not restore before saving the Original CNWSMsg
151-
if(OriginalCNWSMsgAddr != 0)
152-
{
147+
// Be sure to not restore before saving the Original CNWSMsg
148+
if (OriginalCNWSMsgAddr != 0) {
153149
int* ptrToCNWSMessage = GetPtrToCNWSMessage();
154-
*ptrToCNWSMessage = OriginalCNWSMsgAddr;
150+
*ptrToCNWSMessage = OriginalCNWSMsgAddr;
155151
}
156152
}
157153

158-
void ExecuteScript(const char* sScript, NWN::OBJECTID oTarget, bool* outExecuted, bool bReplaceCNWSMsg)
154+
void ExecuteScript(const char* sScript,
155+
NWN::OBJECTID oTarget,
156+
bool* outExecuted,
157+
bool bReplaceCNWSMsg)
159158
{
160159
logger->Trace("ExecuteScript %s, %lu", sScript, oTarget);
161160

src/hook/scriptManagement.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
namespace NWScript {
1111

1212
extern "C" {
13-
void ExecuteScript(const char* sScript, NWN::OBJECTID oTarget, bool* outExecuted = NULL, bool bReplaceCNWSMsg = false);
13+
void ExecuteScript(const char* sScript,
14+
NWN::OBJECTID oTarget,
15+
bool* outExecuted = NULL,
16+
bool bReplaceCNWSMsg = false);
1417
int32_t ExecuteScriptEnhanced(const char* sScriptName,
1518
NWN::OBJECTID oTarget,
1619
bool bClearParams,
17-
bool* outExecuted = NULL,
20+
bool* outExecuted = NULL,
1821
bool bReplaceCNWSMsg = false);
1922
void AddScriptParameterInt(int32_t nParam);
2023
void AddScriptParameterString(const char* sParam);

src/plugins/xp_example_cplugin/cplugin_example.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ NWNXCPlugin_GetInt(void* cplugin, const char* sFunction, const char* sParam1, in
129129
} else if (function == "TEST_EXECUTESCRIPTENHBAD") {
130130
constexpr uint32_t OBJID_MODULE = 0;
131131
bool executed = true;
132-
auto res
133-
= plugin->hooks.ExecuteScriptEnhanced("euqsgdihohcqsc", OBJID_MODULE, true, &executed, false);
132+
auto res = plugin->hooks.ExecuteScriptEnhanced("euqsgdihohcqsc", OBJID_MODULE, true,
133+
&executed, false);
134134
if (executed)
135135
res -= 1000;
136136
return res;

0 commit comments

Comments
 (0)