Skip to content

Commit

Permalink
Added static assertions for struct sizes, and fixed some layout errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SK83RJOSH committed Nov 16, 2020
1 parent 149d77f commit 1711c54
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 15 deletions.
12 changes: 8 additions & 4 deletions convex.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ namespace Teardown {
uint32_t dword8;
Vector4_f32 m_Rotation;
float dword14;
float dword18;
float dword20;
uint32_t dword1C;
uint64_t qword20;
uint32_t dword28;
uint8_t byte2C;
uint8_t gap2D[3];
uint8_t byte2C; uint8_t gap2D[3];
uint32_t m_ArrayBufferHandle;
uint32_t dword34;
small_vector<Vector3_f32> m_Vertices;
Expand All @@ -65,5 +63,11 @@ namespace Teardown {
AnotherBuffer m_AnotherBuffer;
uint8_t pad2B4[4];
};

static_assert(sizeof(Convex) == 0x2B8u, "Convex size is incorrect!");
static_assert(sizeof(AnotherBuffer) == 0x1Cu, "AnotherBuffer size is incorrect!");
static_assert(sizeof(Buffer) == 0x38u, "Buffer size is incorrect!");
static_assert(sizeof(ShaderBinding) == 0x208, "ShaderBinding size is incorrect!");
static_assert(sizeof(ShaderVariable) == 0x20, "ShaderVariable size is incorrect!");
#pragma pack(pop)
}
2 changes: 2 additions & 0 deletions editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ namespace Teardown { namespace Editor {
SCRIPT = 0x19,
COUNT = 0x1A,
};

static_assert(sizeof(EntityType) == 0x4, "EntityType size is incorrect!");
} }
15 changes: 8 additions & 7 deletions entities/body.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace Teardown { namespace Entities {
uint64_t qword64;
uint64_t qword6C;
uint32_t dword74;
uint32_t dword78;
Vector3_f32 m_Velocity;
uint32_t qword84;
uint64_t qword88;
uint64_t qword90;
float m_Density;
uint32_t qword98;
uint32_t qword9C;
uint8_t gapA0[4];
float m_Density;
uint64_t qwordA4;
uint64_t qwordAC;
uint64_t qwordB4;
Expand All @@ -29,12 +29,13 @@ namespace Teardown { namespace Entities {
uint32_t dwordCC;
Vector3_f32 m_MinBounds;
Vector3_f32 m_MaxBounds;
bool m_IsDynamic;
uint8_t padE2[3];
uint64_t qwordE8;
bool byteE8; uint8_t padE9[3];
uint32_t dwordEC;
uint32_t dwordF0;
uint8_t byteF4;
uint8_t m_IsDynamic; uint8_t padF5[3];
uint64_t qwordF8;
};

static_assert(sizeof(Body) == 0x100u, "Body size is incorrect!");
#pragma pack(pop)
} }
5 changes: 5 additions & 0 deletions entities/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ namespace Teardown { namespace Entities {
Entity* m_Sibling;
Entity* m_Child;
};

static_assert(sizeof(Entity::vftable) == 0x20u, "Entity::vftable size is incorrect!");
static_assert(sizeof(Entity::Type) == 0x1u, "Entity::Type size is incorrect!");
static_assert(sizeof(Entity::Flags) == 0x1u, "Entity::Flags size is incorrect!");
static_assert(sizeof(Entity) == 0x28u, "Entity size is incorrect!");
} }
4 changes: 3 additions & 1 deletion entities/shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ namespace Teardown { namespace Entities {
Teardown::Convex* m_Convex;
uint64_t qwordA0;
float m_Emissive;
bool m_Broken;
bool m_Broken; uint8_t pad[3];
};

static_assert(sizeof(Shape) == 0xB0u, "Shape size is incorrect!");
#pragma pack(pop)
} }
2 changes: 2 additions & 0 deletions entities/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ namespace Teardown { namespace Entities {
small_string m_Name;
small_string m_Value;
};

static_assert(sizeof(Tag) == 0x28u, "Tag size is incorrect!");
} }
2 changes: 2 additions & 0 deletions entities/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,7 @@ namespace Teardown { namespace Entities {
uint8_t byte284;
uint8_t gap285[3];
};

static_assert(sizeof(Vehicle) == 0x288u, "Vehicle size is incorrect!");
#pragma pack(pop)
} }
5 changes: 5 additions & 0 deletions fire_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "entities/shape.h"

namespace Teardown {
#pragma pack(push, 1)
struct FireSystem {
struct Fire {
Entities::Shape* m_Parent;
Expand All @@ -14,4 +15,8 @@ namespace Teardown {
void* vftptr_0;
small_vector<Fire> m_Instances;
};

static_assert(sizeof(FireSystem) == 0x18u, "FireSystem size is incorrect!");
static_assert(sizeof(FireSystem::Fire) == 0x1Cu, "FireSystem::Fire size is incorrect!");
#pragma pack(pop)
}
4 changes: 4 additions & 0 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,9 @@ namespace Teardown
uint8_t gap_3B8[56];
char field_3F0;
};

static_assert(sizeof(Game) == 0x3EDu, "Game size is incorrect!");
static_assert(sizeof(Game::Timer) == 0x10u, "Game::Timer size is incorrect!");
static_assert(sizeof(Game::State) == 0x4u, "Game::State size is incorrect!");
#pragma pack(pop)
}
4 changes: 4 additions & 0 deletions graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ namespace Teardown { namespace Graphics {
int32_t m_Invert;
int32_t m_HeadBob;
};

static_assert(sizeof(DisplayMode) == 0xCu, "DisplayMode size is incorrect!");
static_assert(sizeof(Buffers) == 0x3Cu, "Buffers size is incorrect!");
static_assert(sizeof(Options) == 0x3Cu, "Options size is incorrect!");
#pragma pack(pop)
} }
2 changes: 2 additions & 0 deletions player.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,7 @@ namespace Teardown {
int64_t field_356C;
int field_3574;
};

static_assert(sizeof(Player) == 0x3578u, "Player size is incorrect!");
#pragma pack(pop)
}
3 changes: 3 additions & 0 deletions scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,8 @@ namespace Teardown {
uint64_t qword_788;
uint8_t gap_790[128];
};

static_assert(sizeof(Scene::RaycastFilter) == 0x50u, "Scene::RaycastFilter size is incorrect!");
static_assert(sizeof(Scene) == 0x810u, "Scene size is incorrect!");
#pragma pack(pop)
}
5 changes: 5 additions & 0 deletions types.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <assert.h>
#include <stdint.h>
#include <iterator>

namespace Teardown {
namespace {
Expand Down Expand Up @@ -68,4 +70,7 @@ namespace Teardown {
uint32_t m_Capacity;
T** m_Data;
};

static_assert(sizeof(small_string) == 16, "small_string size is incorrect!");
static_assert(sizeof(small_vector<void>) == 16, "small_vector size is incorrect!");
};
12 changes: 9 additions & 3 deletions voxels.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ namespace Teardown {

struct VoxelsPaletteInfo
{
uint8_t m_Id;
uint8_t m_Pad4;
uint32_t m_Type;
VoxelColor m_Color;
VoxelMaterial m_Material;
uint8_t m_Pad20;
uint32_t m_Pad20;
};

struct VoxelsPalette
{
int32_t m_Id;
VoxelsPaletteInfo m_Palettes[256];
uint8_t m_Padding[2048];
};

// Voxel buffers can be indexed via m_Buffer[voxel_x_pos + m_BuffersSize.m_X * (voxel_y_pos + m_BuffersSize.m_Z * voxel_z_pos)]
Expand All @@ -55,5 +55,11 @@ namespace Teardown {
uint32_t m_VoxelCount; // Amount of "solid" voxels in the physics object; used for mass calculations
uint8_t pad5C[4];
};

static_assert(sizeof(VoxelMaterial) == 0x10u, "VoxelMaterial size is incorrect!");
static_assert(sizeof(VoxelColor) == 0x10u, "VoxelColor size is incorrect!");
static_assert(sizeof(VoxelsPaletteInfo) == 0x28u, "VoxelsPaletteInfo size is incorrect!");
static_assert(sizeof(VoxelsPalette) == 0x3004u, "VoxelsPalette size is incorrect!");
static_assert(sizeof(Voxels) == 0x60u, "Voxels size is incorrect!");
#pragma pack(pop)
}

0 comments on commit 1711c54

Please sign in to comment.