-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathisxSQLite.cpp
More file actions
367 lines (309 loc) · 10.1 KB
/
isxSQLite.cpp
File metadata and controls
367 lines (309 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
isxSQLite is an extension for InnerSpace (http://www.lavishsoft.com).
Copyright 2011-2016 isxGames.com (http://www.isxgames.com)
Permission to use the source code in this file is granted under the
Creative Commons Attribution 3.0 Unported (CC BY 3.0) license. Visit
http://creativecommons.org/licenses/by/3.0/ for a summary of what
rights are granted under this license.
*/
#pragma warning(disable : 4100)
#include "isxSQLite.h"
#include <delayimp.h>
#pragma comment(lib,"delayimp")
#ifdef USE_LIBISXGAMES
#pragma comment(lib, "isxGames")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "tidylib.lib")
#pragma comment(lib, "libeay32_lib.lib")
#pragma comment(lib, "ssleay32_lib.lib")
#pragma comment(lib, "zlibstat.lib")
#pragma comment(lib, "libcurl.lib")
#pragma comment(lib,"isxdk_md")
#else
#pragma comment(lib,"isxdk")
#endif
ISXPreSetup("isxSQLite",isxGamesExtension);
bool isxGamesExtension::Initialize(ISInterface *p_ISInterface)
{
pISInterface=p_ISInterface;
gExtensionLoading = true;
if (pISInterface == nullptr)
{
return false;
}
#ifdef USE_LIBISXGAMES
pISInterface->GetInnerSpacePath(ModulePath, sizeof(ModulePath)-1);
strcat(ModulePath, "\\Extensions\\");
#endif
/////////////
// Set some internally used class members
if (pExtension)
{
pExtension->pUIElementTLO = pISInterface->IsTopLevelObject("UIElement");
pExtension->pLGUIElementDT = pISInterface->FindLSType("lguielement");
}
//
/////////////
// Avoid letting people run the extension with an old version of InnerSpace
if (pISInterface->GetBuildNumber() < 5065)
{
printf("\arThis version of isxSQLite requires Inner Space build %d or later.\ax",5065);
if (!IsConsoleOpen())
{
// Open Console
pISInterface->ExecuteCommand("console toggle");
}
return false;
}
#ifdef USE_LIBISXGAMES
// isxSQLite now requires .NET 2.0/3.5
pISInterface->TryInitialize();
if (!pISInterface->IsAvailable())
{
printf("isxSQLite *REQURES* .NET 2.0 and 3.5 (latest versions). Please download these frameworks before using this extension.");
gDoUnloadExtension = true;
if (!IsConsoleOpen())
{
// Open Console
pISInterface->ExecuteCommand("console toggle");
}
return false;
}
#endif
// Register the extension
RegisterExtension();
// retrieve basic ISData types
// (NOTE: These variables are declared in libisxgames.h, not Globals.h)
// retrieve basic ISData types
pStringType = pISInterface->FindLSType("string");
pMutableStringType = pISInterface->FindLSType("mutablestring");
pWStringType = pISInterface->FindLSType("unistring");
pUniStringType = pISInterface->FindLSType("unistring");
pIntType = pISInterface->FindLSType("int");
pUIntType = pISInterface->FindLSType("uint");
pInt64Type = pISInterface->FindLSType("int64");
pInt64PtrType = pISInterface->FindLSType("int64ptr");
pBoolType = pISInterface->FindLSType("bool");
pFloatType = pISInterface->FindLSType("float");
pTimeType = pISInterface->FindLSType("time");
pByteType = pISInterface->FindLSType("byte");
pIntPtrType = pISInterface->FindLSType("intptr");
pBoolPtrType = pISInterface->FindLSType("boolptr");
pFloatPtrType = pISInterface->FindLSType("floatptr");
pFloat64Type = pISInterface->FindLSType("float64");
pFloat64PtrType = pISInterface->FindLSType("float64ptr");
pBytePtrType = pISInterface->FindLSType("byteptr");
pPoint3fType = pISInterface->FindLSType("point3f");
pIndexType = pISInterface->FindLSType("index");
pVectorType = pISInterface->FindLSType("index");
pMapType = pISInterface->FindLSType("collection");
pSetType = pISInterface->FindLSType("set");
isxGamesExtension::ConnectPulseService();
ConnectServices();
pExtension->RegisterExtDataTypes();
pExtension->RegisterExtTopLevelObjects();
// Register persistent class for .NET
isxSQLiteClass = pISInterface->RegisterPersistentClass("isxSQLite");
// Register Events
isxGames_onHTTPResponse = pISInterface->RegisterEvent("isxGames_onHTTPResponse");
isxSQLite_onErrorMsg = pISInterface->RegisterEvent("isxSQLite_onErrorMsg");
isxSQLite_onStatusMsg = pISInterface->RegisterEvent("isxSQLite_onStatusMsg");
// Be sure to 'detach' from any events that you attach to in the Shutdown routine
isxSQLite_onUpdateComplete = pISInterface->RegisterEvent("isxSQLite_onUpdateComplete");
pISInterface->AttachEventTarget(isxSQLite_onUpdateComplete,isxSQLitePostInitialize);
isxSQLite_onDoShutdown = pISInterface->RegisterEvent("isxSQLite_onDoShutdown");
pISInterface->AttachEventTarget(isxSQLite_onDoShutdown,isxSQLiteonDoShutdown);
//Open xml files
sprintf(XMLFileName,"%s\\isxSQLite.xml",ModulePath);
MainXMLFileID = pISInterface->OpenSettings(XMLFileName);
// Create Sets if they don't exist (is this necessary?)
unsigned int GeneralSetID = pISInterface->FindSet(MainXMLFileID,"General");
if (GeneralSetID == 0)
GeneralSetID = pISInterface->CreateSet(MainXMLFileID,"General");
// Process main xml file settings
ProcessMainXMLSettings();
Initialize2();
return true;
}
bool isxGamesExtension::Initialize2()
{
// When compiled in "Release" configuration (i.e., without libisxgames) the patcher is bypassed entirely. Therefore,
// the extension should continue with Post Initialization straight away at this point.
#ifdef USE_LIBISXGAMES
strcpy(ExtensionName,"isxSQLite");
strcpy(ExtensionMajorVersion, __isxSQLiteVersion);
gRunPatcherNow = true;
#else
isxSQLitePostInitialize(0,NULL,NULL);
#endif
return true;
}
// This fires once the event isxSQLite_onOKToLoad has been received.
void __cdecl isxSQLitePostInitialize(int argc, char *argv[], PLSOBJECT)
{
if (gExtensionLoadDone)
return;
pExtension->RegisterCommands();
pExtension->RegisterAliases();
pExtension->RegisterDataTypes();
pExtension->RegisterTopLevelObjects();
pExtension->RegisterServices();
pExtension->RegisterTriggers();
pExtension->RegisterDetours();
gExtensionLoadDone = true;
gExtensionLoading = false;
// Everything worked and we're good to go
VersionInfo verInfo;
printf("\n \n\atisxSQLite v%s\ax", verInfo.GetProductVersion().c_str());
return;
}
void __cdecl isxSQLiteonDoShutdown(int argc, char *argv[], PLSOBJECT)
{
gDoUnloadExtension = true;
return;
}
void isxGamesExtension::Shutdown()
{
if (gExtensionLoadDone)
{
DisconnectServices();
UnRegisterServices();
if (!gDidPreUnload)
{
UnRegisterTopLevelObjects();
UnRegisterDataTypes();
UnRegisterAliases();
UnRegisterCommands();
if (gDetoursActive)
UnRegisterDetours();
UnRegisterTriggers();
}
UnRegisterExtTopLevelObjects();
UnRegisterExtDataTypes();
}
// Close/Unload xml files
pISInterface->UnloadSet(MainXMLFileID);
// Clear arrays
FinalizeAllQueries();
FinalizeAllTables();
CloseAllDatabases();
FreeClear(gDatabases);
FreeClear(gQueries);
FreeClear(gTables);
pISInterface->DetachEventTarget(isxSQLite_onUpdateComplete,isxSQLitePostInitialize);
pISInterface->DetachEventTarget(isxSQLite_onDoShutdown,isxSQLiteonDoShutdown);
//////
pISInterface->InvalidatePersistentClass(isxSQLiteClass);
//////
if (!gUnloadingExtension)
printf("\n \n \n\atisxSQLite UNLOADED\ax");
gUnloadingExtension = true;
}
void isxGamesExtension::RegisterExtension()
{
VersionInfo verInfo;
unsigned int ExtensionSetGUID=pISInterface->GetExtensionSetGUID("isxSQLite");
if (!ExtensionSetGUID)
{
ExtensionSetGUID=pISInterface->CreateExtensionSet("isxSQLite");
if (!ExtensionSetGUID)
{
return;
}
}
pISInterface->SetSetting(ExtensionSetGUID,"Filename",ModuleFileName);
pISInterface->SetSetting(ExtensionSetGUID,"Path",ModulePath);
pISInterface->SetSetting(ExtensionSetGUID,"Version",verInfo.GetProductVersion().c_str());
}
void isxGamesExtension::RegisterCommands()
{
#define COMMAND(name,cmd,parse,hide) pISInterface->AddCommand(name,cmd,parse,hide);
#include "Commands.h"
#undef COMMAND
}
void isxGamesExtension::RegisterAliases()
{
// add any aliases
}
void isxGamesExtension::RegisterExtDataTypes()
{
#define DATATYPE(_class_,_variable_,_inherits_) _variable_ = new _class_; pISInterface->AddLSType(*_variable_); _variable_->SetInheritance(_inherits_);
#define EXT_DTYPES_ONLY
#include "DataTypeList.h"
#undef EXT_DTYPES_ONLY
#undef DATATYPE
}
void isxGamesExtension::RegisterDataTypes()
{
#define DATATYPE(_class_,_variable_,_inherits_) _variable_ = new _class_; pISInterface->AddLSType(*_variable_); _variable_->SetInheritance(_inherits_);
#include "DataTypeList.h"
#undef DATATYPE
// Set Persistant Classes for .NET scripts
pISInterface->SetPersistentClass(pisxSQLiteType,isxSQLiteClass);
}
void isxGamesExtension::RegisterTopLevelObjects()
{
#define TOPLEVELOBJECT(name,funcname) pISInterface->AddTopLevelObject(name,funcname);
#include "TopLevelObjects.h"
#undef TOPLEVELOBJECT
}
void isxGamesExtension::RegisterExtTopLevelObjects()
{
#define EXTTOPLEVELOBJECT(name,funcname) pISInterface->AddTopLevelObject(name,funcname);
#include "ExtTopLevelObjects.h"
#undef EXTTOPLEVELOBJECT
}
void isxGamesExtension::RegisterDetours()
{
return;
}
void isxGamesExtension::RegisterTriggers()
{
return;
}
void isxGamesExtension::UnRegisterCommands()
{
#define COMMAND(name,cmd,parse,hide) pISInterface->RemoveCommand(name);
#include "Commands.h"
#undef COMMAND
}
void isxGamesExtension::UnRegisterAliases()
{
// remove aliases
}
void isxGamesExtension::UnRegisterDataTypes()
{
#define DATATYPE(_class_,_variable_,_inherits_) pISInterface->RemoveLSType(*_variable_); delete _variable_;
#define IGNORE_EXT_DTYPES
#include "DataTypeList.h"
#undef IGNORE_EXT_DTYPES
#undef DATATYPE
}
void isxGamesExtension::UnRegisterExtDataTypes()
{
#define DATATYPE(_class_,_variable_,_inherits_) pISInterface->RemoveLSType(*_variable_); delete _variable_;
#define EXT_DTYPES_ONLY
#include "DataTypeList.h"
#undef EXT_DTYPES_ONLY
#undef DATATYPE
}
void isxGamesExtension::UnRegisterTopLevelObjects()
{
#define TOPLEVELOBJECT(name,funcname) pISInterface->RemoveTopLevelObject(name);
#include "TopLevelObjects.h"
#undef TOPLEVELOBJECT
}
void isxGamesExtension::UnRegisterExtTopLevelObjects()
{
#define EXTTOPLEVELOBJECT(name,funcname) pISInterface->RemoveTopLevelObject(name);
#include "ExtTopLevelObjects.h"
#undef EXTTOPLEVELOBJECT
}
void isxGamesExtension::UnRegisterDetours()
{
return;
}
void isxGamesExtension::UnRegisterTriggers()
{
return;
}