/////////////////////////////////////////updated at 07/28/2016
EncyptedPakTest.Build.cs:
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "PakFile" });
PrivateDependencyModuleNames.AddRange(new string[] { });
EncryptedPakTestActor.h:
#pragma once
#include "IPlatFormFilePak.h"
#include "GameFramework/Actor.h"
#include "EncryptedPakTestActor.generated.h"
UCLASS()
class ENCRYPTEDPAKTEST_API AEncryptedPakTestActor : public AActor
{
GENERATED_BODY()
public:
AEncryptedPakTestActor();
virtual void BeginPlay() override;
virtual void Tick( float DeltaSeconds ) override;
private:
void Test();
void Load(const FString & pakName);
private:
FPakPlatformFile * m_PakPlatformFile;
FStreamableManager * m_Stream;
};
EncryptedPakTestActor.cpp
#include "EncryptedPakTest.h"
#include "EncryptedPakTestActor.h"
AEncryptedPakTestActor::AEncryptedPakTestActor()
: m_PakPlatformFile(new FPakPlatformFile)
, m_Stream(new FStreamableManager) {
PrimaryActorTick.bCanEverTick = true;
IPlatformFile& InnerPlatform = FPlatformFileManager::Get().GetPlatformFile();
m_PakPlatformFile->Initialize(&InnerPlatform, TEXT(""));
FPlatformFileManager::Get().SetPlatformFile(*m_PakPlatformFile);
}
void AEncryptedPakTestActor::Load(const FString & pakName) {
auto pakPath = FPaths::GameContentDir() + pakName + ".pak";
auto mountingPath = FPaths::EngineContentDir() + pakName + "/";
m_PakPlatformFile->Mount(*pakPath, 0, *mountingPath);
TSet<FString> fileList;
FPakFile PakFile(*pakPath, false);
PakFile.FindFilesAtPath(fileList, *PakFile.GetMountPoint(), true, false, true);
for (auto & ele : fileList) {
FString assetShortName = FPackageName::GetShortName(ele);
assetShortName.RemoveFromEnd(FPackageName::GetAssetPackageExtension());
ele = "/Engine/" + pakName + "/" + assetShortName + TEXT(".") + assetShortName;
}
for (const auto & target : fileList) {
m_Stream->SynchronousLoad(target);
}
}
void AEncryptedPakTestActor::Test() {
Load("0a2e3bc4f1a811e5a15500163e0018da");
Load("0aaa19c4a5ab11e3a0e100163e18af41");
}
void AEncryptedPakTestActor::BeginPlay()
{
Super::BeginPlay();
Test();
}
void AEncryptedPakTestActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
////////////////////////////////////////////////////original
I use UnrealPak.exe to encrypt my uassets which are loaded at runtime , the encrypt command is something like
UnreakPak.exe targetPak.pak -create="directory of uassets" -encrypt -compress
I defined AES_KEY in file Core.Build.cs:
Definitions.Add("AES_KEY=\"128bit key\"");
then I use the following code to mount Pak files:
m_PakPlatform = new FPakPlatformFile;
IPlatformFile& InnerPlatform = FPlatformFileManager::Get().GetPlatformFile();
m_PakPlatform->Initialize(&InnerPlatform, TEXT(""));
FPlatformFileManager::Get().SetPlatformFile(*m_PakPlatform);
m_PakPlatform->Mount(*pakFilePath, 0, *mountingPath))
then load uasset:
TSet<FString> fileList;
PakFile.FindFilesAtPath(fileList, *PakFile.GetMountPoint(), true, false, true);
FStreamableManager * m_Stream = new FStreamableManager ;
for (const auto & file : fileList) {
m_Stream->SynchronousLoad(file );
}
the output is
material1.uasset’ contains unrecognizable data, check that it is of the expected type
when I remove the ‘-encrypt’ option, everything works fine.
can anyone help me .