Skip to content

Commit

Permalink
fix: definitively fix WaitingFor3D bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Apr 7, 2022
1 parent fa02977 commit ef580ac
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Code/client/Components/WaitingFor3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
struct WaitingFor3D
{
WaitingFor3D() = default;

// This rather hacky thing is here because entt components seemingly can't be empty
uint8_t Placeholder{};
};
8 changes: 8 additions & 0 deletions Code/client/Games/Skyrim/TESObjectREFR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ExtraData/ExtraWornLeft.h>
#include <Forms/EnchantmentItem.h>
#include <EquipManager.h>
#include <DefaultObjectManager.h>

TP_THIS_FUNCTION(TActivate, void, TESObjectREFR, TESObjectREFR* apActivator, uint8_t aUnk1, TESBoundObject* apObjectToGet, int32_t aCount, char aDefaultProcessing);
TP_THIS_FUNCTION(TAddInventoryItem, void, TESObjectREFR, TESBoundObject* apItem, ExtraDataList* apExtraData, int32_t aCount, TESObjectREFR* apOldOwner);
Expand Down Expand Up @@ -466,7 +467,14 @@ void TESObjectREFR::AddOrRemoveItem(const Inventory::Entry& arEntry) noexcept
ExtraDataList* pExtraDataList = GetExtraDataFromItem(arEntry);

if (arEntry.Count > 0)
{
bool isWorn = pExtraDataList && pExtraDataList->Contains(ExtraData::Worn) && pObject->formType != FormType::Ammo;
AddObjectToContainer(pObject, pExtraDataList, arEntry.Count, nullptr);
/*
if (isWorn)
EquipManager::Get()->Equip(RTTI_CAST(this, TESObjectREFR, Actor), pObject, nullptr, 1, DefaultObjectManager::Get().rightEquipSlot, false, true, false, false);
*/
}
else if (arEntry.Count < 0)
{
spdlog::debug("Removing item {:X}, count {}", pObject->formID, -arEntry.Count);
Expand Down
12 changes: 7 additions & 5 deletions Code/client/Services/Debug/Views/FormDebugView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

void TestService::DrawFormDebugView()
{
static Actor* pActor = nullptr;
static TESObjectREFR* pRefr = nullptr;
static TESForm* pFetchForm = nullptr;

ImGui::InputScalar("Form ID", ImGuiDataType_U32, &m_formId, 0, 0, "%" PRIx32,
Expand All @@ -24,18 +24,20 @@ void TestService::DrawFormDebugView()
if (m_formId)
{
pFetchForm = TESForm::GetById(m_formId);
/*
if (pFetchForm)
pActor = RTTI_CAST(pFetchForm, TESForm, Actor);
*/
pRefr = RTTI_CAST(pFetchForm, TESForm, TESObjectREFR);
}
}

if (pFetchForm)
if (pRefr)
{
ImGui::InputScalar("Memory address", ImGuiDataType_U64, (void*)&pFetchForm, 0, 0, "%" PRIx64,
ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_ReadOnly);

char name[256];
sprintf_s(name, std::size(name), "%s (%x)", pRefr->baseForm->GetName(), pRefr->formID);
ImGui::InputText("Name", name, std::size(name), ImGuiInputTextFlags_ReadOnly);

/*
for (ActiveEffect* pEffect : *pActor->currentProcess->middleProcess->ActiveEffects)
{
Expand Down
16 changes: 0 additions & 16 deletions Code/client/Services/Generic/CharacterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1285,15 +1285,6 @@ void CharacterService::RunRemoteUpdates() const noexcept
FaceGenSystem::Update(m_world, pActor, faceGenComponent);
}

static std::chrono::steady_clock::time_point lastWaitingSpawnTime;
constexpr auto cDelay = 250ms;

const auto now = std::chrono::steady_clock::now();
if (now - lastWaitingSpawnTime < cDelay)
return;

lastWaitingSpawnTime = now;

auto waitingView = m_world.view<FormIdComponent, RemoteComponent, WaitingFor3D>();

StackAllocator<1 << 13> allocator;
Expand Down Expand Up @@ -1321,14 +1312,7 @@ void CharacterService::RunRemoteUpdates() const noexcept
}

for (auto entity : toRemove)
{
// TODO: this used to be remove(), but this didn't work.
// Maybe check if other remove() instances are also compromised?
// Update: erase() is causing crashes if it's not present
//m_world.erase<WaitingFor3D>(entity);
// Temp fix: put in a timer to at least mitigate the spam a bit
m_world.remove<WaitingFor3D>(entity);
}
}

void CharacterService::RunFactionsUpdates() const noexcept
Expand Down
50 changes: 48 additions & 2 deletions Code/client/Services/Generic/ScriptService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ void ScriptService::OnDraw() noexcept
DisplayNetObjects();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("World"))
if (ImGui::BeginTabItem("Actors"))
{
DisplayEntities();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Objects"))
{
DisplayObjects();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}

Expand Down Expand Up @@ -222,7 +227,7 @@ void ScriptService::DisplayEntities() noexcept
StackAllocator<1 << 12> allocator;
ScopedAllocator _{ allocator };

const auto view = m_world.view<FormIdComponent>();
const auto view = m_world.view<FormIdComponent>(entt::exclude<InteractiveObjectComponent>);

Vector<entt::entity> entities(view.begin(), view.end());

Expand Down Expand Up @@ -259,6 +264,47 @@ void ScriptService::DisplayEntities() noexcept
DisplayEntityPanel(entities[s_selected]);
}

// TODO: this stuff shouldn't really be here
void ScriptService::DisplayObjects() noexcept
{
static uint32_t s_selectedFormId = 0;
static uint32_t s_selected = 0;

StackAllocator<1 << 12> allocator;
ScopedAllocator _{ allocator };

const auto view = m_world.view<FormIdComponent, InteractiveObjectComponent>();

Vector<entt::entity> entities(view.begin(), view.end());

ImGui::Text("Object list (%d)", entities.size());

ImGui::BeginChild("Entities", ImVec2(0, 200), true);

int i = 0;
for(auto it : entities)
{
auto& formComponent = view.get<FormIdComponent>(it);
const auto pRefr = RTTI_CAST(TESForm::GetById(formComponent.Id), TESForm, TESObjectREFR);

if (!pRefr || !pRefr->baseForm)
continue;

char name[256];
sprintf_s(name, std::size(name), "%s (%x)", pRefr->baseForm->GetName(), formComponent.Id);

if (ImGui::Selectable(name, s_selectedFormId == formComponent.Id))
s_selectedFormId = formComponent.Id;

if(s_selectedFormId == formComponent.Id)
s_selected = i;

++i;
}

ImGui::EndChild();
}

void ScriptService::DisplayEntityPanel(entt::entity aEntity) noexcept
{
const auto pFormIdComponent = m_world.try_get<FormIdComponent>(aEntity);
Expand Down
1 change: 1 addition & 0 deletions Code/client/Services/ScriptService.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct ScriptService : ScriptStore

void DisplayNetObjects() noexcept;
void DisplayEntities() noexcept;
void DisplayObjects() noexcept;
void DisplayEntityPanel(entt::entity aEntity) noexcept;
void DisplayFormComponent(FormIdComponent& aFormComponent) const noexcept;
void DisplayLocalComponent(LocalComponent& aLocalComponent) const noexcept;
Expand Down

0 comments on commit ef580ac

Please sign in to comment.