Created
July 16, 2019 20:46
-
-
Save CodeAndLoathing/689094e2bcf009b0c76f1137b8360d51 to your computer and use it in GitHub Desktop.
Sunless Skies: convert .bytes files to .json files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#$PSVersionTable.PSVersion | |
#tested on PowerShell 6.2.1 | |
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop | |
$WarningPreference = [System.Management.Automation.ActionPreference]::Inquire | |
# Location of Game Folders | |
$BASE_GAME_FOLDER = "C:\GOG Games\Sunless Skies" | |
$MANAGED_FOLDER = "{0}\Sunless Skies_Data\Managed" -f $BASE_GAME_FOLDER | |
$GAME_DATA = "{0}\..\LocalLow\Failbetter Games\Sunless Skies\storage\data" -f $env:APPDATA | |
$GAME_DATA_BACKUPS = "{0}\..\LocalLow\Failbetter Games\Sunless Skies\storage\data_backups" -f $env:APPDATA | |
# import | |
Add-Type -Path ("{0}\Assembly-CSharp.dll" -f $MANAGED_FOLDER) | |
CD $GAME_DATA | |
$JsonSerializerSettings = [Newtonsoft.Json.JsonSerializerSettings]::new() | |
$JsonSerializerSettings.ReferenceLoopHandling = [Newtonsoft.Json.ReferenceLoopHandling]::Serialize | |
$JsonSerializerSettings.PreserveReferencesHandling = [Newtonsoft.Json.PreserveReferencesHandling]::Objects | |
$JsonSerializerSettings.Formatting = [Newtonsoft.Json.Formatting]::Indented | |
$dataTypes = "areas", "bargains", "domiciles", "events", "exchanges", "personas", "prospects", "qualities", "settings" | |
foreach ($type in $dataTypes) { | |
$br = [System.IO.BinaryReader]::new([System.IO.File]::Open(("{0}\{1}.bytes" -f $GAME_DATA, $type), [System.IO.FileMode]::Open)) | |
switch ($type) { | |
"areas" { $data = [BinarySerializer.BinarySerializer_Area]::DeserializeCollection($br) } | |
"bargains" { $data = [BinarySerializer.BinarySerializer_Bargain]::DeserializeCollection($br) } | |
"domiciles" { $data = [BinarySerializer.BinarySerializer_Domicile]::DeserializeCollection($br) } | |
"events" { $data = [BinarySerializer.BinarySerializer_Event]::DeserializeCollection($br) } | |
"exchanges" { $data = [BinarySerializer.BinarySerializer_Exchange]::DeserializeCollection($br) } | |
"personas" { $data = [BinarySerializer.BinarySerializer_Persona]::DeserializeCollection($br) } | |
"prospects" { $data = [BinarySerializer.BinarySerializer_Prospect]::DeserializeCollection($br) } | |
"qualities" { $data = [BinarySerializer.BinarySerializer_Quality]::DeserializeCollection($br) } | |
"settings" { $data = [BinarySerializer.BinarySerializer_Setting]::DeserializeCollection($br) } | |
} | |
$data | ConvertTo-Json | Out-File ("{0}.json" -f $type) | |
[Newtonsoft.Json.JsonConvert]::SerializeObject($data,$JsonSerializerSettings) | Out-File -FilePath ("{0}/{1}.json" -f $GAME_DATA, $type) | |
$br.Close() | |
} |
[Unable to read Beyond the end of Stream], sorry
I have managed to extract most of the jsons with this script, thanks a lot! However, I have no idea how to convert them back to bytes, I tried writting a script based on this one but I found it too difficult for me. Any help would be much appreciated!
I haven't looked @ this in a long time. Unlike Sunless Seas, Sunless Skies seemed to have limited ability to modify it in any supported manner and I moved on to other things.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Greetings! I ran into a problem while I tried to use this script to deserialize the .bytes file of the newer version of this game. Powershell reports "can not read outside the end of the stream", but this happens just on bargains.bytes and qualities.bytes. Could you please please teach me how to fix this?