source: OniSplit/Level/Later/LevelDatReader.cs@ 1131

Last change on this file since 1131 was 1114, checked in by iritscen, 5 years ago

Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File size: 6.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Oni.Level
6{
7 internal class LevelDatReader
8 {
9 private InstanceDescriptor onlv;
10 private BinaryReader dat;
11 private Level level;
12
13 public static Level Read(InstanceDescriptor onlv, BinaryReader dat)
14 {
15 LevelDatReader reader = new LevelDatReader();
16 reader.onlv = onlv;
17 reader.dat = dat;
18 reader.level = new Level();
19 reader.Read();
20 return reader.level;
21 }
22
23 private void Read()
24 {
25 InstanceDescriptor akev;
26 InstanceDescriptor oboa;
27 InstanceDescriptor onsk;
28 InstanceDescriptor aisa;
29 InstanceDescriptor onoa;
30 InstanceDescriptor envp;
31 InstanceDescriptor crsa;
32
33 level.Name = dat.ReadString(64);
34 akev = dat.ReadInstance();
35 oboa = dat.ReadInstance();
36 dat.Skip(12);
37 onsk = dat.ReadInstance();
38 dat.Skip(4);
39 aisa = dat.ReadInstance();
40 dat.Skip(12);
41 onoa = dat.ReadInstance();
42 envp = dat.ReadInstance();
43 dat.Skip(644);
44 crsa = dat.ReadInstance();
45 }
46
47 private void ReadOBOA(InstanceDescriptor oboa)
48 {
49 List<PhyObject> objects = new List<PhyObject>();
50
51 using (BinaryReader reader = oboa.OpenRead())
52 {
53 reader.Skip(22);
54 int count = reader.ReadUInt16();
55
56 for (int i = 0; i < count; i++)
57 {
58 InstanceDescriptor m3ga = reader.ReadInstance();
59 InstanceDescriptor oban = reader.ReadInstance();
60 InstanceDescriptor envp = reader.ReadInstance();
61 PhyObjectFlags flags = (PhyObjectFlags)reader.ReadInt32();
62 reader.Skip(4);
63 int doorId = reader.ReadInt32();
64 PhyType phyType = (PhyType)reader.ReadInt32();
65 int scriptId = reader.ReadInt32();
66 Vector3 position = reader.ReadVector3();
67 Quaternion rotation = reader.ReadQuaternion();
68 float scale = reader.ReadSingle();
69 Matrix matrix = reader.ReadMatrix4x3();
70 string name = reader.ReadString(64);
71 string fileName = reader.ReadString(64);
72
73 if ((flags & PhyObjectFlags.Used) == 0)
74 continue;
75 }
76 }
77 }
78
79 private void ReadENVP(InstanceDescriptor envp)
80 {
81 List<EnvParticle> objects = new List<EnvParticle>();
82
83 using (BinaryReader reader = envp.OpenRead())
84 {
85 reader.Skip(22);
86 int count = reader.ReadUInt16();
87
88 for (int i = 0; i < count; i++)
89 {
90 string className = reader.ReadString(64);
91 string name = reader.ReadString(48);
92 Matrix matrix = reader.ReadMatrix4x3();
93 Vector2 decalScale = reader.ReadVector2();
94 reader.Skip(40);
95 }
96 }
97 }
98
99 private class DatObjectQuads
100 {
101 public uint ObjectId;
102 public int[] QuadIndices;
103 }
104
105 private void ReadONOA(InstanceDescriptor onoa)
106 {
107 List<DatObjectQuads> objects = new List<DatObjectQuads>();
108 List<InstanceDescriptor> indices = new List<InstanceDescriptor>();
109
110 using (BinaryReader reader = onoa.OpenRead())
111 {
112 reader.Skip(20);
113 int count = reader.ReadInt32();
114
115 for (int i = 0; i < count; i++)
116 {
117 uint id = reader.ReadUInt32();
118 InstanceDescriptor idxa = reader.ReadInstance();
119
120 DatObjectQuads obj = new DatObjectQuads();
121 obj.ObjectId = id;
122 objects.Add(obj);
123 indices.Add(idxa);
124 }
125 }
126
127 for (int i = 0; i < objects.Count; i++)
128 {
129 using (BinaryReader reader = indices[i].OpenRead())
130 {
131 reader.Skip(20);
132 objects[i].QuadIndices = reader.ReadInt32VarArray();
133 }
134 }
135 }
136
137 private void ReadAISA(InstanceDescriptor aisa)
138 {
139 List<ScriptCharacter> chars = new List<ScriptCharacter>();
140
141 using (BinaryReader reader = aisa.OpenRead())
142 {
143 reader.Skip(22);
144 int count = reader.ReadUInt16();
145
146 for (int i = 0; i < count; i++)
147 {
148 string name = reader.ReadString(32);
149 int id = reader.ReadUInt16();
150 int flagId = reader.ReadUInt16();
151 reader.Skip(2);
152 int teamId = reader.ReadUInt16();
153 InstanceDescriptor oncc = reader.ReadInstance();
154 reader.Skip(32);
155 reader.Skip(4);
156 string createScript = reader.ReadString(32);
157 string dieScript = reader.ReadString(32);
158 string enemyScript = reader.ReadString(32);
159 string alarmScript = reader.ReadString(32);
160 string hurtScript = reader.ReadString(32);
161 string lowHealthScript = reader.ReadString(32);
162 string lowAmmoScript = reader.ReadString(32);
163 string noPathScript = reader.ReadString(32);
164 InstanceDescriptor onwc = reader.ReadInstance();
165 int ammo = reader.ReadUInt16();
166 reader.Skip(10);
167 }
168 }
169 }
170 }
171}
Note: See TracBrowser for help on using the repository browser.