2017-12-22 04:26:04 +08:00
|
|
|
|
using CodeWalker.GameFiles;
|
|
|
|
|
using SharpDX;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace CodeWalker.World
|
|
|
|
|
{
|
|
|
|
|
public class AudioZones // : BasePathData
|
|
|
|
|
{
|
|
|
|
|
public volatile bool Inited = false;
|
|
|
|
|
public GameFileCache GameFileCache;
|
|
|
|
|
|
|
|
|
|
//public Vector4[] GetNodePositions()
|
|
|
|
|
//{
|
|
|
|
|
// return null;
|
|
|
|
|
//}
|
|
|
|
|
//public EditorVertex[] GetPathVertices()
|
|
|
|
|
//{
|
|
|
|
|
// return null;
|
|
|
|
|
//}
|
|
|
|
|
//public EditorVertex[] GetTriangleVertices()
|
|
|
|
|
//{
|
|
|
|
|
// return TriangleVerts;
|
|
|
|
|
//}
|
|
|
|
|
//public EditorVertex[] TriangleVerts;
|
|
|
|
|
|
|
|
|
|
public List<AudioPlacement> Zones = new List<AudioPlacement>();
|
|
|
|
|
public List<AudioPlacement> Emitters = new List<AudioPlacement>();
|
|
|
|
|
public List<AudioPlacement> AllItems = new List<AudioPlacement>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Init(GameFileCache gameFileCache, Action<string> updateStatus)
|
|
|
|
|
{
|
|
|
|
|
Inited = false;
|
|
|
|
|
|
|
|
|
|
GameFileCache = gameFileCache;
|
|
|
|
|
|
|
|
|
|
var rpfman = gameFileCache.RpfMan;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Zones.Clear();
|
|
|
|
|
Emitters.Clear();
|
|
|
|
|
AllItems.Clear();
|
|
|
|
|
|
|
|
|
|
|
2017-12-23 04:56:39 +08:00
|
|
|
|
Dictionary<uint, RpfFileEntry> datrelentries = new Dictionary<uint, RpfFileEntry>();
|
2017-12-22 04:26:04 +08:00
|
|
|
|
var audrpf = rpfman.FindRpfFile("x64\\audio\\audio_rel.rpf");
|
|
|
|
|
if (audrpf != null)
|
|
|
|
|
{
|
2017-12-23 04:56:39 +08:00
|
|
|
|
AddRpfDatRels(audrpf, datrelentries);
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gameFileCache.EnableDlc)
|
|
|
|
|
{
|
|
|
|
|
var updrpf = rpfman.FindRpfFile("update\\update.rpf");
|
|
|
|
|
if (updrpf != null)
|
|
|
|
|
{
|
2017-12-23 04:56:39 +08:00
|
|
|
|
AddRpfDatRels(updrpf, datrelentries);
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
foreach (var dlcrpf in GameFileCache.DlcActiveRpfs) //load from current dlc rpfs
|
|
|
|
|
{
|
2017-12-23 04:56:39 +08:00
|
|
|
|
AddRpfDatRels(dlcrpf, datrelentries);
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-12-23 04:56:39 +08:00
|
|
|
|
foreach (var dat151entry in datrelentries.Values)
|
2017-12-22 04:26:04 +08:00
|
|
|
|
{
|
|
|
|
|
var relfile = rpfman.GetFile<RelFile>(dat151entry);
|
|
|
|
|
if (relfile != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var reldata in relfile.RelDatas)
|
|
|
|
|
{
|
2017-12-23 04:56:39 +08:00
|
|
|
|
if (reldata is Dat151AmbientZone)
|
2017-12-22 04:26:04 +08:00
|
|
|
|
{
|
2017-12-23 04:56:39 +08:00
|
|
|
|
Zones.Add(new AudioPlacement(relfile, reldata as Dat151AmbientZone));
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
2017-12-23 04:56:39 +08:00
|
|
|
|
else if (reldata is Dat151AmbientEmitter)
|
2017-12-22 04:26:04 +08:00
|
|
|
|
{
|
2017-12-23 04:56:39 +08:00
|
|
|
|
Emitters.Add(new AudioPlacement(relfile, reldata as Dat151AmbientEmitter));
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AllItems.AddRange(Zones);
|
|
|
|
|
AllItems.AddRange(Emitters);
|
|
|
|
|
|
|
|
|
|
Inited = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-23 04:56:39 +08:00
|
|
|
|
private void AddRpfDatRels(RpfFile rpffile, Dictionary<uint, RpfFileEntry> datrelentries)
|
2017-12-22 04:26:04 +08:00
|
|
|
|
{
|
|
|
|
|
if (rpffile.AllEntries == null) return;
|
|
|
|
|
foreach (var entry in rpffile.AllEntries)
|
|
|
|
|
{
|
|
|
|
|
if (entry is RpfFileEntry)
|
|
|
|
|
{
|
|
|
|
|
RpfFileEntry fentry = entry as RpfFileEntry;
|
2017-12-23 04:56:39 +08:00
|
|
|
|
//if (entry.NameLower.EndsWith(".rel"))
|
|
|
|
|
//{
|
|
|
|
|
// datrelentries[entry.NameHash] = fentry;
|
|
|
|
|
//}
|
|
|
|
|
if (entry.NameLower.EndsWith(".dat54.rel"))
|
|
|
|
|
{
|
|
|
|
|
datrelentries[entry.NameHash] = fentry;
|
|
|
|
|
}
|
2017-12-22 04:26:04 +08:00
|
|
|
|
if (entry.NameLower.EndsWith(".dat151.rel"))
|
|
|
|
|
{
|
2017-12-23 04:56:39 +08:00
|
|
|
|
datrelentries[entry.NameHash] = fentry;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class AudioPlacement
|
|
|
|
|
{
|
2017-12-22 08:25:19 +08:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public MetaHash NameHash { get; set; }
|
2017-12-22 04:26:04 +08:00
|
|
|
|
public RelFile RelFile { get; set; }
|
2017-12-23 04:56:39 +08:00
|
|
|
|
public Dat151AmbientZone AudioZone { get; set; }
|
|
|
|
|
public Dat151AmbientEmitter AudioEmitter { get; set; }
|
2017-12-22 04:26:04 +08:00
|
|
|
|
public Dat151ZoneShape Shape { get; set; }
|
|
|
|
|
public string ShortTypeName { get; set; }
|
|
|
|
|
public string FullTypeName { get; set; }
|
|
|
|
|
public Vector3 InnerPos { get; set; }
|
|
|
|
|
public Vector3 InnerMin { get; set; }
|
|
|
|
|
public Vector3 InnerMax { get; set; }
|
|
|
|
|
public float InnerRad { get; set; }
|
|
|
|
|
public Quaternion InnerOri { get; set; }
|
|
|
|
|
public Vector3 OuterPos { get; set; }
|
|
|
|
|
public Vector3 OuterMin { get; set; }
|
|
|
|
|
public Vector3 OuterMax { get; set; }
|
|
|
|
|
public float OuterRad { get; set; }
|
|
|
|
|
public Quaternion OuterOri { get; set; }
|
2017-12-24 19:49:04 +08:00
|
|
|
|
public Vector3 Position { get; set; }
|
2017-12-22 04:26:04 +08:00
|
|
|
|
public Vector3 HitboxMin { get; set; }
|
|
|
|
|
public Vector3 HitboxMax { get; set; }
|
2017-12-24 19:49:04 +08:00
|
|
|
|
public Quaternion Orientation { get; set; }
|
|
|
|
|
public Quaternion OrientationInv { get; set; }
|
2017-12-22 04:26:04 +08:00
|
|
|
|
public float HitSphereRad { get; set; }
|
|
|
|
|
|
|
|
|
|
|
2017-12-23 04:56:39 +08:00
|
|
|
|
public AudioPlacement(RelFile rel, Dat151AmbientZone zone)
|
2017-12-22 04:26:04 +08:00
|
|
|
|
{
|
|
|
|
|
RelFile = rel;
|
|
|
|
|
AudioZone = zone;
|
|
|
|
|
Shape = zone.Shape;
|
|
|
|
|
ShortTypeName = "AudioZone";
|
|
|
|
|
FullTypeName = "Audio Zone";
|
2017-12-22 08:25:19 +08:00
|
|
|
|
Name = zone.Name;
|
|
|
|
|
NameHash = zone.NameHash;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
|
|
|
|
|
float deg2rad = (float)(Math.PI / 180.0);
|
|
|
|
|
|
|
|
|
|
switch (zone.Shape)
|
|
|
|
|
{
|
|
|
|
|
case Dat151ZoneShape.Box:
|
|
|
|
|
InnerPos = zone.InnerPos;
|
|
|
|
|
InnerMax = zone.InnerSize * 0.5f;
|
|
|
|
|
InnerMin = -InnerMax;
|
|
|
|
|
InnerOri = Quaternion.RotationAxis(Vector3.UnitZ, zone.InnerAngle * deg2rad);
|
|
|
|
|
break;
|
|
|
|
|
case Dat151ZoneShape.Sphere:
|
2017-12-22 08:25:19 +08:00
|
|
|
|
InnerPos = zone.InnerPos;
|
|
|
|
|
InnerOri = Quaternion.Identity;
|
|
|
|
|
InnerRad = zone.InnerSize.X;
|
|
|
|
|
OuterRad = zone.OuterSize.X;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
break;
|
|
|
|
|
case Dat151ZoneShape.Line:
|
|
|
|
|
InnerPos = zone.InnerPos;
|
|
|
|
|
InnerMin = new Vector3(-1.0f, -1.0f, 0.0f);
|
|
|
|
|
InnerMax = new Vector3(1.0f, 1.0f, (zone.InnerSize - zone.InnerPos).Length());
|
|
|
|
|
InnerOri = Quaternion.Invert(Quaternion.LookAtLH(zone.InnerPos, zone.InnerSize, Vector3.UnitZ));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OuterPos = zone.OuterPos;
|
|
|
|
|
OuterMax = zone.OuterSize * 0.5f;
|
|
|
|
|
OuterMin = -OuterMax;
|
|
|
|
|
OuterOri = Quaternion.RotationAxis(Vector3.UnitZ, zone.OuterAngle * deg2rad);
|
|
|
|
|
|
|
|
|
|
bool useouter = ((InnerMax.X == 0) || (InnerMax.Y == 0) || (InnerMax.Z == 0));
|
2017-12-22 08:25:19 +08:00
|
|
|
|
if (useouter && (zone.Shape != Dat151ZoneShape.Sphere))
|
|
|
|
|
{ } //not sure what these are yet!
|
2017-12-24 19:49:04 +08:00
|
|
|
|
Position = useouter ? OuterPos : InnerPos;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
HitboxMax = useouter ? OuterMax : InnerMax;
|
|
|
|
|
HitboxMin = useouter ? OuterMin : InnerMin;
|
2017-12-24 19:49:04 +08:00
|
|
|
|
Orientation = useouter ? OuterOri : InnerOri;
|
|
|
|
|
OrientationInv = Quaternion.Invert(Orientation);
|
2017-12-22 08:25:19 +08:00
|
|
|
|
HitSphereRad = InnerRad;
|
|
|
|
|
if (zone.Shape == Dat151ZoneShape.Sphere)
|
|
|
|
|
{
|
2017-12-24 19:49:04 +08:00
|
|
|
|
Position = InnerPos;
|
2017-12-22 08:25:19 +08:00
|
|
|
|
}
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
2017-12-23 04:56:39 +08:00
|
|
|
|
public AudioPlacement(RelFile rel, Dat151AmbientEmitter emitter)
|
2017-12-22 04:26:04 +08:00
|
|
|
|
{
|
|
|
|
|
RelFile = rel;
|
|
|
|
|
AudioEmitter = emitter;
|
|
|
|
|
Shape = Dat151ZoneShape.Sphere;
|
|
|
|
|
ShortTypeName = "AudioEmitter";
|
|
|
|
|
FullTypeName = "Audio Emitter";
|
2017-12-22 08:25:19 +08:00
|
|
|
|
Name = emitter.Name;
|
|
|
|
|
NameHash = emitter.NameHash;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
|
2017-12-24 19:49:04 +08:00
|
|
|
|
Orientation = Quaternion.Identity;
|
|
|
|
|
OrientationInv = Quaternion.Identity;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
InnerPos = emitter.Position;
|
2017-12-22 08:25:19 +08:00
|
|
|
|
OuterPos = InnerPos;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
InnerRad = emitter.InnerRad;
|
|
|
|
|
OuterRad = emitter.OuterRad;
|
|
|
|
|
|
|
|
|
|
bool useouter = (InnerRad == 0);
|
2017-12-22 08:25:19 +08:00
|
|
|
|
if (useouter)
|
|
|
|
|
{
|
|
|
|
|
InnerRad = 1;
|
|
|
|
|
}
|
2017-12-24 19:49:04 +08:00
|
|
|
|
Position = InnerPos;
|
2017-12-22 08:25:19 +08:00
|
|
|
|
HitSphereRad = InnerRad;// useouter ? OuterRad : InnerRad;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void SetPosition(Vector3 pos)
|
|
|
|
|
{
|
|
|
|
|
bool useouter = ((InnerMax.X == 0) || (InnerMax.Y == 0) || (InnerMax.Z == 0));
|
|
|
|
|
Vector3 delta = pos - InnerPos;
|
|
|
|
|
InnerPos = pos;
|
|
|
|
|
OuterPos += delta;
|
2017-12-24 19:49:04 +08:00
|
|
|
|
Position = useouter ? OuterPos : InnerPos;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
public void SetOrientation(Quaternion ori)
|
|
|
|
|
{
|
2017-12-24 19:49:04 +08:00
|
|
|
|
Orientation = ori;
|
|
|
|
|
OrientationInv = Quaternion.Invert(ori);
|
2017-12-22 04:26:04 +08:00
|
|
|
|
|
|
|
|
|
if (InnerOri == OuterOri)
|
|
|
|
|
{
|
2017-12-24 19:49:04 +08:00
|
|
|
|
InnerOri = Orientation;
|
|
|
|
|
OuterOri = Orientation;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//not sure yet how to allow independent rotation of inner & outer boxes...
|
|
|
|
|
//maybe only in project window?
|
|
|
|
|
bool useouter = ((InnerMax.X == 0) || (InnerMax.Y == 0) || (InnerMax.Z == 0));
|
|
|
|
|
if (useouter)
|
|
|
|
|
{
|
2017-12-24 19:49:04 +08:00
|
|
|
|
OuterOri = Orientation;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-24 19:49:04 +08:00
|
|
|
|
InnerOri = Orientation;
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-24 19:49:04 +08:00
|
|
|
|
|
|
|
|
|
public string GetNameString()
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(Name)) return Name;
|
|
|
|
|
return NameHash.ToString();
|
|
|
|
|
}
|
2017-12-22 04:26:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|