CodeWalker/GameFiles/FileTypes/YcdFile.cs

131 lines
4.3 KiB
C#
Raw Normal View History

2017-09-21 18:33:05 +08:00
using System;
using System.Collections.Generic;
2017-10-04 11:35:39 +08:00
using System.ComponentModel;
2017-09-21 18:33:05 +08:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodeWalker.GameFiles
{
2017-10-04 11:35:39 +08:00
[TypeConverter(typeof(ExpandableObjectConverter))]
2017-09-21 18:33:05 +08:00
public class YcdFile : GameFile, PackedFile
{
public ClipDictionary ClipDictionary { get; set; }
public Dictionary<MetaHash, ClipMapEntry> ClipMap { get; set; }
public Dictionary<MetaHash, AnimationMapEntry> AnimMap { get; set; }
public ClipMapEntry[] ClipMapEntries { get; set; }
public AnimationMapEntry[] AnimMapEntries { get; set; }
2017-09-21 18:33:05 +08:00
public YcdFile() : base(null, GameFileType.Ycd)
{
}
public YcdFile(RpfFileEntry entry) : base(entry, GameFileType.Ycd)
{
}
public void Load(byte[] data, RpfFileEntry entry)
{
Name = entry.Name;
RpfFileEntry = entry;
2017-09-21 18:33:05 +08:00
//Hash = entry.ShortNameHash;
RpfResourceFileEntry resentry = entry as RpfResourceFileEntry;
if (resentry == null)
{
throw new Exception("File entry wasn't a resource! (is it binary data?)");
}
ResourceDataReader rd = new ResourceDataReader(resentry, data);
ClipDictionary = rd.ReadBlock<ClipDictionary>();
ClipMap = new Dictionary<MetaHash, ClipMapEntry>();
AnimMap = new Dictionary<MetaHash, AnimationMapEntry>();
if (ClipDictionary != null)
2017-09-21 18:33:05 +08:00
{
if ((ClipDictionary.Clips != null) && (ClipDictionary.Clips.data_items != null))
2017-09-21 18:33:05 +08:00
{
foreach (var cme in ClipDictionary.Clips.data_items)
2017-09-21 18:33:05 +08:00
{
if (cme != null)
{
ClipMap[cme.Hash] = cme;
var nxt = cme.Next;
while (nxt != null)
{
ClipMap[nxt.Hash] = nxt;
nxt = nxt.Next;
}
}
2017-09-21 18:33:05 +08:00
}
}
if ((ClipDictionary.Animations != null) && (ClipDictionary.Animations.Animations != null) && (ClipDictionary.Animations.Animations.data_items != null))
{
foreach (var ame in ClipDictionary.Animations.Animations.data_items)
{
if (ame != null)
{
AnimMap[ame.Hash] = ame;
var nxt = ame.NextEntry;
while (nxt != null)
{
AnimMap[nxt.Hash] = nxt;
nxt = nxt.NextEntry;
}
}
}
}
}
foreach (var cme in ClipMap.Values)
{
var clip = cme.Clip;
if (clip == null) continue;
2017-10-04 11:35:39 +08:00
clip.Ycd = this;
if (string.IsNullOrEmpty(clip.Name)) continue;
string name = clip.Name.Replace('\\', '/');
var slidx = name.LastIndexOf('/');
if ((slidx >= 0) && (slidx < name.Length - 1))
{
name = name.Substring(slidx + 1);
}
var didx = name.LastIndexOf('.');
if ((didx > 0) && (didx < name.Length))
{
name = name.Substring(0, didx);
}
2017-10-04 11:35:39 +08:00
clip.ShortName = name;
name = name.ToLowerInvariant();
JenkIndex.Ensure(name);
2017-10-04 11:35:39 +08:00
//if (name.EndsWith("_uv_0")) //hash for these entries match string with this removed, +1
//{
//}
//if (name.EndsWith("_uv_1")) //same as above, but +2
//{
//}
2017-09-21 18:33:05 +08:00
}
2017-10-04 11:35:39 +08:00
foreach (var ame in AnimMap.Values)
{
var anim = ame.Animation;
if (anim == null) continue;
anim.Ycd = this;
}
2017-09-21 18:33:05 +08:00
ClipMapEntries = ClipMap.Values.ToArray();
AnimMapEntries = AnimMap.Values.ToArray();
2017-09-21 18:33:05 +08:00
}
}
}