Skip to content

Commit

Permalink
[CKPE]
Browse files Browse the repository at this point in the history
SF:
- Refuse asunc load materials.
- Fixed incorrect used QSplashScreen, swap finish() and show();
- Added "Initializing Materials..." in QSplashScreen;
  • Loading branch information
Perchik71 committed Nov 18, 2024
1 parent 792a48c commit f382b89
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 101 deletions.
4 changes: 2 additions & 2 deletions Creation Kit Platform Extended Core/Core/EngineSFPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
<ClCompile Include="Patches\RenderWindow60FPS.cpp" />
<ClCompile Include="Patches\SF\AllowSaveESMandMasterESPSF.cpp" />
<ClCompile Include="Patches\SF\FixQuoteCmdLineSF.cpp" />
<ClCompile Include="Patches\SF\LoadMaterialsAsync.cpp" />
<ClCompile Include="Patches\SF\LoadMaterialsQSplash.cpp" />
<ClCompile Include="Patches\SF\OptimizationLoadSF.cpp" />
<ClCompile Include="Patches\SF\RemoveThreadDpi.cpp" />
<ClCompile Include="Patches\SF\RemoveUselessMessagesSF.cpp" />
Expand Down Expand Up @@ -656,7 +656,7 @@
<ClInclude Include="Patches\RenderWindow60FPS.h" />
<ClInclude Include="Patches\SF\AllowSaveESMandMasterESPSF.h" />
<ClInclude Include="Patches\SF\FixQuoteCmdLineSF.h" />
<ClInclude Include="Patches\SF\LoadMaterialsAsync.h" />
<ClInclude Include="Patches\SF\LoadMaterialsQSplash.h" />
<ClInclude Include="Patches\SF\OptimizationLoadSF.h" />
<ClInclude Include="Patches\SF\RemoveThreadDpi.h" />
<ClInclude Include="Patches\SF\RemoveUselessMessagesSF.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@
<ClCompile Include="Patches\SF\RemoveThreadDpi.cpp">
<Filter>Patches\SF</Filter>
</ClCompile>
<ClCompile Include="Patches\SF\LoadMaterialsAsync.cpp">
<ClCompile Include="Patches\SF\LoadMaterialsQSplash.cpp">
<Filter>Patches\SF</Filter>
</ClCompile>
<ClCompile Include="Patches\FO4\DontMatchForms.cpp">
Expand Down Expand Up @@ -2152,7 +2152,7 @@
<ClInclude Include="Patches\SF\RemoveThreadDpi.h">
<Filter>Patches\SF</Filter>
</ClInclude>
<ClInclude Include="Patches\SF\LoadMaterialsAsync.h">
<ClInclude Include="Patches\SF\LoadMaterialsQSplash.h">
<Filter>Patches\SF</Filter>
</ClInclude>
<ClInclude Include="Patches\FO4\DontMatchForms.h">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright © 2023-2024 aka perchik71. All rights reserved.
// Contacts: <email:[email protected]>
// 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<String> 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<void>(pointer_LoadMaterialsQSplashPatch_sub0, arg1, arg2);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
return false;
}

return true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -28,15 +33,20 @@ namespace CreationKitPlatformExtended
virtual bool HasDependencies() const;
virtual Array<String> 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;
};
}
}
Expand Down
Binary file modified Creation Kit Platform Extended Core/Version/build_version.txt
Binary file not shown.
Binary file modified Creation Kit Platform Extended Core/Version/resource_version2.h
Binary file not shown.
Binary file not shown.
5 changes: 0 additions & 5 deletions Database/SF/1_14_70_0/LoadMaterialsAsync.relb

This file was deleted.

5 changes: 5 additions & 0 deletions Database/SF/1_14_70_0/LoadMaterialsQSplash.relb
Original file line number Diff line number Diff line change
@@ -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??

0 comments on commit f382b89

Please sign in to comment.