Skip to content

Commit

Permalink
feat: debug TESContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed Dec 2, 2021
1 parent 114c7bd commit 0c48cc5
Showing 1 changed file with 97 additions and 57 deletions.
154 changes: 97 additions & 57 deletions Code/client/Services/Generic/TestService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,87 +936,127 @@ void TestService::OnDraw() noexcept
ImGui::SetNextWindowSize(ImVec2(250, 300), ImGuiCond_FirstUseEver);
ImGui::Begin("Container debug");

static uint32_t s_selectedInvFormId = 0;
static uint32_t s_selectedInv = 0;

auto* pContainerActor = PlayerCharacter::Get();
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
{
if (ImGui::BeginTabItem("ExtraContainerChanges"))
{
static uint32_t s_selectedInvFormId = 0;

ImGui::BeginChild("Items", ImVec2(0, 200), true);
auto* pContainerActor = PlayerCharacter::Get();

const auto pContainerChanges = pContainerActor->GetContainerChanges()->entries;
const auto pContainerChanges = pContainerActor->GetContainerChanges()->entries;

int i = 0;
for (auto pChange : *pContainerChanges)
{
if (pChange && pChange->form && pChange->dataList)
{
char name[256];
sprintf_s(name, std::size(name), "%x", pChange->form->formID);
ImGui::BeginChild("Items", ImVec2(0, 200), true);

if (ImGui::Selectable(name, s_selectedInvFormId == pChange->form->formID))
int i = 0;
for (auto pChange : *pContainerChanges)
{
s_selectedInvFormId = pChange->form->formID;
if (pChange && pChange->form && pChange->dataList)
{
char name[256];
sprintf_s(name, std::size(name), "%x", pChange->form->formID);

if (ImGui::Selectable(name, s_selectedInvFormId == pChange->form->formID))
{
s_selectedInvFormId = pChange->form->formID;
}
}
}
}
}

ImGui::EndChild();
ImGui::EndChild();

int itemCount = 0;
int dataListCount = 0;
int itemCount = 0;
int dataListCount = 0;

ImVec4 red{255.f, 0.f, 0.f, 255.f};
ImVec4 green{0.f, 255.f, 0.f, 255.f};
ImVec4 red{255.f, 0.f, 0.f, 255.f};
ImVec4 green{0.f, 255.f, 0.f, 255.f};

for (auto pChange : *pContainerChanges)
{
if (pChange && pChange->form && pChange->form->formID == s_selectedInvFormId)
for (auto pChange : *pContainerChanges)
{
if (pChange && pChange->form && pChange->form->formID == s_selectedInvFormId)
{
itemCount++;

const auto pDataLists = pChange->dataList;
for (auto* pDataList : *pDataLists)
{
if (pDataList)
{
dataListCount++;

char name[256];
sprintf_s(name, std::size(name), "Item %d", itemCount);

if (ImGui::CollapsingHeader(name, ImGuiTreeNodeFlags_DefaultOpen))
{
BSScopedLock<BSRecursiveLock> _(pDataList->lock);

bool charge = pDataList->Contains(ExtraData::Charge);
ImGui::TextColored(charge ? green : red, "charge");
bool count = pDataList->Contains(ExtraData::Count);
ImGui::TextColored(count ? green : red, "count");
bool enchantment = pDataList->Contains(ExtraData::Enchantment);
ImGui::TextColored(enchantment ? green : red, "enchantment");
bool health = pDataList->Contains(ExtraData::Health);
ImGui::TextColored(health ? green : red, "health");
bool poison = pDataList->Contains(ExtraData::Poison);
ImGui::TextColored(poison ? green : red, "poison");
bool soul = pDataList->Contains(ExtraData::Soul);
ImGui::TextColored(soul ? green : red, "soul");
bool textDisplayData = pDataList->Contains(ExtraData::TextDisplayData);
ImGui::TextColored(textDisplayData ? green : red, "textDisplayData");
bool worn = pDataList->Contains(ExtraData::Worn);
ImGui::TextColored(worn ? green : red, "worn");
bool wornLeft = pDataList->Contains(ExtraData::WornLeft);
ImGui::TextColored(wornLeft ? green : red, "wornLeft");
}
}
}
}
}

if (ImGui::CollapsingHeader("Metadata", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::InputInt("Item count", &itemCount, 0, 0, ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_CharsHexadecimal);
ImGui::InputInt("Data list count", &dataListCount, 0, 0, ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_CharsHexadecimal);
}

ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("TESContainer"))
{
itemCount++;
static uint32_t s_selectedInvFormId = 0;

const auto pDataLists = pChange->dataList;
for (auto* pDataList : *pDataLists)
PlayerCharacter* pPlayer = PlayerCharacter::Get();
TESContainer* pContainer = pPlayer->GetContainer();
if (pContainer && pContainer->entries)
{
if (pDataList)
ImGui::Text("Items (%d)", pContainer->count);

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

for (int i = 0; i < pContainer->count; ++i)
{
dataListCount++;
auto pEntry = pContainer->entries[i];
if (!pEntry || !pEntry->form)
continue;

char name[256];
sprintf_s(name, std::size(name), "Item %d", itemCount);
sprintf_s(name, std::size(name), "%x (%d)", pEntry->form->formID, pEntry->count);

if (ImGui::CollapsingHeader(name, ImGuiTreeNodeFlags_DefaultOpen))
if (ImGui::Selectable(name, s_selectedInvFormId == pEntry->form->formID))
{
BSScopedLock<BSRecursiveLock> _(pDataList->lock);

bool charge = pDataList->Contains(ExtraData::Charge);
ImGui::TextColored(charge ? green : red, "charge");
bool count = pDataList->Contains(ExtraData::Count);
ImGui::TextColored(count ? green : red, "count");
bool enchantment = pDataList->Contains(ExtraData::Enchantment);
ImGui::TextColored(enchantment ? green : red, "enchantment");
bool health = pDataList->Contains(ExtraData::Health);
ImGui::TextColored(health ? green : red, "health");
bool poison = pDataList->Contains(ExtraData::Poison);
ImGui::TextColored(poison ? green : red, "poison");
bool soul = pDataList->Contains(ExtraData::Soul);
ImGui::TextColored(soul ? green : red, "soul");
bool textDisplayData = pDataList->Contains(ExtraData::TextDisplayData);
ImGui::TextColored(textDisplayData ? green : red, "textDisplayData");
bool worn = pDataList->Contains(ExtraData::Worn);
ImGui::TextColored(worn ? green : red, "worn");
bool wornLeft = pDataList->Contains(ExtraData::WornLeft);
ImGui::TextColored(wornLeft ? green : red, "wornLeft");
s_selectedInvFormId = pEntry->form->formID;
}
}

ImGui::EndChild();
}

ImGui::EndTabItem();
}
}

if (ImGui::CollapsingHeader("Metadata", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::InputInt("Item count", &itemCount, 0, 0, ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_CharsHexadecimal);
ImGui::InputInt("Data list count", &dataListCount, 0, 0, ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_CharsHexadecimal);
}

ImGui::End();
#endif
Expand Down

0 comments on commit 0c48cc5

Please sign in to comment.