55#include " AModLoaderTask.h"
66#include " ACoreSettings.h"
77
8+ #include " Enhancements/AInstanceManager2.h"
9+ #include " Enhancements/ATreeManager2.h"
10+
811#include < BYardSDK/AGameStateController.h>
912#include < BYardSDK/THookedRenderD3DInterface.h>
1013#include < BYardSDK/AAssetLoader.h>
1316#include < BYardSDK/ACamera.h>
1417#include < BYardSDK/THookedSingleton.h>
1518#include < BYardSDK/THookedMemory.h>
19+ #include < BYardSDK/AGlowViewport.h>
1620
17- #include < Animation /AModel.h>
18- #include < Animation /AModelRepos.h>
21+ #include < BYardSDK /AModel.h>
22+ #include < BYardSDK /AModelRepos.h>
1923
2024#include < Input/TInputDeviceKeyboard.h>
2125#include < Render/TCameraObject.h>
@@ -543,9 +547,7 @@ MEMBER_HOOK( 0x006154c0, ARenderer, ARenderer_CreateTRender, TBOOL )
543547{
544548 TBOOL bResult = CallOriginal ();
545549
546- TRenderInterface::SetSingletonExplicit (
547- THookedRenderD3DInterface::GetSingleton ()
548- );
550+ TRenderInterface::SetSingletonExplicit (THookedRenderD3DInterface::GetSingleton ());
549551
550552 AGlobalModLoaderTask::Get ()->OnRenderInterfaceReady ();
551553
@@ -580,6 +582,7 @@ MEMBER_HOOK( 0x0060c7c0, ARenderer, ARenderer_OnCreate, TBOOL )
580582 if ( !g_pCommandLine->HasParameter ( " -noimgui" ) )
581583 AImGUI::CreateSingleton ();
582584
585+ AGlowViewport::SetSingletonExplicit ( *TREINTERPRETCAST ( AGlowViewport**, 0x0079b180 ) );
583586 return bResult;
584587}
585588
@@ -791,7 +794,7 @@ MEMBER_HOOK( 0x006d5970, TOrderTable, TOrderTable_Flush, void )
791794
792795HOOK ( 0x006114d0 , AModelLoader_AModelLoaderLoadTRBCallback, TBOOL, TModel* a_pModel )
793796{
794- TBOOL bRes;
797+ TBOOL bRes = TFALSE ;
795798
796799 for ( TINT i = 0 ; i < AHooks::ModelLoader::LoadTRBCallback[ HookType_Before ].Size (); i++ )
797800 {
@@ -808,82 +811,6 @@ HOOK( 0x006114d0, AModelLoader_AModelLoaderLoadTRBCallback, TBOOL, TModel* a_pMo
808811 return bRes;
809812}
810813
811- TBOOL g_bNoCullingInRadiusOfObject = TTRUE;
812- TFLOAT g_fNoCullingAdditionalRadius = 50 .0f ;
813-
814- HOOK ( 0x006cead0 , TRenderContext_CullSphereToFrustumSimple, TBOOL, const TSphere& a_rSphere, const TPlane* a_pPlanes, int a_iNumPlane )
815- {
816- if ( g_bNoCullingInRadiusOfObject && ACameraManager::IsSingletonCreated () )
817- {
818- auto pCamera = ACameraManager::GetSingleton ()->GetCurrentCamera ();
819- auto & vCameraTranslation = pCamera->m_Matrix .GetTranslation ();
820-
821- auto fDistance = TVector3::DistanceSq ( a_rSphere.GetOrigin (), vCameraTranslation.AsVector3 () );
822-
823- if ( fDistance <= a_rSphere.GetRadius () + g_fNoCullingAdditionalRadius )
824- {
825- return TTRUE;
826- }
827- }
828-
829- for ( TSIZE i = 0 ; i < 6 ; i++ )
830- {
831- TFLOAT fDist = TVector4::DotProduct3 ( a_rSphere.AsVector4 (), a_pPlanes[ i ].AsVector4 () );
832-
833- if ( a_rSphere.GetRadius () < fDist - a_pPlanes[ i ].GetD () )
834- return TFALSE;
835- }
836-
837- return TTRUE;
838- }
839-
840- HOOK ( 0x006cea40 , TRenderContext_CullSphereToFrustum, TINT, const TSphere& a_rSphere, const TPlane* a_pPlanes, TINT a_iClipFlags, TINT a_iClipFlagsMask )
841- {
842- if ( g_bNoCullingInRadiusOfObject && ACameraManager::IsSingletonCreated () )
843- {
844- auto pCamera = ACameraManager::GetSingleton ()->GetCurrentCamera ();
845- auto & vCameraTranslation = pCamera->m_Matrix .GetTranslation ();
846-
847- auto fDistance = TVector3::DistanceSq ( a_rSphere.GetOrigin (), vCameraTranslation.AsVector3 () );
848-
849- if ( fDistance <= a_rSphere.GetRadius () + g_fNoCullingAdditionalRadius )
850- {
851- return a_iClipFlags;
852- }
853- }
854-
855- TINT iLeftPlanes = a_iClipFlags & a_iClipFlagsMask;
856- TINT iPlaneFlag = 1 ;
857-
858- do {
859- if ( iLeftPlanes == 0 )
860- {
861- return a_iClipFlags;
862- }
863-
864- if ( iLeftPlanes & iPlaneFlag )
865- {
866- TFLOAT fDist = TVector4::DotProduct3 ( a_rSphere.AsVector4 (), a_pPlanes->AsVector4 () ) - a_pPlanes->GetD ();
867-
868- if ( a_rSphere.GetRadius () < fDist )
869- {
870- return -1 ;
871- }
872-
873- if ( fDist < -a_rSphere.GetRadius () )
874- {
875- a_iClipFlags &= ~iPlaneFlag;
876- }
877-
878- iLeftPlanes &= ~iPlaneFlag;
879- }
880-
881- iPlaneFlag = iPlaneFlag << 1 ;
882- a_pPlanes++;
883-
884- } while ( TTRUE );
885- }
886-
887814MEMBER_HOOK ( 0x006bbb00 , TSystemManager, TSystemManager_Update, void )
888815{
889816 if ( g_oSettings.bLimitFPS )
@@ -1008,12 +935,9 @@ MEMBER_HOOK( 0x006d8a00, Toshi::TMutexLock, TMutexLock_Destructor, void )
1008935}
1009936#endif
1010937
1011- struct AInstanceManager
1012- {};
1013-
1014938MEMBER_HOOK ( 0x005e1e80 , AInstanceManager, AInstanceManager_LoadModels, TBOOL, TINT a_iInstanceLibIndex, TINT a_iNumModels, TUINT* a_pModelIndices, TBOOL a_bCreateCollisionModelNodes, TBOOL a_bCreateCollisionModelInstances, TINT a_iNumCollisionModelNodes )
1015939{
1016- if ( TTRUE || g_oSettings.bLoadAnyLevel )
940+ if ( g_oSettings.bForceAllInstances )
1017941 {
1018942 TUINT aIndices[137 ];
1019943 for (TINT i = 0 ; i < 137 ; i++)
@@ -1027,6 +951,28 @@ MEMBER_HOOK( 0x005e1e80, AInstanceManager, AInstanceManager_LoadModels, TBOOL, T
1027951 return CallOriginal ( a_iInstanceLibIndex, a_iNumModels, a_pModelIndices, a_bCreateCollisionModelNodes, a_bCreateCollisionModelInstances, a_iNumCollisionModelNodes );
1028952}
1029953
954+ MEMBER_HOOK ( 0x005e14d0 , AInstanceManager2, AInstanceManager_FillRenderList_All, void , const Toshi::T2SList<AInstanceManager::StaticInstanceEntry>& a_rcInstanceList, const Toshi::TMatrix44& a_rcWorldTransform, AInstanceManager::RenderListEntry* a_pOutRenderData, TINT& a_rNumInstances, TBOOL a_bDynamic )
955+ {
956+ AInstanceManager2::FillRenderList_All ( a_rcInstanceList, a_rcWorldTransform, a_pOutRenderData, a_rNumInstances, a_bDynamic );
957+ }
958+
959+ MEMBER_HOOK ( 0x005e10e0 , AInstanceManager2, AInstanceManager_FillRenderList_Visible, void , const Toshi::T2SList<AInstanceManager::StaticInstanceEntry>& a_rcInstanceList, const Toshi::TMatrix44& a_rcWorldTransform, AInstanceManager::RenderListEntry* a_pOutRenderData, TINT& a_rNumInstances, TBOOL a_bDynamic )
960+ {
961+ AInstanceManager2::FillRenderList_Visible ( a_rcInstanceList, a_rcWorldTransform, a_pOutRenderData, a_rNumInstances, a_bDynamic );
962+ }
963+
964+ MEMBER_HOOK ( 0x005e17a0 , AInstanceManager2, AInstanceManager_Render, TBOOL )
965+ {
966+ return AInstanceManager2::Render ();
967+ }
968+
969+ MEMBER_HOOK ( 0x005ef3a0 , ATreeManager2, ATreeManager_Render, void )
970+ {
971+ ATreeManager2::Render ();
972+
973+ if ( !g_oSettings.bDisableTreeRendering ) CallOriginal ();
974+ }
975+
1030976void AHooks::Initialise ()
1031977{
1032978 // Apply other hooks
@@ -1062,8 +1008,6 @@ void AHooks::Initialise()
10621008 InstallHook<ADisplayModes_Win_DoesModeExist>();
10631009 // InstallHook<TCameraObject_SetFOV>();
10641010 InstallHook<TRenderD3DInterface_UpdateColourSettings>();
1065- // InstallHook<TRenderContext_CullSphereToFrustumSimple>();
1066- // InstallHook<TRenderContext_CullSphereToFrustum>();
10671011 InstallHook<TTRB_Load>();
10681012
10691013 // Fixing crashes and memory stumps of the original game
@@ -1083,6 +1027,11 @@ void AHooks::Initialise()
10831027 // InstallHook<TNativeFile_FlushWriteBuffer>();
10841028
10851029 InstallHook<AInstanceManager_LoadModels>();
1030+ InstallHook<AInstanceManager_FillRenderList_All>();
1031+ InstallHook<AInstanceManager_FillRenderList_Visible>();
1032+ InstallHook<AInstanceManager_Render>();
1033+
1034+ InstallHook<ATreeManager_Render>();
10861035
10871036#ifdef USE_ATOMIC
10881037 InstallHook<TMutex_Create>();
0 commit comments