public static SFXSaveGameFile Read(Stream input) { if (input == null) { throw new ArgumentNullException("input"); } var save = new SFXSaveGameFile() { _Version = input.ReadValueU32(Endian.Little) }; if (save._Version != 29 && save._Version.Swap() != 29 && save._Version != 59 && save._Version.Swap() != 59) { throw new FormatException("unexpected version"); } var endian = save._Version == 29 || save._Version == 59 ? Endian.Little : Endian.Big; if (endian == Endian.Big) { save._Version = save._Version.Swap(); } var reader = new Unreal.FileReader(input, save._Version, endian); save.Serialize(reader); if (save._Version >= 27) { if (input.Position != input.Length - 4) { throw new FormatException("bad checksum position"); } save._Checksum = input.ReadValueU32(); } if (input.Position != input.Length) { throw new FormatException("did not consume entire file"); } save.Endian = endian; return(save); }
public static void Write(SFXSaveGameFile save, Stream output) { if (save == null) { throw new ArgumentNullException("save"); } if (output == null) { throw new ArgumentNullException("output"); } using (var memory = new MemoryStream()) { memory.WriteValueU32(save.Version, save._Endian); var writer = new Unreal.FileWriter(memory, save._Version, save._Endian); save.Serialize(writer); if (save._Version >= 27) { memory.Position = 0; uint checksum = 0; var buffer = new byte[1024]; while (memory.Position < memory.Length) { int read = memory.Read(buffer, 0, 1024); checksum = Crc32.Compute(buffer, 0, read, checksum); } save._Checksum = checksum; memory.WriteValueU32(checksum, save._Endian); } memory.Position = 0; output.WriteFromStream(memory, memory.Length); } }
public static void SetNewGamePlotStates( this SFXSaveGameFile target, SFXSaveGameFile legacyImport, SFXSaveGameFile plusImport) { if (legacyImport != null) { target.CopyMe2PlotData(legacyImport); target.SetPlayerPlotData(); target.DoMe2PlotImport(legacyImport); } else if (plusImport != null) { target.DoMe3NewGamePlusImport(plusImport); target.SetPlayerPlotData(); } else { target.SetPlayerPlotData(); target.ApplyCanonPlots(Me1CanonPlotVariables); target.ApplyCanonPlots(Me2CanonPlotVariables); } }
public static void CopyMe2PlotData( this SFXSaveGameFile target, SFXSaveGameFile legacyImport) { throw new NotImplementedException(); }
public static void DoMe3NewGamePlusImport( this SFXSaveGameFile target, SFXSaveGameFile plusImport) { throw new NotImplementedException(); }
public static void DoMe2PlotImport( this SFXSaveGameFile target, SFXSaveGameFile legacyImport) { if (legacyImport.ME1Plot.BoolVariables.Length > 0 || legacyImport.ME1Plot.IntVariables.Count > 0 || legacyImport.ME1Plot.FloatVariables.Count > 0) { target.MergeMe1PlotRecord(legacyImport.ME1Plot); target.FixMe1PlotsDuringMe2PlotImport(); target.CopyPlots(Me1ToMe3PlotCopy); target.Plot.SetBoolVariable(Constants.ME3_Plots_Bool_Is_ME1_Import, true); } else { target.ApplyCanonPlots(Me1CanonPlotVariables); target.DoDarkHorseMe1PlotCopyAndPlotLogicFix(); } target.CopyPlots(Me2ToMe3PlotCopy); target.Plot.SetBoolVariable(Constants.ME3_Plots_Bool_Is_ME2_Import, true); }