Added ResourceAnalyzer

This commit is contained in:
dexy 2020-03-10 22:50:02 +11:00
parent 9aa228c1da
commit d3bc78ddb4
2 changed files with 60 additions and 2 deletions

View File

@ -106,6 +106,7 @@ namespace CodeWalker.GameFiles
public YftFile Yft { get; set; }
//public ResourceAnalyzer Analyzer { get; set; }
public override void Read(ResourceDataReader reader, params object[] parameters)
{
@ -196,6 +197,7 @@ namespace CodeWalker.GameFiles
AssignChildrenShaders();
//Analyzer = new ResourceAnalyzer(reader);
////just testing!!
@ -303,8 +305,6 @@ namespace CodeWalker.GameFiles
// default:
// break;//no hit
//}
}
public override void Write(ResourceDataWriter writer, params object[] parameters)
{

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace CodeWalker.GameFiles
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public class ResourceAnalyzer
{
public ResourceAnalyzerItem[] Blocks { get; set; }
[TypeConverter(typeof(ExpandableObjectConverter))]
public class ResourceAnalyzerItem
{
public long Position { get; set; }
public long Length { get; set; }
public long Offset { get { return Position & 0xFFFFFFF; } }
public ResourceSystemBlock SystemBlock { get; set; }
public ResourceGraphicsBlock GraphicsBlock { get; set; }
public override string ToString()
{
var type = "";
if (SystemBlock != null)
{
type = SystemBlock.GetType().Name;
}
if (GraphicsBlock != null)
{
type = GraphicsBlock.GetType().Name;
}
return Offset.ToString() + " - " + Length.ToString() + " - " + type;
}
}
public ResourceAnalyzer(ResourceDataReader reader)
{
var dlist = new List<ResourceAnalyzerItem>();
var dict = reader.blockPool;
foreach (var kvp in dict)
{
var item = new ResourceAnalyzerItem();
item.Position = kvp.Key;
item.Length = kvp.Value.BlockLength;
item.SystemBlock = kvp.Value as ResourceSystemBlock;
item.GraphicsBlock = kvp.Value as ResourceGraphicsBlock;
dlist.Add(item);
}
dlist.Sort((a, b) => a.Position.CompareTo(b.Position));
Blocks = dlist.ToArray();
}
}
}