Skip to content

Commit

Permalink
[CKPE]
Browse files Browse the repository at this point in the history
- Com multithread patch;
- DX11 added fMipLODBias option for mipmaps;
SSE:
- Remove lock render frame;
- Fixed 1.5.73 novysc patch;
SF:
- Added archive patch, load .ba2's with plugins (limit .ba2's 0xfc);
  • Loading branch information
Perchik71 committed Dec 23, 2024
1 parent b80b319 commit 3332ad1
Show file tree
Hide file tree
Showing 39 changed files with 1,583 additions and 241 deletions.
15 changes: 14 additions & 1 deletion Creation Kit Platform Extended Core/Core/D3D11Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace CreationKitPlatformExtended
m_Device->GetImmediateContext2(&temp);

m_ContextProxy = new D3D11DeviceContextProxy(temp);
m_MipLODBias = std::min(3.f, std::max(-3.f,
_READ_OPTION_FLOAT("Graphics", "fMipLODBias", 0.f)));
}

D3D11DeviceProxy::D3D11DeviceProxy(ID3D11Device2 *Device)
Expand All @@ -25,6 +27,8 @@ namespace CreationKitPlatformExtended
m_Device->GetImmediateContext2(&temp);

m_ContextProxy = new D3D11DeviceContextProxy(temp);
m_MipLODBias = std::min(3.f, std::max(-3.f,
_READ_OPTION_FLOAT("Graphics", "fMipLODBias", 0.f)));
}

HRESULT STDMETHODCALLTYPE D3D11DeviceProxy::QueryInterface(REFIID riid, void **ppvObj)
Expand Down Expand Up @@ -165,6 +169,15 @@ namespace CreationKitPlatformExtended

HRESULT STDMETHODCALLTYPE D3D11DeviceProxy::CreateRasterizerState(const D3D11_RASTERIZER_DESC *pRasterizerDesc, ID3D11RasterizerState **ppRasterizerState)
{
if (pRasterizerDesc)
{
auto RasterizerDesc = const_cast<D3D11_RASTERIZER_DESC*>(pRasterizerDesc);
RasterizerDesc->AntialiasedLineEnable = true;
RasterizerDesc->MultisampleEnable = true;

return m_Device->CreateRasterizerState(RasterizerDesc, ppRasterizerState);
}

return m_Device->CreateRasterizerState(pRasterizerDesc, ppRasterizerState);
}

Expand All @@ -174,7 +187,7 @@ namespace CreationKitPlatformExtended
{
auto SamplerDesc = const_cast<D3D11_SAMPLER_DESC*>(pSamplerDesc);

SamplerDesc->MipLODBias = 0.0f; // mipmap level bias value
SamplerDesc->MipLODBias = m_MipLODBias; // mipmap level bias value
SamplerDesc->MinLOD = 0.0f; // alternative minimum mipmap level
SamplerDesc->MaxLOD = D3D11_FLOAT32_MAX; // alternative maximum mipmap level
}
Expand Down
2 changes: 2 additions & 0 deletions Creation Kit Platform Extended Core/Core/D3D11Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace CreationKitPlatformExtended
ID3D11Device2* m_Device;
D3D11DeviceContextProxy* m_ContextProxy;

float m_MipLODBias;

D3D11DeviceProxy(ID3D11Device* Device);
D3D11DeviceProxy(ID3D11Device2* Device);

Expand Down
2 changes: 2 additions & 0 deletions Creation Kit Platform Extended Core/Core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "Patches/PapyrusEditorLimit.h"
#include "Patches/UIHotkeys.h"
#include "Patches/D3D11Patch.h"
#include "Patches/ComPatch.h"

#include "Experimental/RuntimeOptimization.h"

Expand Down Expand Up @@ -211,6 +212,7 @@ namespace CreationKitPlatformExtended
new CreationKitPlatformExtended::Patches::UIThemePatchAdditional(),
new CreationKitPlatformExtended::Patches::PapyrusEditorLimitPatch(),
new CreationKitPlatformExtended::Patches::D3D11Patch(),
new CreationKitPlatformExtended::Patches::ComPatch(),
_Theme,
_ClassicTheme,
INICacheData,
Expand Down
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 @@ -14,12 +14,12 @@
#include "Patches/SF/RTDynamicCastCrash.h"
#include "Patches/SF/OptimizationLoadSF.h"
#include "Patches/SF/RemoveUselessMessagesSF.h"
#include "Patches/SF/RemoveUselessResizeInDialogs.h"
#include "Patches/SF/RemoveThreadDpi.h"
#include "Patches/SF/LoadMaterialsQSplash.h"
#include "Patches/SF/FixQuoteCmdLineSF.h"
#include "Patches/SF/AllowSaveESMandMasterESPSF.h"
#include "Patches/SF/BSResourceLooseFilesPatchSF.h"
#include "Patches/SF/BSArchiveManagerModdedSF.h"

#include "Patches/Windows/SF/DataWindowSF.h"
#include "Patches/Windows/SF/AboutWindowSF.h"
Expand Down Expand Up @@ -48,12 +48,12 @@ namespace CreationKitPlatformExtended
new Patches::RTDynamicCastCrashPatch(),
new Patches::OptimizationLoadPatch(),
new Patches::RemoveUselessMessagesPatch(),
//new Patches::RemoveUselessResizeInDialogsPatch(),
new Patches::RemoveThreadDpiPatch(),
new Patches::LoadMaterialsQSplashPatch(),
new Patches::FixQuoteCmdLinePatch(),
new Patches::AllowSaveESMandMasterESPPatch(),
new Patches::BSResourceLooseFilesPatch(),
new Patches::BSArchiveManagerModdedPatch(),

new Patches::DataWindow(),
new Patches::AboutWindow(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\Dependencies\DirectXTex\src\ScreenGrab11.cpp" />
<ClCompile Include="..\Dependencies\jDialogs\include\jdialogs.cpp" />
<ClCompile Include="Core\AboutWindow.cpp" />
<ClCompile Include="Core\CommandLineParser.cpp" />
Expand Down Expand Up @@ -202,6 +203,7 @@
<ClCompile Include="NiAPI\NiMemoryManager.cpp" />
<ClCompile Include="NiAPI\NiRTTI.cpp" />
<ClCompile Include="Patches\AllowMultipleWindowAndMaster.cpp" />
<ClCompile Include="Patches\ComPatch.cpp" />
<ClCompile Include="Patches\ConsolePatch.cpp" />
<ClCompile Include="Patches\CrashDumpPatch.cpp" />
<ClCompile Include="Patches\D3D11Patch.cpp" />
Expand Down Expand Up @@ -270,7 +272,6 @@
<ClCompile Include="Patches\SF\OptimizationLoadSF.cpp" />
<ClCompile Include="Patches\SF\RemoveThreadDpi.cpp" />
<ClCompile Include="Patches\SF\RemoveUselessMessagesSF.cpp" />
<ClCompile Include="Patches\SF\RemoveUselessResizeInDialogs.cpp" />
<ClCompile Include="Patches\SF\ReplaceImgQSplashWnd.cpp" />
<ClCompile Include="Patches\SF\RTDynamicCastCrash.cpp" />
<ClCompile Include="Patches\SF\RunAppWithoutNet.cpp" />
Expand Down Expand Up @@ -437,6 +438,7 @@
<ClCompile Include="WinHttp Wrapper\Exports.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Dependencies\DirectXTex\include\ScreenGrab11.h" />
<ClInclude Include="..\Dependencies\jDialogs\include\jdialogs.h" />
<ClInclude Include="..\Plug-ins\MyFirstPlugin\CKPE\PluginAPI.h" />
<ClInclude Include="Common.h" />
Expand Down Expand Up @@ -608,6 +610,7 @@
<ClInclude Include="NiAPI\NiTMap.h" />
<ClInclude Include="NiAPI\NiTypes.h" />
<ClInclude Include="Patches\AllowMultipleWindowAndMaster.h" />
<ClInclude Include="Patches\ComPatch.h" />
<ClInclude Include="Patches\ConsolePatch.h" />
<ClInclude Include="Patches\CrashDumpPatch.h" />
<ClInclude Include="Patches\D3D11Patch.h" />
Expand Down Expand Up @@ -676,7 +679,6 @@
<ClInclude Include="Patches\SF\OptimizationLoadSF.h" />
<ClInclude Include="Patches\SF\RemoveThreadDpi.h" />
<ClInclude Include="Patches\SF\RemoveUselessMessagesSF.h" />
<ClInclude Include="Patches\SF\RemoveUselessResizeInDialogs.h" />
<ClInclude Include="Patches\SF\ReplaceImgQSplashWnd.h" />
<ClInclude Include="Patches\SF\RTDynamicCastCrash.h" />
<ClInclude Include="Patches\SF\RunAppWithoutNet.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,6 @@
<ClCompile Include="Patches\FO4\CrashConditionItemGetCrime.cpp">
<Filter>Patches\FO4</Filter>
</ClCompile>
<ClCompile Include="Patches\SF\RemoveUselessResizeInDialogs.cpp">
<Filter>Patches\SF</Filter>
</ClCompile>
<ClCompile Include="Patches\SF\RemoveThreadDpi.cpp">
<Filter>Patches\SF</Filter>
</ClCompile>
Expand Down Expand Up @@ -904,6 +901,12 @@
<ClCompile Include="Patches\FO4\FixBadPictureInRender.cpp">
<Filter>Patches\FO4</Filter>
</ClCompile>
<ClCompile Include="Patches\ComPatch.cpp">
<Filter>Patches</Filter>
</ClCompile>
<ClCompile Include="..\Dependencies\DirectXTex\src\ScreenGrab11.cpp">
<Filter>Dependecies\DirectXTexUtils</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Version">
Expand Down Expand Up @@ -990,6 +993,9 @@
<Filter Include="Editor API\SF\Forms">
<UniqueIdentifier>{8c0ce81a-d9eb-4a96-ac96-1e14a1e870cb}</UniqueIdentifier>
</Filter>
<Filter Include="Dependecies\DirectXTexUtils">
<UniqueIdentifier>{af8e5418-ce4f-476e-819d-01125a452f54}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Version\resource_version.h">
Expand Down Expand Up @@ -2161,9 +2167,6 @@
<ClInclude Include="Patches\FO4\CrashConditionItemGetCrime.h">
<Filter>Patches\FO4</Filter>
</ClInclude>
<ClInclude Include="Patches\SF\RemoveUselessResizeInDialogs.h">
<Filter>Patches\SF</Filter>
</ClInclude>
<ClInclude Include="Patches\SF\RemoveThreadDpi.h">
<Filter>Patches\SF</Filter>
</ClInclude>
Expand Down Expand Up @@ -2200,6 +2203,12 @@
<ClInclude Include="Patches\FO4\FixBadPictureInRender.h">
<Filter>Patches\FO4</Filter>
</ClInclude>
<ClInclude Include="Patches\ComPatch.h">
<Filter>Patches</Filter>
</ClInclude>
<ClInclude Include="..\Dependencies\DirectXTex\include\ScreenGrab11.h">
<Filter>Dependecies\DirectXTexUtils</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Version\resource_version.rc">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ namespace CreationKitPlatformExtended
{
using namespace CreationKitPlatformExtended::Core;

BGSFileSelectorDialog::RegisterArchiveFileCallback* lpArchiveFileCallback = nullptr;

namespace BSResource
{
LocationTree* lpArchiveTree = nullptr;
uintptr_t pointer_Archive2_sub1 = 0;
uintptr_t pointer_Archive2_sub2 = 0;
Array<BSString*> g_arrayArchivesAvailable;
Expand Down Expand Up @@ -101,41 +98,35 @@ namespace CreationKitPlatformExtended
fileSizeStr.Format("%d Byte", fileSize);
}

Archive2::EResultError Archive2::HKLoadArchive(void* arrayDataList, LooseFileStream*& resFile,
void* Unk1, uint32_t Unk2)
uint32_t Archive2::HKLoadArchive(const char* fileName, __int64 unknown01,
__int64 unknown02, __int64 unknown03, __int64 unknown04, __int64 unknown05,
__int64 unknown06, __int64 unknown07)
{
auto fileName = resFile->FileName->Get<CHAR>(true);
AssertMsg(fileName, "There is no name of the load archive");

BSString filePath, fileSizeStr;
filePath.Format("%s%s%s", resFile->AppPath->Get<CHAR>(true), resFile->DataPath->Get<CHAR>(true), fileName);
AssertMsgVa(BSString::Utils::FileExists(filePath), "Can't found file %s", *filePath);

uint64_t fileSize = 0;
WIN32_FILE_ATTRIBUTE_DATA fileData;
ZeroMemory(&fileData, sizeof(WIN32_FILE_ATTRIBUTE_DATA));
if (GetFileAttributesExA(*filePath, GetFileExInfoStandard, &fileData))
fileSize = (uint64_t)fileData.nFileSizeLow | ((uint64_t)fileData.nFileSizeHigh << 32);
if (!fileName)
return 0;

auto resultNo = EC_NONE;
AssertMsg(fileName, "There is no name of the load archive");

if (_stricmp(fileName, "Fallout4 - Shaders.ba2")) // skip load Fallout4 - Shaders.ba2
BSString filePath = BSString::Utils::GetDataPath() + fileName, fileSizeStr;
if (BSString::Utils::FileExists(filePath))
{
unsigned int fileSize = 0;
WIN32_FILE_ATTRIBUTE_DATA fileData;
if (GetFileAttributesExA(*filePath, GetFileExInfoStandard, &fileData))
fileSize = (uint64_t)fileData.nFileSizeLow | ((uint64_t)fileData.nFileSizeHigh << 32);

GetFileSizeStr(fileSize, fileSizeStr);
_CONSOLE("Load an archive file \"%s\" (%s)...", fileName, *fileSizeStr);

resultNo = fastCall<EResultError, void*, LooseFileStream*&, void*, uint32_t>
(pointer_Archive2_sub1, arrayDataList, resFile, Unk1, Unk2);
AssertMsgVa(resultNo == EC_NONE, "Failed load an archive file %s", fileName);
}

return resultNo;
return fastCall<uint32_t>(pointer_Archive2_sub1, fileName, unknown01,
unknown02, unknown03, unknown04, unknown05, unknown06, unknown07);
}

void Archive2::LoadArchive(const char* fileName)
{
if (BSString::Utils::FileExists(BSString::Utils::GetDataPath() + fileName))
fastCall<void>(pointer_Archive2_sub2, fileName, &lpArchiveTree, &lpArchiveFileCallback);
fastCall<void>(pointer_Archive2_sub2, fileName, 0, 0);
}

bool Archive2::IsAvailableForLoad(const char* fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,16 @@ namespace CreationKitPlatformExtended
{
namespace Starfield
{
class BGSFileSelectorDialog
{
public:
class RegisterArchiveFileCallback
{};
};

extern BGSFileSelectorDialog::RegisterArchiveFileCallback* lpArchiveFileCallback;

namespace BSResource
{
class LocationTree
{};

extern LocationTree* lpArchiveTree;

class Archive2
{
public:
enum EResultError : uint32_t
{
EC_NONE = 0,
};
public:
static void Initialize();
static void GetFileSizeStr(uint64_t fileSize, BSString& fileSizeStr);
static EResultError HKLoadArchive(void* arrayDataList, LooseFileStream*& resFile, void* Unk1, uint32_t Unk2);
static uint32_t HKLoadArchive(const char* fileName, __int64 unknown01,
__int64 unknown02, __int64 unknown03, __int64 unknown04, __int64 unknown05,
__int64 unknown06, __int64 unknown07);
static void LoadArchive(const char* fileName);
static bool IsAvailableForLoad(const char* fileName);
};
Expand Down
84 changes: 84 additions & 0 deletions Creation Kit Platform Extended Core/Patches/ComPatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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 "Editor API/EditorUI.h"
#include "ComPatch.h"

namespace CreationKitPlatformExtended
{
namespace Patches
{
using namespace CreationKitPlatformExtended::EditorAPI;

ComPatch::ComPatch() : Module(GlobalEnginePtr)
{}

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

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

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

const char* ComPatch::GetName() const
{
return "COM";
}

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

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

bool ComPatch::QueryFromPlatform(EDITOR_EXECUTABLE_TYPE eEditorCurrentVersion,
const char* lpcstrPlatformRuntimeVersion) const
{
return true;
}

bool ComPatch::Activate(const Relocator* lpRelocator,
const RelocationDatabaseItem* lpRelocationDatabaseItem)
{
if (lpRelocationDatabaseItem->Version() == 1)
{
PatchIAT(HKCoInitializeEx, "COMBASE.DLL", "CoInitializeEx");
PatchIAT(HKCoInitialize, "OLE32.DLL", "CoInitialize");

return true;
}

return false;
}

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

HRESULT ComPatch::HKCoInitialize(LPVOID pvReserved)
{
return CoInitializeEx(pvReserved, COINITBASE_MULTITHREADED);
}

HRESULT ComPatch::HKCoInitializeEx(LPVOID pvReserved, DWORD dwCoInit)
{
return CoInitializeEx(pvReserved, COINITBASE_MULTITHREADED);
}
}
}
Loading

0 comments on commit 3332ad1

Please sign in to comment.