Add LoadInteriorRefListByShopId function
This commit is contained in:
@@ -164,14 +164,17 @@ bool ClearCell(RE::StaticFunctionTag*) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t interior_ref_list_id, RE::TESObjectREFR* target_ref, RE::TESQuest* quest) {
|
void LoadRefsImpl(FFIResult<RawInteriorRefVec> result, RE::TESObjectREFR* target_ref, RE::TESQuest* quest) {
|
||||||
logger::info("Entered LoadInteriorRefListImpl");
|
logger::info("Entered LoadRefsImpl");
|
||||||
|
|
||||||
if (!quest) {
|
if (!quest) {
|
||||||
logger::error("LoadInteriorRefListImpl quest is null!");
|
logger::error("LoadRefsImpl quest is null!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Placing the refs must be done on the main thread otherwise calling MoveTo causes a crash
|
||||||
|
auto task = SKSE::GetTaskInterface();
|
||||||
|
task->AddTask([result, target_ref, quest]() {
|
||||||
RE::TESDataHandler * data_handler = RE::TESDataHandler::GetSingleton();
|
RE::TESDataHandler * data_handler = RE::TESDataHandler::GetSingleton();
|
||||||
RE::BSScript::Internal::VirtualMachine * a_vm = RE::BSScript::Internal::VirtualMachine::GetSingleton();
|
RE::BSScript::Internal::VirtualMachine * a_vm = RE::BSScript::Internal::VirtualMachine::GetSingleton();
|
||||||
using func_t = decltype(&PlaceAtMe);
|
using func_t = decltype(&PlaceAtMe);
|
||||||
@@ -179,24 +182,29 @@ void LoadInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_ke
|
|||||||
using func_t2 = decltype(&MoveTo);
|
using func_t2 = decltype(&MoveTo);
|
||||||
REL::Relocation<func_t2> MoveTo_Native(RE::Offset::TESObjectREFR::MoveTo);
|
REL::Relocation<func_t2> MoveTo_Native(RE::Offset::TESObjectREFR::MoveTo);
|
||||||
|
|
||||||
RE::TESObjectCELL * cell = RE::TESObjectCELL::LookupByEditorID<RE::TESObjectCELL>("BREmpty");
|
|
||||||
logger::info(FMT_STRING("LoadInteriorRefListImpl lookup cell override name: {} id: {:x}"), cell->GetName(), (uint32_t)cell->GetFormID());
|
|
||||||
if (!cell) {
|
|
||||||
logger::error("LoadInteriorRefListImpl cell is null!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target_ref) {
|
|
||||||
FFIResult<RawInteriorRefVec> result = get_interior_ref_list(api_url.c_str(), api_key.c_str(), interior_ref_list_id);
|
|
||||||
|
|
||||||
// Placing the refs must be done on the main thread otherwise calling MoveTo causes a crash
|
|
||||||
auto task = SKSE::GetTaskInterface();
|
|
||||||
task->AddTask([result, target_ref, quest, cell, data_handler, a_vm, MoveTo_Native, PlaceAtMe_Native]() {
|
|
||||||
SKSE::RegistrationMap<bool> successReg = SKSE::RegistrationMap<bool>();
|
SKSE::RegistrationMap<bool> successReg = SKSE::RegistrationMap<bool>();
|
||||||
successReg.Register(quest, RE::BSFixedString("OnLoadInteriorRefListSuccess"));
|
successReg.Register(quest, RE::BSFixedString("OnLoadInteriorRefListSuccess"));
|
||||||
SKSE::RegistrationMap<RE::BSFixedString> failReg = SKSE::RegistrationMap<RE::BSFixedString>();
|
SKSE::RegistrationMap<RE::BSFixedString> failReg = SKSE::RegistrationMap<RE::BSFixedString>();
|
||||||
failReg.Register(quest, RE::BSFixedString("OnLoadInteriorRefListFail"));
|
failReg.Register(quest, RE::BSFixedString("OnLoadInteriorRefListFail"));
|
||||||
|
|
||||||
|
if (!target_ref) {
|
||||||
|
logger::error("LoadRefsImpl target_ref is null!");
|
||||||
|
failReg.SendEvent("Spawn target reference is null");
|
||||||
|
successReg.Unregister(quest);
|
||||||
|
failReg.Unregister(quest);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RE::TESObjectCELL * cell = RE::TESObjectCELL::LookupByEditorID<RE::TESObjectCELL>("BREmpty");
|
||||||
|
logger::info(FMT_STRING("LoadRefsImpl lookup cell override name: {} id: {:x}"), cell->GetName(), (uint32_t)cell->GetFormID());
|
||||||
|
if (!cell) {
|
||||||
|
logger::error("LoadRefsImpl cell is null!");
|
||||||
|
failReg.SendEvent("Lookup failed for the shop Cell: BREmpty");
|
||||||
|
successReg.Unregister(quest);
|
||||||
|
failReg.Unregister(quest);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (result.IsOk()) {
|
if (result.IsOk()) {
|
||||||
logger::info("LoadInteriorRefList get_interior_ref_list result: OK");
|
logger::info("LoadInteriorRefList get_interior_ref_list result: OK");
|
||||||
RawInteriorRefVec vec = result.AsOk();
|
RawInteriorRefVec vec = result.AsOk();
|
||||||
@@ -256,10 +264,12 @@ void LoadInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_ke
|
|||||||
successReg.Unregister(quest);
|
successReg.Unregister(quest);
|
||||||
failReg.Unregister(quest);
|
failReg.Unregister(quest);
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
logger::error("LoadInteriorRefListImpl target_ref is null!");
|
|
||||||
return;
|
void LoadInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t interior_ref_list_id, RE::TESObjectREFR* target_ref, RE::TESQuest* quest) {
|
||||||
}
|
logger::info("Entered LoadInteriorRefListImpl");
|
||||||
|
|
||||||
|
LoadRefsImpl(get_interior_ref_list(api_url.c_str(), api_key.c_str(), interior_ref_list_id), target_ref, quest);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadInteriorRefList(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t interior_ref_list_id, RE::TESObjectREFR* target_ref, RE::TESQuest* quest) {
|
bool LoadInteriorRefList(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t interior_ref_list_id, RE::TESObjectREFR* target_ref, RE::TESQuest* quest) {
|
||||||
@@ -278,3 +288,26 @@ bool LoadInteriorRefList(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::
|
|||||||
thread.detach();
|
thread.detach();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoadInteriorRefListByShopIdImpl(RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t shop_id, RE::TESObjectREFR* target_ref, RE::TESQuest* quest) {
|
||||||
|
logger::info("Entered LoadInteriorRefListByShopIdImpl");
|
||||||
|
|
||||||
|
LoadRefsImpl(get_latest_interior_ref_list_by_shop_id(api_url.c_str(), api_key.c_str(), shop_id), target_ref, quest);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LoadInteriorRefListByShopId(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t shop_id, RE::TESObjectREFR* target_ref, RE::TESQuest* quest) {
|
||||||
|
logger::info("Entered LoadInteriorRefListByShopId");
|
||||||
|
|
||||||
|
if (!target_ref) {
|
||||||
|
logger::error("LoadInteriorRefListByShopId target_ref is null!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!quest) {
|
||||||
|
logger::error("LoadInteriorRefListByShopId quest is null!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::thread thread(LoadInteriorRefListByShopIdImpl, api_url, api_key, shop_id, target_ref, quest);
|
||||||
|
thread.detach();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,3 +3,4 @@
|
|||||||
bool CreateInteriorRefList(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t shop_id, RE::TESQuest* quest);
|
bool CreateInteriorRefList(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t shop_id, RE::TESQuest* quest);
|
||||||
bool ClearCell(RE::StaticFunctionTag*);
|
bool ClearCell(RE::StaticFunctionTag*);
|
||||||
bool LoadInteriorRefList(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t interior_ref_list_id, RE::TESObjectREFR* target_ref, RE::TESQuest* quest);
|
bool LoadInteriorRefList(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t interior_ref_list_id, RE::TESObjectREFR* target_ref, RE::TESQuest* quest);
|
||||||
|
bool LoadInteriorRefListByShopId(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::BSFixedString api_key, uint32_t shop_id, RE::TESObjectREFR* target_ref, RE::TESQuest* quest);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ bool RegisterFuncs(RE::BSScript::IVirtualMachine* a_vm)
|
|||||||
a_vm->RegisterFunction("Create", "BRInteriorRefList", CreateInteriorRefList);
|
a_vm->RegisterFunction("Create", "BRInteriorRefList", CreateInteriorRefList);
|
||||||
a_vm->RegisterFunction("ClearCell", "BRInteriorRefList", ClearCell);
|
a_vm->RegisterFunction("ClearCell", "BRInteriorRefList", ClearCell);
|
||||||
a_vm->RegisterFunction("Load", "BRInteriorRefList", LoadInteriorRefList);
|
a_vm->RegisterFunction("Load", "BRInteriorRefList", LoadInteriorRefList);
|
||||||
|
a_vm->RegisterFunction("LoadByShopId", "BRInteriorRefList", LoadInteriorRefListByShopId);
|
||||||
a_vm->RegisterFunction("Toggle", "BRMerchandiseList", ToggleMerchandise);
|
a_vm->RegisterFunction("Toggle", "BRMerchandiseList", ToggleMerchandise);
|
||||||
a_vm->RegisterFunction("NextPage", "BRMerchandiseList", LoadNextMerchandise);
|
a_vm->RegisterFunction("NextPage", "BRMerchandiseList", LoadNextMerchandise);
|
||||||
a_vm->RegisterFunction("PrevPage", "BRMerchandiseList", LoadPrevMerchandise);
|
a_vm->RegisterFunction("PrevPage", "BRMerchandiseList", LoadPrevMerchandise);
|
||||||
|
|||||||
Reference in New Issue
Block a user