protected override bool InnerTo(ConversionContext context) { XvTBriefingBlock xvtBriefingBlock = null; XvTFlightGroupsBlock xvtFlightGroupBlock = null; var isMultiplayer = false; var isBoPMision = true; short[] fgIcons; context.WriteToTargetBuffer(18, true); context.SourceCursor = 2; //short i, j; context.FlightGroupCount = context.ReadSourceInt16(); short Messages = context.ReadSourceInt16(); context.WriteToTarget((short)(FGs + 2)); // [JB] Modified to +2 since generated skirmish files have two backdrops for ambient lighting context.WriteToTarget(Messages); fgIcons = new short[FGs]; context.WriteToTargetBuffer(1, 8); context.WriteToTargetBuffer(1, 11); //unknowns context.WriteToTargetBuffer(Encoding.ASCII.GetBytes("The Final Frontier"), 100); //make a nice Region name :P context.WriteToTargetBuffer(6, 0x23A); //starting hangar context.TargetCursor++; context.SourceCursor = 0x66; context.WriteToTarget(context.ReadByte()); //time limit (minutes) context.WriteToTargetBuffer(0x62, 0x23B3); //unknown context.TargetCursor = 0x23F0; //[JB] Jumping ahead to get the briefing locations before we load in the FGs. xvtBriefingBlock = new XvTBriefingBlock(context.FlightGroupCount, Messages, context); xvtFlightGroupBlock = new XvTFlightGroupsBlock(context.FlightGroupCount, context); //[JB] Now that flight groups are done, check for player count and patch in skirmish mode if (isMultiplayer && PlayerCraft > 1) { long backupPos = streams.TargetStream.Position; streams.TargetStream.Position = 0x23AC; context.WriteToTargetBuffer(4); streams.TargetStream.Position = backupPos; } #region Messages for (var i = 0; i < Messages; i++) { XvTPos = context.SourceCursor; XWAPos = streams.TargetStream.Position; streams.TargetWriter.Write(streams.SourceReader.ReadInt16()); //Message# - 1 switch (streams.SourceStream.ReadByte()) //takes care of colors if needed { case 49: streams.TargetWriter.Write(streams.SourceReader.ReadBytes(63)); //green streams.TargetStream.Position = XWAPos + 142; context.WriteToTargetBuffer(0); break; case 50: streams.TargetWriter.Write(streams.SourceReader.ReadBytes(63)); //blue streams.TargetStream.Position = XWAPos + 142; context.WriteToTargetBuffer(2); break; case 51: streams.TargetWriter.Write(streams.SourceReader.ReadBytes(63));; //yellow streams.TargetStream.Position = XWAPos + 142; context.WriteToTargetBuffer(3); break; default: context.SourceCursor--; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(64)); //red streams.TargetStream.Position = XWAPos + 142; context.WriteToTargetBuffer(1); break; } streams.TargetStream.Position = XWAPos + 82; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(14)); //Sent to.. -> T1 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //T2 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //T1 AND/OR T2 streams.TargetStream.Position++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //T3 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //T4 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //T3 AND/OR T4 streams.TargetStream.Position = XWAPos + 141; context.SourceCursor += 17; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //T (1/2) AND/OR (3/4) streams.TargetStream.Position = XWAPos + 132; //[JB] OriginatingFG context.WriteToTargetBuffer(System.Convert.ToByte(FGs + 1)); //[JB] Set to last FG (+2 inserted backdrops so the last new FG index is FG+1). Assigning messages to backdrops ensures the object is always present so messages always fire. streams.TargetStream.Position = XWAPos + 140; context.SourceCursor = XvTPos + 114; int msgDelaySec = streams.SourceStream.ReadByte() * 5; //[JB] Corrected delay time. context.WriteToTargetBuffer(System.Convert.ToByte(msgDelaySec % 60)); //Delay context.WriteToTargetBuffer(System.Convert.ToByte(msgDelaySec / 60)); streams.TargetStream.Position += 2; context.WriteToTargetBuffer(10); //[JB] Modified offset for second delay byte streams.TargetStream.Position += 5; context.WriteToTargetBuffer(10); //make sure the Cancel triggers are set to FALSE streams.TargetStream.Position = XWAPos + 162; context.SourceCursor = XvTPos + 116; } #endregion #region Global Goals XvTPos = context.SourceCursor; XWAPos = streams.TargetStream.Position; for (int ti = 0; ti < 10; ti++) //[JB] Converting all 10 teams just in case some triggers depend on them. { context.SourceCursor = XvTPos + (0x80 * ti); streams.TargetStream.Position = XWAPos + (0x170 * ti); context.WriteToTargetBuffer(3); context.SourceCursor++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //Prim T1 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT2 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetStream.Position += 2; context.SourceCursor += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //PT 1 AND/OR 2 streams.TargetStream.Position++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT 3 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT 4 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //PT 3 AND/OR 4 context.SourceCursor += 17; streams.TargetStream.Position += 18; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(3)); //PT (1/2) AND/OR (3/4) -> Points streams.TargetStream.Position += 70; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //Prev T1 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT2 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetStream.Position += 2; context.SourceCursor += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //PT 1 AND/OR 2 streams.TargetStream.Position++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT 3 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //PT 4 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //PT 3 AND/OR 4 context.SourceCursor += 17; streams.TargetStream.Position += 18; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(3)); //PT (1/2) AND/OR (3/4) -> Points streams.TargetStream.Position += 70; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //Sec T1 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //ST2 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetStream.Position += 2; context.SourceCursor += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //ST 1 AND/OR 2 streams.TargetStream.Position++; streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //ST 3 ShipFix(streams.SourceStream, streams.TargetStream); streams.TargetWriter.Write(streams.SourceReader.ReadInt32()); //ST 4 ShipFix(streams.SourceStream, streams.TargetStream); context.SourceCursor += 2; streams.TargetStream.Position += 2; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); //ST 3 AND/OR 4 context.SourceCursor += 17; streams.TargetStream.Position += 18; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(3)); //ST (1/2) AND/OR (3/4) -> Points streams.TargetStream.Position += 70; } context.SourceCursor = XvTPos + (0x80 * 10); //10 teams streams.TargetStream.Position = XWAPos + (0x170 * 10); #endregion #region IFF/Teams streams.TargetWriter.Write(streams.SourceReader.ReadBytes(4870)); //well, that was simple.. #endregion #region Briefing XWAPos = streams.TargetStream.Position; long XWABriefing1 = XWAPos; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(6)); //briefing intro streams.TargetWriter.Write((short)(streams.SourceReader.ReadInt16() + 10 * Briefs[0])); // adjust length for add/moves context.SourceCursor += 2; streams.TargetStream.Position += 20 * Briefs[0] + 2; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(0x32A)); //briefing content streams.TargetStream.Position = XWAPos; var briefingLength = (short)(streams.TargetReader.ReadInt16() * 0x19 / 0x14); // adjust overall briefing length streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); streams.TargetStream.Position += 8; for (var i = 0; i < 0x320; i += 4) // work our way through length of briefing. i automatically increases by 4 per event { briefingLength = streams.TargetReader.ReadInt16(); if (briefingLength == 0x270F) { break; // stop check at t=9999, end briefing } briefingLength = (short)(briefingLength * 0x19 / 0x14); streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); briefingLength = streams.TargetReader.ReadInt16(); // now get the event type if (briefingLength > 8 && briefingLength < 17) // FG tags 1-8 { briefingLength = streams.TargetReader.ReadInt16(); // FG number streams.TargetStream.Position -= 2; streams.TargetWriter.Write(fgIcons[briefingLength]); // Overwrite with the Icon# i += 2; } else if (briefingLength == 7) // Zoom map command { briefingLength = (short)(streams.TargetReader.ReadInt16() * 124 / 58); // X streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); briefingLength = (short)(streams.TargetReader.ReadInt16() * 124 / 88); // Y streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); i += 4; } else { streams.TargetStream.Position += 2 * BRF[briefingLength]; // skip over vars i += (short)(2 * BRF[briefingLength]); // increase length counter by skipped vars } } streams.TargetStream.Position = 0x8960 + (context.FlightGroupCount + 2) * 0xE3E + Messages * 0xA2; //[JB] FGs+2 context.WriteToTargetBuffer(1); //show the non-existant briefing streams.TargetStream.Position += 9; #endregion Briefing #region Briefing tags & strings for (var i = 0; i < 32; i++) //tags { briefingLength = streams.SourceReader.ReadInt16(); //check length.. streams.TargetWriter.Write(briefingLength); //..write length.. if (briefingLength != 0) //and copy if not 0 { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(briefingLength)); } } streams.TargetStream.Position += 192; for (var i = 0; i < 32; i++) //strings { briefingLength = streams.SourceReader.ReadInt16(); //check length.. streams.TargetWriter.Write(briefingLength); //..write length.. if (briefingLength != 0) //and copy if not 0 { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(briefingLength)); } } streams.TargetStream.Position += 192; #endregion Briefing T&S #region Briefing2 //[JB] Begin briefing 2. Basically just copy/paste the same code. if (isMultiplayer) { long XWABriefing2 = streams.TargetStream.Position; XWAPos = streams.TargetStream.Position; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(6)); //briefing intro streams.TargetWriter.Write((short)(streams.SourceReader.ReadInt16() + 10 * Briefs[1])); // adjust length for add/moves context.SourceCursor += 2; streams.TargetStream.Position += 20 * Briefs[1] + 2; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(0x32A)); //briefing content streams.TargetStream.Position = XWAPos; briefingLength = (short)(streams.TargetReader.ReadInt16() * 0x19 / 0x14); // adjust overall briefing length streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); streams.TargetStream.Position += 8; for (var i = 0; i < 0x320; i += 4) // work our way through length of briefing. i automatically increases by 4 per event { briefingLength = streams.TargetReader.ReadInt16(); if (briefingLength == 0x270F) { break; // stop check at t=9999, end briefing } briefingLength = (short)(briefingLength * 0x19 / 0x14); streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); briefingLength = streams.TargetReader.ReadInt16(); // now get the event type if (briefingLength > 8 && briefingLength < 17) // FG tags 1-8 { briefingLength = streams.TargetReader.ReadInt16(); // FG number streams.TargetStream.Position -= 2; streams.TargetWriter.Write(fgIcons[briefingLength]); // Overwrite with the Icon# i += 2; } else if (briefingLength == 7) // Zoom map command { briefingLength = (short)(streams.TargetReader.ReadInt16() * 124 / 58); // X streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); briefingLength = (short)(streams.TargetReader.ReadInt16() * 124 / 88); // Y streams.TargetStream.Position -= 2; streams.TargetWriter.Write(briefingLength); i += 4; } else { streams.TargetStream.Position += 2 * BRF[briefingLength]; // skip over vars i += (short)(2 * BRF[briefingLength]); // increase length counter by skipped vars } } streams.TargetStream.Position = 0x8960 + (XWABriefing2 - XWABriefing1) + (FGs + 2) * 0xE3E + Messages * 0xA2; //[JB] FGs+2 context.WriteToTargetBuffer(0); //show the non-existant briefing context.WriteToTargetBuffer(1); //show the non-existant briefing streams.TargetStream.Position += 8; for (var i = 0; i < 32; i++) //tags { briefingLength = streams.SourceReader.ReadInt16(); //check length.. streams.TargetWriter.Write(briefingLength); //..write length.. if (briefingLength != 0) //and copy if not 0 { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(briefingLength)); } } streams.TargetStream.Position += 192; for (var i = 0; i < 32; i++) //strings { briefingLength = streams.SourceReader.ReadInt16(); //check length.. streams.TargetWriter.Write(briefingLength); //..write length.. if (briefingLength != 0) //and copy if not 0 { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(briefingLength)); } } streams.TargetStream.Position += 192; } else { context.SourceCursor += 0x334; //Jump to tags for (briefingLength = 0; briefingLength < 64; briefingLength++) //32 tags + 32 strings { context.SourceCursor += streams.SourceReader.ReadInt16(); } streams.TargetStream.Position += 0x4614; //Empty briefing plus empty tags/strings } #endregion Briefing2 streams.TargetStream.Position += 0x187C; //Skip EditorNotes streams.TargetStream.Position += 0x3200; //Skip BriefingStringNotes streams.TargetStream.Position += 0x1900; //Skip MessageNotes streams.TargetStream.Position += 0xBB8; //Skip EomNotes streams.TargetStream.Position += 0xFA0; //Skip Unknown streams.TargetStream.Position += 0x12C; //Skip DescriptionNotes //[JB] Briefings have variable length. Need to step over the remaining 6 XvT briefings by properly calculating how big they are. for (var i = 2; i < 8; i++) { context.SourceCursor += 0x334; //Jump to tags for (briefingLength = 0; briefingLength < 64; briefingLength++) //32 tags + 32 strings { context.SourceCursor += streams.SourceReader.ReadInt16(); } } #region FG Goal strings for (var i = 0; i < context.FlightGroupCount; i++) { for (briefingLength = 0; briefingLength < 24; briefingLength++) //8 goals * 3 strings { if (streams.SourceStream.ReadByte() == 0) { streams.TargetStream.Position++; context.SourceCursor += 63; } else { context.SourceCursor--; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(64)); } } } streams.TargetStream.Position += 48; //compensate for adding the Backdrop [JB] Was 24 for one backdrop, needs to be 48 since I added an extra one. #endregion #region Global Goal strings for (var i = 0; i < 10; i++) { for (briefingLength = 0; briefingLength < 36; briefingLength++) { if (streams.SourceStream.ReadByte() == 0) { streams.TargetStream.Position++; context.SourceCursor += 63; } else { context.SourceCursor--; streams.TargetWriter.Write(streams.SourceReader.ReadBytes(64)); } } context.SourceCursor += 3072; } #endregion streams.TargetStream.Position += 3552; //skip custom order strings #region Debrief and Descrip if (!isBoPMision) { streams.TargetStream.Position += 4096; context.WriteToTargetBuffer(35); streams.TargetStream.Position += 4095; context.WriteToTargetBuffer(35); for (var i = 0; i < 1024; i++) { int d = streams.SourceStream.ReadByte(); briefingLength = (short)(1024 - i); switch (d) { case -1: i = 1024; break; case 0: i = 1024; break; case 10: context.WriteToTargetBuffer(35); break; default: context.SourceCursor--; streams.TargetWriter.Write(streams.SourceReader.ReadByte()); break; } } streams.TargetStream.Position += 3071 + briefingLength; } else { streams.TargetWriter.Write(streams.SourceReader.ReadBytes(4096)); // Debrief context.WriteToTargetBuffer(35); streams.TargetWriter.Write(streams.SourceReader.ReadBytes(4095)); // Hints context.SourceCursor++; context.WriteToTargetBuffer(35); streams.TargetWriter.Write(streams.SourceReader.ReadBytes(4095)); // Brief/Description } #endregion context.WriteToTargetBuffer(0); //EOF return(true); }
public XvTFlightGroup(long startXvTPosition, long startXwaPosition, ConversionContext context) { Messages = new List<XvTMessage>(); StartXvTPos = startXvTPosition; StartXWAPos = startXwaPosition; FlightGroupName = GetFlightGroupName(context); context.TargetWriter.Write( context.ConversionStreams.SourceReader.ReadBytes(20)); //name byte[] d1 = new byte[2]; byte[] d2 = new byte[2]; byte[] buffer = new byte[4]; byte[] flightGroupDesignationBytes = new byte[8]; context.SourceStream.Read(flightGroupDesignationBytes, 0, 8); FlightGroupDesignation = new XvTFlightGroupDesignation(flightGroupDesignationBytes); XwaFlightGroupDesignation = FlightGroupDesignation.ToXWingAllianceDesignationBytes(); context.WriteToTargetBuffer(XwaFlightGroupDesignation[0]); context.WriteToTargetBuffer(XwaFlightGroupDesignation[1]); context.WriteToTargetBuffer(XwaFlightGroupDesignation[2]); context.WriteToTargetBuffer(XwaFlightGroupDesignation[3]); context.SourceCursor -= 8; context.TargetStream.Position++; //Skip unknown context.WriteToTargetBuffer(255); //Global cargos set to none context.WriteToTargetBuffer(255); context.TargetStream.Position = StartXWAPos + 40; context.SourceCursor += 20; context.TargetWriter.Write(context.ReadBytes(40)); //Cargo & Special context.TargetStream.Position = StartXWAPos + 0x69; context.TargetWriter.Write(context.ReadBytes(30)); //SC ship# -> Arrival Difficulty context.SourceCursor = StartXWAPos + 0x64; // [JB] Modified if (!context.IsMultiplayerMission) { if (context.ReadByte() != 0 && Player == false) { Player = true; } //check for multiple player craft, take the first one else { context.TargetCursor = StartXvTPos + 0x7D; context.WriteToTargetBuffer(0); } } if (context.ReadByte() != 0) { PlayerCraft++; } context.TargetStream.Position = StartXWAPos + 0x88; context.SourceCursor = StartXvTPos + 0x6E; context.TargetWriter.Write(context.ReadSourceInt32()); //Arival trigger 1 (cheating and using Int32 since it's 4 bytes)... ShipFix(context.SourceStream, context.TargetStream); context.TargetWriter.Write(context.ReadSourceInt32()); //... and 2 ShipFix(context.SourceStream, context.TargetStream); context.TargetStream.Position += 2; context.SourceCursor += 2; context.TargetWriter.Write(context.ReadByte()); //AT 1 AND/OR 2 context.TargetStream.Position++; context.TargetWriter.Write(context.ReadSourceInt32()); //AT 3 ShipFix(context.SourceStream, context.TargetStream); context.TargetWriter.Write(context.ReadSourceInt32()); //AT 4 ShipFix(context.SourceStream, context.TargetStream); context.TargetStream.Position += 2; context.SourceCursor += 2; context.TargetWriter.Write(context.ReadByte()); //AT 3 AND/OR 4 context.TargetStream.Position++; context.TargetWriter.Write(context.ReadSourceInt64()); //AT 1/2 AND/OR 3/4 -> DT (8 bytes) ShipFix(context.SourceStream, context.TargetStream); context.TargetWriter.Write(context.ReadSourceInt32()); //DT 2 ShipFix(context.SourceStream, context.TargetStream); context.TargetStream.Position += 2; context.SourceCursor += 2; context.TargetWriter.Write(context.ReadByte()); //DT 1 AND/OR 2 context.TargetStream.Position += 3; context.SourceCursor += 2; context.TargetWriter.Write(context.ReadByte()); //Abort trigger context.SourceCursor += 4; context.TargetStream.Position += 3; context.TargetWriter.Write(context.ReadSourceInt64()); //Arr/Dep methods long XvTOrderStart = context.SourceCursor; long XWAOrderStart = context.TargetStream.Position; long XvTSubOrderStart = context.SourceCursor; //[JB] ShipOFix modifies the offsets and I assume it's bad to add anything so I'm going to let the original code run then rewind to these offsets later to apply my patches. long XWASubOrderStart = context.TargetStream.Position; context.TargetWriter.Write(context.ReadBytes(18)); //Order 1 ShipOrderFix(context.SourceStream, context.TargetStream); context.SourceCursor = StartXvTPos + 0x46E; for (var j = 0; j < 8; j++) { context.TargetWriter.Write(context.ReadSourceInt16()); //WP X context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP Y context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP Z context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP enabled context.SourceCursor -= 0x84; } //[JB] Patch wait times context.SourceCursor = XvTSubOrderStart; context.TargetStream.Position = XWASubOrderStart; ConvertOrderTime(context.SourceStream, context.TargetStream); //Copy order speed context.SourceCursor = XvTSubOrderStart + 18; context.TargetStream.Position = XWASubOrderStart + 18; context.TargetWriter.Write(context.ReadByte()); //After XvT speed comes flight group player designation, load it to patch the role later. byte[] role = new byte[16]; context.SourceStream.Read(role, 0, 16); context.TargetStream.Position = StartXWAPos + 0x50; //Patch in the display role for the player FG slot screen. context.TargetStream.Write(role, 0, 16); //[JB] End patch code. context.TargetStream.Position = StartXWAPos + 0x15E; context.SourceCursor = StartXvTPos + 0xF4; XvTSubOrderStart = context.SourceCursor; //[JB] ShipOFix modifies the offsets and I assume it's bad to add anything so I'm going to let the original code run then rewind to these offsets later to apply my patches. XWASubOrderStart = context.TargetStream.Position; context.TargetWriter.Write(context.ReadBytes(18)); //Order 2 ShipOrderFix(context.SourceStream, context.TargetStream); context.SourceCursor = StartXvTPos + 0x46E; for (var j = 0; j < 8; j++) { context.TargetWriter.Write(context.ReadSourceInt16()); //WP X context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP Y context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP Z context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP enabled context.SourceCursor -= 0x84; } //[JB] Patch wait times context.SourceCursor = XvTSubOrderStart; context.TargetStream.Position = XWASubOrderStart; ConvertOrderTime(context.SourceStream, context.TargetStream); //Copy order speed context.SourceCursor = XvTSubOrderStart + 18; context.TargetStream.Position = XWASubOrderStart + 18; context.TargetWriter.Write(context.ReadByte()); //[JB] End patch code. context.TargetStream.Position = StartXWAPos + 0x1F2; context.SourceCursor = StartXvTPos + 0x146; XvTSubOrderStart = context.SourceCursor; //[JB] ShipOFix modifies the offsets and I assume it's bad to add anything so I'm going to let the original code run then rewind to these offsets later to apply my patches. XWASubOrderStart = context.TargetStream.Position; context.TargetWriter.Write(context.ReadBytes(18)); //Order 3 ShipOrderFix(context.SourceStream, context.TargetStream); context.SourceCursor = StartXvTPos + 0x46E; for (var j = 0; j < 8; j++) { context.TargetWriter.Write(context.ReadSourceInt16()); //WP X context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP Y context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP Z context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP enabled context.SourceCursor -= 0x84; } //[JB] Patch wait times context.SourceCursor = XvTSubOrderStart; context.TargetStream.Position = XWASubOrderStart; ConvertOrderTime(context.SourceStream, context.TargetStream); //Copy order speed context.SourceCursor = XvTSubOrderStart + 18; context.TargetStream.Position = XWASubOrderStart + 18; context.TargetWriter.Write(context.ReadByte()); //[JB] End patch code. context.TargetStream.Position = StartXWAPos + 0x286; context.SourceCursor = StartXvTPos + 0x198; XvTSubOrderStart = context.SourceCursor; //[JB] ShipOFix modifies the offsets and I assume it's bad to add anything so I'm going to let the original code run then rewind to these offsets later to apply my patches. XWASubOrderStart = context.TargetStream.Position; context.TargetWriter.Write(context.ReadBytes(18)); //Order 4 ShipOrderFix(context.SourceStream, context.TargetStream); context.SourceCursor = StartXvTPos + 0x46E; for (var j = 0; j < 8; j++) { context.TargetWriter.Write(context.ReadSourceInt16()); //WP X context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP Y context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP Z context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //WP enabled context.SourceCursor -= 0x84; } //[JB] Patch wait times context.SourceCursor = XvTSubOrderStart; context.TargetStream.Position = XWASubOrderStart; ConvertOrderTime(context.SourceStream, context.TargetStream); //Copy order speed context.SourceCursor = XvTSubOrderStart + 18; context.TargetStream.Position = XWASubOrderStart + 18; context.TargetWriter.Write(context.ReadByte()); //[JB] End patch code. context.SourceCursor = StartXvTPos + 0x1EA; context.TargetStream.Position = StartXWAPos + 0xA3A; context.TargetWriter.Write(context.ReadSourceInt32()); //jump to Order 4 T1 ShipFix(context.SourceStream, context.TargetStream); context.TargetWriter.Write(context.ReadSourceInt32()); //jump to Order 4 T2 ShipFix(context.SourceStream, context.TargetStream); context.TargetStream.Position += 2; context.SourceCursor += 2; context.TargetWriter.Write(context.ReadByte()); //jump to Order 4 T 1AND/OR 2 context.TargetStream.Position = StartXWAPos + 0xB0A; context.SourceCursor = StartXvTPos + 0x1F5; for (var j = 0; j < 8; j++) { context.TargetWriter.Write(context.ReadBytes(14)); //Goals context.SourceCursor += 0x40; context.TargetStream.Position += 0x42; } context.SourceCursor = StartXvTPos + 0x466; context.TargetStream.Position = StartXWAPos + 0xD8A; for (var j = 0; j < 3; j++) { context.TargetWriter.Write(context.ReadSourceInt16()); //SP X context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //SP Y context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //SP Z context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //SP enabled context.SourceCursor -= 0x84; } context.SourceCursor = StartXvTPos + 0x480; context.TargetWriter.Write(context.ReadSourceInt16()); //HYP X context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //HYP Y context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //HYP Z context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //HYP enabled context.SourceCursor = StartXvTPos + 0x506; if (context.SourceStream.ReadByte() == 1) //okay, briefing time. if BP enabled.. { //[JB] 0x23F0 (fileheader) + 0xE60 (GlobalGoal[10]) + 0x1306 (Team[10]) = 0x4556 (17750 dec) context.TargetStream.Position = 17762 + (context.FlightGroupCount + 2) * 3646 + Messages * 162 + Briefs[0] * 20; //place for next insert command [JB] Modified to FGs+2 context.WriteToTargetBuffer(26); context.TargetStream.Position++; context.TargetWriter.Write(Briefs[0]); //Add command fgIcons[i] = Briefs[0]; // store the Icon# for the FG context.SourceCursor = StartXvTPos + 0x52; context.TargetWriter.Write(context.ReadByte()); context.TargetStream.Position++; //Ship context.SourceCursor = StartXvTPos + 0x57; context.TargetWriter.Write(context.ReadByte()); context.TargetStream.Position += 3; //IFF context.SourceCursor = StartXvTPos + 0x482; context.WriteToTargetBuffer(28); context.TargetStream.Position++; context.TargetWriter.Write(Briefs[0]); //Move command context.TargetWriter.Write(context.ReadSourceInt16()); //BP X context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //BP Y Briefs[0]++; } if (context.IsMultiplayerMission) { context.SourceCursor = StartXvTPos + 0x508; if (context.SourceStream.ReadByte() == 1) //okay, briefing time. if BP enabled.. { //[JB] 0x23F0 (fileheader) + 0xE60 (GlobalGoal[10]) + 0x1306 (Team[10]) = 0x4556 (17750 dec) context.TargetStream.Position = 17750 + (context.FlightGroupCount + 2) * 3646 + Messages * 162 + Briefs[1] * 20; //place for next insert command [JB] Modified to FGs+2 context.TargetStream.Position += 0x4414 + brief1StringSize + 384 + 0x000A + 2; //briefing(minus strings) + XvT string list size + 192 shorts for empty messages in XWA + start of Brief2 event list context.WriteToTargetBuffer(26); context.TargetStream.Position++; context.TargetWriter.Write(Briefs[1]); //Add command fgIcons[i] = Briefs[1]; // store the Icon# for the FG context.SourceCursor = StartXvTPos + 0x52; context.TargetWriter.Write(context.ReadByte()); context.TargetStream.Position++; //Ship context.SourceCursor = StartXvTPos + 0x57; context.TargetWriter.Write(context.ReadByte()); context.TargetStream.Position += 3; //IFF context.SourceCursor = StartXvTPos + 0x484; //Offset for BP2 context.WriteToTargetBuffer(28); context.TargetStream.Position++; context.TargetWriter.Write(Briefs[1]); //Move command context.TargetWriter.Write(context.ReadSourceInt16()); //BP X context.SourceCursor += 0x2A; context.TargetWriter.Write(context.ReadSourceInt16()); //BP Y Briefs[1]++; } } context.TargetStream.Position = StartXWAPos + 0xDC7; context.SourceCursor = StartXvTPos + 0x523; context.TargetWriter.Write(context.ReadSourceInt32()); //CM -> Global Unit context.TargetStream.Position++; context.SourceCursor += 9; context.TargetWriter.Write(context.ReadBytes(48)); //Optionals context.SourceCursor = StartXvTPos + 0x562; context.TargetStream.Position = StartXWAPos + 0xE3E; }