forked from ACEmulator/ACE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetupModel.cs
115 lines (96 loc) · 4.54 KB
/
SetupModel.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
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using ACE.DatLoader.Entity;
using ACE.Entity.Enum;
namespace ACE.DatLoader.FileTypes
{
/// <summary>
/// These are client_portal.dat files starting with 0x02.
/// They are basically 3D model descriptions.
/// </summary>
/// <remarks>
/// A big huge thank you to "Pea" for his trailblazing work on decoding this structure. Without his work on this, we might still be decoding models on cave walls.
/// </remarks>
[DatFileType(DatFileType.Setup)]
public class SetupModel : FileType
{
public SetupFlags Flags { get; private set; }
public bool AllowFreeHeading { get; private set; }
public bool HasPhysicsBSP { get; private set; }
public List<uint> Parts { get; } = new List<uint>();
public List<uint> ParentIndex { get; } = new List<uint>();
public List<Vector3> DefaultScale { get; } = new List<Vector3>();
public Dictionary<int, LocationType> HoldingLocations { get; } = new Dictionary<int, LocationType>();
public Dictionary<int, LocationType> ConnectionPoints { get; } = new Dictionary<int, LocationType>();
public Dictionary<int, PlacementType> PlacementFrames { get; } = new Dictionary<int, PlacementType>();
public List<CylSphere> CylSpheres { get; } = new List<CylSphere>();
public List<Sphere> Spheres { get; } = new List<Sphere>();
public float Height { get; private set; }
public float Radius { get; private set; }
public float StepUpHeight { get; private set; }
public float StepDownHeight { get; private set; }
public Sphere SortingSphere { get; private set; } = new Sphere();
public Sphere SelectionSphere { get; private set; } = new Sphere();
public Dictionary<int, LightInfo> Lights { get; } = new Dictionary<int, LightInfo>();
public uint DefaultAnimation { get; private set; }
public uint DefaultScript { get; private set; }
public uint DefaultMotionTable { get; private set; }
public uint DefaultSoundTable { get; private set; }
public uint DefaultScriptTable { get; private set; }
public override void Unpack(BinaryReader reader)
{
Id = reader.ReadUInt32();
Flags = (SetupFlags)reader.ReadUInt32();
AllowFreeHeading = (Flags & SetupFlags.AllowFreeHeading) != 0;
HasPhysicsBSP = (Flags & SetupFlags.HasPhysicsBSP) != 0;
// Get all the GraphicsObjects in this SetupModel. These are all the 01-types.
uint numParts = reader.ReadUInt32();
for (int i = 0; i < numParts; i++)
Parts.Add(reader.ReadUInt32());
if ((Flags & SetupFlags.HasParent) != 0)
{
for (int i = 0; i < numParts; i++)
ParentIndex.Add(reader.ReadUInt32());
}
if ((Flags & SetupFlags.HasDefaultScale) != 0)
{
for (int i = 0; i < numParts; i++)
DefaultScale.Add(reader.ReadVector3());
}
HoldingLocations.Unpack(reader);
ConnectionPoints.Unpack(reader);
int placementsCount = reader.ReadInt32();
for (int i = 0; i < placementsCount; i++)
{
int key = reader.ReadInt32();
// there is a frame for each Part
var placementType = new PlacementType();
placementType.Unpack(reader, (uint)Parts.Count);
PlacementFrames.Add(key, placementType);
}
CylSpheres.Unpack(reader);
Spheres.Unpack(reader);
Height = reader.ReadSingle();
Radius = reader.ReadSingle();
StepUpHeight = reader.ReadSingle();
StepDownHeight = reader.ReadSingle();
SortingSphere.Unpack(reader);
SelectionSphere.Unpack(reader);
Lights.Unpack(reader);
DefaultAnimation = reader.ReadUInt32();
DefaultScript = reader.ReadUInt32();
DefaultMotionTable = reader.ReadUInt32();
DefaultSoundTable = reader.ReadUInt32();
DefaultScriptTable = reader.ReadUInt32();
}
public static SetupModel CreateSimpleSetup()
{
var setup = new SetupModel();
setup.SortingSphere = Sphere.CreateDummySphere();
setup.SelectionSphere = Sphere.CreateDummySphere();
setup.AllowFreeHeading = true;
return setup;
}
}
}