Skip to content

Commit

Permalink
add OnHeapPointer, EntityFactory, separate LiquidPhysics to it's own …
Browse files Browse the repository at this point in the history
…window, some more GameAPI stuff
  • Loading branch information
Mr-Auto committed Jun 25, 2024
1 parent f8b6196 commit bee776c
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 25 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ x64dbg_plugin(${PROJECT_NAME}
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 Down
4 changes: 4 additions & 0 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace S2Plugin
Dummy, // dummy type for uses like fake parent type in StdMap
CodePointer,
DataPointer,
OnHeapPointer,
Byte,
UnsignedByte,
Word,
Expand All @@ -91,9 +92,12 @@ namespace S2Plugin
GameManager,
GameAPI,
Hud,
EntityFactory,
State,
SaveGame,
LevelGen,
LiquidPhysics,
LiquidPhysicsPointer,
EntityDB,
EntityPointer,
EntityDBPointer,
Expand Down
13 changes: 13 additions & 0 deletions include/Spelunky2.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,25 @@ namespace S2Plugin
uintptr_t get_HudPtr();
uintptr_t get_StatePtr() const
{
if (heapBaseAddr == 0)
return 0;

return heapBaseAddr + GAME_OFFSET::STATE;
};
uintptr_t get_LevelGenPtr() const
{
if (heapBaseAddr == 0)
return 0;

return heapBaseAddr + GAME_OFFSET::LEVEL_GEN;
};
uintptr_t get_LiquidEnginePtr() const
{
if (heapBaseAddr == 0)
return 0;

return heapBaseAddr + GAME_OFFSET::LIQUID_ENGINE;
}
uintptr_t get_HeapBase() const
{
return heapBaseAddr;
Expand Down
34 changes: 34 additions & 0 deletions include/Views/ViewEntityFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "Configuration.h"
#include "QtHelpers/TreeViewMemoryFields.h"
#include "Spelunky2.h"
#include "ViewStruct.h"
#include <QSize>
#include <QWidget>

namespace S2Plugin
{
class ViewEntityFactory : public ViewStruct
{
public:
explicit ViewEntityFactory(QWidget* parent = nullptr) : ViewStruct(0, {}, "Entity Factory", parent)
{
auto config = Configuration::get();
MemoryField dummy;
dummy.type = MemoryFieldType::Dummy;
dummy.name = "EntityDB here";
auto& entityDB = Spelunky2::get()->get_EntityDB();
auto address = entityDB.addressOfIndex(0);
mMainTreeView->addMemoryField(dummy, {}, address, 0);
auto offset = entityDB.entitySize() * (config->entityList().highestID() + 2); // +2 for the id 0 and one extra slot at the end
mMainTreeView->addMemoryFields(config->typeFields(MemoryFieldType::EntityFactory), "EntityFactory", address + offset, offset);
}

protected:
QSize sizeHint() const override
{
return QSize(750, 200);
}
};
} // namespace S2Plugin
4 changes: 3 additions & 1 deletion include/Views/ViewToolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace S2Plugin
void showVirtualFunctions(uintptr_t address, const std::string& typeName);
void showJournalPage(uintptr_t address);
void showLevelGen(uintptr_t address);
void showLiquidPhysics(uintptr_t address);
void showArray(uintptr_t address, std::string name, std::string arrayTypeName, size_t length);
void showMatrix(uintptr_t address, std::string name, std::string arrayTypeName, size_t rows, size_t columns);
void showEntityList(uintptr_t address);
Expand All @@ -38,10 +39,10 @@ namespace S2Plugin
ViewTextureDB* showTextureDB();
void showStringsTable();
ViewCharacterDB* showCharacterDB();

void showMainThreadState();
void showGameManager();
void showMainThreadLevelGen();
void showMainThreadLiquidPhysics();
void showEntities();
ViewVirtualTable* showVirtualTableLookup();
void showSaveGame();
Expand All @@ -50,6 +51,7 @@ namespace S2Plugin
void showThreads();
void showGameAPI();
void showHud();
void showEntityFactory();

private slots:
void clearLabels();
Expand Down
99 changes: 77 additions & 22 deletions resources/Spelunky2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@
{ "field": "stickers", "type": "Array", "length":20, "arraytype": "TextureRenderingInfo" }
],
"SaveGameDataPointer": [
{ "field": "heap_offset", "type": "UnsignedQword" },
{ "field": "heap_offset", "type": "OnHeapPointer" },
{ "field": "journal_popup_ui", "type": "JournalPopupUI" }
],
"ScreenBase": [
Expand Down Expand Up @@ -4084,8 +4084,10 @@
"type": "EntityUID",
"comment": "if set to -1, you have free control over camera focus through focus_x, focus_y"
},
{ "field": "unknown3", "type": "UnsignedDword" },
{ "field": "unknown4", "type": "UnsignedDword" },
{ "field": "peek_layer_timer", "type": "UnsignedDword" },
{ "field": "peek_layer", "type": "UnsignedByte" },
{ "field": "unknown4b", "type": "UnsignedByte" },
{ "field": "unknown4c", "type": "UnsignedWord" },
{
"field": "inertia",
"type": "Float",
Expand All @@ -4101,7 +4103,7 @@
{ "field": "bottom", "type": "Float" },
{ "field": "top", "type": "Float" }
],
"LiquidPhysicsPointer": [
"LiquidPhysics": [
{ "field": "unknown1", "type": "MysteryLiquidPointer1" },
{ "field": "water_physics_defaults", "type": "LiquidPhysicsParams" },
{ "field": "water_physics_engine", "type": "LiquidPhysicsEngine" },
Expand Down Expand Up @@ -7439,11 +7441,7 @@
{ "field": "unknown44", "type": "ConstCharPointerPointer" },
{ "field": "texture_num", "type": "UnsignedDword" },
{ "field": "padding_probably1", "type": "UnsignedDword" },
{
"field": "entity_offset",
"type": "UnsignedQword",
"comment": "the offset of the associated entity in memory, starting from the memory segment that State resides in"
},
{ "field": "entity_offset", "type": "OnHeapPointer" },
{ "field": "flip_horizontal", "type": "Bool", "comment": "facing left" },
{ "field": "padding_probably2", "type": "UnsignedByte" },
{ "field": "padding_probably3", "type": "UnsignedByte" },
Expand Down Expand Up @@ -8343,23 +8341,59 @@
}
}
],
"UnknownSteamStuff": [
{ "field": "unknown1", "type": "ConstCharPointer" },
{ "field": "unknown2", "type": "Dword" },
{ "field": "unknown3", "type": "Dword" },
{ "field": "unknown4", "type": "CodePointer" }
],
"SteamCallback": [
{
"field": "__vftable",
"type": "VirtualFunctionTable",
"functions": {
"0": {
"name": "unknown",
"params": "",
"return": ""
},
"1": {
"name": "unknown",
"params": "",
"return": ""
},
"2": {
"name": "unknown",
"params": "",
"return": ""
},
"3": {
"name": "~SteamCallback",
"params": "",
"return": ""
}
}},
{ "field": "unknown1", "type": "UnsignedByte", "comment": "bool?" },
{ "field": "padding2", "type": "Skip", "offset": 7, "comment": "probably padding, if it's subclass below" },
{ "field": "steam_overlay_open", "type": "Bool" },
{ "field": "unknown4", "type": "Skip", "offset": 3, "comment": "probably padding" },
{ "field": "unknown_timer", "type": "UnsignedDword", "comment": "can run only when game is out of focus" },
{ "field": "unknown6", "type": "Float" },
{ "field": "unknown7", "type": "UnsignedDword", "comment": "probably padding" }
],
"GameAPI": [
{ "field": "unknown1", "type": "Bool" },
{ "field": "padding1", "type": "Skip", "offset": 7 },
{ "field": "unknown3", "type": "DataPointer", "comment": "input related" },
{ "field": "renderer", "type": "Renderer", "pointer": true },
{ "field": "window_width", "type": "UnsignedDword" },
{ "field": "window_height", "type": "UnsignedDword" },
{ "field": "unknown5", "type": "UnsignedQword", "comment": "always garbage?" },
{ "field": "unknown5", "type": "UnknownSteamStuff", "pointer": true },
{ "field": "exe_begin", "type": "DataPointer" },
{ "field": "unknown7", "type": "UnsignedQword", "comment": "some offset" },
{ "field": "unknown8", "type": "UnsignedQword", "comment": "always garbage?" },
{ "field": "SteamAPI_Callback", "type": "DataPointer" },
{ "field": "unknown10a", "type": "UnsignedByte", "comment": "bool?" },
{ "field": "padding2", "type": "Skip", "offset": 3 },
{ "field": "unknown10b", "type": "UnsignedDword" },
{ "field": "unknown11", "type": "UnsignedQword", "comment": "always garbage?" },
{ "field": "unknown12", "type": "UnsignedQword", "comment": "always garbage?" }
{ "field": "unknown7", "type": "OnHeapPointer", "comment": "some offset, OnHeapPointer for now" },
{ "field": "unknown8", "type": "CodePointer", "comment": "steam related" },
{ "field": "SteamAPI_Callback", "type": "SteamCallback", "comment": "OnGameOverlayActivated" },
{ "field": "unknown14", "type": "UnsignedQword" }
],
"Renderer": [
{
Expand Down Expand Up @@ -8479,8 +8513,8 @@
{ "field": "elixir", "type": "Bool" },
{ "field": "unknown5", "type": "UnsignedByte" },
{ "field": "crown", "type": "EntityDBID" },
{ "field": "powerups_sprite_position", "type": "Array", "length": 18, "arraytype": "SpritePosition" },
{ "field": "powerups_count", "type": "UnsignedDword" }
{ "field": "powerup_sprites", "type": "Array", "length": 18, "arraytype": "SpritePosition" },
{ "field": "powerup_count", "type": "UnsignedDword" }
],
"HudElement": [
{ "field": "name_state", "type": "State32", "states": { "0": "highlight", "1": "normal" } },
Expand Down Expand Up @@ -8519,7 +8553,7 @@
{ "field": "seed", "type": "UnsignedDword" },
{ "field": "opacity", "type": "Float" },
{ "field": "player_highlight", "type": "TextureRenderingInfo" },
{ "field": "player_hearth", "type": "TextureRenderingInfo" },
{ "field": "player_heart", "type": "TextureRenderingInfo" },
{ "field": "player_ankh", "type": "TextureRenderingInfo" },
{ "field": "kapala_icon", "type": "TextureRenderingInfo" },
{ "field": "player_crown", "type": "TextureRenderingInfo" },
Expand Down Expand Up @@ -8580,7 +8614,7 @@
{ "field": "loading_dragon", "type": "TextureRenderingInfo" },
{ "field": "loading_visibility", "type": "Float" },
{ "field": "unknown42", "type": "Float" },
{ "field": "unknown42b", "type": "Float" },
{ "field": "unknown43", "type": "Float" },
{ "field": "loading_cog", "type": "TextureRenderingInfo" },
{ "field": "unknown45", "type": "Float" },
{ "field": "loading_cog_timer", "type": "UnsignedDword" },
Expand All @@ -8592,6 +8626,27 @@
{ "field": "unknown52", "type": "UnsignedDword", "comment": "probably padding" },
{ "field": "player_cursed_paricles", "type": "Array", "length": 4, "arraytype": "ParticleEmitterInfoPointer" },
{ "field": "player_poisoned_paricles", "type": "Array", "length": 4, "arraytype": "ParticleEmitterInfoPointer" }
],
"EntityPool": [
{ "field": "slot_size", "type": "UnsignedDword" },
{ "field": "initial_slots", "type": "UnsignedDword" },
{ "field": "slots_growth", "type": "UnsignedDword" },
{ "field": "current_slots", "type": "UnsignedDword" },
{ "field": "unknwon1", "type": "UnsignedQword" },
{ "field": "unknwon2", "type": "StdVector", "valuetype": "EntityPointer", "pointer": true },
{ "field": "empty_buckets", "type": "StdVector", "valuetype": "DataPointer", "pointer": true }
],
"EntityPoolOnHeapPointer": [
{ "field": "pointer", "type": "OnHeapPointer", "pointertype": "EntityPool" }
],
"EntityFactory": [
// EntityDB will be inserted here automatically
{ "field": "active_types", "type": "Array", "length": 917, "arraytype": "Bool" },
{ "field": "skip1", "type": "Skip", "offset": 3 },
{ "field": "entity_buckets", "type": "StdUnorderedMap", "keytype": "UnsignedDword", "valuetype": "EntityPoolOnHeapPointer", "comment": "key is the bucket size" },
{ "field": "entity_names_map", "type": "StdUnorderedMap", "keytype": "StdString", "valuetype": "UnsignedWord" },
{ "field": "unknwon2", "type": "UnsignedQword" },
{ "field": "unknwon3", "type": "UnsignedQword" }
]
}
}
13 changes: 13 additions & 0 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ namespace S2Plugin
{MemoryFieldType::Online, "Online", "", "Online", 0, false},
{MemoryFieldType::GameAPI, "GameAPI", "", "GameAPI", 0, false},
{MemoryFieldType::Hud, "Hud", "", "Hud", 0, false},
{MemoryFieldType::EntityFactory, "EntityFactory", "", "EntityFactory", 0, false},
{MemoryFieldType::LiquidPhysics, "LiquidPhysics", "", "LiquidPhysics", 0, false},
// Special Types
{MemoryFieldType::OnHeapPointer, "OnHeap Pointer", "OnHeapPointer<T>", "OnHeapPointer", 8, false}, // not pointer since it's more of a offset
{MemoryFieldType::EntityPointer, "Entity pointer", "Entity*", "EntityPointer", 8, true},
{MemoryFieldType::EntityDBPointer, "EntityDB pointer", "EntityDB*", "EntityDBPointer", 8, true},
{MemoryFieldType::EntityDBID, "EntityDB ID", "uint32_t", "EntityDBID", 4, false},
Expand All @@ -142,6 +145,7 @@ namespace S2Plugin
{MemoryFieldType::COThemeInfoPointer, "COThemeInfoPointer", "ThemeInfo*", "COThemeInfoPointer", 8, true}, // just theme name
{MemoryFieldType::LevelGenRoomsPointer, "LevelGenRoomsPointer", "LevelGenRooms*", "LevelGenRoomsPointer", 8, true},
{MemoryFieldType::LevelGenRoomsMetaPointer, "LevelGenRoomsMetaPointer", "LevelGenRoomsMeta*", "LevelGenRoomsMetaPointer", 8, true},
{MemoryFieldType::LiquidPhysicsPointer, "LiquidPhysicsPointer", "LiquidPhysicsPointer*", "LiquidPhysicsPointer", 8, true},
{MemoryFieldType::JournalPagePointer, "JournalPagePointer", "JournalPage*", "JournalPagePointer", 8, true},
{MemoryFieldType::LevelGenPointer, "LevelGenPointer", "LevelGen*", "LevelGenPointer", 8, true},
{MemoryFieldType::StringsTableID, "StringsTable ID", "uint32_t", "StringsTableID", 4, false},
Expand Down Expand Up @@ -540,6 +544,14 @@ S2Plugin::MemoryField S2Plugin::Configuration::populateMemoryField(const nlohman
throw std::runtime_error("Missing `col` parameter for Matrix (" + struct_name + "." + memField.name + ")");
break;
}
case MemoryFieldType::OnHeapPointer:
{
if (field.contains("pointertype"))
{
memField.jsonName = field["pointertype"].get<std::string_view>();
}
break;
}
case MemoryFieldType::DefaultStructType:
memField.jsonName = fieldTypeStr;
break;
Expand Down Expand Up @@ -908,6 +920,7 @@ uint8_t S2Plugin::Configuration::getAlingment(MemoryFieldType type) const
case MemoryFieldType::StdList:
case MemoryFieldType::EntityList:
case MemoryFieldType::StdUnorderedMap:
case MemoryFieldType::OnHeapPointer:
default:
return sizeof(uintptr_t);
}
Expand Down
Loading

0 comments on commit bee776c

Please sign in to comment.