static void Main() { var disk = new FileSystem(); var baseDir = ConfigUtil.FindBasePath(disk); if (baseDir == null) { throw new InvalidOperationException("No base directory could be found."); } var dir = Path.Combine(baseDir, RelativePath); var files = Directory.EnumerateFiles(dir, "*.bin"); foreach (var file in files) { using var stream = File.OpenRead(file); using var br = new BinaryReader(stream); using var s = new AlbionReader(br); var flic = new FlicFile(s); var buffer = new byte[flic.Width * flic.Height]; AviFile.Write( Path.ChangeExtension(file, "avi"), flic.Speed, flic.Width, flic.Height, flic.Play(() => buffer).AllFrames32()); // break; } }
static IMapEvent BytesToEvent(byte[] bytes) { using var ms = new MemoryStream(bytes); using var br = new BinaryReader(ms); using var s = new AlbionReader(br); return(MapEvent.Serdes(null, s, EventSetId.None, TextId.None, AssetMapping.Global)); }
AlbionPalette LoadPalette(string file, AssetInfo assetInfo) { using var stream = File.Open(file, FileMode.Open); using var br = new BinaryReader(stream); using var s = new AlbionReader(br, stream.Length); return(new AlbionPalette(s, assetInfo)); }
IReadOnlyTexture <byte> LoadSprite(string filename, AssetInfo conf) { using var stream = File.OpenRead(Path.Combine(_core.BaseExportDirectory, filename)); using var br = new BinaryReader(stream); using var ar = new AlbionReader(br, stream.Length); return((IReadOnlyTexture <byte>)GetLoader(conf).Serdes(null, conf, AssetMapping.Global, ar)); }
public ISerializer Open(string file, AssetInfo info) { if (info == null) { throw new ArgumentNullException(nameof(info)); } using var s = new AlbionReader(new BinaryReader(File.OpenRead(file))); var bytes = LoadAsset(info.SubAssetId, s); var ms = new MemoryStream(bytes); return(new AlbionReader(new BinaryReader(ms))); }
public static string GetName(BinaryReader br) { var s = new AlbionReader(br, br.BaseStream.Length); ushort nameLength = s.UInt16("NameLength", 0); if (nameLength > 1024) { return("Invalid"); } s.UInt16(nameof(Unk0), 0); return(s.FixedLengthString(nameof(Name), null, nameLength)); }
public static void RoundTripTest(string baseDir) { var mapping = AssetMapping.Global; // TODO: Base game mapping. var saveDir = Path.Combine(baseDir, "re", "TestSaves"); var regex = new Regex(@"\.[0-9][0-9][0-9]$"); foreach (var file in Directory.EnumerateFiles(saveDir)) { if (!regex.IsMatch(file)) { continue; } Console.WriteLine("Round-trip testing " + file); using var stream = File.Open(file, FileMode.Open); using var br = new BinaryReader(stream); using var ar = new AlbionReader(br, stream.Length); var save = SavedGame.Serdes(null, mapping, ar); using var ms = new MemoryStream(); using var bw = new BinaryWriter(ms); using var aw = new AlbionWriter(bw); SavedGame.Serdes(save, mapping, aw); br.BaseStream.Position = 0; var originalBytes = br.ReadBytes((int)stream.Length); var roundTripBytes = ms.ToArray(); //* Save round-tripped and annotated text output for debugging File.WriteAllBytes(file + ".bin", roundTripBytes); using var ts = new MemoryStream(); using var tw = new StreamWriter(ts); using var afw = new AnnotatedFormatWriter(tw); SavedGame.Serdes(save, mapping, afw); ts.Position = 0; File.WriteAllBytes(file + ".txt", ts.ToArray()); //*/ ApiUtil.Assert(originalBytes.Length == roundTripBytes.Length); ApiUtil.Assert(originalBytes.SequenceEqual(roundTripBytes)); var sw = new StringWriter(); using var jw = new JsonWriter(sw); SavedGame.Serdes(save, mapping, jw); File.WriteAllText(file + ".json", sw.ToString()); break; } Console.WriteLine("Done"); Console.ReadLine(); }
public ISerializer Read(string file, AssetInfo info, IFileSystem disk, IJsonUtil jsonUtil) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (disk == null) { throw new ArgumentNullException(nameof(disk)); } using var s = new AlbionReader(new BinaryReader(disk.OpenRead(file))); var bytes = LoadAsset(info.Index, s); var ms = new MemoryStream(bytes); return(new AlbionReader(new BinaryReader(ms))); }
public static string GetName(BinaryReader br) { if (br == null) { throw new ArgumentNullException(nameof(br)); } using var s = new AlbionReader(br, br.BaseStream.Length); ushort nameLength = s.UInt16("NameLength", 0); if (nameLength > 1024) { return("Invalid"); } s.UInt16(nameof(Unk0), 0); return(s.FixedLengthString(nameof(Name), null, nameLength)); }