-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
490 lines (398 loc) · 14.8 KB
/
main.cpp
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
#include "nvse/PluginAPI.h"
#include "nvse/CommandTable.h"
#include "nvse/GameAPI.h"
#include "nvse/ParamInfos.h"
#include "nvse/GameObjects.h"
#include "file_addon.h"
#include <string>
//NoGore is unsupported in this fork
#ifndef RegisterScriptCommand
#define RegisterScriptCommand(name) nvse->RegisterCommand(&kCommandInfo_ ##name);
#endif
IDebugLog gLog("knvse_jsongenerator.log");
PluginHandle g_pluginHandle = kPluginHandle_Invalid;
NVSEMessagingInterface* g_messagingInterface;
NVSEInterface* g_nvseInterface;
NVSECommandTableInterface* g_cmdTable;
NVSEArrayVarInterface* dataArr;
const CommandInfo* g_TFC;
typedef void (*PF)();
std::map<std::string, PF> defined_functions;
static ParamInfo kParams_OneString_ThreeOptionalStringsFiveOptionalInts[9] =
{
{ "string", kParamType_String, 0 },
{ "string", kParamType_String, 1 },
{ "string", kParamType_String, 1 },
{ "string", kParamType_String, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
};
static ParamInfo kParams_OneOptionalString_FourOptionalInts[5] =
{
{ "string", kParamType_String, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
};
static ParamInfo kParams_FourOptionalInts[4] =
{
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
};
static ParamInfo kParams_FiveOptionalInts[5] =
{
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
{ "int", kParamType_Integer, 1 },
};
static ParamInfo kParams_OneString_OneOptionalString[2] =
{
{ "string", kParamType_String, 0 },
{ "string", kParamType_String, 1 }
};
static ParamInfo kParams_OneString_OneOptionalStringOneOptionalInt[3] =
{
{ "string", kParamType_String, 0 },
{ "string", kParamType_String, 1 },
{ "int", kParamType_Integer, 1 },
};
static ParamInfo kParams_OneString_OneOptionalInt[2] =
{
{ "string", kParamType_String, 0 },
{ "int", kParamType_Integer, 1 },
};
#if RUNTIME
NVSEScriptInterface* g_script;
#endif
// This is a message handler for nvse events
// With this, plugins can listen to messages such as whenever the game loads
void MessageHandler(NVSEMessagingInterface::Message* msg)
{
switch (msg->type)
{
case NVSEMessagingInterface::kMessage_DeferredInit:
_MESSAGE("kMessage_DeferredInit TEST");
break;
case NVSEMessagingInterface::kMessage_PostLoad:
_MESSAGE("kMessage_PostLoad TEST");
break;
default:
break;
}
}
bool Cmd_knvse_generate_Execute(COMMAND_ARGS);
#if RUNTIME
//In here we define a script function
//Script functions must always follow the Cmd_FunctionName_Execute naming convention
bool Cmd_knvse_generate_Execute(COMMAND_ARGS)
{
_MESSAGE("Generating files");
char pref[0x1000];
std::string modIDX = "FF";
char typesfilename[0x1000] = "_";
char weapsfilename[0x1000] = "_";
int eWeaponType = 00;
int handGrip = 000;
int reloadAnim = 00;
int attackAnim = 00;
int reversed = 0;
if (ExtractArgs(EXTRACT_ARGS, &pref, &modIDX, &typesfilename, &weapsfilename, &eWeaponType, &handGrip, &reloadAnim, &attackAnim, &reversed))
{
if (modIDX == "FF")
{
Console_Print(FormatString("Generating for all: folders %s and %s", typesfilename, weapsfilename).c_str());
}
else {
Console_Print(FormatString("Generating for mod index %s, folders %s and %s", eWeaponType, typesfilename, weapsfilename).c_str());
}
processTypesAndWrite2(pref, modIDX, eWeaponType, handGrip, reloadAnim, attackAnim, reversed, typesfilename, weapsfilename);
}
return true;
}
#endif
DEFINE_COMMAND_PLUGIN(knvse_generate, "Generates .json files for all the weapons that fit into types - with parameters.", 0, 9, kParams_OneString_ThreeOptionalStringsFiveOptionalInts)
/// prefix, mod ID (hex), first folder (usually types), second folder (usually weapons), 4 weapon parameters, reversed or not (priority over options in .json)
bool Cmd_knvse_auto_Execute(COMMAND_ARGS);
#if RUNTIME
//In here we define a script function
//Script functions must always follow the Cmd_FunctionName_Execute naming convention
bool Cmd_knvse_auto_Execute(COMMAND_ARGS)
{
_MESSAGE("Generating files");
char typesfilename[0x1000] = "_";
if (ExtractArgs(EXTRACT_ARGS, &typesfilename))
{
readAutoTypes(typesfilename);
}
return true;
}
#endif
DEFINE_COMMAND_PLUGIN(knvse_auto, "AUTOMATICALLY Generates .json files for all the weapons that fit into types - with parameters.", 0, 1, kParams_OneString)
bool Cmd_knvse_getfolders_Execute(COMMAND_ARGS);
#if RUNTIME
//In here we define a script function
//Script functions must always follow the Cmd_FunctionName_Execute naming convention
bool Cmd_knvse_getfolders_Execute(COMMAND_ARGS)
{
_MESSAGE("Reading weapon data...");
PlayerCharacter* npc = g_thePlayer->GetSingleton();
Actor* actor = static_cast<Actor*>(npc);
auto* weap = actor->GetWeaponForm();
int eWeaponType = 00;
int handGrip = 000;
int reloadAnim = 00;
int attackAnim = 00;
weaponType weaparams = getWeaponData1(weap);
Console_Print(FormatString("Parameters: %d %d %d %d", weaparams.typeParams[0], weaparams.typeParams[1], weaparams.typeParams[2], weaparams.typeParams[3]).c_str());
if (ExtractArgs(EXTRACT_ARGS, &eWeaponType, &handGrip, &reloadAnim, &attackAnim)) {
if (eWeaponType == 00 && handGrip == 000 && reloadAnim == 00 && attackAnim == 00) {
vector<string> folders = matchAWeapon1(weaparams);
for (auto folder : folders) {
Console_Print(folder.c_str());
}
}
else {
Console_Print(FormatString("Input instead: %d %d %d %d", eWeaponType, handGrip, reloadAnim, attackAnim).c_str());
vector<string> folders = matchAWeapon1(weaparams, { eWeaponType, handGrip, reloadAnim, attackAnim });
for (auto folder : folders) {
Console_Print(folder.c_str());
}
}
}
return true;
}
#endif
DEFINE_COMMAND_PLUGIN(knvse_getfolders, "Prints folders suited for the equipped weapon", 0, 4, kParams_FourOptionalInts)
bool Cmd_knvse_generateone_Execute(COMMAND_ARGS);
#if RUNTIME
//In here we define a script function
//Script functions must always follow the Cmd_FunctionName_Execute naming convention
bool Cmd_knvse_generateone_Execute(COMMAND_ARGS)
{
_MESSAGE("Reading weapon data...");
PlayerCharacter* npc = g_thePlayer->GetSingleton();
string prefix = "aaa_";
int reversed = 0;
char folder[0x1000] = "_";
if (ExtractArgs(EXTRACT_ARGS, &prefix, &folder, &reversed))
{
Actor* actor = static_cast<Actor*>(npc);
auto* weap = actor->GetWeaponForm();
weaponType weaparams = getWeaponData1(weap);
nlohmann::json result = writeAweapon2(prefix, weap, reversed, folder);
Console_Print(FormatString("Writing in: %s .json", prefix + weaparams.fileModName + folder).c_str());
}
return true;
}
#endif
DEFINE_COMMAND_PLUGIN(knvse_generateone, "Writes a json for the equipped weapon", 0, 4, kParams_OneString_OneOptionalStringOneOptionalInt)
// Prefix, folder, reversed or not
bool Cmd_knvse_scan_Execute(COMMAND_ARGS);
#if RUNTIME
//In here we define a script function
//Script functions must always follow the Cmd_FunctionName_Execute naming convention
bool Cmd_knvse_scan_Execute(COMMAND_ARGS)
{
_MESSAGE("Reading weapon data...");
char folder[0x1000];
aniMap themap;
folderMap scanResult;
if (ExtractArgs(EXTRACT_ARGS, &folder)) {
scanResult.getParams(themap, folder);
for (auto data : scanResult.subMaps) {
Console_Print(("Reloads for " + data.type + ": " + data.Sreloads).c_str());
Console_Print(("Attacks for " + data.type + ": " + data.Sattacks).c_str());
}
Console_Print((to_string(scanResult.typeParams.size()) + " combination(s) total ").c_str());
}
return true;
}
#endif
DEFINE_COMMAND_PLUGIN(knvse_scan, "Scans folders for data", 0, 1, kParams_OneString)
bool Cmd_knvse_deepscan_Execute(COMMAND_ARGS);
#if RUNTIME
//In here we define a script function
//Script functions must always follow the Cmd_FunctionName_Execute naming convention
bool Cmd_knvse_deepscan_Execute(COMMAND_ARGS)
{
_MESSAGE("Reading weapon data...");
PlayerCharacter* npc = g_thePlayer->GetSingleton();
Actor* actor = static_cast<Actor*>(npc);
auto* weap = actor->GetWeaponForm();
int eWeaponType = 00;
int handGrip = 000;
int reloadAnim = 00;
int attackAnim = 00;
char moreIfnfo = 'f';
if (ExtractArgs(EXTRACT_ARGS, &moreIfnfo, &eWeaponType, &handGrip, &reloadAnim, &attackAnim)) {
map<string, map<string, vector<int>>> dataMap;
if (eWeaponType == 00 && handGrip == 000 && reloadAnim == 00 && attackAnim == 00) {
weaponType weaparams = getWeaponData1(weap);
Console_Print(FormatString("Parameters: %d %d %d %d", weaparams.typeParams[0], weaparams.typeParams[1], weaparams.typeParams[2], weaparams.typeParams[3]).c_str());
dataMap = DEEPscan(weaparams.typeParams);
} else {
dataMap = DEEPscan({ eWeaponType, handGrip, reloadAnim, attackAnim });
Console_Print(FormatString("Parameters: %d %d %d %d", eWeaponType, handGrip, reloadAnim, attackAnim).c_str());
}
for (auto folder : dataMap) {
if (moreIfnfo != 'a' && moreIfnfo != 'r') {
if (folder.second["matched"][0] != 0 && folder.second["matched"][1] != 0 && folder.second["matched"][3] != 0 && folder.second["matched"][4] != 0) {
Log1((folder.first + ": full match [" + to_string(folder.second["matched"][0]) + " " + to_string(folder.second["matched"][1]) + " " + to_string(folder.second["matched"][2]) + " " + to_string(folder.second["matched"][3]) + "] ").c_str());
Console_Print((folder.first + ": full match [" + to_string(folder.second["matched"][0]) + " " + to_string(folder.second["matched"][1]) + " " + to_string(folder.second["matched"][2]) + " " + to_string(folder.second["matched"][3]) + "] ").c_str());
}
}
if (moreIfnfo != 'a' && moreIfnfo != 'f') {
if (folder.second["reload"].size() > 0) {
string reloads;
for (auto reload : folder.second["reload"]) {
reloads += " " + to_string(reload);
}
Log1((folder.first + ": only reload, attacks: [" + reloads + "] ").c_str());
Console_Print((folder.first + ": only reload, attacks: [" + reloads + "] ").c_str());
}
}
if (moreIfnfo != 'r' && moreIfnfo != 'f') {
if (folder.second["attack"].size() > 0)
{
string attacks;
for (auto reload : folder.second["attack"]) {
attacks += " " + to_string(reload);
}
Console_Print((folder.first + ": only attack, reloads: [" + attacks + "] ").c_str());
Log1((folder.first + ": only attack, reloads: [" + attacks + "] ").c_str());
}
}
}
}
else Console_Print("f is full match only, a is attacks, r is reloads, anything else is all. The rest is four parameters");
return true;
}
#endif
DEFINE_COMMAND_PLUGIN(knvse_deepscan, "Scans all the folders for animations and looks for mathing parameters", 0, 5, kParams_OneOptionalString_FourOptionalInts)
bool Cmd_knvse_generatetypes_Execute(COMMAND_ARGS);
#if RUNTIME
//In here we define a script function
//Script functions must always follow the Cmd_FunctionName_Execute naming convention
bool Cmd_knvse_generatetypes_Execute(COMMAND_ARGS)
{
_MESSAGE("Reading weapon data...");
char folder[0x1000];
int many = 0;
aniMap themap;
folderMap scanResult;
if (ExtractArgs(EXTRACT_ARGS, &folder, &many)) {
if (many == 0) {
scanResult.getParams(themap, folder);
writeType(scanResult);
Console_Print(("Generated " + to_string(scanResult.typeParams.size()) + " types ").c_str());
}
else {
int numTypes = writeTypesFolders(folder);
Console_Print(("Generated many, " + to_string(numTypes) + " types ").c_str());
}
}
return true;
}
#endif
DEFINE_COMMAND_PLUGIN(knvse_generatetypes, "Generates types file for a folder", 0, 2, kParams_OneString_OneOptionalInt)
bool Cmd_knvse_generatelist_Execute(COMMAND_ARGS);
#if RUNTIME
//In here we define a script function
//Script functions must always follow the Cmd_FunctionName_Execute naming convention
bool Cmd_knvse_generatelist_Execute(COMMAND_ARGS)
{
_MESSAGE("Reading weapon data...");
char folder[0x1000];
string modID = "FF";
if (ExtractArgs(EXTRACT_ARGS, &folder, &modID)) {
writeWeapList(folder, modID);
Console_Print(FormatString("Writing weapons list of all with %s for a modID %s ",folder, modID).c_str());
}
return true;
}
#endif
DEFINE_COMMAND_PLUGIN(knvse_generatelist, "Generates weapons file for a folder", 0, 2, kParams_OneString_OneOptionalString)
bool NVSEPlugin_Query(const NVSEInterface* nvse, PluginInfo* info)
{
_MESSAGE("query");
// fill out the info structure
info->infoVersion = PluginInfo::kInfoVersion;
info->name = "MyFirstPlugin";
info->version = 2;
// version checks
if (nvse->nvseVersion < NVSE_VERSION_INTEGER)
{
_ERROR("NVSE version too old (got %08X expected at least %08X)", nvse->nvseVersion, NVSE_VERSION_INTEGER);
return false;
}
if (!nvse->isEditor)
{
if (nvse->runtimeVersion < RUNTIME_VERSION_1_4_0_525)
{
_ERROR("incorrect runtime version (got %08X need at least %08X)", nvse->runtimeVersion, RUNTIME_VERSION_1_4_0_525);
return false;
}
if (nvse->isNogore)
{
_ERROR("NoGore is not supported");
return false;
}
}
else
{
if (nvse->editorVersion < CS_VERSION_1_4_0_518)
{
_ERROR("incorrect editor version (got %08X need at least %08X)", nvse->editorVersion, CS_VERSION_1_4_0_518);
return false;
}
}
// version checks pass
// any version compatibility checks should be done here
return true;
}
bool NVSEPlugin_Load(const NVSEInterface* nvse)
{
_MESSAGE("load");
g_pluginHandle = nvse->GetPluginHandle();
// save the NVSEinterface in cas we need it later
g_nvseInterface = (NVSEInterface*)nvse;
// register to receive messages from NVSE
g_messagingInterface = (NVSEMessagingInterface*)nvse->QueryInterface(kInterface_Messaging);
g_messagingInterface->RegisterListener(g_pluginHandle, "NVSE", MessageHandler);
#if RUNTIME
g_script = (NVSEScriptInterface*)nvse->QueryInterface(kInterface_Script);
#endif
/***************************************************************************
*
* READ THIS!
*
* Before releasing your plugin, you need to request an opcode range from
* the NVSE team and set it in your first SetOpcodeBase call. If you do not
* do this, your plugin will create major compatibility issues with other
* plugins, and will not load in release versions of NVSE. See
* nvse_readme.txt for more information.
*
* See https://geckwiki.com/index.php?title=NVSE_Opcode_Base
*
**************************************************************************/
// register commands
nvse->SetOpcodeBase(0x3DDD);
//RegisterScriptCommand(knvse_typegen);
RegisterScriptCommand(knvse_generate);
RegisterScriptCommand(knvse_auto);
RegisterScriptCommand(knvse_getfolders);
RegisterScriptCommand(knvse_generateone);
RegisterScriptCommand(knvse_scan);
RegisterScriptCommand(knvse_deepscan);
RegisterScriptCommand(knvse_generatetypes);
RegisterScriptCommand(knvse_generatelist);
return true;
}