From ecf970adec3aa0f4aa725ce20207e20c8c8c8376 Mon Sep 17 00:00:00 2001 From: Guffawaffle Date: Sat, 10 Oct 2026 01:40:21 -0500 Subject: [PATCH 1/2] Apply configured backdrop scale when scenery loads --- mods/src/patches/parts/zoom.cc | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/mods/src/patches/parts/zoom.cc b/mods/src/patches/parts/zoom.cc index 6291c32a5..c319bf385 100644 --- a/mods/src/patches/parts/zoom.cc +++ b/mods/src/patches/parts/zoom.cc @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -534,6 +535,30 @@ void PlanetViewUtils_CameraZoomedEventHandler_Hook(auto original, PlanetViewUtil } } +void PlanetViewUtils_CreateBackdrop_Hook(auto original, PlanetViewUtils *_this, Il2CppObject *backdrop, + Il2CppObject *resource, bool usingDefault) +{ + original(_this, backdrop, resource, usingDefault); + // Native creation has now assigned the selected scenery's authored transform. + // Reuse the existing getter/scaling path before any player zoom event. + if (_this && resource) { + // A newly authored scale must not be compared with the previous system. + s_expectedScale = 0; + _this->GetFlatRenderable(); + } +} + +void PlanetViewUtils_CreateBackdropCollection_Hook(auto original, PlanetViewUtils *_this, Il2CppObject *backdrop, + Il2CppObject *resource, bool usingDefault) +{ + original(_this, backdrop, resource, usingDefault); + // The collection overload can load scenery without the Object callback. + if (_this && resource) { + s_expectedScale = 0; + _this->GetFlatRenderable(); + } +} + void NavigationZoom_SetViewParameters_Hook(auto original, NavigationZoom *_this, float radius, NodeDepth depth) { if (fleet_label_hooks_installed && depth != NodeDepth::SolarSystem) { @@ -701,6 +726,21 @@ void InstallZoomHooks() { auto pv_helper = il2cpp_get_class_helper("Assembly-CSharp", "Digit.Prime.Navigation", "PlanetViewUtils"); if (pv_helper.isValidHelper()) { + const auto *create = method_contract::Resolve( + pv_helper.get_cls(), "CreateBackdrop", false, "System.Void", + {"Digit.PrimeServer.Models.ITreeNode", "UnityEngine.Object", "System.Boolean"}); + const auto *create_collection = method_contract::Resolve( + pv_helper.get_cls(), "CreateBackdrop", false, "System.Void", + {"Digit.PrimeServer.Models.ITreeNode", "SystemVariationConfigCollection", "System.Boolean"}); + if (create) + SPUD_STATIC_DETOUR(create->methodPointer, PlanetViewUtils_CreateBackdrop_Hook); + else + ErrorMsg::MissingMethod("PlanetViewUtils", "CreateBackdrop(Object)"); + if (create_collection) + SPUD_STATIC_DETOUR(create_collection->methodPointer, PlanetViewUtils_CreateBackdropCollection_Hook); + else + ErrorMsg::MissingMethod("PlanetViewUtils", "CreateBackdrop(SystemVariationConfigCollection)"); + auto ptr_zoom = pv_helper.GetMethod("CameraZoomedEventHandler"); if (ptr_zoom != nullptr) { SPUD_STATIC_DETOUR(ptr_zoom, PlanetViewUtils_CameraZoomedEventHandler_Hook); From 812b534f2b1eb17870940409dd45d18c81c31734 Mon Sep 17 00:00:00 2001 From: Guffawaffle Date: Sat, 10 Oct 2026 03:19:38 -0500 Subject: [PATCH 2/2] Apply backdrop scale when cached system variations reload --- mods/src/patches/parts/zoom.cc | 26 ++++++++++++++++++++++++++ mods/src/prime/PopulatedSystemData.h | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/mods/src/patches/parts/zoom.cc b/mods/src/patches/parts/zoom.cc index c319bf385..2fb7af700 100644 --- a/mods/src/patches/parts/zoom.cc +++ b/mods/src/patches/parts/zoom.cc @@ -227,6 +227,7 @@ inline void StoreZoom(std::string label, float &zoom, NavigationZoom *_this) } static float s_expectedScale = 0; +static uint64_t s_backdropLoadRevision = 0; static void ApplySystemZoomRange(NavigationZoom *_this, float radius) { @@ -542,6 +543,7 @@ void PlanetViewUtils_CreateBackdrop_Hook(auto original, PlanetViewUtils *_this, // Native creation has now assigned the selected scenery's authored transform. // Reuse the existing getter/scaling path before any player zoom event. if (_this && resource) { + ++s_backdropLoadRevision; // A newly authored scale must not be compared with the previous system. s_expectedScale = 0; _this->GetFlatRenderable(); @@ -554,6 +556,24 @@ void PlanetViewUtils_CreateBackdropCollection_Hook(auto original, PlanetViewUtil original(_this, backdrop, resource, usingDefault); // The collection overload can load scenery without the Object callback. if (_this && resource) { + ++s_backdropLoadRevision; + s_expectedScale = 0; + _this->GetFlatRenderable(); + } +} + +void PlanetViewUtils_Populate_Hook(auto original, PlanetViewUtils *_this, Il2CppObject *system, int64_t nodeId, + NodeDepth depth) +{ + auto *previous_population = _this ? _this->_popData : nullptr; + const auto load_revision = s_backdropLoadRevision; + original(_this, system, nodeId, depth); + + // Cached variations reload their authored transforms in Populate rather than CreateBackdrop. + // A cached prefab backdrop already retains its scaled transform and must not be scaled again. + auto *population = _this ? _this->_popData : nullptr; + if (depth == NodeDepth::SolarSystem && population && population != previous_population + && population->VariationCollection && load_revision == s_backdropLoadRevision) { s_expectedScale = 0; _this->GetFlatRenderable(); } @@ -726,6 +746,12 @@ void InstallZoomHooks() { auto pv_helper = il2cpp_get_class_helper("Assembly-CSharp", "Digit.Prime.Navigation", "PlanetViewUtils"); if (pv_helper.isValidHelper()) { + auto ptr_populate = pv_helper.GetMethod("Populate"); + if (ptr_populate) + SPUD_STATIC_DETOUR(ptr_populate, PlanetViewUtils_Populate_Hook); + else + ErrorMsg::MissingMethod("PlanetViewUtils", "Populate"); + const auto *create = method_contract::Resolve( pv_helper.get_cls(), "CreateBackdrop", false, "System.Void", {"Digit.PrimeServer.Models.ITreeNode", "UnityEngine.Object", "System.Boolean"}); diff --git a/mods/src/prime/PopulatedSystemData.h b/mods/src/prime/PopulatedSystemData.h index ffb98404a..f361bf9af 100644 --- a/mods/src/prime/PopulatedSystemData.h +++ b/mods/src/prime/PopulatedSystemData.h @@ -6,6 +6,7 @@ struct PopulatedSystemData { public: __declspec(property(get = __get__backdrop)) void* _backdrop; __declspec(property(get = __get__systemId)) int64_t _systemId; + __declspec(property(get = __get__VariationCollection)) void* VariationCollection; private: static IL2CppClassHelper& get_class_helper() @@ -16,6 +17,12 @@ struct PopulatedSystemData { } public: + void* __get__VariationCollection() + { + static auto field = get_class_helper().GetField("k__BackingField"); + return field.get_info() ? *(void**)((ptrdiff_t)this + field.offset()) : nullptr; + } + void* __get__backdrop() { static auto field = get_class_helper().GetField("_backdrop");