Advertisement
Kyojin96

RCon Account File Saving

Jan 25th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. void AUERConPluginProjectGameModeBase::WriteAccountData()
  2. {
  3.     FString SaveDirectory = FString("E:/UESaves");
  4.     FString FileName = FString("UE4Save.bin");
  5.     FString TextToSave = FString("YoungWolf?db235ccsa432ds");
  6.  
  7.     bool bAllowOverwriting = false;
  8.  
  9.     IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
  10.  
  11.     FString FullPath = SaveDirectory + "/" + FileName;
  12.  
  13.     IFileHandle* FileHandle = PlatformFile.OpenWrite(*FullPath);
  14.    
  15.     if (FileHandle)
  16.     {
  17.         //FileHandle->Write((const uint8*)TCHAR_TO_ANSI(*TextToSave), TextToSave.Len());
  18.    
  19.         int32 size = TextToSave.Len();
  20.    
  21.         uint8* ByteArray = reinterpret_cast<uint8*>(FMemory::Malloc(size + 1));
  22.    
  23.         int32 sizeWritten = StringToBytes(TextToSave, ByteArray, size + 1);
  24.    
  25.         FileHandle->Write(ByteArray, sizeWritten);
  26.    
  27.         delete FileHandle;
  28.     }
  29. }
  30.  
  31. void AUERConPluginProjectGameModeBase::LoadAccountData()
  32. {
  33.     FString SaveDirectory = FString("E:/UESaves");
  34.     FString FileName = FString("UE4Save.bin");
  35.     FString TextToSave = FString("YoungWolf?db235ccsa432ds");
  36.  
  37.     bool bAllowOverwriting = false;
  38.  
  39.     IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
  40.  
  41.     FString FullPath = SaveDirectory + "/" + FileName;
  42.  
  43.     IFileHandle* FileHandle = PlatformFile.OpenRead(*FullPath);
  44.    
  45.     if (FileHandle)
  46.     {
  47.         int64 size = GetFileSizeOf(FullPath);
  48.    
  49.         //Allocate uint8 buffer with size
  50.         uint8* ByteArray = reinterpret_cast<uint8*>(FMemory::Malloc(size + 1));
  51.    
  52.         //Read Data to buffer
  53.         FileHandle->Read(ByteArray, size);
  54.    
  55.         //Convert to decimal here..
  56.         FString Converted = BytesToString(ByteArray, size);
  57.    
  58.         FString Fixed = FixString(Converted);
  59.    
  60.         GEngine->AddOnScreenDebugMessage(3, 5.0f, FColor::Yellow, Converted);
  61.    
  62.         delete FileHandle;
  63.     }
  64. }
  65.  
  66. int64 AUERConPluginProjectGameModeBase::GetFileSizeOf(FString FullPath)
  67. {
  68.     int64 FileSize = 0;
  69.  
  70.     if (!FPlatformFileManager::Get().GetPlatformFile().FileExists(*FullPath))
  71.     {
  72.         GEngine->AddOnScreenDebugMessage(0, 5.0f, FColor::Red, TEXT("File not found!"));
  73.         return 0;
  74.     }
  75.  
  76.     FileSize = FPlatformFileManager::Get().GetPlatformFile().FileSize(*FullPath);
  77.  
  78.     return FileSize;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement