From f382b89a8dbe63343d17f8a8c7e20c0e4ffbf966 Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 18 Nov 2024 03:58:38 +0300 Subject: [PATCH] [CKPE] SF: - Refuse asunc load materials. - Fixed incorrect used QSplashScreen, swap finish() and show(); - Added "Initializing Materials..." in QSplashScreen; --- .../Core/EngineSFPatches.cpp | 4 +- ...reation Kit Platform Extended Core.vcxproj | 4 +- ...Kit Platform Extended Core.vcxproj.filters | 4 +- .../Patches/SF/LoadMaterialsAsync.cpp | 86 ----------- .../Patches/SF/LoadMaterialsQSplash.cpp | 135 ++++++++++++++++++ ...aterialsAsync.h => LoadMaterialsQSplash.h} | 18 ++- .../Version/build_version.txt | Bin 12 -> 12 bytes .../Version/resource_version2.h | Bin 2004 -> 2004 bytes ...nKitPlatformExtended_SF_1_14_70_0.database | Bin 17222 -> 17521 bytes Database/SF/1_14_70_0/LoadMaterialsAsync.relb | 5 - .../SF/1_14_70_0/LoadMaterialsQSplash.relb | 5 + 11 files changed, 160 insertions(+), 101 deletions(-) delete mode 100644 Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsAsync.cpp create mode 100644 Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsQSplash.cpp rename Creation Kit Platform Extended Core/Patches/SF/{LoadMaterialsAsync.h => LoadMaterialsQSplash.h} (68%) delete mode 100644 Database/SF/1_14_70_0/LoadMaterialsAsync.relb create mode 100644 Database/SF/1_14_70_0/LoadMaterialsQSplash.relb diff --git a/Creation Kit Platform Extended Core/Core/EngineSFPatches.cpp b/Creation Kit Platform Extended Core/Core/EngineSFPatches.cpp index 3909ece..db6b1c5 100644 --- a/Creation Kit Platform Extended Core/Core/EngineSFPatches.cpp +++ b/Creation Kit Platform Extended Core/Core/EngineSFPatches.cpp @@ -16,7 +16,7 @@ #include "Patches/SF/RemoveUselessMessagesSF.h" #include "Patches/SF/RemoveUselessResizeInDialogs.h" #include "Patches/SF/RemoveThreadDpi.h" -#include "Patches/SF/LoadMaterialsAsync.h" +#include "Patches/SF/LoadMaterialsQSplash.h" #include "Patches/SF/FixQuoteCmdLineSF.h" #include "Patches/SF/AllowSaveESMandMasterESPSF.h" @@ -49,7 +49,7 @@ namespace CreationKitPlatformExtended new Patches::RemoveUselessMessagesPatch(), //new Patches::RemoveUselessResizeInDialogsPatch(), new Patches::RemoveThreadDpiPatch(), - //new Patches::LoadMaterialsAsyncPatch(), + new Patches::LoadMaterialsQSplashPatch(), new Patches::FixQuoteCmdLinePatch(), new Patches::AllowSaveESMandMasterESPPatch(), diff --git a/Creation Kit Platform Extended Core/Creation Kit Platform Extended Core.vcxproj b/Creation Kit Platform Extended Core/Creation Kit Platform Extended Core.vcxproj index 8a67892..80b2ff4 100644 --- a/Creation Kit Platform Extended Core/Creation Kit Platform Extended Core.vcxproj +++ b/Creation Kit Platform Extended Core/Creation Kit Platform Extended Core.vcxproj @@ -256,7 +256,7 @@ - + @@ -656,7 +656,7 @@ - + diff --git a/Creation Kit Platform Extended Core/Creation Kit Platform Extended Core.vcxproj.filters b/Creation Kit Platform Extended Core/Creation Kit Platform Extended Core.vcxproj.filters index 66e2923..e5a2429 100644 --- a/Creation Kit Platform Extended Core/Creation Kit Platform Extended Core.vcxproj.filters +++ b/Creation Kit Platform Extended Core/Creation Kit Platform Extended Core.vcxproj.filters @@ -874,7 +874,7 @@ Patches\SF - + Patches\SF @@ -2152,7 +2152,7 @@ Patches\SF - + Patches\SF diff --git a/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsAsync.cpp b/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsAsync.cpp deleted file mode 100644 index 54b8f17..0000000 --- a/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsAsync.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright © 2023-2024 aka perchik71. All rights reserved. -// Contacts: -// License: https://www.gnu.org/licenses/gpl-3.0.html - -#include "Core/Engine.h" -#include "LoadMaterialsAsync.h" - -namespace CreationKitPlatformExtended -{ - namespace Patches - { - namespace Starfield - { - uintptr_t pointer_LoadMaterialsAsyncPatch_sub0 = 0; - - LoadMaterialsAsyncPatch::LoadMaterialsAsyncPatch() : Module(GlobalEnginePtr) - {} - - bool LoadMaterialsAsyncPatch::HasOption() const - { - return false; - } - - bool LoadMaterialsAsyncPatch::HasCanRuntimeDisabled() const - { - return false; - } - - const char* LoadMaterialsAsyncPatch::GetOptionName() const - { - return nullptr; - } - - const char* LoadMaterialsAsyncPatch::GetName() const - { - return "Load Materials Async"; - } - - bool LoadMaterialsAsyncPatch::HasDependencies() const - { - return false; - } - - Array LoadMaterialsAsyncPatch::GetDependencies() const - { - return {}; - } - - bool LoadMaterialsAsyncPatch::QueryFromPlatform(EDITOR_EXECUTABLE_TYPE eEditorCurrentVersion, - const char* lpcstrPlatformRuntimeVersion) const - { - return eEditorCurrentVersion >= EDITOR_EXECUTABLE_TYPE::EDITOR_STARFIELD_1_14_70_0; - } - - bool LoadMaterialsAsyncPatch::Activate(const Relocator* lpRelocator, - const RelocationDatabaseItem* lpRelocationDatabaseItem) - { - if (lpRelocationDatabaseItem->Version() == 1) - { - pointer_LoadMaterialsAsyncPatch_sub0 = _RELDATA_ADDR(0); - lpRelocator->DetourCall(_RELDATA_RAV(1), (uintptr_t)&sub); - - return true; - } - - return false; - } - - bool LoadMaterialsAsyncPatch::Shutdown(const Relocator* lpRelocator, - const RelocationDatabaseItem* lpRelocationDatabaseItem) - { - return false; - } - - void LoadMaterialsAsyncPatch::sub(void* arg1, void* arg2) - { - auto mat_thread = std::thread([](void* arg1, void* arg2) { - fastCall(pointer_LoadMaterialsAsyncPatch_sub0, arg1, arg2); - }, arg1, arg2); - - SetThreadPriority(mat_thread.native_handle(), THREAD_PRIORITY_HIGHEST); - mat_thread.join(); - } - } - } -} \ No newline at end of file diff --git a/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsQSplash.cpp b/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsQSplash.cpp new file mode 100644 index 0000000..d64122e --- /dev/null +++ b/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsQSplash.cpp @@ -0,0 +1,135 @@ +// Copyright © 2023-2024 aka perchik71. All rights reserved. +// Contacts: +// License: https://www.gnu.org/licenses/gpl-3.0.html + +#include "Core/Engine.h" +#include "LoadMaterialsQSplash.h" + +namespace CreationKitPlatformExtended +{ + namespace Patches + { + namespace Starfield + { + static constexpr const char* MESSAGE = "Initializing Materials..."; + + HANDLE g_LoadMaterialsQSplashPatch_wait = NULL; + uintptr_t pointer_LoadMaterialsQSplashPatch_sub0 = 0; +#ifdef _CKPE_WITH_QT5 + QSplashScreen* g_LoadMaterialsQSplashPatch_logoWin = nullptr; + QWidget* g_LoadMaterialsQSplashPatch_mainWin = nullptr; +#endif // !_CKPE_WITH_QT5 + + LoadMaterialsQSplashPatch::LoadMaterialsQSplashPatch() : Module(GlobalEnginePtr) + {} + + bool LoadMaterialsQSplashPatch::HasOption() const + { + return false; + } + + bool LoadMaterialsQSplashPatch::HasCanRuntimeDisabled() const + { + return false; + } + + const char* LoadMaterialsQSplashPatch::GetOptionName() const + { + return nullptr; + } + + const char* LoadMaterialsQSplashPatch::GetName() const + { + return "Load Materials QSplash"; + } + + bool LoadMaterialsQSplashPatch::HasDependencies() const + { + return false; + } + + Array LoadMaterialsQSplashPatch::GetDependencies() const + { + return {}; + } + + bool LoadMaterialsQSplashPatch::QueryFromPlatform(EDITOR_EXECUTABLE_TYPE eEditorCurrentVersion, + const char* lpcstrPlatformRuntimeVersion) const + { + return eEditorCurrentVersion >= EDITOR_EXECUTABLE_TYPE::EDITOR_STARFIELD_1_14_70_0; + } + + bool LoadMaterialsQSplashPatch::Activate(const Relocator* lpRelocator, + const RelocationDatabaseItem* lpRelocationDatabaseItem) + { +#ifdef _CKPE_WITH_QT5 + if (lpRelocationDatabaseItem->Version() == 1) + { + // Bethesda error: finish() must be called after show() + // READ DOC: https://doc.qt.io/qt-6/qsplashscreen.html#finish + // Erase error, replace it with our own + lpRelocator->DetourCall(_RELDATA_RAV(0), (uintptr_t)&hk_finish); + lpRelocator->PatchNop(_RELDATA_RAV(0) + 5, 0xA); + + *(uintptr_t*)&pointer_LoadMaterialsQSplashPatch_sub0 = + voltek::detours_function_class_jump(_RELDATA_ADDR(1), (uintptr_t)&sub); + + return true; + } +#endif // !_CKPE_WITH_QT5 + + return false; + } + + bool LoadMaterialsQSplashPatch::Shutdown(const Relocator* lpRelocator, + const RelocationDatabaseItem* lpRelocationDatabaseItem) + { + return false; + } + +#ifdef _CKPE_WITH_QT5 + void LoadMaterialsQSplashPatch::hk_finish(QSplashScreen* logoWin, QWidget* mainWin) + { + logoWin->showMessage(MESSAGE, 1, Qt::red); + // Instead of QtCore::ProcessMessage, since CKPE Qt is not initialized + Utils::ProcessMessage(); + // Wait loading materials + g_LoadMaterialsQSplashPatch_wait = CreateEvent(NULL, TRUE, FALSE, NULL); + ResetEvent(g_LoadMaterialsQSplashPatch_wait); + WaitForSingleObject(g_LoadMaterialsQSplashPatch_wait, INFINITE); + CloseHandle(g_LoadMaterialsQSplashPatch_wait); + // Show main window + mainWin->show(); + logoWin->finish(mainWin); + } +#endif // !_CKPE_WITH_QT5 + + void LoadMaterialsQSplashPatch::sub(void* arg1, void* arg2) + { + _CONSOLE(MESSAGE); + // To be processed faster by the process + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); + // Load + _CONSOLE("%s %s", MESSAGE, LoadMaterials(arg1, arg2) ? "SUCCESS" : "FATAL"); + // Return priority + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); + // End loading + SetEvent(g_LoadMaterialsQSplashPatch_wait); + } + + bool LoadMaterialsQSplashPatch::LoadMaterials(void* arg1, void* arg2) + { + __try + { + fastCall(pointer_LoadMaterialsQSplashPatch_sub0, arg1, arg2); + } + __except (EXCEPTION_EXECUTE_HANDLER) + { + return false; + } + + return true; + } + } + } +} \ No newline at end of file diff --git a/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsAsync.h b/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsQSplash.h similarity index 68% rename from Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsAsync.h rename to Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsQSplash.h index 305fe70..7dfdbd6 100644 --- a/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsAsync.h +++ b/Creation Kit Platform Extended Core/Patches/SF/LoadMaterialsQSplash.h @@ -8,6 +8,11 @@ #include "Core/Relocator.h" #include "Core/RelocationDatabase.h" +#ifdef _CKPE_WITH_QT5 +# include "QtWidgets/qwidget.h" +# include "QtWidgets/qsplashscreen.h" +#endif // !_CKPE_WITH_QT5 + namespace CreationKitPlatformExtended { namespace Patches @@ -16,10 +21,10 @@ namespace CreationKitPlatformExtended { using namespace CreationKitPlatformExtended::Core; - class LoadMaterialsAsyncPatch : public Module + class LoadMaterialsQSplashPatch : public Module { public: - LoadMaterialsAsyncPatch(); + LoadMaterialsQSplashPatch(); virtual bool HasOption() const; virtual bool HasCanRuntimeDisabled() const; @@ -28,15 +33,20 @@ namespace CreationKitPlatformExtended virtual bool HasDependencies() const; virtual Array GetDependencies() const; +#ifdef _CKPE_WITH_QT5 + static void hk_finish(QSplashScreen* logoWin, QWidget* mainWin); +#endif // !_CKPE_WITH_QT5 + static void sub(void* arg1, void* arg2); + static bool LoadMaterials(void* arg1, void* arg2); protected: virtual bool QueryFromPlatform(EDITOR_EXECUTABLE_TYPE eEditorCurrentVersion, const char* lpcstrPlatformRuntimeVersion) const; virtual bool Activate(const Relocator* lpRelocator, const RelocationDatabaseItem* lpRelocationDatabaseItem); virtual bool Shutdown(const Relocator* lpRelocator, const RelocationDatabaseItem* lpRelocationDatabaseItem); private: - LoadMaterialsAsyncPatch(const LoadMaterialsAsyncPatch&) = default; - LoadMaterialsAsyncPatch& operator=(const LoadMaterialsAsyncPatch&) = default; + LoadMaterialsQSplashPatch(const LoadMaterialsQSplashPatch&) = default; + LoadMaterialsQSplashPatch& operator=(const LoadMaterialsQSplashPatch&) = default; }; } } diff --git a/Creation Kit Platform Extended Core/Version/build_version.txt b/Creation Kit Platform Extended Core/Version/build_version.txt index d06c4bfcfa76d92717c9c12c68c7f7d33e586ff1..26b8d8c1fa8084b2d6c649202702a0b0074814e4 100644 GIT binary patch literal 12 TcmezW&w{~_!GM96fr|kE90~%i literal 12 TcmezW&z!-M!GeL8fr|kE9B=}? diff --git a/Creation Kit Platform Extended Core/Version/resource_version2.h b/Creation Kit Platform Extended Core/Version/resource_version2.h index e734571abed29ed6db679da40769894ba5c38fee..31d606418ade7ffd63ab3e860adf676d7e0b3758 100644 GIT binary patch delta 30 mcmcb@e}#X;J!Vb|1_K6523`iP$&Ad>lOtHAHp{T=UlOtHAHp{T=U1Lp zS`a%yXAa{O1~)gu$^BL`f|eFe&aSQ&_E6yJG?~v-CeQ>ZY+(iybT+dvfUyk>oh%Iv z42%tc0HMvq!ot$R6s88qGj%pFH?gVe)4}^iF!9jpp27?C5W`JL{e>O z;%o#|4c2D~(g$Q2I~&^DquAhN;e@0IQ{K|V1Z0YZlL^qZ7Em70Bui6>>FgF3E+%gF L_M1P*g{c4lwGK}o delta 93 zcmey^!Fa5Val;}xzc2;}U<6Vk3_kgZDGI)cC8VOE$w59&E=)jK9jHnW f`$8KxD;vXuimBWT3=6dRfoz2m5PP$ -50F2BA0 0 \ No newline at end of file diff --git a/Database/SF/1_14_70_0/LoadMaterialsQSplash.relb b/Database/SF/1_14_70_0/LoadMaterialsQSplash.relb new file mode 100644 index 0000000..2bf4d8b --- /dev/null +++ b/Database/SF/1_14_70_0/LoadMaterialsQSplash.relb @@ -0,0 +1,5 @@ +Load Materials QSplash +1 +extended +19C2C60 0 FF15????????498BCEFF15????????498BCEE8????????EB??488D8D????????FF15????????498B86????????C680????????01B910030000E8????????488985????????4885C074?? +50B86D0 0 v0_48895C24??574883EC??488BFA488BD9488B89????????48894C24??4885C974??4883C1??E8????????488B8B????????4883C1??E8????????48894424??8B40??894424??48895C24??488D4F?? \ No newline at end of file