Clean up dead commented code

This commit is contained in:
Tyler Hallada 2020-10-17 17:32:38 -04:00
parent 404f2d9ae5
commit 00e99bba2e
2 changed files with 1 additions and 170 deletions

View File

@ -27,9 +27,6 @@ int CreateInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_k
std::vector<RefRecord> ref_records;
for (auto entry = cell->references.begin(); entry != cell->references.end(); ++entry)
{
// TODO: skip saving the ref if it is part of mod file
// OR: continue to save it, but with a special flag (useful in order to allow repositioning default statics)
// Then, during Load, skip PlaceAtMe, lookup the ref by id and then reposition it
RE::TESObjectREFR * ref = (*entry).get();
const char * name = ref->GetName();
logger::info(FMT_STRING("CreateInteriorRefList ref: {}"), name);
@ -63,7 +60,6 @@ int CreateInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_k
char * base_file_name = base_file->fileName;
bool is_light = base_file->recordFlags.all(RE::TESFile::RecordFlag::kSmallFile);
uint32_t base_local_form_id = is_light ? base_form_id & 0xfff : base_form_id & 0xFFFFFF;
//_MESSAGE("FILE: %s isLight: %d formID: 0x%x localFormId: 0x%x", file_name, is_light, form_id, local_form_id);
RE::FormID ref_form_id = ref->GetFormID();
uint16_t ref_mod_index = ref_form_id >> 24;
char * ref_file_name = nullptr;
@ -165,44 +161,6 @@ bool ClearCell(RE::StaticFunctionTag*)
return true;
}
// TODO: store the FFIResult in a HashMap cache (with ids assigned from incrementing a global int) and return its key in this function
// * bool BRResult.IsOk(int resultId) ; if false, then only GetErr() shall be accessed
// * bool BRResult.IsErr(int resultId) ; maybe not needed
// * string BRResult.GetErr(int resultId) ; always a string
// * string BRResult.GetType(int resultId) ; returns type of Ok value encoded as string
// * BRResult.Drop(int resultId) ; once we are done using the data from the result or displaying an error, delete it from the cache and free the memory
// These will panic if a) the result is an error or b) the type of the result value different than what was requested
// That will cause CTDs but there's not much else to do, silently causing undefined behavior would be worse
// Every step of this API has an explicit check you must make before continuing. If you break that contract, that's on you, the scripter.
// * string BRResult.GetString(int resultId)
// * int BRResult.GetInt(int resultId)
// * bool BRResult.GetBool(int resultId)
// * int BRResult.GetResponseId(int resultId)
// For BRResponse (maybe just completely get rid of this):
// * int BRResponse.GetStatus(int responseId) ; if >= 300 then none of the other functions should be accessed
// * bool BRResponse.IsFromCache(int responseId)
// * string BRResponse.GetType(int responseId) ; may return things like "string" or "shop"
// * string BRResponse.GetString(int responseId) ; is this going to be needed?
// * int BRResponse.GetShopId(int responseId) ; for a get_shop request
// * int BRResponse.GetInteriorRefListId(int responseId) ; for a get_interior_ref_list request
// * BRResponse.Drop()
// The following will return values from a HashMap cache on the rust-side where entries are not evicted unless explicitly told to by papyrus.
// These methods will panic if there isn't an entry in the cache for the id. This can happen if a request was not made beforehand and verified to be non-err result with a non-error response.
// For BRShop
// * string BRShop.GetName(int shopId)
// * int BRShop.GetOwnerId(int shopId)
// * BRShop.Drop()
// For BROwner
// * string BROwner.GetName(int ownerId)
// * BROwner.Drop()
// Should split this up into GetInteriorRefList and LoadInteriorRefList.
// Get: makes the request to the api and stores the Result in a rust cache, returns id of Result
// Load: given id of interior ref list, gets the data from the rust cache, does the PlaceAtMe loop and returns an id of another Result
bool 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");
@ -219,16 +177,6 @@ bool LoadInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_ke
using func_t2 = decltype(&MoveTo);
REL::Relocation<func_t2> MoveTo_Native(RE::Offset::TESObjectREFR::MoveTo);
// testing returning a script object
// RE::BSTSmartPointer<RE::BSScript::Object> ret = RE::BSTSmartPointer<RE::BSScript::Object>::BSTSmartPointer();
// a_vm->CreateObject(RE::BSFixedString("BRResult"), ret);
// RE::BSScript::Variable var = RE::BSScript::Variable::Variable(RE::BSScript::TypeInfo::TypeInfo(RE::BSScript::TypeInfo::RawType::kBool));
// var.SetBool(false);
// a_vm->SetPropertyValue(ret, "value", var);
// RE::BSScript::Variable ret_var = RE::BSScript::Variable::Variable(RE::BSScript::TypeInfo::TypeInfo(RE::BSScript::TypeInfo::RawType::kObject));
// ret_var.SetObject(ret);
// return ret_var;
RE::TESObjectCELL * cell = RE::TESObjectCELL::LookupByEditorID<RE::TESObjectCELL>("BREmpty");
logger::info(FMT_STRING("LoadInteriorRefList lookup cell override name: {} id: {:x}"), cell->GetName(), (uint32_t)cell->GetFormID());
if (!cell) {
@ -236,7 +184,6 @@ bool LoadInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_ke
return false;
}
//RE::TESObjectREFR * x_marker = data_handler->LookupForm<RE::TESObjectREFR>(6628, "BazaarRealm.esp");
if (target_ref) {
FFIResult<RefRecordVec> result = get_interior_ref_list(api_url.c_str(), api_key.c_str(), interior_ref_list_id);
@ -267,18 +214,6 @@ bool LoadInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_ke
game_ref = data_handler->LookupForm<RE::TESObjectREFR>(ref.ref_local_form_id, ref.ref_mod_name);
if (game_ref) {
logger::info(FMT_STRING("LoadInteriorRefList lookup ref name: {}, form_id: {:x}"), game_ref->GetName(), (uint32_t)game_ref->GetFormID());
// Failed experiment at trying to call the ObjectReference.Enable() papyrus native function
//RE::BSTSmartPointer<RE::BSScript::Object> object;
//RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor> callback = RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor>::BSTSmartPointer(RE::BSScript::IStackCallbackFunctor());
//a_vm->CreateObject(RE::BSFixedString("ObjectReference"), game_ref, object);
//_MESSAGE("Created Object isConstructed: %d, isInitialized: %d, isValid: %d, type: %s", object->IsConstructed(), object->IsInitialized(), object->IsValid(), object->GetTypeInfo()->GetName());
//RE::BSTHashMap<RE::VMStackID, RE::BSTSmartPointer<RE::BSScript::Stack>> runningStacks = a_vm->allRunningStacks;
//_MESSAGE("allRunningStacks size: %d", runningStacks.size());
//for (auto entry = runningStacks.begin(); entry != runningStacks.end(); ++entry) {
//_MESSAGE("allRunningStacks %d", entry->first);
//}
//a_vm->DispatchMethodCall(object, RE::BSFixedString("Enable"), RE::MakeFunctionArguments<>(), RE::BSScript::IStackCallbackFunctor::IStackCallbackFunctor())
}
else {
logger::info(FMT_STRING("LoadInteriorRefList lookup ref not found, ref_mod_name: {}, ref_local_form_id: {:x}"), ref.ref_mod_name, ref.ref_local_form_id);
@ -322,14 +257,6 @@ bool LoadInteriorRefListImpl(RE::BSFixedString api_url, RE::BSFixedString api_ke
return false;
}
//RE::TESForm * gold = RE::TESForm::LookupByID(15);
//_MESSAGE("Gold form name: %s", gold->GetName());
//_MESSAGE("Gold form id: %d", gold->GetFormID());
//using func_t = decltype(&PlaceAtMe);
//REL::Offset<func_t> func{ REL::ID(55672) };
//RE::TESObjectREFR * new_ref = func(RE::BSScript::Internal::VirtualMachine::GetSingleton(), 1, player, gold, 50, false, false);
//_MESSAGE("New ref initially disabled: %d", new_ref->IsDisabled());
//_MESSAGE("New ref persistent: %d", new_ref->loadedData->flags & RE::TESObjectREFR::RecordFlags::kPersistent);
return true;
}
@ -345,8 +272,6 @@ bool LoadInteriorRefList(RE::StaticFunctionTag*, RE::BSFixedString api_url, RE::
return false;
}
// LoadInteriorRefListImpl(api_url, api_key, interior_ref_list_id, target_ref, quest);
// TODO: making this async causes a crash
std::thread thread(LoadInteriorRefListImpl, api_url, api_key, interior_ref_list_id, target_ref, quest);
thread.detach();
return true;

View File

@ -2,7 +2,7 @@
#include "NativeFunctions.h"
// TODO: replace "placeholder" with "buy_activator" and "ref" with "item_ref"
// TODO: should I replace "placeholder" with "buy_activator" and "ref" with "item_ref"?
bool ClearMerchandiseImpl(RE::TESObjectREFR* merchant_chest, RE::TESObjectREFR* merchant_shelf, RE::TESForm* placeholder_static, RE::BGSKeyword * shelf_keyword, RE::BGSKeyword * item_keyword)
{
logger::info("Entered ClearMerchandiseImpl");
@ -27,23 +27,12 @@ bool ClearMerchandiseImpl(RE::TESObjectREFR* merchant_chest, RE::TESObjectREFR*
if (linked_ref) {
logger::info(FMT_STRING("ClearMerchandise deleting ref linked to placeholder ref: {:x}"), (uint32_t)linked_ref->GetFormID());
// TODO: should I use the MemoryManager to free these references?
// linked_ref->Load3D(false);
// linked_ref->SetPosition(linked_ref->GetPosition() -= RE::NiPoint3(-10000, -10000, -10000));
// linked_ref->Update3DPosition(false);
// linked_ref->Set3D(ref->GetCurrent3D());
// linked_ref->Release3DRelatedData();
linked_ref->Disable(); // disabling first is required to prevent CTD on unloading cell
linked_ref->SetDelete(true);
// linked_ref->DeleteThis(); // does this do anything?
}
logger::info(FMT_STRING("ClearMerchandise deleting existing placeholder ref: {:x}"), (uint32_t)ref->GetFormID());
// ref->Load3D(false);
// ref->SetPosition(ref->GetPosition() -= RE::NiPoint3(-10000, -10000, -10000));
// ref->Update3DPosition(false);
// ref->Release3DRelatedData();
ref->Disable(); // disabling first is required to prevent CTD on unloading cell
ref->SetDelete(true);
// ref->DeleteThis(); // does this do anything?
cell->references.erase(*entry++); // prevents slowdowns after many runs of ClearMerchandise
}
else {
@ -171,10 +160,8 @@ bool LoadMerchandiseImpl(
logger::info(FMT_STRING("LoadMerchandise ref bounds min: {:.2f} {:.2f} {:.2f}, max: {:.2f} {:.2f} {:.2f}"), bound_min.x, bound_min.y, bound_min.z, bound_max.x, bound_max.y, bound_max.z);
RE::ExtraLinkedRef * extra_linked_ref = (RE::ExtraLinkedRef*)RE::BSExtraData::Create(sizeof(RE::ExtraLinkedRef), extra_linked_ref_vtbl.address());
// RE::BGSKeywordForm * place_keyword1 = data_handler->LookupForm<RE::BGSKeywordForm>(595228, "BazaarRealm.esm");
extra_linked_ref->linkedRefs.push_back({shelf_keyword, merchant_shelf});
placeholder_ref->extraList.Add(extra_linked_ref);
// _MESSAGE("PLACEHOLDER LINKED REF: %s", placeholder_ref->GetLinkedRef(nullptr)->GetName());
// This extra count stored on the placeholder_ref indicates the quanity of the merchandise item it is linked to
RE::ExtraCount * extra_page_num = (RE::ExtraCount*)RE::BSExtraData::Create(sizeof(RE::ExtraCount), RE::Offset::ExtraCount::Vtbl.address());
@ -240,85 +227,10 @@ bool LoadMerchandiseImpl(
}
MoveTo_Native(ref, ref->CreateRefHandle(), cell, cell->worldSpace, ref_position - RE::NiPoint3(10000, 10000, 10000), ref_angle);
MoveTo_Native(placeholder_ref, placeholder_ref->CreateRefHandle(), cell, cell->worldSpace, ref_position, ref_angle);
// ref->Load3D(false);
// Note: passing false to this method occasionally causes the game to crash due to access violation
// RE::NiAVObject * obj_3d = ref->Load3D(true);
// None of this works, havok is still applied, which isn't that bad really
// _MESSAGE("objectReference: %x, GetBaseObject: %x", *ref->data.objectReference, *ref->GetBaseObject());
// RE::NiAVObject * cloned_obj_3d = ref->data.objectReference->Clone3D(placeholder_ref, false);
// _MESSAGE("loaded 3d: %x, cloned 3d: %x", *obj_3d, *cloned_obj_3d);
// Need to Load3D() before calling this:
// ref->SetMotionType(RE::TESObjectREFR::MotionType::kKeyframed);
// obj_3d->SetMotionType(static_cast<uint32_t>(RE::TESObjectREFR::MotionType::kKeyframed));
// obj_3d->SetMotionType(5);
// Fails if loadedData is nullptr (if Load3D is not called first):
// ref->loadedData->flags = ref->loadedData->flags | RE::TESObjectREFR::RecordFlags::kDontHavokSettle | RE::TESObjectREFR::RecordFlags::kCollisionsDisabled | RE::TESObjectREFR::RecordFlags::kCollisionsDisabled;
// ref->InitHavok();
/// ref->DetachHavok(obj_3d);
// ref->SetCollision(false);
// ref->ClampToGround();
// placeholder_ref->Load3D(false);
// RE::NiPointer<RE::NiAVObject> placeholder_3d_data = placeholder_ref->loadedData->data3D;
// _MESSAGE("PLACEHOLDER 3D (pre-set-3d): %x", placeholder_3d_data.get());
// placeholder_ref->Set3D(obj_3d); // steal the 3D model from the item ref
// RE::ExtraLight * x_light = ref->extraList.GetByType<RE::ExtraLight>();
// if (x_light) {
// _MESSAGE("ExtraLight exists on ref: %x", x_light);
// ref->extraList.RemoveByType(RE::ExtraDataType::kLight);
// x_light = ref->extraList.GetByType<RE::ExtraLight>();
// if (!x_light) {
// _MESSAGE("ExtraLight removed");
// }
// else {
// _MESSAGE("After removing ExtraLight: %x", x_light);
// }
// }
// x_light = placeholder_ref->extraList.GetByType<RE::ExtraLight>();
// if (x_light) {
// _MESSAGE("ExtraLight exists on placeholder_ref: %x", x_light);
// placeholder_ref->extraList.RemoveByType(RE::ExtraDataType::kLight);
// x_light = placeholder_ref->extraList.GetByType<RE::ExtraLight>();
// if (!x_light) {
// _MESSAGE("ExtraLight removed");
// }
// else {
// _MESSAGE("After removing ExtraLight: %x", x_light);
// }
// }
RE::BSFixedString name = RE::BSFixedString::BSFixedString(ref->GetName());
placeholder_ref->SetDisplayName(name, true);
// placeholder_ref->SetObjectReference(base);
placeholder_ref->extraList.SetOwner(base); // I'm abusing "owner" to link the activator with the Form that should be bought once activated
// Do I still need to set this flag? I could maybe use the deleted flag instead
// uint32_t phantom_ref_flag = 1 << 9; // this is my own made up ExtraFlags::Flag that marks the reference we stole the 3D from as needing to be deleted at the start of the next LoadMerchandise
// RE::ExtraFlags * x_flags = ref->extraList.GetByType<RE::ExtraFlags>();
// RE::ExtraFlags::Flag new_flags;
// if (x_flags) {
// _MESSAGE("REF XFLAGS pre-set: %x", x_flags->flags);
// new_flags = (RE::ExtraFlags::Flag)((uint32_t)(x_flags->flags) | phantom_ref_flag);
// }
// else {
// new_flags = (RE::ExtraFlags::Flag)phantom_ref_flag;
// }
//ref->extraList.SetExtraFlags(new_flags, true);
// x_flags = ref->extraList.GetByType<RE::ExtraFlags>();
extra_linked_ref->linkedRefs.push_back({item_keyword, ref});
// _MESSAGE("REF XFLAGS post-set: %x", x_flags->flags);
// Test deleting ref that owns 3d
// ref->Disable(); // disabling first is required to prevent CTD on unloading cell
// ref->SetDelete(true);
// ref->Predestroy();
// ref->formFlags |= RE::TESObjectREFR::RecordFlags::kDeleted;
// ref->AddChange(RE::TESObjectREFR::ChangeFlags::kItemExtraData);
// ref->AddChange(RE::TESObjectREFR::ChangeFlags::kGameOnlyExtra);
// ref->AddChange(RE::TESObjectREFR::ChangeFlags::kCreatedOnlyExtra);
// placeholder_ref->inGameFormFlags |= RE::TESObjectREFR::InGameFormFlag::kWantsDelete;
// placeholder_ref->AddChange(RE::TESObjectREFR::ChangeFlags::kGameOnlyExtra);
}
// I'm abusing the ExtraCount ExtraData type for storing the current page number state of the shelf
@ -367,10 +279,6 @@ bool LoadMerchandiseImpl(
else {
prev_ref->SetDisplayName(fmt::format("Back to page {:d}", page - 1).c_str(), true);
}
// auto messaging = SKSE::GetModCallbackEventSource();
// const SKSE::ModCallbackEvent event = { RE::BSFixedString("BazaarRealm_LoadMerchandiseDone"), RE::BSFixedString(""), 0, nullptr };
// messaging->SendEvent(&event);
// a_vm->SendEventAll(RE::BSFixedString("BazaarRealm_LoadMerchandiseDone"), RE::MakeFunctionArguments());
}
else {
const char * error = result.AsErr();
@ -561,7 +469,6 @@ RE::TESForm * BuyMerchandise(RE::StaticFunctionTag*, RE::TESObjectREFR * merchan
logger::info(FMT_STRING("BuyMerchandise owner: {}"), owner->GetName());
logger::info(FMT_STRING("BuyMerchandise count: {:d}"), merchandise_placeholder->extraList.GetCount());
// TODO: do add item here
// player->AddObjectToContainer(owner, *RE::ExtraDataList::ExtraDataList(), 1, merchandise_placeholder)
return owner;
}
@ -633,7 +540,6 @@ int CreateMerchandiseListImpl(RE::BSFixedString api_url, RE::BSFixedString api_k
const char * mod_name = file->fileName;
bool is_light = file->recordFlags.all(RE::TESFile::RecordFlag::kSmallFile);
uint32_t local_form_id = is_light ? form_id & 0xfff : form_id & 0xFFFFFF;
//_MESSAGE("FILE: %s isLight: %d formID: 0x%x localFormId: 0x%x", file_name, is_light, form_id, local_form_id);
logger::info(FMT_STRING("CreateMerchandiseList base form file_name: {}, local_form_id"), mod_name, local_form_id);