Ejemplo n.º 1
0
		static byte[] GenerateSoundFile(byte[] buffer, byte[] footer)
		{
			byte[] sound_file;

			using (MemoryStream ms = new MemoryStream())
			using (IO.EndianWriter write = new IO.EndianWriter(ms))
			{
				write.Write("RIFF", "RIFF".Length);
				write.Write(uint.MinValue);
				write.Write("WAVEdata", "WAVEdata".Length);
				write.Write(uint.MinValue);

				write.Write(buffer);

				if(footer != null)
					write.Write(footer);

				int size = (int)ms.Length;

				// Write file size to RIFF header
				write.Seek(4);
				write.Write(size - 8);

				// Write data size to WAVE header
				write.Seek(16);
				write.Write(buffer.Length);

				sound_file = ms.ToArray();
			}

			return sound_file;
		}
Ejemplo n.º 2
0
        public void UpdateValue(ref byte[] packet, object value, long pos, Type type)
        {
            MemoryStream temp = new MemoryStream();
            temp.Write(packet, 0, packet.Length);

            EndianWriter toc = new EndianWriter(temp, false);
            toc.Seek((int)pos, SeekOrigin.Begin);

            value = Convert.ChangeType(value, type);

            if (type == typeof(Byte))
            {
                toc.Write((Byte)value);
            }
            else if (type == typeof(UInt16))
            {
                toc.Write((UInt16)value);
            }
            else if (type == typeof(UInt32))
            {
                toc.Write((UInt32)value);
            }
            else if (type == typeof(UInt64))
            {
                toc.Write((UInt64)value);
            }
            else if (type == typeof(Single))
            {
                toc.Write((Single)value);
            }
            else
            {
                throw new Exception("Not supported type!");
            }

            toc.Close();

            MemoryStream myStream = (MemoryStream)toc.BaseStream;
            packet = myStream.ToArray();
        }
Ejemplo n.º 3
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; }
		}
Ejemplo n.º 4
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();
		}
Ejemplo n.º 5
0
		/// <summary>
		/// Creates the file and opens
		/// it for writing
		/// </summary>
		/// <remarks>Closes existing file streams</remarks>
		public void CreateForWrite()
		{
			Create();

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

			SetupBaseAddress();
		}
Ejemplo n.º 6
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; }
		}
Ejemplo n.º 7
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;
		}
Ejemplo n.º 8
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);
		}
Ejemplo n.º 9
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();
		}
Ejemplo n.º 10
0
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		/// <remarks>Caller must call the returned memory stream's <c>Close</c> method</remarks>
		protected System.IO.MemoryStream InitializeMemoryStream()
		{
			System.IO.MemoryStream mem = new System.IO.MemoryStream(); // the memory stream for writing all the data to a fixed base address
			MemoryStream = new IO.EndianWriter(mem, this); // Endian stream wrapper for memory stream
			MemoryStream.BaseAddress = OwnerState.Definition.MemoryInfo.BaseAddress;

			return mem;
		}
Ejemplo n.º 11
0
		public void Write(string folder, string filename)
		{
			using (IO.EndianWriter ew = new IO.EndianWriter(
					folder + System.IO.Path.GetFileNameWithoutExtension(filename) + ".CheApe.map",
					BlamLib.IO.EndianState.Little, this, true)
					)
			{
				Write(ew);
			}
		}
Ejemplo n.º 12
0
		public virtual void Dispose()
		{
			if(MemoryStream != null)
			{
				MemoryStream.Dispose();
				MemoryStream = null;
			}

			if(RamMemory != null)
			{
				RamMemory.Dispose();
				RamMemory = null;
			}
		}
Ejemplo n.º 13
0
		public virtual void Reset()
		{
			Dispose();

			Head = new CacheFileHeader(Head);

			DebugStrings = new Util.StringPool(true);
			RamMemory = new BlamLib.IO.EndianWriter(new System.IO.MemoryStream(1024), this);

			Locations.Clear();
		}
Ejemplo n.º 14
0
		protected Compiler(BlamVersion engine)
		{
			Head = new CacheFileHeader(engine);
			MemoryStream = null;
			OwnerState = null;

			DebugStrings = new Util.StringPool(true);
			RamMemory = new BlamLib.IO.EndianWriter(new System.IO.MemoryStream(1024), this);
		}
Ejemplo n.º 15
0
		/// <summary>Build debug streams which foreign native code can easily interop with</summary>
		/// <param name="offsets">Buffer containing the offsets of the string values in <paramref name="buffer"/></param>
		/// <param name="buffer">Buffer containing the string values</param>
		/// <param name="pack">If true, the strings are stored as null terminated strings, else in 128 character strings</param>
		/// <remarks>
		/// <paramref name="buffer"/> will most likely contain more bytes than needed for its data 
		/// so you may want to use <paramref name="buffer"/>.<see cref="System.IO.MemoryStream.ToArray()"/> 
		/// when writing the data to another stream. Note that ToArray returns a COPY of the underlying 
		/// byte[] so you, in some cases, may just want to use GetBuffer instead but use the 
		/// <see cref="System.IO.MemoryStream.Length"/> field (compared to <see cref="System.IO.MemoryStream.Capacity"/>) 
		/// to only write non-zero (ie, unused) bytes
		/// </remarks>
		public void GenerateDebugStream(out System.IO.MemoryStream offsets, out System.IO.MemoryStream buffer, bool pack)
		{
			int fixed_length = pack ? 0 : Definition.Description.ValueBufferSize; // TODO: figure out a good starting buffer size for packed

			int count = Count;
			offsets = new System.IO.MemoryStream(count * sizeof(int));
			buffer = new System.IO.MemoryStream(count * fixed_length);

			using (var offsets_s = new IO.EndianWriter(offsets))
			using (var buffer_s = new IO.EndianWriter(buffer))
			{
				m_staticCollection.ToDebugStream(offsets_s, buffer_s, pack);
				m_dynamicCollection.ToDebugStream(offsets_s, buffer_s, pack);
			}
		}
Ejemplo n.º 16
0
		public void SetupCreate()
		{
			GameMan.Namespace n;
			GameMan.Platform p;
			GameMan.FromBlamVersion(engine, out n, out p);

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