Skip to content

Commit

Permalink
[CKPE]
Browse files Browse the repository at this point in the history
FO4 and SSE:
- AllowSaveESM patch unavailable vc mode;
SF:
- Added patch quotes support for CLI;
  • Loading branch information
Perchik71 committed Nov 15, 2024
1 parent c4649da commit a93629b
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 75 deletions.
2 changes: 2 additions & 0 deletions Creation Kit Platform Extended Core/Core/EngineSFPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Patches/SF/RemoveUselessResizeInDialogs.h"
#include "Patches/SF/RemoveThreadDpi.h"
#include "Patches/SF/LoadMaterialsAsync.h"
#include "Patches/SF/FixQuoteCmdLineSF.h"

#include "Patches/Windows/SF/DataWindowSF.h"
#include "Patches/Windows/SF/AboutWindowSF.h"
Expand Down Expand Up @@ -48,6 +49,7 @@ namespace CreationKitPlatformExtended
//new Patches::RemoveUselessResizeInDialogsPatch(),
new Patches::RemoveThreadDpiPatch(),
//new Patches::LoadMaterialsAsyncPatch(),
new Patches::FixQuoteCmdLinePatch(),

new Patches::DataWindow(),
new Patches::AboutWindow(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
<ClCompile Include="Patches\QuitHandlerPatch.cpp" />
<ClCompile Include="Patches\RenameCreationKitApp.cpp" />
<ClCompile Include="Patches\RenderWindow60FPS.cpp" />
<ClCompile Include="Patches\SF\FixQuoteCmdLineSF.cpp" />
<ClCompile Include="Patches\SF\LoadMaterialsAsync.cpp" />
<ClCompile Include="Patches\SF\OptimizationLoadSF.cpp" />
<ClCompile Include="Patches\SF\RemoveThreadDpi.cpp" />
Expand Down Expand Up @@ -652,6 +653,7 @@
<ClInclude Include="Patches\QuitHandlerPatch.h" />
<ClInclude Include="Patches\RenameCreationKitApp.h" />
<ClInclude Include="Patches\RenderWindow60FPS.h" />
<ClInclude Include="Patches\SF\FixQuoteCmdLineSF.h" />
<ClInclude Include="Patches\SF\LoadMaterialsAsync.h" />
<ClInclude Include="Patches\SF\OptimizationLoadSF.h" />
<ClInclude Include="Patches\SF\RemoveThreadDpi.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,9 @@
<ClCompile Include="Patches\FO4\DontMatchForms.cpp">
<Filter>Patches\FO4</Filter>
</ClCompile>
<ClCompile Include="Patches\SF\FixQuoteCmdLineSF.cpp">
<Filter>Patches\SF</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Version">
Expand Down Expand Up @@ -2152,6 +2155,9 @@
<ClInclude Include="Patches\FO4\DontMatchForms.h">
<Filter>Patches\FO4</Filter>
</ClInclude>
<ClInclude Include="Patches\SF\FixQuoteCmdLineSF.h">
<Filter>Patches\SF</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Version\resource_version.rc">
Expand Down
4 changes: 2 additions & 2 deletions Creation Kit Platform Extended Core/Editor API/EditorUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ namespace CreationKitPlatformExtended
break;
}

//_MESSAGE("DBG dialog: %X(%u) %p", (DWORD)lpTemplateName, (DWORD)lpTemplateName, lpDialogFunc);
_MESSAGE("DBG dialog: %X(%u) %p", (DWORD)lpTemplateName, (DWORD)lpTemplateName, lpDialogFunc);

auto dialog = Core::GlobalDialogManagerPtr->GetDialog(reinterpret_cast<LONG_PTR>(lpTemplateName));
if (dialog)
Expand Down Expand Up @@ -435,7 +435,7 @@ namespace CreationKitPlatformExtended
break;
}

//_MESSAGE("DBG dialog modal: %X(%u) %p", (DWORD)lpTemplateName, (DWORD)lpTemplateName, lpDialogFunc);
_MESSAGE("DBG dialog modal: %X(%u) %p", (DWORD)lpTemplateName, (DWORD)lpTemplateName, lpDialogFunc);

auto dialog = Core::GlobalDialogManagerPtr->GetDialog(reinterpret_cast<ULONG_PTR>(lpTemplateName));
if (dialog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ namespace CreationKitPlatformExtended
bool AllowSaveESMandMasterESPPatch::QueryFromPlatform(EDITOR_EXECUTABLE_TYPE eEditorCurrentVersion,
const char* lpcstrPlatformRuntimeVersion) const
{
return eEditorCurrentVersion <= EDITOR_EXECUTABLE_TYPE::EDITOR_FALLOUT_C4_LAST;
auto Path = EditorAPI::BSString::Utils::GetApplicationPath();
bool vc_enabled =
GetPrivateProfileIntA("General", "bUseVersionControl", 0, (Path + "CreationKit.ini").c_str()) ||
GetPrivateProfileIntA("General", "bUseVersionControl", 0, (Path + "CreationKitCustom.ini").c_str());
return !vc_enabled && eEditorCurrentVersion <= EDITOR_EXECUTABLE_TYPE::EDITOR_FALLOUT_C4_LAST;
}

bool AllowSaveESMandMasterESPPatch::Activate(const Relocator* lpRelocator,
Expand Down Expand Up @@ -140,37 +144,10 @@ namespace CreationKitPlatformExtended
extension = "esm";
}

auto result = ((BOOL(__fastcall*)(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPVOID, BOOL, BOOL, LPSTR, uint32_t, LPCSTR, LPVOID))
pointer_AllowSaveESMandMasterESP_sub1)(ParentWindow, BasePath, filter, title, extension, NULL, FALSE, TRUE, Buffer,
BufferSize, Directory, NULL);

bool bUseVersionControl = false;

if (INICacheData->HasActive())
bUseVersionControl = (bool)INICacheData->HKGetPrivateProfileIntA("General", "bUseVersionControl", 0,
(EditorAPI::BSString::Utils::GetApplicationPath() + "CreationKitCustom.ini").c_str());
else
bUseVersionControl = (bool)GetPrivateProfileIntA("General", "bUseVersionControl", 0,
(EditorAPI::BSString::Utils::GetApplicationPath() + "CreationKitCustom.ini").c_str());

if (result && bUseVersionControl)
{
std::string sbuf = Buffer;
auto ibegin = sbuf.find_last_of('\\');
if (ibegin == sbuf.npos) {
ibegin = sbuf.find_last_of('/');
if (ibegin == sbuf.npos)
goto end_func;
else
sbuf = sbuf.substr(ibegin + 1);
}
else
sbuf = sbuf.substr(ibegin + 1);

strcpy_s(Buffer, BufferSize, sbuf.c_str());
}
end_func:
return result;
return ((bool(__fastcall*)(HWND, const char*, const char*, const char*, const char*, void*, bool, bool, char*,
uint32_t, const char*, void*))
pointer_AllowSaveESMandMasterESP_sub1)(ParentWindow, BasePath, filter, title, extension, nullptr, false, true, Buffer,
BufferSize, Directory, nullptr);
}
}
}
Expand Down
104 changes: 104 additions & 0 deletions Creation Kit Platform Extended Core/Patches/SF/FixQuoteCmdLineSF.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// 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 "FixQuoteCmdLineSF.h"
#include "Editor API/BSString.h"

namespace CreationKitPlatformExtended
{
namespace Patches
{
namespace Starfield
{
FixQuoteCmdLinePatch::FixQuoteCmdLinePatch() : Module(GlobalEnginePtr)
{}

bool FixQuoteCmdLinePatch::HasOption() const
{
return false;
}

bool FixQuoteCmdLinePatch::HasCanRuntimeDisabled() const
{
return false;
}

const char* FixQuoteCmdLinePatch::GetOptionName() const
{
return nullptr;
}

const char* FixQuoteCmdLinePatch::GetName() const
{
return "Fixed quote to cmdline";
}

bool FixQuoteCmdLinePatch::HasDependencies() const
{
return false;
}

Array<String> FixQuoteCmdLinePatch::GetDependencies() const
{
return {};
}

bool FixQuoteCmdLinePatch::QueryFromPlatform(EDITOR_EXECUTABLE_TYPE eEditorCurrentVersion,
const char* lpcstrPlatformRuntimeVersion) const
{
return eEditorCurrentVersion >= EDITOR_EXECUTABLE_TYPE::EDITOR_STARFIELD_1_14_70_0;
}

bool FixQuoteCmdLinePatch::Activate(const Relocator* lpRelocator,
const RelocationDatabaseItem* lpRelocationDatabaseItem)
{
if (lpRelocationDatabaseItem->Version() == 1)
{
for (uint32_t i = 0; i < lpRelocationDatabaseItem->Count(); i++)
lpRelocator->DetourCall(_RELDATA_RAV(i), (uintptr_t)&sub);

return true;
}

return false;
}

bool FixQuoteCmdLinePatch::Shutdown(const Relocator* lpRelocator,
const RelocationDatabaseItem* lpRelocationDatabaseItem)
{
return false;
}

char* FixQuoteCmdLinePatch::sub(char* str, const char* delim, char** next_token)
{
if (str) {
while (*str == ' ') {
if (*str == '\0')
return nullptr;
str++;
}
if (*str == '\"')
return strtok_s(++str, "\"", next_token);
else
return strtok_s(str, " ", next_token);
}
else if (next_token && *next_token) {
if (strchr(*next_token, '\"')) {
char* lpRes = strtok_s(nullptr, "\"", next_token);

if (lpRes && !Utils::Trim(lpRes).length())
lpRes = strtok_s(nullptr, "\"", next_token);

return lpRes;
}
else
return strtok_s(nullptr, " ", next_token);
}
else
return strtok_s(str, delim, next_token);
}
}
}
}
44 changes: 44 additions & 0 deletions Creation Kit Platform Extended Core/Patches/SF/FixQuoteCmdLineSF.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright © 2023-2024 aka perchik71. All rights reserved.
// Contacts: <email:[email protected]>
// License: https://www.gnu.org/licenses/gpl-3.0.html

#pragma once

#include "Core/Module.h"
#include "Core/Relocator.h"
#include "Core/RelocationDatabase.h"

namespace CreationKitPlatformExtended
{
namespace Patches
{
namespace Starfield
{
using namespace CreationKitPlatformExtended::Core;

class FixQuoteCmdLinePatch : public Module
{
public:
FixQuoteCmdLinePatch();

virtual bool HasOption() const;
virtual bool HasCanRuntimeDisabled() const;
virtual const char* GetOptionName() const;
virtual const char* GetName() const;
virtual bool HasDependencies() const;
virtual Array<String> GetDependencies() const;

static char* sub(char* str, const char* delim, char** next_token);
static void sub2(char* lpCmdLine, char* 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:
FixQuoteCmdLinePatch(const FixQuoteCmdLinePatch&) = default;
FixQuoteCmdLinePatch& operator=(const FixQuoteCmdLinePatch&) = default;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ namespace CreationKitPlatformExtended
bool AllowSaveESMandMasterESPPatch::QueryFromPlatform(EDITOR_EXECUTABLE_TYPE eEditorCurrentVersion,
const char* lpcstrPlatformRuntimeVersion) const
{
return eEditorCurrentVersion <= EDITOR_EXECUTABLE_TYPE::EDITOR_SKYRIM_SE_LAST;
auto Path = EditorAPI::BSString::Utils::GetApplicationPath();
bool vc_enabled =
GetPrivateProfileIntA("General", "bUseVersionControl", 0, (Path + "CreationKit.ini").c_str()) ||
GetPrivateProfileIntA("General", "bUseVersionControl", 0, (Path + "CreationKitCustom.ini").c_str());
return !vc_enabled && eEditorCurrentVersion <= EDITOR_EXECUTABLE_TYPE::EDITOR_SKYRIM_SE_LAST;
}

bool AllowSaveESMandMasterESPPatch::Activate(const Relocator* lpRelocator,
Expand Down Expand Up @@ -140,46 +144,10 @@ namespace CreationKitPlatformExtended
extension = "esm";
}

auto result = ((bool(__fastcall*)(HWND, const char*, const char*, const char*,
return ((bool(__fastcall*)(HWND, const char*, const char*, const char*,
const char*, void*, bool, bool, char*, uint32_t, const char*, void*))
pointer_AllowSaveESMandMasterESP_sub1)(ParentWindow, BasePath, filter, title, extension, nullptr,
false, true, Buffer, BufferSize, Directory, nullptr);

bool bUseVersionControl = false;

if (INICacheData->HasActive())
{
bUseVersionControl = (bool)INICacheData->HKGetPrivateProfileIntA("General", "bUseVersionControl", 0,
(EditorAPI::BSString::Utils::GetApplicationPath() + "CreationKit.ini").c_str());
bUseVersionControl = (bool)INICacheData->HKGetPrivateProfileIntA("General", "bUseVersionControl", 0,
(EditorAPI::BSString::Utils::GetApplicationPath() + "CreationKitCustom.ini").c_str());
}
else
{
bUseVersionControl = (bool)GetPrivateProfileIntA("General", "bUseVersionControl", 0,
(EditorAPI::BSString::Utils::GetApplicationPath() + "CreationKit.ini").c_str());
bUseVersionControl = (bool)GetPrivateProfileIntA("General", "bUseVersionControl", 0,
(EditorAPI::BSString::Utils::GetApplicationPath() + "CreationKitCustom.ini").c_str());
}

if (result && bUseVersionControl)
{
std::string sbuf = Buffer;
auto ibegin = sbuf.find_last_of('\\');
if (ibegin == sbuf.npos) {
ibegin = sbuf.find_last_of('/');
if (ibegin == sbuf.npos)
goto end_func;
else
sbuf = sbuf.substr(ibegin + 1);
}
else
sbuf = sbuf.substr(ibegin + 1);

strcpy_s(Buffer, BufferSize, sbuf.c_str());
}
end_func:
return result;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,16 @@ namespace CreationKitPlatformExtended
void ProgressWindow::update_progressbar(LPCSTR lpcstrText)
{
// For some reason, 95 does not go further
static DWORD dwProgressLoadMax95 = (DWORD)(*dwProgressLoadMax * 95.0f) / 100.0f;
if (*dwProgressLoadCurrent == dwProgressLoadMax95)
// NEWS: Fallout4.esm contains ~80k incorrect forms.
//static DWORD dwProgressLoadMax95 = (DWORD)(*dwProgressLoadMax * 95.0f) / 100.0f;
if (*dwProgressLoadCurrent == *dwProgressLoadMax)
return;

static double lastPercent = 0.0f;
(*dwProgressLoadCurrent)++;

// Only update every quarter percent, rather than every single form load
double newPercent = ((double)(*dwProgressLoadCurrent) / (double)(dwProgressLoadMax95)) * 100.0f;
double newPercent = ((double)(*dwProgressLoadCurrent) / (double)(*dwProgressLoadMax)) * 100.0f;
if (abs(lastPercent - newPercent) <= 0.25f)
return;

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.
Loading

0 comments on commit a93629b

Please sign in to comment.