static public string GetTagLongName(uint TagType) { byte[] sf = new byte[4]; sf = BitConverter.GetBytes(TagType); string Class = CompUtil.GetTagClass(sf, 0); string LongName = (string)strConversionTable[Class]; return(LongName); }
public void Read(ref FileStream FI) { MapHeader.Read(ref FI); FI.Seek(MapHeader.IndexOffset, System.IO.SeekOrigin.Begin); IndexHeader.Read(ref FI); IndexItem = new sIndexItem[IndexHeader.TagCount]; MapMagic = IndexHeader.IndexMagic - IndexHeader.TagStartOffset; StringTable.OffsetsOffset = MapHeader.StringTableListOffset; StringTable.OffsetsBufferSize = MapHeader.StringTableListSize; StringTable.StringOffset = MapHeader.StringTableOffset; StringTable.StringBufferSize = MapHeader.StringTableSize; StringTable.Read(ref FI); FI.Seek(IndexHeader.TagStartOffset, System.IO.SeekOrigin.Begin); //uint ScnrOffset = 0; for (int tc = 0; tc < IndexHeader.TagCount; tc += 1) { IndexItem[tc].Read(ref FI); //IndexItem[tc].TagOffset = IndexItem[tc].TagOffset; byte[] strtemp = BitConverter.GetBytes(IndexItem[tc].TagType); string tmpstr = CompUtil.GetTagClass(strtemp, 0); if (tmpstr == "<fx>") { tmpstr = "FXFX"; } string MagfilePathRoot = Application.StartupPath + @"\Tag Structures\Halo2\"; string ProcessTagFile = tmpstr.Trim() + ".mag"; StreamReader MagReader = new StreamReader(MagfilePathRoot + ProcessTagFile); string InLine = MagReader.ReadLine(); IndexItem[tc].NameString = StringTable.TagStrings[tc] + "." + InLine; StringTable.TagStrings[tc] = StringTable.TagStrings[tc] + "." + InLine; MagReader = null; } MapMagic = IndexItem[0].TagOffset - MapHeader.OffsetToFirstObject; uint BspIndex = 0; for (int tc = 0; tc < IndexHeader.TagCount; tc += 1) { byte[] strtemp = BitConverter.GetBytes(IndexItem[tc].TagType); string tmpstr = CompUtil.GetTagClass(strtemp, 0); if (tmpstr == "scnr") { byte[] TmpScnrBuff = new byte[0x3E0]; long fpSav = FI.Position; IndexItem[tc].TagOffset = IndexItem[tc].TagOffset - MapMagic; IndexItem[tc].TagMagic = MapMagic; IndexItem[tc].TagOffsetMagic = MapMagic; FI.Seek(IndexItem[tc].TagOffset, System.IO.SeekOrigin.Begin); FI.Read(TmpScnrBuff, 0, TmpScnrBuff.Length); uint BSPCount = BitConverter.ToUInt32(TmpScnrBuff, 0x210); //Struct Size 0x44 uint BSPOffset = BitConverter.ToUInt32(TmpScnrBuff, 0x214) - MapMagic; FI.Seek((long)BSPOffset, System.IO.SeekOrigin.Begin); sbspltmpref = new sScnrBsp[BSPCount]; for (int i = 0; i < BSPCount; i++) { sbspltmpref[i].Read(ref FI); } FI.Seek(fpSav, System.IO.SeekOrigin.Begin); } else if (tmpstr == "sbsp") { //byte[] tmp = new byte[0x10]; //long possave = FI.Position; //FI.Seek((long)sbspltmpref[BspIndex].Offset,System.IO.SeekOrigin.Begin); //FI.Read(tmp,0,tmp.Length); //FI.Seek(possave,System.IO.SeekOrigin.Begin); IndexItem[tc].TagOffset = sbspltmpref[BspIndex].Offset + 0x10; IndexItem[tc].TagSize = sbspltmpref[BspIndex].Size; IndexItem[tc].TagMagic = MapMagic; IndexItem[tc].TagOffsetMagic = sbspltmpref[BspIndex].Magic - (IndexItem[tc].TagOffset - 0x10); BspIndex += 1; } else if (tmpstr == "ltmp") //lovers brain << My wifes atemp to program... { byte[] tmp = new byte[0x10]; long possave = FI.Position; FI.Seek((long)sbspltmpref[BspIndex].Offset, System.IO.SeekOrigin.Begin); FI.Read(tmp, 0, tmp.Length); FI.Seek(possave, System.IO.SeekOrigin.Begin); IndexItem[tc].TagOffset = BitConverter.ToUInt32(tmp, 0x08) - sbspltmpref[BspIndex].Magic + sbspltmpref[BspIndex].Offset; //sbspltmpref[BspIndex].Offset; IndexItem[tc].TagSize = BitConverter.ToUInt32(tmp, 0x0); //sbspltmpref[BspIndex].Size; IndexItem[tc].TagMagic = MapMagic; IndexItem[tc].TagOffsetMagic = sbspltmpref[BspIndex].Magic - sbspltmpref[BspIndex].Offset; } else { IndexItem[tc].TagOffset = IndexItem[tc].TagOffset - MapMagic; IndexItem[tc].TagMagic = MapMagic; IndexItem[tc].TagOffsetMagic = MapMagic; } } FilenameTable = new Hashtable((int)IndexHeader.TagCount); for (int strs = 0; strs < IndexHeader.TagCount; strs += 1) { //IndexItemStringList[strs] = StringLoader(ref FI,IndexItems[strs].OffsetToString) + GetTagLongName(IndexItems[strs].Type1); FilenameTable.Add(StringTable.TagStrings[strs], strs); } }
private void ExtractH2Tag(int index) { //Load Shared Map streams FileStream fsShared = OptionsManager.GetHalo2SharedStream(); FileStream fsSinglePlayerShared = OptionsManager.GetHalo2SinglePlayerSharedStream(); FileStream fsMainMenu = OptionsManager.GetHalo2MainMenuStream(); //Tag Header loader start string TagClass = CompUtil.GetTagClass(BitConverter.GetBytes(Halo2Map.IndexItem[index].TagType), 0); if (TagClass == "<fx>") { TagClass = "FXFX"; } byte[] TagHeaderBuffer = new byte[64]; OptionsManager.GetGuerillaHeader(m_MapVersion, TagClass, TagHeaderBuffer); string MagfilePathRoot = Application.StartupPath + @"\Tag Structures\Halo2\"; string OutputPathRoot = Application.StartupPath + @"\Games\Xbox\Halo2\"; //Creating Directorys for extacted tag string[] Directorys = new string[256]; string DirSep = @"\"; Directorys = Halo2Map.StringTable.TagStrings[index].Split(DirSep.ToCharArray(), 256); uint Dircount = (uint)Directorys.Length - 1; string NewDirectoryStructure = ""; for (uint Count = 0; Count < Dircount; Count += 1) { if (Directory.Exists(OutputPathRoot + NewDirectoryStructure + Directorys[Count]) == false) { Directory.CreateDirectory(OutputPathRoot + NewDirectoryStructure + Directorys[Count]); NewDirectoryStructure += Directorys[Count] + @"\"; } else { NewDirectoryStructure += Directorys[Count] + @"\"; } } //Loading Tag Long name from mag file string ProcessTagFile = TagClass.Trim() + ".mag"; StreamReader MagReader = new StreamReader(MagfilePathRoot + ProcessTagFile); string InLine = MagReader.ReadLine(); //Create the Tag on disk string SplitChar = "."; string[] FixTagName = Halo2Map.StringTable.TagStrings[index].Split(SplitChar.ToCharArray(), 2); //FileInfo fiout = new FileInfo(OptionsManager.GetExtractPath(m_MapVersion) + FixTagName[0] + "." + InLine.Trim()); string FileName = FixTagName[0] + "." + InLine.Trim(); MemoryStream msout = new MemoryStream(); TagHeader.SeekToTagDataStart(ref msout); // Create a tag table for byte[] TagTable = new byte[TagCount * 16]; fsin.Seek(Halo2Map.IndexHeader.OffsetToTags, System.IO.SeekOrigin.Begin); fsin.Read(TagTable, 0, TagTable.Length); // Move File pointer to start of tag fsin.Seek(Halo2Map.IndexItem[index].TagOffset, System.IO.SeekOrigin.Begin); // Create the Tab char to provent errors byte TabByte = 0x09; string TabReplace = ""; TabReplace += (char)TabByte; // Read the Structure from the mag file string[] MagArray = new string[256]; int MagIndex = 0; do { InLine = MagReader.ReadLine(); MagArray[MagIndex] = InLine.Replace(TabReplace, "").ToLower().Trim(); MagIndex = MagIndex + 1; }while(MagReader.Peek() != -1); MagReader.Close(); // Create debug stream writer //StreamWriter DebugFile; //DebugFile = new StreamWriter(msout.Name + ".txt" ); // Start the Tags extraction Halo2Structure MainStruct = new Halo2Structure(); //if(TagClass == "sbsp") MainStruct.StructureCS((uint)MagIndex, Halo2Map.IndexItem[index].TagOffsetMagic, Halo2Map.IndexItem[index].TagMagic, MagArray, 1, fsin, msout, fsShared, 0, 0, Halo2Map.StringTable.StringBuffer, Halo2Map.StringTable.OffsetsBuffer, fsSinglePlayerShared, fsMainMenu, fsShared, Halo2Map.MapHeader.MetaStart, Halo2Map.MapHeader.FileSize, null, TagTable, Halo2Map.MapHeader.ScriptStringArray); //DebugFile.Flush(); //DebugFile.Close(); //For Refernce only //public void StructureCS(uint MagIndex,uint OffsetMagic,uint MapMagic,string[] StructureArray,uint ChunkCount,FileStream MapFile,FileStream TagFile,FileStream BitmapFile,uint VerticesOffset,uint IndicesOffset,byte[] StringTable,byte[] StringTableOffsetList,FileStream single_player_shared_map,FileStream mainmenu_map,FileStream shared_map,uint StartOfTags,uint MapSize,StreamWriter DebugFile,byte[] TagTable,string[] ScriptStringArray) // Initialize and write out the PROM tag header TagHeader tag_hdr = new TagHeader(); tag_hdr.TagClass0 = Halo2Map.IndexItem[index].TagType; tag_hdr.GameVersion = m_MapVersion; tag_hdr.TagSize = (int)msout.Position - TagHeader.PROM_HEADER_SIZE; tag_hdr.Write(ref msout); //Write out a zero-attachment header tag_hdr.SeekToAttachStart(ref msout); AttachmentHeader attach_hdr = new AttachmentHeader(); attach_hdr.Write(ref msout); if (m_OutputArchive != null) { //m_OutputArchive.AddTagfileToArchive(HaloMap.IndexItemStringList[index], msout.GetBuffer(), (int)msout.Position); m_OutputArchive.AddFile(FileName, GetSubArray(msout.GetBuffer(), 0, (int)msout.Position - 12)); } msout.Close(); fsShared.Close(); fsSinglePlayerShared.Close(); fsMainMenu.Close(); }
public void DoProcessMeta(ref TSFReader sr, MemoryStream FI, ref FileStream FO, ref FileStream BSPFile, uint Count, string[] IndexStrings, StructInfo Info, ref XBoxHaloMap.sXBoxHalo XBoxMap, ref IndexBuilder IndexBuild) { TabReplace += (char)TabByte; Name = sr.GetUName(); Size = sr.GetSOC(); TagBuff = new byte[Size * Count]; FI.Read(TagBuff, 0, TagBuff.Length); long StructPosition = FO.Position; FO.Write(TagBuff, 0, TagBuff.Length); uint StartOfStruct = sr.Position; uint sc = 0; bool ExitStruct = false; do { do { sr.Read(); switch (sr.GetCMD()) { case TSFReader.TSFStruct: // "struct": #region Structure uint ChildCount = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size))); if (ChildCount != 0) { XBoxMeta Child = new XBoxMeta(); CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP() + 4 + (sc * Size)), (uint)(FO.Position + Info.TagMagic)); Child.DoProcessMeta(ref sr, FI, ref FO, ref BSPFile, ChildCount, IndexStrings, Info, ref XBoxMap, ref IndexBuild); CompUtil.FixIntPosition(ref FO); } else { sr.SeekAheadTo(0xA7, sr.GetUName()); //sr.SeekAheadTo("end " + CMD[2]); //sr.Seek(sr.Position + 1); } break; #endregion case TSFReader.TSFBSPTagRef: // "bspstagref": case TSFReader.TSFTagRef: // "tagref": #region TagRefernce uint tStringSize = 0; CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x08, ref tStringSize); if (tStringSize != 0x00) { CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x04, 0x00000000); CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x08, 0x00000000); uint TagClass = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size))); string TagClassString = CompUtil.GetTagClassRev(BitConverter.GetBytes(TagClass), 0); byte[] tmpStr = new byte[tStringSize + 1]; FI.Read(tmpStr, 0, tmpStr.Length); string tag = CompUtil.ReadString(tmpStr, 0); int t = 0; //string[] test; bool con = false; do { string[] test = Info.Items[t].NameString.Split(new char[] { '.' }, 256); //IndexStrings[t].Split(new char[]{'.'},256); string testClass = CompUtil.GetTagClassRev(BitConverter.GetBytes(Info.Items[t].TagClass1), 0); if (testClass == TagClassString && test[0] == tag) { con = true; } else { t += 1; } }while (con == false); // testClass != TagClass); CompUtil.SwapInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x00); CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x04, Info.Items[t].StringOffset); CompUtil.PutUShort(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x0C, (ushort)Info.Items[t].IndexID1); CompUtil.PutUShort(ref TagBuff, (uint)(sr.GetOIP() + (sc * Size)) + 0x0E, (ushort)Info.Items[t].IndexID2); if (Name == 0x0468) { uint SaveTagMagic = Info.TagMagic; byte[] BspHeader = new byte[0x18]; CompUtil.PutUInt(ref TagBuff, 0x00 + (sc * Size), (uint)(0x800 + BSPFile.Position)); uint CurrentPosition = (uint)BSPFile.Position; Info.CurrentOffset = (uint)BSPFile.Position; MTSFReader mr = new MTSFReader(); mr.MTSFRead("Core.Compiler.HALO_PC_SET.MTSF"); TSFReader tmpSTSF = new TSFReader(); //SwapInt(TagClasses,0); tmpSTSF.TSF(ref mr, 0x70736273); // 73627370); //MAG tmpsr = new MAG(Info.StructurePath + "sbsp.mag"); //FileInfo BspMetaFile_info = new FileInfo(Info.TagsPath + tag + "." + tmpSTSF.Name); //FileStream BspMetaFile; //BspMetaFile = BspMetaFile_info.Open(FileMode.Open,FileAccess.Read); //BspMetaFile.Seek(0x40,SeekOrigin.Begin); Trace.WriteLine(tag + ".sbsp" + " Hello I'm your bsp"); TagFileName tfnTAG = new TagFileName(tag + "." + tmpSTSF.Name, MapfileVersion.XHALO1); TagBase tbTAG = new TagBase(); tbTAG.LoadTagBuffer(tfnTAG); string[] gh; int tt = -1; do { tt += 1; }while((tag + "." + tmpSTSF.Name) != Info.Items[tt].NameString); uint BSPFileSize = (0x800 - ((uint)(Info.Items[tt].MetaSize) % 0x800)); BSPFileSize += (uint)(Info.Items[tt].MetaSize); uint tmpMagic = (uint)(0x819a5800 - BSPFileSize); Info.TagMagic = tmpMagic; CompUtil.PutUInt(ref TagBuff, 0x08 + (sc * Size), tmpMagic); //IndexBuild.XBoxMapData.XBSPVerts.Finish(); uint CompoundSize = (uint)IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length + (uint)IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length + (uint)IndexBuild.XBoxMapData.XBSPVerts.ModelData.Length; CompUtil.PutUInt(ref BspHeader, 0x00 + (sc * Size), 0x18 + CompoundSize + tmpMagic); CompUtil.PutUInt(ref BspHeader, 0x04 + (sc * Size), IndexBuild.XBoxMapData.XBSPVerts.DataCount); CompUtil.PutUInt(ref BspHeader, 0x08 + (sc * Size), 0x18 + tmpMagic); CompUtil.PutUInt(ref BspHeader, 0x0C + (sc * Size), IndexBuild.XBoxMapData.XBSPVerts.DataCount); CompUtil.PutUInt(ref BspHeader, 0x10 + (sc * Size), (uint)((IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length + 0x18) + tmpMagic)); CompUtil.PutUInt(ref BspHeader, 0x14 + (sc * Size), 0x73627370); long BSPHeaderPos = BSPFile.Position; BSPFile.Write(BspHeader, 0, BspHeader.Length); //IndexBuild.XBoxMapData.XBSPVerts.FixOffsets((uint)BSPFile.Position + (uint)IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length + (uint)IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length,Info.TagMagic); long savepos = BSPFile.Position; BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets, 0, IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length); BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets, 0, IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length); CompUtil.Fix0x20Position(ref BSPFile); IndexBuild.XBoxMapData.XBSPVerts.FixOffsets((uint)BSPFile.Position, Info.TagMagic); BSPFile.Seek(savepos, SeekOrigin.Begin); IndexBuild.XBoxMapData.XBSPVerts.VLMapOffset = (uint)BSPFile.Position + (uint)IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length; BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets, 0, IndexBuild.XBoxMapData.XBSPVerts.VIndirectOffsets.Length); IndexBuild.XBoxMapData.XBSPVerts.ILMapOffset = (uint)BSPFile.Position + (uint)IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length; BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets, 0, IndexBuild.XBoxMapData.XBSPVerts.LIndirectOffsets.Length); CompUtil.Fix0x20Position(ref BSPFile); BSPFile.Write(IndexBuild.XBoxMapData.XBSPVerts.ModelData, 0, IndexBuild.XBoxMapData.XBSPVerts.ModelData.Length); long BSPSavPos = BSPFile.Position; CompUtil.PutUInt(ref BspHeader, 0x00, (uint)(BSPFile.Position + tmpMagic)); BSPFile.Seek(BSPHeaderPos, SeekOrigin.Begin); BSPFile.Write(BspHeader, 0, BspHeader.Length); BSPFile.Seek(BSPSavPos, SeekOrigin.Begin); XBoxMeta BspMeta = new XBoxMeta(); BspMeta.DoProcessMeta(ref tmpSTSF, tbTAG.Stream, ref BSPFile, ref BSPFile, 1, IndexStrings, Info, ref XBoxMap, ref IndexBuild); CompUtil.FixIntPosition2K(ref BSPFile); CompUtil.PutUInt(ref TagBuff, 0x04 + (sc * Size), (uint)(CurrentPosition + BSPFile.Position)); //BspMetaFile.Close(); tbTAG = null; Info.TagMagic = SaveTagMagic; int a = 0; } } break; #endregion case TSFReader.TSFInternalRaw: // "internalraw": #region InternalRaw uint RawSize = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size))); //Compile Mag.Map if (RawSize == 0) { break; } uint RawOffset = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + 0x0c + (sc * Size))); //Tag Text CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetOIP()) + 0x0c + (sc * Size), ((uint)FO.Position + Info.TagMagic)); byte[] tmp = new byte[RawSize]; FI.Read(tmp, 0, tmp.Length); FO.Write(tmp, 0, tmp.Length); CompUtil.FixIntPosition(ref FO); tmp = null; break; #endregion case TSFReader.TSFBitmapRaw: // "bitmapraw": #region BitmapRaw MemoryStream BMD; uint TiffSize = 0; CompUtil.GetUInt(TagBuff, 0x1C, ref TiffSize); byte[] TiffBuffer = new byte[TiffSize]; FI.Read(TiffBuffer, 0, TiffBuffer.Length); uint BitmapSize = CompUtil.GetUInt(TagBuff, 0x30); TiffBuffer = new byte[BitmapSize]; FI.Read(TiffBuffer, 0, TiffBuffer.Length); BMD = new MemoryStream(TiffBuffer); uint BitMapStructCount = CompUtil.GetUInt(TagBuff, 0x60); uint BitMapStructOffset = CompUtil.GetUInt(TagBuff, 0x64); byte[] tmpBMS = new byte[BitMapStructCount * 0x30]; long sv = FI.Position; FI.Seek((long)BitMapStructOffset, SeekOrigin.Begin); FI.Read(tmpBMS, 0, tmpBMS.Length); for (int i = 0; i < BitMapStructCount; i++) { uint BitMapDataSize = CompUtil.GetUInt(tmpBMS, (uint)(0x1C + (i * 0x30))); uint svBmPos = (uint)BSPFile.Position + 0x800; CompUtil.PutUInt(ref tmpBMS, (uint)(0x18 + (i * 0x30)), (uint)svBmPos); byte[] tmpBuff = new byte[BitMapDataSize]; BMD.Read(tmpBuff, 0, tmpBuff.Length); BSPFile.Write(tmpBuff, 0, tmpBuff.Length); CompUtil.Fix0x100Position(ref BSPFile); svBmPos += BitMapDataSize; } FI.Seek((long)BitMapStructOffset, SeekOrigin.Begin); FI.Write(tmpBMS, 0, tmpBMS.Length); FI.Seek(sv, SeekOrigin.Begin); //BSPFile.Write(TiffBuffer,0,TiffBuffer.Length); //Fix0x100Position(ref BSPFile); TiffBuffer = null; break; #endregion case TSFReader.TSFRawXModelData: // "XBoxModelData": #region XModelData uint XTrueVerticesSize = (CompUtil.GetUInt(TagBuff, 88 + (sc * Size))) * 32; uint XTrueIndicesSize = (((CompUtil.GetUInt(TagBuff, 72 + (sc * Size))) / 3) + 1) * 6; uint XNewIndicesDataSize = (CompUtil.GetUInt(TagBuff, 72 + (sc * Size)) / 3) + 1; uint XTrueVerticesOffset = CompUtil.GetUInt(TagBuff, 100 + (sc * Size)) - Info.MapMagic; uint XSaveMapFilePos = (uint)FI.Position; //MapFile.Position; byte[] XModelHeader = new byte[16]; //uint XTrueVerticesOffset = GetUInt(TagBuff,100 + (sc * Size)) - Info.MapMagic; CompUtil.PutUInt(ref TagBuff, 100 + (sc * Size), XBoxMap.IndirectVerts + Info.MapMagic); //uint XTrueIndicesOffset = GetUInt(TagBuff, 80+ (sc * Size)) - Info.MapMagic; CompUtil.PutUInt(ref TagBuff, 80 + (sc * Size), XBoxMap.IndirectIndices + Info.MapMagic); XBoxMap.IndirectVerts += 0x0c; XBoxMap.IndirectIndices += 0x0c; CompUtil.PutUInt(ref TagBuff, 0x4c + (sc * Size), IndexBuild.XBoxMapData.XIndices.GetOffset()); byte[] RawXModelBuffer = new byte[XTrueVerticesSize]; FI.Read(RawXModelBuffer, 0, (int)XTrueVerticesSize); byte[] XTestBuffer = new byte[6]; RawXModelBuffer = new byte[XTrueIndicesSize]; FI.Read(RawXModelBuffer, 0, RawXModelBuffer.Length); FI.Read(XTestBuffer, 0, 6); if (XTestBuffer[4] == 0xff) { XTrueIndicesSize += 6; } else { FI.Seek(FI.Position - 6, SeekOrigin.Begin); } break; #endregion case TSFReader.TSFBSPModel: // "bspmodel": #region BspModel uint UnCompressedVerts = sr.GetOIP(); uint CompressedVerts = sr.GetSOC(); uint UnCompressedVertsOffset = sr.GetOIP(); //uint VertsOffset = GetUInt(TagBuff,CompressedVerts); uint TrueVertCount = CompUtil.GetUInt(TagBuff, 180 + (sc * Size)); uint TrueLightMapDataCount = CompUtil.GetUInt(TagBuff, 200 + (sc * Size)); uint UnCompressedLightMapData = (TrueLightMapDataCount * 20); uint CompressedLightMapData = (TrueLightMapDataCount * 8); UnCompressedVerts = (TrueVertCount * 56); CompressedVerts = (TrueVertCount * 32); byte[] BspVertsUnCompressed = new byte[UnCompressedVerts]; FI.Read(BspVertsUnCompressed, 0, BspVertsUnCompressed.Length); //PutUInt(ref TagBuff,0xe4 + (sc * Size),(uint)(FO.Position + Info.TagMagic)); //FO.Write(BspVertsUnCompressed,0,BspVertsUnCompressed.Length); //byte[] BspVertsCompressed = new byte[CompressedVerts]; byte[] BspLightMapDataUnCompressed = new byte[UnCompressedLightMapData]; FI.Read(BspLightMapDataUnCompressed, 0, BspLightMapDataUnCompressed.Length); //FO.Write(BspLightMapDataUnCompressed,0,BspLightMapDataUnCompressed.Length); //byte[] BspLightMapDataCompressed = new byte[CompressedLightMapData]; uint PotLuck = IndexBuild.XBoxMapData.XBSPVerts.CurrentOffset; // + 0x800; uint VOOffset = 0xB4; uint LOOffset = 0xC8; IndexBuild.XBoxMapData.XBSPVerts.VLMapOffset -= 0x0c; CompUtil.PutUInt(ref TagBuff, VOOffset + 0x0c + (sc * Size), (uint)(IndexBuild.XBoxMapData.XBSPVerts.VLMapOffset + Info.TagMagic)); IndexBuild.XBoxMapData.XBSPVerts.ILMapOffset -= 0x0c; CompUtil.PutUInt(ref TagBuff, LOOffset + 0x0c + (sc * Size), (uint)(IndexBuild.XBoxMapData.XBSPVerts.ILMapOffset + Info.TagMagic)); PotLuck += 0x0c; IndexBuild.XBoxMapData.XBSPVerts.CurrentOffset = PotLuck; CompUtil.PutUInt(ref TagBuff, 0xF8 + (sc * Size), IndexBuild.XBoxMapData.XBSPVerts.GetVOffset()); //viper told me to skip past compressed data as a quick fix to // the crash problem - Grenadiac FI.Seek(CompressedVerts, SeekOrigin.Current); //gren added this FI.Seek(CompressedLightMapData, SeekOrigin.Current); //gren added this break; #endregion case TSFReader.TSFResource: // "resources": #region Resources ushort rStringSize = CompUtil.GetUShort(TagBuff, 0x06 + (sc * Size)); if (rStringSize != 0x00) { uint TagClassFlag = CompUtil.GetUShort(TagBuff, 0x00 + (sc * Size)); uint TagResouceIndex = CompUtil.GetUShort(TagBuff, 0x02 + (sc * Size)); string TagClassString = ""; switch (TagClassFlag) { case 0x00: TagClassString = "bitm"; break; case 0x01: TagClassString = "snd!"; break; } //MAG tmpMR = new MAG(Info.StructurePath + TagClassString.Trim() + ".mag"); byte[] tmpStr = new byte[rStringSize + 1]; FI.Read(tmpStr, 0, tmpStr.Length); string tag = CompUtil.ReadString(tmpStr, 0); Trace.WriteLine(tag + "." + TagClassString + " PRIndex" + Convert.ToString(TagResouceIndex, 10)); //tmpMR.Seek(0); int t = 0; //string[] test; bool con = false; do { string[] test = Info.Items[t].GetString().Split(new char[] { '.' }, 256); //IndexStrings[t].Split(new char[]{'.'},256); string testClass = CompUtil.GetTagClass(BitConverter.GetBytes(Info.Items[t].TagClass1), 0); if (testClass == TagClassString && test[0] == tag) { con = true; } else { t += 1; } }while (con == false); CompUtil.PutUShort(ref TagBuff, (uint)(0x04 + (sc * Size)), (ushort)Info.Items[t].IndexID1); CompUtil.PutUShort(ref TagBuff, (uint)(0x06 + (sc * Size)), (ushort)Info.Items[t].IndexID2); } break; #endregion case TSFReader.TSFSoundData: // "sounddata": #region SoundData uint sRawSize = CompUtil.GetUInt(TagBuff, (uint)(sr.GetOIP() + (sc * Size))); uint sRawOffset = CompUtil.GetUInt(TagBuff, (uint)(sr.GetUName() + 4 + (sc * Size))); byte[] stmp = new byte[sRawSize]; uint svSndPos = (uint)BSPFile.Position + 0x800; CompUtil.PutUInt(ref TagBuff, (uint)(sr.GetUName() + 4 + (sc * Size)), svSndPos); FI.Read(stmp, 0, stmp.Length); BSPFile.Write(stmp, 0, stmp.Length); CompUtil.Fix0x100Position(ref BSPFile); stmp = null; break; #endregion case TSFReader.TSFEnd: // "end": #region EndStructure if (sr.GetOIP() == Name) { ExitStruct = true; } else { ExitStruct = false; } break; #endregion } }while(ExitStruct == false); if (Count != 0) { sc += 1; if (sc != Count) { sr.Seek(StartOfStruct); ExitStruct = false; } } }while(sc != Count); long tmpPosSave = FO.Position; FO.Seek(StructPosition, SeekOrigin.Begin); FO.Write(TagBuff, 0, TagBuff.Length); FO.Seek(tmpPosSave, SeekOrigin.Begin); }