Skip to content

Commit

Permalink
Runtime version detection and complete engine types refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNaeem committed Dec 11, 2022
1 parent 659cd14 commit f66ebb1
Show file tree
Hide file tree
Showing 16 changed files with 1,012 additions and 1,001 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The source code relies a lot on the power of templates in order to make overridi

## Plans

> Deducing engine version at runtime.
> GPackageFileUEVersion support.
> More compression methods.
Expand Down
10 changes: 6 additions & 4 deletions UnrealMappingsDumper/UnrealMappingsDumper.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
Expand Down Expand Up @@ -120,6 +120,7 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpplatest</LanguageStandard>
<DisableSpecificWarnings>4244;4267;</DisableSpecificWarnings>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -139,6 +140,7 @@
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpplatest</LanguageStandard>
<DisableSpecificWarnings>4244;4267;</DisableSpecificWarnings>
<ExceptionHandling>Async</ExceptionHandling>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -151,29 +153,29 @@
<ItemGroup>
<ClInclude Include="app.h" />
<ClInclude Include="dumper.h" />
<ClInclude Include="engine.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="oodle.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="scanning.h" />
<ClInclude Include="unrealEnums.h" />
<ClInclude Include="unrealContainers.h" />
<ClInclude Include="unrealFunctions.h" />
<ClInclude Include="uobjectDependency.h" />
<ClInclude Include="unrealTypes.h" />
<ClInclude Include="unrealVersion.h" />
<ClInclude Include="writer.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="app.cpp" />
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="dumper.cpp" />
<ClCompile Include="engine.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="scanning.cpp" />
<ClCompile Include="unrealVersion.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
18 changes: 9 additions & 9 deletions UnrealMappingsDumper/UnrealMappingsDumper.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@
<ClInclude Include="dumper.h">
<Filter>Core\Dumper</Filter>
</ClInclude>
<ClInclude Include="engine.h">
<Filter>Core\Engine</Filter>
</ClInclude>
<ClInclude Include="uobjectDependency.h">
<Filter>Core\Engine</Filter>
</ClInclude>
<ClInclude Include="unrealEnums.h">
<Filter>Core\Engine</Filter>
</ClInclude>
Expand All @@ -72,6 +66,12 @@
<ClInclude Include="oodle.h">
<Filter>Core\Compression</Filter>
</ClInclude>
<ClInclude Include="unrealTypes.h">
<Filter>Core\Engine</Filter>
</ClInclude>
<ClInclude Include="unrealVersion.h">
<Filter>Core\Engine</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand All @@ -83,14 +83,14 @@
<ClCompile Include="app.cpp">
<Filter>Core\App</Filter>
</ClCompile>
<ClCompile Include="engine.cpp">
<Filter>Core\Engine</Filter>
</ClCompile>
<ClCompile Include="scanning.cpp">
<Filter>Core\Scanning</Filter>
</ClCompile>
<ClCompile Include="dumper.cpp">
<Filter>Core\Dumper</Filter>
</ClCompile>
<ClCompile Include="unrealVersion.cpp">
<Filter>Core\Engine</Filter>
</ClCompile>
</ItemGroup>
</Project>
78 changes: 66 additions & 12 deletions UnrealMappingsDumper/app.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,74 @@
#include "pch.h"

#include "app.h"
#include "unrealVersion.h"

IDumper* CreateAppInstance(EUnrealVersion Version)
struct GameInstance
{
switch (Version)
std::filesystem::path GamePath;
float Version = 0;
};

static std::optional<GameInstance> TryGetGameInfo()
{
wchar_t GameFilePath[MAX_PATH];
GetModuleFileName(0, GameFilePath, MAX_PATH);

DWORD verHandle = 0;
DWORD verSize = GetFileVersionInfoSize(GameFilePath, &verHandle);

if (!verSize)
return std::nullopt;

std::string VerData(verSize, '\0');
uint32_t size = 0;
VS_FIXEDFILEINFO* VersionInfo = nullptr;

if (!GetFileVersionInfo(GameFilePath, verHandle, verSize, VerData.data()) ||
!VerQueryValue(VerData.data(), L"\\", (VOID FAR * FAR*) & VersionInfo, &size) ||
!size ||
VersionInfo->dwSignature != 0xfeef04bd)
{
case EUnrealVersion::UE5:
case EUnrealVersion::UE5_01:
return new Dumper<Engine_UE5>();
break;
case EUnrealVersion::FORTNITE:
return new Dumper<Engine_Fortnite>();
break;
default:
return new Dumper<DefaultEngine<>>();
break;
return std::nullopt;
}

auto VersionStr = std::format("{:d}.{:d}.{:d}.{:d}",
(VersionInfo->dwFileVersionMS >> 16) & 0xffff,
(VersionInfo->dwFileVersionMS >> 0) & 0xffff,
(VersionInfo->dwFileVersionLS >> 16) & 0xffff,
(VersionInfo->dwFileVersionLS >> 0) & 0xffff);

GameInstance Ret;
Ret.GamePath = std::filesystem::path(GameFilePath);
Ret.Version = std::stof(VersionStr);

return Ret;
}

static bool InitEngine(GameInstance& Game)
{
// if an engine version has a different type or offset, set it here

if (Game.GamePath.filename() == "FortniteClient-Win64-Shipping.exe"
and Game.Version >= 5.0)
{
return IUnrealVersion::InitTypes<Version_FortniteLatest>();
}

return IUnrealVersion::InitTypes<UnrealVersionBase>();
}

bool App::Init()
{
auto GameOpt = TryGetGameInfo();

if (!GameOpt.has_value())
return false;

auto& Game = GameOpt.value();

UE_LOG("Detected Unreal Engine version %f", Game.Version);
UE_LOG("Detected game %s", Game.GamePath.filename().string().c_str());

return InitEngine(Game);
}
18 changes: 5 additions & 13 deletions UnrealMappingsDumper/app.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
#pragma once

#include "dumper.h"

enum class EUnrealVersion
{
UE4_26,
UE4_27,
UE5,
UE5_01,
FORTNITE
};

IDumper* CreateAppInstance(EUnrealVersion Version);

static void UE_LOG(const char* str, ...)
{
va_list fmt;
Expand All @@ -23,4 +10,9 @@ static void UE_LOG(const char* str, ...)
printf("\n");

va_end(fmt);
}

namespace App
{
bool Init();
}
22 changes: 5 additions & 17 deletions UnrealMappingsDumper/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include "pch.h"

#include "app.h"

#define CLEANUP() \
delete App; \
FreeLibraryAndExitThread(Module, NULL); \
#include "dumper.h"

constexpr bool OpenConsole = true;

Expand All @@ -19,31 +16,22 @@ void WINAPI Main(HMODULE Module)

UE_LOG("Unreal Mappings Dumper created by OutTheShade");

auto App = CreateAppInstance(EUnrealVersion::UE5_01); // TODO: a way to determine the engine version at runtime

if (!App)
{
UE_LOG("Couldn't instantiate dumper instance. Returning.");
CLEANUP();
return;
}

if (!App->Init())
if (!App::Init())
{
UE_LOG("Failed to initialize the dumper. Returning.");
CLEANUP();
FreeLibraryAndExitThread(Module, NULL);
return;
}

auto Start = std::chrono::steady_clock::now();

App->Run(ECompressionMethod::None);
Dumper::Run(ECompressionMethod::None);

auto End = std::chrono::steady_clock::now();

UE_LOG("Successfully generated mappings file in %.02f ms", (End - Start).count() / 1000000.);

CLEANUP();
FreeLibraryAndExitThread(Module, NULL);
}

BOOL APIENTRY DllMain(
Expand Down
Loading

0 comments on commit f66ebb1

Please sign in to comment.