5
5
#include < cstring>
6
6
#include < string>
7
7
8
- #include " nwn2heap.h"
9
8
#include " ../misc/log.h"
9
+ #include " nwn2heap.h"
10
10
extern std::unique_ptr<LogNWNX> logger;
11
11
12
12
constexpr uint32_t NWN_DEFAULT_EXECUTESCRIPT_ENH_PARAMS_LEN = 32 ;
@@ -85,8 +85,8 @@ static int OriginalCNWSMsgAddr = 0;
85
85
int * GetPtrToCNWSMessage ()
86
86
{
87
87
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 );
90
90
return (int *)(ptr + 0x10020 );
91
91
}
92
92
@@ -97,14 +97,13 @@ void ApplyScriptCNWSMessage()
97
97
static unsigned char * scriptCNWSMsg;
98
98
static bool isInit = false ;
99
99
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 );
108
107
109
108
scriptCNWSMsg[0 ] = 0xC0 ;
110
109
scriptCNWSMsg[1 ] = 0x42 ;
@@ -118,44 +117,44 @@ void ApplyScriptCNWSMessage()
118
117
((uint32_t *)scriptCNWSMsg)[2 ] = 0x80 ;
119
118
((uint32_t *)scriptCNWSMsg)[3 ] = 0x0 ;
120
119
121
-
122
120
((uint32_t *)scriptCNWSMsg)[4 ] = (int )Msg2;
123
121
((uint32_t *)scriptCNWSMsg)[5 ] = 0x80 ;
124
122
((uint32_t *)scriptCNWSMsg)[6 ] = 0 ;
125
123
((uint32_t *)scriptCNWSMsg)[7 ] = 0 ;
126
124
127
125
scriptCNWSMsg[0x20 ] = 0 ;
128
126
129
-
130
- ((uint32_t *)scriptCNWSMsg)[9 ] = 0x0 ;
127
+ ((uint32_t *)scriptCNWSMsg)[9 ] = 0x0 ;
131
128
((uint32_t *)scriptCNWSMsg)[0xa ] = 0x0 ;
132
129
((uint32_t *)scriptCNWSMsg)[0xb ] = 0x0 ;
133
130
((uint32_t *)scriptCNWSMsg)[0xc ] = 0x0 ;
134
131
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 ;
138
135
((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 ;
142
139
}
143
140
144
- if (scriptCNWSMsg != NULL )
141
+ if (scriptCNWSMsg != NULL )
145
142
*ptrToCNWSMessage = (int )(scriptCNWSMsg);
146
143
}
147
144
148
145
void RestoreOriginalCNWSMessage ()
149
146
{
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 ) {
153
149
int * ptrToCNWSMessage = GetPtrToCNWSMessage ();
154
- *ptrToCNWSMessage = OriginalCNWSMsgAddr;
150
+ *ptrToCNWSMessage = OriginalCNWSMsgAddr;
155
151
}
156
152
}
157
153
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)
159
158
{
160
159
logger->Trace (" ExecuteScript %s, %lu" , sScript , oTarget);
161
160
0 commit comments