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