diff options
Diffstat (limited to 'WADEntry.cs')
| -rw-r--r-- | WADEntry.cs | 143 | 
1 files changed, 143 insertions, 0 deletions
| diff --git a/WADEntry.cs b/WADEntry.cs new file mode 100644 index 0000000..d43da68 --- /dev/null +++ b/WADEntry.cs @@ -0,0 +1,143 @@ +// Noddybox.DOOM - DOOM WAD Wrapper +// Copyright (C) 2004  Ian Cowburn +//  +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +//  +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +// GNU General Public License for more details. +//  +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. +// +using System; +using System.IO; + +namespace Noddybox.DOOM +{ +	/// <summary> +	/// Describes a directory entry in a WAD file +	/// </summary> +	public class WADEntry +	{ +		// ==================================== +		// PUBLIC +		// ==================================== + +		/// <summary> +		/// Create an empty lump +		/// </summary> +		public WADEntry() +		{ +			Name="LUMP"; +			Data=null; +		} + +		/// <summary> +		/// Create a lump +		/// </summary> +		/// <param name="name">The name</param> +		/// <param name="data">The data</param> +		public WADEntry(string name, byte[] data) +		{ +			Name=name; +			Data=data; +		} +		 +		/// <summary> +		/// Create a lump +		/// </summary> +		/// <param name="we">The lump to copy</param> +		public WADEntry(WADEntry we) +		{ +			Name=we.Name; +			Data=(byte[])we.Data.Clone(); +		} +		 +		/// <summary> +		/// Get/set the lump's name +		/// </summary> +		public string Name +		{ +			get {return m_name;} +			set +			{ +				m_name=value; +				 +				if (m_name.Length>8) +				{ +					m_name=m_name.Substring(0,8); +				} +				 +				m_name=m_name.Trim(new char[] {'\0'}); +			} +		} +		 +		/// <summary> +		/// Get the length of the lump's data +		/// </summary> +		public int Length +		{ +			get {return m_length;} +		} +		 +		/// <summary> +		/// Get/set the lump data +		/// </summary> +		public byte[] Data +		{ +			get {return m_data;} +			set +			{ +				m_data=value; +				 +				if (m_data!=null) +				{ +					m_length=m_data.Length; +				} +				else +				{ +					m_length=0; +				} +			} +		} +		 +		/// <summary> +		/// Index into the lump data as bytes +		/// </summary> +		public byte this[int index] +		{ +			get {return m_data[index];} +			set {m_data[index]=value;} +		} +		 +		/// <summary> +		/// Index into the lump data as bytes +		/// </summary> +		public byte this[uint index] +		{ +			get {return m_data[index];} +			set {m_data[index]=value;} +		} +		 +		/// <summary> +		/// Get the lump data as a MemoryStream +		/// </summary> +		public MemoryStream Stream +		{ +			get {return new MemoryStream(m_data);} +		} +		 +		// ==================================== +		// PRIVATE +		// ==================================== +		private string		m_name; +		private int			m_length; +		private byte[]		m_data; +	} +} | 
