#define _NX_LOADSAVE_
#include "nvse_extender.h"
#include "SafeWrite.h"
#include "nvse/GameAPI.h"
#include "nvse/ParamInfos.h"
#include "nvse/GameObjects.h"
#include "nvse/GameRTTI.h"
#include "nvse/GameExtraData.h"
#include "nvse/GameProcess.h"
#include <string>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <exception>
#include "gameforms_extended.h"
#ifdef _NX_LOADSAVE_
#include "NX_save_load.h"
#endif
#include <exception>
#include "nvse/StringVar.h"
NVSE_EXEVRefStringMap nvse_ex_evstringmap;
NVSE_EXEVRefFloatMap nvse_ex_evfloatmap;
NVSE_EXEVRefFormMap nvse_ex_evformmap;
NVSECommandTableInterface* nvseCommandTableInterface;
CommandInfo* gqvCommandInfo;
#if RUNTIME_VERSION == RUNTIME_VERSION_1_4_0_525
IDebugLog gLog("nvse_extender.log");
#else
IDebugLog gLog("nvse_extender_ng.log");
#endif
PluginHandle g_pluginHandle = kPluginHandle_Invalid;
NVSEStringVarInterface* g_svIntfc;
NVSEArrayVarInterface* g_avIntfc;
NVSEScriptInterface* g_sIntfc;
#define ExtractArgsEx(...) g_sIntfc->ExtractArgsEx(__VA_ARGS__)
#define ExtractFormatStringArgs(...) g_sIntfc->ExtractFormatStringArgs(__VA_ARGS__)
#ifdef _NX_LOADSAVE_
NVSEMessagingInterface* g_msg;
void MessageHandler(NVSEMessagingInterface::Message* msg)
{
try
{
switch (msg->type)
{
case NVSEMessagingInterface::kMessage_LoadGame:
_MESSAGE("Received load message with file path %s", msg->data);
loadSettings((char *)msg->data);
break;
case NVSEMessagingInterface::kMessage_SaveGame:
_MESSAGE("Received save message with file path %s", msg->data);
saveSettings((char *)msg->data);
break;
default:
_MESSAGE("Plugin Example received unknown message");
break;
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in messagehandler: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in messagehandler");
}
}
/*
*/
#endif
bool NVSEPlugin_Query(const NVSEInterface * nvse, PluginInfo * info)
{
info->infoVersion = PluginInfo::kInfoVersion;
info->name = NVSE_EXTENDER_NAME;
info->version = NVSE_EXTENDER_VER;
if(!nvse->isEditor)
{
#if RUNTIME_VERSION == RUNTIME_VERSION_1_4_0_525
// return false if nvse reporsts NG
if (nvse->runtimeVersion != RUNTIME_VERSION_1_4_0_525)
{
_MESSAGE("Standard extender aborting in NOGORE FONV");
return false;
}
else
{
_MESSAGE("Standard NVSE Extender ready");
}
#elif RUNTIME_VERSION == RUNTIME_VERSION_1_4_0_525ng
// return false if nvse does not report NG
if (nvse->runtimeVersion != RUNTIME_VERSION_1_4_0_525ng)
{
_MESSAGE("NOGORE extender aborting in standard FONV");
return false;
}
else
{
_MESSAGE("NOGORE NVSE Extender ready");
}
#endif
}
else
{
// Just don't load the NG version in the editor since they are the same for the GECK.
#if RUNTIME_VERSION != RUNTIME_VERSION_1_4_0_525
_MESSAGE("NOGORE extender aborting GECK");
return false;
#endif
}
if(!nvse->isEditor)
{
// Would like to send a message to console here, as NVSE does, even
// if NOT in console mode.
// Console_Print("NVSE Extender version: %d", NVSE_EXTENDER_VER);
}
return true;
}
bool NVSEPlugin_Load(const NVSEInterface * nvse)
{
g_pluginHandle = nvse->GetPluginHandle();
nvse->SetOpcodeBase(NVSE_EXTENDER_OPCODE_BASE);
/* START published plugins, do not change order */
nvse->RegisterCommand(&kCommandInfo_NX_GetVersion);
nvse->RegisterCommand(&kCommandInfo_NX_IsUsingSkeleton);
nvse->RegisterCommand(&kCommandInfo_NX_IsInList);
nvse->RegisterCommand(&kCommandInfo_NX_SetEVFl);
nvse->RegisterCommand(&kCommandInfo_NX_GetEVFl);
nvse->RegisterCommand(&kCommandInfo_NX_SetEVFo);
nvse->RegisterCommand(&kCommandInfo_NX_GetEVFo);
nvse->RegisterCommand(&kCommandInfo_NX_GetConversationPartner);
nvse->RegisterCommand(&kCommandInfo_NX_ClrEVFl);
nvse->RegisterCommand(&kCommandInfo_NX_ClrEVFo);
/* END published plugins, do not change order */
nvse->RegisterCommand(&kCommandInfo_NX_GetQVEVFl);
nvse->RegisterCommand(&kCommandInfo_NX_SetEVSt);
nvse->RegisterTypedCommand(&kCommandInfo_NX_GetEVSt, kRetnType_String);
nvse->RegisterCommand(&kCommandInfo_NX_ClrEVSt);
nvse->RegisterTypedCommand(&kCommandInfo_NX_GetEVFlAr, kRetnType_Array);
nvse->RegisterTypedCommand(&kCommandInfo_NX_GetEVFoAr, kRetnType_Array);
nvse->RegisterTypedCommand(&kCommandInfo_NX_GetEVStAr, kRetnType_Array);
// nvse->RegisterCommand(&kCommandInfo_NX_TestCmd);
// Cannot find the flag for these
// nvse->RegisterCommand(&kCommandInfo_NX_CanEquipItem);
// nvse->RegisterCommand(&kCommandInfo_NX_CanUnequipItem);
// nvse->RegisterCommand(&kCommandInfo_NX_ChangeRace);
// nvse->RegisterCommand(&kCommandInfo_NX_IsFIKEnabled);
// nvse->RegisterCommand(&kCommandInfo_NX_TFIK);
// nvse->RegisterCommand(&kCommandInfo_NX_IsUFOEnabled);
// nvse->RegisterCommand(&kCommandInfo_NX_RunBatchScript);
if(!nvse->isEditor)
{
#ifdef _NX_LOADSAVE_
clearSettings();
// register to receive messages from NVSE
NVSEMessagingInterface* msgIntfc = (NVSEMessagingInterface*)nvse->QueryInterface(kInterface_Messaging);
msgIntfc->RegisterListener(g_pluginHandle, "NVSE", MessageHandler);
g_msg = msgIntfc;
#endif
g_avIntfc = (NVSEArrayVarInterface*)nvse->QueryInterface(kInterface_ArrayVar);
g_svIntfc = (NVSEStringVarInterface*)nvse->QueryInterface(kInterface_StringVar);
g_sIntfc = (NVSEScriptInterface*)nvse->QueryInterface(kInterface_Script);
RegisterStringVarInterface(g_svIntfc);
nvseCommandTableInterface = (NVSECommandTableInterface*)nvse->QueryInterface(kInterface_CommandTable);
if (nvseCommandTableInterface)
gqvCommandInfo = (CommandInfo*)nvseCommandTableInterface->GetByName("GetQuestVariable");
}
return true;
}
// Implemented in-use functions
bool Cmd_NX_GetVersion_Execute(COMMAND_ARGS)
{
try
{
*result = NVSE_EXTENDER_VER;
if (IsConsoleMode())
{
Console_Print("NVSE Extender version: %d", NVSE_EXTENDER_VER);
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getver: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getver");
}
return true;
}
bool Cmd_NX_IsUsingSkeleton_Execute(COMMAND_ARGS)
{
TESActorBase *pActor;
char skelName[512];
char actorModel[512];
char *pch = NULL;
char *dummy = NULL;
char **parts = NULL;
int cnt = 0;
int idx;
_MESSAGE("START IsUsingSkeleton");
gLog.Indent();
try
{
*result = 0;
if (ExtractArgsEx(EXTRACT_ARGS_EX, &skelName))
{
pActor = DYNAMIC_CAST(thisObj->baseForm, TESForm, TESActorBase);
if (pActor)
{
strcpy_s(actorModel, 512, pActor->model.GetModelPath());
pch = strtok_s(actorModel, "/\\", &dummy);
while (NULL != pch)
{
parts = (char **) realloc(parts, (cnt + 1) * (sizeof(char*)));
parts[cnt] = pch;
cnt++;
pch = strtok_s(NULL, "/\\", &dummy);
}
for (idx = 0; idx < cnt; idx++)
{
_MESSAGE("\tIDX %d is %s", idx, parts[idx]);
}
if (cnt >= 2)
{
_MESSAGE("\tSIC %s %s is %d", skelName, parts[cnt - 2], _stricmp(skelName, parts[cnt - 2]));
if (0 == _stricmp(skelName, parts[cnt - 2]))
{
*result = 1;
}
}
// Free our memory
free(parts);
if (IsConsoleMode())
{
Console_Print("IsUsingSkeleton %.0f", *result);
}
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in isusingskeleton: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in isusingskeleton");
}
gLog.Outdent();
_MESSAGE("END IsUsingSkeleton %0.0f", *result);
return true;
}
TESCreature* GetRootCreature(TESCreature *cre)
{
try
{
while ((GetObjectClassName(cre) != "<no rtti>") && (NULL != cre->creatureTemplate))
{
if (GetObjectClassName(cre->creatureTemplate) == "<no rtti>")
break;
cre = cre->creatureTemplate;
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getRootCreature: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getRootCreature");
}
return cre;
}
bool Cmd_NX_IsInList_Execute(COMMAND_ARGS)
{
BGSListForm *pFormList = NULL; // the formlist
TESForm *pItem = NULL; // item we are looking for
TESForm *pListItem = NULL; // current item from list
TESForm *pBaseItem = NULL; // item we are looking for
TESForm *pBaseListItem = NULL; // current item from list
// need to handle creatures in a special fashion
TESCreature *pCreature = NULL;
TESCreature *pLCreature = NULL;
TESCreature *pCreatureB = NULL;
TESCreature *pLCreatureB = NULL;
UInt32 n = 0; // do not do recursion
int i;
*result = 0;
try
{
ExtractArgsEx(EXTRACT_ARGS_EX, &pFormList, &pItem, &n);
if (pFormList && pItem)
{
pBaseItem = pItem->TryGetREFRParent();
pCreature = DYNAMIC_CAST(pBaseItem, TESForm, TESCreature);
for (i = 0; i < pFormList->Count(); i++)
{
pListItem = pFormList->GetNthForm(i);
if (pListItem)
{
if (NULL != pCreature)
{
pCreatureB = GetRootCreature(pCreature);
pLCreature = DYNAMIC_CAST(pListItem, TESForm, TESCreature);
if (NULL != pLCreature)
{
pLCreatureB = GetRootCreature(pLCreature);
if (pCreature->refID == pLCreature->refID)
{
*result = 1;
break;
}
else if (pCreatureB->refID == pLCreature->refID)
{
*result = 2;
break;
}
else if (pCreature->refID == pLCreatureB->refID)
{
*result = 3;
break;
}
else if (pCreatureB->refID == pLCreatureB->refID)
{
*result = 4;
break;
}
}
}
else
{
pBaseListItem = pListItem->TryGetREFRParent();
if (pItem->refID == pListItem->refID)
{
*result = 1;
break;
}
else if (pBaseItem->refID == pListItem->refID)
{
*result = 2;
break;
}
else if (pItem->refID == pBaseListItem->refID)
{
*result = 3;
break;
}
else if (pBaseItem->refID == pBaseListItem->refID)
{
*result = 4;
break;
}
}
}
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in isinlist: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in isinlist");
}
return true;
}
// TBD functions
bool Cmd_NX_ChangeRace_Execute(COMMAND_ARGS)
{
UInt32 *refResult = NULL;
Actor *pActor = NULL; // item we are looking for
TESRace *pRace = NULL; // current item from list
// refResult = (UInt32*)result;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &pActor, &pRace))
{
if (pActor)
{
// _MESSAGE(" Actor is a Character");
// needs a TESRaceForm not TESRace
// pActor->race.race = *pRace;
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in changerace: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in changerace");
}
return true;
}
bool Cmd_NX_SetEVSt_Execute(COMMAND_ARGS)
{
std::string key;
char keyName[512];
char sValue[512];
UInt32 iPersist = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &sValue, &iPersist))
{
if (thisObj)
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
nvse_ex_evstringmap[thisObj->refID][key] = sValue;
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in setevst: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in setevst");
}
return true;
}
bool Cmd_NX_GetEVSt_Execute(COMMAND_ARGS)
{
char keyName[512];
std::string key;
std::string value;
UInt32 iPersist = 0;
*result = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &iPersist))
{
if (thisObj)
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
value = "";
try // searching for absent values throws an exception, but this avoids creating "empty" values
{
if ("" != nvse_ex_evstringmap.at(thisObj->refID).at(key))
value = nvse_ex_evstringmap[thisObj->refID][key];
}
catch (...){}
g_svIntfc->Assign(PASS_COMMAND_ARGS, value.c_str());
if (IsConsoleMode())
{
Console_Print("GetEVSt: %s", value.c_str());
}
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getevst: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getevst");
}
return true;
}
bool Cmd_NX_SetEVFl_Execute(COMMAND_ARGS)
{
std::string key;
char keyName[512];
float fValue = 0;
UInt32 iPersist = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &fValue, &iPersist))
{
if (thisObj)
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
nvse_ex_evfloatmap[thisObj->refID][key] = fValue;
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in setevfl: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in setevfl");
}
return true;
}
bool Cmd_NX_GetEVFl_Eval(COMMAND_ARGS_EVAL)
{
std::string key;
UInt32 iPersist = 0;
*result = 0;
try
{
if (thisObj)
{
key = (char *)arg1;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
try // searching for absent values throws an exception, but this avoids creating "empty" values
{
if (nvse_ex_evfloatmap.at(thisObj->refID).at(key))
*result = nvse_ex_evfloatmap[thisObj->refID][key];
}
catch(...){}
if (IsConsoleMode())
{
Console_Print("GetEVFl: %.5f", *result);
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getevfl: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getevfl");
}
return true;
}
bool Cmd_NX_GetEVFl_Execute(COMMAND_ARGS)
{
char keyName[512];
*result = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName))
{
return Cmd_NX_GetEVFl_Eval(thisObj, &keyName, NULL, result);
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getevfl: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getevfl");
}
return true;
}
bool Cmd_NX_SetEVFlEx_Execute(COMMAND_ARGS)
{
std::string key;
char buffer[kMaxMessageLength];
*result = 0;
try
{
if (ExtractFormatStringArgs(0, buffer, paramInfo, scriptData, opcodeOffsetPtr, scriptObj, eventList, 19))
{
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in setevflex: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in setevflex");
}
return true;
}
bool Cmd_NX_SetEVFo_Execute(COMMAND_ARGS)
{
std::string key;
char keyName[512];
TESForm *fValue = 0;
UInt32 iPersist = 0;
try
{
if (thisObj)
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &fValue, &iPersist))
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
if (fValue)
{
nvse_ex_evformmap[thisObj->refID][key] = fValue->refID;
}
else
{
nvse_ex_evformmap[thisObj->refID][key] = 0;
}
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in setevfo: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in setevfo");
}
return true;
}
bool Cmd_NX_GetEVFo_Execute(COMMAND_ARGS)
{
std::string key;
char keyName[512];
UInt32 iPersist = 0;
UInt32* refResult;
refResult = (UInt32*)result;
*refResult = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName))
{
if (thisObj)
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
try // searching for absent values throws an exception, but this avoids creating "empty" values
{
if (nvse_ex_evformmap.at(thisObj->refID).at(key))
*refResult = nvse_ex_evformmap[thisObj->refID][key];
}
catch(...){}
}
}
if (IsConsoleMode())
{
Console_Print("GetEVFl: %x", *refResult);
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getevfo: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getevfo");
}
return true;
}
/**
doMatch:
1 = exact match
2 = left side match
**/
bool Cmd_NX_ClrEVFl_Execute(COMMAND_ARGS)
{
std::string key = "";
char keyName[512] = "";
int doMatch = 1;
*result = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &doMatch))
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
}
if (thisObj)
{
if (nvse_ex_evfloatmap.count(thisObj->refID) > 0)
{
auto it = nvse_ex_evfloatmap[thisObj->refID].begin();
if (key != "")
{
switch (doMatch)
{
case 2:
while (it != nvse_ex_evfloatmap[thisObj->refID].end())
{
if (it->first.compare(0, key.size(), key) == 0)
{
it = nvse_ex_evfloatmap[thisObj->refID].erase(it);
}
else
{
it++;
}
}
break;
default:
case 1:
nvse_ex_evfloatmap[thisObj->refID].erase(key);
break;
}
}
else
{
nvse_ex_evfloatmap.clear();
}
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in clrevfl: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in clrevfl");
}
return true;
}
bool Cmd_NX_ClrEVFo_Execute(COMMAND_ARGS)
{
std::string key = "";
char keyName[512] = "";
int doMatch = 1;
*result = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &doMatch))
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
}
if (thisObj)
{
if (nvse_ex_evformmap.count(thisObj->refID) > 0)
{
if (key != "")
{
if (doMatch == 1)
{
nvse_ex_evformmap[thisObj->refID].erase(key);
}
else if (doMatch == 2)
{
auto it = nvse_ex_evformmap[thisObj->refID].begin();
while (it != nvse_ex_evformmap[thisObj->refID].end())
{
if (it->first.compare(0, key.size(), key) == 0)
{
it = nvse_ex_evformmap[thisObj->refID].erase(it);
}
else
{
it++;
}
}
}
else
{
_MESSAGE("Unknown domatch setting %i", doMatch);
}
}
else
{
nvse_ex_evformmap.clear();
}
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in clrevfo: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in clrevfo");
}
return true;
}
bool Cmd_NX_ClrEVSt_Execute(COMMAND_ARGS)
{
std::string key = "";
char keyName[512] = "";
int doMatch = 1;
*result = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &doMatch))
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
}
if (thisObj)
{
if (nvse_ex_evstringmap.count(thisObj->refID) > 0)
{
if (key != "")
{
if (doMatch == 1)
{
nvse_ex_evstringmap[thisObj->refID].erase(key);
}
else if (doMatch == 2)
{
auto it = nvse_ex_evstringmap[thisObj->refID].begin();
while (it != nvse_ex_evstringmap[thisObj->refID].end())
{
if (it->first.compare(0, key.size(), key) == 0)
{
it = nvse_ex_evstringmap[thisObj->refID].erase(it);
}
else
{
it++;
}
}
}
else
{
_MESSAGE("Unknown domatch setting %i", doMatch);
}
}
else
{
nvse_ex_evformmap.clear();
}
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in clrevst: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in clrevst");
}
return true;
}
bool Cmd_NX_GetEVFlAr_Execute(COMMAND_ARGS)
{
std::string key = "";
char keyName[512] = "";
int doMatch = 2;
NVSEArrayVarInterface::Element *eKey;
NVSEArrayVarInterface::Element *eValue;
*result = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &doMatch))
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
}
if (thisObj)
{
NVSEArrayVarInterface::Array* arArray = g_avIntfc->CreateStringMap(NULL, NULL, 0, scriptObj);
if (arArray && (nvse_ex_evfloatmap.count(thisObj->refID) > 0))
{
auto it = nvse_ex_evfloatmap[thisObj->refID].begin();
if (key != "")
{
switch (doMatch)
{
default:
case 2:
while (it != nvse_ex_evfloatmap[thisObj->refID].end())
{
if (it->first.compare(0, key.size(), key) == 0)
{
eKey = new NVSEArrayVarInterface::Element(it->first.c_str());
eValue = new NVSEArrayVarInterface::Element(it->second);
g_avIntfc->SetElement(arArray, *eKey, *eValue);
}
it++;
}
break;
case 1:
eKey = new NVSEArrayVarInterface::Element(keyName);
eValue = new NVSEArrayVarInterface::Element(nvse_ex_evfloatmap[thisObj->refID][key]);
g_avIntfc->SetElement(arArray, *eKey, *eValue);
break;
}
}
else
{
auto it = nvse_ex_evfloatmap[thisObj->refID].begin();
while (it != nvse_ex_evfloatmap[thisObj->refID].end())
{
eKey = new NVSEArrayVarInterface::Element(it->first.c_str());
eValue = new NVSEArrayVarInterface::Element(it->second);
g_avIntfc->SetElement(arArray, *eKey, *eValue);
it++;
}
}
g_avIntfc->AssignCommandResult(arArray, result);
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getevflar: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getevflar");
}
return true;
}
bool Cmd_NX_GetEVFoAr_Execute(COMMAND_ARGS)
{
std::string key = "";
char keyName[512] = "";
int doMatch = 2;
NVSEArrayVarInterface::Element *eKey;
NVSEArrayVarInterface::Element *eValue;
*result = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &doMatch))
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
}
if (thisObj)
{
NVSEArrayVarInterface::Array* arArray = g_avIntfc->CreateStringMap(NULL, NULL, 0, scriptObj);
if (arArray && (nvse_ex_evformmap.count(thisObj->refID) > 0))
{
if (key != "")
{
if (doMatch == 1)
{
eKey = new NVSEArrayVarInterface::Element(keyName);
eValue = new NVSEArrayVarInterface::Element(nvse_ex_evformmap[thisObj->refID][key]);
g_avIntfc->SetElement(arArray, *eKey, *eValue);
}
else
{
auto it = nvse_ex_evformmap[thisObj->refID].begin();
while (it != nvse_ex_evformmap[thisObj->refID].end())
{
if (it->first.compare(0, key.size(), key) == 0)
{
eKey = new NVSEArrayVarInterface::Element(it->first.c_str());
eValue = new NVSEArrayVarInterface::Element(it->second);
g_avIntfc->SetElement(arArray, *eKey, *eValue);
}
it++;
}
}
}
else
{
auto it = nvse_ex_evformmap[thisObj->refID].begin();
while (it != nvse_ex_evformmap[thisObj->refID].end())
{
eKey = new NVSEArrayVarInterface::Element(it->first.c_str());
eValue = new NVSEArrayVarInterface::Element(it->second);
g_avIntfc->SetElement(arArray, *eKey, *eValue);
it++;
}
}
g_avIntfc->AssignCommandResult(arArray, result);
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getevfoar: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getevfoar");
}
return true;
}
bool Cmd_NX_GetEVStAr_Execute(COMMAND_ARGS)
{
std::string key = "";
char keyName[512] = "";
int doMatch = 2;
NVSEArrayVarInterface::Element *eKey;
NVSEArrayVarInterface::Element *eValue;
*result = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &keyName, &doMatch))
{
key = keyName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
}
if (thisObj)
{
NVSEArrayVarInterface::Array* arArray = g_avIntfc->CreateStringMap(NULL, NULL, 0, scriptObj);
if (arArray && (nvse_ex_evstringmap.count(thisObj->refID) > 0))
{
if (key != "")
{
if (doMatch == 1)
{
eKey = new NVSEArrayVarInterface::Element(keyName);
eValue = new NVSEArrayVarInterface::Element(nvse_ex_evstringmap[thisObj->refID][key].c_str());
g_avIntfc->SetElement(arArray, *eKey, *eValue);
}
else
{
auto it = nvse_ex_evstringmap[thisObj->refID].begin();
while (it != nvse_ex_evstringmap[thisObj->refID].end())
{
if (it->first.compare(0, key.size(), key) == 0)
{
eKey = new NVSEArrayVarInterface::Element(it->first.c_str());
eValue = new NVSEArrayVarInterface::Element(it->second.c_str());
g_avIntfc->SetElement(arArray, *eKey, *eValue);
}
it++;
}
}
}
else
{
auto it = nvse_ex_evstringmap[thisObj->refID].begin();
while (it != nvse_ex_evstringmap[thisObj->refID].end())
{
eKey = new NVSEArrayVarInterface::Element(it->first.c_str());
eValue = new NVSEArrayVarInterface::Element(it->second.c_str());
g_avIntfc->SetElement(arArray, *eKey, *eValue);
it++;
}
}
g_avIntfc->AssignCommandResult(arArray, result);
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getevstar: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getevstar");
}
return true;
}
bool Cmd_NX_GetConversationPartner_Execute(COMMAND_ARGS)
{
UInt32 *refResult = (UInt32*)result;
Actor *pActor = NULL;
NXBaseProcess* pProcess = NULL;
TESPackage *pPackage = NULL;
DialoguePackage* pDPackage = NULL;
*result = 0;
*refResult = 0;
try
{
pActor = DYNAMIC_CAST(thisObj, TESForm, Actor);
if (pActor)
{
pProcess = (NXBaseProcess*)pActor->baseProcess;
}
if (pProcess)
{
pPackage = pProcess->GetCurrentPackage();
}
if (pPackage)
{
pDPackage = DYNAMIC_CAST(pPackage, TESPackage, DialoguePackage);
}
if (pDPackage)
{
if (pDPackage->subject)
{
*refResult = pDPackage->subject->refID;
}
}
if (IsConsoleMode())
{
Console_Print("NX_GetConversatioNPartner: %x", *result);
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getconvopartner: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getconvopartner");
}
return true;
}
#define PASS_CMD_ARGS_EVAL thisObj, arg1, arg2, result
bool Cmd_NX_GetQVEVFl_Eval(COMMAND_ARGS_EVAL)
{
std::string key;
UInt32 strIndex = 0;
*result = 0;
try
{
if (gqvCommandInfo && gqvCommandInfo->eval(PASS_CMD_ARGS_EVAL))
if (thisObj)
{
strIndex = *result;
key = g_svIntfc->GetString(strIndex);
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
*result = nvse_ex_evfloatmap[thisObj->refID][key];
if (IsConsoleMode())
{
Console_Print("GetQVEVFl: %.5f", *result);
}
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getQVevfl: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getQVevfl");
}
return true;
}
bool Cmd_NX_GetQVEVFl_Execute(COMMAND_ARGS)
{
UInt32 varIndex;
TESQuest* quest;
*result = 0;
try
{
if (ExtractArgsEx(EXTRACT_ARGS_EX, &quest, &varIndex))
{
return Cmd_NX_GetQVEVFl_Eval(thisObj, quest, (void*)varIndex, result);
}
}
catch (std::exception& e)
{
_MESSAGE("Exception in getQVevfl: %s", e.what());
}
catch (int n)
{
_MESSAGE("Exception in getver: %#8.8x", (unsigned)n);
}
catch (...)
{
_MESSAGE("Unknown exception in getQVevfl");
}
return true;
}
bool Cmd_NX_TestCmd_Execute(COMMAND_ARGS)
{
// saveSettings("test.csv");
/*
TESCreature *pActor = NULL; // item we are looking for
DumpClass(thisObj);
pActor = DYNAMIC_CAST(thisObj, TESForm, TESCreature);
if (pActor)
{
if (IsConsoleMode())
{
Console_Print("Before :%s", pActor->model.nifPath);
}
pActor->model.SetPath("meshes\\creatures\\test.nif");
if (IsConsoleMode())
{
Console_Print("After :%s", pActor->model.nifPath);
}
}
else
{
if (IsConsoleMode())
{
Console_Print(" %8x Not an actor", thisObj->refID);
}
}
*/
return true;
}