Skip to content

Commit

Permalink
[CKPE]
Browse files Browse the repository at this point in the history
- Fixed utf8 to author and desc in plugin;
SF:
- Added Unicode patch;
- Added instant quit;
  • Loading branch information
Perchik71 committed Dec 1, 2024
1 parent f8bf7f5 commit 0168747
Show file tree
Hide file tree
Showing 20 changed files with 5,853 additions and 36 deletions.
Binary file modified Creation Kit Platform Extended Core/CoreRes.aps
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<CallingConvention>StdCall</CallingConvention>
<ForcedIncludeFiles>Common.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<AdditionalIncludeDirectories>$(SolutionDir)Creation Kit Platform Extended Core\;$(SolutionDir)Dependencies\mzip\src;$(SolutionDir)Dependencies\mINI\src\mini;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)Creation Kit Platform Extended Core\;$(SolutionDir)Dependencies\mzip\src;$(SolutionDir)Dependencies\mINI\src\mini;$(SolutionDir)Dependencies\PropertyGrid;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAsWinRT>false</CompileAsWinRT>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
Expand Down Expand Up @@ -111,7 +111,7 @@
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<CallingConvention>StdCall</CallingConvention>
<ForcedIncludeFiles>Common.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<AdditionalIncludeDirectories>$(SolutionDir)Creation Kit Platform Extended Core\;$(SolutionDir)Dependencies\mzip\src;$(SolutionDir)Dependencies\mINI\src\mini;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)Creation Kit Platform Extended Core\;$(SolutionDir)Dependencies\mzip\src;$(SolutionDir)Dependencies\mINI\src\mini;$(SolutionDir)Dependencies\PropertyGrid;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<CompileAsWinRT>false</CompileAsWinRT>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<FloatingPointModel>Fast</FloatingPointModel>
Expand Down
10 changes: 6 additions & 4 deletions Creation Kit Platform Extended Core/Patches/UIThemePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,14 +736,15 @@ namespace CreationKitPlatformExtended
PostMessageA(hWnd, WM_SETFONT, (WPARAM)UITheme::ThemeFont->Handle, TRUE);
PostMessageA(hWnd, WM_SYSCOLORCHANGE, 0, 0);
break;
case ThemeType::ListBox: {
case ThemeType::ListBox:
{
scrollBarTheme = UITheme::ListBox::Initialize(hWnd);

LONG_PTR uID = GetWindowLongPtrA(hWnd, GWLP_ID);
if (uID != 0x7D0 && uID != 0x7D1)
PostMessageA(hWnd, WM_SETFONT, (WPARAM)UITheme::ThemeFont->Handle, TRUE);
}
break;
break;
case ThemeType::ListView:
scrollBarTheme = UITheme::ListView::Initialize(hWnd);
PostMessageA(hWnd, WM_SETFONT, (WPARAM)UITheme::ThemeFont->Handle, TRUE);
Expand All @@ -766,13 +767,14 @@ namespace CreationKitPlatformExtended
case ThemeType::ProgressBar:
UITheme::ProgressBar::Initialize(hWnd);
break;
case ThemeType::PopupMenu: {
case ThemeType::PopupMenu:
{
Graphics::CUIMonitor Monitor = Graphics::Screen.MonitorFromWindow(hWnd);
// Avoid the up and down arrows in PopupMenu
if (Monitor.WorkAreaRect.Height > 768)
UITheme::PopupMenu::Initialize(hWnd);
}
break;
break;
case ThemeType::Spin:
UITheme::UpDown::Initialize(hWnd);
break;
Expand Down
95 changes: 76 additions & 19 deletions Creation Kit Platform Extended Core/Patches/UnicodePatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace CreationKitPlatformExtended
{
namespace Patches
{
uintptr_t pointer_UnicodePatch_sub1 = 0;
uintptr_t pointer_UnicodePatch_sub2 = 0;

UnicodePatch::UnicodePatch() : Module(GlobalEnginePtr)
{}

Expand Down Expand Up @@ -52,13 +55,13 @@ namespace CreationKitPlatformExtended
bool UnicodePatch::Activate(const Relocator* lpRelocator,
const RelocationDatabaseItem* lpRelocationDatabaseItem)
{
// Initial mode
// Initially, the original state must be set
EditorAPI::ConvertorString.SetMode(EditorAPI::BGSConvertorString::MODE_ANSI);

auto verPatch = lpRelocationDatabaseItem->Version();
if (verPatch == 1)
{
// Initial mode
// Initially, the original state must be set
EditorAPI::ConvertorString.SetMode(EditorAPI::BGSConvertorString::MODE_ANSI);

// Intercepting the receipt of a string
*(uintptr_t*)&EditorAPI::BGSLocalizedString_OldGetStrProc =
voltek::detours_function_class_jump(_RELDATA_ADDR(0), &EditorAPI::BGSLocalizedString::GetStr);
Expand Down Expand Up @@ -86,10 +89,6 @@ namespace CreationKitPlatformExtended
}
else if (verPatch == 2)
{
// Initial mode
// Initially, the original state must be set
EditorAPI::ConvertorString.SetMode(EditorAPI::BGSConvertorString::MODE_ANSI);

// Also delete it message "You must close all Dialoge Boxes",
// which has problems with programs that work with multiple monitors.
lpRelocator->DetourCall(_RELDATA_RAV(0), (uintptr_t)&HKBeginPluginSave);
Expand Down Expand Up @@ -126,6 +125,34 @@ namespace CreationKitPlatformExtended

return true;
}
else if (verPatch == 3)
{
// Hook save plugin
pointer_UnicodePatch_sub1 =
voltek::detours_function_class_jump(_RELDATA_ADDR(0), (uintptr_t)&HKPluginSaveSF);

// Introduction of string processing.
pointer_UnicodePatch_sub2 =
voltek::detours_function_class_jump(_RELDATA_ADDR(1), (uintptr_t)&HKGetStringLocalizeSF);

// In the "Data" dialog box, the "author" and "description" controls are independent,
// and I'm forced to make a trap for WinAPI calls
lpRelocator->DetourCall(_RELDATA_RAV(2), (uintptr_t)&HKSetDlgItemTextA);
lpRelocator->DetourCall(_RELDATA_RAV(3), (uintptr_t)&HKSetDlgItemTextA);
lpRelocator->DetourCall(_RELDATA_RAV(4), (uintptr_t)&HKSendDlgItemMessageA);
lpRelocator->DetourCall(_RELDATA_RAV(5), (uintptr_t)&HKSendDlgItemMessageA);
lpRelocator->DetourCall(_RELDATA_RAV(6), (uintptr_t)&HKSendDlgItemMessageA);
lpRelocator->DetourCall(_RELDATA_RAV(7), (uintptr_t)&HKSendDlgItemMessageA);

//
// Cut check spelling window
//

ScopeRelocator text;

for (uint32_t i = 8; i < lpRelocationDatabaseItem->Count(); i++)
lpRelocator->PatchNop(_RELDATA_RAV(i), 5);
}

return false;
}
Expand All @@ -148,7 +175,7 @@ namespace CreationKitPlatformExtended
SetCursor(hCursor);
}

bool UnicodePatch::HKSetDlgItemTextA(HWND hDlg, int nIDDlgItem, LPCSTR lpString) {
BOOL UnicodePatch::HKSetDlgItemTextA(HWND hDlg, int nIDDlgItem, LPCSTR lpString) {
switch (nIDDlgItem)
{
case 1024:
Expand All @@ -166,9 +193,9 @@ namespace CreationKitPlatformExtended
}
}

bool UnicodePatch::HKSendDlgItemMessageA(HWND hDlg, INT nIDDlgItem, UINT Msg,
LRESULT UnicodePatch::HKSendDlgItemMessageA(HWND hDlg, INT nIDDlgItem, UINT Msg,
WPARAM wParam, LPARAM lParam) {
if (Msg != WM_GETTEXT && Msg != WM_GETTEXTLENGTH)
if ((Msg != WM_GETTEXT) && (Msg != WM_GETTEXTLENGTH))
MsgTextDef:
return SendDlgItemMessageA(hDlg, nIDDlgItem, Msg, wParam, lParam);

Expand All @@ -180,19 +207,17 @@ namespace CreationKitPlatformExtended
case 1025:
{
hCtrlWnd = GetDlgItem(hDlg, nIDDlgItem);
INT32 maxlen = GetWindowTextLengthA(hCtrlWnd) << 2;
INT32 maxlen = GetWindowTextLengthA(hCtrlWnd);

if (maxlen <= 0)
goto MsgTextDef;

String ansi_str;
ansi_str.resize(maxlen);
ansi_str.resize(GetWindowTextA(hCtrlWnd, &ansi_str[0], maxlen));
maxlen <<= 1;
auto ansi_str = std::make_unique<char[]>((size_t)maxlen + 1);
GetWindowTextA(hCtrlWnd, ansi_str.get(), maxlen);
ansi_str.get()[maxlen] = 0;

if (!Conversion::IsUtf8Valid(ansi_str))
goto MsgTextDef;

String utf8_str = Conversion::AnsiToUtf8(ansi_str);
String utf8_str = Conversion::AnsiToUtf8(ansi_str.get());

if (Msg == WM_GETTEXT)
strncpy((LPSTR)(lParam), utf8_str.c_str(), wParam);
Expand All @@ -203,5 +228,37 @@ namespace CreationKitPlatformExtended
goto MsgTextDef;
}
}

void UnicodePatch::HKPluginSaveSF(__int64 unk01, __int64 unk02, __int64 unk03, __int64 unk04)
{
EditorAPI::ConvertorString.SetMode(EditorAPI::BGSConvertorString::MODE_UTF8);
fastCall<void>(pointer_UnicodePatch_sub1, unk01, unk02, unk03, unk04);
EditorAPI::ConvertorString.SetMode(EditorAPI::BGSConvertorString::MODE_ANSI);
}

const char* UnicodePatch::HKGetStringLocalizeSF(__int64 lstring)
{
// Fixed:
// First problem, Bethesda removed the check for an null pointer

if (!lstring) return nullptr;
auto utf8_string = fastCall<const char*>(pointer_UnicodePatch_sub2, lstring);
if (!utf8_string) return nullptr;

// Second problem is that all the strings have become BGSLocalizedString,
// Even the path, system strings, and script properties.
// It can't have localization, goonies, "<ID=" it also don't have.

// Extremely surprisingly, I don't get CTD when I translate a string,
// but I return the same memory address, however, this is only applicable when converting WinCP.
if (EditorAPI::ConvertorString.GetMode() == EditorAPI::BGSConvertorString::MODE_UTF8)
return EditorAPI::BGSLocalizedString::GetStr2(utf8_string);
// All APIs are implemented as ANSI. In this regard, utf-8 must be converted to the specified ANSI.
else
{
EditorAPI::BGSLocalizedString::GetStr2(utf8_string);
return utf8_string;
}
}
}
}
7 changes: 5 additions & 2 deletions Creation Kit Platform Extended Core/Patches/UnicodePatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ namespace CreationKitPlatformExtended

static bool HKBeginPluginSave();
static void HKEndPluginSave(HCURSOR hCursor);
static bool HKSetDlgItemTextA(HWND hDlg, int nIDDlgItem, LPCSTR lpString);
static bool HKSendDlgItemMessageA(HWND hDlg, int nIDDlgItem, UINT Msg,
static BOOL HKSetDlgItemTextA(HWND hDlg, int nIDDlgItem, LPCSTR lpString);
static LRESULT HKSendDlgItemMessageA(HWND hDlg, int nIDDlgItem, UINT Msg,
WPARAM wParam, LPARAM lParam);

static void HKPluginSaveSF(__int64 unk01, __int64 unk02, __int64 unk03, __int64 unk04);
static const char* HKGetStringLocalizeSF(__int64 lstring);
protected:
virtual bool QueryFromPlatform(EDITOR_EXECUTABLE_TYPE eEditorCurrentVersion,
const char* lpcstrPlatformRuntimeVersion) const;
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.
3 changes: 2 additions & 1 deletion Database/SF/1_14_74_0/QuitHandler.relb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Quit Handler
1
extended
1982630 0 48895C24??48897424??574883EC??488BD9488D05????????488901488D05????????488941??33F64839B1????????74??
1982630 0 48895C24??48897424??574883EC??488BD9488D05????????488901488D05????????488941??33F64839B1????????74??
19B4CE3 0 <nope>
13 changes: 13 additions & 0 deletions Database/SF/1_14_74_0/Unicode.relb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Unicode
3
extended
B78BD0 0 <nope>
6098510 0 v2_8B4114D1E8A80174??488B4908E9????????488D4118C3
2EA1FCF 0 <nope>
2EA1FEF 0 <nope>
2F7AAA5 0 <nope>
2F7AADE 0 <nope>
2F7AB19 0 <nope>
2F7AB52 0 <nope>
1E6AC32 0 <nope>
1E6AC62 0 <nope>
Loading

0 comments on commit 0168747

Please sign in to comment.