Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions UE4-27-0/Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


[/Script/EngineSettings.GameMapsSettings]
GameDefaultMap=/Game/Main.Main
EditorStartupMap=/Game/Main.Main

Binary file added UE4-27-0/Content/Main.umap
Binary file not shown.
Binary file added UE4-27-0/Content/SimpleWebSocket.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added UE4-27-0/Content/Tests/NewLevelSequence.uasset
Binary file not shown.
Binary file added UE4-27-0/Content/Tests/UnrealHelperTest.umap
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "UnrealHelper.h"

#define LOCTEXT_NAMESPACE "FUnrealHelperModule"

void FUnrealHelperModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module

}

void FUnrealHelperModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.

}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FUnrealHelperModule, UnrealHelper)
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#include "UnrealHelperBPLibrary.h"
#include "UnrealHelper.h"
#include "IImageWrapper.h"
#include "IImageWrapperModule.h"
#include "ImageUtils.h"
#include "RenderUtils.h"
#include "Engine/World.h"
#include "HAL/IPlatformFileModule.h"
#include "IPlatformFilePak.h"
#include "AssetRegistryModule.h"
#include "Engine/StreamableManager.h"
#include "Kismet/GameplayStatics.h"
#include "Runtime/Core/Public/Serialization/ArrayReader.h"

UUnrealHelperBPLibrary::UUnrealHelperBPLibrary(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{

}

void UUnrealHelperBPLibrary::GetStringFromGameConfig(const FString Section, const FString Key, bool& Succeeded, FString& String)
{
if (!GConfig)
{
return;
}

Succeeded = GConfig->GetString(
*Section,
*Key,
String,
GGameIni
);
}

FString UUnrealHelperBPLibrary::RunCommand(FString Cmd, FString Args, FString& StdErr)
{
FString Result;
int32 ExitCode;
// example (on mac)
// FPlatformProcess::ExecProcess(TEXT("/usr/bin/curl"), TEXT("-XPOST localhost:4443"), &ExitCode, &Result, &StdErr);
// this may be poorly implemented in windows, running sleep instead of blocking on read.
FPlatformProcess::ExecProcess(*Cmd, *Args, &ExitCode, &Result, &StdErr);
return Result;
}

void UUnrealHelperBPLibrary::ListFiles(FString Directory, FString FileExtension, TArray<FString>& Files)
{
IFileManager& FileManager = IFileManager::Get();
FPaths::NormalizeDirectoryName(Directory);
FileManager.FindFiles(Files, *Directory, *FileExtension);
}

void UUnrealHelperBPLibrary::ExportRenderTargetAsBuffer(UTextureRenderTarget2D* RenderTarget, bool& bSuccess, TArray<uint8>& Buffer)
{
// From FImageUtils
bSuccess = false;

if(RenderTarget->GetFormat() != PF_B8G8R8A8)
{
return;
}

check(RenderTarget != nullptr);

FRenderTarget* SafeRenderTarget = RenderTarget->GameThread_GetRenderTargetResource();

FIntPoint Size = SafeRenderTarget->GetSizeXY();

TArray<uint8> RawData;
EPixelFormat Format = RenderTarget->GetFormat();
int32 ImageBytes = 32 * Size.X * Size.Y; // CalculateImageBytes(Size.X, Size.Y, 0, Format);
RawData.AddUninitialized(ImageBytes);
bSuccess = SafeRenderTarget->ReadPixelsPtr((FColor*) RawData.GetData());

IImageWrapperModule& ImageWrapperModule = FModuleManager::Get().LoadModuleChecked<IImageWrapperModule>(TEXT("ImageWrapper"));

TSharedPtr<IImageWrapper> PNGImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);

PNGImageWrapper->SetRaw(RawData.GetData(), RawData.GetAllocatedSize(), Size.X, Size.Y, ERGBFormat::BGRA, 8);

Buffer = PNGImageWrapper->GetCompressed(100);

bSuccess = true;

}

void UUnrealHelperBPLibrary::GetClipboardAsString(FString& String)
{
FPlatformApplicationMisc::ClipboardPaste(String);
}

void UUnrealHelperBPLibrary::MountPak(const FString PakFilename, const FString ProjectFolder, const FString ContentFolder)
{
// Asset Registry
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();

// Virtual Filesystem
const TCHAR* PakTypeName = FPakPlatformFile::GetTypeName();

FPlatformFileManager* PlatformFileManager = &FPlatformFileManager::Get();
IPlatformFile* PlatformFile = PlatformFileManager->FindPlatformFile(PakTypeName);

FPakPlatformFile* PakPlatformFile = static_cast<FPakPlatformFile*>(PlatformFile);
if (PakPlatformFile == nullptr)
{
PakPlatformFile = static_cast<FPakPlatformFile*>(PlatformFileManager->GetPlatformFile(PakTypeName)); // new FPakPlatformFile();
PakPlatformFile->Initialize(&PlatformFileManager->GetPlatformFile(), PakTypeName);
PakPlatformFile->InitializeNewAsyncIO();
PlatformFileManager->SetPlatformFile(*PakPlatformFile);
}

// Mount Pak at /GRACE/<PakBaseFilename>/ then link appropriately to /Game/<ContentFolder>/
// if(PakFile->GetIsMounted()) UnRegisterMountPoint

FString StandardFilename(PakFilename);
FPaths::MakeStandardFilename(StandardFilename);
FString BaseFilename = FPaths::GetBaseFilename(StandardFilename);
FString MountPoint = FString::Format(TEXT("/GRACE/{0}/"), {BaseFilename});
FString IgnoreEngine = FString::Format(TEXT("{0}Engine/"), {MountPoint});
FString OptionalProjectFolder = ProjectFolder.IsEmpty() ? ProjectFolder : FString::Format(TEXT("{0}/"), {ProjectFolder});
FString PakContentFolder = FString::Format(TEXT("/{0}Content/{1}/"), {OptionalProjectFolder, ContentFolder});
FString GraceContentMount = FString::Format(TEXT("{0}{1}Content/{2}/"), {MountPoint, OptionalProjectFolder, ContentFolder});
FString GameContentFolder = FString::Format(TEXT("/Game/{0}/"), {ContentFolder});

if (!FPaths::FileExists(*StandardFilename))
{
UE_LOG(LogTemp, Warning, TEXT("Could not find pak file: %s"), *StandardFilename);
return;
}

FPakFile* PakFile = new FPakFile(PakPlatformFile, *StandardFilename, false);
if (!PakFile->IsValid())
{
UE_LOG(LogTemp, Warning, TEXT("Invalid pak file: %s"), *StandardFilename);
return;
}

PakFile->SetMountPoint(*MountPoint);

if(!PakFile->DirectoryExistsInPruned(*GraceContentMount))
{
UE_LOG(LogTemp, Warning, TEXT("Content folder not found in Pak File: %s"), *GraceContentMount);
return;
}

if (!PakPlatformFile->Mount(*PakFilename, 0, *MountPoint))
{
UE_LOG(LogTemp, Warning, TEXT("Failed to mount: %s"), *MountPoint);
return;
}

FPackageName::RegisterMountPoint(GameContentFolder, GraceContentMount);
TArray< FString > ContentPaths;
ContentPaths.Add(GameContentFolder);
AssetRegistry.ScanPathsSynchronous(ContentPaths);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "Modules/ModuleManager.h"

class FUnrealHelperModule : public IModuleInterface
{
public:

/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "Runtime/Core/Public/Misc/ConfigCacheIni.h"
#include "Engine/TextureRenderTarget2D.h"
#include "IImageWrapper.h"
#include "HAL/PlatformApplicationMisc.h"
#include "HAL/FileManager.h"
#include "UnrealHelperBPLibrary.generated.h"

// class UTextureRenderTarget2D;

UCLASS()
class UUnrealHelperBPLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()

UFUNCTION(BlueprintPure, meta = (DisplayName = "Get String from Game Config", Keywords = "Config"), Category = "Unreal Helper BP Library")
static void GetStringFromGameConfig(const FString Section, const FString Key, bool& Succeeded, FString& String);

UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Project Version from Game Config", Keywords = "Config"), Category = "Unreal Helper BP Library")
static void GetProjectVersion(FString& ProjectVersion);

UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Float as String Rounded to Precision", Keywords = "Math"), Category = "Unreal Helper BP Library")
static void GetFloatAsStringWithPrecision(float InFloat, FString& ReturnValue, int32 Precision = 2, bool IncludeLeadingZero = true);

// Intended to block execution of rendering while it waits.
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Blocking External Command", Keywords = "Shell"), Category = "Unreal Helper BP Library")
static FString RunCommand(FString Cmd, FString Params, FString& StdErr);

UFUNCTION(BlueprintCallable, meta = (DisplayName = "List Files", Keywords = "File System"), Category = "Unreal Helper BP Library")
static void ListFiles(FString Directory, FString FileExtension, TArray<FString>& Files);

UFUNCTION(BlueprintCallable, meta = (DisplayName = "Export Render Target as Buffer", Keywords = "Media"), Category = "Unreal Helper BP Library")
static void ExportRenderTargetAsBuffer(UTextureRenderTarget2D* RenderTarget, bool& bSuccess, TArray<uint8>& Buffer);

UFUNCTION(BlueprintCallable, meta = (DisplayName = "Get Clipboard as String", Keywords = "Clipboard"), Category = "Unreal Helper BP Library")
static void GetClipboardAsString(FString& String);

UFUNCTION(BlueprintCallable, meta = (DisplayName = "Mount Pak", Keywords = "File System"), Category = "Unreal Helper BP Library")
static void MountPak(const FString PakFilename, const FString ProjectFolder, const FString ContentFolder);

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using UnrealBuildTool;

public class UnrealHelper : ModuleRules
{
public UnrealHelper(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
}
);


PrivateDependencyModuleNames.AddRange(
new string[]
{
"ApplicationCore",
"CoreUObject",
"Engine",
"PakFile"
}
);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "UnrealHttp.h"

#define LOCTEXT_NAMESPACE "FUnrealHttpModule"

void FUnrealHttpModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module

}

void FUnrealHttpModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
//UE_LOG("")
//FModuleManager::UnloadModule("WebSockets");

}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FUnrealHttpModule, UnrealHttp)
Loading