Skip to content

Commit

Permalink
some post self review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Auto committed Jun 16, 2024
1 parent b0757ce commit d79bdf6
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 109 deletions.
1 change: 0 additions & 1 deletion include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ namespace S2Plugin
private:
size_t size{0};
friend class Configuration;
friend class ViewMatrix;
};

struct RoomCode
Expand Down
205 changes: 103 additions & 102 deletions include/Data/EntityList.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,108 +33,109 @@ namespace S2Plugin
{
return mSize;
}
struct Iterator
{
// Iterator(){};
explicit Iterator(const EntityList entityList, uint32_t index) noexcept : Iterator(entityList.begin())
{
advance(index);
}
void advance(int count) noexcept // should probably be int64
{
addr.first += count * sizeof(uintptr_t);
addr.second += count * sizeof(uint32_t);
}
Iterator& operator++() noexcept
{
advance(1);
return *this;
}
Iterator operator++(int) noexcept
{
auto copy = *this;
advance(1);
return copy;
}
Iterator& operator--() noexcept
{
advance(-1);
}
Iterator operator--(int) noexcept
{
auto copy = *this;
advance(-1);
return copy;
}
std::pair<uintptr_t, uint32_t> operator*() const
{
return {addr.first, Script::Memory::ReadDword(addr.second)};
}
bool operator==(const Iterator& other) const noexcept
{
return addr.first == other.addr.first;
}
bool operator!=(const Iterator& other) const noexcept
{
return addr.first != other.addr.first;
}
uintptr_t entityRaw() const
{
return Script::Memory::ReadQword(addr.first);
}
Entity entity() const
{
return Entity{Script::Memory::ReadQword(addr.first)};
}
uint32_t uid() const
{
return Script::Memory::ReadDword(addr.second);
}

private:
explicit Iterator(uintptr_t entitiesAddress, uintptr_t uidsAddress) : addr(entitiesAddress, uidsAddress){};
std::pair<uintptr_t, uintptr_t> addr;
friend class EntityList;
};

Iterator begin() const
{
return Iterator{entities(), uids()};
}
Iterator end() const
{
uintptr_t entitiesEnd = entities() + size() * sizeof(uintptr_t);
uintptr_t uidsEnd = uids() + size() * sizeof(uint32_t);
return Iterator{entitiesEnd, uidsEnd};
}
const Iterator cbegin() const
{
return begin();
}
const Iterator cend() const
{
return end();
}
Iterator find(uint32_t uid) const
{
auto endIterator = end();
for (auto it = begin(); it != endIterator; ++it)
{
if (it.uid() == uid)
return it;
}
return endIterator;
}
Iterator findEntity(uintptr_t addr) const
{
auto endIterator = end();
for (auto it = begin(); it != endIterator; ++it)
{
if (it.entityRaw() == addr)
return it;
}
return endIterator;
}
// prefer getting whole struct as it's much faster then calling read multiple times
// struct Iterator
//{
// // Iterator(){};
// explicit Iterator(const EntityList entityList, uint32_t index) noexcept : Iterator(entityList.begin())
// {
// advance(index);
// }
// void advance(int count) noexcept // should probably be int64
// {
// addr.first += count * sizeof(uintptr_t);
// addr.second += count * sizeof(uint32_t);
// }
// Iterator& operator++() noexcept
// {
// advance(1);
// return *this;
// }
// Iterator operator++(int) noexcept
// {
// auto copy = *this;
// advance(1);
// return copy;
// }
// Iterator& operator--() noexcept
// {
// advance(-1);
// }
// Iterator operator--(int) noexcept
// {
// auto copy = *this;
// advance(-1);
// return copy;
// }
// std::pair<uintptr_t, uint32_t> operator*() const
// {
// return {addr.first, Script::Memory::ReadDword(addr.second)};
// }
// bool operator==(const Iterator& other) const noexcept
// {
// return addr.first == other.addr.first;
// }
// bool operator!=(const Iterator& other) const noexcept
// {
// return addr.first != other.addr.first;
// }
// uintptr_t entityRaw() const
// {
// return Script::Memory::ReadQword(addr.first);
// }
// Entity entity() const
// {
// return Entity{Script::Memory::ReadQword(addr.first)};
// }
// uint32_t uid() const
// {
// return Script::Memory::ReadDword(addr.second);
// }
//
// private:
// explicit Iterator(uintptr_t entitiesAddress, uintptr_t uidsAddress) : addr(entitiesAddress, uidsAddress){};
// std::pair<uintptr_t, uintptr_t> addr;
// friend class EntityList;
//};
//
// Iterator begin() const
//{
// return Iterator{entities(), uids()};
// }
// Iterator end() const
//{
// uintptr_t entitiesEnd = entities() + size() * sizeof(uintptr_t);
// uintptr_t uidsEnd = uids() + size() * sizeof(uint32_t);
// return Iterator{entitiesEnd, uidsEnd};
// }
// const Iterator cbegin() const
//{
// return begin();
// }
// const Iterator cend() const
//{
// return end();
// }
// Iterator find(uint32_t uid) const
//{
// auto endIterator = end();
// for (auto it = begin(); it != endIterator; ++it)
// {
// if (it.uid() == uid)
// return it;
// }
// return endIterator;
// }
// Iterator findEntity(uintptr_t addr) const
//{
// auto endIterator = end();
// for (auto it = begin(); it != endIterator; ++it)
// {
// if (it.entityRaw() == addr)
// return it;
// }
// return endIterator;
// }
std::vector<uintptr_t> getAllEntities() const
{
std::vector<uintptr_t> result;
Expand Down
1 change: 1 addition & 0 deletions include/QtHelpers/WidgetPagination.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QSpinBox>
#include <QStringList>
#include <QWidget>
#include <cstdint>
#include <vector>

namespace S2Plugin
Expand Down
6 changes: 1 addition & 5 deletions src/QtHelpers/TreeViewMemoryFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ QTreeView::branch:open:has-children:has-siblings {
})");

QObject::connect(this, &QTreeView::clicked, this, &TreeViewMemoryFields::cellClicked);
// QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
// setFont(font);
}

void S2Plugin::TreeViewMemoryFields::addMemoryFields(const std::vector<MemoryField>& fields, const std::string& mainName, uintptr_t structAddr, size_t initialDelta, uint8_t deltaPrefixCount,
Expand Down Expand Up @@ -162,8 +160,6 @@ QStandardItem* S2Plugin::TreeViewMemoryFields::addMemoryField(const MemoryField&
typeName += "StdSet";
else if (field.type == MemoryFieldType::StdUnorderedMap && field.secondParameterType.empty()) // exception
typeName += "StdUnorderedSet";
// else if (field.type == MemoryFieldType::Dummy)
// typeName = "";
else if (auto str = Configuration::getTypeDisplayName(field.type); !str.empty())
typeName += QString::fromUtf8(str.data(), static_cast<int>(str.size()));
else
Expand Down Expand Up @@ -2155,7 +2151,7 @@ void S2Plugin::TreeViewMemoryFields::updateRow(int row, std::optional<uintptr_t>
{
std::optional<uint32_t> comparisonValue;
auto addr = valueComparisonMemoryOffset == 0 ? 0 : valueComparisonMemoryOffset + 0x14;
comparisonValue = updateField<uint32_t>(itemField, addr, itemComparisonValue, nullptr, nullptr, true, nullptr, true, false, highlightColor);
comparisonValue = updateField<uint32_t>(itemField, addr, itemComparisonValue, nullptr, nullptr, true, nullptr, false, false, highlightColor);
if (comparisonValue.has_value())
{
if (comparisonValue.value() == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Views/ViewEntityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ S2Plugin::ViewEntityList::ViewEntityList(uintptr_t address, QWidget* parent) : m
mEntityField.isPointer = true;
mEntityField.type = MemoryFieldType::EntityPointer;

mMainTreeView->activeColumns.disable(gsColComparisonValue).disable(gsColComparisonValueHex).disable(gsColComment); //.disable(gsColMemoryAddressDelta).disable(gsColMemoryAddress);
mMainTreeView->activeColumns.disable(gsColComparisonValue).disable(gsColComparisonValueHex).disable(gsColComment);
mMainTreeView->updateTableHeader(false);
mMainTreeView->setColumnWidth(gsColField, 120);
mMainTreeView->setColumnWidth(gsColValueHex, 125);
Expand Down

0 comments on commit d79bdf6

Please sign in to comment.