mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2026-05-14 15:55:40 +08:00
TextureBase BlockLength fix, ResourceAnalyzer improvement, resource packing improvement
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace CodeWalker.GameFiles
|
||||
@@ -17,12 +18,15 @@ namespace CodeWalker.GameFiles
|
||||
public long Position { get; set; }
|
||||
public long Length { get; set; }
|
||||
public long Offset { get { return Position & 0xFFFFFFF; } }
|
||||
public bool Overlapping { get; set; }
|
||||
public ResourceSystemBlock SystemBlock { get; set; }
|
||||
public ResourceGraphicsBlock GraphicsBlock { get; set; }
|
||||
public Array Array { get; set; }
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var type = "";
|
||||
var type = "########## ??? ##########";
|
||||
if (SystemBlock != null)
|
||||
{
|
||||
type = SystemBlock.GetType().Name;
|
||||
@@ -31,15 +35,18 @@ namespace CodeWalker.GameFiles
|
||||
{
|
||||
type = GraphicsBlock.GetType().Name;
|
||||
}
|
||||
return Offset.ToString() + " - " + Length.ToString() + " - " + type;
|
||||
if (Array != null)
|
||||
{
|
||||
type = Array.GetType().Name + " (" + Array.Length.ToString() + ")";
|
||||
}
|
||||
return Offset.ToString() + " - " + Length.ToString() + " - " + type + (Overlapping ? " (embedded)" : "");
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceAnalyzer(ResourceDataReader reader)
|
||||
{
|
||||
var dlist = new List<ResourceAnalyzerItem>();
|
||||
var dict = reader.blockPool;
|
||||
foreach (var kvp in dict)
|
||||
foreach (var kvp in reader.blockPool)
|
||||
{
|
||||
var item = new ResourceAnalyzerItem();
|
||||
item.Position = kvp.Key;
|
||||
@@ -48,11 +55,56 @@ namespace CodeWalker.GameFiles
|
||||
item.GraphicsBlock = kvp.Value as ResourceGraphicsBlock;
|
||||
dlist.Add(item);
|
||||
}
|
||||
foreach (var kvp in reader.arrayPool)
|
||||
{
|
||||
var item = new ResourceAnalyzerItem();
|
||||
item.Position = kvp.Key;
|
||||
item.Array = kvp.Value as Array;
|
||||
if (item.Array != null)
|
||||
{
|
||||
var typ = item.Array.GetType().GetElementType();
|
||||
var siz = Marshal.SizeOf(typ);
|
||||
item.Length = item.Array.Length * siz;
|
||||
}
|
||||
dlist.Add(item);
|
||||
}
|
||||
|
||||
dlist.Sort((a, b) => a.Position.CompareTo(b.Position));
|
||||
|
||||
Blocks = dlist.ToArray();
|
||||
//Blocks = dlist.ToArray();
|
||||
|
||||
|
||||
var dlist2 = new List<ResourceAnalyzerItem>();
|
||||
long pos = 0;
|
||||
foreach (var item in dlist)
|
||||
{
|
||||
if (item.Offset > pos)
|
||||
{
|
||||
var gap = new ResourceAnalyzerItem();
|
||||
gap.Position = pos;
|
||||
gap.Length = item.Offset - pos;
|
||||
dlist2.Add(gap);
|
||||
pos = item.Offset;
|
||||
}
|
||||
if (item.Offset == pos)
|
||||
{
|
||||
dlist2.Add(item);
|
||||
pos = item.Offset + item.Length;
|
||||
if ((pos % 16) != 0) pos += (16 - (pos % 16));//ignore alignment paddings
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Overlapping = true;
|
||||
dlist2.Add(item);
|
||||
var pos2 = item.Offset + item.Length;
|
||||
if (pos2 > pos) pos = pos2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Blocks = dlist2.ToArray();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user