YCD inspector form. Minor PSO to XML improvements

This commit is contained in:
dexyfex
2017-09-29 22:23:37 +10:00
Unverified
parent f974c9eb49
commit fd740a761d
10 changed files with 752 additions and 3216 deletions
+70 -5
View File
@@ -11,6 +11,11 @@ namespace CodeWalker.GameFiles
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; }
public YcdFile() : base(null, GameFileType.Ycd)
{
@@ -22,7 +27,8 @@ namespace CodeWalker.GameFiles
public void Load(byte[] data, RpfFileEntry entry)
{
//Name = entry.Name;
Name = entry.Name;
RpfFileEntry = entry;
//Hash = entry.ShortNameHash;
@@ -38,18 +44,77 @@ namespace CodeWalker.GameFiles
ClipDictionary = rd.ReadBlock<ClipDictionary>();
ClipMap = new Dictionary<MetaHash, ClipMapEntry>();
if ((ClipDictionary != null) && (ClipDictionary.Clips != null) && (ClipDictionary.Clips.data_items != null))
AnimMap = new Dictionary<MetaHash, AnimationMapEntry>();
if (ClipDictionary != null)
{
foreach (var cme in ClipDictionary.Clips.data_items)
if ((ClipDictionary.Clips != null) && (ClipDictionary.Clips.data_items != null))
{
if (cme != null)
foreach (var cme in ClipDictionary.Clips.data_items)
{
ClipMap[cme.Hash] = cme;
if (cme != null)
{
ClipMap[cme.Hash] = cme;
var nxt = cme.Next;
while (nxt != null)
{
ClipMap[nxt.Hash] = nxt;
nxt = nxt.Next;
}
}
}
}
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;
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);
}
name = name.ToLowerInvariant();
JenkIndex.Ensure(name);
//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
//{
//}
}
ClipMapEntries = ClipMap.Values.ToArray();
AnimMapEntries = AnimMap.Values.ToArray();
}
}
}
File diff suppressed because it is too large Load Diff
+68 -15
View File
@@ -545,7 +545,18 @@ namespace CodeWalker.GameFiles
}
break;
case PsoDataType.Flags:
var flagsInfo = cont.GetEnumInfo(entry.EntryNameHash);
uint fCount = (entry.ReferenceKey >> 16) & 0x0000FFFF;
uint fEntry = (entry.ReferenceKey & 0xFFFF);
var fEnt = structInfo.GetEntry((int)fEntry);
PsoEnumInfo flagsInfo = null;
if ((fEnt != null) && (fEnt.EntryNameHash == MetaName.ARRAYINFO))
{
flagsInfo = cont.GetEnumInfo((MetaName)fEnt.ReferenceKey);
}
if (flagsInfo == null)
{
flagsInfo = cont.GetEnumInfo(entry.EntryNameHash);
}
uint? flagsVal = null;
switch (entry.Unk_5h)
{
@@ -869,7 +880,7 @@ namespace CodeWalker.GameFiles
var arrHash = MetaTypes.ConvertData<Array_uint>(data, eoffset);
arrHash.SwapEnd();
var hashArr = PsoTypes.GetHashArray(cont.Pso, arrHash);
WriteItemArray(sb, hashArr, indent, ename, "Hash", FormatHash);
WriteItemArray(sb, hashArr, indent, ename, "Hash", HashString);
break;
}
break;
@@ -957,23 +968,54 @@ namespace CodeWalker.GameFiles
var mapreftype2 = structInfo.Entries[mapidx1];
var x1 = MetaTypes.SwapBytes(BitConverter.ToInt32(data, eoffset));//same as ref key?
var x2 = MetaTypes.SwapBytes(BitConverter.ToInt32(data, eoffset + 4));//0?
var xStrucPtr = MetaTypes.ConvertData<Array_Structure>(data, eoffset + 8);
xStrucPtr.SwapEnd();
var xBlockId = (int)xStrucPtr.PointerDataId;
var x3 = MetaTypes.SwapBytes(BitConverter.ToInt32(data, eoffset + 8));//pointer?
var x4 = MetaTypes.SwapBytes(BitConverter.ToInt32(data, eoffset + 12));//
var x5 = MetaTypes.SwapBytes(BitConverter.ToInt32(data, eoffset + 16));//count/capacity?
var x6 = MetaTypes.SwapBytes(BitConverter.ToInt32(data, eoffset + 20));//
//File.WriteAllText("C:\\CodeWalker.Projects\\testxml.xml", sb.ToString());
if (x1 != 0x1000000)
{ }
if (x2 != 0)
{ }
if (x4 != 0)
{ }
if (x6 != 0)
{ }
var xBlockId = x3 & 0xFFF;
var xOffset = (x3 >> 12) & 0xFFFFF;
var xCount1 = x5 & 0xFFFF;
var xCount2 = (x5 >> 16) & 0xFFFF;
//var x1a = x1 & 0xFFF; //block id? for another pointer?
//var x1b = (x1 >> 12) & 0xFFFFF; //offset?
//var x4u = (uint)x4;
//var x4a = x4 & 0xFFF; //block id?
//var x4b = (x4 >> 12) & 0xFFFFF; //offset?
//var x2h = (MetaHash)(uint)x2;
//var x6h = (MetaHash)(uint)x6;
//if (x1a > 0)
//{ }
var xBlock = cont.Pso.GetBlock(xBlockId);
if ((xBlock == null) && (xStrucPtr.Count1 > 0))
if ((xBlock == null) && (xCount1 > 0))
{
ErrorXml(sb, cind, ename + ": Couldn't find Map xBlock: " + xStrucPtr.PointerDataId.ToString());
ErrorXml(sb, cind, ename + ": Couldn't find Map xBlock: " + xBlockId.ToString());
}
else
{
if (xStrucPtr.Count1 != xStrucPtr.Count2)
if (xCount1 != xCount2)
{
}
if (xStrucPtr.Count1 > 0)
if (xCount1 > 0)
{
var xStruct = cont.GetStructureInfo(xBlock.NameHash);
var xOffset1 = xStrucPtr.PointerDataOffset;
var xOffset1 = xOffset;
var xind = indent + 1;
var aind = indent + 2;
var kEntry = xStruct?.FindEntry(MetaName.Key);
@@ -1010,14 +1052,14 @@ namespace CodeWalker.GameFiles
else
{
OpenTag(sb, xind, ename);
int xOffset = (int)xOffset1;
int xCount = xStrucPtr.Count1;
int xOffset2 = (int)xOffset1;
int xCount = xCount1;
for (int n = 0; n < xCount; n++)
{
//WriteNode(sb, aind, cont, xBlockId, xOffset, XmlTagMode.Item, xStruct.IndexInfo.NameHash);
int sOffset = xOffset + xBlock.Offset;
int sOffset = xOffset2 + xBlock.Offset;
var kOffset = sOffset + kEntry.DataOffset;
var iOffset = sOffset + iEntry.DataOffset;
var kStr = GetStringValue(cont.Pso, kEntry, data, kOffset);
@@ -1036,7 +1078,9 @@ namespace CodeWalker.GameFiles
var iStruc = cont.GetStructureInfo(iBlock.NameHash);
if (iStruc?.EntriesCount == 0)
{
SelfClosingTag(sb, aind, iStr);
//SelfClosingTag(sb, aind, iStr);
OpenTag(sb, aind, iStr);
CloseTag(sb, aind, "Item");
}
else
{
@@ -1045,7 +1089,7 @@ namespace CodeWalker.GameFiles
CloseTag(sb, aind, "Item");
}
}
xOffset += xStruct.StructureLength;
xOffset2 += xStruct.StructureLength;
if ((n < (xCount - 1)) && (xBlock != null) && (xOffset >= xBlock.Length))
{
ErrorXml(sb, aind, "Offset out of range! Count is " + xCount.ToString());
@@ -1490,6 +1534,15 @@ namespace CodeWalker.GameFiles
{
var str = JenkIndex.TryGetString(h);
if (string.IsNullOrEmpty(str))
{
var nh = (MetaName)(uint)h;
if (Enum.IsDefined(typeof(MetaName), nh))
{
return nh.ToString();
}
}
//todo: make sure JenkIndex is built!
//todo: do extra hash lookup here
+31 -26
View File
@@ -378,18 +378,18 @@ namespace CodeWalker.GameFiles
}
// structure data
public byte Unknown_00h { get; set; }
public byte Unknown_01h { get; set; }
public byte Unknown_02h { get; set; }
public byte Unknown_03h { get; set; }
//public byte Unknown_00h { get; set; }
//public byte Unknown_01h { get; set; }
//public byte Unknown_02h { get; set; }
//public byte Unknown_03h { get; set; }
public MetaHash Unknown_00h { get; set; }
public uint DataLength { get; set; }
public uint Unknown_08h { get; set; } // 0x00000000
public uint Unknown_0Ch { get; set; }
public uint Unknown_10h { get; set; }
public ushort Unknown_14h { get; set; }
public ushort Unknown_16h { get; set; }
//public uint Unknown_18h { get; set; }
public ushort Unknown_18h { get; set; }
public uint Unknown_08h { get; set; } // 0x00000000 ..sequence header offset?
public uint Unknown_0Ch { get; set; } //[uv1:] bytes used by sequence "header"? offset to data items
public uint Unknown_10h { get; set; } //total block length, == BlockLength
public ushort Unknown_14h { get; set; } //
public ushort Unknown_16h { get; set; } // count of data items (361?)
public ushort Unknown_18h { get; set; } //[uv1:8] stride of data item?
public ushort Unknown_1Ah { get; set; }
public ushort Unknown_1Ch { get; set; }
public ushort Unknown_1Eh { get; set; }
@@ -398,11 +398,11 @@ namespace CodeWalker.GameFiles
public override void Read(ResourceDataReader reader, params object[] parameters)
{
// read structure data
//this.Unknown_00h = reader.ReadUInt32();//2965995365 2837183178
this.Unknown_00h = reader.ReadByte(); //101 202 97 120
this.Unknown_01h = reader.ReadByte(); //127 250 202 168
this.Unknown_02h = reader.ReadByte(); //201 27 115 126
this.Unknown_03h = reader.ReadByte(); //176 169 131 74
this.Unknown_00h = reader.ReadUInt32();//2965995365 2837183178
//this.Unknown_00h = reader.ReadByte(); //101 202 97 120
//this.Unknown_01h = reader.ReadByte(); //127 250 202 168
//this.Unknown_02h = reader.ReadByte(); //201 27 115 126
//this.Unknown_03h = reader.ReadByte(); //176 169 131 74
this.DataLength = reader.ReadUInt32(); //282 142 1206 358
this.Unknown_08h = reader.ReadUInt32();//0 0 0 0
this.Unknown_0Ch = reader.ReadUInt32();//224 (E0) 32 (20) 536 (218) 300 offset in data to?
@@ -420,10 +420,10 @@ namespace CodeWalker.GameFiles
this.Data = reader.ReadBytes((int)DataLength);
reader.Position = pos;
float[] fvals = reader.ReadFloatsAt((ulong)pos, DataLength / 4);
ushort[] svals = reader.ReadUshortsAt((ulong)pos, DataLength / 2);
if (fvals != null)
{ }
//float[] fvals = reader.ReadFloatsAt((ulong)pos, DataLength / 4);
//ushort[] svals = reader.ReadUshortsAt((ulong)pos, DataLength / 2);
//if (fvals != null)
//{ }
//reader.Position = pos;
//float f0 = reader.ReadSingle(); // 0 0 0 0
@@ -463,6 +463,11 @@ namespace CodeWalker.GameFiles
writer.Write(this.Unknown_1Eh);
writer.Write(this.Data);
}
public override string ToString()
{
return Unknown_00h.ToString() + ": " + DataLength.ToString();
}
}
[TypeConverter(typeof(ExpandableObjectConverter))] public class ClipMapEntry : ResourceSystemBlock
@@ -528,7 +533,7 @@ namespace CodeWalker.GameFiles
public override string ToString()
{
return Hash.ToString();
return Clip?.Name ?? Hash.ToString();
}
}
[TypeConverter(typeof(ExpandableObjectConverter))] public class ClipBase : ResourceSystemBlock, IResourceXXSystemBlock
@@ -546,8 +551,8 @@ namespace CodeWalker.GameFiles
public uint Unknown_10h { get; set; }
public uint Unknown_14h { get; set; } // 0x00000000
public ulong NamePointer { get; set; }
public ushort Unknown_20h { get; set; } // short, name length
public ushort Unknown_22h { get; set; } // short, name length +1
public ushort NameLength { get; set; } // short, name length
public ushort NameCapacity { get; set; } // short, name length +1
public uint Unknown_24h { get; set; } // 0x00000000
public ulong Unknown_28hPtr { get; set; } // 0x50000000
public uint Unknown_30h { get; set; }
@@ -572,8 +577,8 @@ namespace CodeWalker.GameFiles
this.Unknown_10h = reader.ReadUInt32();
this.Unknown_14h = reader.ReadUInt32();
this.NamePointer = reader.ReadUInt64();
this.Unknown_20h = reader.ReadUInt16();
this.Unknown_22h = reader.ReadUInt16();
this.NameLength = reader.ReadUInt16();
this.NameCapacity = reader.ReadUInt16();
this.Unknown_24h = reader.ReadUInt32();
this.Unknown_28hPtr = reader.ReadUInt64();
this.Unknown_30h = reader.ReadUInt32();
@@ -613,7 +618,7 @@ namespace CodeWalker.GameFiles
writer.Write(this.Unknown_10h);
writer.Write(this.Unknown_14h);
writer.Write(this.NamePointer);
writer.Write(this.Unknown_20h);
writer.Write(this.NameLength);
writer.Write(this.Unknown_24h);
writer.Write(this.Unknown_28hPtr);
writer.Write(this.Unknown_30h);