-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathWEPFile.cs
137 lines (113 loc) · 4.68 KB
/
WEPFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using PangLib.WEP.Helpers;
using PangLib.WEP.Models;
namespace PangLib.WEP;
public class WEPFile
{
/// <summary>
/// Version of the WEP file
/// </summary>
public int Version = 0;
/// <summary>
/// List of <see cref="PangLib.WEP.Models.CameraNode"/> parsed from this WEP file
/// </summary>
public List<CameraNode> CameraNodes { get; set; }
/// <summary>
/// List of <see cref="PangLib.WEP.Models.PointNode"/> parsed from this WEP file
/// </summary>
public List<PointNode> PointNodes { get; set; }
/// <summary>
/// List of <see cref="PangLib.WEP.Models.AreaNode"/> parsed from this WEP file
/// </summary>
public List<AreaNode> AreaNodes { get; set; }
/// <summary>
/// List of textures parsed from this WEP file
/// </summary>
public List<string> Textures { get; set; }
/// <summary>
/// List of <see cref="PangLib.WEP.Models.NodeList"/> parsed from this WEP file
/// </summary>
public List<NodeList> NodeLists { get; set; }
/// <summary>
/// Base <see cref="PangLib.WEP.Models.Element"/> of this WEP file
/// </summary>
public Element BaseElement { get; set; }
/// <summary>
/// List of <see cref="PangLib.WEP.Models.Color"/> parsed from this WEP file
/// </summary>
public List<Color> BaseColors { get; set; }
/// <summary>
/// List of <see cref="PangLib.WEP.Models.VertexColorMap"/> parsed from this WEP file
/// </summary>
public List<VertexColorMap> VertexColorMaps { get; set; }
/// <summary>
/// List of <see cref="PangLib.WEP.Models.Element"/> parsed from this WEP file
/// </summary>
public List<Element> Elements { get; set; }
/// <summary>
/// <see cref="PangLib.WEP.Models.MapCheck"/> of this WEP file
/// </summary>
public MapCheck MapCheck { get; set; }
/// <summary>
/// Initializes a new instance of <see cref="WEPFile"/> from the provided stream
/// </summary>
/// <param name="data">Stream containing the WEP file data</param>
public WEPFile(Stream data)
{
Parse(data);
}
/// <summary>
/// Parses the passed Stream into WEP file structures
/// </summary>
/// <param name="data">Stream containing the WEP file data</param>
private void Parse(Stream data)
{
using (BinaryReader reader = new BinaryReader(data))
{
string magic = Encoding.UTF8.GetString(reader.ReadBytes(4));
if (magic != "WEPX")
{
throw new Exception("File is not a valid WEP file");
}
Version = reader.ReadInt32();
int globalElementCount = reader.ReadInt32();
int elementType0Count = reader.ReadInt32();
int elementType1Count = reader.ReadInt32();
int cameraNodeCount = reader.ReadInt32();
int pointNodeCount = reader.ReadInt32();
int areaNodeCount = reader.ReadInt32();
int textureCount = reader.ReadInt32();
int nodeListCount = reader.ReadInt32();
int elementType2Count = 0;
if (Version == 114)
{
elementType2Count = reader.ReadInt32();
}
CameraNodes = CameraNodeReader.ReadAllCameraNodes(reader, Version, cameraNodeCount);
PointNodes = PointNodeReader.ReadAllPointNodes(reader, Version, pointNodeCount);
AreaNodes = AreaNodeReader.ReadAllAreaNodes(reader, Version, areaNodeCount);
Textures = TextureReader.ReadAllTextures(reader, textureCount);
NodeLists = NodeListReader.ReadAllNodeLists(reader, Version, nodeListCount);
int fullElementCount = globalElementCount + elementType0Count + elementType1Count;
if (fullElementCount > 0)
{
BaseElement = ElementReader.ReadElement(reader, Version);
if (Version == 113)
{
BaseColors = ColorReader.ReadAllColors(reader, BaseElement.VertexCount);
}
else
{
VertexColorMaps = ColorReader.ReadAllVertexColorMaps(reader);
}
Elements = ElementReader.ReadAllElements(reader, Version, fullElementCount);
Elements = Elements.Concat(ElementReader.ReadAllNewElements(reader, elementType2Count)).ToList();
MapCheck = MapCheckReader.ReadMapCheck(reader, Version);
}
}
}
}