diff --git a/src/Hook.cpp b/src/Hook.cpp index 15d83e1..9fd1a37 100644 --- a/src/Hook.cpp +++ b/src/Hook.cpp @@ -3,6 +3,9 @@ #include "Hook.h" #include "input/MessageHook.h" +// Modules +#include "modules/InstanceViewer.h" + #include "cdc/render/PCDeviceManager.h" using namespace std::placeholders; @@ -19,13 +22,15 @@ static bool D3D_Init() return ret; } -Hook::Hook() : m_menu(nullptr) +Hook::Hook() : m_menu(nullptr), m_modules() { Initialize(); } void Hook::Initialize() { + RegisterModules(); + MH_Initialize(); MH_CreateHook((void*)0x4153E0, D3D_Init, (void**)&s_D3D_Init); MH_EnableHook(MH_ALL_HOOKS); @@ -43,6 +48,11 @@ void Hook::PostInitialize() void Hook::OnMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { m_menu->OnMessage(hWnd, msg, wParam, lParam); + + for (auto& mod : m_modules) + { + mod->OnInput(hWnd, msg, wParam, lParam); + } } void Hook::OnDevice() @@ -54,6 +64,19 @@ void Hook::OnDevice() PostInitialize(); } +template +void Hook::RegisterModule() +{ + auto module = std::make_shared(); + + m_modules.push_back(module); +} + +void Hook::RegisterModules() +{ + RegisterModule(); +} + Hook& Hook::GetInstance() { static Hook instance; diff --git a/src/Hook.h b/src/Hook.h index 37a5ee3..a053ef1 100644 --- a/src/Hook.h +++ b/src/Hook.h @@ -1,17 +1,24 @@ #pragma once #include +#include #include "menu/Menu.h" +#include "modules/Module.h" class Hook { private: std::unique_ptr m_menu; + std::list> m_modules; void Initialize(); void PostInitialize(); + template + void RegisterModule(); + void RegisterModules(); + void OnMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); public: @@ -19,5 +26,7 @@ class Hook void OnDevice(); + const auto& GetModules() { return m_modules; } + static Hook& GetInstance(); }; \ No newline at end of file diff --git a/src/cdc/math/Matrix.h b/src/cdc/math/Matrix.h new file mode 100644 index 0000000..91eef5c --- /dev/null +++ b/src/cdc/math/Matrix.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Vector.h" + +namespace cdc +{ + class Matrix + { + public: + cdc::Vector col0; + cdc::Vector col1; + cdc::Vector col2; + cdc::Vector col3; + }; +} \ No newline at end of file diff --git a/src/cdc/math/Vector.h b/src/cdc/math/Vector.h new file mode 100644 index 0000000..1bdcd22 --- /dev/null +++ b/src/cdc/math/Vector.h @@ -0,0 +1,39 @@ +#pragma once + +#include + +namespace cdc +{ + class Vector + { + public: + union + { + __m128 vec128; + + struct + { + float x; + float y; + float z; + float w; + }; + }; + }; + + class Vector2 : public Vector + { + }; + + class Vector3 : public Vector + { + }; + + class Vector4 : public Vector + { + }; + + class Euler : public Vector + { + }; +} \ No newline at end of file diff --git a/src/instance/Instance.h b/src/instance/Instance.h new file mode 100644 index 0000000..dd6126b --- /dev/null +++ b/src/instance/Instance.h @@ -0,0 +1,64 @@ +#pragma once + +#include "Object.h" + +#include "cdc/math/Vector.h" +#include "cdc/math/Matrix.h" + +struct NodeType +{ + NodeType* prev; + NodeType* next; +}; + +struct Intro +{ +}; + +struct HModel; +struct SoundInstanceData; +struct Body; +struct AnimatedGeoms; +struct AnimComponent; +struct CharacterProxy; + +struct Instance; + +struct BaseInstance +{ + NodeType node; + + Instance* next; + Instance* prev; + + cdc::Vector3 position; + cdc::Vector3 oldPos; + + cdc::Euler rotation; + cdc::Euler oldRotation; + + cdc::Vector3 scale; + cdc::Vector3 shadowPosition; + cdc::Vector3 centerOfMass; + + cdc::Matrix* matrix; + cdc::Matrix* oldMatrix; + + char pad1[12]; + + Object* object; + Intro* intro; + + char pad2[100]; +}; + +struct Instance : BaseInstance +{ + char pad1[192]; + + void* data; + + char pad2[12]; + + int introUniqueID; +}; \ No newline at end of file diff --git a/src/instance/Instances.cpp b/src/instance/Instances.cpp new file mode 100644 index 0000000..15a6e3c --- /dev/null +++ b/src/instance/Instances.cpp @@ -0,0 +1,11 @@ +#include "Instances.h" + +void Instances::Iterate(std::function callback) +{ + auto first = *(Instance**)0x817D64; + + for (auto instance = first; instance != nullptr; instance = instance->next) + { + callback(instance); + } +} \ No newline at end of file diff --git a/src/instance/Instances.h b/src/instance/Instances.h new file mode 100644 index 0000000..ba9914d --- /dev/null +++ b/src/instance/Instances.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +#include "Instance.h" + +class Instances +{ +public: + static void Iterate(std::function callback); +}; \ No newline at end of file diff --git a/src/instance/Object.h b/src/instance/Object.h new file mode 100644 index 0000000..a015c55 --- /dev/null +++ b/src/instance/Object.h @@ -0,0 +1,42 @@ +#pragma once + +struct Model +{ +}; + +struct AnimListEntry; +struct AnimFxHeader; +struct AnimScriptObject; +struct ObjectBase; + +struct Object +{ + int oflags; + int oflags2; + + int uniqueID; + unsigned int guiID; + int functionTableID; + + void* obsoleteSoundBank; + + __int16 numModels; + __int16 numAnims; + __int16 numAnimPatterns; + + Model** modelList; + + AnimListEntry* animList; + AnimFxHeader** animFXList; + AnimScriptObject** animPatternList; + + int introDist; + int vvIntroDist; + int removeDist; + int vvRemoveDist; + + ObjectBase* baseData; + + void* data; + char* name; +}; \ No newline at end of file diff --git a/src/menu/Menu.cpp b/src/menu/Menu.cpp index 6710dab..be7a27d 100644 --- a/src/menu/Menu.cpp +++ b/src/menu/Menu.cpp @@ -8,6 +8,7 @@ #include "render/RenderContext.h" #include "input/MouseHook.h" #include "input/Input.h" +#include "Hook.h" #include "cdc/render/PCDeviceManager.h" @@ -88,10 +89,24 @@ void Menu::OnMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) void Menu::Draw() { + auto& modules = Hook::GetInstance().GetModules(); + if (ImGui::BeginMainMenuBar()) { + // Draw all modules menus + for (auto& mod : modules) + { + mod->OnMenu(); + } + ImGui::EndMainMenuBar(); } + + // Draw all menus + for (auto& mod : modules) + { + mod->OnDraw(); + } } void Menu::SetFocus(bool focus) diff --git a/src/modules/InstanceViewer.cpp b/src/modules/InstanceViewer.cpp new file mode 100644 index 0000000..08e2dd4 --- /dev/null +++ b/src/modules/InstanceViewer.cpp @@ -0,0 +1,72 @@ +#include + +#include "InstanceViewer.h" +#include "instance/Instances.h" + +void InstanceViewer::OnMenu() +{ + if (ImGui::BeginMenu("Instance")) + { + ImGui::MenuItem("Instances", nullptr, &m_show); + + ImGui::EndMenu(); + } +} + +void InstanceViewer::OnDraw() +{ + if (m_show) + { + ImGui::Begin("Instances", &m_show); + ImGui::Columns(2, "instances"); + + // Instance list + ImGui::BeginChild("InstancesTree"); + + Instances::Iterate([this](Instance* instance) + { + if (ImGui::TreeNodeEx((void*)instance, ImGuiTreeNodeFlags_Leaf, "%d %s", instance->introUniqueID, instance->object->name)) + { + if (ImGui::IsItemClicked()) + { + m_selected = instance; + } + + ImGui::TreePop(); + } + }); + + ImGui::EndChild(); + + // Instance properties + ImGui::NextColumn(); + + // Check if the instance still exists + if (m_selected && m_selected->node.prev == nullptr) + { + m_selected = nullptr; + } + + if (m_selected) + { + DrawInstance(); + } + + ImGui::End(); + } +} + +void InstanceViewer::DrawInstance() +{ + auto instance = m_selected; + + ImGui::Text("%s", instance->object->name); + + auto position = instance->position; + auto rotation = instance->rotation; + + ImGui::Text("Position: %f %f %f", position.x, position.y, position.z); + ImGui::Text("Rotation: %f %f %f", rotation.x, rotation.y, rotation.z); + ImGui::Text("Intro: %d", instance->introUniqueID); + ImGui::Text("Address: %p", instance); +} \ No newline at end of file diff --git a/src/modules/InstanceViewer.h b/src/modules/InstanceViewer.h new file mode 100644 index 0000000..3b41b30 --- /dev/null +++ b/src/modules/InstanceViewer.h @@ -0,0 +1,20 @@ +#pragma once + +#include "Module.h" + +#include "instance/Instance.h" + +class InstanceViewer : public Module +{ +private: + bool m_show = false; + Instance* m_selected = nullptr; + + void DrawInstance(); + +public: + void OnMenu(); + void OnDraw(); + + Instance* GetSelected() { return m_selected; } +}; \ No newline at end of file diff --git a/src/modules/Module.h b/src/modules/Module.h new file mode 100644 index 0000000..e2a8d95 --- /dev/null +++ b/src/modules/Module.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +class Module +{ +public: + virtual void OnMenu() { }; + virtual void OnDraw() { }; + virtual void OnInput(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { }; +}; \ No newline at end of file