diff --git a/LibBSP/LibBSP.csproj b/LibBSP/LibBSP.csproj
index 9fec1f4..ae0a154 100644
--- a/LibBSP/LibBSP.csproj
+++ b/LibBSP/LibBSP.csproj
@@ -59,6 +59,7 @@
+
@@ -69,9 +70,7 @@
-
-
diff --git a/LibBSP/Source/Extensions/ColorExtensions.cs b/LibBSP/Source/Extensions/ColorExtensions.cs
index 4aba980..c22df81 100644
--- a/LibBSP/Source/Extensions/ColorExtensions.cs
+++ b/LibBSP/Source/Extensions/ColorExtensions.cs
@@ -35,7 +35,7 @@ namespace LibBSP {
}
///
- /// Gets this Color as R8G8B8A8.
+ /// Gets this Color as R8G8B8A8 (RGBA32).
///
/// This Color.
/// A byte array with four members, RGBA.
diff --git a/LibBSP/Source/Structs/BSP/BSP.cs b/LibBSP/Source/Structs/BSP/BSP.cs
index e9227e4..4ddfd11 100644
--- a/LibBSP/Source/Structs/BSP/BSP.cs
+++ b/LibBSP/Source/Structs/BSP/BSP.cs
@@ -106,6 +106,7 @@ namespace LibBSP {
private Lump _patches;
private Lump _patchVerts;
private NumList _patchIndices;
+ private NumList _leafPatches;
// Nightfire
private Textures _materials;
private NumList _indices;
@@ -113,8 +114,8 @@ namespace LibBSP {
private Lump _originalFaces;
private NumList _texTable;
private Lump _texDatas;
- private Lump _dispInfos;
- private DisplacementVertices _dispVerts;
+ private Lump _dispInfos;
+ private Lump _dispVerts;
private NumList _displacementTriangles;
// public SourceOverlays overlays;
private Lump _cubemaps;
@@ -372,14 +373,14 @@ namespace LibBSP {
}
///
- /// A of objects in the BSP file, if available.
+ /// A of objects in the BSP file, if available.
///
- public Lump dispInfos {
+ public Lump dispInfos {
get {
if (_dispInfos == null) {
- int index = DisplacementInfo.GetIndexForLump(version);
+ int index = Displacement.GetIndexForLump(version);
if (index >= 0) {
- _dispInfos = DisplacementInfo.LumpFactory(reader.ReadLump(this[index]), this, this[index]);
+ _dispInfos = Displacement.LumpFactory(reader.ReadLump(this[index]), this, this[index]);
}
}
return _dispInfos;
@@ -387,9 +388,9 @@ namespace LibBSP {
}
///
- /// The object in the BSP file, if available.
+ /// The object in the BSP file, if available.
///
- public DisplacementVertices dispVerts {
+ public Lump dispVerts {
get {
if (_dispVerts == null) {
int index = DisplacementVertex.GetIndexForLump(version);
@@ -543,6 +544,22 @@ namespace LibBSP {
}
}
+ ///
+ /// A object containing the Leaf Patches lump, if available.
+ ///
+ public NumList leafPatches {
+ get {
+ if (_leafPatches == null) {
+ NumList.DataType type;
+ int index = NumList.GetIndexForLeafPatchesLump(version, out type);
+ if (index >= 0) {
+ _leafPatches = NumList.LumpFactory(reader.ReadLump(this[index]), type, this, this[index]);
+ }
+ }
+ return _leafPatches;
+ }
+ }
+
///
/// A object containing the Face Vertex Indices lump, if available.
///
@@ -612,8 +629,8 @@ namespace LibBSP {
public StaticProps staticProps {
get {
if (_staticProps == null) {
- if (gameLump != null && gameLump.ContainsKey(GameLumpType.sprp)) {
- LumpInfo info = gameLump[GameLumpType.sprp];
+ if (gameLump != null && gameLump.ContainsKey(GameLumpType.prps)) {
+ LumpInfo info = gameLump[GameLumpType.prps];
byte[] thisLump;
// GameLump lumps may have their offset specified from either the beginning of the GameLump, or the beginning of the file.
if (gameLump.GetLowestLumpOffset() < this[GameLump.GetIndexForLump(version)].offset) {
diff --git a/LibBSP/Source/Structs/BSP/Brush.cs b/LibBSP/Source/Structs/BSP/Brush.cs
index 62ea7ae..6462442 100644
--- a/LibBSP/Source/Structs/BSP/Brush.cs
+++ b/LibBSP/Source/Structs/BSP/Brush.cs
@@ -43,7 +43,21 @@ namespace LibBSP {
}
}
- [Index("brushSides")] public int firstSide {
+ ///
+ /// Enumerates the s referenced by this .
+ ///
+ public IEnumerable Sides {
+ get {
+ for (int i = 0; i < NumSides; ++i) {
+ yield return Parent.Bsp.brushSides[FirstSideIndex + i];
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first side of this .
+ ///
+ [Index("brushSides")] public int FirstSideIndex {
get {
switch (MapType) {
case MapType.Quake2:
@@ -114,7 +128,10 @@ namespace LibBSP {
}
}
- [Count("brushSides")] public int numSides {
+ ///
+ /// Gets or sets the count of sides in this .
+ ///
+ [Count("brushSides")] public int NumSides {
get {
switch (MapType) {
case MapType.CoD:
@@ -202,7 +219,19 @@ namespace LibBSP {
}
}
- public int texture {
+ ///
+ /// Gets the referenced by this . Quake 3 engines only use this for contents.
+ ///
+ public Texture Texture {
+ get {
+ return Parent.Bsp.textures[TextureIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the used by this . Quake 3 engines only use this for contents.
+ ///
+ public int TextureIndex {
get {
switch (MapType) {
case MapType.CoD:
@@ -245,7 +274,10 @@ namespace LibBSP {
}
}
- public int contents {
+ ///
+ /// Gets or sets the Contents mask for this .
+ ///
+ public int Contents {
get {
switch (MapType) {
case MapType.Nightfire: {
diff --git a/LibBSP/Source/Structs/BSP/BrushSide.cs b/LibBSP/Source/Structs/BSP/BrushSide.cs
index 696054f..9983557 100644
--- a/LibBSP/Source/Structs/BSP/BrushSide.cs
+++ b/LibBSP/Source/Structs/BSP/BrushSide.cs
@@ -1,8 +1,18 @@
+#if 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 || UNITY_5_3_OR_NEWER
+#define UNITY
+#endif
+
using System;
-using System.Collections.Generic;
using System.Reflection;
namespace LibBSP {
+#if UNITY
+ using Plane = UnityEngine.Plane;
+#elif GODOT
+ using Plane = Godot.Plane;
+#else
+ using Plane = System.Numerics.Plane;
+#endif
///
/// Holds the data used by the brush side structures of all formats of BSP.
@@ -43,7 +53,19 @@ namespace LibBSP {
}
}
- public int plane {
+ ///
+ /// Gets the Plane referenced by this .
+ ///
+ public Plane Plane {
+ get {
+ return Parent.Bsp.planes[PlaneIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the Plane used by this .
+ ///
+ public int PlaneIndex {
get {
switch (MapType) {
case MapType.SiN:
@@ -126,7 +148,10 @@ namespace LibBSP {
}
}
- public float dist {
+ ///
+ /// In Call of Duty based maps, gets or sets the distance of this from its axis.
+ ///
+ public float Distance {
get {
switch (MapType) {
case MapType.CoD:
@@ -152,7 +177,19 @@ namespace LibBSP {
}
}
- public int texture {
+ ///
+ /// Gets the referenced by this .
+ ///
+ public Texture Texture {
+ get {
+ return Parent.Bsp.textures[TextureIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the used by this .
+ ///
+ public int TextureIndex {
get {
switch (MapType) {
case MapType.STEF2: {
@@ -232,8 +269,20 @@ namespace LibBSP {
}
}
}
-
- public int face {
+
+ ///
+ /// Gets the referenced by this .
+ ///
+ public Face Face {
+ get {
+ return Parent.Bsp.faces[FaceIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the used by this .
+ ///
+ public int FaceIndex {
get {
switch (MapType) {
case MapType.Nightfire: {
@@ -261,8 +310,22 @@ namespace LibBSP {
}
}
}
-
- public int displacement {
+
+ ///
+ /// In Source engine, gets the referenced by this .
+ /// This is never used since the brushes used to create Displacements are optimized out.
+ ///
+ public Displacement Displacement {
+ get {
+ return Parent.Bsp.dispInfos[DisplacementIndex];
+ }
+ }
+
+ ///
+ /// In Source engine, gets or sets the index of the used by this .
+ /// This is never used since the brushes used to create Displacements are optimized out.
+ ///
+ public int DisplacementIndex {
get {
switch (MapType) {
case MapType.Source17:
@@ -311,8 +374,11 @@ namespace LibBSP {
}
}
}
-
- public bool bevel {
+
+ ///
+ /// Is this a bevel?
+ ///
+ public bool IsBevel {
get {
switch (MapType) {
case MapType.Source17:
@@ -360,7 +426,10 @@ namespace LibBSP {
}
}
- public bool thin {
+ ///
+ /// Is this thin?
+ ///
+ public bool IsThin {
get {
switch (MapType) {
case MapType.Source17:
diff --git a/LibBSP/Source/Structs/BSP/Cubemap.cs b/LibBSP/Source/Structs/BSP/Cubemap.cs
index f563807..db310bf 100644
--- a/LibBSP/Source/Structs/BSP/Cubemap.cs
+++ b/LibBSP/Source/Structs/BSP/Cubemap.cs
@@ -3,7 +3,6 @@
#endif
using System;
-using System.Collections.Generic;
using System.Reflection;
namespace LibBSP {
@@ -54,7 +53,10 @@ namespace LibBSP {
}
}
- public Vector3 origin {
+ ///
+ /// Gets or sets the position of this .
+ ///
+ public Vector3 Origin {
get {
switch (MapType) {
case MapType.Source17:
@@ -90,14 +92,19 @@ namespace LibBSP {
case MapType.L4D2:
case MapType.Vindictus:
case MapType.DMoMaM: {
- value.GetBytes().CopyTo(Data, 0);
+ BitConverter.GetBytes((int)value.X()).CopyTo(Data, 0);
+ BitConverter.GetBytes((int)value.Y()).CopyTo(Data, 4);
+ BitConverter.GetBytes((int)value.Z()).CopyTo(Data, 8);
break;
}
}
}
}
- public int size {
+ ///
+ /// Gets or sets the size of this .
+ ///
+ public int Size {
get {
switch (MapType) {
case MapType.Source17:
diff --git a/LibBSP/Source/Structs/BSP/DisplacementInfo.cs b/LibBSP/Source/Structs/BSP/Displacement.cs
similarity index 65%
rename from LibBSP/Source/Structs/BSP/DisplacementInfo.cs
rename to LibBSP/Source/Structs/BSP/Displacement.cs
index 86ec42a..faabcb7 100644
--- a/LibBSP/Source/Structs/BSP/DisplacementInfo.cs
+++ b/LibBSP/Source/Structs/BSP/Displacement.cs
@@ -18,7 +18,7 @@ namespace LibBSP {
///
/// Holds all data for a Displacement from Source engine.
///
- public struct DisplacementInfo : ILumpObject {
+ public struct Displacement : ILumpObject {
///
/// The this came from.
@@ -54,7 +54,10 @@ namespace LibBSP {
}
}
- public Vector3 startPosition {
+ ///
+ /// Gets or sets the starting position of this .
+ ///
+ public Vector3 StartPosition {
get {
return new Vector3(BitConverter.ToSingle(Data, 0), BitConverter.ToSingle(Data, 4), BitConverter.ToSingle(Data, 8));
}
@@ -62,8 +65,23 @@ namespace LibBSP {
value.GetBytes().CopyTo(Data, 0);
}
}
-
- public int dispVertStart {
+
+ ///
+ /// Enumerates the es referenced by this .
+ ///
+ public IEnumerable Vertices {
+ get {
+ int numVertices = NumVertices;
+ for (int i = 0; i < numVertices; ++i) {
+ yield return Parent.Bsp.dispVerts[FirstVertexIndex + i];
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first used by this .
+ ///
+ public int FirstVertexIndex {
get {
return BitConverter.ToInt32(Data, 12);
}
@@ -72,7 +90,21 @@ namespace LibBSP {
}
}
- public int dispTriStart {
+ ///
+ /// Enumerates the flags for the triangles in this .
+ ///
+ public IEnumerable Triangles {
+ get {
+ for (int i = 0; i < NumTriangles; ++i) {
+ yield return (ushort)Parent.Bsp.displacementTriangles[FirstTriangleIndex + i];
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first Displacement Triangle used by this .
+ ///
+ public int FirstTriangleIndex {
get {
return BitConverter.ToInt32(Data, 16);
}
@@ -80,8 +112,11 @@ namespace LibBSP {
BitConverter.GetBytes(value).CopyTo(Data, 16);
}
}
-
- public int power {
+
+ ///
+ /// Gets or sets the power of this .
+ ///
+ public int Power {
get {
return BitConverter.ToInt32(Data, 20);
}
@@ -90,7 +125,30 @@ namespace LibBSP {
}
}
- public int minTess {
+ ///
+ /// Gets the number of vertices this uses, based on .
+ ///
+ public int NumVertices {
+ get {
+ int numSideVerts = (int)Math.Pow(2, Power) + 1;
+ return numSideVerts * numSideVerts;
+ }
+ }
+
+ ///
+ /// Gets the number of triangles this has, based on .
+ ///
+ public int NumTriangles {
+ get {
+ int side = Power * Power;
+ return 2 * side * side;
+ }
+ }
+
+ ///
+ /// Gets or sets the minimum allowed tesselation for this .
+ ///
+ public int MinimumTesselation {
get {
return BitConverter.ToInt32(Data, 24);
}
@@ -99,7 +157,10 @@ namespace LibBSP {
}
}
- public float smoothingAngle {
+ ///
+ /// Gets or sets the lighting smoothing angle for this .
+ ///
+ public float SmoothingAngle {
get {
return BitConverter.ToSingle(Data, 28);
}
@@ -108,7 +169,10 @@ namespace LibBSP {
}
}
- public int contents {
+ ///
+ /// Gets or sets the contents flags for this .
+ ///
+ public int Contents {
get {
return BitConverter.ToInt32(Data, 32);
}
@@ -117,7 +181,19 @@ namespace LibBSP {
}
}
- public ushort mapFace {
+ ///
+ /// Gets the this was made from, for texturing and other information.
+ ///
+ public Face Face {
+ get {
+ return Parent.Bsp.faces[FaceIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the this was made from, for texturing and other information.
+ ///
+ public ushort FaceIndex {
get {
return BitConverter.ToUInt16(Data, 36);
}
@@ -126,7 +202,10 @@ namespace LibBSP {
}
}
- public int lightmapAlphaStart {
+ ///
+ /// Get or sets the index of the lightmap alpha for this .
+ ///
+ public int LightmapAlphaStart {
get {
return BitConverter.ToInt32(Data, 38);
}
@@ -135,7 +214,10 @@ namespace LibBSP {
}
}
- public int lightmapSamplePositionStart {
+ ///
+ /// Gets or sets the index of the first lightmap sample position used by this .
+ ///
+ public int LightmapSamplePositionStart {
get {
return BitConverter.ToInt32(Data, 42);
}
@@ -144,9 +226,12 @@ namespace LibBSP {
}
}
- public uint[] allowedVerts {
+ ///
+ /// Gets or sets the allowed vertices for this .
+ ///
+ public uint[] AllowedVertices {
get {
- uint[] allowedVerts = new uint[10];
+ uint[] allowedVertices = new uint[10];
int offset = -1;
switch (MapType) {
case MapType.Source17:
@@ -176,10 +261,10 @@ namespace LibBSP {
}
if (offset >= 0) {
for (int i = 0; i < 10; ++i) {
- allowedVerts[i] = BitConverter.ToUInt32(Data, offset + (i * 4));
+ allowedVertices[i] = BitConverter.ToUInt32(Data, offset + (i * 4));
}
}
- return allowedVerts;
+ return allowedVertices;
}
set {
if (value.Length != 10) {
@@ -221,12 +306,12 @@ namespace LibBSP {
}
///
- /// Creates a new object from a byte array.
+ /// Creates a new object from a byte array.
///
/// byte array to parse.
- /// The this came from.
+ /// The this came from.
/// was null.
- public DisplacementInfo(byte[] data, ILump parent = null) {
+ public Displacement(byte[] data, ILump parent = null) {
if (data == null) {
throw new ArgumentNullException();
}
@@ -236,19 +321,19 @@ namespace LibBSP {
}
///
- /// Factory method to parse a byte array into a .
+ /// Factory method to parse a byte array into a .
///
/// The data to parse.
/// The this lump came from.
/// The associated with this lump.
- /// A .
+ /// A .
/// parameter was null.
- public static Lump LumpFactory(byte[] data, BSP bsp, LumpInfo lumpInfo) {
+ public static Lump LumpFactory(byte[] data, BSP bsp, LumpInfo lumpInfo) {
if (data == null) {
throw new ArgumentNullException();
}
- return new Lump(data, GetStructLength(bsp.version, lumpInfo.version), bsp, lumpInfo);
+ return new Lump(data, GetStructLength(bsp.version, lumpInfo.version), bsp, lumpInfo);
}
///
diff --git a/LibBSP/Source/Structs/BSP/DisplacementVertex.cs b/LibBSP/Source/Structs/BSP/DisplacementVertex.cs
index 7beb1ed..341cf0f 100644
--- a/LibBSP/Source/Structs/BSP/DisplacementVertex.cs
+++ b/LibBSP/Source/Structs/BSP/DisplacementVertex.cs
@@ -54,9 +54,9 @@ namespace LibBSP {
}
///
- /// The normalized vector direction this vertex points from "flat".
+ /// Gets or sets the normalized vector direction this vertex points from "flat".
///
- public Vector3 normal {
+ public Vector3 Normal {
get {
return new Vector3(BitConverter.ToSingle(Data, 0), BitConverter.ToSingle(Data, 4), BitConverter.ToSingle(Data, 8));
}
@@ -66,9 +66,9 @@ namespace LibBSP {
}
///
- /// Magnitude of normal, before normalization.
+ /// Gets or sets the magnitude of the vertex.
///
- public float dist {
+ public float Magnitude {
get {
return BitConverter.ToSingle(Data, 12);
}
@@ -78,9 +78,9 @@ namespace LibBSP {
}
///
- /// Alpha value of texture at this vertex.
+ /// Gets or sets the alpha value of the material at this vertex.
///
- public float alpha {
+ public float Alpha {
get {
return BitConverter.ToSingle(Data, 16);
}
@@ -105,19 +105,19 @@ namespace LibBSP {
}
///
- /// Factory method to parse a byte array into a object.
+ /// Factory method to parse a byte array into a object.
///
/// The data to parse.
/// The this lump came from.
/// The associated with this lump.
- /// A object.
+ /// A object.
/// parameter was null.
- public static DisplacementVertices LumpFactory(byte[] data, BSP bsp, LumpInfo lumpInfo) {
+ public static Lump LumpFactory(byte[] data, BSP bsp, LumpInfo lumpInfo) {
if (data == null) {
throw new ArgumentNullException();
}
- return new DisplacementVertices(data, GetStructLength(bsp.version, lumpInfo.version), bsp, lumpInfo);
+ return new Lump(data, GetStructLength(bsp.version, lumpInfo.version), bsp, lumpInfo);
}
///
diff --git a/LibBSP/Source/Structs/BSP/Edge.cs b/LibBSP/Source/Structs/BSP/Edge.cs
index 91c21be..c8aa663 100644
--- a/LibBSP/Source/Structs/BSP/Edge.cs
+++ b/LibBSP/Source/Structs/BSP/Edge.cs
@@ -1,8 +1,20 @@
+#if 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 || UNITY_5_3_OR_NEWER
+#define UNITY
+#if !UNITY_5_6_OR_NEWER
+#define OLDUNITY
+#endif
+#endif
+
using System;
-using System.Collections.Generic;
using System.Reflection;
namespace LibBSP {
+#if UNITY
+ using Vector3 = UnityEngine.Vector3;
+#if !OLDUNITY
+ using Vertex = UnityEngine.UIVertex;
+#endif
+#endif
///
/// Holds all the data for an edge in a BSP map.
@@ -43,7 +55,19 @@ namespace LibBSP {
}
}
- public int firstVertex {
+ ///
+ /// Gets the first in this Edge.
+ ///
+ public Vertex FirstVertex {
+ get {
+ return Parent.Bsp.vertices[FirstVertexIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first in this Edge.
+ ///
+ public int FirstVertexIndex {
get {
switch (MapType) {
case MapType.Quake:
@@ -102,8 +126,20 @@ namespace LibBSP {
}
}
}
-
- public int secondVertex {
+
+ ///
+ /// Gets the second in this Edge.
+ ///
+ public Vertex SecondVertex {
+ get {
+ return Parent.Bsp.vertices[SecondVertexIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the second in this Edge.
+ ///
+ public int SecondVertexIndex {
get {
switch (MapType) {
case MapType.Quake:
diff --git a/LibBSP/Source/Structs/BSP/Face.cs b/LibBSP/Source/Structs/BSP/Face.cs
index 54774f9..b6c2f49 100644
--- a/LibBSP/Source/Structs/BSP/Face.cs
+++ b/LibBSP/Source/Structs/BSP/Face.cs
@@ -1,5 +1,10 @@
#if 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 || UNITY_5_3_OR_NEWER
#define UNITY
+#if !UNITY_5_6_OR_NEWER
+// UIVertex was introduced in Unity 4.5 but it only had color, position and one UV.
+// From 4.6.0 until 5.5.6 it was missing two sets of UVs.
+#define OLDUNITY
+#endif
#endif
using System;
@@ -9,10 +14,16 @@ using System.Reflection;
namespace LibBSP {
#if UNITY
using Vector2 = UnityEngine.Vector2;
+ using Plane = UnityEngine.Plane;
+#if !OLDUNITY
+ using Vertex = UnityEngine.UIVertex;
+#endif
#elif GODOT
using Vector2 = Godot.Vector2;
+ using Plane = Godot.Plane;
#else
using Vector2 = System.Numerics.Vector2;
+ using Plane = System.Numerics.Plane;
#endif
///
@@ -60,7 +71,19 @@ namespace LibBSP {
}
}
- public int plane {
+ ///
+ /// Gets the Plane used by this .
+ ///
+ public Plane Plane {
+ get {
+ return Parent.Bsp.planes[PlaneIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the Plane used by this .
+ ///
+ public int PlaneIndex {
get {
switch (MapType) {
case MapType.Quake:
@@ -128,7 +151,10 @@ namespace LibBSP {
}
}
- public int side {
+ ///
+ /// Does the 's normal point in the same direction as the Plane's?
+ ///
+ public bool PlaneSide {
get {
switch (MapType) {
case MapType.Quake:
@@ -136,7 +162,7 @@ namespace LibBSP {
case MapType.Daikatana:
case MapType.SiN:
case MapType.SoF: {
- return BitConverter.ToUInt16(Data, 2);
+ return BitConverter.ToUInt16(Data, 2) > 0;
}
case MapType.Source18:
case MapType.Source19:
@@ -148,31 +174,26 @@ namespace LibBSP {
case MapType.L4D2:
case MapType.TacticalInterventionEncrypted:
case MapType.DMoMaM: {
- return (int)Data[2];
+ return Data[2] > 0;
}
case MapType.Vindictus: {
- return (int)Data[4];
+ return Data[4] > 0;
}
case MapType.Source17: {
- return (int)Data[34];
+ return Data[34] > 0;
}
default: {
- return -1;
+ return true;
}
}
}
set {
- byte[] bytes = BitConverter.GetBytes(value);
switch (MapType) {
case MapType.Quake:
case MapType.Quake2:
case MapType.Daikatana:
case MapType.SiN:
- case MapType.SoF: {
- Data[2] = bytes[0];
- Data[3] = bytes[1];
- break;
- }
+ case MapType.SoF:
case MapType.Source18:
case MapType.Source19:
case MapType.Source20:
@@ -183,22 +204,40 @@ namespace LibBSP {
case MapType.L4D2:
case MapType.TacticalInterventionEncrypted:
case MapType.DMoMaM: {
- Data[2] = bytes[0];
+ Data[2] = (byte)(value ? 1 : 0);
break;
}
case MapType.Vindictus: {
- Data[4] = bytes[0];
+ Data[4] = (byte)(value ? 1 : 0);
break;
}
case MapType.Source17: {
- Data[34] = bytes[0];
+ Data[34] = (byte)(value ? 1 : 0);
break;
}
}
}
}
-
- [Index("edges")] public int firstEdge {
+
+ ///
+ /// For formats which use s, enumerates the indices referenced
+ /// by this . A negative index means the is used backward from
+ /// its second to its first.
+ ///
+ public IEnumerable EdgeIndices {
+ get {
+ for (int i = 0; i < NumEdgeIndices; ++i) {
+ yield return (int)Parent.Bsp.surfEdges[FirstEdgeIndexIndex + i];
+ }
+ }
+ }
+
+ ///
+ /// For formats which use s, gets or sets the index of the first
+ /// index in this . A negative index means the is used backward
+ /// from its second to first.
+ ///
+ [Index("edges")] public int FirstEdgeIndexIndex {
get {
switch (MapType) {
case MapType.Quake:
@@ -262,7 +301,11 @@ namespace LibBSP {
}
}
- [Count("edges")] public int numEdges {
+ ///
+ /// For formats which use s, gets or sets the count of indices
+ /// in this .
+ ///
+ [Count("edges")] public int NumEdgeIndices {
get {
switch (MapType) {
case MapType.Quake:
@@ -327,8 +370,20 @@ namespace LibBSP {
}
}
}
+
+ ///
+ /// Gets the referenced by this .
+ ///
+ public Texture Texture {
+ get {
+ return Parent.Bsp.textures[TextureIndex];
+ }
+ }
- public int texture {
+ ///
+ /// Gets or sets the index of the used by this .
+ ///
+ public int TextureIndex {
get {
switch (MapType) {
case MapType.CoD:
@@ -392,8 +447,22 @@ namespace LibBSP {
}
}
}
+
+ ///
+ /// Enumerates the objects referenced by this .
+ ///
+ public IEnumerable Vertices {
+ get {
+ for (int i = 0; i < NumVertices; ++i) {
+ yield return Parent.Bsp.vertices[FirstVertexIndex + i];
+ }
+ }
+ }
- [Index("vertices")] public int firstVertex {
+ ///
+ /// Gets or sets the index of the first used by this .
+ ///
+ [Index("vertices")] public int FirstVertexIndex {
get {
switch (MapType) {
case MapType.CoD:
@@ -438,7 +507,10 @@ namespace LibBSP {
}
}
- [Count("vertices")] public int numVertices {
+ ///
+ /// Gets or sets the number of objects used by this .
+ ///
+ [Count("vertices")] public int NumVertices {
get {
switch (MapType) {
case MapType.CoD:
@@ -494,8 +566,20 @@ namespace LibBSP {
}
}
}
+
+ ///
+ /// For Nightfire, gets the material referenced by this .
+ ///
+ public Texture Material {
+ get {
+ return Parent.Bsp.materials[TextureIndex];
+ }
+ }
- public int material {
+ ///
+ /// For Nightfire, gets or sets the index of the material referenced by this .
+ ///
+ public int MaterialIndex {
get {
switch (MapType) {
case MapType.Nightfire: {
@@ -516,8 +600,20 @@ namespace LibBSP {
}
}
}
+
+ ///
+ /// Gets the returned by this .
+ ///
+ public TextureInfo TextureInfo {
+ get {
+ return Parent.Bsp.texInfo[TextureInfoIndex];
+ }
+ }
- public int textureInfo {
+ ///
+ /// Gets or sets the index of the used by this .
+ ///
+ public int TextureInfoIndex {
get {
switch (MapType) {
case MapType.Quake:
@@ -582,7 +678,10 @@ namespace LibBSP {
}
}
- public int displacement {
+ ///
+ /// Gets or sets the index of the using this .
+ ///
+ public int DisplacementIndex {
get {
switch (MapType) {
case MapType.Source18:
@@ -637,8 +736,20 @@ namespace LibBSP {
}
}
}
-
- public int original {
+
+ ///
+ /// Gets the original which was split to create this .
+ ///
+ public Face OriginalFace {
+ get {
+ return Parent.Bsp.originalFaces[OriginalFaceIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the original which was split to create this .
+ ///
+ public int OriginalFaceIndex {
get {
switch (MapType) {
case MapType.Source18:
@@ -702,7 +813,10 @@ namespace LibBSP {
}
}
- public int flags {
+ ///
+ /// Gets or sets the type (flags) of this face.
+ ///
+ public int Type {
get {
switch (MapType) {
case MapType.Quake3:
@@ -740,8 +854,24 @@ namespace LibBSP {
}
}
}
+
+ ///
+ /// For formats which use triangle corner indices, enumerates the indices of
+ /// objects used by this .
+ ///
+ public IEnumerable Indices {
+ get {
+ for (int i = 0; i < NumIndices; ++i) {
+ yield return (int)Parent.Bsp.indices[FirstIndexIndex + i];
+ }
+ }
+ }
- [Index("indices")] public int firstIndex {
+ ///
+ /// For formats which use triangle corner indices, gets or sets the index first index
+ /// used by this .
+ ///
+ [Index("indices")] public int FirstIndexIndex {
get {
switch (MapType) {
case MapType.CoD:
@@ -785,8 +915,12 @@ namespace LibBSP {
}
}
}
-
- [Count("indices")] public int numIndices {
+
+ ///
+ /// For formats which use triangle corner indices, gets or sets the count of indices
+ /// used by this .
+ ///
+ [Count("indices")] public int NumIndices {
get {
switch (MapType) {
case MapType.CoD:
@@ -843,7 +977,10 @@ namespace LibBSP {
}
}
- public int lightStyles {
+ ///
+ /// Gets or sets the flags for lightmap style used by this .
+ ///
+ public int LightStyle {
get {
switch (MapType) {
case MapType.Nightfire: {
@@ -865,7 +1002,10 @@ namespace LibBSP {
}
}
- public int lightMaps {
+ ///
+ /// Gets or sets the offset into the lightmap data this uses.
+ ///
+ public int LightMapOffset {
get {
switch (MapType) {
case MapType.Nightfire: {
@@ -887,7 +1027,10 @@ namespace LibBSP {
}
}
- public Vector2 patchSize {
+ ///
+ /// Gets the size of the used by this .
+ ///
+ public Vector2 PatchSize {
get {
switch (MapType) {
case MapType.Quake3:
diff --git a/LibBSP/Source/Structs/BSP/LODTerrain.cs b/LibBSP/Source/Structs/BSP/LODTerrain.cs
index 233a49d..762effe 100644
--- a/LibBSP/Source/Structs/BSP/LODTerrain.cs
+++ b/LibBSP/Source/Structs/BSP/LODTerrain.cs
@@ -43,7 +43,10 @@ namespace LibBSP {
}
}
- public byte flags {
+ ///
+ /// Gets or sets the flags for this terrain.
+ ///
+ public byte Flags {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -64,7 +67,10 @@ namespace LibBSP {
}
}
- public byte scale {
+ ///
+ /// Gets or sets the scale of this terrain.
+ ///
+ public byte Scale {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -85,7 +91,10 @@ namespace LibBSP {
}
}
- public byte[] lightmapCoords {
+ ///
+ /// Gets or sets the lightmap UVs for this terrain.
+ ///
+ public byte[] LightmapCoordinates {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -98,7 +107,7 @@ namespace LibBSP {
}
set {
if (value.Length != 2) {
- throw new ArgumentException("LightmapCoords array must have 2 elements.");
+ throw new ArgumentException("LightmapCoordinates array must have 2 elements.");
}
switch (MapType) {
case MapType.MOHAA: {
@@ -110,7 +119,10 @@ namespace LibBSP {
}
}
- public float[] textureCoords {
+ ///
+ /// Gets or sets the texture UVs for this terrain.
+ ///
+ public float[] UVs {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -132,7 +144,7 @@ namespace LibBSP {
}
set {
if (value.Length != 8) {
- throw new ArgumentException("TextureCoords array must have 8 elements.");
+ throw new ArgumentException("UVs array must have 8 elements.");
}
switch (MapType) {
case MapType.MOHAA: {
@@ -146,7 +158,10 @@ namespace LibBSP {
}
}
- public sbyte x {
+ ///
+ /// Gets or sets the X position of this terrain, on a 64x64 grid.
+ ///
+ public sbyte X {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -166,8 +181,11 @@ namespace LibBSP {
}
}
}
-
- public sbyte y {
+
+ ///
+ /// Gets or sets the Y position of this terrain, on a 64x64 grid.
+ ///
+ public sbyte Y {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -187,8 +205,11 @@ namespace LibBSP {
}
}
}
-
- public short baseZ {
+
+ ///
+ /// Gets or sets the Z position of this terrain.
+ ///
+ public short BaseZ {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -209,8 +230,20 @@ namespace LibBSP {
}
}
}
+
+ ///
+ /// Gets the referenced by this terrain.
+ ///
+ public Texture Texture {
+ get {
+ return Parent.Bsp.textures[TextureIndex];
+ }
+ }
- public ushort texture {
+ ///
+ /// Gets or sets the index for this terrain.
+ ///
+ public ushort TextureIndex {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -232,7 +265,10 @@ namespace LibBSP {
}
}
- public short lightmap {
+ ///
+ /// Gets or sets the lightmap index for this terrain.
+ ///
+ public short Lightmap {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -254,7 +290,10 @@ namespace LibBSP {
}
}
- public ushort[,] vertexFlags {
+ ///
+ /// Gets or sets the vertex flags for each vertex in this terrain.
+ ///
+ public ushort[,] VertexFlags {
get {
ushort[,] ret = new ushort[2,63];
switch (MapType) {
@@ -281,7 +320,10 @@ namespace LibBSP {
}
}
- public byte[,] heightmap {
+ ///
+ /// Gets or sets the heightmap for each vertex in this terrain.
+ ///
+ public byte[,] Heightmap {
get {
byte[,] ret = new byte[9, 9];
switch (MapType) {
diff --git a/LibBSP/Source/Structs/BSP/Leaf.cs b/LibBSP/Source/Structs/BSP/Leaf.cs
index 1582b7a..d5fdad5 100644
--- a/LibBSP/Source/Structs/BSP/Leaf.cs
+++ b/LibBSP/Source/Structs/BSP/Leaf.cs
@@ -43,7 +43,10 @@ namespace LibBSP {
}
}
- public int contents {
+ ///
+ /// Gets or sets the contents flags for this .
+ ///
+ public int Contents {
get {
switch (MapType) {
case MapType.SoF:
@@ -96,8 +99,22 @@ namespace LibBSP {
}
}
}
+
+ ///
+ /// Enumerates the brush indices used by this .
+ ///
+ public IEnumerable MarkBrushes {
+ get {
+ for (int i = 0; i < NumMarkBrushIndices; ++i) {
+ yield return (int)Parent.Bsp.markBrushes[FirstMarkBrushIndex + i];
+ }
+ }
+ }
- [Index("markBrushes")] public int firstMarkBrush {
+ ///
+ /// Gets or sets the index of the first mark brush reference for this .
+ ///
+ [Index("markBrushes")] public int FirstMarkBrushIndex {
get {
switch (MapType) {
case MapType.CoD4: {
@@ -195,8 +212,11 @@ namespace LibBSP {
}
}
}
-
- [Count("markBrushes")] public int numMarkBrushes {
+
+ ///
+ /// Gets or sets the count of mark brush references for this .
+ ///
+ [Count("markBrushes")] public int NumMarkBrushIndices {
get {
switch (MapType) {
case MapType.CoD4: {
@@ -294,8 +314,22 @@ namespace LibBSP {
}
}
}
+
+ ///
+ /// Enumerates the indices used by this .
+ ///
+ public IEnumerable MarkFaces {
+ get {
+ for (int i = 0; i < NumMarkFaceIndices; ++i) {
+ yield return (int)Parent.Bsp.markSurfaces[FirstMarkFaceIndex + i];
+ }
+ }
+ }
- [Index("markSurfaces")] public int firstMarkFace {
+ ///
+ /// Gets or sets the index of the first mark face reference for this .
+ ///
+ [Index("markSurfaces")] public int FirstMarkFaceIndex {
get {
switch (MapType) {
case MapType.CoD:
@@ -388,8 +422,11 @@ namespace LibBSP {
}
}
}
-
- [Count("markSurfaces")] public int numMarkFaces {
+
+ ///
+ /// Gets or sets the count of mark face references for this .
+ ///
+ [Count("markSurfaces")] public int NumMarkFaceIndices {
get {
switch (MapType) {
case MapType.CoD:
@@ -483,7 +520,10 @@ namespace LibBSP {
}
}
- public int pvs {
+ ///
+ /// Gets or sets the offset in the visibility data used by this .
+ ///
+ public int VisibilityOffset {
get {
switch (MapType) {
case MapType.Nightfire: {
diff --git a/LibBSP/Source/Structs/BSP/Lumps/DisplacementVertices.cs b/LibBSP/Source/Structs/BSP/Lumps/DisplacementVertices.cs
deleted file mode 100644
index bb69713..0000000
--- a/LibBSP/Source/Structs/BSP/Lumps/DisplacementVertices.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace LibBSP {
-
- ///
- /// Class representing a group of objects. Contains helpful methods to handle Displacement Vertices in the List.
- ///
- public class DisplacementVertices : Lump {
-
- ///
- /// Creates an empty object.
- ///
- /// The this lump came from.
- /// The associated with this lump.
- public DisplacementVertices(BSP bsp = null, LumpInfo lumpInfo = default(LumpInfo)) : base(bsp, lumpInfo) { }
-
- ///
- /// Creates a new that contains elements copied from the passed .
- ///
- /// The elements to copy into this Lump.
- /// The this lump came from.
- /// The associated with this lump.
- public DisplacementVertices(IEnumerable items, BSP bsp = null, LumpInfo lumpInfo = default(LumpInfo)) : base(items, bsp, lumpInfo) { }
-
- ///
- /// Creates an empty object with the specified initial capactiy.
- ///
- /// The number of elements that can initially be stored.
- /// The this lump came from.
- /// The associated with this lump.
- public DisplacementVertices(int capacity, BSP bsp = null, LumpInfo lumpInfo = default(LumpInfo)) : base(capacity, bsp, lumpInfo) { }
-
- ///
- /// Parses the passed byte array into a object.
- ///
- /// Array of bytes to parse.
- /// Number of bytes to copy into the children.
- /// The this lump came from.
- /// The associated with this lump.
- /// was null.
- public DisplacementVertices(byte[] data, int structLength, BSP bsp = null, LumpInfo lumpInfo = default(LumpInfo)) : base(data, structLength, bsp, lumpInfo) { }
-
- ///
- /// Gets enough vertices from the list for a displacement of power , starting at .
- ///
- /// The first vertex to get.
- /// The power of the displacement.
- /// Array of objects containing all the vertices in this displacement
- public DisplacementVertex[] GetVerticesInDisplacement(int first, int power) {
- int numSideVerts = (int)Math.Pow(2, power) + 1;
- int numVerts = numSideVerts * numSideVerts;
- DisplacementVertex[] ret = new DisplacementVertex[numVerts];
- for (int i = 0; i < numVerts; ++i) {
- ret[i] = this[first + i];
- }
- return ret;
- }
-
- }
-}
diff --git a/LibBSP/Source/Structs/BSP/Lumps/GameLump.cs b/LibBSP/Source/Structs/BSP/Lumps/GameLump.cs
index 5e5f27c..9b4a380 100644
--- a/LibBSP/Source/Structs/BSP/Lumps/GameLump.cs
+++ b/LibBSP/Source/Structs/BSP/Lumps/GameLump.cs
@@ -7,10 +7,14 @@ namespace LibBSP {
/// Enum containing known game lumps.
///
public enum GameLumpType : int {
+ /// LDR detail prop lighting.
hlpd = 1685089384,
+ /// HDR detail prop lighting.
tlpd = 1685089396,
+ /// Detail props.
prpd = 1685090928,
- sprp = 1936749168,
+ /// .
+ prps = 1936749168,
}
///
diff --git a/LibBSP/Source/Structs/BSP/Lumps/StaticProps.cs b/LibBSP/Source/Structs/BSP/Lumps/StaticProps.cs
index d413615..c6a6934 100644
--- a/LibBSP/Source/Structs/BSP/Lumps/StaticProps.cs
+++ b/LibBSP/Source/Structs/BSP/Lumps/StaticProps.cs
@@ -9,7 +9,15 @@ namespace LibBSP {
///
public class StaticProps : Lump {
- public string[] dictionary { get; private set; }
+ ///
+ /// Gets or sets the dictionary of prop model names.
+ ///
+ public string[] ModelDictionary { get; set; }
+
+ ///
+ /// Gets or sets the lists of leaves each occupies.
+ ///
+ public short[] LeafIndices { get; set; }
///
/// Creates an empty object.
@@ -17,7 +25,7 @@ namespace LibBSP {
/// The this lump came from.
/// The associated with this lump.
public StaticProps(BSP bsp = null, LumpInfo lumpInfo = default(LumpInfo)) : base(bsp, lumpInfo) {
- dictionary = new string[] { };
+ ModelDictionary = new string[] { };
}
///
@@ -28,7 +36,7 @@ namespace LibBSP {
/// The this lump came from.
/// The associated with this lump.
public StaticProps(IEnumerable items, IList dictionary, BSP bsp = null, LumpInfo lumpInfo = default(LumpInfo)) : base(items, bsp, lumpInfo) {
- this.dictionary = dictionary.ToArray();
+ this.ModelDictionary = dictionary.ToArray();
}
///
@@ -38,7 +46,7 @@ namespace LibBSP {
/// The this lump came from.
/// The associated with this lump.
public StaticProps(int capacity, BSP bsp = null, LumpInfo lumpInfo = default(LumpInfo)) : base(capacity, bsp, lumpInfo) {
- dictionary = new string[] { };
+ ModelDictionary = new string[] { };
}
///
@@ -54,17 +62,20 @@ namespace LibBSP {
throw new ArgumentNullException();
}
- dictionary = new string[0];
if (data.Length > 0) {
int offset = 0;
- dictionary = new string[BitConverter.ToInt32(data, 0)];
+ ModelDictionary = new string[BitConverter.ToInt32(data, 0)];
offset += 4;
- for (int i = 0; i < dictionary.Length; ++i) {
- dictionary[i] = data.ToNullTerminatedString(offset, 128);
+ for (int i = 0; i < ModelDictionary.Length; ++i) {
+ ModelDictionary[i] = data.ToNullTerminatedString(offset, 128);
offset += 128;
}
- int numLeafDefinitions = BitConverter.ToInt32(data, offset);
- offset += 4 + (numLeafDefinitions * 2);
+ LeafIndices = new short[BitConverter.ToInt32(data, offset)];
+ offset += 4;
+ for (int i = 0; i < LeafIndices.Length; ++i) {
+ LeafIndices[i] = BitConverter.ToInt16(data, offset);
+ offset += 2;
+ }
if (Bsp.version == MapType.Vindictus && lumpInfo.version == 6) {
int numPropScales = BitConverter.ToInt32(data, offset);
offset += 4 + (numPropScales * 16);
@@ -84,6 +95,8 @@ namespace LibBSP {
offset += structLength;
}
}
+ } else {
+ ModelDictionary = new string[0];
}
}
}
diff --git a/LibBSP/Source/Structs/BSP/Lumps/Textures.cs b/LibBSP/Source/Structs/BSP/Lumps/Textures.cs
index 311d30e..e6869bd 100644
--- a/LibBSP/Source/Structs/BSP/Lumps/Textures.cs
+++ b/LibBSP/Source/Structs/BSP/Lumps/Textures.cs
@@ -133,9 +133,9 @@ namespace LibBSP {
for (int i = 0; i < Count; ++i) {
if (current < offset) {
// Add 1 for the missing null byte.
- current += this[i].name.Length + 1;
+ current += this[i].Name.Length + 1;
} else {
- return this[i].name;
+ return this[i].Name;
}
}
// If we get to this point, the strings ended before target offset was reached
@@ -150,10 +150,10 @@ namespace LibBSP {
public int GetOffsetOf(string name) {
int offset = 0;
for (int i = 0; i < Count; ++i) {
- if (this[i].name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) {
+ if (this[i].Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) {
return offset;
} else {
- offset += this[i].name.Length + 1;
+ offset += this[i].Name.Length + 1;
}
}
// If we get here, the requested texture didn't exist.
diff --git a/LibBSP/Source/Structs/BSP/Model.cs b/LibBSP/Source/Structs/BSP/Model.cs
index 41e5094..48f6c88 100644
--- a/LibBSP/Source/Structs/BSP/Model.cs
+++ b/LibBSP/Source/Structs/BSP/Model.cs
@@ -43,7 +43,19 @@ namespace LibBSP {
}
}
- [Index("nodes")] public int headNode {
+ ///
+ /// Gets the head referenced by this .
+ ///
+ public Node HeadNode {
+ get {
+ return Parent.Bsp.nodes[HeadNodeIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the head used by this .
+ ///
+ [Index("nodes")] public int HeadNodeIndex {
get {
switch (MapType) {
case MapType.Quake:
@@ -102,7 +114,21 @@ namespace LibBSP {
}
}
- [Index("leaves")] public int firstLeaf {
+ ///
+ /// Enumerates the s used by this .
+ ///
+ public IEnumerable Leaves {
+ get {
+ for (int i = 0; i < NumLeaves; ++i) {
+ yield return Parent.Bsp.leaves[FirstLeafIndex + i];
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first used by this .
+ ///
+ [Index("leaves")] public int FirstLeafIndex {
get {
switch (MapType) {
case MapType.Nightfire: {
@@ -124,7 +150,10 @@ namespace LibBSP {
}
}
- [Count("leaves")] public int numLeaves {
+ ///
+ /// Gets or sets the count of objects used by this .
+ ///
+ [Count("leaves")] public int NumLeaves {
get {
switch (MapType) {
case MapType.Nightfire: {
@@ -146,7 +175,21 @@ namespace LibBSP {
}
}
- [Index("brushes")] public int firstBrush {
+ ///
+ /// Enumerates the es used by this .
+ ///
+ public IEnumerable Brushes {
+ get {
+ for (int i = 0; i < NumBrushes; ++i) {
+ yield return Parent.Bsp.brushes[FirstBrushIndex + i];
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first used by this .
+ ///
+ [Index("brushes")] public int FirstBrushIndex {
get {
switch (MapType) {
case MapType.STEF2:
@@ -189,7 +232,10 @@ namespace LibBSP {
}
}
- [Count("brushes")] public int numBrushes {
+ ///
+ /// Gets or sets the count of objects referenced by this .
+ ///
+ [Count("brushes")] public int NumBrushes {
get {
switch (MapType) {
case MapType.STEF2:
@@ -232,7 +278,21 @@ namespace LibBSP {
}
}
- [Index("faces")] public int firstFace {
+ ///
+ /// Enumerates the s used by this .
+ ///
+ public IEnumerable Faces {
+ get {
+ for (int i = 0; i < NumFaces; ++i) {
+ yield return Parent.Bsp.faces[FirstFaceIndex + i];
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first used by this .
+ ///
+ [Index("faces")] public int FirstFaceIndex {
get {
switch (MapType) {
case MapType.CoD4: {
@@ -332,7 +392,10 @@ namespace LibBSP {
}
}
- [Count("faces")] public int numFaces {
+ ///
+ /// Gets or sets the count of objects referenced by this .
+ ///
+ [Count("faces")] public int NumFaces {
get {
switch (MapType) {
case MapType.CoD4: {
@@ -432,12 +495,24 @@ namespace LibBSP {
}
}
- [Index("markSurfaces")]
- public int firstLeafPatch {
+ ///
+ /// Enumerates the patch indices used by this .
+ ///
+ public IEnumerable PatchIndices {
+ get {
+ for (int i = 0; i < NumPatchIndices; ++i) {
+ yield return (int)Parent.Bsp.leafPatches[FirstPatchIndicesIndex + i];
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first patch index for this .
+ ///
+ [Index("patchIndices")] public int FirstPatchIndicesIndex {
get {
switch (MapType) {
- case MapType.CoD:
- case MapType.CoD2: {
+ case MapType.CoD: {
return BitConverter.ToInt32(Data, 32);
}
default: {
@@ -448,8 +523,7 @@ namespace LibBSP {
set {
byte[] bytes = BitConverter.GetBytes(value);
switch (MapType) {
- case MapType.CoD:
- case MapType.CoD2: {
+ case MapType.CoD: {
bytes.CopyTo(Data, 32);
break;
}
@@ -457,11 +531,13 @@ namespace LibBSP {
}
}
- [Count("markSurfaces")] public int numLeafPatches {
+ ///
+ /// Gets or sets the count of patch indices referenced by this .
+ ///
+ [Count("patchIndices")] public int NumPatchIndices {
get {
switch (MapType) {
- case MapType.CoD:
- case MapType.CoD2: {
+ case MapType.CoD: {
return BitConverter.ToInt32(Data, 36);
}
default: {
@@ -472,8 +548,7 @@ namespace LibBSP {
set {
byte[] bytes = BitConverter.GetBytes(value);
switch (MapType) {
- case MapType.CoD:
- case MapType.CoD2: {
+ case MapType.CoD: {
bytes.CopyTo(Data, 36);
break;
}
diff --git a/LibBSP/Source/Structs/BSP/Node.cs b/LibBSP/Source/Structs/BSP/Node.cs
index 377ee78..50b9a75 100644
--- a/LibBSP/Source/Structs/BSP/Node.cs
+++ b/LibBSP/Source/Structs/BSP/Node.cs
@@ -1,8 +1,19 @@
+#if 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 || UNITY_5_3_OR_NEWER
+#define UNITY
+#endif
+
using System;
using System.Collections.Generic;
using System.Reflection;
namespace LibBSP {
+#if UNITY
+ using Plane = UnityEngine.Plane;
+#elif GODOT
+ using Plane = Godot.Plane;
+#else
+ using Plane = System.Numerics.Plane;
+#endif
///
/// Contains all data needed for a node in a BSP tree.
@@ -43,7 +54,19 @@ namespace LibBSP {
}
}
- public int plane {
+ ///
+ /// Gets the Plane used by this .
+ ///
+ public Plane Plane {
+ get {
+ return Parent.Bsp.planes[PlaneIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the Plane used by this .
+ ///
+ public int PlaneIndex {
get {
return BitConverter.ToInt32(Data, 0);
}
@@ -52,7 +75,23 @@ namespace LibBSP {
}
}
- public int child1 {
+ ///
+ /// Gets the first child of this . If is positive, the child will be
+ /// another . Otherwise it's a .
+ ///
+ public ILumpObject Child1 {
+ get {
+ if (Child1Index >= 0) {
+ return Parent.Bsp.nodes[Child1Index];
+ }
+ return Parent.Bsp.leaves[-Child1Index];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first child of this , positive for other s, negative for s.
+ ///
+ public int Child1Index {
get {
switch (MapType) {
case MapType.Quake: {
@@ -130,7 +169,23 @@ namespace LibBSP {
}
}
- public int child2 {
+ ///
+ /// Gets the second child of this . If is positive, the child will be
+ /// another . Otherwise it's a .
+ ///
+ public ILumpObject Child2 {
+ get {
+ if (Child2Index >= 0) {
+ return Parent.Bsp.nodes[Child2Index];
+ }
+ return Parent.Bsp.leaves[-Child2Index];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the second child of this , positive for other s, negative for s.
+ ///
+ public int Child2Index {
get {
switch (MapType) {
case MapType.Quake: {
diff --git a/LibBSP/Source/Structs/BSP/Patch.cs b/LibBSP/Source/Structs/BSP/Patch.cs
index f67c184..1a0bc48 100644
--- a/LibBSP/Source/Structs/BSP/Patch.cs
+++ b/LibBSP/Source/Structs/BSP/Patch.cs
@@ -1,5 +1,10 @@
#if 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 || UNITY_5_3_OR_NEWER
#define UNITY
+#if !UNITY_5_6_OR_NEWER
+// UIVertex was introduced in Unity 4.5 but it only had color, position and one UV.
+// From 4.6.0 until 5.5.6 it was missing two sets of UVs.
+#define OLDUNITY
+#endif
#endif
using System;
@@ -9,15 +14,27 @@ using System.Reflection;
namespace LibBSP {
#if UNITY
using Vector2 = UnityEngine.Vector2;
+ using Vector3 = UnityEngine.Vector3;
+#if !OLDUNITY
+ using Vertex = UnityEngine.UIVertex;
+#endif
#elif GODOT
using Vector2 = Godot.Vector2;
+ using Vector3 = Godot.Vector3;
#else
using Vector2 = System.Numerics.Vector2;
+ using Vector3 = System.Numerics.Vector3;
#endif
///
/// Holds the data for a patch in a CoD BSP.
///
+ ///
+ /// This lump only seems to be used for patch collision data, the visual parts of patch and terrain
+ /// meshes are still stored in the s lump. Since patches are stored this way and the
+ /// CoD structure does away with Quake 3's type field, there's no easy reliable way
+ /// of getting UVs for the vertices.
+ ///
public struct Patch : ILumpObject {
///
@@ -54,7 +71,19 @@ namespace LibBSP {
}
}
- public short shader {
+ ///
+ /// Gets the referenced by this .
+ ///
+ public Texture Shader {
+ get {
+ return Parent.Bsp.textures[ShaderIndex];
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the used by this .
+ ///
+ public int ShaderIndex {
get {
switch (MapType) {
case MapType.CoD: {
@@ -76,7 +105,10 @@ namespace LibBSP {
}
}
- public short patchType {
+ ///
+ /// Gets or sets the type of this is. 0 is a typical patch, 1 is a terrain.
+ ///
+ public short Type {
get {
switch (MapType) {
case MapType.CoD: {
@@ -98,11 +130,14 @@ namespace LibBSP {
}
}
- public Vector2 dimensions {
+ ///
+ /// If this is a typical patch, gets or sets the dimensions of this patch.
+ ///
+ public Vector2 Dimensions {
get {
switch (MapType) {
case MapType.CoD: {
- if (patchType == 0) {
+ if (Type == 0) {
return new Vector2(BitConverter.ToInt16(Data, 4), BitConverter.ToInt16(Data, 6));
} else {
return new Vector2(float.NaN, float.NaN);
@@ -116,7 +151,7 @@ namespace LibBSP {
set {
switch (MapType) {
case MapType.CoD: {
- if (patchType == 0) {
+ if (Type == 0) {
BitConverter.GetBytes((short)value.X()).CopyTo(Data, 4);
BitConverter.GetBytes((short)value.Y()).CopyTo(Data, 6);
}
@@ -126,11 +161,14 @@ namespace LibBSP {
}
}
- public int flags {
+ ///
+ /// If this is a typical patch, gets or sets the flags on this patch.
+ ///
+ public int Flags {
get {
switch (MapType) {
case MapType.CoD: {
- if (patchType == 0) {
+ if (Type == 0) {
return BitConverter.ToInt32(Data, 8);
} else {
return -1;
@@ -145,7 +183,7 @@ namespace LibBSP {
byte[] bytes = BitConverter.GetBytes(value);
switch (MapType) {
case MapType.CoD: {
- if (patchType == 0) {
+ if (Type == 0) {
bytes.CopyTo(Data, 8);
}
break;
@@ -153,14 +191,28 @@ namespace LibBSP {
}
}
}
-
- [Index("patchVerts")] public int firstVertex {
+
+ ///
+ /// Enumerates the Patch es referenced by this .
+ ///
+ public IEnumerable Vertices {
+ get {
+ for (int i = 0; i < NumVertices; ++i) {
+ yield return Parent.Bsp.patchVerts[FirstVertex + i];
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first Patch used by this .
+ ///
+ [Index("patchVerts")] public int FirstVertex {
get {
switch (MapType) {
case MapType.CoD: {
- if (patchType == 0) {
+ if (Type == 0) {
return BitConverter.ToInt32(Data, 12);
- } else if (patchType == 1) {
+ } else if (Type == 1) {
return BitConverter.ToInt32(Data, 8);
} else {
return -1;
@@ -175,9 +227,9 @@ namespace LibBSP {
byte[] bytes = BitConverter.GetBytes(value);
switch (MapType) {
case MapType.CoD: {
- if (patchType == 0) {
+ if (Type == 0) {
bytes.CopyTo(Data, 12);
- } else if (patchType == 1) {
+ } else if (Type == 1) {
bytes.CopyTo(Data, 8);
}
break;
@@ -185,14 +237,17 @@ namespace LibBSP {
}
}
}
-
- [Count("patchVerts")] public int numVertices {
+
+ ///
+ /// Gets the count of Patch es used by this .
+ ///
+ [Count("patchVerts")] public int NumVertices {
get {
switch (MapType) {
case MapType.CoD: {
- if (patchType == 0) {
+ if (Type == 0) {
return BitConverter.ToInt16(Data, 4) * BitConverter.ToInt16(Data, 6);
- } else if (patchType == 1) {
+ } else if (Type == 1) {
return BitConverter.ToInt16(Data, 4);
} else {
return -1;
@@ -207,21 +262,39 @@ namespace LibBSP {
byte[] bytes = BitConverter.GetBytes(value);
switch (MapType) {
case MapType.CoD: {
- if (patchType == 1) {
+ if (Type == 1) {
Data[4] = bytes[0];
Data[5] = bytes[1];
+ } else {
+ throw new NotSupportedException("Cannot set count of Patch Vertices on a pure patch. Set Patch.Dimensions instead.");
}
break;
}
}
}
}
+
+ ///
+ /// If this is a terrain, enumerates the Patch indices
+ /// referenced by this .
+ ///
+ public IEnumerable VertexIndices {
+ get {
+ for (int i = 0; i < NumVertexIndices; ++i) {
+ yield return (short)Parent.Bsp.patchIndices[FirstVertexIndex + i];
+ }
+ }
+ }
- [Count("patchIndices")] public int numIndices {
+ ///
+ /// If this is a terrain, gets the count of Patch indices
+ /// used by this .
+ ///
+ [Count("patchIndices")] public int NumVertexIndices {
get {
switch (MapType) {
case MapType.CoD: {
- if (patchType == 1) {
+ if (Type == 1) {
return BitConverter.ToInt16(Data, 6);
} else {
return -1;
@@ -236,7 +309,7 @@ namespace LibBSP {
byte[] bytes = BitConverter.GetBytes(value);
switch (MapType) {
case MapType.CoD: {
- if (patchType == 1) {
+ if (Type == 1) {
Data[6] = bytes[0];
Data[7] = bytes[1];
}
@@ -245,12 +318,16 @@ namespace LibBSP {
}
}
}
-
- [Index("patchIndices")] public int firstIndex {
+
+ ///
+ /// If this is a terrain, gets or sets the index of the first Patch
+ /// index used by this .
+ ///
+ [Index("patchIndices")] public int FirstVertexIndex {
get {
switch (MapType) {
case MapType.CoD: {
- if (patchType == 1) {
+ if (Type == 1) {
return BitConverter.ToInt32(Data, 12);
} else {
return -1;
@@ -265,7 +342,7 @@ namespace LibBSP {
byte[] bytes = BitConverter.GetBytes(value);
switch (MapType) {
case MapType.CoD: {
- if (patchType == 1) {
+ if (Type == 1) {
bytes.CopyTo(Data, 12);
}
break;
diff --git a/LibBSP/Source/Structs/BSP/StaticModel.cs b/LibBSP/Source/Structs/BSP/StaticModel.cs
index 67849bc..ae5fd50 100644
--- a/LibBSP/Source/Structs/BSP/StaticModel.cs
+++ b/LibBSP/Source/Structs/BSP/StaticModel.cs
@@ -55,7 +55,10 @@ namespace LibBSP {
}
}
- public string name {
+ ///
+ /// Gets or sets the name of the model.
+ ///
+ public string Name {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -80,7 +83,10 @@ namespace LibBSP {
}
}
- public Vector3 origin {
+ ///
+ /// Gets or sets the origin of this model.
+ ///
+ public Vector3 Origin {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -101,7 +107,10 @@ namespace LibBSP {
}
}
- public Vector3 angles {
+ ///
+ /// Gets or sets the Angles for this model.
+ ///
+ public Vector3 Angles {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -122,7 +131,10 @@ namespace LibBSP {
}
}
- public float scale {
+ ///
+ /// Gets or sets the uniform scale of this model.
+ ///
+ public float Scale {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -143,50 +155,6 @@ namespace LibBSP {
}
}
}
-
- [Index("vertices")] public int firstVertex {
- get {
- switch (MapType) {
- case MapType.MOHAA: {
- return BitConverter.ToInt32(Data, 156);
- }
- default: {
- return -1;
- }
- }
- }
- set {
- byte[] bytes = BitConverter.GetBytes(value);
- switch (MapType) {
- case MapType.MOHAA: {
- bytes.CopyTo(Data, 156);
- break;
- }
- }
- }
- }
-
- [Count("vertices")] public short numVertices {
- get {
- switch (MapType) {
- case MapType.MOHAA: {
- return BitConverter.ToInt16(Data, 160);
- }
- default: {
- return -1;
- }
- }
- }
- set {
- byte[] bytes = BitConverter.GetBytes(value);
- switch (MapType) {
- case MapType.MOHAA: {
- bytes.CopyTo(Data, 160);
- break;
- }
- }
- }
- }
///
/// Creates a new object from a byte array.
diff --git a/LibBSP/Source/Structs/BSP/StaticProp.cs b/LibBSP/Source/Structs/BSP/StaticProp.cs
index 17bb6ad..f916d05 100644
--- a/LibBSP/Source/Structs/BSP/StaticProp.cs
+++ b/LibBSP/Source/Structs/BSP/StaticProp.cs
@@ -3,6 +3,7 @@
#endif
using System;
+using System.Collections.Generic;
using System.Text;
namespace LibBSP {
@@ -13,8 +14,8 @@ namespace LibBSP {
using Color = Godot.Color;
using Vector3 = Godot.Vector3;
#else
- using Vector3 = System.Numerics.Vector3;
using Color = System.Drawing.Color;
+ using Vector3 = System.Numerics.Vector3;
#endif
///
@@ -56,7 +57,10 @@ namespace LibBSP {
}
}
- public Vector3 origin {
+ ///
+ /// Gets or sets the origin of this model.
+ ///
+ public Vector3 Origin {
get {
switch (MapType) {
case MapType.Source17:
@@ -128,8 +132,11 @@ namespace LibBSP {
}
}
}
-
- public Vector3 angles {
+
+ ///
+ /// Gets or sets the Angles for this model.
+ ///
+ public Vector3 Angles {
get {
switch (MapType) {
case MapType.Source17:
@@ -201,8 +208,20 @@ namespace LibBSP {
}
}
}
+
+ ///
+ /// Gets the name of the model for this from .
+ ///
+ public string Model {
+ get {
+ return ((StaticProps)Parent).ModelDictionary[ModelIndex];
+ }
+ }
- public short dictionaryEntry {
+ ///
+ /// Gets or sets the index of this model's name in .
+ ///
+ public short ModelIndex {
get {
switch (MapType) {
case MapType.Source17:
@@ -276,7 +295,22 @@ namespace LibBSP {
}
}
- public short firstLeaf {
+ ///
+ /// Enumerates the indices referenced by this .
+ ///
+ public IEnumerable LeafIndices {
+ get {
+ for (int i = 0; i < NumLeafIndices; ++i) {
+ yield return ((StaticProps)Parent).LeafIndices[FirstLeafIndexIndex + i];
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets the index of the first index in
+ /// for the leaves containing this .
+ ///
+ public short FirstLeafIndexIndex {
get {
switch (MapType) {
case MapType.Source17:
@@ -346,7 +380,11 @@ namespace LibBSP {
}
}
- public short numLeafs {
+ ///
+ /// Gets the number of indices in for leaves
+ /// which contain this .
+ ///
+ public short NumLeafIndices {
get {
switch (MapType) {
case MapType.Source17:
@@ -416,7 +454,10 @@ namespace LibBSP {
}
}
- public byte solidity {
+ ///
+ /// Gets or sets the solidity type of this .
+ ///
+ public byte Solidity {
get {
switch (MapType) {
case MapType.Source17:
@@ -489,7 +530,10 @@ namespace LibBSP {
}
}
- public byte flags {
+ ///
+ /// Gets or sets the flags of this .
+ ///
+ public byte Flags {
get {
switch (MapType) {
case MapType.Source17:
@@ -562,7 +606,10 @@ namespace LibBSP {
}
}
- public int skin {
+ ///
+ /// Gets or sets the model skin used by this .
+ ///
+ public int Skin {
get {
switch (MapType) {
case MapType.Source17:
@@ -649,7 +696,10 @@ namespace LibBSP {
}
}
- public float minFadeDist {
+ ///
+ /// Gets or sets the distance at which this will start to fade out.
+ ///
+ public float MinimumFadeDistance {
get {
switch (MapType) {
case MapType.Source17:
@@ -735,8 +785,11 @@ namespace LibBSP {
}
}
}
-
- public float maxFadeDist {
+
+ ///
+ /// Gets or sets the distance at which this will finish fading out.
+ ///
+ public float MaximumFadeDistance {
get {
switch (MapType) {
case MapType.Source17:
@@ -823,7 +876,10 @@ namespace LibBSP {
}
}
- public Vector3 lightingOrigin {
+ ///
+ /// Gets or sets the lighting origin of this .
+ ///
+ public Vector3 LightingOrigin {
get {
switch (MapType) {
case MapType.Source17:
@@ -910,7 +966,10 @@ namespace LibBSP {
}
}
- public float forcedFadeScale {
+ ///
+ /// Gets or sets the fade distance scale for this .
+ ///
+ public float ForcedFadeScale {
get {
switch (MapType) {
case MapType.Source17:
@@ -995,7 +1054,10 @@ namespace LibBSP {
}
}
- public short minDXLevel {
+ ///
+ /// Gets or sets the minimum DirectX version supported for this to be visible.
+ ///
+ public short MinimumDirectXLevel {
get {
switch (MapType) {
case MapType.Source17:
@@ -1049,7 +1111,10 @@ namespace LibBSP {
}
}
- public short maxDXLevel {
+ ///
+ /// Gets or sets the maximum DirectX version supported for this to be visible.
+ ///
+ public short MaximumDirectXLevel {
get {
switch (MapType) {
case MapType.Source17:
@@ -1103,7 +1168,10 @@ namespace LibBSP {
}
}
- public byte minCPULevel {
+ ///
+ /// Gets or sets the minimum CPU level supported for this to be visible.
+ ///
+ public byte MinimumCPULevel {
get {
switch (MapType) {
case MapType.Source17:
@@ -1181,7 +1249,10 @@ namespace LibBSP {
}
}
- public byte maxCPULevel {
+ ///
+ /// Gets or sets the maximum CPU level supported for this to be visible.
+ ///
+ public byte MaximumCPULevel {
get {
switch (MapType) {
case MapType.Source17:
@@ -1259,7 +1330,10 @@ namespace LibBSP {
}
}
- public byte minGPULevel {
+ ///
+ /// Gets or sets the minimum GPU level supported for this to be visible.
+ ///
+ public byte MinimumGPULevel {
get {
switch (MapType) {
case MapType.Source17:
@@ -1337,7 +1411,10 @@ namespace LibBSP {
}
}
- public byte maxGPULevel {
+ ///
+ /// Gets or sets the maximum GPU level supported for this to be visible.
+ ///
+ public byte MaximumGPULevel {
get {
switch (MapType) {
case MapType.Source17:
@@ -1415,7 +1492,10 @@ namespace LibBSP {
}
}
- public Color diffuseModulaton {
+ ///
+ /// Gets or sets the diffuse modulation of this .
+ ///
+ public Color DiffuseModulaton {
get {
switch (MapType) {
case MapType.Source17:
@@ -1495,7 +1575,10 @@ namespace LibBSP {
}
}
- public float scale {
+ ///
+ /// Gets or sets the uniform scale of this .
+ ///
+ public float Scale {
get {
switch (MapType) {
case MapType.Source17:
@@ -1551,7 +1634,10 @@ namespace LibBSP {
}
}
- public string targetname {
+ ///
+ /// Gets or sets the of this .
+ ///
+ public string Name {
get {
switch (MapType) {
case MapType.Source20: {
diff --git a/LibBSP/Source/Structs/BSP/Texture.cs b/LibBSP/Source/Structs/BSP/Texture.cs
index 151d59b..b5a33a3 100644
--- a/LibBSP/Source/Structs/BSP/Texture.cs
+++ b/LibBSP/Source/Structs/BSP/Texture.cs
@@ -63,7 +63,10 @@ namespace LibBSP {
}
}
- public string name {
+ ///
+ /// Gets or sets the name of this .
+ ///
+ public string Name {
get {
switch (MapType) {
case MapType.Quake: {
@@ -171,7 +174,10 @@ namespace LibBSP {
}
}
- public string mask {
+ ///
+ /// Gets or sets the name of the mask used on this .
+ ///
+ public string Mask {
get {
switch (MapType) {
case MapType.MOHAA: {
@@ -196,7 +202,10 @@ namespace LibBSP {
}
}
- public int flags {
+ ///
+ /// Gets or sets the flags on this .
+ ///
+ public int Flags {
get {
switch (MapType) {
case MapType.Quake2:
@@ -247,7 +256,10 @@ namespace LibBSP {
}
}
- public int contents {
+ ///
+ /// Gets or sets the contents flags used by this .
+ ///
+ public int Contents {
get {
switch (MapType) {
case MapType.STEF2:
@@ -285,7 +297,10 @@ namespace LibBSP {
}
}
- public TextureInfo texAxes {
+ ///
+ /// Gets or sets the in this .
+ ///
+ public TextureInfo TextureInfo {
get {
switch (MapType) {
case MapType.Quake2:
@@ -309,13 +324,13 @@ namespace LibBSP {
case MapType.SoF:
case MapType.Daikatana:
case MapType.SiN: {
- byte[] bytes = value.uAxis.GetBytes();
+ byte[] bytes = value.UAxis.GetBytes();
bytes.CopyTo(Data, 0);
- bytes = value.vAxis.GetBytes();
+ bytes = value.VAxis.GetBytes();
bytes.CopyTo(Data, 16);
- bytes = BitConverter.GetBytes(value.translation.X());
+ bytes = BitConverter.GetBytes(value.Translation.X());
bytes.CopyTo(Data, 12);
- bytes = BitConverter.GetBytes(value.translation.Y());
+ bytes = BitConverter.GetBytes(value.Translation.Y());
bytes.CopyTo(Data, 28);
break;
}
diff --git a/LibBSP/Source/Structs/BSP/TextureData.cs b/LibBSP/Source/Structs/BSP/TextureData.cs
index 4f62c30..09ed3eb 100644
--- a/LibBSP/Source/Structs/BSP/TextureData.cs
+++ b/LibBSP/Source/Structs/BSP/TextureData.cs
@@ -8,11 +8,14 @@ using System.Reflection;
namespace LibBSP {
#if UNITY
- using Vector3 = UnityEngine.Vector3;
+ using Color = UnityEngine.Color32;
+ using Vector2 = UnityEngine.Vector2;
#elif GODOT
- using Vector3 = Godot.Vector3;
+ using Color = Godot.Color;
+ using Vector2 = Godot.Vector2;
#else
- using Vector3 = System.Numerics.Vector3;
+ using Color = System.Drawing.Color;
+ using Vector2 = System.Numerics.Vector2;
#endif
///
@@ -54,16 +57,35 @@ namespace LibBSP {
}
}
- public Vector3 reflectivity {
+ ///
+ /// Gets or sets the reflectivity color of this .
+ ///
+ public Color Reflectivity {
get {
- return new Vector3(BitConverter.ToSingle(Data, 0), BitConverter.ToSingle(Data, 4), BitConverter.ToSingle(Data, 8));
+ return ColorExtensions.FromArgb((int)(BitConverter.ToSingle(Data, 0) * 255), (int)(BitConverter.ToSingle(Data, 4) * 255), (int)(BitConverter.ToSingle(Data, 8) * 255), 255);
}
set {
+ float r = value.R() / 255f;
+ float g = value.G() / 255f;
+ float b = value.B() / 255f;
value.GetBytes().CopyTo(Data, 0);
}
}
+
+ ///
+ /// Gets the offset into for the texture name for this .
+ ///
+ public uint TextureStringOffset {
+ get {
+ return (uint)Parent.Bsp.texTable[TextureStringOffsetIndex];
+ }
+ }
- public int stringTableIndex {
+ ///
+ /// Gets or sets the index into , which is an offset into for
+ /// the texture name for this .
+ ///
+ public int TextureStringOffsetIndex {
get {
return BitConverter.ToInt32(Data, 12);
}
@@ -72,39 +94,33 @@ namespace LibBSP {
}
}
- public int width {
+ ///
+ /// Gets or sets the actual size of the referenced by this .
+ ///
+ public Vector2 Size {
get {
- return BitConverter.ToInt32(Data, 16);
+ return new Vector2(BitConverter.ToInt32(Data, 16), BitConverter.ToInt32(Data, 20));
}
set {
- BitConverter.GetBytes(value).CopyTo(Data, 16);
+ int width = (int)value.X();
+ int height = (int)value.Y();
+ BitConverter.GetBytes(width).CopyTo(Data, 16);
+ BitConverter.GetBytes(height).CopyTo(Data, 20);
}
}
-
- public int height {
+
+ ///
+ /// Gets or sets the internal size of the referenced by this .
+ ///
+ public Vector2 ViewSize {
get {
- return BitConverter.ToInt32(Data, 20);
+ return new Vector2(BitConverter.ToInt32(Data, 24), BitConverter.ToInt32(Data, 28));
}
set {
- BitConverter.GetBytes(value).CopyTo(Data, 20);
- }
- }
-
- public int view_width {
- get {
- return BitConverter.ToInt32(Data, 24);
- }
- set {
- BitConverter.GetBytes(value).CopyTo(Data, 24);
- }
- }
-
- public int view_height {
- get {
- return BitConverter.ToInt32(Data, 28);
- }
- set {
- BitConverter.GetBytes(value).CopyTo(Data, 28);
+ int width = (int)value.X();
+ int height = (int)value.Y();
+ BitConverter.GetBytes(width).CopyTo(Data, 24);
+ BitConverter.GetBytes(height).CopyTo(Data, 28);
}
}
diff --git a/LibBSP/Source/Structs/Common/Entity.cs b/LibBSP/Source/Structs/Common/Entity.cs
index 3201cda..56361f5 100644
--- a/LibBSP/Source/Structs/Common/Entity.cs
+++ b/LibBSP/Source/Structs/Common/Entity.cs
@@ -76,12 +76,12 @@ namespace LibBSP {
///
/// Gets whether this is brush-based or not.
///
- public bool brushBased { get { return brushes.Count > 0 || modelNumber >= 0; } }
+ public bool IsBrushBased { get { return brushes.Count > 0 || ModelNumber >= 0; } }
///
/// Wrapper for the "spawnflags" attribute.
///
- public uint spawnflags {
+ public uint Spawnflags {
get {
try {
if (ContainsKey("spawnflags")) {
@@ -101,7 +101,7 @@ namespace LibBSP {
///
/// Wrapper for the "origin" attribute.
///
- public Vector3 origin {
+ public Vector3 Origin {
get {
Vector4 vec = GetVector("origin");
return new Vector3(vec.X(), vec.Y(), vec.Z());
@@ -114,7 +114,7 @@ namespace LibBSP {
///
/// Wrapper for the "angles" attribute.
///
- public Vector3 angles {
+ public Vector3 Angles {
get {
Vector4 vec = GetVector("angles");
return new Vector3(vec.X(), vec.Y(), vec.Z());
@@ -127,7 +127,7 @@ namespace LibBSP {
///
/// Wrapper for the "targetname" attribute.
///
- public string name {
+ public string Name {
get {
if (ContainsKey("targetname")) {
return this["targetname"];
@@ -146,7 +146,7 @@ namespace LibBSP {
/// Wrapper for the "classname" attribute.
///
/// If an entity has no class, it has no behavior. It's either an error or metadata.
- public string className {
+ public string ClassName {
get {
if (ContainsKey("classname")) {
return this["classname"];
@@ -159,12 +159,28 @@ namespace LibBSP {
}
}
+ ///
+ /// Gets or sets the model name for this . If this is a
+ /// brush-based , consider using instead.
+ ///
+ public string Model {
+ get {
+ if (ContainsKey("model")) {
+ return this["model"];
+ }
+ return null;
+ }
+ set {
+ this["model"] = value;
+ }
+ }
+
///
/// If there's a model number in the attributes list, this method fetches it
/// and returns it. If there is no model defined, or it's not a numerical
/// value, then -1 is returned. If it's the worldspawn then a 0 is returned.
///
- public int modelNumber {
+ public int ModelNumber {
get {
try {
if (this["classname"] == "worldspawn") {
@@ -476,7 +492,7 @@ namespace LibBSP {
/// 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);
+ return ((Spawnflags & bits) == bits);
}
///
@@ -484,7 +500,7 @@ namespace LibBSP {
///
/// Bitmask of bits to toggle.
public void ToggleSpawnflags(uint bits) {
- this["spawnflags"] = (spawnflags ^ bits).ToString();
+ this["spawnflags"] = (Spawnflags ^ bits).ToString();
}
///
@@ -493,7 +509,7 @@ namespace LibBSP {
///
/// Bitmask of bits to clear.
public void ClearSpawnflags(uint bits) {
- ToggleSpawnflags(spawnflags & bits);
+ ToggleSpawnflags(Spawnflags & bits);
}
///
@@ -501,7 +517,7 @@ namespace LibBSP {
///
/// Bitmask of bits to set.
public void SetSpawnflags(uint bits) {
- this["spawnflags"] = (spawnflags | bits).ToString();
+ this["spawnflags"] = (Spawnflags | bits).ToString();
}
///
@@ -577,8 +593,8 @@ namespace LibBSP {
throw new ArgumentException("Object is not an Entity");
}
- int firstTry = className.CompareTo(other.className);
- return firstTry != 0 ? firstTry : name.CompareTo(other.name);
+ int comparison = ClassName.CompareTo(other.ClassName);
+ return comparison != 0 ? comparison : Name.CompareTo(other.Name);
}
///
@@ -591,8 +607,8 @@ namespace LibBSP {
if (other == null) {
return 1;
}
- int firstTry = className.CompareTo(other.className);
- return firstTry != 0 ? firstTry : name.CompareTo(other.name);
+ int comparison = ClassName.CompareTo(other.ClassName);
+ return comparison != 0 ? comparison : Name.CompareTo(other.Name);
}
#endregion
diff --git a/LibBSP/Source/Structs/Common/Lumps/Entities.cs b/LibBSP/Source/Structs/Common/Lumps/Entities.cs
index 163510f..ceff8f8 100644
--- a/LibBSP/Source/Structs/Common/Lumps/Entities.cs
+++ b/LibBSP/Source/Structs/Common/Lumps/Entities.cs
@@ -146,7 +146,7 @@ namespace LibBSP {
/// Targetname attribute to find.
/// List<> with the specified targetname.
public List GetAllWithName(string targetname) {
- return FindAll(entity => { return entity.name.Equals(targetname, StringComparison.InvariantCultureIgnoreCase); });
+ return FindAll(entity => { return entity.Name.Equals(targetname, StringComparison.InvariantCultureIgnoreCase); });
}
///
@@ -165,7 +165,7 @@ namespace LibBSP {
/// Targetname attribute to find.
/// object with the specified targetname.
public Entity GetWithName(string targetname) {
- return Find(entity => { return entity.name.Equals(targetname, StringComparison.InvariantCultureIgnoreCase); });
+ return Find(entity => { return entity.Name.Equals(targetname, StringComparison.InvariantCultureIgnoreCase); });
}
}
}
diff --git a/LibBSP/Source/Structs/Common/Lumps/NumList.cs b/LibBSP/Source/Structs/Common/Lumps/NumList.cs
index 90b54ef..8479d9d 100644
--- a/LibBSP/Source/Structs/Common/Lumps/NumList.cs
+++ b/LibBSP/Source/Structs/Common/Lumps/NumList.cs
@@ -327,6 +327,23 @@ namespace LibBSP {
return -1;
}
+ ///
+ /// Gets the index for the leaf patch indices lump in the BSP file for a specific map format, and the type of data the format uses.
+ ///
+ /// The map type.
+ /// out parameter that will contain the data type this version uses.
+ /// Index for this lump, or -1 if the format doesn't have this lump or it's not implemented.
+ public static int GetIndexForLeafPatchesLump(MapType version, out DataType dataType) {
+ switch (version) {
+ case MapType.CoD:{
+ dataType = DataType.UInt32;
+ return 26;
+ }
+ }
+ dataType = DataType.Invalid;
+ return -1;
+ }
+
///
/// Gets the index for the texture table lump in the BSP file for a specific map format, and the type of data the format uses.
///
diff --git a/LibBSP/Source/Structs/Common/TextureInfo.cs b/LibBSP/Source/Structs/Common/TextureInfo.cs
index 333be59..c2aad60 100644
--- a/LibBSP/Source/Structs/Common/TextureInfo.cs
+++ b/LibBSP/Source/Structs/Common/TextureInfo.cs
@@ -21,7 +21,7 @@ namespace LibBSP {
#endif
///
- /// This class contains the texture scaling information for certain formats.
+ /// This struct contains the texture scaling information for certain formats.
/// Some BSP formats lack this lump (or the information is contained in a
/// different lump) so their cases will be left out.
///
@@ -65,7 +65,10 @@ namespace LibBSP {
public Vector2 scale;
public float rotation;
- public Vector3 uAxis {
+ ///
+ /// Gets or sets the U axis, used to calculate the U coordinates for each .
+ ///
+ public Vector3 UAxis {
get {
return new Vector3(BitConverter.ToSingle(Data, 0), BitConverter.ToSingle(Data, 4), BitConverter.ToSingle(Data, 8));
}
@@ -74,7 +77,10 @@ namespace LibBSP {
}
}
- public Vector3 vAxis {
+ ///
+ /// Gets or sets the V axis, used to calculate the V coordinates for each .
+ ///
+ public Vector3 VAxis {
get {
return new Vector3(BitConverter.ToSingle(Data, 16), BitConverter.ToSingle(Data, 20), BitConverter.ToSingle(Data, 24));
}
@@ -83,7 +89,10 @@ namespace LibBSP {
}
}
- public Vector2 translation {
+ ///
+ /// Gets or sets the translation of the texture along the U and V axes.
+ ///
+ public Vector2 Translation {
get {
return new Vector2(BitConverter.ToSingle(Data, 12), BitConverter.ToSingle(Data, 28));
}
@@ -93,7 +102,10 @@ namespace LibBSP {
}
}
- public int flags {
+ ///
+ /// Gets or sets the flags for this .
+ ///
+ public int Flags {
get {
switch (MapType) {
case MapType.Source17:
@@ -151,7 +163,16 @@ namespace LibBSP {
}
}
- public int texture {
+ ///
+ /// Gets or sets the index of the (or in Source engine)
+ /// used by this .
+ ///
+ ///
+ /// Using one field for data access in different lumps because of the similarity between Source and
+ /// Quake II engines. Both engines reference texture data in this structure, Source just goes through
+ /// a few more steps.
+ ///
+ public int TextureIndex {
get {
switch (MapType) {
case MapType.Source17:
@@ -242,11 +263,11 @@ namespace LibBSP {
this.scale = scale;
this.rotation = rotation;
- this.uAxis = uAxis;
- this.vAxis = vAxis;
- this.translation = translation;
- this.flags = flags;
- this.texture = texture;
+ UAxis = uAxis;
+ VAxis = vAxis;
+ Translation = translation;
+ Flags = flags;
+ TextureIndex = texture;
}
///
diff --git a/LibBSP/Source/Structs/MAP/MAPBrushSide.cs b/LibBSP/Source/Structs/MAP/MAPBrushSide.cs
index d8a6bb0..b2df47c 100644
--- a/LibBSP/Source/Structs/MAP/MAPBrushSide.cs
+++ b/LibBSP/Source/Structs/MAP/MAPBrushSide.cs
@@ -130,16 +130,16 @@ namespace LibBSP {
string[] split = tokens[1].SplitUnlessBetweenDelimiters(' ', '[', ']', StringSplitOptions.RemoveEmptyEntries);
textureInfo.scale = new Vector2(float.Parse(split[1], _format), textureInfo.scale.Y());
split = split[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- textureInfo.uAxis = new Vector3(float.Parse(split[0], _format), float.Parse(split[1], _format), float.Parse(split[2], _format));
- textureInfo.translation = new Vector2(float.Parse(split[3], _format), textureInfo.translation.Y());
+ textureInfo.UAxis = new Vector3(float.Parse(split[0], _format), float.Parse(split[1], _format), float.Parse(split[2], _format));
+ textureInfo.Translation = new Vector2(float.Parse(split[3], _format), textureInfo.Translation.Y());
break;
}
case "vaxis": {
string[] split = tokens[1].SplitUnlessBetweenDelimiters(' ', '[', ']', StringSplitOptions.RemoveEmptyEntries);
textureInfo.scale = new Vector2(textureInfo.scale.X(), float.Parse(split[1], _format));
split = split[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- textureInfo.vAxis = new Vector3(float.Parse(split[0], _format), float.Parse(split[1], _format), float.Parse(split[2], _format));
- textureInfo.translation = new Vector2(textureInfo.translation.X(), float.Parse(split[3], _format));
+ textureInfo.VAxis = new Vector3(float.Parse(split[0], _format), float.Parse(split[1], _format), float.Parse(split[2], _format));
+ textureInfo.Translation = new Vector2(textureInfo.Translation.X(), float.Parse(split[3], _format));
break;
}
case "rotation": {