Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions LibBSP/Source/Structs/BSP/BSP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public enum MapType : int
/// Half-Life Blue Shift
/// </summary>
BlueShift = 0x01010001,
/// <summary>
/// Quake BSP2
/// </summary>
BSP2 = 0x01000001,

/// <summary>
/// Quake 2 or Quake 2 Engine flags, including <see cref="Daikatana"/> <see cref="SoF"/>
Expand Down
11 changes: 9 additions & 2 deletions LibBSP/Source/Structs/BSP/BSPHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ namespace LibBSP
/// </summary>
public struct BSPHeader
{

/// <summary>
/// "BSP2" represented as int32.
/// </summary>
public const int BSP2Header = 844124994;
/// <summary>
/// "IBSP" represented as int32.
/// </summary>
Expand Down Expand Up @@ -421,7 +424,11 @@ public static byte[] GetMagic(MapType type)
case MapType.Quake:
{
return BitConverter.GetBytes(29);
}
}
case MapType.BSP2:
{
return BitConverter.GetBytes(BSP2Header);
}
case MapType.GoldSrc:
case MapType.BlueShift:
{
Expand Down
31 changes: 25 additions & 6 deletions LibBSP/Source/Structs/BSP/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public int FirstVertexIndex
{
get
{
if (MapType == MapType.Vindictus)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
return (int)BitConverter.ToUInt32(Data, 0);
}
else if (MapType == MapType.Vindictus)
{
return BitConverter.ToInt32(Data, 0);
}
Expand All @@ -99,8 +103,11 @@ public int FirstVertexIndex
set
{
byte[] bytes = BitConverter.GetBytes(value);

if (MapType == MapType.Vindictus)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
BitConverter.GetBytes((uint)value).CopyTo(Data, 0);
}
else if (MapType == MapType.Vindictus)
{
bytes.CopyTo(Data, 0);
}
Expand Down Expand Up @@ -132,7 +139,11 @@ public int SecondVertexIndex
{
get
{
if (MapType == MapType.Vindictus)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
return (int)BitConverter.ToUInt32(Data, 4);
}
else if (MapType == MapType.Vindictus)
{
return BitConverter.ToInt32(Data, 4);
}
Expand All @@ -149,7 +160,11 @@ public int SecondVertexIndex
{
byte[] bytes = BitConverter.GetBytes(value);

if (MapType == MapType.Vindictus)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
BitConverter.GetBytes((uint)value).CopyTo(Data, 4);
}
else if (MapType == MapType.Vindictus)
{
BitConverter.GetBytes(value).CopyTo(Data, 4);
}
Expand Down Expand Up @@ -252,7 +267,11 @@ public static Lump<Edge> LumpFactory(byte[] data, BSP bsp, LumpInfo lumpInfo)
/// <exception cref="ArgumentException">This struct is not valid or is not implemented for the given <paramref name="mapType"/> and <paramref name="lumpVersion"/>.</exception>
public static int GetStructLength(MapType mapType, int lumpVersion = 0)
{
if (mapType == MapType.Vindictus)
if (mapType.IsSubtypeOf(MapType.BSP2))
{
return 8;
}
else if (mapType == MapType.Vindictus)
{
return 8;
}
Expand Down
100 changes: 81 additions & 19 deletions LibBSP/Source/Structs/BSP/Face.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ public int PlaneIndex
{
get
{
if (MapType == MapType.Nightfire
if (MapType.IsSubtypeOf(MapType.BSP2))
{
return BitConverter.ToInt32(Data, 0);
}
else if (MapType == MapType.Nightfire
|| MapType == MapType.Vindictus)
{
return BitConverter.ToInt32(Data, 0);
Expand All @@ -128,14 +132,17 @@ public int PlaneIndex
{
return BitConverter.ToUInt16(Data, 0);
}

return -1;
}
set
{
byte[] bytes = BitConverter.GetBytes(value);

if (MapType == MapType.Nightfire
if (MapType.IsSubtypeOf(MapType.BSP2))
{
bytes.CopyTo(Data, 0);
}
else if (MapType == MapType.Nightfire
|| MapType == MapType.Vindictus)
{
bytes.CopyTo(Data, 0);
Expand Down Expand Up @@ -167,8 +174,12 @@ public bool PlaneSide
{
get
{
if (MapType.IsSubtypeOf(MapType.Quake)
|| MapType.IsSubtypeOf(MapType.Quake2))
if (MapType.IsSubtypeOf(MapType.BSP2))
{
return BitConverter.ToUInt32(Data, 4) > 0;
}
else if (MapType.IsSubtypeOf(MapType.Quake)
|| MapType.IsSubtypeOf(MapType.Quake2))
{
return BitConverter.ToUInt16(Data, 2) > 0;
}
Expand All @@ -193,7 +204,11 @@ public bool PlaneSide
}
set
{
if (MapType == MapType.Vindictus)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
BitConverter.GetBytes(value ? 1 : 0).CopyTo(Data, 4);
}
else if (MapType == MapType.Vindictus)
{
Data[4] = (byte)(value ? 1 : 0);
}
Expand Down Expand Up @@ -287,7 +302,11 @@ public int FirstEdgeIndexIndex
{
get
{
if (MapType == MapType.Source17)
if (MapType == MapType.BSP2)
{
return BitConverter.ToInt32(Data, 8);
}
else if(MapType == MapType.Source17)
{
return BitConverter.ToInt32(Data, 36);
}
Expand All @@ -312,7 +331,11 @@ public int FirstEdgeIndexIndex
{
byte[] bytes = BitConverter.GetBytes(value);

if (MapType == MapType.Source17)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
bytes.CopyTo(Data, 8);
}
else if (MapType == MapType.Source17)
{
bytes.CopyTo(Data, 36);
}
Expand Down Expand Up @@ -342,7 +365,11 @@ public int NumEdgeIndices
{
get
{
if (MapType == MapType.Source17)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
return BitConverter.ToInt32(Data, 12);
}
else if (MapType == MapType.Source17)
{
return BitConverter.ToUInt16(Data, 40);
}
Expand All @@ -367,7 +394,11 @@ public int NumEdgeIndices
{
byte[] bytes = BitConverter.GetBytes(value);

if (MapType == MapType.Source17)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
bytes.CopyTo(Data, 12);
}
else if (MapType == MapType.Source17)
{
Data[40] = bytes[0];
Data[41] = bytes[1];
Expand Down Expand Up @@ -602,7 +633,7 @@ public TextureInfo TextureInfo
{
get
{
return Parent.Bsp.TextureInfo[TextureInfoIndex];
return Parent.Bsp.TextureInfo[TextureInfoIndex];
}
}

Expand All @@ -613,7 +644,11 @@ public int TextureInfoIndex
{
get
{
if (MapType == MapType.Nightfire)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
return BitConverter.ToInt32(Data, 16);
}
else if (MapType == MapType.Nightfire)
{
return BitConverter.ToInt32(Data, 32);
}
Expand All @@ -634,14 +669,17 @@ public int TextureInfoIndex
{
return BitConverter.ToUInt16(Data, 10);
}

return -1;
}
set
{
byte[] bytes = BitConverter.GetBytes(value);

if (MapType == MapType.Nightfire)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
bytes.CopyTo(Data, 16);
}
else if (MapType == MapType.Nightfire)
{
bytes.CopyTo(Data, 32);
}
Expand Down Expand Up @@ -1087,7 +1125,13 @@ public byte[] LightmapStyles
{
get
{
if (MapType == MapType.SiN)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
byte[] bytes = new byte[4];
Array.Copy(Data, 20, bytes, 0, 4);
return bytes;
}
else if(MapType == MapType.SiN)
{
byte[] bytes = new byte[16];
Array.Copy(Data, 12, bytes, 0, bytes.Length);
Expand Down Expand Up @@ -1148,7 +1192,12 @@ public byte[] LightmapStyles
}
set
{
if (MapType == MapType.SiN)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
Array.Copy(value, 0, Data, 20, Math.Min(value.Length, 4));
}

else if (MapType == MapType.SiN)
{
Array.Copy(value, 0, Data, 12, Math.Min(value.Length, 16));
}
Expand Down Expand Up @@ -1248,7 +1297,11 @@ public int Lightmap
{
get
{
if (MapType == MapType.Raven)
if (MapType == MapType.BSP2)
{
return BitConverter.ToInt32(Data, 24);
}
else if(MapType == MapType.Raven)
{
return BitConverter.ToInt32(Data, 36);
}
Expand Down Expand Up @@ -1301,7 +1354,12 @@ public int Lightmap
{
byte[] bytes = BitConverter.GetBytes(value);

if (MapType == MapType.Raven)
if (MapType.IsSubtypeOf(MapType.BSP2))
{
bytes.CopyTo(Data, 24);
}

else if (MapType == MapType.Raven)
{
bytes.CopyTo(Data, 36);
}
Expand Down Expand Up @@ -2188,7 +2246,11 @@ public static Lump<Face> LumpFactory(byte[] data, BSP bsp, LumpInfo lumpInfo)
/// <exception cref="ArgumentException">This struct is not valid or is not implemented for the given <paramref name="mapType"/> and <paramref name="lumpVersion"/>.</exception>
public static int GetStructLength(MapType mapType, int lumpVersion = 0)
{
if (mapType == MapType.CoD4)
if (mapType.IsSubtypeOf(MapType.BSP2))
{
return 28;
}
else if(mapType == MapType.CoD4)
{
return 24;
}
Expand Down
Loading