Skip to content

Commit

Permalink
Merge pull request #5 from spelunky-fyi/more.build.in.types
Browse files Browse the repository at this point in the history
More build in types and structs
  • Loading branch information
Mr-Auto authored Jun 28, 2024
2 parents 4dd195f + 0b660a4 commit 357e5ca
Show file tree
Hide file tree
Showing 71 changed files with 3,265 additions and 2,085 deletions.
19 changes: 16 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ find_package(Qt5Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
if(QT_NAMESPACE)
add_definitions(-DQT_NAMESPACE=${QT_NAMESPACE})
add_definitions(-DQT_NAMESPACE=${QT_NAMESPACE})
endif()


Expand Down Expand Up @@ -60,6 +60,9 @@ x64dbg_plugin(${PROJECT_NAME}
include/Data/Logger.h
include/Data/StdString.h
include/Data/StdMap.h
include/Data/EntityList.h
include/Data/StdList.h
include/Data/StdUnorderedMap.h
include/Views/ViewToolbar.h
include/Views/ViewEntityDB.h
include/Views/ViewParticleDB.h
Expand All @@ -77,6 +80,10 @@ x64dbg_plugin(${PROJECT_NAME}
include/Views/ViewJournalPage.h
include/Views/ViewThreads.h
include/Views/ViewStdMap.h
include/Views/ViewStdUnorderedMap.h
include/Views/ViewStdList.h
include/Views/ViewEntityList.h
include/Views/ViewEntityFactory.h
include/QtHelpers/StyledItemDelegateHTML.h
include/QtHelpers/StyledItemDelegateColorPicker.h
include/QtHelpers/TreeViewMemoryFields.h
Expand All @@ -99,9 +106,11 @@ x64dbg_plugin(${PROJECT_NAME}
include/QtHelpers/WidgetSampling.h
include/QtHelpers/WidgetSamplesPlot.h
include/QtHelpers/ItemModelLoggerSamples.h
include/QtHelpers/WidgetDatabaseView.h
include/QtHelpers/AbstractDatabaseView.h
include/QtHelpers/AbstractContainerView.h
include/QtHelpers/WidgetAutorefresh.h
include/QtHelpers/LongLongSpinBox.h
include/QtHelpers/WidgetPagination.h
src/Spelunky2.cpp
src/Configuration.cpp
src/Data/EntityDB.cpp
Expand Down Expand Up @@ -129,8 +138,11 @@ x64dbg_plugin(${PROJECT_NAME}
src/Views/ViewVirtualFunctions.cpp
src/Views/ViewStdVector.cpp
src/Views/ViewStdMap.cpp
src/Views/ViewStdUnorderedMap.cpp
src/Views/ViewStdList.cpp
src/Views/ViewJournalPage.cpp
src/Views/ViewThreads.cpp
src/Views/ViewEntityList.cpp
src/QtHelpers/StyledItemDelegateHTML.cpp
src/QtHelpers/TreeViewMemoryFields.cpp
src/QtHelpers/WidgetMemoryView.cpp
Expand All @@ -148,7 +160,8 @@ x64dbg_plugin(${PROJECT_NAME}
src/QtHelpers/ItemModelLoggerFields.cpp
src/QtHelpers/WidgetSamplesPlot.cpp
src/QtHelpers/ItemModelLoggerSamples.cpp
src/QtHelpers/WidgetDatabaseView.cpp
src/QtHelpers/AbstractDatabaseView.cpp
src/QtHelpers/AbstractContainerView.cpp
src/QtHelpers/WidgetAutorefresh.cpp
${CMAKE_CURRENT_BINARY_DIR}/include/pluginconfig.h
resources/spelunky2.qrc
Expand Down
78 changes: 54 additions & 24 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ namespace S2Plugin
constexpr uint16_t gsRoleStdContainerFirstParameterType = Qt::UserRole + 8;
constexpr uint16_t gsRoleStdContainerSecondParameterType = Qt::UserRole + 9;
constexpr uint16_t gsRoleSize = Qt::UserRole + 10;
constexpr uint16_t gsRoleEntityAddress = Qt::UserRole + 11; // for entity uid to not look for the uid twice
constexpr uint16_t gsRoleColumns = Qt::UserRole + 11; // for Matrix
constexpr uint16_t gsRoleEntityAddress = Qt::UserRole + 12; // for entity uid to not look for the uid twice

// new types need to be added to
// - the MemoryFieldType enum
Expand All @@ -69,6 +70,7 @@ namespace S2Plugin
Dummy, // dummy type for uses like fake parent type in StdMap
CodePointer,
DataPointer,
OnHeapPointer,
Byte,
UnsignedByte,
Word,
Expand All @@ -88,9 +90,14 @@ namespace S2Plugin
State32, // this is signed, can be negative!
Skip,
GameManager,
GameAPI,
Hud,
EntityFactory,
State,
SaveGame,
LevelGen,
LiquidPhysics,
LiquidPhysicsPointer,
EntityDB,
EntityPointer,
EntityDBPointer,
Expand Down Expand Up @@ -126,6 +133,12 @@ namespace S2Plugin
Online,
IPv4Address,
Double,
Array,
Matrix,
EntityList,
OldStdList,
StdList,
StdUnorderedMap,
};

struct VirtualFunction
Expand All @@ -139,7 +152,7 @@ namespace S2Plugin
VirtualFunction(size_t i, std::string n, std::string p, std::string r, std::string t) : index(i), name(n), params(p), returnValue(r), type(t){};
};

struct MemoryField
struct MemoryField // TODO this got big over time, consider size optimaizations
{
std::string name;
MemoryFieldType type{MemoryFieldType::None};
Expand All @@ -148,11 +161,21 @@ namespace S2Plugin
// jsonName only if applicable: if a type is not a MemoryFieldType, but fully defined in the json file
// then save its name so we can compare later
std::string jsonName;
// parameter types for stuff like vectors, maps etc.
std::string firstParameterType;
std::string secondParameterType;
std::string comment;
// size in bytes
size_t get_size() const;
union
{
// length, size of array etc.
size_t numberOfElements{0};
// row count for matrix
size_t rows;
};
// column count for matrix
size_t columns{0};

// For checking duplicate names
bool operator==(const MemoryField& other) const
Expand Down Expand Up @@ -186,7 +209,7 @@ namespace S2Plugin
{
return get() != nullptr;
}

// Accessors
const std::unordered_map<std::string, std::string>& entityClassHierarchy() const noexcept
{
return mEntityClassHierarchy;
Expand All @@ -195,6 +218,19 @@ namespace S2Plugin
{
return mDefaultEntityClassTypes;
}
const EntityNamesList& entityList() const noexcept
{
return entityNames;
}
const ParticleEmittersList& particleEmittersList() const noexcept
{
return particleEmitters;
}
const std::vector<std::string>& getJournalPageNames() const noexcept
{
return mJournalPages;
}
//
std::vector<std::string> classHierarchyOfEntity(const std::string& entityName) const;

const std::vector<MemoryField>& typeFields(const MemoryFieldType& type) const;
Expand All @@ -209,42 +245,36 @@ namespace S2Plugin
static std::string_view getTypeDisplayName(MemoryFieldType type);
static size_t getBuiltInTypeSize(MemoryFieldType type);
static bool isPointerType(MemoryFieldType type);
MemoryField nameToMemoryField(const std::string& typeName) const;

uintptr_t offsetForField(const std::vector<MemoryField>& fields, std::string_view fieldUID, uintptr_t base_addr = 0) const;
uintptr_t offsetForField(MemoryFieldType type, std::string_view fieldUID, uintptr_t base_addr = 0) const;

// equivalent to alignof operator
int getAlingment(const std::string& type) const;
bool isPermanentPointer(const std::string& type) const
{
return std::find(mPointerTypes.begin(), mPointerTypes.end(), type) != mPointerTypes.end();
}
bool isJsonStruct(const std::string type) const
{
return mTypeFieldsStructs.find(type) != mTypeFieldsStructs.end();
}
uint8_t getAlingment(const std::string& type) const;
uint8_t getAlingment(MemoryFieldType type) const;
uint8_t getAlingment(const MemoryField& type) const;

std::string flagTitle(const std::string& fieldName, uint8_t flagNumber) const;
std::string stateTitle(const std::string& fieldName, int64_t state) const;
const std::vector<std::pair<int64_t, std::string>>& refTitlesOfField(const std::string& fieldName) const;

size_t getTypeSize(const std::string& typeName, bool entitySubclass = false);
const EntityList& entityList() const
{
return entityNames;
};

const ParticleEmittersList& particleEmittersList() const
{
return particleEmitters;
}

RoomCode roomCodeForID(uint16_t code) const;
std::string getEntityName(uint32_t type) const;

const std::vector<std::string>& getJournalPageNames()
bool isPermanentPointer(const std::string& type) const
{
return mJournalPages;
return std::find(mPointerTypes.begin(), mPointerTypes.end(), type) != mPointerTypes.end();
}
bool isPermanentPointer(const std::string_view type) const
{
return std::find(mPointerTypes.begin(), mPointerTypes.end(), type) != mPointerTypes.end();
}
bool isJsonStruct(const std::string& type) const
{
return mTypeFieldsStructs.find(type) != mTypeFieldsStructs.end();
}

private:
Expand Down Expand Up @@ -275,7 +305,7 @@ namespace S2Plugin
void processRoomCodesJSON(nlohmann::ordered_json& json);
MemoryField populateMemoryField(const nlohmann::ordered_json& field, const std::string& struct_name);

EntityList entityNames;
EntityNamesList entityNames;
ParticleEmittersList particleEmitters;

Configuration();
Expand Down
2 changes: 1 addition & 1 deletion include/Data/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace S2Plugin
class Entity
{
public:
Entity(uintptr_t addr) : mEntityPtr(addr){};
explicit Entity(uintptr_t addr) : mEntityPtr(addr){};
Entity() = delete;

std::string entityClassName() const;
Expand Down
Loading

0 comments on commit 357e5ca

Please sign in to comment.