public byte[] SaveToBytes() { SortEntries(); List <byte> bytes = new List <byte>(); //Header bytes.AddRange(BitConverter.GetBytes(CNS_SIGNATURE)); //0 bytes.AddRange(BitConverter.GetBytes((UInt16)65534)); //4 bytes.AddRange(BitConverter.GetBytes(Version)); //6 bytes.AddRange(BitConverter.GetBytes(CnsEntries.Count)); //8 bytes.AddRange(BitConverter.GetBytes(20)); //12 bytes.AddRange(BitConverter.GetBytes(28)); //16 //Unknown values Assertion.AssertArraySize(UnknownValues, 4, "CNS", "UnknownValues"); bytes.AddRange(BitConverter_Ex.GetBytes(UnknownValues)); //Entries for (int i = 0; i < CnsEntries.Count; i++) { bytes.AddRange(CNS_Entry.Write(CnsEntries[i])); } return(bytes.ToArray()); }
public static List <byte> Write(CNS_Entry cnsEntry) { List <byte> bytes = new List <byte>(); //Code if (cnsEntry.Str_00.Length > 8) { throw new Exception(String.Format("Dual_Code = {0} exceeds the maximum allowed length of 8. Load failed.", cnsEntry.Str_00)); } bytes.AddRange(Encoding.ASCII.GetBytes(cnsEntry.Str_00)); bytes.AddRange(new byte[8 - cnsEntry.Str_00.Length]); //Validate arrays Assertion.AssertArraySize(cnsEntry.I_10, 33, "CnsEntry", "I_10"); Assertion.AssertArraySize(cnsEntry.I_76, 33, "CnsEntry", "I_76"); Assertion.AssertArraySize(cnsEntry.I_146, 7, "CnsEntry", "I_146"); Assertion.AssertArraySize(cnsEntry.I_162, 7, "CnsEntry", "I_162"); //Remaining values bytes.AddRange(BitConverter.GetBytes(ushort.Parse(cnsEntry.Index))); bytes.AddRange(BitConverter_Ex.GetBytes(cnsEntry.I_10)); bytes.AddRange(BitConverter_Ex.GetBytes(cnsEntry.I_76)); bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_142)); bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_144)); bytes.AddRange(BitConverter_Ex.GetBytes(cnsEntry.I_146)); bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_160)); bytes.AddRange(BitConverter_Ex.GetBytes(cnsEntry.I_162)); bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_176)); bytes.AddRange(BitConverter.GetBytes(cnsEntry.I_178)); return(bytes); }
private void WriteEffect(IBD_Effect effect) { bytes.AddRange(BitConverter.GetBytes(effect.I_00)); bytes.AddRange(BitConverter.GetBytes(effect.I_04)); bytes.AddRange(BitConverter.GetBytes(effect.I_08)); bytes.AddRange(BitConverter.GetBytes(effect.F_12)); Assertion.AssertArraySize(effect.F_16, 6, "Effect", "Ability_Values"); bytes.AddRange(BitConverter_Ex.GetBytes(effect.F_16)); bytes.AddRange(BitConverter.GetBytes(effect.I_40)); bytes.AddRange(BitConverter.GetBytes(effect.I_44)); Assertion.AssertArraySize(effect.F_48, 6, "Effect", "Multipliers"); bytes.AddRange(BitConverter_Ex.GetBytes(effect.F_48)); Assertion.AssertArraySize(effect.I_72, 6, "Effect", "I_72"); bytes.AddRange(BitConverter_Ex.GetBytes(effect.I_72)); bytes.AddRange(BitConverter.GetBytes(effect.F_96)); bytes.AddRange(BitConverter.GetBytes(effect.F_100)); bytes.AddRange(BitConverter.GetBytes(effect.F_104)); bytes.AddRange(BitConverter.GetBytes(effect.F_108)); bytes.AddRange(BitConverter.GetBytes(effect.F_112)); bytes.AddRange(BitConverter.GetBytes(effect.F_116)); bytes.AddRange(BitConverter.GetBytes(effect.F_120)); bytes.AddRange(BitConverter.GetBytes(effect.F_124)); bytes.AddRange(BitConverter.GetBytes(effect.F_128)); bytes.AddRange(BitConverter.GetBytes(effect.F_132)); bytes.AddRange(BitConverter.GetBytes(effect.F_136)); bytes.AddRange(BitConverter.GetBytes(effect.F_140)); bytes.AddRange(BitConverter.GetBytes(effect.F_144)); bytes.AddRange(BitConverter.GetBytes(effect.F_148)); bytes.AddRange(BitConverter.GetBytes(effect.F_152)); Assertion.AssertArraySize(effect.F_156, 17, "Effect", "F_156"); bytes.AddRange(BitConverter_Ex.GetBytes(effect.F_156)); }
public List <byte> Write() { List <byte> bytes = new List <byte>(); bytes.AddRange(BitConverter_Ex.GetBytes(Indexes.ToArray())); if (bytes.Count != FPF_File.UnknownIndexListCount * 4) { throw new InvalidDataException("UnknownIndexes is an invalid size."); } return(bytes); }
public List <byte> Write() { if (Values.Length != 4) { throw new InvalidDataException("UnkSkeletonData > Values must have 4 values."); } List <byte> bytes = new List <byte>(); bytes.AddRange(BitConverter_Ex.GetBytes(Values)); return(bytes); }
private void WriteUnk3(List <Unk3> unk3, int offsetToFill, int relativeOffset) { if (unk3 != null) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - relativeOffset), offsetToFill); for (int i = 0; i < unk3.Count(); i++) { Assertion.AssertArraySize(unk3[i].I_00, 6, "Unk3", "values"); bytes.AddRange(BitConverter_Ex.GetBytes(unk3[i].I_00)); } } }
private void WriteSkeleton(ESK_Skeleton skeleton, int offsetToReplace) { List <ESK_BoneNonHierarchal> bones = eskFile.Skeleton.GetNonHierarchalBoneList(); bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), offsetToReplace); int startOffset = bytes.Count(); int count = (bones != null) ? bones.Count() : 0; bytes.AddRange(BitConverter.GetBytes((short)count)); bytes.AddRange(BitConverter.GetBytes(skeleton.I_02)); bytes.AddRange(new byte[24]); bytes.AddRange(BitConverter_Ex.GetBytes(skeleton.I_28)); if (count > 0) { //Writing Index List bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 4); for (int i = 0; i < count; i++) { bytes.AddRange(BitConverter.GetBytes(bones[i].Index1)); bytes.AddRange(BitConverter.GetBytes(bones[i].Index2)); bytes.AddRange(BitConverter.GetBytes(bones[i].Index3)); bytes.AddRange(BitConverter.GetBytes(bones[i].Index4)); } //Writing Name Table and List bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 8); List <StringWriter.StringInfo> stringInfo = new List <StringWriter.StringInfo>(); for (int i = 0; i < count; i++) { stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = bones[i].Name, Offset = bytes.Count(), RelativeOffset = startOffset }); bytes.AddRange(new byte[4]); } for (int i = 0; i < count; i++) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - stringInfo[i].RelativeOffset), stringInfo[i].Offset); bytes.AddRange(Encoding.ASCII.GetBytes(stringInfo[i].StringToWrite)); bytes.Add(0); } //Writing RelativeTransform StartNewLine(); bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 12); for (int i = 0; i < count; i++) { bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_00)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_04)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_08)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_12)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_16)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_20)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_24)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_28)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_32)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_36)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_40)); bytes.AddRange(BitConverter.GetBytes(bones[i].RelativeTransform.F_44)); } //Writing AbsoluteTransform (esk only) StartNewLine(); bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 16); for (int i = 0; i < count; i++) { bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_00)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_04)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_08)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_12)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_16)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_20)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_24)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_28)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_32)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_36)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_40)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_44)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_48)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_52)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_56)); bytes.AddRange(BitConverter.GetBytes(bones[i].AbsoluteTransform.F_60)); } //Writing Unk1 if (skeleton.Unk1 != null) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 20); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_00)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_04)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_08)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_12)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_16)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_20)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_24)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_28)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_32)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_36)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_40)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_44)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_48)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_52)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_56)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_60)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_64)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_68)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_72)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_76)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_80)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_84)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_88)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_92)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_96)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_100)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_104)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_108)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_112)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_116)); bytes.AddRange(BitConverter.GetBytes(skeleton.Unk1.I_120)); } //Writing Unk2 if (skeleton.UseUnk2 == true && count > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - startOffset), startOffset + 24); for (int i = 0; i < count; i++) { bytes.AddRange(BitConverter.GetBytes(281470681743360)); } } } }
private void WriteFile() { //Section 1 bytes.Add(1); for (int i = 0; i < tsd_File.Triggers.Count(); i++) { bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Triggers[i].Index))); bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_04)); bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_08)); bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_12)); bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Triggers[i].I_16))); bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_20)); bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Triggers[i].I_24))); bytes.AddRange(BitConverter.GetBytes(tsd_File.Triggers[i].I_28)); bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Triggers[i].Condition))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Triggers[i].Condition)); } //Section 2 bytes.AddRange(BitConverter.GetBytes(magicNumber)); bytes.Add(2); for (int i = 0; i < tsd_File.Events.Count(); i++) { bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Events[i].Index))); bytes.AddRange(BitConverter.GetBytes(tsd_File.Events[i].I_04)); bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Events[i].Str1))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Events[i].Str1)); bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Events[i].Str2))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Events[i].Str2)); bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Events[i].Str3))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Events[i].Str3)); bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Events[i].Str4))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Events[i].Str4)); string args = tsd_File.Events[i].Arguments.Write(); bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(args))); bytes.AddRange(Encoding.UTF8.GetBytes(args)); bytes.AddRange(BitConverter.GetBytes(tsd_File.Events[i].TNL_IDs.Count())); List <int> tnlIds = ArrayConvert.ConvertToInt32List(tsd_File.Events[i].TNL_IDs); bytes.AddRange(BitConverter_Ex.GetBytes(tnlIds.ToArray())); } //Section 3 bytes.AddRange(BitConverter.GetBytes(magicNumber)); bytes.Add(3); for (int i = 0; i < tsd_File.Globals.Count(); i++) { bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Globals[i].Index))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Globals[i].Index)); bytes.AddRange(BitConverter.GetBytes(tsd_File.Globals[i].Type)); bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Globals[i].Str))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Globals[i].Str)); } //Section 4 bytes.AddRange(BitConverter.GetBytes(magicNumber)); bytes.Add(4); for (int i = 0; i < tsd_File.Constants.Count(); i++) { bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Constants[i].Index))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Constants[i].Index)); bytes.AddRange(BitConverter.GetBytes(tsd_File.Constants[i].Type)); bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Constants[i].Str))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Constants[i].Str)); } //Section 5 bytes.AddRange(BitConverter.GetBytes(magicNumber)); bytes.Add(5); for (int i = 0; i < tsd_File.Zones.Count(); i++) { bytes.AddRange(BitConverter.GetBytes(int.Parse(tsd_File.Zones[i].Index))); bytes.AddRange(BitConverter.GetBytes(tsd_File.Zones[i].I_04)); bytes.AddRange(BitConverter.GetBytes(Encoding.UTF8.GetByteCount(tsd_File.Zones[i].Str))); bytes.AddRange(Encoding.UTF8.GetBytes(tsd_File.Zones[i].Str)); } }
private void WriteDem() { //init int unkValueCount = (demFile.DEM_UnkValues != null) ? demFile.DEM_UnkValues.Count : 0; int section2Count = (demFile.Section2Entries != null) ? demFile.Section2Entries.Count : 0; int actorCount = (demFile.Settings.Characters != null) ? demFile.Settings.Characters.Count : 0; int charaOffsetPos = 0; //Header bytes.AddRange(BitConverter.GetBytes(DEM_File.DEM_SIGNATURE)); //Signature bytes.AddRange(BitConverter.GetBytes((ushort)65534)); //Endianess bytes.AddRange(BitConverter.GetBytes((ushort)64)); //Header size bytes.AddRange(BitConverter.GetBytes(demFile.I_08)); //Version? bytes.AddRange(BitConverter.GetBytes(section2Count)); //Count bytes.AddRange(BitConverter.GetBytes(unkValueCount)); //UnkValues Count bytes.AddRange(new byte[12]); //Padding bytes.AddRange(BitConverter.GetBytes((UInt64)64)); //Offset to name bytes.AddRange(BitConverter.GetBytes((UInt64)0)); //Offset to Section 2 (fill in later) bytes.AddRange(BitConverter.GetBytes((UInt64)80)); //Offset to DemoSettings bytes.AddRange(BitConverter.GetBytes((UInt64)0)); //File size (fill in later) //Name Assertion.AssertStringSize(demFile.Name, 16, "DEM", "Name"); bytes.AddRange(Utils.GetStringBytes(demFile.Name, 16)); //DemoSettings stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_00, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //0 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_08, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //8 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_16, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //16 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_24, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //24 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_32, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //32 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_40, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //40 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_48, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //48 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_56, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //56 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_64, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //64 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_72, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //72 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_80, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //80 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_88, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //88 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_96, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //96 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Str_104, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[12]); //104 bytes.AddRange(BitConverter.GetBytes(actorCount)); charaOffsetPos = bytes.Count; bytes.AddRange(BitConverter.GetBytes(208)); //Offset to actors, fill in later bytes.AddRange(new byte[4]); //Actors/charactors if (actorCount > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), charaOffsetPos); for (int i = 0; i < actorCount; i++) { stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Characters[i].Str_00, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[8]); //0 bytes.AddRange(BitConverter.GetBytes(demFile.Settings.Characters[i].I_08)); //8 bytes.AddRange(new byte[4]); //12 stringInfo.Add(new StringWriter.StringInfo() { StringToWrite = demFile.Settings.Characters[i].Str_16, Offset = bytes.Count, RelativeOffset = 0 }); bytes.AddRange(new byte[48]); //16 } } //Pad the file (it must be in 16-byte blocks before string section starts) FilePad(); //Write strings bytes = StringWriter.WritePointerStrings(stringInfo, bytes); //Pad the file (it must be in 16-byte blocks before Section2 starts) bytes.Add(0); FilePad(); //Section2 bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), 40); //Filling in header offset List <int> section2Offsets = new List <int>(); //Section2 main entries for (int i = 0; i < section2Count; i++) { bytes.AddRange(BitConverter.GetBytes(demFile.Section2Entries[i].I_00)); bytes.AddRange(BitConverter.GetBytes((demFile.Section2Entries[i].SubEntries != null) ? demFile.Section2Entries[i].SubEntries.Count : 0)); section2Offsets.Add(bytes.Count); bytes.AddRange(new byte[24]); } //Section2 subentries for (int i = 0; i < section2Count; i++) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), section2Offsets[i]); int subEntryCount = (demFile.Section2Entries[i].SubEntries != null) ? demFile.Section2Entries[i].SubEntries.Count : 0; demFile.Section2Entries[i].SubEntries = demFile.Section2Entries[i].SubEntries.OrderBy(o => o.I_00).ToList(); for (int a = 0; a < subEntryCount; a++) { bytes.AddRange(BitConverter.GetBytes(demFile.Section2Entries[i].SubEntries[a].I_00)); //Type int[] type = demFile.Section2Entries[i].SubEntries[a].GetDemoType(); bytes.AddRange(BitConverter.GetBytes((ushort)type[0])); //Type1 bytes.AddRange(BitConverter.GetBytes((ushort)type[1])); //Type2 bytes.AddRange(new byte[4]); //Padding demFile.Section2Entries[i].SubEntries[a].ValueCount = type[2]; bytes.AddRange(BitConverter.GetBytes(type[2])); //Count demFile.Section2Entries[i].SubEntries[a].PointerOffset = bytes.Count; bytes.AddRange(new byte[16]); //Offset and padding } } //Types (pointer list) for (int i = 0; i < section2Count; i++) { int subEntryCount = (demFile.Section2Entries[i].SubEntries != null) ? demFile.Section2Entries[i].SubEntries.Count : 0; for (int a = 0; a < subEntryCount; a++) { if (demFile.Section2Entries[i].SubEntries[a].ValueCount > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), demFile.Section2Entries[i].SubEntries[a].PointerOffset); } for (int z = 0; z < demFile.Section2Entries[i].SubEntries[a].ValueCount; z++) { demFile.Section2Entries[i].SubEntries[a].ValueOffsets.Add(bytes.Count); bytes.AddRange(new byte[8]); } } } //Types (values) for (int i = 0; i < section2Count; i++) { int subEntryCount = (demFile.Section2Entries[i].SubEntries != null) ? demFile.Section2Entries[i].SubEntries.Count : 0; for (int a = 0; a < subEntryCount; a++) { DEM_Type.DemoDataTypes type = demFile.Section2Entries[i].SubEntries[a].GetDemoDataType(); switch (type) { case DEM_Type.DemoDataTypes.Type0_1_6: bytes = demFile.Section2Entries[i].SubEntries[a].Type0_1_6.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.FadeInOut: bytes = demFile.Section2Entries[i].SubEntries[a].Type0_2_7.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type0_3_8: bytes = demFile.Section2Entries[i].SubEntries[a].Type0_3_8.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type0_16_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type0_16_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type0_19_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type0_19_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type0_20_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type0_20_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type0_21_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type0_21_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_1_5: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_1_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_1_9: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_1_9.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_2_3: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_2_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_2_5: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_2_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Transformation: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_4_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_6_4: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_6_4.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_7_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_7_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_8_6: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_8_6.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_11_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_11_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_12_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_12_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_13_10: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_13_10.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_14_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_14_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_16_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_16_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_20_12: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_20_12.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_26_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_26_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_27_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_27_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.AnimationSmall: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_0_9.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Animation: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_0_10.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.ActorVisibility: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_3_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.ActorDamage: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_9_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_10_8: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_10_8.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_17_6: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_17_6.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type1_19_3: bytes = demFile.Section2Entries[i].SubEntries[a].Type1_19_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type2_6_3: bytes = demFile.Section2Entries[i].SubEntries[a].Type2_6_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type2_7_5: bytes = demFile.Section2Entries[i].SubEntries[a].Type2_7_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type2_9_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type2_9_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type2_10_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type2_10_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type2_11_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type2_11_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type3_0_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type3_0_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type3_1_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type3_1_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Camera: bytes = demFile.Section2Entries[i].SubEntries[a].Type2_0_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type2_7_8: bytes = demFile.Section2Entries[i].SubEntries[a].Type2_7_8.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type3_2_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type3_2_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type3_3_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type3_3_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type3_4_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type3_4_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Effect: bytes = demFile.Section2Entries[i].SubEntries[a].Type4_0_12.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.ScreenEffect: bytes = demFile.Section2Entries[i].SubEntries[a].Type4_1_8.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type4_2_3: bytes = demFile.Section2Entries[i].SubEntries[a].Type4_2_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type4_3_5: bytes = demFile.Section2Entries[i].SubEntries[a].Type4_3_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type4_4_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type4_4_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Sound: bytes = demFile.Section2Entries[i].SubEntries[a].Type5_0_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Music: bytes = demFile.Section2Entries[i].SubEntries[a].Type5_2_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type5_0_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type5_0_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type5_1_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type5_1_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type5_3_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type5_3_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type5_4_3: bytes = demFile.Section2Entries[i].SubEntries[a].Type5_4_3.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type6_0_1: bytes = demFile.Section2Entries[i].SubEntries[a].Type6_0_1.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.DistanceFocus: bytes = demFile.Section2Entries[i].SubEntries[a].Type6_16_6.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.SpmControl: bytes = demFile.Section2Entries[i].SubEntries[a].Type6_17_19.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type6_18_7: bytes = demFile.Section2Entries[i].SubEntries[a].Type6_18_7.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type6_19_15: bytes = demFile.Section2Entries[i].SubEntries[a].Type6_19_15.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type6_20_2: bytes = demFile.Section2Entries[i].SubEntries[a].Type6_20_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type7_0_5: bytes = demFile.Section2Entries[i].SubEntries[a].Type7_0_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.YearDisplay: bytes = demFile.Section2Entries[i].SubEntries[a].Type9_0_2.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type9_1_5: bytes = demFile.Section2Entries[i].SubEntries[a].Type9_1_5.Write(bytes, demFile.Section2Entries[i].SubEntries[a].ValueOffsets); break; case DEM_Type.DemoDataTypes.Type0_16_0: case DEM_Type.DemoDataTypes.Type0_17_0: case DEM_Type.DemoDataTypes.Type9_8_0: //No values break; default: throw new Exception(String.Format("Unrecognized DEM_Type: {0}", type)); } } } //Pad file before UnkValues bytes.Add(0); FilePad(); bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), 56); //UnkValues for (int i = 0; i < unkValueCount; i++) { Assertion.AssertArraySize(demFile.DEM_UnkValues[i].Values, 40, "DEM_UnknownValues", "uint16s"); bytes.AddRange(BitConverter_Ex.GetBytes(demFile.DEM_UnkValues[i].Values)); } }
private void Write() { //Header int I_18 = (bcsFile.SkeletonData2 != null) ? 1 : 0; byte[] _i_44 = { bcsFile.Race, Convert.ToByte(bcsFile.Sex), 0, 0 }; bytes.AddRange(BitConverter.GetBytes((short)PartSetCount)); bytes.AddRange(BitConverter.GetBytes((short)PartColorCount)); bytes.AddRange(BitConverter.GetBytes((short)BodyCount)); bytes.AddRange(BitConverter.GetBytes((short)I_18)); bytes.AddRange(new byte[24]); bytes.AddRange(_i_44); Assertion.AssertArraySize(bcsFile.F_48, 7, "BCS", "F_48"); bytes.AddRange(BitConverter_Ex.GetBytes(bcsFile.F_48)); //PartSet Table if (bcsFile.PartSets != null) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 24); for (int i = 0; i < PartSetCount; i++) { for (int a = 0; a < bcsFile.PartSets.Count; a++) { if (int.Parse(bcsFile.PartSets[a].Index) == i) { PartSetTable.Add(bytes.Count()); bytes.AddRange(new byte[4]); break; } else if (a == bcsFile.PartSets.Count() - 1) { //Null entry bytes.AddRange(new byte[4]); break; } } } } //PartColor Table if (bcsFile.Part_Colors != null) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 28); for (int i = 0; i < PartColorCount; i++) { for (int a = 0; a < bcsFile.Part_Colors.Count(); a++) { if (int.Parse(bcsFile.Part_Colors[a].Index) == i) { PartColorTable.Add(bytes.Count()); bytes.AddRange(new byte[4]); break; } else if (a == bcsFile.Part_Colors.Count() - 1) { //Null entry bytes.AddRange(new byte[4]); break; } } } } //Body Table if (bcsFile.Bodies != null) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 32); for (int i = 0; i < BodyCount; i++) { for (int a = 0; a < bcsFile.Bodies.Count(); a++) { if (int.Parse(bcsFile.Bodies[a].Index) == i) { BodyTable.Add(bytes.Count()); bytes.AddRange(new byte[4]); break; } else if (a == bcsFile.Bodies.Count() - 1) { //Null entry bytes.AddRange(new byte[4]); break; } } } } //Skeleton1 Table if (bcsFile.SkeletonData1 != null) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 40); Skeleton1Table = bytes.Count(); bytes.AddRange(new byte[4]); } //Skeleton2 Table if (bcsFile.SkeletonData2 != null) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 36); Skeleton2Table = bytes.Count(); bytes.AddRange(new byte[4]); } //PartSets if (bcsFile.PartSets != null) { for (int i = 0; i < bcsFile.PartSets.Count(); i++) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), PartSetTable[i]); int PartSetStart = bytes.Count(); bytes.AddRange(new byte[20]); bytes.AddRange(BitConverter.GetBytes(10)); bytes.AddRange(BitConverter.GetBytes(32)); bytes.AddRange(new byte[4]); int[] PartSetSubTable = new int[10] { bytes.Count() + 0, bytes.Count() + 4, bytes.Count() + 8, bytes.Count() + 12, bytes.Count() + 16, bytes.Count() + 20, bytes.Count() + 24, bytes.Count() + 28, bytes.Count() + 32, bytes.Count() + 36 }; bytes.AddRange(new byte[40]); //Parts WritePart(bcsFile.PartSets[i].FaceBase, PartSetSubTable[0], PartSetStart); WritePart(bcsFile.PartSets[i].FaceForehead, PartSetSubTable[1], PartSetStart); WritePart(bcsFile.PartSets[i].FaceEye, PartSetSubTable[2], PartSetStart); WritePart(bcsFile.PartSets[i].FaceNose, PartSetSubTable[3], PartSetStart); WritePart(bcsFile.PartSets[i].FaceEar, PartSetSubTable[4], PartSetStart); WritePart(bcsFile.PartSets[i].Hair, PartSetSubTable[5], PartSetStart); WritePart(bcsFile.PartSets[i].Bust, PartSetSubTable[6], PartSetStart); WritePart(bcsFile.PartSets[i].Pants, PartSetSubTable[7], PartSetStart); WritePart(bcsFile.PartSets[i].Rist, PartSetSubTable[8], PartSetStart); WritePart(bcsFile.PartSets[i].Boots, PartSetSubTable[9], PartSetStart); } } //PartColors if (bcsFile.Part_Colors != null) { List <int> PartColorOffsets = new List <int>(); for (int i = 0; i < bcsFile.Part_Colors.Count(); i++) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), PartColorTable[i]); int PartColorStart = bytes.Count(); int colorCount = (bcsFile.Part_Colors[i]._Colors != null) ? bcsFile.Part_Colors[i]._Colors.Count() : 0; stringInfo.Add(new StringWriter.StringInfo() { Offset = bytes.Count(), RelativeOffset = PartColorStart, StringToWrite = bcsFile.Part_Colors[i].Str_00 }); bytes.AddRange(new byte[10]); bytes.AddRange(BitConverter.GetBytes((short)colorCount)); PartColorOffsets.Add(bytes.Count()); bytes.AddRange(new byte[4]); } for (int i = 0; i < bcsFile.Part_Colors.Count(); i++) { if (bcsFile.Part_Colors[i]._Colors != null) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - PartColorOffsets[i] + 12), PartColorOffsets[i]); for (int a = 0; a < bcsFile.Part_Colors[i]._Colors.Count(); a++) { bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_00)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_04)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_08)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_12)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_16)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_20)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_24)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_28)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_32)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_36)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_40)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_44)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_48)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_52)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_56)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_60)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_64)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_68)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_72)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Part_Colors[i]._Colors[a].F_76)); } } } } //Bodies if (bcsFile.Bodies != null) { List <int> BodyOffsets = new List <int>(); for (int i = 0; i < bcsFile.Bodies.Count(); i++) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), BodyTable[i]); int bodyScalesCount = (bcsFile.Bodies[i].BodyScales != null) ? bcsFile.Bodies[i].BodyScales.Count() : 0; bytes.AddRange(new byte[2]); bytes.AddRange(BitConverter.GetBytes((short)bodyScalesCount)); BodyOffsets.Add(bytes.Count()); bytes.AddRange(new byte[4]); } for (int i = 0; i < bcsFile.Bodies.Count(); i++) { if (bcsFile.Bodies[i].BodyScales != null) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count() - BodyOffsets[i] + 4), BodyOffsets[i]); for (int a = 0; a < bcsFile.Bodies[i].BodyScales.Count(); a++) { bytes.AddRange(BitConverter.GetBytes(bcsFile.Bodies[i].BodyScales[a].F_00)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Bodies[i].BodyScales[a].F_04)); bytes.AddRange(BitConverter.GetBytes(bcsFile.Bodies[i].BodyScales[a].F_08)); stringInfo.Add(new StringWriter.StringInfo() { Offset = bytes.Count(), RelativeOffset = bytes.Count() - 12, StringToWrite = bcsFile.Bodies[i].BodyScales[a].Str_12 }); bytes.AddRange(new byte[4]); } } } } //Skeleton1 WriteSkeleton(bcsFile.SkeletonData1, Skeleton1Table); //Skeleton2 WriteSkeleton(bcsFile.SkeletonData2, Skeleton2Table); //Strings bytes = StringWriter.WritePointerStrings(stringInfo, bytes); }
private void WriteBac() { SortEntries(); int count = (bacFile.BacEntries != null) ? bacFile.BacEntries.Count() : 0; List <int> BacEntryOffsets = new List <int>(); List <List <int> > TypeOffsets = new List <List <int> >(); //Header bytes.AddRange(BitConverter.GetBytes(count)); bytes.AddRange(new byte[4]); bytes.AddRange(BitConverter.GetBytes(96)); bytes.AddRange(BitConverter_Ex.GetBytes(bacFile.I_20)); bytes.AddRange(BitConverter_Ex.GetBytes(bacFile.F_32)); bytes.AddRange(BitConverter_Ex.GetBytes(bacFile.I_80)); //Bac_Entries for (int i = 0; i < count; i++) { if (bacFile.BacEntries[i].TypeDummy == null) { bacFile.BacEntries[i].TypeDummy = new List <int>(); } bytes.AddRange(BitConverter.GetBytes((uint)bacFile.BacEntries[i].Flag)); bytes.AddRange(BitConverter.GetBytes((short)GetSubEntryCount(bacFile.BacEntries[i]))); bytes.AddRange(BitConverter.GetBytes((short)0)); BacEntryOffsets.Add(bytes.Count()); bytes.AddRange(new byte[8]); } //Bac_SubEntries for (int i = 0; i < count; i++) { TypeOffsets.Add(new List <int>()); int subEntryCount = GetSubEntryCount(bacFile.BacEntries[i]); int[] types = GetSubEntryTypes(bacFile.BacEntries[i]); if (subEntryCount > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), BacEntryOffsets[i]); for (int a = 0; a < subEntryCount; a++) { bytes.AddRange(BitConverter.GetBytes((short)types[a])); bytes.AddRange(BitConverter.GetBytes((short)GetTypeCount(bacFile.BacEntries[i], types[a]))); bytes.AddRange(new byte[4]); TypeOffsets[i].Add(bytes.Count()); bytes.AddRange(new byte[8]); } } } //Bac Types for (int i = 0; i < count; i++) { int subEntryCount = GetSubEntryCount(bacFile.BacEntries[i]); int[] types = GetSubEntryTypes(bacFile.BacEntries[i]); for (int a = 0; a < subEntryCount; a++) { if (bacFile.BacEntries[i].TypeDummy.IndexOf(types[a]) == -1) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), TypeOffsets[i][a]); switch (types[a]) { case 0: bytes.AddRange(BAC_Type0.Write(bacFile.BacEntries[i].Type0)); break; case 1: bytes.AddRange(BAC_Type1.Write(bacFile.BacEntries[i].Type1)); break; case 2: bytes.AddRange(BAC_Type2.Write(bacFile.BacEntries[i].Type2)); break; case 3: bytes.AddRange(BAC_Type3.Write(bacFile.BacEntries[i].Type3)); break; case 4: bytes.AddRange(BAC_Type4.Write(bacFile.BacEntries[i].Type4)); break; case 5: bytes.AddRange(BAC_Type5.Write(bacFile.BacEntries[i].Type5)); break; case 6: bytes.AddRange(BAC_Type6.Write(bacFile.BacEntries[i].Type6)); break; case 7: bytes.AddRange(BAC_Type7.Write(bacFile.BacEntries[i].Type7)); break; case 8: bytes.AddRange(BAC_Type8.Write(bacFile.BacEntries[i].Type8)); break; case 9: bytes.AddRange(BAC_Type9.Write(bacFile.BacEntries[i].Type9)); break; case 10: bytes.AddRange(BAC_Type10.Write(bacFile.BacEntries[i].Type10)); break; case 11: bytes.AddRange(BAC_Type11.Write(bacFile.BacEntries[i].Type11)); break; case 12: bytes.AddRange(BAC_Type12.Write(bacFile.BacEntries[i].Type12)); break; case 13: bytes.AddRange(BAC_Type13.Write(bacFile.BacEntries[i].Type13)); break; case 14: bytes.AddRange(BAC_Type14.Write(bacFile.BacEntries[i].Type14)); break; case 15: bytes.AddRange(BAC_Type15.Write(bacFile.BacEntries[i].Type15)); break; case 16: bytes.AddRange(BAC_Type16.Write(bacFile.BacEntries[i].Type16)); break; case 17: bytes.AddRange(BAC_Type17.Write(bacFile.BacEntries[i].Type17)); break; case 18: bytes.AddRange(BAC_Type18.Write(bacFile.BacEntries[i].Type18)); break; case 19: bytes.AddRange(BAC_Type19.Write(bacFile.BacEntries[i].Type19)); break; case 20: bytes.AddRange(BAC_Type20.Write(bacFile.BacEntries[i].Type20)); break; case 21: bytes.AddRange(BAC_Type21.Write(bacFile.BacEntries[i].Type21)); break; case 22: bytes.AddRange(BAC_Type22.Write(bacFile.BacEntries[i].Type22)); break; case 23: bytes.AddRange(BAC_Type23.Write(bacFile.BacEntries[i].Type23)); break; case 24: bytes.AddRange(BAC_Type24.Write(bacFile.BacEntries[i].Type24)); break; case 25: bytes.AddRange(BAC_Type25.Write(bacFile.BacEntries[i].Type25)); break; case 26: bytes.AddRange(BAC_Type26.Write(bacFile.BacEntries[i].Type26)); break; case 27: bytes.AddRange(BAC_Type27.Write(bacFile.BacEntries[i].Type27)); break; } } } } }
void WriteQuestData() { //writing the count bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(qxd_File.Quests.Count()), 8); //counts int totalQuests = qxd_File.Quests.Count(); int totalCharacters1 = 0; int totalCharacters2 = 0; int totalUnknownDatas = 0; if (qxd_File.Characters1 != null) { totalCharacters1 = qxd_File.Characters1.Count; } if (qxd_File.Characters2 != null) { totalCharacters2 = qxd_File.Characters2.Count; } if (qxd_File.Collections != null) { totalUnknownDatas = qxd_File.Collections.Count; } //offsets (where to write the offsets) List <int> MsgEntryOffsets = new List <int>(); List <int> UnkNum1Offsets = new List <int>(); List <int> UnkNum2Offsets = new List <int>(); List <int> QbtFilesOffsets = new List <int>(); List <int> EquipRewardOffsets = new List <int>(); List <int> SkillRewardOffsets = new List <int>(); List <int> CharaUnlockOffsets = new List <int>(); List <int> StageDisplayOffsets = new List <int>(); for (int i = 0; i < totalQuests; i++) { bytes.AddRange(Encoding.ASCII.GetBytes(qxd_File.Quests[i].Name)); for (int a = 0; a < 16 - qxd_File.Quests[i].Name.Count(); a++) { bytes.Add(0); } bytes.AddRange(BitConverter.GetBytes(int.Parse(qxd_File.Quests[i].Index))); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_20)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_24)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_28)); //MsgEntries if (qxd_File.Quests[i].MsgFiles != null) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].MsgFiles.Count())); MsgEntryOffsets.Add(bytes.Count()); bytes.AddRange(new List <byte>() { 0, 0, 0, 0 }); } else { bytes.AddRange(new List <byte>() { 0, 0, 0, 0, 0, 0, 0, 0, }); MsgEntryOffsets.Add(0); } //some shorts bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_40)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_42)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_44)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_46)); bytes.AddRange(BitConverter_Ex.GetBytes(qxd_File.Quests[i].I_48)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_64)); bytes.AddRange(BitConverter_Ex.GetBytes(qxd_File.Quests[i].I_68)); //UnkNum1 if (qxd_File.Quests[i].UnknownNum1 != null) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].UnknownNum1.Count())); UnkNum1Offsets.Add(bytes.Count()); bytes.AddRange(new List <byte>() { 0, 0, 0, 0 }); } else { bytes.AddRange(new List <byte>() { 0, 0, 0, 0, 0, 0, 0, 0 }); UnkNum1Offsets.Add(0); } //UnkNum2 if (qxd_File.Quests[i].UnknownNum2 != null) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].UnknownNum2.Count())); UnkNum2Offsets.Add(bytes.Count()); bytes.AddRange(new List <byte>() { 0, 0, 0, 0 }); } else { bytes.AddRange(new List <byte>() { 0, 0, 0, 0, 0, 0, 0, 0 }); UnkNum2Offsets.Add(0); } //more values bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_104)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_106)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_108)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_110)); //QBT if (qxd_File.Quests[i].QedFiles != null) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].QedFiles.Count())); QbtFilesOffsets.Add(bytes.Count()); bytes.AddRange(new List <byte>() { 0, 0, 0, 0 }); } else { bytes.AddRange(new List <byte>() { 0, 0, 0, 0, 0, 0, 0, 0 }); QbtFilesOffsets.Add(0); } //more values bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_120)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_124)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_128)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_132)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_136)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_140)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_144)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_148)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_152)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_156)); //Equipment Reward if (qxd_File.Quests[i].EquipReward != null) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].EquipReward.Count())); EquipRewardOffsets.Add(bytes.Count()); bytes.AddRange(new List <byte>() { 0, 0, 0, 0 }); } else { bytes.AddRange(new List <byte>() { 0, 0, 0, 0, 0, 0, 0, 0 }); EquipRewardOffsets.Add(0); } //Skill Reward if (qxd_File.Quests[i].Skill_Reward != null) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].Skill_Reward.Count())); SkillRewardOffsets.Add(bytes.Count()); bytes.AddRange(new List <byte>() { 0, 0, 0, 0 }); } else { bytes.AddRange(new List <byte>() { 0, 0, 0, 0, 0, 0, 0, 0 }); SkillRewardOffsets.Add(0); } //Chara Unlock if (qxd_File.Quests[i].Chara_Unlock != null) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].Chara_Unlock.Count())); CharaUnlockOffsets.Add(bytes.Count()); bytes.AddRange(new List <byte>() { 0, 0, 0, 0 }); } else { bytes.AddRange(new List <byte>() { 0, 0, 0, 0, 0, 0, 0, 0 }); CharaUnlockOffsets.Add(0); } //Stage Portrait if (qxd_File.Quests[i].StageDisplay != null) { bytes.AddRange(BitConverter.GetBytes((int)1)); StageDisplayOffsets.Add(bytes.Count()); bytes.AddRange(new List <byte>() { 0, 0, 0, 0 }); } else { bytes.AddRange(new List <byte>() { 0, 0, 0, 0, 0, 0, 0, 0 }); StageDisplayOffsets.Add(0); } //random value bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_192)); //Enemy Portrait InvalidCollectionCheck("EnemyPortraits", 6, qxd_File.Quests[i].EnemyPortraitDisplay.Count(), qxd_File.Quests[i].Name); int addedOffset = 0; for (int a = 0; a < 6; a++) { bytes.AddRange(BitConverter.GetBytes((short)qxd_File.Quests[i].EnemyPortraitDisplay[a].CharaID)); bytes.AddRange(BitConverter.GetBytes((short)qxd_File.Quests[i].EnemyPortraitDisplay[a].CostumeIndex)); bytes.AddRange(BitConverter.GetBytes((short)qxd_File.Quests[i].EnemyPortraitDisplay[a].State)); addedOffset += 6; } //collection of unknown values bytes.AddRange(BitConverter_Ex.GetBytes(qxd_File.Quests[i].I_232)); //5 Int32s bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_248)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_252)); bytes.AddRange(BitConverter.GetBytes((int)qxd_File.Quests[i].I_256)); bytes.AddRange(BitConverter.GetBytes((int)qxd_File.Quests[i].I_260)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_264)); //Music Values bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_268)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_270)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_272)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_274)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].F_276)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].I_280)); //end main Quest Data, Next: MSG entries } //MSG section for (int i = 0; i < totalQuests; i++) { if (MsgEntryOffsets[i] > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), MsgEntryOffsets[i]); for (int a = 0; a < qxd_File.Quests[i].MsgFiles.Count(); a++) { bytes.AddRange(Encoding.ASCII.GetBytes(qxd_File.Quests[i].MsgFiles[a])); int remainingBytes = 32 - qxd_File.Quests[i].MsgFiles[a].Count(); for (int b = 0; b < remainingBytes; b++) { bytes.Add(0); } } } } //UnkNum1 section for (int i = 0; i < totalQuests; i++) { if (UnkNum1Offsets[i] > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), UnkNum1Offsets[i]); for (int e = 0; e < qxd_File.Quests[i].UnknownNum1.Count(); e++) { InvalidCollectionCheck("UnkNum1", 16, qxd_File.Quests[i].UnknownNum1[e].I_00.Count(), qxd_File.Quests[i].Name); for (int a = 0; a < qxd_File.Quests[i].UnknownNum1[e].I_00.Count(); a++) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].UnknownNum1[e].I_00[a])); } } } } //UnkNum2 section for (int i = 0; i < totalQuests; i++) { if (UnkNum2Offsets[i] > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), UnkNum2Offsets[i]); for (int a = 0; a < qxd_File.Quests[i].UnknownNum2.Count(); a++) { InvalidCollectionCheck("UnkNum2", 16, qxd_File.Quests[i].UnknownNum2[a].I_00.Count(), qxd_File.Quests[i].Name); for (int b = 0; b < qxd_File.Quests[i].UnknownNum2[a].I_00.Count(); b++) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].UnknownNum2[a].I_00[b])); } } } } //QBT section for (int i = 0; i < totalQuests; i++) { if (QbtFilesOffsets[i] > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), QbtFilesOffsets[i]); for (int a = 0; a < qxd_File.Quests[i].QedFiles.Count(); a++) { ErrorStringToLongCheck(qxd_File.Quests[i].QedFiles[a], 31); bytes.AddRange(Encoding.ASCII.GetBytes(qxd_File.Quests[i].QedFiles[a])); int remainingBytes = 32 - qxd_File.Quests[i].QedFiles[a].Count(); for (int b = 0; b < remainingBytes; b++) { bytes.Add(0); } } } } //Equipment Reward section for (int i = 0; i < totalQuests; i++) { if (EquipRewardOffsets[i] > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), EquipRewardOffsets[i]); for (int a = 0; a < qxd_File.Quests[i].EquipReward.Count(); a++) { bytes.AddRange(BitConverter.GetBytes((int)qxd_File.Quests[i].EquipReward[a].I_00)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].EquipReward[a].I_04)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].EquipReward[a].I_08)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].EquipReward[a].I_12)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].EquipReward[a].I_16)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].EquipReward[a].I_20)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].EquipReward[a].F_24)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].EquipReward[a].I_28)); } } } //Skill Reward Section for (int i = 0; i < totalQuests; i++) { if (SkillRewardOffsets[i] > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), SkillRewardOffsets[i]); for (int a = 0; a < qxd_File.Quests[i].Skill_Reward.Count(); a++) { bytes.AddRange(BitConverter.GetBytes((int)qxd_File.Quests[i].Skill_Reward[a].I_00)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].Skill_Reward[a].I_04)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].Skill_Reward[a].I_08)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].Skill_Reward[a].I_12)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].Skill_Reward[a].F_16)); } } } //Chara Unlock Section for (int i = 0; i < totalQuests; i++) { if (CharaUnlockOffsets[i] > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), CharaUnlockOffsets[i]); for (int a = 0; a < qxd_File.Quests[i].Chara_Unlock.Count(); a++) { ErrorStringToLongCheck(qxd_File.Quests[i].Chara_Unlock[a].ShortName, 3); bytes.AddRange(Encoding.ASCII.GetBytes(qxd_File.Quests[i].Chara_Unlock[a].ShortName)); int remainingBytes = 4 - qxd_File.Quests[i].Chara_Unlock[a].ShortName.Count(); for (int b = 0; b < remainingBytes; b++) { bytes.Add(0); } bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].Chara_Unlock[a].CostumeIndex)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].Chara_Unlock[a].I_06)); } } } //Stage Portrait Section for (int i = 0; i < totalQuests; i++) { if (StageDisplayOffsets[i] > 0) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), StageDisplayOffsets[i]); for (int a = 0; a < qxd_File.Quests[i].StageDisplay.Count(); a++) { bytes.AddRange(BitConverter.GetBytes(qxd_File.Quests[i].StageDisplay[a])); } } } WriteCharacterData(); }
void WriteCharacterData() { //setting header info for Characters1 bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 20); bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(qxd_File.Characters1.Count()), 16); for (int i = 0; i < qxd_File.Characters1.Count(); i++) { bytes.AddRange(BitConverter.GetBytes(int.Parse(qxd_File.Characters1[i].Index))); bytes.AddRange(Encoding.ASCII.GetBytes(qxd_File.Characters1[i].CharaShortName)); int remainingBytes = 4 - qxd_File.Characters1[i].CharaShortName.Count(); for (int b = 0; b < remainingBytes; b++) { bytes.Add(0); } bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].I_08)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].I_12)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].I_16)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_20)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_24)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_28)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_32)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_36)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_40)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_44)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_48)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_52)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_56)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_60)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_64)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_68)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_72)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_76)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].F_80)); bytes.AddRange(BitConverter.GetBytes(int.Parse(qxd_File.Characters1[i].I_84))); //Skills bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i]._Skills.I_00))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i]._Skills.I_02))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i]._Skills.I_04))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i]._Skills.I_06))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i]._Skills.I_08))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i]._Skills.I_10))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i]._Skills.I_12))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i]._Skills.I_14))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i]._Skills.I_16))); bytes.AddRange(BitConverter_Ex.GetBytes(qxd_File.Characters1[i].I_106)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters1[i].I_120)); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters1[i].I_122))); } //CHARACTERS2 (duplicated code) //setting header info for Characters2 bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count()), 28); bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(qxd_File.Characters2.Count()), 24); for (int i = 0; i < qxd_File.Characters2.Count(); i++) { bytes.AddRange(BitConverter.GetBytes(int.Parse(qxd_File.Characters2[i].Index))); bytes.AddRange(Encoding.ASCII.GetBytes(qxd_File.Characters2[i].CharaShortName)); int remainingBytes = 4 - qxd_File.Characters2[i].CharaShortName.Count(); for (int b = 0; b < remainingBytes; b++) { bytes.Add(0); } bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].I_08)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].I_12)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].I_16)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_20)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_24)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_28)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_32)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_36)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_40)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_44)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_48)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_52)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_56)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_60)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_64)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_68)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_72)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_76)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].F_80)); bytes.AddRange(BitConverter.GetBytes(int.Parse(qxd_File.Characters2[i].I_84))); //Skills bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i]._Skills.I_00))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i]._Skills.I_02))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i]._Skills.I_04))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i]._Skills.I_06))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i]._Skills.I_08))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i]._Skills.I_10))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i]._Skills.I_12))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i]._Skills.I_14))); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i]._Skills.I_16))); bytes.AddRange(BitConverter_Ex.GetBytes(qxd_File.Characters2[i].I_106)); bytes.AddRange(BitConverter.GetBytes(qxd_File.Characters2[i].I_120)); bytes.AddRange(BitConverter.GetBytes(ushort.Parse(qxd_File.Characters2[i].I_122))); } WriteUnknownData(); }