Skip to content

Commit a05c26d

Browse files
committed
- Fixed issues with xml export/imports
- More work for anims, fragments & bounds..
1 parent 5cf5509 commit a05c26d

File tree

58 files changed

+264882
-415
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+264882
-415
lines changed

Files/WasFile.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ public class WasFile : FilePack
1010
{
1111
public Rpf6FileEntry FileEntry;
1212
public Rsc6AnimationSet AnimSet;
13-
public string Name;
1413
public JenkHash Hash;
14+
public string Name;
15+
public bool HasHumanAnim;
16+
public bool HasAnimalAnim;
1517

1618
public WasFile()
1719
{
@@ -20,11 +22,9 @@ public WasFile()
2022
public WasFile(Rpf6FileEntry e)
2123
{
2224
FileEntry = e;
23-
if (FileEntry != null)
24-
{
25-
Name = FileEntry.Name;
26-
Hash = FileEntry.ShortNameHash;
27-
}
25+
FileInfo = e;
26+
Name = e?.NameLower;
27+
Hash = JenkHash.GenHash(e?.NameLower ?? "");
2828
}
2929

3030
public override void Load(byte[] data)
@@ -37,6 +37,14 @@ public override void Load(byte[] data)
3737
Position = (ulong)e.FlagInfos.RSC85_ObjectStart + Rpf6Crypto.VIRTUAL_BASE
3838
};
3939
AnimSet = r.ReadBlock<Rsc6AnimationSet>();
40+
41+
foreach (var type in AnimSet?.ClipDictionary.Item?.AnimDict.Item?.AnimTypes)
42+
{
43+
if (type == "human")
44+
HasHumanAnim = true;
45+
else if (type == "animal")
46+
HasAnimalAnim = true;
47+
}
4048
}
4149

4250
public override byte[] Save()

Files/WcgFile.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using CodeX.Core.Engine;
2+
using CodeX.Core.Utilities;
3+
using CodeX.Games.RDR1.RPF6;
4+
using CodeX.Games.RDR1.RSC6;
5+
6+
namespace CodeX.Games.RDR1.Files
7+
{
8+
public class WcgFile : FilePack
9+
{
10+
public Rpf6FileEntry FileEntry;
11+
public Rsc6CombatCoverGrid Grid;
12+
public string Name;
13+
public JenkHash Hash;
14+
15+
public WcgFile()
16+
{
17+
}
18+
19+
public WcgFile(Rpf6FileEntry file) : base(file)
20+
{
21+
FileEntry = file;
22+
Name = file?.NameLower;
23+
Hash = JenkHash.GenHash(file?.NameLower ?? "");
24+
}
25+
26+
public WcgFile(Rsc6CombatCoverGrid grid) : base(null)
27+
{
28+
Grid = grid;
29+
}
30+
31+
public override void Load(byte[] data)
32+
{
33+
if (FileInfo is not Rpf6ResourceFileEntry e)
34+
return;
35+
36+
var r = new Rsc6DataReader(e, data)
37+
{
38+
Position = (ulong)e.FlagInfos.RSC85_ObjectStart + Rpf6Crypto.VIRTUAL_BASE
39+
};
40+
Grid = r.ReadBlock<Rsc6CombatCoverGrid>();
41+
}
42+
43+
public override byte[] Save()
44+
{
45+
if (Grid == null) return null;
46+
var writer = new Rsc6DataWriter();
47+
writer.WriteBlock(Grid);
48+
byte[] data = writer.Build(26);
49+
return data;
50+
}
51+
52+
public override void Read(MetaNodeReader reader)
53+
{
54+
}
55+
56+
public override void Write(MetaNodeWriter writer)
57+
{
58+
}
59+
60+
public override string ToString()
61+
{
62+
return Grid.ToString();
63+
}
64+
}
65+
}

Files/WfdFile.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,16 @@ public override byte[] Save()
5454
byte[] data = writer.Build(1);
5555
return data;
5656
}
57+
58+
public override void Read(MetaNodeReader reader)
59+
{
60+
FragDrawable = new();
61+
FragDrawable.Read(reader);
62+
}
63+
64+
public override void Write(MetaNodeWriter writer)
65+
{
66+
FragDrawable?.Write(writer);
67+
}
5768
}
5869
}

Files/WftFile.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,16 @@ public override byte[] Save()
6060
byte[] data = writer.Build(138);
6161
return data;
6262
}
63+
64+
public override void Read(MetaNodeReader reader)
65+
{
66+
Fragment = new();
67+
Fragment.Read(reader);
68+
}
69+
70+
public override void Write(MetaNodeWriter writer)
71+
{
72+
Fragment?.Write(writer);
73+
}
6374
}
6475
}

Files/WsiFile.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using CodeX.Core.Utilities;
33
using CodeX.Games.RDR1.RPF6;
44
using CodeX.Games.RDR1.RSC6;
5-
using System.Diagnostics;
6-
using System.Text;
75

86
namespace CodeX.Games.RDR1.Files
97
{

Files/WvdFile.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,16 @@ public override byte[] Save()
6969
byte[] data = writer.Build(133);
7070
return data;
7171
}
72+
73+
public override void Read(MetaNodeReader reader)
74+
{
75+
VisualDictionary = new();
76+
VisualDictionary.Read(reader);
77+
}
78+
79+
public override void Write(MetaNodeWriter writer)
80+
{
81+
VisualDictionary?.Write(writer);
82+
}
7283
}
7384
}

Prefabs/RDR1Animals.cs

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using System.Linq;
1010
using System.IO;
1111
using CodeX.Games.RDR1.RSC6;
12+
using CodeX.Core.Numerics;
13+
using System.Numerics;
1214

1315
namespace CodeX.Games.RDR1.Prefabs
1416
{
@@ -51,15 +53,16 @@ public void Init(Rpf6FileManager fman)
5153
Prefabs[name] = new RDR1AnimalPrefab(this, name);
5254
}
5355

54-
var wasEntries = FileManager.DataFileMgr.StreamEntries[Rpf6FileExt.was];
56+
var wasEntries = dfm.WasFiles;
5557
if (wasEntries != null)
5658
{
5759
var wasList = new List<string>() { "" };
58-
foreach (var was in wasEntries)
60+
foreach (var kv in wasEntries)
5961
{
60-
if (was.Value == null) continue;
61-
if (!was.Value.Name.EndsWith(".was")) continue;
62-
wasList.Add(was.Value.ShortName);
62+
var was = kv.Value;
63+
if (was == null) continue;
64+
if (!was.HasAnimalAnim) continue;
65+
wasList.Add(kv.Key.ToString());
6366
}
6467
wasList.Sort();
6568
WasNames = wasList.ToArray();
@@ -180,6 +183,9 @@ public RDR1Animal(RDR1AnimalPrefab prefab, bool buildPiece = true) : base(false)
180183
Target = this
181184
};
182185

186+
//Turn peds to the sun and the camera
187+
SetOrientation(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, FloatUtil.HalfPi), false);
188+
183189
if (buildPiece)
184190
{
185191
BuildPiece();
@@ -198,6 +204,8 @@ public void BuildPiece()
198204

199205
var piece = Wft.Piece;
200206
piece.ImmediateLoad = true;
207+
piece.UpdateAllModels();
208+
piece.UpdateBounds();
201209

202210
SetPiece(piece);
203211
UpdateBounds();
@@ -233,6 +241,30 @@ public string[] GetWasClipNames(out string defaultval)
233241
return list.ToArray();
234242
}
235243

244+
public string[] GetWasAnimNames(out string defaultval)
245+
{
246+
defaultval = null;
247+
248+
var anims = Was?.AnimSet?.ClipDictionary.Item?.AnimDict.Item?.Animations;
249+
var animTypes = Was?.AnimSet?.ClipDictionary.Item?.AnimDict.Item?.AnimTypes;
250+
if (anims == null) return null;
251+
252+
var list = new List<string>();
253+
for (int i = 0; i < anims.Length; i++)
254+
{
255+
var anim = anims[i];
256+
if (anim == null) continue;
257+
258+
var type = animTypes[i];
259+
if (type != "animal") continue;
260+
261+
var name = anim.RefactoredName.ToString();
262+
list.Add(name);
263+
}
264+
list.Sort();
265+
return list.ToArray();
266+
}
267+
236268
public void LoadWas(string name)
237269
{
238270
var animals = Prefab.Animals;
@@ -279,6 +311,21 @@ public void PlayClip(string name)
279311
animator.Anim = null;
280312
}
281313

314+
public void PlayAnim(string animName)
315+
{
316+
if (Animator is not RDR1Animator animator) return;
317+
var animdict = Was?.AnimSet?.ClipDictionary.Item?.AnimDict.Item?.Dict;
318+
var anim = (Rsc6Animation)null;
319+
320+
foreach (var kv in animdict)
321+
{
322+
if (kv.Value.RefactoredName != animName) continue;
323+
anim = kv.Value;
324+
}
325+
animator.Anim = anim;
326+
animator.Clip = null;
327+
}
328+
282329
public Prefab GetPrefab()
283330
{
284331
return Prefab;
@@ -303,14 +350,14 @@ public void GetSlotOptions(PrefabSlot slot, out object[] options, out object def
303350
}
304351
else if (slot.Name == "Clip")
305352
{
306-
options = GetWasClipNames(out var defaultstr);
307-
defaultOption = Path.GetFileName(defaultstr);
353+
//options = GetWasClipNames(out var defaultstr);
354+
//defaultOption = Path.GetFileName(defaultstr);
308355
}
309-
/*else if (slot.Name == "Anim")
356+
else if (slot.Name == "Anim")
310357
{
311358
options = GetWasAnimNames(out var defaultstr);
312359
defaultOption = defaultstr;
313-
}*/
360+
}
314361
}
315362
}
316363

@@ -329,12 +376,12 @@ public void SetSlotOption(PrefabSlot slot, object option)
329376
}
330377
else if (slot.Name == "Clip")
331378
{
332-
PlayClip(option as string);
379+
//PlayClip(option as string);
333380
}
334-
/*else if (slot.Name == "Anim")
381+
else if (slot.Name == "Anim")
335382
{
336383
PlayAnim(option as string);
337-
}*/
384+
}
338385
}
339386
}
340387
}

0 commit comments

Comments
 (0)