public UnpackResult Unpack(BinaryReader reader) { _reader = reader; UnpackResult result = null; try { byte[] identifier; byte[] header; byte[] actions; byte[] map; // unpack the identifier and header identifier = UnpackNextSection(IDENTIFIER_LENGTH); header = UnpackNextSection(HEADER_LENGTH); // unpack the actions section int actionsSize = Common.ToInteger(UnpackNextSection(SECTION_SIZE_LENGTH)); actions = UnpackNextSection(actionsSize); // unpack the map section int mapSize = Common.ToInteger(UnpackNextSection(SECTION_SIZE_LENGTH)); map = UnpackNextSection(mapSize); result = new UnpackResult(identifier, header, actions, map); } finally { reader.Close(); } return(result); }
public static UnpackResult LoadReplay(BinaryReader reader, Boolean noparse) { Unpacker unpacker = new Unpacker(); UnpackResult result = unpacker.Unpack(reader); return(result); }
public static IReplay LoadReplay(BinaryReader reader) { Unpacker unpacker = new Unpacker(); UnpackResult result = unpacker.Unpack(reader); return(ParseReplay(result)); }
public UnpackResult Unpack(BinaryReader reader) { _reader = reader; UnpackResult result = null; try { byte[] identifier; byte[] header; byte[] actions; byte[] map; // unpack the identifier and header identifier = UnpackNextSection(IDENTIFIER_LENGTH); header = UnpackNextSection(HEADER_LENGTH); // unpack the actions section int actionsSize = Common.ToInteger(UnpackNextSection(SECTION_SIZE_LENGTH)); actions = UnpackNextSection(actionsSize); // unpack the map section int mapSize = Common.ToInteger(UnpackNextSection(SECTION_SIZE_LENGTH)); map = UnpackNextSection(mapSize); result = new UnpackResult(identifier, header, actions, map); } finally { reader.Close(); } return result; }
public UnpackResult Unpack(BinaryReader reader) { _reader = reader; UnpackResult result = null; try { byte[] identifier; byte[] header; byte[] actions; byte[] map; // unpack the identifier and header identifier = ZlibUnpack(IDENTIFIER_LENGTH); int identity = Common.ToInteger(identifier); if (identity != 1397908850 /*new patch replay */ && identity != 1397908851) { throw new Exception( "Not a valid replay file!"); //if a file somehow makes it here before any of the other exceptions (typically would throw insufficient space in decode buffer first) } /* * header = UnpackNextSection(HEADER_LENGTH); * Console.WriteLine(_reader.BaseStream.Position.ToString("X")); * * int actionsSize = Common.ToInteger(UnpackNextSection(SECTION_SIZE_LENGTH)); * actions = UnpackNextSection(actionsSize); * * int mapSize = Common.ToInteger(UnpackNextSection(SECTION_SIZE_LENGTH)); * map = UnpackNextSection(mapSize); */ header = ZlibUnpack(HEADER_LENGTH, true); Header headerUnpacked = new HeaderParser(header).ParseHeader(); //Console.WriteLine(headerUnpacked.GameCreator); // unpack the actions section int actionsSize = Common.ToInteger(ZlibUnpack(SECTION_SIZE_LENGTH)); actions = ZlibUnpack(actionsSize); // unpack the map section int mapSize = Common.ToInteger(ZlibUnpack(SECTION_SIZE_LENGTH)); map = ZlibUnpack(mapSize); result = new UnpackResult(identifier, header, actions, map); } finally { reader.Close(); } return(result); }
private static IReplay ParseReplay(UnpackResult result) { HeaderParser headerParser = new HeaderParser(result.Header); Header header = headerParser.ParseHeader(); ActionParser actionsParser = new ActionParser(result.Actions, header.Players.ToList<IPlayer>()); List<IAction> actions = actionsParser.ParseActions(); IReplay replay = new Replay(header, actions); return replay; }
private static IReplay ParseReplay(UnpackResult result) { HeaderParser headerParser = new HeaderParser(result.Header); Header header = headerParser.ParseHeader(); ActionParser actionsParser = new ActionParser(result.Actions, header.Players.ToList <IPlayer>()); List <IAction> actions = actionsParser.ParseActions(); IReplay replay = new Replay(header, actions); return(replay); }