diff --git a/src/Hook.cpp b/src/Hook.cpp index 246ea7c..dfcf8f1 100644 --- a/src/Hook.cpp +++ b/src/Hook.cpp @@ -23,6 +23,7 @@ #include "modules/Frontend.h" #include "modules/Draw.h" #include "modules/Debug.h" +#include "modules/Materials.h" #include "modules/camera/FreeCamera.h" #include "cdc/render/PCDeviceManager.h" @@ -144,6 +145,7 @@ void Hook::RegisterModules() RegisterModule(); #else RegisterModule(); + RegisterModule(); #endif } diff --git a/src/cdc/render/CommonMaterial.cpp b/src/cdc/render/CommonMaterial.cpp new file mode 100644 index 0000000..2d763a1 --- /dev/null +++ b/src/cdc/render/CommonMaterial.cpp @@ -0,0 +1,6 @@ +#include "CommonMaterial.h" + +cdc::MaterialData* cdc::CommonMaterial::GetMaterialData() const noexcept +{ + return m_pData; +} \ No newline at end of file diff --git a/src/cdc/render/CommonMaterial.h b/src/cdc/render/CommonMaterial.h new file mode 100644 index 0000000..0df1bfc --- /dev/null +++ b/src/cdc/render/CommonMaterial.h @@ -0,0 +1,21 @@ +#pragma once + +#include "MaterialData.h" + +namespace cdc +{ + class IMaterial + { + public: + virtual ~IMaterial() = 0; + }; + + class CommonMaterial : public IMaterial + { + private: + MaterialData* m_pData; + + public: + MaterialData* GetMaterialData() const noexcept; + }; +} \ No newline at end of file diff --git a/src/cdc/render/MaterialData.h b/src/cdc/render/MaterialData.h new file mode 100644 index 0000000..6e574f2 --- /dev/null +++ b/src/cdc/render/MaterialData.h @@ -0,0 +1,12 @@ +#pragma once + +namespace cdc +{ + struct MaterialData + { + char pad[88]; + + __int16 numParameters; + float* parameters; + }; +} \ No newline at end of file diff --git a/src/cdc/sys/Array.h b/src/cdc/sys/Array.h new file mode 100644 index 0000000..58c1664 --- /dev/null +++ b/src/cdc/sys/Array.h @@ -0,0 +1,14 @@ +#pragma once + +namespace cdc +{ + template + class Array + { + public: + unsigned int m_size; + unsigned int m_cap; + + T* m_data; + }; +} \ No newline at end of file diff --git a/src/cdc/sys/HashMap.h b/src/cdc/sys/HashMap.h new file mode 100644 index 0000000..43accd1 --- /dev/null +++ b/src/cdc/sys/HashMap.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "Array.h" + +namespace cdc +{ + template + class HashTable + { + public: + class Node + { + public: + Node* m_next; + std::pair m_data; + }; + + cdc::Array m_buckets; + unsigned int m_size; + }; +} \ No newline at end of file diff --git a/src/modules/Materials.cpp b/src/modules/Materials.cpp new file mode 100644 index 0000000..75f4c51 --- /dev/null +++ b/src/modules/Materials.cpp @@ -0,0 +1,94 @@ +#include +#include + +#include "Materials.h" +#include "render/Material.h" + +#include "cdc/sys/HashMap.h" + +void Materials::OnMenu() +{ + if (ImGui::BeginMenu("Materials")) + { + ImGui::MenuItem("Material editor", nullptr, &m_show); + + ImGui::EndMenu(); + } +} + +void Materials::OnDraw() +{ + if (m_show) + { + DrawMaterialEditor(); + } +} + +void Materials::DrawMaterialEditor() +{ + ImGui::Begin("Materials", &m_show); + ImGui::Columns(2); + + // Filter + ImGui::InputText("Material", m_filter, sizeof(m_filter)); + + // Material list + ImGui::BeginChild("MaterialsTree"); + + auto materials = (cdc::HashTable*)0x8A6EBC; + + for (int i = 0; i < materials->m_buckets.m_size; i++) + { + auto node = materials->m_buckets.m_data[i]; + + if (node) + { + auto id = node->m_data.first; + auto entry = &node->m_data.second; + + // Check the filter + if (strlen(m_filter) > 0 && std::to_string(id).find(m_filter) == std::string::npos) + { + continue; + } + + if (ImGui::TreeNodeEx((void*)entry, ImGuiTreeNodeFlags_Leaf, "%d", id)) + { + if (ImGui::IsItemClicked()) + { + m_selected = entry->pMaterial; + } + + ImGui::TreePop(); + } + } + } + + ImGui::EndChild(); + + // Material editor + ImGui::NextColumn(); + + if (m_selected) + { + ImGui::BeginChild("MaterialEditor"); + + DrawMaterialEditor(m_selected); + + ImGui::EndChild(); + } + + ImGui::End(); +} + +void Materials::DrawMaterialEditor(cdc::CommonMaterial* material) +{ + auto data = material->GetMaterialData(); + + for (int i = 0; i < data->numParameters; i++) + { + ImGui::PushID(i); + ImGui::InputFloat4("##Parameters", &data->parameters[i * 4]); + ImGui::PopID(); + } +} \ No newline at end of file diff --git a/src/modules/Materials.h b/src/modules/Materials.h new file mode 100644 index 0000000..50fb285 --- /dev/null +++ b/src/modules/Materials.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Module.h" +#include "render/Material.h" + +class Materials : public Module +{ +private: + bool m_show = false; + cdc::CommonMaterial* m_selected = nullptr; + char m_filter[12] = ""; + + void DrawMaterialEditor(); + void DrawMaterialEditor(cdc::CommonMaterial* material); + +public: + void OnDraw(); + void OnMenu(); +}; \ No newline at end of file diff --git a/src/render/Material.h b/src/render/Material.h new file mode 100644 index 0000000..2232b58 --- /dev/null +++ b/src/render/Material.h @@ -0,0 +1,12 @@ +#pragma once + +#include "cdc/render/CommonMaterial.h" + +struct MaterialEntry +{ + cdc::CommonMaterial* pMaterial; + int field_4; + unsigned int refCount; + unsigned int size; + unsigned int versionID; +}; \ No newline at end of file