Exemplo n.º 1
0
		void DebugVertices(StreamWriter s, Render.VertexBufferInterface.VertexBuffersGen3 gr, bool denormalize,
			Render.VertexBufferInterface.VertexBuffersGen3.Definition def,
			s_tag_d3d_vertex_buffer vb)
		{
			var stream_r = new Render.VertexBufferInterface.StreamReader(def);

			using (var er = new IO.EndianReader(vb.VertexBuffer.Value, IO.EndianState.Big, this))
			{
				for (int x = 0; x < vb.VertexCount.Value; x++) // foreach vertex...
				{
					s.WriteLine("\tVertex\t{0}", x.ToString("X8"));
					{
						stream_r.Read(er);
						if (denormalize)
						{
							foreach (string str in stream_r.GetDenormalizedStrings())
								s.WriteLine("\t\t{0}", str);
						}
						else
							foreach (string str in stream_r.GetNormalizedStrings())
								s.WriteLine("\t\t{0}", str);
					}
					s.WriteLine();
				}
				s.WriteLine(); s.WriteLine();
			}
		}
Exemplo n.º 2
0
		void DebugVerticesOld(StreamWriter s, Render.VertexBufferInterface.VertexBuffersGen3 gr, bool denormalize,
			Render.VertexBufferInterface.VertexBuffersGen3.Definition def,
			s_tag_d3d_vertex_buffer vb)
		{
			LowLevel.Math.real_quaternion quat;

			var elements = new Render.DeclarationTypes.IDeclType[def.Elements.Length];
			for (int x = 0; x < elements.Length; x++)
				elements[x] = def.Elements[x].DeclarationType.AllocateDeclType();

			using (var er = new IO.EndianReader(vb.VertexBuffer.Value, IO.EndianState.Big, this))
			{
				for (int x = 0; x < vb.VertexCount.Value; x++) // foreach vertex...
				{
					s.WriteLine("\tVertex\t{0}", x.ToString("X8"));
					foreach (Render.DeclarationTypes.IDeclType dt in elements) // and foreach type in the vertex...
					{
						dt.Read(er); // load the type data
						if (denormalize)
						{
							dt.Denormalize(out quat);
							s.WriteLine("\t\t{0}", dt.ToString(quat));
						}
						else s.WriteLine("\t\t{0}", dt.ToString());
						s.Flush();
					}
					s.WriteLine();
				}
				s.WriteLine(); s.WriteLine();
			}
		}
Exemplo n.º 3
0
        /// <summary>
        /// Constructs a new EndianStream based off of a Stream object.
        /// </summary>
        /// <param name="stream">The Stream to use. It must at least be available for reading or writing.</param>
        /// <param name="endianness">The endianness to use when performing I/O operations.</param>
        public EndianStream(Stream stream, Endian endianness)
        {
            _stream = stream;
            if (stream.CanRead)
                _reader = new EndianReader(stream, endianness);
            if (stream.CanWrite)
                _writer = new EndianWriter(stream, endianness);

            if (_reader == null && _writer == null)
                throw new ArgumentException("The input stream cannot be read from or written to.");
        }
Exemplo n.º 4
0
        public bool ReadETOC(EndianReader br, ulong startoffset)
        {
            br.BaseStream.Seek((long)startoffset, SeekOrigin.Begin);

            if (tools.ReadCString(br, 4) != "ETOC")
            {
                br.Close();
                return false;
            }

            //br.BaseStream.Seek(0xC, SeekOrigin.Current); //skip header data

            ReadUTFData(br);

            ETOC_packet = utf_packet;

            FileEntry etoc_entry = FileTable.Where(x => x.FileName.ToString() == "ETOC_HDR").Single();
            etoc_entry.Encrypted = isUtfEncrypted;
            etoc_entry.FileSize = ETOC_packet.Length;

            MemoryStream ms = new MemoryStream(utf_packet);
            EndianReader utfr = new EndianReader(ms, false);

            files = new UTF(tools);
            if (!files.ReadUTF(utfr))
            {
                br.Close();
                return false;
            }

            utfr.Close();
            ms.Close();

            List<FileEntry> fileEntries = FileTable.Where(x => x.FileType == "FILE").ToList();

            for (int i = 0; i < fileEntries.Count; i++)
            {
                FileTable[i].LocalDir = GetColumnData(files, i, "LocalDir");
                FileTable[i].UpdateDateTime = (ulong)GetColumnData(files, i, "UpdateDateTime");
            }

            return true;
        }
Exemplo n.º 5
0
        public bool ReadCPK(string sPath)
        {
            if (File.Exists(sPath))
            {
                uint Files;
                ushort Align;

                EndianReader br = new EndianReader(File.OpenRead(sPath), true);
                MemoryStream ms;
                EndianReader utfr;

                if (tools.ReadCString(br, 4) != "CPK ")
                {
                    br.Close();
                    return false;
                }

                ReadUTFData(br);

                CPK_packet = utf_packet;

                FileEntry CPAK_entry = new FileEntry
                {
                    FileName = "CPK_HDR",
                    FileOffsetPos = br.BaseStream.Position + 0x10,
                    FileSize = CPK_packet.Length,
                    Encrypted = isUtfEncrypted,
                    FileType = "CPK"
                };

                FileTable.Add(CPAK_entry);

                ms = new MemoryStream(utf_packet);
                utfr = new EndianReader(ms, false);

                utf = new UTF(tools);
                if (!utf.ReadUTF(utfr))
                {
                    br.Close();
                    return false;
                }

                utfr.Close();
                ms.Close();

                cpkdata = new Dictionary<string, object>();

                try
                {
                    for (int i = 0; i < utf.columns.Count; i++)
                    {
                        cpkdata.Add(utf.columns[i].name, utf.rows[0].rows[i].GetValue());
                    }
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.ToString());
                    Console.WriteLine(ex.ToString());
                }

                TocOffset = (ulong)GetColumsData2(utf, 0, "TocOffset", 3);
                long TocOffsetPos = GetColumnPostion(utf, 0, "TocOffset");

                EtocOffset = (ulong)GetColumsData2(utf, 0, "EtocOffset", 3);
                long ETocOffsetPos = GetColumnPostion(utf, 0, "EtocOffset");

                ItocOffset = (ulong)GetColumsData2(utf, 0, "ItocOffset", 3);
                long ITocOffsetPos = GetColumnPostion(utf, 0, "ItocOffset");

                GtocOffset = (ulong)GetColumsData2(utf, 0, "GtocOffset", 3);
                long GTocOffsetPos = GetColumnPostion(utf, 0, "GtocOffset");

                ContentOffset = (ulong)GetColumsData2(utf, 0, "ContentOffset", 3);
                long ContentOffsetPos = GetColumnPostion(utf, 0, "ContentOffset");
                FileTable.Add(CreateFileEntry("CONTENT_OFFSET", ContentOffset, typeof(ulong), ContentOffsetPos, "CPK", "CONTENT", false));

                Files = (uint)GetColumsData2(utf, 0, "Files", 2);
                Align = (ushort)GetColumsData2(utf, 0, "Align", 1);

                if (TocOffset != 0xFFFFFFFFFFFFFFFF)
                {
                    FileEntry entry = CreateFileEntry("TOC_HDR", TocOffset, typeof(ulong), TocOffsetPos, "CPK", "HDR", false);
                    FileTable.Add(entry);

                    if (!ReadTOC(br, TocOffset, ContentOffset))
                        return false;
                }

                if (EtocOffset != 0xFFFFFFFFFFFFFFFF)
                {
                    FileEntry entry = CreateFileEntry("ETOC_HDR", EtocOffset, typeof(ulong), ETocOffsetPos, "CPK", "HDR", false);
                    FileTable.Add(entry);

                    if (!ReadETOC(br, EtocOffset))
                        return false;
                }

                if (ItocOffset != 0xFFFFFFFFFFFFFFFF)
                {
                    //FileEntry ITOC_entry = new FileEntry {
                    //    FileName = "ITOC_HDR",
                    //    FileOffset = ItocOffset, FileOffsetType = typeof(ulong), FileOffsetPos = ITocOffsetPos,
                    //    TOCName = "CPK",
                    //    FileType = "FILE", Encrypted = true,
                    //};

                    FileEntry entry = CreateFileEntry("ITOC_HDR", ItocOffset, typeof(ulong), ITocOffsetPos, "CPK", "HDR", false);
                    FileTable.Add(entry);

                    if (!ReadITOC(br, ItocOffset, ContentOffset, Align))
                        return false;
                }

                if (GtocOffset != 0xFFFFFFFFFFFFFFFF)
                {
                    FileEntry entry = CreateFileEntry("GTOC_HDR", GtocOffset, typeof(ulong), GTocOffsetPos, "CPK", "HDR", false);
                    FileTable.Add(entry);

                    if (!ReadGTOC(br, GtocOffset))
                        return false;
                }

                br.Close();

                // at this point, we should have all needed file info

                //utf = null;
                files = null;
                return true;
            }
            return false;
        }
Exemplo n.º 6
0
        public bool ReadUTF(EndianReader br)
        {
            long offset = br.BaseStream.Position;

            if (tools.ReadCString(br, 4) != "@UTF")
            {
                return false;
            }

            table_size = br.ReadInt32();
            rows_offset = br.ReadInt32();
            strings_offset = br.ReadInt32();
            data_offset = br.ReadInt32();

            // CPK Header & UTF Header are ignored, so add 8 to each offset
            rows_offset += (offset + 8);
            strings_offset += (offset + 8);
            data_offset += (offset + 8);

            table_name = br.ReadInt32();
            num_columns = br.ReadInt16();
            row_length = br.ReadInt16();
            num_rows = br.ReadInt32();

            //read Columns
            columns = new List<COLUMN>();
            COLUMN column;

            for (int i = 0; i < num_columns; i++)
            {
                column = new COLUMN();
                column.flags = br.ReadByte();
                if (column.flags == 0)
                {
                    br.BaseStream.Seek(3, SeekOrigin.Current);
                    column.flags = br.ReadByte();
                }

                column.name = tools.ReadCString(br, -1, (long)(br.ReadInt32() + strings_offset));
                columns.Add(column);
            }

            //read Rows

            rows = new List<ROWS>();
            ROWS current_entry;
            ROW current_row;
            int storage_flag;

            for (int j = 0; j < num_rows; j++)
            {
                br.BaseStream.Seek(rows_offset + (j * row_length), SeekOrigin.Begin);

                current_entry = new ROWS();

                for (int i = 0; i < num_columns; i++)
                {
                    current_row = new ROW();

                    storage_flag = (columns[i].flags & (int)COLUMN_FLAGS.STORAGE_MASK);

                    if (storage_flag == (int)COLUMN_FLAGS.STORAGE_NONE) // 0x00
                    {
                        current_entry.rows.Add(current_row);
                        continue;
                    }

                    if (storage_flag == (int)COLUMN_FLAGS.STORAGE_ZERO) // 0x10
                    {
                        current_entry.rows.Add(current_row);
                        continue;
                    }

                    if (storage_flag == (int)COLUMN_FLAGS.STORAGE_CONSTANT) // 0x30
                    {
                        current_entry.rows.Add(current_row);
                        continue;
                    }

                    // 0x50

                    current_row.type = columns[i].flags & (int)COLUMN_FLAGS.TYPE_MASK;

                    current_row.position = br.BaseStream.Position;

                    switch (current_row.type)
                    {
                        case 0:
                        case 1:
                            current_row.uint8 = br.ReadByte();
                            break;

                        case 2:
                        case 3:
                            current_row.uint16 = br.ReadUInt16();
                            break;

                        case 4:
                        case 5:
                            current_row.uint32 = br.ReadUInt32();
                            break;

                        case 6:
                        case 7:
                            current_row.uint64 = br.ReadUInt64();
                            break;

                        case 8:
                            current_row.ufloat = br.ReadSingle();
                            break;

                        case 0xA:
                            current_row.str = tools.ReadCString(br, -1, br.ReadInt32() + strings_offset);
                            break;

                        case 0xB:
                            long position = br.ReadInt32() + data_offset;
                            current_row.position = position;
                            current_row.data = tools.GetData(br, position, br.ReadInt32());
                            break;

                        default: throw new NotImplementedException();
                    }

                    current_entry.rows.Add(current_row);
                }

                rows.Add(current_entry);
            }

            return true;
        }
Exemplo n.º 7
0
        public byte[] DecompressCRILAYLA(byte[] input, int USize)
        {
            byte[] result;// = new byte[USize];

            MemoryStream ms = new MemoryStream(input);
            EndianReader br = new EndianReader(ms, true);

            br.BaseStream.Seek(8, SeekOrigin.Begin); // Skip CRILAYLA
            int uncompressed_size = br.ReadInt32();
            int uncompressed_header_offset = br.ReadInt32();
            result = new byte[uncompressed_size + 0x100];

            // do some error checks here.........

            // copy uncompressed 0x100 header to start of file
            Array.Copy(input, uncompressed_header_offset + 0x10, result, 0, 0x100);

            int input_end = input.Length - 0x100 - 1;
            int input_offset = input_end;
            int output_end = 0x100 + uncompressed_size - 1;
            byte bit_pool = 0;
            int bits_left = 0, bytes_output = 0;
            int[] vle_lens = new int[4] { 2, 3, 5, 8 };

            while (bytes_output < uncompressed_size)
            {
                if (get_next_bits(input, ref input_offset, ref  bit_pool, ref bits_left, 1) > 0)
                {
                    int backreference_offset = output_end - bytes_output + get_next_bits(input, ref input_offset, ref  bit_pool, ref bits_left, 13) + 3;
                    int backreference_length = 3;
                    int vle_level;

                    for (vle_level = 0; vle_level < vle_lens.Length; vle_level++)
                    {
                        int this_level = get_next_bits(input, ref input_offset, ref  bit_pool, ref bits_left, vle_lens[vle_level]);
                        backreference_length += this_level;
                        if (this_level != ((1 << vle_lens[vle_level]) - 1)) break;
                    }

                    if (vle_level == vle_lens.Length)
                    {
                        int this_level;
                        do
                        {
                            this_level = get_next_bits(input, ref input_offset, ref  bit_pool, ref bits_left, 8);
                            backreference_length += this_level;
                        } while (this_level == 255);
                    }

                    for (int i = 0; i < backreference_length; i++)
                    {
                        result[output_end - bytes_output] = result[backreference_offset--];
                        bytes_output++;
                    }
                }
                else
                {
                    // verbatim byte
                    result[output_end - bytes_output] = (byte)get_next_bits(input, ref input_offset, ref  bit_pool, ref bits_left, 8);
                    bytes_output++;
                }
            }

            br.Close();
            ms.Close();

            return result;
        }
Exemplo n.º 8
0
		/// <summary>
		/// Closes the file manager's streams
		/// </summary>
		public void Close()
		{
			if (this.InputStream != null) { InputStream.Close(); InputStream = null; }
			if (this.OutputStream != null) { OutputStream.Close(); OutputStream = null; }
		}
Exemplo n.º 9
0
        public bool ReadTOC(EndianReader br, ulong TocOffset, ulong ContentOffset)
        {
            ulong add_offset = 0;

            if (ContentOffset < 0)
                add_offset = TocOffset;
            else
            {
                if (TocOffset < 0)
                    add_offset = ContentOffset;
                else
                {
                    if (ContentOffset < TocOffset)
                        add_offset = ContentOffset;
                    else
                        add_offset = TocOffset;
                }
            }

            br.BaseStream.Seek((long)TocOffset, SeekOrigin.Begin);

            if (tools.ReadCString(br, 4) != "TOC ")
            {
                br.Close();
                return false;
            }

            ReadUTFData(br);

            // Store unencrypted TOC
            TOC_packet = utf_packet;

            FileEntry toc_entry = FileTable.Where(x => x.FileName.ToString() == "TOC_HDR").Single();
            toc_entry.Encrypted = isUtfEncrypted;
            toc_entry.FileSize = TOC_packet.Length;

            MemoryStream ms = new MemoryStream(utf_packet);
            EndianReader utfr = new EndianReader(ms, false);

            files = new UTF(tools);
            if (!files.ReadUTF(utfr))
            {
                br.Close();
                return false;
            }

            utfr.Close();
            ms.Close();

            FileEntry temp;
            for (int i = 0; i < files.num_rows; i++)
            {
                temp = new FileEntry();

                temp.TOCName = "TOC";

                temp.DirName = GetColumnData(files, i, "DirName");
                temp.FileName = GetColumnData(files, i, "FileName");

                temp.FileSize = GetColumnData(files, i, "FileSize");
                temp.FileSizePos = GetColumnPostion(files, i, "FileSize");
                temp.FileSizeType = GetColumnType(files, i, "FileSize");

                temp.ExtractSize = GetColumnData(files, i, "ExtractSize");
                temp.ExtractSizePos = GetColumnPostion(files, i, "ExtractSize");
                temp.ExtractSizeType = GetColumnType(files, i, "ExtractSize");

                temp.FileOffset = ((ulong)GetColumnData(files, i, "FileOffset") + (ulong)add_offset);
                temp.FileOffsetPos = GetColumnPostion(files, i, "FileOffset");
                temp.FileOffsetType = GetColumnType(files, i, "FileOffset");

                temp.FileType = "FILE";

                temp.Offset = add_offset;

                temp.ID = GetColumnData(files, i, "ID");
                temp.UserString = GetColumnData(files, i, "UserString");

                FileTable.Add(temp);
            }
            files = null;

            return true;
        }
Exemplo n.º 10
0
		protected DataCacheFile(BlamVersion engine, string path)
		{
			if (!SharableReferencePc(path) && !SharableReferenceCe(path))
			{
				InputStream = new IO.EndianReader(path, IO.EndianState.Little, this);
				if (!CacheIsReadonly(path))
					OutputStream = new IO.EndianWriter(path, IO.EndianState.Little, this);
			}

			cacheIndex = new DataIndex();

			engineVersion = engine;
		}
Exemplo n.º 11
0
		protected CacheFileBase(string map_name)
		{
			InputStream = new IO.EndianReader(map_name, IO.EndianState.Little, this);
			if (!CacheIsReadonly(map_name))
				OutputStream = new IO.EndianWriter(map_name, IO.EndianState.Little, this);
		}
Exemplo n.º 12
0
		protected CacheFileBase(string map_name)
		{
			if (!SharableReferenceXbox(map_name) && !SharableReferencePc(map_name))
			{
				InputStream = new IO.EndianReader(map_name, IO.EndianState.Big, this);
				if (!CacheIsReadonly(map_name))
					OutputStream = new IO.EndianWriter(map_name, IO.EndianState.Big, this);
			}

			cacheHeader = new CacheHeader();
		}
Exemplo n.º 13
0
			internal TI.Definition LoadResources(CacheFileGen3 c, cache_file_resource_gestalt_group owner, cache_file_resource_layout_table cache_layout, bool mega_hack)
			{
				if (Reference.Datum == DatumIndex.Null) return null; // this is a null entry
				if (loadedResources != null) return loadedResources; // data already loaded, return

				var rdf = c.GetCacheFileResourceDefinitionFactory();

				// pre-process cache for resource loading
				cache_layout.BuildInteropData();
				owner.BuildInteropData();

				int resource_stream_definition_size = BlockSize.Value;
				
				// sound resource case hack
				bool use_sound_resource_hack = false;
				if (resource_stream_definition_size == 0)
				{
					Debug.Assert.If(ResourceType.Value == owner.resource_index_sound_resource_definition);
					resource_stream_definition_size = sound_resource_definition.kSizeOf;
					use_sound_resource_hack = true;
				}

				int resource_stream_size_required = resource_stream_definition_size;
				// base address to use on cache fixups, cache data will be appended 
				// later on
				uint cache_required_base_address = 0, cache_optional_base_address = 0;
				byte[] resource_stream_data;

				#region create resource buffer
				{// Get our page segment data so we can build our resource buffer for loading
					int seg_index = SegmentIndex.Value;
					cache_file_resource_layout_table.page_segment_block page_segment = cache_layout.PageSegments[seg_index];
					int required_size = page_segment.GetRequiredSize();
					int optional_size = page_segment.GetOptionalSize();

					cache_required_base_address = (uint)resource_stream_size_required;
					if (required_size > 0) resource_stream_size_required += required_size;

					if (optional_size > 0) // optional isn't always used so don't set the base address if it isn't
					{
						cache_optional_base_address = (uint)resource_stream_size_required;
						resource_stream_size_required += optional_size;
					}

					// get our definition data buffer
					resource_stream_data = new byte[resource_stream_size_required];
					if (use_sound_resource_hack) // sound_resources don't occupy space in the resource-definition-data, so we have to create faux def data
					{
						int data_size = 0;
						if (required_size > 0) data_size += required_size;
						if (optional_size > 0) data_size += optional_size;
						if (data_size > 0) rdf.InsertDataSizeIntoFauxDefinitionData(resource_stream_data, (uint)data_size);
					}
					else
						Array.Copy(owner.ResourceDefinitionData.Value, BlockOffset.Value, resource_stream_data, 0, resource_stream_definition_size);

					{ // get cache data and append it
						byte[] page_data = 
							cache_layout.Pages[page_segment.RequiredPageIndex.Value].GetSegmentData(c, cache_layout, page_segment.RequiredSegmentOffset.Value);

						Array.Copy(page_data, 0, resource_stream_data, (int)cache_required_base_address, required_size);

						if (page_segment.OptionalPageIndex.Value >=0 && cache_optional_base_address > 0)
						{
							page_data = cache_layout.Pages[page_segment.OptionalPageIndex.Value].GetSegmentData(c, cache_layout, page_segment.OptionalSegmentOffset.Value);
							Array.Copy(page_data, 0, resource_stream_data, (int)cache_optional_base_address, optional_size);
						}
					}
				}
				#endregion

				Util.OptionalValue optv = new Util.OptionalValue((byte)resource_fixup_type.Count);

				#region perform fixups
				using (var ms = new System.IO.MemoryStream(resource_stream_data, true))
				{
					foreach (resource_fixup_block def in ResourceFixups)
					{
						uint address = (uint)def.Address.Value;
						uint address_offset = optv.GetValue(address);
						ms.Seek(def.BlockOffset.Value, System.IO.SeekOrigin.Begin);
						resource_fixup_type rft = (resource_fixup_type)optv.GetOption(address);

						switch (rft)
						{
							case resource_fixup_type.Data: break;
							case resource_fixup_type.CacheRequired: address_offset += cache_required_base_address; break;
							case resource_fixup_type.CacheOptional: address_offset += cache_optional_base_address; break;

							default: throw new Debug.Exceptions.UnreachableException();
						}

						IO.ByteSwap.SwapUDWordAndWrite(address_offset, ms);
						
						// hack identifier for StructReference fields when the definition is at offset '0' 
						// as that f***s with the init code
						//if (address_offset == 0) IO.ByteSwap.SwapUDWordAndWrite(1, ms);
					}

//					foreach (resource_definition_fixup_block def in ResourceDefinitionFixups)
//					{
//					}
				}
				#endregion

				#region create and stream definition
				using (var s = new IO.EndianReader(resource_stream_data, IO.EndianState.Big, null))
				{
					int res_type = ResourceType.Value;
					if (res_type == owner.resource_index_render_geometry_api_resource_definition)			loadedResources = rdf.GenerateRenderGeometryApiResource();
					else if (res_type == owner.resource_index_bitmap_texture_interop_resource)				loadedResources = rdf.GenerateBitmapTextureInteropResource();
					else if (res_type == owner.resource_index_model_animation_tag_resource)					loadedResources = rdf.GenerateModelAnimationTagResource();
					// TODO: haven't quite figured this one out yet. Currently using hacked up code (see [use_sound_resource_hack])
					else if (res_type == owner.resource_index_sound_resource_definition)					loadedResources = rdf.GenerateSoundResourceResource();
					else if (res_type == owner.resource_index_bitmap_texture_interleaved_interop_resource)	loadedResources = rdf.GenerateBitmapTextureInterleavedInteropResource();
					else if (res_type == owner.resource_index_structure_bsp_tag_resources)					loadedResources = rdf.GenerateStructureBspTagResource();
					// TODO: haven't figured this one out yet
					else if (res_type == owner.resource_index_structure_bsp_cache_file_tag_resources)		loadedResources = rdf.GenerateStructureBspCacheFileTagResource();
					else throw new Debug.Exceptions.UnreachableException();

					s.Seek(optv.GetValue((uint)DefinitionOffset.Value));
					IO.ITagStream ts = new resource_tag_stream(c, Reference.Datum, s);

					ts.Flags.Add(
						IO.ITagStreamFlags.UseStreamPositions |
						IO.ITagStreamFlags.DontStreamStringData |
						IO.ITagStreamFlags.DontStreamFieldSetHeader |
						IO.ITagStreamFlags.DontPostprocess);
					if (mega_hack) ts.Flags.Add(IO.ITagStreamFlags.Halo3VertexBufferMegaHack);
					loadedResources.Read(ts);
				}
				#endregion

				return loadedResources;
			}
Exemplo n.º 14
0
        public bool ReadGTOC(EndianReader br, ulong startoffset)
        {
            br.BaseStream.Seek((long)startoffset, SeekOrigin.Begin);

            if (tools.ReadCString(br, 4) != "GTOC")
            {
                br.Close();
                return false;
            }

            br.BaseStream.Seek(0xC, SeekOrigin.Current); //skip header data

            return true;
        }
Exemplo n.º 15
0
		/// <summary>
		/// Creates the file
		/// </summary>
		/// <remarks>Closes existing file streams</remarks>
		public void Create()
		{
			string dir = System.IO.Path.GetDirectoryName(path);
			if (!System.IO.Directory.Exists(dir)) System.IO.Directory.CreateDirectory(dir);

			if (!System.IO.File.Exists(path)) System.IO.File.Create(path).Close();

			if (InputStream != null) { InputStream.Close(); InputStream = null; }
			if (OutputStream != null) { OutputStream.Close(); OutputStream = null; }
		}
Exemplo n.º 16
0
        public bool ReadITOC(EndianReader br, ulong startoffset, ulong ContentOffset, ushort Align)
        {
            br.BaseStream.Seek((long)startoffset, SeekOrigin.Begin);

            if (tools.ReadCString(br, 4) != "ITOC")
            {
                br.Close();
                return false;
            }

            ReadUTFData(br);

            ITOC_packet = utf_packet;

            FileEntry itoc_entry = FileTable.Where(x => x.FileName.ToString() == "ITOC_HDR").Single();
            itoc_entry.Encrypted = isUtfEncrypted;
            itoc_entry.FileSize = ITOC_packet.Length;

            MemoryStream ms = new MemoryStream(utf_packet);
            EndianReader utfr = new EndianReader(ms, false);

            files = new UTF(tools);
            if (!files.ReadUTF(utfr))
            {
                br.Close();
                return false;
            }

            utfr.Close();
            ms.Close();

            //uint FilesL = (uint)GetColumnData(files, 0, "FilesL");
            //uint FilesH = (uint)GetColumnData(files, 0, "FilesH");
            byte[] DataL = (byte[])GetColumnData(files, 0, "DataL");
            long DataLPos = GetColumnPostion(files, 0, "DataL");

            byte[] DataH = (byte[])GetColumnData(files, 0, "DataH");
            long DataHPos = GetColumnPostion(files, 0, "DataH");

            //MemoryStream ms;
            //EndianReader ir;
            UTF utfDataL, utfDataH;
            Dictionary<int, uint> SizeTable, CSizeTable;
            Dictionary<int, long> SizePosTable, CSizePosTable;
            Dictionary<int, Type> SizeTypeTable, CSizeTypeTable;

            List<int> IDs = new List<int>();

            SizeTable = new Dictionary<int, uint>();
            SizePosTable = new Dictionary<int, long>();
            SizeTypeTable = new Dictionary<int, Type>();

            CSizeTable = new Dictionary<int, uint>();
            CSizePosTable = new Dictionary<int, long>();
            CSizeTypeTable = new Dictionary<int, Type>();

            ushort ID, size1;
            uint size2;
            long pos;
            Type type;

            if (DataL != null)
            {
                ms = new MemoryStream(DataL);
                utfr = new EndianReader(ms, false);
                utfDataL = new UTF(tools);
                utfDataL.ReadUTF(utfr);

                for (int i = 0; i < utfDataL.num_rows; i++)
                {
                    ID = (ushort)GetColumnData(utfDataL, i, "ID");
                    size1 = (ushort)GetColumnData(utfDataL, i, "FileSize");
                    SizeTable.Add((int)ID, (uint)size1);

                    pos = GetColumnPostion(utfDataL, i, "FileSize");
                    SizePosTable.Add((int)ID, pos + DataLPos);

                    type = GetColumnType(utfDataL, i, "FileSize");
                    SizeTypeTable.Add((int)ID, type);

                    if ((GetColumnData(utfDataL, i, "ExtractSize")) != null)
                    {
                        size1 = (ushort)GetColumnData(utfDataL, i, "ExtractSize");
                        CSizeTable.Add((int)ID, (uint)size1);

                        pos = GetColumnPostion(utfDataL, i, "ExtractSize");
                        CSizePosTable.Add((int)ID, pos + DataLPos);

                        type = GetColumnType(utfDataL, i, "ExtractSize");
                        CSizeTypeTable.Add((int)ID, type);
                    }

                    IDs.Add(ID);
                }
            }

            if (DataH != null)
            {
                ms = new MemoryStream(DataH);
                utfr = new EndianReader(ms, false);
                utfDataH = new UTF(tools);
                utfDataH.ReadUTF(utfr);

                for (int i = 0; i < utfDataH.num_rows; i++)
                {
                    ID = (ushort)GetColumnData(utfDataH, i, "ID");
                    size2 = (uint)GetColumnData(utfDataH, i, "FileSize");
                    SizeTable.Add(ID, size2);

                    pos = GetColumnPostion(utfDataH, i, "FileSize");
                    SizePosTable.Add((int)ID, pos + DataHPos);

                    type = GetColumnType(utfDataH, i, "FileSize");
                    SizeTypeTable.Add((int)ID, type);

                    if ((GetColumnData(utfDataH, i, "ExtractSize")) != null)
                    {
                        size2 = (uint)GetColumnData(utfDataH, i, "ExtractSize");
                        CSizeTable.Add(ID, size2);

                        pos = GetColumnPostion(utfDataH, i, "ExtractSize");
                        CSizePosTable.Add((int)ID, pos + DataHPos);

                        type = GetColumnType(utfDataH, i, "ExtractSize");
                        CSizeTypeTable.Add((int)ID, type);
                    }

                    IDs.Add(ID);
                }
            }

            FileEntry temp;
            //int id = 0;
            uint value = 0, value2 = 0;
            ulong baseoffset = ContentOffset;

            // Seems ITOC can mix up the IDs..... but they'll alwaysy be in order...
            IDs = IDs.OrderBy(x => x).ToList();

            for (int i = 0; i < IDs.Count; i++)
            {
                int id = IDs[i];

                temp = new FileEntry();
                SizeTable.TryGetValue(id, out value);
                CSizeTable.TryGetValue(id, out value2);

                temp.TOCName = "ITOC";

                temp.DirName = null;
                temp.FileName = id.ToString("D4");

                temp.FileSize = value;
                temp.FileSizePos = SizePosTable[id];
                temp.FileSizeType = SizeTypeTable[id];

                if (CSizeTable.Count > 0 && CSizeTable.ContainsKey(id))
                {
                    temp.ExtractSize = value2;
                    temp.ExtractSizePos = CSizePosTable[id];
                    temp.ExtractSizeType = CSizeTypeTable[id];
                }

                temp.FileType = "FILE";

                temp.FileOffset = baseoffset;
                temp.ID = id;
                temp.UserString = null;

                FileTable.Add(temp);

                if ((value % Align) > 0)
                    baseoffset += value + (Align - (value % Align));
                else
                    baseoffset += value;

                //id++;
            }

            files = null;
            utfDataL = null;
            utfDataH = null;

            ms.Close();
            utfr.Close();

            return true;
        }
Exemplo n.º 17
0
		/// <summary>
		/// Opens the file for reading and writing
		/// </summary>
		/// <remarks>Closes existing file streams</remarks>
		public void OpenForReadWrite()
		{
			Close();

			InputStream = new BlamLib.IO.EndianReader(path, endianState, this);
			OutputStream = new BlamLib.IO.EndianWriter(path, endianState, this);

			SetupBaseAddress();
		}
Exemplo n.º 18
0
        private void ReadUTFData(EndianReader br)
        {
            isUtfEncrypted = false;
            br.IsLittleEndian = true;

            unk1 = br.ReadInt32();
            utf_size = br.ReadInt64();
            utf_packet = br.ReadBytes((int)utf_size);

            if (utf_packet[0] != 0x40 && utf_packet[1] != 0x55 && utf_packet[2] != 0x54 && utf_packet[3] != 0x46) //@UTF
            {
                utf_packet = DecryptUTF(utf_packet);
                isUtfEncrypted = true;
            }

            br.IsLittleEndian = false;
        }
Exemplo n.º 19
0
		public void SetupParse()
		{
			GameMan.Namespace n;
			GameMan.Platform p;
			GameMan.FromBlamVersion(engine, out n, out p);

			InputStream = new BlamLib.IO.EndianReader(
				GameMan.GetPlatformFolderPath(
				n, 
				p, 
				BlamLib.Managers.GameManager.PlatformFolder.Definitions_TDF
				) + groupTag.Name + "." + Ext, 
				BlamLib.IO.EndianState.Little, this);
		}