diff --git a/src/core/StructTest.h b/src/core/StructTest.h index 25fe598..fc9c53f 100644 --- a/src/core/StructTest.h +++ b/src/core/StructTest.h @@ -3,3 +3,6 @@ #include "ViewportRenderState.h" MACRO_STRUCT_RESOLVER(ViewportRenderState, false, 0x100) ViewportRenderState_Struct; + +// in this case, it will just instantiate the struct, calling the constructor, but only if implemented +MACRO_STRUCT_INSTANCE(ViewportRenderState, 0x100); diff --git a/src/core/ViewportRenderState.cpp b/src/core/ViewportRenderState.cpp index 20146bf..cb69806 100644 --- a/src/core/ViewportRenderState.cpp +++ b/src/core/ViewportRenderState.cpp @@ -3,18 +3,6 @@ #include "windowslib.h" -// could also be placed in own file against the clutter -// PROBLEM: Needs definition of address twice, could however be helped if addresses are moved into own struct/file -MACRO_STRUCT_INSTANCE(ViewportRenderState, 0x100) -{ - // needs direct create return to properly work - // interestingly, "ViewportRenderState" here would be so big, - // a stack overflow would occur if it was not optimized to be no copy - // works with variables - // might work good together with the copy prevention - return ViewportRenderState(); -} - ViewportRenderState::ViewportRenderState() { MACRO_CALL_MEMBER(ViewportRenderState_Func::_constructor_, this)(); } // FUNCTION: STRONGHOLDCRUSADER 0x004e1fa0 diff --git a/src/precomp/StructResolver.h b/src/precomp/StructResolver.h index 3160ea3..8930932 100644 --- a/src/precomp/StructResolver.h +++ b/src/precomp/StructResolver.h @@ -5,14 +5,10 @@ struct StructResolver { private: - template static T instance(); + template struct Instance; template struct InternalResolver; template struct InternalResolver { - private: - static T instance; - - public: static T* const ptr; }; template struct InternalResolver { @@ -44,9 +40,10 @@ struct StructResolver { template T* const StructResolver::InternalResolver::ptr = reinterpret_cast(gameAddress); + template -T StructResolver::InternalResolver::instance = StructResolver::instance(); -template T* const StructResolver::InternalResolver::ptr = &instance; +T* const StructResolver::InternalResolver::ptr + = &StructResolver::Instance::instance; template bool StructResolver::AddressUsageKeeper
::initialized = false; @@ -65,6 +62,9 @@ StructResolver::Resolver::Initializer::Initializer( typedef StructResolver::Resolver::Ptr #define MACRO_STRUCT_INSTANCE(STRUCT_TYPE, GAME_ADDRESS) \ - template <> STRUCT_TYPE StructResolver::instance() + template struct StructResolver::Instance { \ + static STRUCT_TYPE instance; \ + }; \ + template STRUCT_TYPE StructResolver::Instance::instance #endif // STRUCT_RESOLVER