From ff10e884dc947df9b95284b0764d26f5591de627 Mon Sep 17 00:00:00 2001 From: LUCASTUCIOUS Date: Sun, 29 Sep 2024 17:43:07 +0200 Subject: [PATCH] some QoL --- Source/SkyPortal/Private/SkyPortalFigure.cpp | 23 +++++++++++++ .../SkyPortal/Private/SkyPortalSubsystem.cpp | 14 +++++--- Source/SkyPortal/Public/SkyPortalFigure.h | 34 +++++++++++++++---- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/Source/SkyPortal/Private/SkyPortalFigure.cpp b/Source/SkyPortal/Private/SkyPortalFigure.cpp index 0fb8652..2b741fc 100644 --- a/Source/SkyPortal/Private/SkyPortalFigure.cpp +++ b/Source/SkyPortal/Private/SkyPortalFigure.cpp @@ -5,6 +5,7 @@ UFigureData::UFigureData() { ClearData(); + GenerationID = EVariantIDGeneration::UNKNOW; } int32 UFigureData::GetFigureID() @@ -29,6 +30,28 @@ int32 UFigureData::GetFigureID() }; +int32 UFigureData::GetVariantID() { + + int16_t OutFigureID = 0; + + // The figure ID is stored in Block 1 of Sector 0 (i.e., data[1]), bytes 0 and 1 (16-bit integer, little-endian) + OutFigureID = decryptedData[1][0] | // Least significant byte + (data[1][1] << 8); // Most significant byte, shifted left by 8 bits + + VariantID = OutFigureID;// Return the 16-bit figure ID + return OutFigureID; +} + +EVariantIDGeneration UFigureData::GetGeneration() +{ + return static_cast(VariantID); +} + void UFigureData::ClearData() { } + +bool UFigureData::Dump(bool decrypted, FString filePath) +{ + return true; +} diff --git a/Source/SkyPortal/Private/SkyPortalSubsystem.cpp b/Source/SkyPortal/Private/SkyPortalSubsystem.cpp index 7a59cd1..d9ae979 100644 --- a/Source/SkyPortal/Private/SkyPortalSubsystem.cpp +++ b/Source/SkyPortal/Private/SkyPortalSubsystem.cpp @@ -266,6 +266,8 @@ void USkyPortalSubsystem::PortalAnalyzeAsync(const uint8 Index) // Run the PortalAnalyze function asynchronously on a background thread AsyncTask(ENamedThreads::AnyBackgroundThreadNormalTask, [this, Index]() { + UE_LOG(LogSkyportalIO, Verbose, TEXT("Async Task started for figure index %d"), Index); + // Perform the blocking operation on the background thread PortalAnalyze(Index); @@ -283,13 +285,17 @@ void USkyPortalSubsystem::PortalAnalyzeAsync(const uint8 Index) { UE_LOG(LogSkyportalIO, Log, TEXT("Reading figure...")); - if (FigureArray.IsValidIndex(index)) { - FigureArray[index] = PortalHandle->ReadFigureBlocks(index); - UE_LOG(LogSkyportalIO, Log, TEXT("Figure ID : %d"), FigureArray[index]->GetFigureID()); + if (FigureArray.IsValidIndex(index) && StatusData.StatusArray[index] == EFigureStatus::PRESENT) { + if (IsValid(PortalHandle)) { + FigureArray[index] = PortalHandle->ReadFigureBlocks(index); + UE_LOG(LogSkyportalIO, Log, TEXT("Figure ID : %d"), FigureArray[index]->GetFigureID()); + return; + } + UE_LOG(LogSkyportalIO, Error, TEXT("PortalHandle unreachable")); return; } UE_LOG(LogSkyportalIO, Error, TEXT("Error in FigureArray")); - + return; } diff --git a/Source/SkyPortal/Public/SkyPortalFigure.h b/Source/SkyPortal/Public/SkyPortalFigure.h index 8b39588..e785900 100644 --- a/Source/SkyPortal/Public/SkyPortalFigure.h +++ b/Source/SkyPortal/Public/SkyPortalFigure.h @@ -13,13 +13,26 @@ static const uint8 HASH_CONST[] = { #define FIGURE_TOTAL_BLOCKS 64 #define FIGURE_BLOCK_SIZE 16 + +UENUM(BlueprintType) +enum EVariantIDGeneration { + UNKNOW = -1, + SPYROS_ADVENTURE = 0, + GIANTS = 1, + SWAP_FORCE = 2, + TRAP_TEAM = 3, + SUPERCHARGERS = 4, + IMAGINATORS = 5 + +}; + /* typedef struct { unsigned char blockdata[FIGURE_TOTAL_BLOCKS][FIGURE_BLOCK_SIZE]; bool error; } FigureDataBlock; */ -UCLASS() +UCLASS(BlueprintType,Blueprintable) class UFigureData : public UObject { GENERATED_BODY() @@ -30,6 +43,11 @@ public: // Data Arrays uint8 data[64][16]; uint8 decryptedData[64][16]; + + UPROPERTY(BlueprintReadOnly) + bool bDecrypted; + + UPROPERTY(BlueprintReadOnly) bool dataError; // Properties @@ -47,6 +65,7 @@ public: #pragma endregion int16 ID; //Skylander ID int16 VariantID; //Skylander Variant ID + EVariantIDGeneration GenerationID; #pragma region counters uint8 counter1; uint8 counter2; @@ -56,13 +75,14 @@ public: // Methods - UFUNCTION(BlueprintCallable) + UFUNCTION(BlueprintCallable,BlueprintPure, meta = (Category = "SkyPortal|Figure")) int32 GetFigureID(); - uint32 GetFigureIdByIndex(uint32 index); + UFUNCTION(BlueprintCallable,BlueprintPure, meta = (Category = "SkyPortal|Figure")) + int32 GetVariantID(); - //UFUNCTION() - //TArray QueryBlock(uint8 characterIndex, uint8 block = 0x00); + UFUNCTION(BlueprintCallable, BlueprintPure, meta = (Category = "SkyPortal|Figure")) + EVariantIDGeneration GetGeneration(); void ReadData(uint8 index); void ClearData(); @@ -70,7 +90,9 @@ public: void SetByte(int block, int offset, uint8 value); uint16 GetShort(int block, int offset); uint32 GetUInt(int block, int offset); - void Dump(bool decrypted, FString filePath); + + UFUNCTION(BlueprintCallable) + bool Dump(bool decrypted, FString filePath); };