diff --git a/.gitattributes b/.gitattributes index b0f32f0..ad623c1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ ReleaseBuilds/** filter=lfs diff=lfs merge=lfs -text Images/** filter=lfs diff=lfs merge=lfs -text Fonts/** filter=lfs diff=lfs merge=lfs -text +Audio/** filter=lfs diff=lfs merge=lfs -text diff --git a/Audio/Dialogue/RAIMaquette_CustomDialogue/GLaDOS_HowHaveYouBeen.wav b/Audio/Dialogue/RAIMaquette_CustomDialogue/GLaDOS_HowHaveYouBeen.wav new file mode 100644 index 0000000..80afba7 --- /dev/null +++ b/Audio/Dialogue/RAIMaquette_CustomDialogue/GLaDOS_HowHaveYouBeen.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d83b577196ae6976ff5ee2c6274b94f49cd653e8572fd038979430a5437313bf +size 403280 diff --git a/UnrealProject/Lost_Edge/Content/Audio/Music/Minigames/SW_Minigame_RythmClick.uasset b/UnrealProject/Lost_Edge/Content/Audio/Music/Minigames/SW_Minigame_RythmClick.uasset index a32b43b..1d5f328 100644 --- a/UnrealProject/Lost_Edge/Content/Audio/Music/Minigames/SW_Minigame_RythmClick.uasset +++ b/UnrealProject/Lost_Edge/Content/Audio/Music/Minigames/SW_Minigame_RythmClick.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:76f3fa2ae8f6d4389b6a1daf56df1fcb27b61e60590c9096d2d9119dce709728 -size 7376077 +oid sha256:04fc312b5b37ea8293d79a5f5f242f5ecd9dc1183e7680d2956d50d44a228fb0 +size 7376219 diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/Actors/RuntimeLoadTest/BP_Test_RuntimeLoad.uasset b/UnrealProject/Lost_Edge/Content/Levels/Test/Actors/RuntimeLoadTest/BP_Test_RuntimeLoad.uasset index b1a0cfc..aba621b 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/Actors/RuntimeLoadTest/BP_Test_RuntimeLoad.uasset +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/Actors/RuntimeLoadTest/BP_Test_RuntimeLoad.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:23adf40e0f008b1a773ef6507f145a26888cfb6ddde6cdf6b4e8ed373718d709 -size 60103 +oid sha256:8895891731e8da1a221aacd6a03ad0bf81128aa3a980588173be9fbd863a9244 +size 84828 diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap index 90f2678..278e2c4 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:517227541cd118fc0c58a1ccaebb377531a4b888a9ee45394fe2531cbc3e434d -size 2257413 +oid sha256:26ba9021d327e31a02433e566da5b6428681e17f2ae92ad100200f30c073dea3 +size 2257698 diff --git a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/BP_ImportTest_Barrel.uasset b/UnrealProject/Lost_Edge/Content/Misc/ImportTest/BP_ImportTest_Barrel.uasset deleted file mode 100644 index c05daaf..0000000 --- a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/BP_ImportTest_Barrel.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:951dd836a6715f743d3779f7db429ef6fcf444e3918ffe0b3ccd518217ba4a2e -size 31005 diff --git a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/Build/pakchunk100-Windows.pak b/UnrealProject/Lost_Edge/Content/Misc/ImportTest/Build/pakchunk100-Windows.pak deleted file mode 100644 index b9a4593..0000000 --- a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/Build/pakchunk100-Windows.pak +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f0a11d6b8b873ca5988740ab6b443f9627828a931fc27c14574afa596b18b963 -size 1091148 diff --git a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/DA_ImportTest.uasset b/UnrealProject/Lost_Edge/Content/Misc/ImportTest/DA_ImportTest.uasset deleted file mode 100644 index a2e2dcc..0000000 --- a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/DA_ImportTest.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:7ed903f0079d7add5446e94bcb4be9bd190157a441b4be3778465039cf9ef3f7 -size 3824 diff --git a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/M_ImportTest_BarelWood.uasset b/UnrealProject/Lost_Edge/Content/Misc/ImportTest/M_ImportTest_BarelWood.uasset deleted file mode 100644 index f52518a..0000000 --- a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/M_ImportTest_BarelWood.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:99c7f71a92b560c7cbb728e61859c2011d9d385b835d65490d1770d07f214097 -size 13533 diff --git a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/M_ImportTest_BarrelRings.uasset b/UnrealProject/Lost_Edge/Content/Misc/ImportTest/M_ImportTest_BarrelRings.uasset deleted file mode 100644 index bdda9ad..0000000 --- a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/M_ImportTest_BarrelRings.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:b342de6b20ff05eca91758b24424a618a4f1b1fbed125ef7c00b6df47883d770 -size 10948 diff --git a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/SM_ImportTest_Barrel.uasset b/UnrealProject/Lost_Edge/Content/Misc/ImportTest/SM_ImportTest_Barrel.uasset deleted file mode 100644 index 77ff968..0000000 --- a/UnrealProject/Lost_Edge/Content/Misc/ImportTest/SM_ImportTest_Barrel.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1aa963b1ca237c5f3838dc7a5926e5395f7c06a4ecff4decd2cf1b8d30a60895 -size 59070 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/BuildedPaks/CustomDialogue.pak b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/BuildedPaks/CustomDialogue.pak new file mode 100644 index 0000000..aab4643 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/BuildedPaks/CustomDialogue.pak @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51ffb5d76432fcf8a763df961fe32102c89c64075b0267dc0f5ea9f5ab3fffd6 +size 84604 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/BuildedPaks/CustomInteractable.pak b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/BuildedPaks/CustomInteractable.pak new file mode 100644 index 0000000..1841ed1 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/BuildedPaks/CustomInteractable.pak @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:07c723d67b987a9c61a8e797abdd75a7e6b868e89ef0b6831769a2073819db65 +size 1571745 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/BuildedPaks/CustomLevel.pak b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/BuildedPaks/CustomLevel.pak new file mode 100644 index 0000000..8643d52 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/BuildedPaks/CustomLevel.pak @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a4fb0078ea006e03b5ab586f99332d7702a51cb22475499fd61511a469d28f6 +size 14433 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/BP_RAIMaquett_CustomAnimatedLightLoader.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/BP_RAIMaquett_CustomAnimatedLightLoader.uasset new file mode 100644 index 0000000..76857d3 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/BP_RAIMaquett_CustomAnimatedLightLoader.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f904e38b34f7eab7cb9eff85f910776334b4b71caeff70fcc124424a75d7f8d8 +size 32082 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/Content/BP_RAIMaquett_SmokeLamp.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/Content/BP_RAIMaquett_SmokeLamp.uasset new file mode 100644 index 0000000..d8e63b5 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/Content/BP_RAIMaquett_SmokeLamp.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1a6eeaa00e0bffeeb078c4cce09b243ad48ed35516659535cabefb6563371b0 +size 21443 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/Content/L_RAIMaquett_CustomAnimatedLightWorld.umap b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/Content/L_RAIMaquett_CustomAnimatedLightWorld.umap new file mode 100644 index 0000000..e0e117a --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/Content/L_RAIMaquett_CustomAnimatedLightWorld.umap @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:005472c34d0b68e532975c44acd5d8fb1d0183145ec3534e7b5b3b209dddbbb0 +size 31617 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/Content/Seq_RAIMaquett_CustomAnimatedLightAnimation.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/Content/Seq_RAIMaquett_CustomAnimatedLightAnimation.uasset new file mode 100644 index 0000000..d3b8ef6 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/Content/Seq_RAIMaquett_CustomAnimatedLightAnimation.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:141a669c733b383eaff586dcda3e149881829f65d0bc00d740cb0fe2c543eed7 +size 21227 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/DA_RAIMaquett_CustomAnimatedLight.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/DA_RAIMaquett_CustomAnimatedLight.uasset new file mode 100644 index 0000000..6077994 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomAnimatedLight/DA_RAIMaquett_CustomAnimatedLight.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2b92953aa0ab6e30b405b1a676c05cb60eae26373cbf1ae1cfcf5d8c2a1a973 +size 6098 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/BP_RAIMaquett_CustomDialogue.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/BP_RAIMaquett_CustomDialogue.uasset new file mode 100644 index 0000000..6736789 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/BP_RAIMaquett_CustomDialogue.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a07e099a034efa8b7a41a3b611f537cdd2493ca26152d6ada59ef4510026a15d +size 27705 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/DA_RAIMaquett_CustomDialogue.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/DA_RAIMaquett_CustomDialogue.uasset new file mode 100644 index 0000000..24ee3c1 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/DA_RAIMaquett_CustomDialogue.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:760a68a4934bae6b7d428f1aacbd2aab0d22ef5fc2e6ca16ccda5c9222a18e37 +size 3278 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/DT_RAIMaquett_CustomDialogue.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/DT_RAIMaquett_CustomDialogue.uasset new file mode 100644 index 0000000..9a4ef6c --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/DT_RAIMaquett_CustomDialogue.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:916bfaab01566e0d018dd165b42ac179373550297ff4ad6016c971f354b36727 +size 3708 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/SW_RAIMaquett_CustomDialogue.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/SW_RAIMaquett_CustomDialogue.uasset new file mode 100644 index 0000000..391b269 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomDialogue/SW_RAIMaquett_CustomDialogue.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf0a9397b1b63120fbf89026615cd30dc59303eeecff4bcd064a3aac00a1645e +size 315116 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/BP_RAIMaquett_CustomBarrel.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/BP_RAIMaquett_CustomBarrel.uasset new file mode 100644 index 0000000..91d53be --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/BP_RAIMaquett_CustomBarrel.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:262f978d4bd0cb3d6f1227eb6b4564f085a687113c08c5745e04e83687ab76ed +size 31360 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/DA_RAIMaquett_CustomMovableInteractable.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/DA_RAIMaquett_CustomMovableInteractable.uasset new file mode 100644 index 0000000..29f2d23 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/DA_RAIMaquett_CustomMovableInteractable.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e823132261e8a387a386596e9bb416abff1b8f5b2d4b3c9bc991f835cfdd023e +size 4353 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/M_RAIMaquett_BarelWood.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/M_RAIMaquett_BarelWood.uasset new file mode 100644 index 0000000..95b0d2c --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/M_RAIMaquett_BarelWood.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e04e97db631606ef75e4eb3b99872828b0083ac1a7da78643d943115918bb1aa +size 13587 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/M_RAIMaquett_BarrelRings.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/M_RAIMaquett_BarrelRings.uasset new file mode 100644 index 0000000..811bff7 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/M_RAIMaquett_BarrelRings.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b1d1078d01ad66b7de433ec4a6b8532731f25a097872413b747f5f7d05f2575 +size 11002 diff --git a/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/SM_RAIMaquett_Barrel.uasset b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/SM_RAIMaquett_Barrel.uasset new file mode 100644 index 0000000..04e5122 --- /dev/null +++ b/UnrealProject/Lost_Edge/Content/Misc/RAIMaquetts/CustomMovableInteractable/SM_RAIMaquett_Barrel.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1758dc7cc9e6203364525ffd5393cc7e278728798bc00602090beb69fccb422b +size 59290 diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Lost_Edge.Build.cs b/UnrealProject/Lost_Edge/Source/Lost_Edge/Lost_Edge.Build.cs index f0e199e..a64361a 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Lost_Edge.Build.cs +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Lost_Edge.Build.cs @@ -9,7 +9,7 @@ public class Lost_Edge : ModuleRules { PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "OpenCV" }); PrivateDependencyModuleNames.AddRange(new string[] { "EnhancedInput", "UMG", "RHI", "RenderCore", "Lost_EdgeShaders", "PakFile", //"TextureCompressor", - "LevelSequence", "MovieScene" }); // "Slate", "SlateCore" + "LevelSequence", "MovieScene", "HTTP", "Json" }); // "Slate", "SlateCore" // UE_LOG(LogTemp, Log, TEXT("capture: %s"), (capture ? TEXT("true") : TEXT("false"))); // GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("1")); diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h index 40c5160..903cead 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h @@ -2,6 +2,7 @@ #pragma once +#include "CoreMinimal.h" #include "Kismet/BlueprintFunctionLibrary.h" #include "CommonFunctions.generated.h" @@ -37,6 +38,12 @@ public: static FWorldDilationChangedDelegate& GetWorldDilationChangedDelegate(); + + template + static TArray ArrayDiff(const TArray& a, const TArray& b); + template + static void ArrayRemoveFirstFromEnd(TArray& array, T element); + private: static void SlowMotionTick(); @@ -48,3 +55,37 @@ namespace SlowMotion constexpr float slowDilation = 0.2f; constexpr float interpolationSpeed = 0.1f; } + +template +inline TArray UCommonFunctions::ArrayDiff(const TArray& a, const TArray& b) +{ + TSet result; + + if(a.Num() == 0) + return b; + else if(b.Num() == 0) + return a; + + for(auto& i : a) + if(!b.Contains(i)) + result.Add(i); + + for(auto& i : b) + if(!a.Contains(i)) + result.Add(i); + + return result.Array(); +} + +template +inline void UCommonFunctions::ArrayRemoveFirstFromEnd(TArray& array, T element) +{ + for(int32 i = array.Num() - 1; i > -1; --i) + { + if(array[i] == element) + { + array.RemoveAt(i); + return; + } + } +} diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp index 0a39ebc..8d01c52 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp @@ -3,7 +3,26 @@ #include "ContentLoader.h" +#include "CommonFunctions.h" #include "IPlatformFilePak.h" +#include "Misc/FileHelper.h" + +#include +#include +#include + +namespace +{ + constexpr auto httpGet = TEXT("GET"); + + constexpr int32 httpResponseOK = 200; + + constexpr auto httpContentTypeHtml = TEXT("text/html"); + constexpr auto httpContentTypeJson = TEXT("application/json"); + + constexpr auto pakIndexUrl = TEXT("https://pixelyfier.com/lost_edge/content/"); + const auto pakFileSavePath = FString::Printf(TEXT("%sDownloaded/"), *FPaths::ProjectDir()); +} void UContentLoader::BeginDestroy() { @@ -18,9 +37,129 @@ void UContentLoader::BeginDestroy() UObject::BeginDestroy(); } +void UContentLoader::HttpGet(const FString& url, FHttpRequestCompleteDelegate requestCompleteCallback) +{ + TSharedRef request = FHttpModule::Get().CreateRequest(); + request->SetURL(url); + request->SetVerb(httpGet); + request->OnProcessRequestComplete() = std::move(requestCompleteCallback); + request->ProcessRequest(); +} + +TArray UContentLoader::ParseDirectoryIndex(const TArray& content, const FString& contentType) +{ + TArray result; + + if(contentType == httpContentTypeHtml) + { + std::string contentHtml{ reinterpret_cast(content.GetData()), static_cast(content.Num()) }; + std::regex hrefRegex(R"( 1) + { + result.Add(UTF8_TO_TCHAR(match[1].str().c_str())); + } + it = match.suffix().first; + } + } + else if(contentType == httpContentTypeJson) + { + // TODO + } + + return result; +} + +FString UContentLoader::SelectContentByMethod(const TArray& content, const EContentDownloadMethod method) +{ + switch(method) + { + case EContentDownloadMethod::NonRepeatRandom: + { + auto filteredContent = UCommonFunctions::ArrayDiff(content, downloadedContent); + if(filteredContent.Num() == 0 && content.Num() != 0) + { + downloadedContent.Reset(); + filteredContent = UCommonFunctions::ArrayDiff(content, downloadedContent); + } + return filteredContent[FMath::RandRange(0, filteredContent.Num() - 1)]; + } + case EContentDownloadMethod::RatingOftenRandom: + // TODO + case EContentDownloadMethod::ClearRandom: + default: + return content[FMath::RandRange(0, content.Num() - 1)]; + } +} + +void UContentLoader::DownloadPak(FContentDownloadedCallback downloadedCallback, const EContentDownloadMethod method) +{ + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Requesting pak http index at %s."), pakIndexUrl); + + FHttpRequestCompleteDelegate indexRequestCallback; + indexRequestCallback.BindLambda([=, this](FHttpRequestPtr request, FHttpResponsePtr response, bool successful) + { + if(!successful || response->GetResponseCode() != httpResponseOK) + { + int32 responseCode = response.IsValid() ? response->GetResponseCode() : -1; + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Requesting pak http index failed with code: %d (-1 if response is null)."), responseCode); + return; + } + + TArray availablePaks = ParseDirectoryIndex(response->GetContent(), response->GetContentType()); + if(availablePaks.Num() == 0) + { + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Pak http index is empty.")); + return; + } + + FString pakToDownload = SelectContentByMethod(availablePaks, method); + downloadedContent.Add(pakToDownload); + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Pak selected for loading: %s."), *pakToDownload); + + auto savePath = FString::Printf(TEXT("%s%s"), *pakFileSavePath, *pakToDownload); + if(FPlatformFileManager::Get().GetPlatformFile().FileExists(*savePath)) + { + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Selected pak already exists... skipping download.")); + downloadedCallback.ExecuteIfBound(savePath); + return; + } + + FHttpRequestCompleteDelegate pakDownloadCallback; + pakDownloadCallback.BindLambda([=, this](FHttpRequestPtr request, FHttpResponsePtr response, bool successful) + { + if(!successful || response->GetResponseCode() != httpResponseOK) + { + UCommonFunctions::ArrayRemoveFirstFromEnd(downloadedContent, pakToDownload); + int32 responseCode = response.IsValid() ? response->GetResponseCode() : -1; + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Pak downloading failed with code: %d (-1 if response is null)."), responseCode); + return; + } + + if(!FFileHelper::SaveArrayToFile(response->GetContent(), *savePath)) + { + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Saving pak file %s failed."), *savePath); + return; + } + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Pak file saved as %s."), *savePath); + + downloadedCallback.ExecuteIfBound(savePath); + }); + + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Starting to download pak %s from index."), *pakToDownload); + HttpGet(FString::Printf(TEXT("%s%s"), pakIndexUrl, *pakToDownload), pakDownloadCallback); + }); + + HttpGet(pakIndexUrl, indexRequestCallback); +} + UClass* UContentLoader::LoadPak(const FString& pakFilePath) { - UE_LOG(LogTemp, Log, TEXT("ContentLoader: Starting to mount pak %s"), *pakFilePath); + UE_LOG(LogTemp, Log, TEXT("ContentLoader: Starting to mount pak %s."), *pakFilePath); FPakPlatformFile* pakFileMgr = (FPakPlatformFile*)(FPlatformFileManager::Get().FindPlatformFile(TEXT("PakFile"))); if(!pakFileMgr) @@ -104,13 +243,13 @@ bool UContentLoader::UnloadPak(const FString& pakFilePath) FPakPlatformFile* pakFileMgr = (FPakPlatformFile*)(FPlatformFileManager::Get().FindPlatformFile(TEXT("PakFile"))); if(!pakFileMgr) { - UE_LOG(LogTemp, Warning, TEXT("Unable to get PakPlatformFile for pak file (Unmount): %s"), *pakFilePath); + UE_LOG(LogTemp, Warning, TEXT("ContentLoader: Unable to get PakPlatformFile for pak file (Unmount): %s."), *pakFilePath); return false; } if(!pakFileMgr->Unmount(*pakFilePath)) { - UE_LOG(LogTemp, Warning, TEXT("Unable to unmount pak: %s"), *pakFilePath); + UE_LOG(LogTemp, Warning, TEXT("ContentLoader: Unable to unmount pak: %s."), *pakFilePath); return false; } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.h index b169842..2263206 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.h @@ -2,10 +2,21 @@ #pragma once +#include "Http.h" #include "UObject/Object.h" #include "ContentLoader.generated.h" +UENUM(BlueprintType) +enum class EContentDownloadMethod : uint8 +{ + ClearRandom = 0, + NonRepeatRandom, + RatingOftenRandom +}; + +DECLARE_DYNAMIC_DELEGATE_OneParam(FContentDownloadedCallback, FString, pakFilePath); + UCLASS(BlueprintType) class UContentLoader : public UObject { @@ -13,15 +24,23 @@ class UContentLoader : public UObject public: UFUNCTION(BlueprintCallable, Category = "ContentLoader") - UClass* LoadPak(const FString& pakFilePath); + void DownloadPak(FContentDownloadedCallback downloadedCallback, const EContentDownloadMethod method = EContentDownloadMethod::NonRepeatRandom); -protected: - virtual void BeginDestroy() override; + UFUNCTION(BlueprintCallable, Category = "ContentLoader") + UClass* LoadPak(const FString& pakFilePath); UFUNCTION(BlueprintCallable, Category = "ContentLoader") bool UnloadPak(const FString& pakFilePath); protected: + virtual void BeginDestroy() override; + + void HttpGet(const FString& url, FHttpRequestCompleteDelegate requestCompleteCallback); + TArray ParseDirectoryIndex(const TArray& content, const FString& contentType); + FString SelectContentByMethod(const TArray& content, const EContentDownloadMethod method); + FString GetPakMountContent(const FString& pakFilePath, TArray* content = nullptr); UClass* GetPakClass(const FString& pakContentPath); + + TArray downloadedContent; }; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/DialogueManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/DialogueManager.cpp index 6ed5613..a9bbbd1 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/DialogueManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/DialogueManager.cpp @@ -147,7 +147,7 @@ void UDialogueManager::PlayNextDialogue() { FDialogueEndCallback callback; _endCallbacks.Dequeue(callback); - callback.Execute(); + callback.ExecuteIfBound(); _nextDialogues.Pop(); return; }