IT WORKS
This commit is contained in:
parent
67a5aa000e
commit
a377bf6f00
7 changed files with 49 additions and 29 deletions
|
@ -2,8 +2,12 @@
|
|||
|
||||
#include "SkyPortalFigure.h"
|
||||
|
||||
UFigureData::UFigureData()
|
||||
{
|
||||
ClearData();
|
||||
}
|
||||
|
||||
uint32 FigureData::GetFigureID()
|
||||
int32 UFigureData::GetFigureID()
|
||||
{
|
||||
if (ID == 0) {
|
||||
int16_t OutFigureID = 0;
|
||||
|
@ -25,6 +29,6 @@ uint32 FigureData::GetFigureID()
|
|||
|
||||
};
|
||||
|
||||
void FigureData::ClearData()
|
||||
void UFigureData::ClearData()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ uint8* USkyPortalIO::QueryBlock(uint8 FigureIndex, uint8 BlockIndex)
|
|||
UE_LOG(LogSkyportalIO, Verbose, TEXT("Trying to write... attempt:%d"), attempt);
|
||||
if (Write(&command)) {
|
||||
output = Read();
|
||||
if (output != 0) {
|
||||
if (output != nullptr && output != 0) {
|
||||
UE_LOG(LogSkyportalIO, Verbose, TEXT("Read success: output[0]=%d, output[1]=%d, output[2]=%d"), output[0], output[1], output[2]);
|
||||
}else{
|
||||
UE_LOG(LogSkyportalIO, Error, TEXT("Read failed, output is null"));
|
||||
|
@ -340,11 +340,11 @@ void DecryptAES128(uint8* OutData, const uint8* InData, const uint8* Key)
|
|||
UE_LOG(LogSkyportalIO, VeryVerbose, TEXT("DECRYPT -- data %s with %s key decryted"), *DataToString(InData), *DataToString(Key));
|
||||
}
|
||||
|
||||
FigureData USkyPortalIO::ReadFigureBlocks(uint8 FigureIndex)
|
||||
UFigureData* USkyPortalIO::ReadFigureBlocks(uint8 FigureIndex)
|
||||
{
|
||||
|
||||
FigureData TempFigureData;
|
||||
TempFigureData.dataError = false; // Initialize error flag
|
||||
UFigureData* TempFigureData = NewObject<UFigureData>();
|
||||
TempFigureData->dataError = false; // Initialize error flag
|
||||
|
||||
|
||||
|
||||
|
@ -362,13 +362,13 @@ FigureData USkyPortalIO::ReadFigureBlocks(uint8 FigureIndex)
|
|||
}
|
||||
|
||||
// Copy 16 bytes from the output, starting at the third byte
|
||||
FMemory::Memcpy(TempFigureData.data[BlockIndex], output + 3, FIGURE_BLOCK_SIZE);
|
||||
FMemory::Memcpy(TempFigureData->data[BlockIndex], output + 3, FIGURE_BLOCK_SIZE);
|
||||
|
||||
|
||||
// Block 1 is sometimes a duplicate of block 0
|
||||
if (BlockIndex == 1)
|
||||
{
|
||||
if (FMemory::Memcmp(TempFigureData.data[1], TempFigureData.data[0], FIGURE_BLOCK_SIZE) == 0)
|
||||
if (FMemory::Memcmp(TempFigureData->data[1], TempFigureData->data[0], FIGURE_BLOCK_SIZE) == 0)
|
||||
{
|
||||
// Decrement BlockIndex to reprocess block 1 if it's a duplicate of block 0
|
||||
--BlockIndex;
|
||||
|
@ -380,7 +380,7 @@ FigureData USkyPortalIO::ReadFigureBlocks(uint8 FigureIndex)
|
|||
if (((BlockIndex + 1) % 4 == 0) || BlockIndex < 8)
|
||||
{
|
||||
// Direct copy from data to decryptedData for certain blocks
|
||||
FMemory::Memcpy(TempFigureData.decryptedData[BlockIndex], TempFigureData.data[BlockIndex], FIGURE_BLOCK_SIZE);
|
||||
FMemory::Memcpy(TempFigureData->decryptedData[BlockIndex], TempFigureData->data[BlockIndex], FIGURE_BLOCK_SIZE);
|
||||
UE_LOG(LogSkyportalIO, Verbose, TEXT("Block %d doesnt need decryption"), BlockIndex);
|
||||
}
|
||||
else {
|
||||
|
@ -388,8 +388,8 @@ FigureData USkyPortalIO::ReadFigureBlocks(uint8 FigureIndex)
|
|||
// Prepare the hash input buffer
|
||||
UE_LOG(LogSkyportalIO, Verbose, TEXT("DECRYPT -- Starting decryting block %d"), BlockIndex);
|
||||
uint8 hashIn[0x56];
|
||||
FMemory::Memcpy(hashIn, TempFigureData.data[0], 16);
|
||||
FMemory::Memcpy(hashIn + 0x10, TempFigureData.data[1], 16);
|
||||
FMemory::Memcpy(hashIn, TempFigureData->data[0], 16);
|
||||
FMemory::Memcpy(hashIn + 0x10, TempFigureData->data[1], 16);
|
||||
hashIn[0x20] = BlockIndex;
|
||||
// Append the 35-byte constant
|
||||
FMemory::Memcpy(hashIn + 0x21, HASH_CONST, sizeof(HASH_CONST));
|
||||
|
@ -407,7 +407,7 @@ FigureData USkyPortalIO::ReadFigureBlocks(uint8 FigureIndex)
|
|||
|
||||
//TODO: FAES implementation in Unreal is AES-256. We need AES-128
|
||||
//FAES::DecryptData(TempFigureData.decryptedData[BlockIndex], TempFigureData.data[BlockIndex], 16, AesKey);
|
||||
DecryptAES128(TempFigureData.decryptedData[BlockIndex], TempFigureData.data[BlockIndex], key);
|
||||
DecryptAES128(TempFigureData->decryptedData[BlockIndex], TempFigureData->data[BlockIndex], key);
|
||||
UE_LOG(LogSkyportalIO, Verbose, TEXT("DECRYPT -- block %d decrypted"), BlockIndex);
|
||||
}
|
||||
UE_LOG(LogSkyportalIO, VeryVerbose, TEXT("block %d readed with success"), BlockIndex);
|
||||
|
|
|
@ -49,18 +49,18 @@ void FPortalStatusChecker::CheckPortalStatus()
|
|||
{
|
||||
USkyPortalSubsystem* subref = Cast<USkyPortalSubsystem>(SkyPortalSubsystemRef);
|
||||
USkyPortalIO* PortalHandleRef = subref->PortalHandle;
|
||||
UE_LOG(LogSkyportalIO, Verbose, TEXT("Check portal"));
|
||||
UE_LOG(LogSkyportalIO, VeryVerbose, TEXT("Check portal"));
|
||||
if (PortalHandleRef && PortalHandleRef->bPortalReady)
|
||||
{
|
||||
// Call the subsystem function to get portal status
|
||||
uint8* output = PortalHandleRef->Read();
|
||||
EPortalCommand CommandResponse = GetPortalCommandFromChar(output[0]);
|
||||
FigureData figData;
|
||||
//UFigureData figData;
|
||||
switch (CommandResponse)
|
||||
{
|
||||
case S:
|
||||
CurrentStatusData = ParsePortalStatus(output);
|
||||
UE_LOG(LogSkyportalIO, Verbose, TEXT("Output Data: %s"), *BytesToHex(output, sizeof(output)));
|
||||
UE_LOG(LogSkyportalIO, VeryVerbose, TEXT("Output Data: %s"), *BytesToHex(output, sizeof(output)));
|
||||
|
||||
//Send delegate when new informations are received
|
||||
if (OldStatusData != CurrentStatusData) {
|
||||
|
@ -97,7 +97,7 @@ void FPortalStatusChecker::CheckPortalStatus()
|
|||
}
|
||||
|
||||
// Do something with the status (log, notify, etc.)
|
||||
UE_LOG(LogSkyportalIO, Verbose, TEXT("Portal Status:"));
|
||||
UE_LOG(LogSkyportalIO, VeryVerbose, TEXT("Portal Status:"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,12 @@ void USkyPortalSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
|||
{
|
||||
|
||||
Super::Initialize(Collection);
|
||||
|
||||
FigureArray.SetNum(16);
|
||||
// Create UFigureData objects dynamically
|
||||
for (uint8 i = 0; i < FigureArray.Num(); i++)
|
||||
{
|
||||
FigureArray[i] = NewObject<UFigureData>(this);
|
||||
}
|
||||
UE_LOG(LogTemp, Log, TEXT("SkyPortalSubsystem Initialized"));
|
||||
|
||||
}
|
||||
|
@ -276,8 +281,14 @@ void USkyPortalSubsystem::PortalAnalyzeAsync(const uint8 Index)
|
|||
{
|
||||
|
||||
UE_LOG(LogSkyportalIO, Log, TEXT("Reading figure..."));
|
||||
FigureArray[index] = PortalHandle->ReadFigureBlocks(index);
|
||||
UE_LOG(LogSkyportalIO, Log, TEXT("Figure ID : %d"), FigureArray[index].GetFigureID());
|
||||
if (FigureArray.IsValidIndex(index)) {
|
||||
FigureArray[index] = PortalHandle->ReadFigureBlocks(index);
|
||||
UE_LOG(LogSkyportalIO, Log, TEXT("Figure ID : %d"), FigureArray[index]->GetFigureID());
|
||||
return;
|
||||
}
|
||||
UE_LOG(LogSkyportalIO, Error, TEXT("Error in FigureArray"));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
//#include "SkyPortalFigure.generated.h"
|
||||
#include "SkyPortalFigure.generated.h"
|
||||
|
||||
//Copyright (C) 2010 Activision.All Rights Reserved.
|
||||
static const uint8 HASH_CONST[] = {
|
||||
|
@ -18,9 +19,14 @@ typedef struct {
|
|||
} FigureDataBlock;
|
||||
*/
|
||||
|
||||
UCLASS()
|
||||
class UFigureData : public UObject {
|
||||
GENERATED_BODY()
|
||||
|
||||
class FigureData {
|
||||
public:
|
||||
|
||||
UFigureData();
|
||||
|
||||
// Data Arrays
|
||||
uint8 data[64][16];
|
||||
uint8 decryptedData[64][16];
|
||||
|
@ -43,18 +49,16 @@ public:
|
|||
int16 VariantID; //Skylander Variant ID
|
||||
#pragma region counters
|
||||
uint8 counter1;
|
||||
uint8 couter2;
|
||||
uint8 counter2;
|
||||
#pragma endregion
|
||||
FString Nickname;
|
||||
|
||||
FigureData()
|
||||
{
|
||||
ClearData();
|
||||
}
|
||||
|
||||
|
||||
// Methods
|
||||
UFUNCTION(BlueprintCallable)
|
||||
int32 GetFigureID();
|
||||
|
||||
uint32 GetFigureID();
|
||||
uint32 GetFigureIdByIndex(uint32 index);
|
||||
|
||||
//UFUNCTION()
|
||||
|
|
|
@ -80,7 +80,7 @@ public:
|
|||
*/
|
||||
unsigned char* QueryBlock(uint8 characterIndex, uint8 block = 0x00);
|
||||
|
||||
FigureData ReadFigureBlocks(uint8 FigureIndex);
|
||||
UFigureData* ReadFigureBlocks(uint8 FigureIndex);
|
||||
|
||||
/* Close connection to Portal*/
|
||||
void Close();
|
||||
|
|
|
@ -117,7 +117,8 @@ public:
|
|||
UPROPERTY(BlueprintReadOnly)
|
||||
FPortalStatusData StatusData;
|
||||
|
||||
TArray<FigureData> FigureArray;
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
TArray<UFigureData*> FigureArray;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
float RunnerInterval = 0.01f; //In seconds
|
||||
|
|
Loading…
Reference in a new issue