Skip to content

Commit

Permalink
Fix issues when loading savegames
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbyte committed Mar 22, 2024
1 parent b322504 commit 229de92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
14 changes: 7 additions & 7 deletions LSLib/LS/Save/SavegameHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public byte[] ResaveStoryToGlobals(Story.Story story, ResourceConversionParamete
var rsrcWriter = new LSFWriter(rewrittenStream)
{
Version = conversionParams.LSF,
EncodeSiblingData = false
MetadataFormat = LSFMetadataFormat.None
};
rsrcWriter.Write(globals);
rewrittenStream.Seek(0, SeekOrigin.Begin);
Expand Down Expand Up @@ -105,10 +105,10 @@ public void ResaveStory(Story.Story story, Game game, string path)
foreach (var file in Package.Files.Where(x => x.Name.ToLowerInvariant() != "globals.lsf"))
{
using var stream = file.CreateContentReader();
var contents = new byte[stream.Length];
stream.ReadExactly(contents, 0, contents.Length);
using var unpacked = new MemoryStream();
stream.CopyTo(unpacked);

build.Files.Add(PackageBuildInputFile.CreateFromBlob(contents, file.Name));
build.Files.Add(PackageBuildInputFile.CreateFromBlob(unpacked.ToArray(), file.Name));
}
}
else
Expand All @@ -124,10 +124,10 @@ public void ResaveStory(Story.Story story, Game game, string path)
foreach (var file in Package.Files.Where(x => x.Name.ToLowerInvariant() != "StorySave.bin"))
{
using var stream = file.CreateContentReader();
var contents = new byte[stream.Length];
stream.ReadExactly(contents, 0, contents.Length);
using var unpacked = new MemoryStream();
stream.CopyTo(unpacked);

build.Files.Add(PackageBuildInputFile.CreateFromBlob(contents, file.Name));
build.Files.Add(PackageBuildInputFile.CreateFromBlob(unpacked.ToArray(), file.Name));
}
}

Expand Down
6 changes: 2 additions & 4 deletions LSLib/LS/Story/Compiler/StoryEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ private DatabaseNode EmitDatabase(FunctionSignature signature)
{
Types = new List<uint>(signature.Params.Count)
},
OwnerNode = null,
FactsPosition = 0
OwnerNode = null
};

foreach (var param in signature.Params)
Expand Down Expand Up @@ -457,8 +456,7 @@ private Database EmitIntermediateDatabase(IRRule rule, int tupleSize, Node owner
{
Types = paramTypes
},
OwnerNode = ownerNode,
FactsPosition = 0
OwnerNode = ownerNode
};

osiDb.Facts = new FactCollection(osiDb, Story);
Expand Down
3 changes: 0 additions & 3 deletions LSLib/LS/Story/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,13 @@ public class Database : OsirisSerializable
public ParameterList Parameters;
public FactCollection Facts;
public Node OwnerNode;
public long FactsPosition;

public void Read(OsiReader reader)
{
Index = reader.ReadUInt32();
Parameters = new ParameterList();
Parameters.Read(reader);

FactsPosition = reader.BaseStream.Position;
Facts = new FactCollection(this, reader.Story);
reader.ReadList<Fact>(Facts);
}
Expand All @@ -229,7 +227,6 @@ public void DebugDump(TextWriter writer, Story story)
writer.Write("(Not owned)");
}

writer.Write(" @ {0:X}: ", FactsPosition);
Parameters.DebugDump(writer, story);

writer.WriteLine("");
Expand Down

0 comments on commit 229de92

Please sign in to comment.