Skip to content

Commit

Permalink
Physics, joints, and other goodies
Browse files Browse the repository at this point in the history
  • Loading branch information
SK83RJOSH committed Nov 23, 2020
1 parent 22b268d commit 04414ee
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 13 deletions.
13 changes: 9 additions & 4 deletions entities/joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ namespace Teardown { namespace Entities {
Joint* m_AttachmentJoint0;
Joint* m_AttachmentJoint1;
Type m_JointType;
float m_Strength;
uint8_t field_50;
float m_Size;
bool m_Collide;
bool m_IsConnected; uint8_t pad_52[2];
float m_Stiffness;
int64_t field_58;
float m_Springiness;
int32_t field_5C;
int64_t field_60;
Vector3_f32 m_AttachmentPosition0;
Vector3_f32 m_AttachmentPosition1;
Expand All @@ -33,9 +34,13 @@ namespace Teardown { namespace Entities {
Vector2_f32 m_Limits; // In meters or radians depending on joint type
Vector2_f32 m_Motor;
int64_t field_B8; // Pointer to unidentified structure; only used with Wire type
bool field_C0; uint8_t pad_C1[7];
bool m_Sound; uint8_t pad_C1[7];

inline static function_signature<bool(__fastcall*)(Joint* ptr, Entity* parent)> Constructor = { "\x40\x53\x48\x83\xEC\x20\x4C\x8B\xC2\x48\x8B\xD9\xBA\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xC7\x43\x2A\x2A\x2A\x2A\x2A\x48\x8D\x05\x2A\x2A\x2A\x2A\x48\x89\x03\x33\xC0\x48\x89\x43\x28\x48\x89\x43\x30\x48\x89\x43\x38\x48\x89\x43\x40\x89\x43\x48\x66\xC7\x43\x2A\x2A\x2A\xC7\x43\x2A\x2A\x2A\x2A\x2A\x48\xC7\x43\x2A\x2A\x2A\x2A\x2A\x48\x89\x43\x60\x48\x89\x43\x68\x48\x89\x43\x70\x48\x89\x43\x78\x48\x89\x83\x2A\x2A\x2A\x2A\x48\x89\x83\x2A\x2A\x2A\x2A\x48\x89\x83\x2A\x2A\x2A\x2A\x48\x89\x83\x2A\x2A\x2A\x2A\x89\x83\x2A\x2A\x2A\x2A\x48\xC7\x83\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x48\x89\x83\x2A\x2A\x2A\x2A\x89\x83\x2A\x2A\x2A\x2A\x48\x89\x83\x2A\x2A\x2A\x2A\x88\x83\x2A\x2A\x2A\x2A\x48\x8B\xC3\x48\x83\xC4\x20\x5B\xC3" };
inline static function_signature<bool(__fastcall*)(Joint* ptr, Transform* transform, float size, float strength, float springiness, bool collide)> InitBall = { "\x48\x89\x5C\x24\x2A\x48\x89\x6C\x24\x2A\x48\x89\x74\x24\x2A\x48\x89\x7C\x24\x2A\x41\x56\x48\x83\xEC\x40\x0F\xB6\x44\x24\x2A\x4C\x8D\x49\x30\xF3\x0F\x10\x44\x24\x2A\x4C\x8D\x41\x28\x45\x33\xF6\xF3\x0F\x11\x41" };
inline static function_signature<bool(__fastcall*)(Joint* ptr, Transform* transform, float size, float strength, int64_t springiness, bool collide, Vector2_f32* limits)> InitHinge = { "\x40\x55\x56\x41\x54\x41\x56\x41\x57\x48\x8B\xEC\x48\x83\xEC\x40\x0F\xB6\x45\x58\x4C\x8D\x49\x30\xF3\x0F\x10\x45\x2A\x4C\x8D\x41\x28\x88\x41\x50\x45\x33\xE4\x48\x8B\x45\x60\x48\x8B\xF1\xF3\x0F\x11\x51\x2A\xF3\x0F\x11\x59\x2A\xF3\x0F\x11\x41\x2A\xC7\x41" };
inline static function_signature<bool(__fastcall*)(Joint* ptr, Transform* transform, float size, bool collide, Vector2_f32* limits)> InitPrismatic = { "\x40\x55\x56\x41\x54\x41\x56\x41\x57\x48\x8B\xEC\x48\x83\xEC\x40\x48\x8B\x45\x50\x4C\x8D\x41\x28\x44\x88\x49\x50\x45\x33\xE4\xF3\x0F\x11\x51" };
inline static function_signature<bool(__fastcall*)(Joint* ptr, const Vector3_f32& pos_0, const Vector3_f32& pos_1, float size, const Vector4_f32& color, float slack, float strength, float max_stretch)> InitWire = { "\x48\x8B\xC4\x55\x41\x56\x41\x57\x48\x8D\x68\xC1\x48\x81\xEC\x2A\x2A\x2A\x2A\x48\xC7\x45\x2A\x2A\x2A\x2A\x2A\x48\x89\x58\x08\x48\x89\x70\x10\x48\x89\x78\x18\x4C\x89\x60\x20\x4D\x8B\xF0\x4C\x8B\xFA\x48\x8B\xD9\xC7\x41" };
inline static function_signature<bool(__fastcall*)(Joint* ptr, Shape& shape_0, Shape& shape_1, const Vector3_f32& pos_0, const Vector3_f32& pos_1)> Attach = { "\x48\x89\x5C\x24\x2A\x48\x89\x74\x24\x2A\x57\x48\x83\xEC\x30\x48\x89\x51\x28\x48\x8B\xF1\x4C\x89\x41\x30\x49\x8B\xF8\x48\x8D\x4A\x34\x48\x8B\xDA\x48\x8D\x54\x24\x2A\x4D\x8B\xC1\xE8\x2A\x2A\x2A\x2A\x4C\x8B\x44\x24\x2A\x48\x8D\x4F\x34\x48\x8D\x54\x24\x2A\xF3\x0F\x10\x40\x2A\xF3\x0F\x10\x10\xF3\x0F\x58\x43\x2A\xF3\x0F\x10\x48\x2A\xF3\x0F\x58\x53\x2A\xF3\x0F\x58\x4B\x2A\xF3\x0F\x11\x44\x24\x2A\x8B\x44\x24\x28\x0F\x28\xC2\x0F\x14\xC1\xF2\x0F\x11\x46\x2A\x89\x46\x70\xE8" };
inline static function_signature<bool(__fastcall*)(Joint* ptr)> UpdateAngle = { "\x40\x53\x48\x83\xEC\x40\x48\x8B\x41\x28\x48\x8B\xD9\x48\x85\xC0\x74\x6D\x4C\x8B\x41\x30\x4D\x85\xC0\x74\x64\x48\x8B\x40\x10\x48\x8D\x54\x24\x2A\xF3\x0F\x10\x15\x2A\x2A\x2A\x2A\x48\x8D\x4C\x24\x2A\x4D\x8B\x40\x10\x49\x83\xC0\x34\xF3\x0F\x10\x40\x2A\xF3\x0F\x10\x48\x2A\x0F\x57\xC2\xF3\x0F\x11\x44\x24\x2A\x0F\x57\xCA\xF3\x0F\x10\x40\x2A\x0F\x57\xC2\xF3\x0F\x11\x4C\x24\x2A\xF3\x0F\x11\x44\x24\x2A\xF3\x0F\x10\x40\x2A\xF3\x0F\x11\x44\x24\x2A\xE8\x2A\x2A\x2A\x2A\x0F\x10\x44\x24\x2A\x0F\x11\x83\x2A\x2A\x2A\x2A\x48\x83\xC4\x40\x5B\xC3" };
};
Expand Down
35 changes: 35 additions & 0 deletions physics_system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include "scene.h"
#include "entities/body.h"
#include "entities/shape.h"

namespace Teardown {
struct Scene;

#pragma pack(push, 1)
struct PhysicsSystem {
Scene* m_Scene;
uint8_t gap4[16];
int32_t field_18;
uint8_t gap1C[4];
int32_t field_20;
uint8_t gap24[28];
float m_UpdateInterval;
uint8_t gap44[4];
int32_t field_48;
uint8_t gap4C[10652];
int32_t field_29E8;
uint8_t gap29EC[76];
small_vector<Entities::Body*> m_ActiveBodies;
bool field_2A48;
uint8_t gap2A49[39];
int32_t field_2A70;
uint8_t gap2A74[92];
int32_t field_2AD0;
uint8_t gap2AD4[76];
};

static_assert(sizeof(PhysicsSystem) == 0x2B20u, "PhysicsSystem size is incorrect!");
#pragma pack(pop)
}
39 changes: 32 additions & 7 deletions scene.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once


#include "player.h"
#include "fire_system.h"
#include "physics_system.h"

#include "entities/tag.h"
#include "entities/entity.h"
Expand Down Expand Up @@ -30,13 +30,34 @@ namespace Teardown {
small_vector<Entities::Shape*> m_IgnoredShapes;
};

struct JointInfo
{
Entities::Joint* m_Joint;
Entities::Joint::Type m_Type;
Transform m_Transform;
bool m_Collide; uint8_t pad_29[3];
float m_Size;
float m_Stiffness;
float m_Springiness;
Vector3_f32 m_Position0;
Vector3_f32 m_Position1;
Vector4_f32 m_Color;
float m_Slack;
float m_Strength;
float m_MaxStretch;
Vector2_f32 m_Limits;
bool m_Sound; uint8_t pad_75[3];
};

int64_t vftptr_0;
uint64_t qword_8;
PhysicsSystem* m_PhysicsSystem;
uint64_t qword_10;
uint32_t dword_18;
uint32_t dword_1C;
uint64_t qword_20;
uint8_t gap_28[64];
uint8_t gap_28[24];
small_vector<JointInfo> m_PendingJoints;
uint8_t gap_38[24];
uint64_t qword_68;
uint64_t qword_70;
uint64_t qword_78;
Expand All @@ -49,7 +70,7 @@ namespace Teardown {
uint64_t qword_B0;
uint64_t qword_B8;
uint64_t qword_C0;
Transform m_PlayerTransform;
Transform m_SpawnPoint;
uint8_t gap_E4[12];
uint64_t qword_F0;
uint8_t byte_F8; uint8_t pad_F9[7];
Expand All @@ -58,7 +79,7 @@ namespace Teardown {
uint64_t qword_110;
uint64_t qword_118;
Entities::Vehicle* m_ActiveVehicle;
uint64_t m_ActiveScreen;
Entities::Screen* m_ActiveScreen;
uint64_t qword_130;
uint32_t dword_138;
uint32_t dword_13C;
Expand Down Expand Up @@ -87,8 +108,10 @@ namespace Teardown {
uint64_t qword_2A8;
small_vector<Entities::Tag> m_EntityTags;
uint32_t m_NextEntityId;
uint32_t dword_2C8;
uint8_t gap_2CC[1144];
uint32_t dword_2C4;
uint8_t gap_2C8[616];
small_vector<Vector2_f32> m_BoundaryVertices;
uint8_t gap_540[512];
uint32_t dword_740;
bool m_CanQuickLoad;
uint8_t gap_745[3];
Expand All @@ -111,7 +134,9 @@ namespace Teardown {
inline static function_signature<bool(__fastcall*)(Scene* ptr, Vector3_f32* pos, Vector3_f32* dir, __int32 type)> CreateProjectile = { "\x48\x89\x5C\x24\x08\x57\x48\x81\xEC\x80\x00\x00\x00" };
};


static_assert(sizeof(Scene::RaycastFilter) == 0x50u, "Scene::RaycastFilter size is incorrect!");
static_assert(sizeof(Scene::JointInfo) == 0x78u, "Scene::JointInfo size incorrect!");
static_assert(sizeof(Scene) == 0x810u, "Scene size is incorrect!");
#pragma pack(pop)
}
15 changes: 13 additions & 2 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace Teardown {
* It does not support:
* Copying and assignment
* Non-trivially constructible types
* Insertion, deletion, modification
* Deletion
*
* You are welcome to submit pull requests for these if you wish.
*/
Expand All @@ -161,6 +161,17 @@ namespace Teardown {
uint32_t size() const { return m_Size; }
uint32_t capacity() const { return m_Capacity; }

void push_back(const T& value)
{
if (m_Capacity <= m_Size)
{
reserve(2 * m_Capacity + 1);
}

m_Data[m_Size] = value;
++m_Size;
}

void reserve(uint32_t capacity) {
if (auto memory = MemoryNew<T>(capacity))
{
Expand Down Expand Up @@ -230,5 +241,5 @@ namespace Teardown {
};

static_assert(sizeof(small_string) == 16, "small_string size is incorrect!");
static_assert(sizeof(small_vector<void>) == 16, "small_vector size is incorrect!");
static_assert(sizeof(small_vector<uint8_t>) == 16, "small_vector size is incorrect!");
};

0 comments on commit 04414ee

Please sign in to comment.