diff --git a/LibBSP/LibBSP.csproj b/LibBSP/LibBSP.csproj
index be37cf4..74526eb 100644
--- a/LibBSP/LibBSP.csproj
+++ b/LibBSP/LibBSP.csproj
@@ -72,13 +72,6 @@
-
-
-
-
-
-
-
diff --git a/LibBSP/Source/Extensions/UIVertexExtensions.cs b/LibBSP/Source/Extensions/UIVertexExtensions.cs
index 9256526..fef764b 100644
--- a/LibBSP/Source/Extensions/UIVertexExtensions.cs
+++ b/LibBSP/Source/Extensions/UIVertexExtensions.cs
@@ -82,11 +82,6 @@ namespace LibBSP {
}
UIVertex result = new UIVertex();
switch (type) {
- case MapType.Doom:
- case MapType.Hexen: {
- result.position = new Vector3(BitConverter.ToInt16(data, 0), BitConverter.ToInt16(data, 2));
- break;
- }
case MapType.MOHAA:
case MapType.Quake3:
case MapType.CoD:
@@ -151,11 +146,6 @@ namespace LibBSP {
}
int structLength = 0;
switch (type) {
- case MapType.Doom:
- case MapType.Hexen: {
- structLength = 4;
- break;
- }
case MapType.Quake:
case MapType.Nightfire:
case MapType.SiN:
diff --git a/LibBSP/Source/Structs/BSP/BSP.cs b/LibBSP/Source/Structs/BSP/BSP.cs
index 31ce8f1..fa9f6ec 100644
--- a/LibBSP/Source/Structs/BSP/BSP.cs
+++ b/LibBSP/Source/Structs/BSP/BSP.cs
@@ -23,8 +23,6 @@ namespace LibBSP {
STEF2 = 556942937,
MOHAA = 892416069,
// TYPE_MOHBT = 1095516506, // Similar enough to MOHAA to use the same structures and algorithm
- Doom = 1145132868, // "DWAD"
- Hexen = 1145132872, // "HWAD"
STEF2Demo = 1263223129,
FAKK = 1263223152,
TacticalInterventionEncrypted = 1268885814,
@@ -52,14 +50,13 @@ namespace LibBSP {
///
/// Holds data for any and all BSP formats. Any unused lumps in a given format
- /// will be left as null. Then it will be fed into a universal decompile method
- /// which should be able to perform its job based on what data is stored.
+ /// will be left as null.
///
public class BSP {
private MapType _version;
- private BSPReader reader;
+ private BSPReader _reader;
// Map structures
// Quake 1/GoldSrc
@@ -95,18 +92,13 @@ namespace LibBSP {
private GameLump _gameLump;
private SourceStaticProps _staticProps;
- ///
- /// An XOr encryption key for encrypted map formats. Must be read and set.
- ///
- public byte[] key = new byte[0];
-
///
/// The version of this BSP. DO NOT CHANGE THIS unless you want to force reading a BSP as a certain format.
///
public MapType version {
get {
if (_version == MapType.Undefined) {
- _version = reader.GetVersion();
+ _version = _reader.GetVersion();
}
return _version;
}
@@ -115,14 +107,14 @@ namespace LibBSP {
}
}
- public bool bigEndian { get { return reader.bigEndian; } }
+ public bool bigEndian { get { return _reader.bigEndian; } }
public Entities entities {
get {
if (_entities == null) {
int index = Entity.GetIndexForLump(version);
if (index >= 0) {
- _entities = Entity.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _entities = Entity.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _entities;
@@ -134,7 +126,7 @@ namespace LibBSP {
if (_planes == null) {
int index = PlaneExtensions.GetIndexForLump(version);
if (index >= 0) {
- _planes = PlaneExtensions.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _planes = PlaneExtensions.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _planes;
@@ -146,7 +138,7 @@ namespace LibBSP {
if (_textures == null) {
int index = Texture.GetIndexForLump(version);
if (index >= 0) {
- _textures = Texture.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _textures = Texture.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _textures;
@@ -158,7 +150,7 @@ namespace LibBSP {
if (_vertices == null) {
int index = UIVertexExtensions.GetIndexForLump(version);
if (index >= 0) {
- _vertices = UIVertexExtensions.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _vertices = UIVertexExtensions.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _vertices;
@@ -170,7 +162,7 @@ namespace LibBSP {
if (_nodes == null) {
int index = Node.GetIndexForLump(version);
if (index >= 0) {
- _nodes = Node.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _nodes = Node.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _nodes;
@@ -182,7 +174,7 @@ namespace LibBSP {
if (_texInfo == null) {
int index = TexInfo.GetIndexForLump(version);
if (index >= 0) {
- _texInfo = TexInfo.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _texInfo = TexInfo.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _texInfo;
@@ -194,7 +186,7 @@ namespace LibBSP {
if (_faces == null) {
int index = Face.GetIndexForLump(version);
if (index >= 0) {
- _faces = Face.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _faces = Face.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _faces;
@@ -206,7 +198,7 @@ namespace LibBSP {
if (_leaves == null) {
int index = Leaf.GetIndexForLump(version);
if (index >= 0) {
- _leaves = Leaf.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _leaves = Leaf.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _leaves;
@@ -218,7 +210,7 @@ namespace LibBSP {
if (_edges == null) {
int index = Edge.GetIndexForLump(version);
if (index >= 0) {
- _edges = Edge.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _edges = Edge.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _edges;
@@ -230,7 +222,7 @@ namespace LibBSP {
if (_models == null) {
int index = Model.GetIndexForLump(version);
if (index >= 0) {
- _models = Model.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _models = Model.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _models;
@@ -242,7 +234,7 @@ namespace LibBSP {
if (_brushes == null) {
int index = Brush.GetIndexForLump(version);
if (index >= 0) {
- _brushes = Brush.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _brushes = Brush.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _brushes;
@@ -254,7 +246,7 @@ namespace LibBSP {
if (_brushSides == null) {
int index = BrushSide.GetIndexForLump(version);
if (index >= 0) {
- _brushSides = BrushSide.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _brushSides = BrushSide.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _brushSides;
@@ -266,7 +258,7 @@ namespace LibBSP {
if (_materials == null) {
int index = Texture.GetIndexForMaterialLump(version);
if (index >= 0) {
- _materials = Texture.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _materials = Texture.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _materials;
@@ -278,7 +270,7 @@ namespace LibBSP {
if (_originalFaces == null) {
int index = Face.GetIndexForOriginalFacesLump(version);
if (index >= 0) {
- _originalFaces = Face.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _originalFaces = Face.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _originalFaces;
@@ -290,7 +282,7 @@ namespace LibBSP {
if (_texDatas == null) {
int index = SourceTexData.GetIndexForLump(version);
if (index >= 0) {
- _texDatas = SourceTexData.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _texDatas = SourceTexData.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _texDatas;
@@ -302,7 +294,7 @@ namespace LibBSP {
if (_dispInfos == null) {
int index = SourceDispInfo.GetIndexForLump(version);
if (index >= 0) {
- _dispInfos = SourceDispInfo.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _dispInfos = SourceDispInfo.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _dispInfos;
@@ -314,7 +306,7 @@ namespace LibBSP {
if (_dispVerts == null) {
int index = SourceDispVertex.GetIndexForLump(version);
if (index >= 0) {
- _dispVerts = SourceDispVertex.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _dispVerts = SourceDispVertex.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _dispVerts;
@@ -326,7 +318,7 @@ namespace LibBSP {
if (_cubemaps == null) {
int index = SourceCubemap.GetIndexForLump(version);
if (index >= 0) {
- _cubemaps = SourceCubemap.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _cubemaps = SourceCubemap.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _cubemaps;
@@ -339,7 +331,7 @@ namespace LibBSP {
NumList.DataType type;
int index = NumList.GetIndexForMarkSurfacesLump(version, out type);
if (index >= 0) {
- _markSurfaces = NumList.LumpFactory(reader.ReadLumpNum(index, version), type);
+ _markSurfaces = NumList.LumpFactory(_reader.ReadLumpNum(index, version), type);
}
}
return _markSurfaces;
@@ -352,7 +344,7 @@ namespace LibBSP {
NumList.DataType type;
int index = NumList.GetIndexForSurfEdgesLump(version, out type);
if (index >= 0) {
- _surfEdges = NumList.LumpFactory(reader.ReadLumpNum(index, version), type);
+ _surfEdges = NumList.LumpFactory(_reader.ReadLumpNum(index, version), type);
}
}
return _surfEdges;
@@ -365,7 +357,7 @@ namespace LibBSP {
NumList.DataType type;
int index = NumList.GetIndexForMarkBrushesLump(version, out type);
if (index >= 0) {
- _markBrushes = NumList.LumpFactory(reader.ReadLumpNum(index, version), type);
+ _markBrushes = NumList.LumpFactory(_reader.ReadLumpNum(index, version), type);
}
}
return _markBrushes;
@@ -378,7 +370,7 @@ namespace LibBSP {
NumList.DataType type;
int index = NumList.GetIndexForIndicesLump(version, out type);
if (index >= 0) {
- _indices = NumList.LumpFactory(reader.ReadLumpNum(index, version), type);
+ _indices = NumList.LumpFactory(_reader.ReadLumpNum(index, version), type);
}
}
return _indices;
@@ -391,7 +383,7 @@ namespace LibBSP {
NumList.DataType type;
int index = NumList.GetIndexForTexTableLump(version, out type);
if (index >= 0) {
- _texTable = NumList.LumpFactory(reader.ReadLumpNum(index, version), type);
+ _texTable = NumList.LumpFactory(_reader.ReadLumpNum(index, version), type);
}
}
return _texTable;
@@ -404,7 +396,7 @@ namespace LibBSP {
NumList.DataType type;
int index = NumList.GetIndexForDisplacementTrianglesLump(version, out type);
if (index >= 0) {
- _displacementTriangles = NumList.LumpFactory(reader.ReadLumpNum(index, version), type);
+ _displacementTriangles = NumList.LumpFactory(_reader.ReadLumpNum(index, version), type);
}
}
return _displacementTriangles;
@@ -416,7 +408,7 @@ namespace LibBSP {
if (_gameLump == null) {
int index = GameLump.GetIndexForLump(version);
if (index >= 0) {
- _gameLump = GameLump.LumpFactory(reader.ReadLumpNum(index, version), version);
+ _gameLump = GameLump.LumpFactory(_reader.ReadLumpNum(index, version), version);
}
}
return _gameLump;
@@ -498,9 +490,9 @@ namespace LibBSP {
/// Creates a new BSP instance pointing to the file at . The
/// Lists in this class will be read and populated when accessed through their properties.
///
- /// The path to the .BSP file
+ /// The path to the .BSP file.
public BSP(string filePath) {
- reader = new BSPReader(new FileInfo(filePath));
+ _reader = new BSPReader(new FileInfo(filePath));
this.filePath = filePath;
}
@@ -508,9 +500,9 @@ namespace LibBSP {
/// Creates a new BSP instance using the file referenced by . The
/// Lists in this class will be read and populated when accessed through their properties.
///
- /// A reference to the .BSP file
+ /// A reference to the .BSP file.
public BSP(FileInfo file) {
- reader = new BSPReader(file);
+ _reader = new BSPReader(file);
this.filePath = file.FullName;
}
@@ -518,7 +510,7 @@ namespace LibBSP {
/// Tells the object to release file handles for the BSP file.
///
public void Close() {
- reader.Close();
+ _reader.Close();
}
///
@@ -535,8 +527,7 @@ namespace LibBSP {
/// The List<> of objects in the lump from the index and length specified in .
/// The BSP class contains no property corresponding to .
/// The object referenced by is missing one or both members with IndexAttribute or CountAttribute attributes corresponding to .
- public List GetReferencedObjects(object o, string lumpName)
- {
+ public List GetReferencedObjects(object o, string lumpName) {
// First, find the property in this class corresponding to lumpName, and grab its "get" method
PropertyInfo targetLump = typeof(BSP).GetProperty(lumpName, BindingFlags.Public | BindingFlags.Instance);
if (targetLump == null) {
diff --git a/LibBSP/Source/Structs/BSP/Edge.cs b/LibBSP/Source/Structs/BSP/Edge.cs
index e8eab4a..276f2b6 100644
--- a/LibBSP/Source/Structs/BSP/Edge.cs
+++ b/LibBSP/Source/Structs/BSP/Edge.cs
@@ -3,14 +3,12 @@ using System.Collections.Generic;
namespace LibBSP {
///
- /// Holds all the data for an edge in a BSP map. Doubles as a subsector class for Doom maps, and has accessors for them.
+ /// Holds all the data for an edge in a BSP map.
///
- public class Edge {
+ public struct Edge {
public int firstVertex { get; private set; }
public int secondVertex { get; private set; }
- public int NumSegs { get { return firstVertex; } private set { firstVertex = value; } }
- public int FirstSeg { get { return secondVertex; } private set { secondVertex = value; } }
///
/// Creates a new Edge object from a byte array.
@@ -19,7 +17,7 @@ namespace LibBSP {
/// The map type
/// was null
/// This structure is not implemented for the given maptype
- public Edge(byte[] data, MapType type) {
+ public Edge(byte[] data, MapType type) : this() {
if (data == null) {
throw new ArgumentNullException();
}
@@ -48,12 +46,6 @@ namespace LibBSP {
secondVertex = BitConverter.ToInt32(data, 4);
break;
}
- case MapType.Doom:
- case MapType.Hexen: {
- firstVertex = BitConverter.ToUInt16(data, 0);
- secondVertex = BitConverter.ToUInt16(data, 2);
- break;
- }
default: {
throw new ArgumentException("Map type " + type + " isn't supported by the Edge class.");
}
@@ -96,11 +88,6 @@ namespace LibBSP {
structLength = 8;
break;
}
- case MapType.Doom:
- case MapType.Hexen: {
- structLength = 4;
- break;
- }
default: {
throw new ArgumentException("Map type " + type + " isn't supported by the Edge lump factory.");
}
diff --git a/LibBSP/Source/Structs/BSP/TexInfo.cs b/LibBSP/Source/Structs/BSP/TexInfo.cs
index cd0495d..ad950a4 100644
--- a/LibBSP/Source/Structs/BSP/TexInfo.cs
+++ b/LibBSP/Source/Structs/BSP/TexInfo.cs
@@ -125,10 +125,10 @@ namespace LibBSP {
bestaxis = i;
}
}
- Vector3[] out_Renamed = new Vector3[2];
- out_Renamed[0] = new Vector3(baseAxes[bestaxis * 3 + 1][0], baseAxes[bestaxis * 3 + 1][1], baseAxes[bestaxis * 3 + 1][2]);
- out_Renamed[1] = new Vector3(baseAxes[bestaxis * 3 + 2][0], baseAxes[bestaxis * 3 + 2][1], baseAxes[bestaxis * 3 + 2][2]);
- return out_Renamed;
+ Vector3[] newAxes = new Vector3[2];
+ newAxes[0] = new Vector3(baseAxes[bestaxis * 3 + 1][0], baseAxes[bestaxis * 3 + 1][1], baseAxes[bestaxis * 3 + 1][2]);
+ newAxes[1] = new Vector3(baseAxes[bestaxis * 3 + 2][0], baseAxes[bestaxis * 3 + 2][1], baseAxes[bestaxis * 3 + 2][2]);
+ return newAxes;
}
///
diff --git a/LibBSP/Source/Structs/Common/Entity.cs b/LibBSP/Source/Structs/Common/Entity.cs
index d7d402d..482c999 100644
--- a/LibBSP/Source/Structs/Common/Entity.cs
+++ b/LibBSP/Source/Structs/Common/Entity.cs
@@ -70,6 +70,8 @@ namespace LibBSP {
get {
if (ContainsKey("targetname")) {
return this["targetname"];
+ } else if (ContainsKey("name")) {
+ return this["name"];
} else {
return "";
}
@@ -335,10 +337,9 @@ namespace LibBSP {
}
///
- /// Gets a string representation of this Entity.
+ /// Gets a string representation of this Entity.
///
- /// Don't use this to export the entity to a file
- /// String representation of this Entity
+ /// string representation of this Entity.
public override string ToString() {
StringBuilder output = new StringBuilder();
output.Append("{\n");
@@ -356,45 +357,45 @@ namespace LibBSP {
}
///
- /// Checks if the attribute named "" has the value ""
+ /// Checks if the attribute named "" has the value "".
///
- /// The attribute to check
- /// The value to compare
- /// true if the values match
+ /// The attribute to check.
+ /// The value to compare.
+ /// true if the values match.
public bool ValueIs(string key, string value) {
return value.Equals(this[key], StringComparison.InvariantCultureIgnoreCase);
}
///
- /// Checks if the bits in "spawnflags" corresponding to the set bits set in are set
+ /// Checks if the bits in "spawnflags" corresponding to the set bits set in are set.
///
- /// The bits to compare spawnflags to
- /// true if all bits that were set in were set in spawnflags
+ /// The bits to compare spawnflags to.
+ /// true if all bits that were set in were set in spawnflags.
public bool SpawnflagsSet(uint bits) {
return ((spawnflags & bits) == bits);
}
///
- /// Toggles the bits in "spawnflags" which are set in
+ /// Toggles the bits in "spawnflags" which are set in .
///
- /// Bitmask of bits to toggle
+ /// Bitmask of bits to toggle.
public void ToggleSpawnflags(uint bits) {
this["spawnflags"] = (spawnflags ^ bits).ToString();
}
///
- /// Clears the bits in "spawnflags" which are set in
- /// Equivalent to spawnflags = ( ^ 0xFFFFFFFF) & spawnflags
+ /// Clears the bits in "spawnflags" which are set in .
+ /// Equivalent to spawnflags = ( ^ 0xFFFFFFFF) & spawnflags.
///
- /// Bitmask of bits to clear
+ /// Bitmask of bits to clear.
public void ClearSpawnflags(uint bits) {
ToggleSpawnflags(spawnflags & bits);
}
///
- /// Sets the bits in "spawnflags" which are set in
+ /// Sets the bits in "spawnflags" which are set in .
///
- /// Bitmask of bits to set
+ /// Bitmask of bits to set.
public void SetSpawnflags(uint bits) {
this["spawnflags"] = (spawnflags | bits).ToString();
}
@@ -403,9 +404,9 @@ namespace LibBSP {
/// Gets a numeric attribute as a float. Throws if the attribute could not be converted to a numerical value
/// and no was provided.
///
- /// Name of the attribute to retrieve
- /// Value to return if doesn't exist, or couldn't be converted
- /// The numeric value of the value corresponding to
+ /// Name of the attribute to retrieve.
+ /// Value to return if doesn't exist, or couldn't be converted.
+ /// The numeric value of the value corresponding to .
public float GetFloat(string key, float? failDefault = null) {
try {
return Single.Parse(this[key]);
@@ -421,9 +422,9 @@ namespace LibBSP {
/// Gets a numeric attribute as an int. Throws if the attribute could not be converted to a numerical value
/// and no was provided.
///
- /// Name of the attribute to retrieve
- /// Value to return if doesn't exist, or couldn't be converted
- /// The numeric value of the value corresponding to
+ /// Name of the attribute to retrieve.
+ /// Value to return if doesn't exist, or couldn't be converted.
+ /// The numeric value of the value corresponding to .
public int GetInt(string key, int? failDefault = null) {
try {
return Int32.Parse(this[key]);
@@ -437,10 +438,10 @@ namespace LibBSP {
///
/// Gets a Vector attribute as a Vector4. This will only read as many values as are in the attribute, and can be
- /// implicitly converted to Vector3, Vector2, or Color.
+ /// implicitly converted to Vector3, Vector2, or Color.
///
- /// Name of the attribute to retrieve
- /// Vector representation of the components of the attribute
+ /// Name of the attribute to retrieve.
+ /// Vector representation of the components of the attribute.
public Vector4 GetVector(string key) {
float[] results = new float[4];
if (ContainsKey(key) && !string.IsNullOrEmpty(this[key])) {
@@ -460,9 +461,9 @@ namespace LibBSP {
/// Compares this Entity to another object. First "classname" attributes are compared, then "targetname".
/// Attributes are compared alphabetically. Targetnames are only compared if classnames match.
///
- /// Object to compare to
- /// Less than zero if this entity is first, 0 if they occur at the same time, greater than zero otherwise
- /// was not of type Entity
+ /// Object to compare to.
+ /// Less than zero if this entity is first, 0 if they occur at the same time, greater than zero otherwise.
+ /// was not of type Entity.
public int CompareTo(object obj) {
if (obj == null) { return 1; }
Entity other = obj as Entity;
@@ -476,8 +477,8 @@ namespace LibBSP {
/// Compares this Entity to another Entity. First "classname" attributes are compared, then "targetname".
/// Attributes are compared alphabetically. Targetnames are only compared if classnames match.
///
- /// Entity to compare to
- /// Less than zero if this entity is first, 0 if they occur at the same time, greater than zero otherwise
+ /// Entity to compare to.
+ /// Less than zero if this entity is first, 0 if they occur at the same time, greater than zero otherwise.
public int CompareTo(Entity other) {
if (other == null) { return 1; }
int firstTry = className.CompareTo(other.className);
@@ -487,9 +488,9 @@ namespace LibBSP {
///
/// Factory method for an Entities object from a byte array.
///
- /// The data to parse
- /// The map type
- /// An Entities object, which is a List of Entitys
+ /// The data to parse.
+ /// The map type.
+ /// An Entities object, which is a List of Entitys.
public static Entities LumpFactory(byte[] data, MapType type) {
return new Entities(data, type);
}
@@ -497,8 +498,8 @@ namespace LibBSP {
///
/// Gets the index for this lump in the BSP file for a specific map format.
///
- /// The map type
- /// Index for this lump, or -1 if the format doesn't have this lump or it's not implemented
+ /// The map type.
+ /// Index for this lump, or -1 if the format doesn't have this lump or it's not implemented.
public static int GetIndexForLump(MapType type) {
switch (type) {
case MapType.Raven:
@@ -546,7 +547,7 @@ namespace LibBSP {
}
///
- /// Struct containing the fields necessary for Source entity I/O
+ /// Struct containing the fields necessary for Source entity I/O.
///
public struct EntityConnection {
public string name;
diff --git a/LibBSP/Source/Structs/Common/Lumps/Entities.cs b/LibBSP/Source/Structs/Common/Lumps/Entities.cs
index 1506888..5d5965c 100644
--- a/LibBSP/Source/Structs/Common/Lumps/Entities.cs
+++ b/LibBSP/Source/Structs/Common/Lumps/Entities.cs
@@ -3,20 +3,20 @@ using System.Collections.Generic;
namespace LibBSP {
///
- /// Class representing a group of Entity objects. Contains helpful methods to handle Entities in the List
+ /// Class representing a group of Entity objects. Contains helpful methods to handle Entities in the List.
///
public class Entities : List {
///
/// Initializes a new instance of an Entities object copying a passed IEnumerable of Entity objects.
///
- /// Collection of Entity objects to copy
+ /// Collection of Entity objects to copy.
public Entities(IEnumerable data) : base(data) { }
///
/// Initializes a new instance of an Entities object with a specified initial capacity.
///
- /// Initial capacity of the List of Entity objects
+ /// Initial capacity of the List of Entity objects.
public Entities(int initialCapacity) : base(initialCapacity) { }
///
@@ -27,7 +27,7 @@ namespace LibBSP {
///
/// Initializes a new Entities object, and parses the passed byte array into the List.
///
- /// Bytes read from a file
+ /// Bytes read from a file.
public Entities(byte[] data, MapType type) : base() {
// Keep track of whether or not we're currently in a set of quotation marks.
// I came across a map where the idiot map maker used { and } within a value. This broke the code before.
@@ -86,49 +86,48 @@ namespace LibBSP {
///
/// Deletes all Entity with "" set to "".
///
- /// Attribute to match
- /// Desired value of attribute
+ /// Attribute to match.
+ /// Desired value of attribute.
public void RemoveAllWithAttribute(string key, string value) {
- //DeleteEnts(FindAllWithAttribute(key, value));
- this.RemoveAll(entity => { return entity[key] == value; });
+ this.RemoveAll(entity => { return entity[key].Equals(value, StringComparison.InvariantCultureIgnoreCase); });
}
///
/// Gets a List of all Entitys with "" set to "".
///
- /// Name of the attribute to search for
- /// Value of the attribute to search for
- /// List(Entity) that have the specified key/value pair
+ /// Name of the attribute to search for.
+ /// Value of the attribute to search for.
+ /// List(Entity) that have the specified key/value pair.
public List GetAllWithAttribute(string key, string value) {
- return FindAll(entity => { return entity[key] == value; });
+ return FindAll(entity => { return entity[key].Equals(value, StringComparison.InvariantCultureIgnoreCase); });
}
///
- /// Gets a List of Entitys objects with the specified targetname
+ /// Gets a List of Entitys objects with the specified targetname.
///
- /// Targetname attribute to find
- /// List(Entity) with the specified targetname
+ /// Targetname attribute to find.
+ /// List(Entity) with the specified targetname.
public List GetAllWithName(string targetname) {
- return GetAllWithAttribute("targetname", targetname);
+ return FindAll(entity => { return entity.name.Equals(targetname, StringComparison.InvariantCultureIgnoreCase); });
}
///
/// Gets the first Entity with "" set to "".
///
- /// Name of the attribute to search for
- /// Value of the attribute to search for
- /// Entity with the specified key/value pair, or null if none exists
+ /// Name of the attribute to search for.
+ /// Value of the attribute to search for.
+ /// Entity with the specified key/value pair, or null if none exists.
public Entity GetWithAttribute(string key, string value) {
- return Find(entity => { return entity[key] == value; });
+ return Find(entity => { return entity[key].Equals(value, StringComparison.InvariantCultureIgnoreCase); });
}
///
/// Gets the first Entity with the specified targetname.
///
- /// Targetname attribute to find
- /// Entity object with the specified targetname
+ /// Targetname attribute to find.
+ /// Entity object with the specified targetname.
public Entity GetWithName(string targetname) {
- return GetWithAttribute("targetname", targetname);
+ return Find(entity => { return entity.name.Equals(targetname, StringComparison.InvariantCultureIgnoreCase); });
}
}
}
diff --git a/LibBSP/Source/Structs/Common/Plane.cs b/LibBSP/Source/Structs/Common/Plane.cs
index f276f30..5a6d52d 100644
--- a/LibBSP/Source/Structs/Common/Plane.cs
+++ b/LibBSP/Source/Structs/Common/Plane.cs
@@ -1,4 +1,4 @@
-#if !(UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
+#if !(UNITY || UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
using System;
using System.Collections.Generic;
diff --git a/LibBSP/Source/Structs/Common/Ray.cs b/LibBSP/Source/Structs/Common/Ray.cs
index d3ef380..ecbcb77 100644
--- a/LibBSP/Source/Structs/Common/Ray.cs
+++ b/LibBSP/Source/Structs/Common/Ray.cs
@@ -1,4 +1,4 @@
-#if !(UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
+#if !(UNITY || UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
using System;
namespace LibBSP {
diff --git a/LibBSP/Source/Structs/Common/Rect.cs b/LibBSP/Source/Structs/Common/Rect.cs
index 54bdf5b..dbeb393 100644
--- a/LibBSP/Source/Structs/Common/Rect.cs
+++ b/LibBSP/Source/Structs/Common/Rect.cs
@@ -1,4 +1,4 @@
-#if !(UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
+#if !(UNITY || UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
using System;
using System.Collections.Generic;
diff --git a/LibBSP/Source/Structs/Common/Vector2d.cs b/LibBSP/Source/Structs/Common/Vector2d.cs
index 652793b..e0daf08 100644
--- a/LibBSP/Source/Structs/Common/Vector2d.cs
+++ b/LibBSP/Source/Structs/Common/Vector2d.cs
@@ -1,4 +1,4 @@
-#if !(UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
+#if !(UNITY || UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
using System;
using System.Collections;
using System.Collections.Generic;
diff --git a/LibBSP/Source/Structs/Common/Vector3d.cs b/LibBSP/Source/Structs/Common/Vector3d.cs
index 5cf48f4..5773205 100644
--- a/LibBSP/Source/Structs/Common/Vector3d.cs
+++ b/LibBSP/Source/Structs/Common/Vector3d.cs
@@ -1,4 +1,4 @@
-#if !(UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
+#if !(UNITY || UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
using System;
using System.Collections;
using System.Collections.Generic;
diff --git a/LibBSP/Source/Structs/Common/Vector4d.cs b/LibBSP/Source/Structs/Common/Vector4d.cs
index 84269a1..84573ea 100644
--- a/LibBSP/Source/Structs/Common/Vector4d.cs
+++ b/LibBSP/Source/Structs/Common/Vector4d.cs
@@ -1,4 +1,4 @@
-#if !(UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
+#if !(UNITY || UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5)
using System;
using System.Collections;
using System.Collections.Generic;
diff --git a/LibBSP/Source/Structs/Doom/DoomMap.cs b/LibBSP/Source/Structs/Doom/DoomMap.cs
deleted file mode 100644
index f316681..0000000
--- a/LibBSP/Source/Structs/Doom/DoomMap.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-#if UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5
-#define UNITY
-#endif
-
-using System;
-using System.Collections.Generic;
-#if UNITY
-using UnityEngine;
-#endif
-
-namespace LibBSP.Doom {
- ///
- /// Gathers all relevant information from the lumps of a Doom Map.
- ///
- public class DoomMap {
-
- // Since all Doom engine maps were incorporated into the WAD, we need to keep
- // track of both the location of the WAD file and the internal name of the map.
- public string wadPath { get; private set; }
- public string mapName { get; private set; }
- public MapType version { get; private set; }
-
- public List things;
- public List linedefs;
- public List sidedefs;
- public List vertices;
- public List segs;
- public List subsectors;
- public List nodes;
- public List sectors;
-
- ///
- /// Gets the folder path for the WAD containing this map
- ///
- public string Folder {
- get {
- int i;
- for (i = 0; i < wadPath.Length; ++i) {
- if (wadPath[wadPath.Length - 1 - i] == '\\') {
- break;
- }
- if (wadPath[wadPath.Length - 1 - i] == '/') {
- break;
- }
- }
- return wadPath.Substring(0, (wadPath.Length - i) - (0));
- }
- }
-
- ///
- /// Gets the name of the WAD file containing this map
- ///
- public string WadName {
- get {
- System.IO.FileInfo newFile = new System.IO.FileInfo(wadPath);
- return newFile.Name.Substring(0, (newFile.Name.Length - 4) - (0));
- }
- }
-
- ///
- /// Creates a new DoomMap instance with no initial data. The Lists in this class must be populated elsewhere.
- ///
- /// The path to the .WAD file
- /// The name of the map within the WAD file
- /// The version of the map
- public DoomMap(string wadpath, string map, MapType version) {
- this.wadPath = wadpath;
- this.mapName = map;
- this.version = version;
- }
- }
-}
diff --git a/LibBSP/Source/Structs/Doom/Linedef.cs b/LibBSP/Source/Structs/Doom/Linedef.cs
deleted file mode 100644
index 67d186b..0000000
--- a/LibBSP/Source/Structs/Doom/Linedef.cs
+++ /dev/null
@@ -1,108 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace LibBSP.Doom {
- ///
- /// Contains all necessary information for a Doom LINEDEF object.
- ///
- ///
- /// The linedef is a strange animal. It roughly equates to the Planes of other
- /// BSP formats, but also defines what sectors are on what side.
- ///
- public struct Linedef {
-
- public short start { get; private set; }
- public short end { get; private set; }
- public short flags { get; private set; }
- public short action { get; private set; }
- public short tag { get; private set; }
- public short right { get; private set; }
- public short left { get; private set; }
- public byte[] arguments { get; private set; }
-
- public bool oneSided {
- get {
- return (right == -1 || left == -1);
- }
- }
-
- ///
- /// Creates a new Linedef object from a byte array.
- ///
- /// byte array to parse
- /// The map type
- /// was null
- /// This structure is not implemented for the given maptype
- public Linedef(byte[] data, MapType type) : this() {
- if (data == null) {
- throw new ArgumentNullException();
- }
- start = BitConverter.ToInt16(data, 0);
- end = BitConverter.ToInt16(data, 2);
- flags = BitConverter.ToInt16(data, 4);
- action = -1;
- tag = -1;
- right = -1;
- left = -1;
- arguments = new byte[5];
- switch (type) {
- case MapType.Doom: {
- action = BitConverter.ToInt16(data, 6);
- tag = BitConverter.ToInt16(data, 8);
- right = BitConverter.ToInt16(data, 10);
- left = BitConverter.ToInt16(data, 12);
- break;
- }
- case MapType.Hexen: {
- action = data[6];
- arguments[0] = data[7];
- arguments[1] = data[8];
- arguments[2] = data[9];
- arguments[3] = data[10];
- arguments[4] = data[11];
- right = BitConverter.ToInt16(data, 12);
- left = BitConverter.ToInt16(data, 14);
- break;
- }
- default: {
- throw new ArgumentException("Map type " + type + " isn't supported by the Linedef class.");
- }
- }
- }
-
- ///
- /// Factory method to parse a byte array into a List of Linedef objects.
- ///
- /// The data to parse
- /// The map type
- /// A List of Linedef objects
- /// was null
- /// This structure is not implemented for the given maptype
- public static List LumpFactory(byte[] data, MapType type) {
- if (data == null) {
- throw new ArgumentNullException();
- }
- int structLength = 0;
- switch (type) {
- case MapType.Doom: {
- structLength = 14;
- break;
- }
- case MapType.Hexen: {
- structLength = 16;
- break;
- }
- default: {
- throw new ArgumentException("Map type " + type + " isn't supported by the Linedef lump factory.");
- }
- }
- List lump = new List(data.Length / structLength);
- byte[] bytes = new byte[structLength];
- for (int i = 0; i < data.Length / structLength; ++i) {
- Array.Copy(data, i * structLength, bytes, 0, structLength);
- lump.Add(new Linedef(bytes, type));
- }
- return lump;
- }
- }
-}
diff --git a/LibBSP/Source/Structs/Doom/Node.cs b/LibBSP/Source/Structs/Doom/Node.cs
deleted file mode 100644
index ebd3456..0000000
--- a/LibBSP/Source/Structs/Doom/Node.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-#if UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5
-#define UNITY
-#endif
-
-using System;
-using System.Collections.Generic;
-#if UNITY
-using UnityEngine;
-#endif
-
-namespace LibBSP.Doom {
-#if !UNITY
- using Vector3 = Vector3d;
-#endif
- ///
- /// Holds all the data for a node in a Doom map.
- ///
- ///
- /// This is the one lump that has a structure similar to future BSPs.
- ///
- public struct Node {
- // This format uses a vector head and tail for partitioning, rather
- // than the 3D plane conventionally used by more modern engines.
- // The "tail" is actually a change in X and Y, rather than an explicitly defined point.
- public Vector3 vecHead { get; private set; }
- public Vector3 vecTail { get; private set; }
- // These rectangles are defined by
- // Top, Bottom, Left, Right. That's YMax, YMin, XMin, XMax, in that order
- public Rect RRectangle { get; private set; }
- public Rect LRectangle { get; private set; }
- public short RChild { get; private set; }
- public short LChild { get; private set; }
-
- ///
- /// Creates a new Node object from a byte array.
- ///
- /// byte array to parse
- /// The map type
- /// was null
- public Node(byte[] data, MapType type) : this() {
- if (data == null) {
- throw new ArgumentNullException();
- }
- vecHead = new Vector3(BitConverter.ToInt16(data, 0), BitConverter.ToInt16(data, 2));
- vecTail = new Vector3(BitConverter.ToInt16(data, 4), BitConverter.ToInt16(data, 6));
- RRectangle = Rect.MinMaxRect(BitConverter.ToInt16(data, 12), BitConverter.ToInt16(data, 8), BitConverter.ToInt16(data, 14), BitConverter.ToInt16(data, 10));
- LRectangle = Rect.MinMaxRect(BitConverter.ToInt16(data, 20), BitConverter.ToInt16(data, 16), BitConverter.ToInt16(data, 22), BitConverter.ToInt16(data, 18));
- this.RChild = BitConverter.ToInt16(data, 24);
- this.LChild = BitConverter.ToInt16(data, 26);
- }
-
- ///
- /// Factory method to parse a byte array into a List of Node objects.
- ///
- /// The data to parse
- /// The map type
- /// A List of Node objects
- /// was null
- public static List LumpFactory(byte[] data, MapType type) {
- if (data == null) {
- throw new ArgumentNullException();
- }
- int structLength = 28;
- List lump = new List(data.Length / structLength);
- byte[] bytes = new byte[structLength];
- for (int i = 0; i < data.Length / structLength; ++i) {
- Array.Copy(data, i * structLength, bytes, 0, structLength);
- lump.Add(new Node(bytes, type));
- }
- return lump;
- }
- }
-}
diff --git a/LibBSP/Source/Structs/Doom/Sector.cs b/LibBSP/Source/Structs/Doom/Sector.cs
deleted file mode 100644
index 8b9eb26..0000000
--- a/LibBSP/Source/Structs/Doom/Sector.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace LibBSP.Doom {
- ///
- /// Contains all necessary information for a Doom SECTOR object.
- ///
- ///
- /// The sector defines an area, the heights of the floor and cieling
- /// of the area, the floor and cieling textures, the light level, the
- /// type of sector and a tag number.
- ///
- public struct Sector {
-
- public short floor { get; private set; }
- public short cieling { get; private set; }
-
- public string floorTexture { get; private set; }
- public string cielingTexture { get; private set; }
-
- public short light { get; private set; }
- public short type { get; private set; }
- public short tag { get; private set; }
-
- ///
- /// Creates a new Sector object from a byte array.
- ///
- /// byte array to parse
- /// The map type
- /// was null
- public Sector(byte[] data, MapType type) : this() {
- this.floor = BitConverter.ToInt16(data, 0);
- this.cieling = BitConverter.ToInt16(data, 2);
- this.floorTexture = data.ToNullTerminatedString(4, 8);
- this.cielingTexture = data.ToNullTerminatedString(12, 8);
- this.light = BitConverter.ToInt16(data, 20);
- this.type = BitConverter.ToInt16(data, 22);
- this.tag = BitConverter.ToInt16(data, 24);
- }
-
- ///
- /// Factory method to parse a byte array into a List of Sector objects.
- ///
- /// The data to parse
- /// The map type
- /// A List of Sector objects
- /// was null
- public static List LumpFactory(byte[] data, MapType type) {
- int structLength = 26;
- List lump = new List(data.Length / structLength);
- byte[] bytes = new byte[structLength];
- for (int i = 0; i < data.Length / structLength; ++i) {
- Array.Copy(data, i * structLength, bytes, 0, structLength);
- lump.Add(new Sector(bytes, type));
- }
- return lump;
- }
- }
-}
diff --git a/LibBSP/Source/Structs/Doom/Segment.cs b/LibBSP/Source/Structs/Doom/Segment.cs
deleted file mode 100644
index 02da87b..0000000
--- a/LibBSP/Source/Structs/Doom/Segment.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace LibBSP.Doom {
- ///
- /// This class holds data of a single Doom line Segment
- ///
- public struct Segment {
-
- public short startVertex { get; private set; }
- public short endVertex { get; private set; }
- public short angle { get; private set; }
- public short lineDef { get; private set; }
- // 0 for right side of linedef, 1 for left
- public short direction { get; private set; }
- public short dist { get; private set; }
-
- ///
- /// Creates a new Segment object from a byte array.
- ///
- /// byte array to parse
- /// The map type
- /// was null
- public Segment(byte[] data, MapType type) : this() {
- if (data == null) {
- throw new ArgumentNullException();
- }
- this.startVertex = BitConverter.ToInt16(data, 0);
- this.endVertex = BitConverter.ToInt16(data, 2);
- this.angle = BitConverter.ToInt16(data, 4);
- this.lineDef = BitConverter.ToInt16(data, 6);
- this.direction = BitConverter.ToInt16(data, 8);
- this.dist = BitConverter.ToInt16(data, 10);
- }
-
- ///
- /// Factory method to parse a byte array into a List of Segment objects.
- ///
- /// The data to parse
- /// The map type
- /// A List of Segment objects
- /// was null
- public static List LumpFactory(byte[] data, MapType type) {
- if (data == null) {
- throw new ArgumentNullException();
- }
- int structLength = 12;
- List lump = new List(data.Length / structLength);
- byte[] bytes = new byte[structLength];
- for (int i = 0; i < data.Length / structLength; ++i) {
- Array.Copy(data, i * structLength, bytes, 0, structLength);
- lump.Add(new Segment(bytes, type));
- }
- return lump;
- }
-
- }
-}
diff --git a/LibBSP/Source/Structs/Doom/Sidedef.cs b/LibBSP/Source/Structs/Doom/Sidedef.cs
deleted file mode 100644
index 4520ae1..0000000
--- a/LibBSP/Source/Structs/Doom/Sidedef.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-#if UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5
-#define UNITY
-#endif
-
-using System;
-using System.Collections.Generic;
-#if UNITY
-using UnityEngine;
-#endif
-
-namespace LibBSP.Doom {
-#if !UNITY
- using Vector2 = Vector2d;
-#endif
-
- ///
- /// Contains all necessary information for a Doom SIDEDEF object.
- ///
- ///
- /// The sidedef is roughly equivalent to the Face (or surface)
- /// object in later BSP versions.
- ///
- public struct Sidedef {
-
- public Vector2 offsets { get; private set; }
- public string highTexture { get; private set; }
- public string midTexture { get; private set; }
- public string lowTexture { get; private set; }
- public short sector { get; private set; }
-
- ///
- /// Creates a new Sidedef object from a byte array.
- ///
- /// byte array to parse
- /// The map type
- /// was null
- public Sidedef(byte[] data, MapType type) : this() {
- if (data == null) {
- throw new ArgumentNullException();
- }
- offsets = new Vector2(BitConverter.ToInt16(data, 0), BitConverter.ToInt16(data, 2));
- highTexture = data.ToNullTerminatedString(4, 8);
- midTexture = data.ToNullTerminatedString(12, 8);
- lowTexture = data.ToNullTerminatedString(20, 8);
- sector = BitConverter.ToInt16(data, 28);
- }
-
- ///
- /// Factory method to parse a byte array into a List of Sidedef objects.
- ///
- /// The data to parse
- /// The map type
- /// A List of Sidedef objects
- /// was null
- public static List LumpFactory(byte[] data, MapType type) {
- if (data == null) {
- throw new ArgumentNullException();
- }
- int structLength = 30;
- List lump = new List(data.Length / structLength);
- byte[] bytes = new byte[structLength];
- for (int i = 0; i < data.Length / structLength; ++i) {
- Array.Copy(data, i * structLength, bytes, 0, structLength);
- lump.Add(new Sidedef(bytes, type));
- }
- return lump;
- }
-
- }
-}
diff --git a/LibBSP/Source/Structs/Doom/Thing.cs b/LibBSP/Source/Structs/Doom/Thing.cs
deleted file mode 100644
index 9df9462..0000000
--- a/LibBSP/Source/Structs/Doom/Thing.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-#if UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5
-#define UNITY
-#endif
-
-using System;
-using System.Collections.Generic;
-#if UNITY
-using UnityEngine;
-#endif
-
-namespace LibBSP.Doom {
-#if !UNITY
- using Vector2 = Vector2d;
- using Vector3 = Vector3d;
-#endif
- ///
- /// Contains all necessary information for a Doom THING object. Essentially Doom's entities.
- ///
- public struct Thing {
-
- public Vector3 origin { get; private set; }
- public short angle { get; private set; }
- public short classNum { get; private set; }
- public short flags { get; private set; }
-
- public short id { get; private set; }
- public byte action { get; private set; }
- public byte[] arguments { get; private set; }
-
- ///
- /// Creates a new Thing object from a byte array.
- ///
- /// byte array to parse
- /// The map type
- /// was null
- /// This structure is not implemented for the given maptype
- public Thing(byte[] data, MapType type) : this() {
- if (data == null) {
- throw new ArgumentNullException();
- }
- switch (type) {
- case MapType.Doom: {
- origin = new Vector2(BitConverter.ToInt16(data, 0), BitConverter.ToInt16(data, 2));
- this.angle = BitConverter.ToInt16(data, 4);
- this.classNum = BitConverter.ToInt16(data, 6);
- this.flags = BitConverter.ToInt16(data, 8);
- break;
- }
- case MapType.Hexen: {
- id = BitConverter.ToInt16(data, 0);
- origin = new Vector3(BitConverter.ToInt16(data, 2), BitConverter.ToInt16(data, 4), BitConverter.ToInt16(data, 6));
- this.angle = BitConverter.ToInt16(data, 8);
- this.classNum = BitConverter.ToInt16(data, 10);
- this.flags = BitConverter.ToInt16(data, 12);
- action = data[14];
- arguments[0] = data[15];
- arguments[1] = data[16];
- arguments[2] = data[17];
- arguments[3] = data[18];
- arguments[4] = data[19];
- break;
- }
- default: {
- throw new ArgumentException("Map type " + type + " isn't supported by the Thing class.");
- }
- }
- }
-
- ///
- /// Factory method to parse a byte array into a List of Thing objects.
- ///
- /// The data to parse
- /// The map type
- /// A List of Thing objects
- /// was null
- /// This structure is not implemented for the given maptype
- public static List LumpFactory(byte[] data, MapType type) {
- if (data == null) {
- throw new ArgumentNullException();
- }
- int structLength = 0;
- switch (type) {
- case MapType.Doom: {
- structLength = 10;
- break;
- }
- case MapType.Hexen: {
- structLength = 20;
- break;
- }
- default: {
- throw new ArgumentException("Map type " + type + " isn't supported by the Thing lump factory.");
- }
- }
- List lump = new List(data.Length / structLength);
- byte[] bytes = new byte[structLength];
- for (int i = 0; i < data.Length / structLength; ++i) {
- Array.Copy(data, i * structLength, bytes, 0, structLength);
- lump.Add(new Thing(bytes, type));
- }
- return lump;
- }
- }
-}
diff --git a/LibBSP/Source/Util/BSPReader.cs b/LibBSP/Source/Util/BSPReader.cs
index 5b96f92..697d992 100644
--- a/LibBSP/Source/Util/BSPReader.cs
+++ b/LibBSP/Source/Util/BSPReader.cs
@@ -12,15 +12,20 @@ namespace LibBSP {
private bool _bigEndian = false;
- // Decryption key for Tactical Intervention; should be 32 bytes
+ ///
+ /// An XOr encryption key for encrypted map formats. Must be read and set.
+ ///
private byte[] key = new byte[0];
- public bool bigEndian { get { return _bigEndian; } }
+ ///
+ /// Was this map determined to be in big endian format?
+ ///
+ public bool bigEndian { get { return _bigEndian; } set { _bigEndian = value; } }
///
/// Creates a new instance of a BSPReader class to read the specified file.
///
- ///
+ /// The FileInfo representing the file this BSPReader should read.
public BSPReader(FileInfo file) {
if (!File.Exists(file.FullName)) {
throw new FileNotFoundException("Unable to open BSP file; file " + file.FullName + " not found.");
@@ -33,9 +38,9 @@ namespace LibBSP {
///
/// Reads this lump in the map.
///
- /// The index of the lump to get
- /// The version of BSP this is
- /// Array of bytes read from the BSP file
+ /// The index of the lump to get.
+ /// The version of BSP this is.
+ /// Array of bytes read from the BSP file.
public byte[] ReadLumpNum(int index, MapType version) {
switch (version) {
case MapType.Quake:
@@ -105,9 +110,9 @@ namespace LibBSP {
/// Returns the lump referenced by the offset/length pair at the specified ,
/// read as two Int32.
///
- /// The byte offset for the offset/length pair
- /// The version of BSP this is
- /// Array of bytes read from the BSP file
+ /// The byte offset for the offset/length pair.
+ /// The version of BSP this is.
+ /// Array of bytes read from the BSP file.
private byte[] ReadLumpFromOffsetLengthPairAtOffset(int offset, MapType version) {
stream.Seek(offset, SeekOrigin.Begin);
byte[] input = binaryReader.ReadBytes(12);
@@ -135,12 +140,12 @@ namespace LibBSP {
}
///
- /// Reads the lump bytes long at in the file
+ /// Reads the lump bytes long at in the file.
///
- /// Offset to start reading from
- /// Length of the lump to read
- /// The version of BSP this is
- /// Array of bytes read from the BSP file
+ /// Offset to start reading from.
+ /// Length of the lump to read.
+ /// The version of BSP this is.
+ /// Array of bytes read from the BSP file.
public byte[] ReadLump(int offset, int length, MapType version) {
stream.Seek(offset, SeekOrigin.Begin);
byte[] input = binaryReader.ReadBytes(length);
@@ -153,10 +158,10 @@ namespace LibBSP {
///
/// Xors the byte array with the localls stored key byte array, starting at a certain in the key.
///
- /// The byte array to Xor
- /// The index in the key byte array to start reading from
- /// The input byte array Xored with the key byte array
- /// The passed parameter was null
+ /// The byte array to Xor.
+ /// The index in the key byte array to start reading from.
+ /// The input byte array Xored with the key byte array.
+ /// The passed parameter was null.
private byte[] XorWithKeyStartingAtIndex(byte[] data, int index = 0) {
if (data == null) {
throw new ArgumentNullException();
@@ -175,7 +180,7 @@ namespace LibBSP {
/// Tries to get the MapType member most closely represented by the referenced file. If the file is
/// found to be big-endian, this will set bigEndian to true.
///
- /// The MapType of this BSP, MapType.Undefined if it could not be determined
+ /// The MapType of this BSP, MapType.Undefined if it could not be determined.
public MapType GetVersion() {
MapType ret = GetVersion(false);
if (ret == MapType.Undefined) {
@@ -190,8 +195,8 @@ namespace LibBSP {
///
/// Tries to get the MapType member most closely represented by the referenced file.
///
- /// Set to true to attempt reading the data in big-endian byte order
- /// The MapType of this BSP, MapType.Undefined if it could not be determined
+ /// Set to true to attempt reading the data in big-endian byte order.
+ /// The MapType of this BSP, MapType.Undefined if it could not be determined.
private MapType GetVersion(bool bigEndian) {
MapType current = MapType.Undefined;
stream.Seek(0, SeekOrigin.Begin);