void initialize() { _invalidError = _invalidError.Replace("{0}", "TIE"); _endOfMissionIndexer = new Indexer <string>(_endOfMissionMessages, 63); FlightGroups = new FlightGroupCollection(); FlightGroupsBriefing = new FlightGroupCollection(); Briefing = new Briefing(); }
/// <summary>Loads a mission briefing (.BRF) file from an open FileStream</summary> /// <param name="stream">Opened FileStream to mission briefing file</param> /// <exception cref="InvalidDataException"><paramref name="stream"/> is not a valid X-wing mission briefing file</exception> public void LoadBriefingFromStream(FileStream stream) { BinaryReader br = new BinaryReader(stream, System.Text.Encoding.GetEncoding(437)); //[JB] Changed encoding to IBM437 (OEM United States) to properly handle the DOS ASCII character set. string str; short s; s = br.ReadInt16(); //PlatformID if (s != 2) { throw new InvalidDataException("Not a valid X-wing briefing file."); } short shipCount = br.ReadInt16(); short coordCount = br.ReadInt16(); FlightGroupsBriefing = new FlightGroupCollection(shipCount); int wp; for (int i = 0; i < coordCount; i++) { //Just in case there too many coord sets than what the editor allows, read them but only load them if the indexes are valid. if (i == 0) { wp = 0; //SP1 } else { wp = 7 + i - 1; //CS1 starts at [7], but at this point i==1 so subtract to compensate } if (wp >= 10) { wp = -1; } for (int j = 0; j < shipCount; j++) { for (int k = 0; k < 3; k++) { short dat = br.ReadInt16(); if (wp >= 0) { FlightGroupsBriefing[j].Waypoints[wp][k] = dat; } } if (wp >= 0 && wp < 7) { FlightGroupsBriefing[j].Waypoints[wp][3] = 1; } } } if (coordCount < 2) { coordCount = 2; //Sanity check for editor purposes. All LEC missions have 2 sets. } else if (coordCount > 4) { coordCount = 4; } Briefing.MaxCoordSet = coordCount; for (int i = 0; i < shipCount; i++) { s = br.ReadInt16(); //craft type if (s < 18) { FlightGroupsBriefing[i].CraftType = (byte)s; FlightGroupsBriefing[i].ObjectType = 0; } else { FlightGroupsBriefing[i].CraftType = 0; FlightGroupsBriefing[i].ObjectType = s; } FlightGroupsBriefing[i].IFF = (byte)br.ReadInt16(); FlightGroupsBriefing[i].NumberOfCraft = (byte)br.ReadInt16(); FlightGroupsBriefing[i].NumberOfWaves = (byte)br.ReadInt16(); FlightGroupsBriefing[i].Name = new string(br.ReadChars(16)); FlightGroupsBriefing[i].Cargo = new string(br.ReadChars(16)); FlightGroupsBriefing[i].SpecialCargo = new string(br.ReadChars(16)); FlightGroupsBriefing[i].SpecialCargoCraft = br.ReadInt16(); FlightGroupsBriefing[i].Yaw = br.ReadInt16(); FlightGroupsBriefing[i].Pitch = br.ReadInt16(); FlightGroupsBriefing[i].Roll = br.ReadInt16(); } #region WindowUISettings short count = br.ReadInt16(); //Setting count. Usually 2, but not always. Briefing.ResetUISettings(count); for (int i = 0; i < count; i++) { for (int j = 0; j < 5; j++) { BriefingUIItem item = Briefing.WindowSettings[i].Items[j]; item.Top = br.ReadInt16(); item.Left = br.ReadInt16(); item.Bottom = br.ReadInt16(); item.Right = br.ReadInt16(); item.IsVisible = Convert.ToBoolean(br.ReadInt16()); } } #endregion WindowUISettings #region Pages count = br.ReadInt16(); Briefing.ResetPages(count); for (int i = 0; i < count; i++) { BriefingPage pg = Briefing.Pages[i]; pg.Length = br.ReadInt16(); //total ticks pg.EventsLength = br.ReadInt16(); //Count of Int16s pg.CoordSet = br.ReadInt16(); pg.PageType = br.ReadInt16(); byte[] briefBuffer = br.ReadBytes(pg.EventsLength * 2); Buffer.BlockCopy(briefBuffer, 0, pg.Events, 0, briefBuffer.Length); } #endregion Pages stream.Position += 6; /*s = br.ReadInt16(); //TimeLimitMinutes? * s = br.ReadInt16(); //EndEvent? * s = br.ReadInt16(); //Unknown1?*/ Briefing.MissionLocation = br.ReadInt16(); stream.Position += 3 * 64; /*for (int i = 0; i < 3; i++) //EndOfMissionMessages * str = new string(br.ReadChars(64));*/ stream.Position += 90 * shipCount; /*for (int i = 0; i < shipCount; i++) * { * //No idea what data this is, or even what order. * br.ReadBytes(68); * s = br.ReadInt16(); //PlayerCraft? * br.ReadBytes(20); * }*/ #region Text/Tags count = br.ReadInt16(); //Tags Briefing.ResizeTagList(count); for (int i = 0; i < count; i++) { short len = br.ReadInt16(); Briefing.BriefingTag[i] = new string(br.ReadChars(len)); } count = br.ReadInt16(); //Text Briefing.ResizeStringList(count); for (int i = 0; i < count; i++) { short len = br.ReadInt16(); str = new string(br.ReadChars(len)); byte[] highlight = new byte[len]; br.Read(highlight, 0, len); Briefing.BriefingString[i] = Briefing.TranslateHighlightToString(str, highlight); } #endregion Text/Tags }
/// <summary>Loads a mission from an open FileStream</summary> /// <param name="stream">Opened FileStream to mission file</param> /// <exception cref="InvalidDataException"><paramref name="stream"/> is not a valid X-wing mission file</exception> public void LoadFromStream(FileStream stream) { if (GetPlatform(stream) != Platform.Xwing) { throw new InvalidDataException(_invalidError); } BinaryReader br = new BinaryReader(stream, System.Text.Encoding.GetEncoding(437)); //[JB] Changed encoding to IBM437 (OEM United States) to properly handle the DOS ASCII character set. int i; //Position 0 = PlatformID (2 bytes) stream.Position = 2; TimeLimitMinutes = br.ReadInt16(); EndEvent = br.ReadInt16(); RndSeed = br.ReadInt16(); Location = br.ReadInt16(); for (i = 0; i < 3; i++) { EndOfMissionMessages[i] = new string(br.ReadChars(64)); } short numFlightGroups = br.ReadInt16(); short numObjectGroups = br.ReadInt16(); //Header is finished. Begin Flight Groups. FlightGroups = new FlightGroupCollection(numFlightGroups + numObjectGroups); for (i = 0; i < numFlightGroups; i++) { #region Craft int j; FlightGroups[i].Name = new string(br.ReadChars(16)); FlightGroups[i].Cargo = new string(br.ReadChars(16)); FlightGroups[i].SpecialCargo = new string(br.ReadChars(16)); FlightGroups[i].SpecialCargoCraft = (byte)br.ReadInt16(); FlightGroups[i].CraftType = (byte)br.ReadInt16(); FlightGroups[i].IFF = (byte)br.ReadInt16(); FlightGroups[i].Status1 = (byte)br.ReadInt16(); FlightGroups[i].NumberOfCraft = (byte)br.ReadInt16(); FlightGroups[i].NumberOfWaves = (byte)br.ReadInt16(); #endregion #region Arr/Dep FlightGroups[i].ArrivalEvent = br.ReadInt16(); FlightGroups[i].ArrivalDelay = br.ReadInt16(); FlightGroups[i].ArrivalFG = br.ReadInt16(); FlightGroups[i].Mothership = br.ReadInt16(); FlightGroups[i].ArrivalHyperspace = br.ReadInt16(); FlightGroups[i].DepartureHyperspace = br.ReadInt16(); #endregion //Waypoints (7 real waypoints, rest are virtualized BRF coordinate sets) for (j = 0; j < 4; j++) { for (int k = 0; k < 7; k++) { FlightGroups[i].Waypoints[k][j] = (br.ReadInt16() /* (j == 1 ? -1 : 1) */); } } //More craft info FlightGroups[i].Formation = (byte)br.ReadInt16(); FlightGroups[i].PlayerCraft = (byte)br.ReadInt16(); FlightGroups[i].AI = (byte)br.ReadInt16(); FlightGroups[i].Order = br.ReadInt16(); FlightGroups[i].DockTimeThrottle = br.ReadInt16(); FlightGroups[i].Markings = (byte)br.ReadInt16(); stream.Position += 2; //Second marking. FlightGroups[i].Objective = br.ReadInt16(); FlightGroups[i].TargetPrimary = br.ReadInt16(); FlightGroups[i].TargetSecondary = br.ReadInt16(); } //Read the Object Groups into the FG list. Although Flight Groups and Object Groups are separate in X-wing, YOGEME abstracts them to appear as flight groups for editing purposes. for (i = numFlightGroups; i < FlightGroups.Count; i++) { FlightGroups[i].Name = new string(br.ReadChars(16)); //Only the name is used, but the format appears to resemble FGs FlightGroups[i].Cargo = new string(br.ReadChars(16)); FlightGroups[i].SpecialCargo = new string(br.ReadChars(16)); FlightGroups[i].SpecialCargoCraft = (byte)br.ReadInt16(); FlightGroups[i].CraftType = 0; FlightGroups[i].ObjectType = br.ReadInt16(); FlightGroups[i].IFF = (byte)br.ReadInt16(); //The format begins to deviate here FlightGroups[i].Formation = (byte)br.ReadInt16(); FlightGroups[i].NumberOfWaves = 0; //Doesn't exist in file, but setting it here just in case. FlightGroups[i].NumberOfCraft = (byte)br.ReadInt16(); FlightGroups[i].Waypoints[0][0] = br.ReadInt16(); FlightGroups[i].Waypoints[0][1] = br.ReadInt16(); FlightGroups[i].Waypoints[0][2] = br.ReadInt16(); FlightGroups[i].Yaw = br.ReadInt16(); //Conversion to/from degrees handled in the editor. This helps preserve the exact values used by pilot proving ground platforms. FlightGroups[i].Pitch = br.ReadInt16(); FlightGroups[i].Roll = br.ReadInt16(); } MissionPath = stream.Name; }