diff --git a/reversing/sf6.genny b/reversing/sf6.genny index 662d449dd..b5a514367 100644 --- a/reversing/sf6.genny +++ b/reversing/sf6.genny @@ -1232,7 +1232,7 @@ struct RenderOutput : via.Component 0x1000 { SceneArray2 scenes @ 0x98 } -struct RenderResource { +struct RenderResource 0x18 { //void* vtable; Poop* unkpoop; int32_t ref_count @ 8; @@ -1263,7 +1263,7 @@ struct DXResource : via.render.RenderResource { void* destructor; }; -struct Texture : RenderResource { +struct Texture : RenderResource 0x90 { via.render.UsageType usage_type; TextureDesc desc + 4; uint32_t vram; @@ -1271,15 +1271,7 @@ struct Texture : RenderResource { }; struct TextureDX12 : Texture 0x1000 { - uint16_t index + 2; // might not be right. - DXResource* unk_resource + 0xC; - uint32_t last_frame; - uint32_t locked_thing; - uint32_t scale; - bool b1; - bool b2; - - DXResource* resource @ 0xA0 + DXResource* resource + 0x28 // IDK }; @@ -1311,12 +1303,12 @@ struct RenderLayer : via.clr.ManagedObject 0x88 { uint32_t version }; -struct RenderTargetView : via.render.RenderResource 0x90 { +struct RenderTargetView : via.render.RenderResource 0x98 { uint32_t format uint32_t dimension } -struct RenderTargetViewDX12 : RenderTargetView 0x100 { +struct RenderTargetViewDX12 : RenderTargetView 0x108 { struct via.render.TargetState* output_target TextureDX12* tex } @@ -1328,7 +1320,7 @@ struct DepthStencilView : via.render.RenderResource 0x18 { struct DepthStencilViewDX12 : DepthStencilView 0x100 { uint32_t format2 - TextureDX12* tex @ 0x30 + TextureDX12* tex + 0x20 } struct TargetState : via.render.RenderResource 0x1000 { diff --git a/shared/sdk/Renderer.cpp b/shared/sdk/Renderer.cpp index cf8b5b03d..4b63375ff 100644 --- a/shared/sdk/Renderer.cpp +++ b/shared/sdk/Renderer.cpp @@ -7,6 +7,7 @@ #include "Application.hpp" #include "RETypeDB.hpp" +#include "RETypes.hpp" #include "SceneManager.hpp" #include "Renderer.hpp" @@ -1105,6 +1106,51 @@ sdk::intrusive_ptr RenderTargetView::clone(uint32_t new_width, return sdk::renderer::create_render_target_view(tex->clone(new_width, new_height), &get_desc()); } +namespace detail { +#if TDB_VER == 71 +#ifdef SF6 + constexpr auto rtv_size = 0x98; +#else + constexpr auto rtv_size = 0x98 - sizeof(void*); +#endif +#elif TDB_VER == 70 + constexpr auto rtv_size = 0x90 - sizeof(void*); +#elif TDB_VER == 69 + constexpr auto rtv_size = 0x88 - sizeof(void*); +#elif TDB_VER <= 67 +// TODO: 66 and below + constexpr auto rtv_size = 0x88 - sizeof(void*); +#endif +} + +sdk::intrusive_ptr& RenderTargetView::get_texture_d3d12() const { + // The via.render.RenderTargetView is not part of the normal TDB... I think. + static const auto rtv_type = reframework::get_types()->get("via.render.RenderTargetView"); + + // The texture and target state members are always at the very start of the RenderTargetViewDX12 structure + // so we can very easily automate it like this, otherwise we fall back to the hardcoded offset + if (rtv_type != nullptr && rtv_type->size > 0 && rtv_type->size < 0x1000) { + const auto rtv_size = rtv_type->size; + + return *(sdk::intrusive_ptr*)((uintptr_t)this + rtv_size + sizeof(void*)); + } + + return *(sdk::intrusive_ptr*)((uintptr_t)this + detail::rtv_size + sizeof(void*)); +} + +sdk::intrusive_ptr& RenderTargetView::get_target_state_d3d12() const { + // The via.render.RenderTargetView is not part of the normal TDB... I think. + static const auto rtv_type = reframework::get_types()->get("via.render.RenderTargetView"); + + if (rtv_type != nullptr && rtv_type->size > 0 && rtv_type->size < 0x1000) { + const auto rtv_size = rtv_type->size; + + return *(sdk::intrusive_ptr*)((uintptr_t)this + rtv_size); + } + + return *(sdk::intrusive_ptr*)((uintptr_t)this + detail::rtv_size); +} + sdk::intrusive_ptr TargetState::clone() const { auto cloned_desc = get_desc(); diff --git a/shared/sdk/Renderer.hpp b/shared/sdk/Renderer.hpp index 6a3392547..d1c6cf031 100644 --- a/shared/sdk/Renderer.hpp +++ b/shared/sdk/Renderer.hpp @@ -42,11 +42,7 @@ template class DirectXResource : public RenderResource { public: T* get_native_resource() const { - #if TDB_VER > 67 - return *(ID3D12Resource**)((uintptr_t)this + 0x10); - #else - return *(ID3D12Resource**)((uintptr_t)this + 0x18); - #endif + return *(ID3D12Resource**)((uintptr_t)this + sizeof(RenderResource)); } private: @@ -94,7 +90,13 @@ class Texture : public RenderResource { private: #if TDB_VER >= 71 +#ifdef SF6 + // So because this discrepancy in SF6 is > 8 bytes (which is how much was added to RenderResource), trying to automate this + // is a bit trickier so we can look into this later, and just hardcode it for now. + static constexpr inline auto s_d3d12_resource_offset = 0xB8; +#else static constexpr inline auto s_d3d12_resource_offset = 0xA0; +#endif #elif TDB_VER == 70 static constexpr inline auto s_d3d12_resource_offset = 0x98; #elif TDB_VER == 69 @@ -124,29 +126,11 @@ class RenderTargetView : public RenderResource { return m_desc; } - sdk::intrusive_ptr& get_texture_d3d12() const { - return *(sdk::intrusive_ptr*)((uintptr_t)this + s_texture_d3d12_offset); - } - - sdk::intrusive_ptr& get_target_state_d3d12() const { - return *(sdk::intrusive_ptr*)((uintptr_t)this + s_target_state_d3d12_offset); - } + sdk::intrusive_ptr& get_texture_d3d12() const; + sdk::intrusive_ptr& get_target_state_d3d12() const; private: Desc m_desc; - -#if TDB_VER == 71 - static constexpr inline auto s_texture_d3d12_offset = 0x98; -#elif TDB_VER == 70 - static constexpr inline auto s_texture_d3d12_offset = 0x90; -#elif TDB_VER == 69 - static constexpr inline auto s_texture_d3d12_offset = 0x88; -#elif TDB_VER <= 67 - // TODO: 66 and below - static constexpr inline auto s_texture_d3d12_offset = 0x88; -#endif - - static constexpr inline auto s_target_state_d3d12_offset = s_texture_d3d12_offset - sizeof(void*); }; static_assert(sizeof(RenderTargetView::Desc) == 0x14); @@ -202,7 +186,11 @@ class TargetState : public RenderResource { // more here but not needed... for now }; #if TDB_VER > 67 +#ifdef SF6 +static_assert(offsetof(TargetState, m_desc) + offsetof(TargetState::Desc, num_rtv) == 0x28); +#else static_assert(offsetof(TargetState, m_desc) + offsetof(TargetState::Desc, num_rtv) == 0x20); +#endif #else static_assert(offsetof(TargetState, m_desc) + offsetof(TargetState::Desc, num_rtv) == 0x28); #endif diff --git a/shared/sdk/renderer/RenderResource.hpp b/shared/sdk/renderer/RenderResource.hpp index 390b2240e..27a142a1e 100644 --- a/shared/sdk/renderer/RenderResource.hpp +++ b/shared/sdk/renderer/RenderResource.hpp @@ -15,5 +15,9 @@ class RenderResource { void* m_vtable; int32_t m_ref_count; uint32_t m_render_frame; + +#ifdef SF6 + void* _sf6_padding; // something added here in Dec 1 2023 update +#endif }; } \ No newline at end of file