Skip to content

Commit

Permalink
[CKPE]
Browse files Browse the repository at this point in the history
SF:
- Fixed #106, redone save plugin, fixed absence of master flag during conversion;
  • Loading branch information
Perchik71 committed Jan 13, 2025
1 parent 781e55f commit 53c8c3c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 18 deletions.
1 change: 1 addition & 0 deletions Creation Kit Platform Extended Core/Core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// License: https://www.gnu.org/licenses/gpl-3.0.html

#include "Version/resource_version2.h"
#include <VersionHelpers.h>

#include "ConsoleWindow.h"
#include "CommandLineParser.h"
Expand Down
79 changes: 65 additions & 14 deletions Creation Kit Platform Extended Core/Editor API/SF/TESFileSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace CreationKitPlatformExtended
{
uintptr_t pointer_TESFile_sub1 = 0;
uintptr_t pointer_TESFile_sub2 = 0;
uintptr_t pointer_TESFile_sub3 = 0;
uintptr_t pointer_TESFile_data = 0;
uint32_t conversion_TESFile_data = 0;

int32_t TESFile::hk_LoadTESInfo()
{
Expand Down Expand Up @@ -49,33 +51,82 @@ namespace CreationKitPlatformExtended

int64_t TESFile::hk_WriteTESInfo()
{
bool resetEsmFlag = false;

if (AllowSaveESM)
{
bool resetEsmFlag = false;

if (IsActive())
{
LPCSTR extension = strrchr(m_FileName, '.');
if (conversion_TESFile_data)
{
// The conversion takes place in 3 stages: saving the plugin,
// changing the header and saving, returning the header and saving.
// Plugin always with ext as .esp.

// forced remove esm flag
m_Flags &= ~FILE_RECORD_ESM;
if (IsMaster())
{
_CONSOLE("Conversion plugin: 0x%X", conversion_TESFile_data);

// forced remove esm flag
m_Flags &= ~FILE_RECORD_ESM;

if (extension && !_stricmp(extension, ".esm"))
_CONSOLE("Regenerating ONAM data for master file '%s'...\n", m_FileName);
((void(__fastcall*)(TESFile*))pointer_TESFile_sub2)(this);

// returned esm flag and type
m_Flags |= FILE_RECORD_ESM;
m_Flags |= conversion_TESFile_data;
}
}
else
{
_CONSOLE("Regenerating ONAM data for master file '%s'...\n", m_FileName);
LPCSTR extension = strrchr(m_FileName, '.');
if (extension && !_stricmp(extension, ".esm"))
{
// forced remove esm flag
m_Flags &= ~FILE_RECORD_ESM;

((void(__fastcall*)(TESFile*))pointer_TESFile_sub2)(this);
resetEsmFlag = true;
_CONSOLE("Regenerating ONAM data for master file '%s'...\n", m_FileName);
((void(__fastcall*)(TESFile*))pointer_TESFile_sub2)(this);

resetEsmFlag = true;
}
}
}
}

auto form = WriteTESInfo(this);
auto form = WriteTESInfo(this);

if (resetEsmFlag)
m_Flags &= ~FILE_RECORD_ESM;
if (resetEsmFlag)
m_Flags &= ~FILE_RECORD_ESM;

return form;
}
else
return WriteTESInfo(this);
}

void TESFile::hk_ConversionPlugin(void* __This, uint32_t Type)
{
switch (Type)
{
case 1:
conversion_TESFile_data = FILE_RECORD_LIGHT;
break;
case 2:
conversion_TESFile_data = FILE_RECORD_MID;
break;
case 3:
conversion_TESFile_data = FILE_RECORD_ESM;
break;
default:
conversion_TESFile_data = 0;
break;
}

return form;
// call native function
Core::fastCall<void>(pointer_TESFile_sub3, __This, Type);
// reset conversion flag
conversion_TESFile_data = 0;
}

bool TESFile::IsMasterFileToBlacklist() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace CreationKitPlatformExtended
inline static int64_t(*WriteTESInfo)(TESFile*);
int32_t hk_LoadTESInfo();
int64_t hk_WriteTESInfo();
static void hk_ConversionPlugin(void* __This, uint32_t Type);
bool IsMasterFileToBlacklist();
void Dump();
public:
Expand Down
8 changes: 6 additions & 2 deletions Creation Kit Platform Extended Core/Patches/FaceGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ namespace CreationKitPlatformExtended
}
else if (Flag == BC5_UNORM)
{
hr = DirectX::Compress(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
DXGI_FORMAT_BC5_UNORM, DirectX::TEX_COMPRESS_DEFAULT, DirectX::TEX_THRESHOLD_DEFAULT, bcImage);
if (pointer_d3d11DeviceIntf)
hr = DirectX::Compress(pointer_d3d11DeviceIntf, image->GetImages(), image->GetImageCount(), image->GetMetadata(),
DXGI_FORMAT_BC5_UNORM, DirectX::TEX_COMPRESS_DEFAULT, DirectX::TEX_ALPHA_WEIGHT_DEFAULT, bcImage);
else
hr = DirectX::Compress(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
DXGI_FORMAT_BC5_UNORM, DirectX::TEX_COMPRESS_DEFAULT, DirectX::TEX_ALPHA_WEIGHT_DEFAULT, bcImage);
}
else return false;
if (FAILED(hr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace CreationKitPlatformExtended
{
extern uintptr_t pointer_TESFile_sub1;
extern uintptr_t pointer_TESFile_sub2;
extern uintptr_t pointer_TESFile_sub3;
extern uintptr_t pointer_TESFile_data;
}
}
Expand Down Expand Up @@ -98,6 +99,8 @@ namespace CreationKitPlatformExtended

if (TESFile::AllowSaveESM)
{
pointer_TESFile_sub3 = voltek::detours_function_class_jump(_RELDATA_ADDR(12), &TESFile::hk_ConversionPlugin);

// Also allow non-game ESMs to be set as "Active File"
lpRelocator->DetourCall(_RELDATA_RAV(5), &TESFile::IsMasterFileToBlacklist);
lpRelocator->PatchNop(_RELDATA_RAV(6), 2);
Expand Down Expand Up @@ -132,7 +135,7 @@ namespace CreationKitPlatformExtended
{
EditorAPI::BSString BasePath = EditorAPI::BSString::Utils::GetApplicationPath() + "Data";

const char* filter = "TES Plugin Files (*.esp)\0*.esp\0TES Light Master Files (*.esl)\0*.esl\0TES Master Files (*.esm)\0*.esm\0\0";
const char* filter = "TES Plugin Files (*.esp)\0*.esp\0TES Master Files (*.esm)\0*.esm\0\0";
const char* title = "Select Target Plugin";
const char* extension = "esp";

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.
3 changes: 2 additions & 1 deletion Database/SF/1_14_74_0/AllowSaveESMandMasterESP.relb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ B7910B 0 BA0002000041F68424C0010000050F85????????4C8D05????????488B5C24??488BCBE
86BFD60 0 <nope>
2F8B0C0 0 48895C2408488974241048897C24184C896424205541564157488DAC2440FEFFFF4881EC????????458BF1498BF80FB6F24C8BF94533E44C896424784C89658848C745900F0000004488642478488B15????????48C7C3FFFFFFFF488BC3669048FFC0803C0200
AD320E 0 F680C00100000174??488D70??498B0E4883C1??488BD6FF15????????85C0742C498B3E4533C0488BD6488D4C24??
2F842A0 0 48895C24??48897424??48897C24??48894C24??554154415541564157488DAC24????????B8????????E8????????
2F842A0 0 48895C24??48897424??48897C24??48894C24??554154415541564157488DAC24????????B8????????E8????????
30A1310 0 <nope>

0 comments on commit 53c8c3c

Please sign in to comment.