mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-22 23:12:59 +08:00
Refactored loading resource files from raw byte array code
This commit is contained in:
parent
bfddaada31
commit
68273e7dca
@ -71,54 +71,7 @@ namespace CodeWalker.GameFiles
|
||||
{
|
||||
//direct load from a raw, compressed ymap file (openIV-compatible format)
|
||||
|
||||
RpfResourceFileEntry resentry = new RpfResourceFileEntry();
|
||||
|
||||
//hopefully this format has an RSC7 header...
|
||||
uint rsc7 = BitConverter.ToUInt32(data, 0);
|
||||
if (rsc7 == 0x37435352) //RSC7 header present!
|
||||
{
|
||||
int version = BitConverter.ToInt32(data, 4);
|
||||
resentry.SystemFlags = BitConverter.ToUInt32(data, 8);
|
||||
resentry.GraphicsFlags = BitConverter.ToUInt32(data, 12);
|
||||
if (data.Length > 16)
|
||||
{
|
||||
int newlen = data.Length - 16; //trim the header from the data passed to the next step.
|
||||
byte[] newdata = new byte[newlen];
|
||||
Buffer.BlockCopy(data, 16, newdata, 0, newlen);
|
||||
data = newdata;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = null; //shouldn't happen... empty..
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//direct load from file without the rpf header..
|
||||
//assume it's in resource meta format
|
||||
resentry.SystemFlags = RpfResourceFileEntry.GetFlagsFromSize(data.Length, 0);
|
||||
resentry.GraphicsFlags = RpfResourceFileEntry.GetFlagsFromSize(0, 2); //graphics type 2 for ymap
|
||||
}
|
||||
|
||||
var oldresentry = RpfFileEntry as RpfResourceFileEntry;
|
||||
if (oldresentry != null) //update the existing entry with the new one
|
||||
{
|
||||
oldresentry.SystemFlags = resentry.SystemFlags;
|
||||
oldresentry.GraphicsFlags = resentry.GraphicsFlags;
|
||||
resentry.Name = oldresentry.Name;
|
||||
resentry.NameHash = oldresentry.NameHash;
|
||||
resentry.NameLower = oldresentry.NameLower;
|
||||
resentry.ShortNameHash = oldresentry.ShortNameHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
RpfFileEntry = resentry; //just stick it in there for later...
|
||||
}
|
||||
|
||||
data = ResourceBuilder.Decompress(data);
|
||||
|
||||
|
||||
Load(data, resentry);
|
||||
RpfFile.LoadResourceFile(this, data, 2);
|
||||
|
||||
Loaded = true;
|
||||
}
|
||||
|
@ -43,62 +43,14 @@ namespace CodeWalker.GameFiles
|
||||
|
||||
|
||||
|
||||
public void LoadRSC(byte[] data)
|
||||
public void Load(byte[] data)
|
||||
{
|
||||
//direct load from a raw, compressed ymt resource file (openIV-compatible format)
|
||||
|
||||
RpfResourceFileEntry resentry = new RpfResourceFileEntry();
|
||||
RpfFile.LoadResourceFile(this, data, 2);
|
||||
|
||||
//hopefully this format has an RSC7 header...
|
||||
uint rsc7 = BitConverter.ToUInt32(data, 0);
|
||||
if (rsc7 == 0x37435352) //RSC7 header present!
|
||||
{
|
||||
int version = BitConverter.ToInt32(data, 4);
|
||||
resentry.SystemFlags = BitConverter.ToUInt32(data, 8);
|
||||
resentry.GraphicsFlags = BitConverter.ToUInt32(data, 12);
|
||||
if (data.Length > 16)
|
||||
{
|
||||
int newlen = data.Length - 16; //trim the header from the data passed to the next step.
|
||||
byte[] newdata = new byte[newlen];
|
||||
Buffer.BlockCopy(data, 16, newdata, 0, newlen);
|
||||
data = newdata;
|
||||
Loaded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = null; //shouldn't happen... empty..
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//direct load from file without the rpf header..
|
||||
//assume it's in resource meta format
|
||||
resentry.SystemFlags = RpfResourceFileEntry.GetFlagsFromSize(data.Length, 0);
|
||||
resentry.GraphicsFlags = RpfResourceFileEntry.GetFlagsFromSize(0, 2); //graphics type 2 for ymt/meta
|
||||
}
|
||||
|
||||
var oldresentry = RpfFileEntry as RpfResourceFileEntry;
|
||||
if (oldresentry != null) //update the existing entry with the new one
|
||||
{
|
||||
oldresentry.SystemFlags = resentry.SystemFlags;
|
||||
oldresentry.GraphicsFlags = resentry.GraphicsFlags;
|
||||
resentry.Name = oldresentry.Name;
|
||||
resentry.NameHash = oldresentry.NameHash;
|
||||
resentry.NameLower = oldresentry.NameLower;
|
||||
resentry.ShortNameHash = oldresentry.ShortNameHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
RpfFileEntry = resentry; //just stick it in there for later...
|
||||
}
|
||||
|
||||
data = ResourceBuilder.Decompress(data);
|
||||
|
||||
|
||||
Load(data, resentry);
|
||||
|
||||
//Loaded = true;
|
||||
}
|
||||
|
||||
|
||||
public void Load(byte[] data, RpfFileEntry entry)
|
||||
{
|
||||
|
@ -63,60 +63,12 @@ namespace CodeWalker.GameFiles
|
||||
{
|
||||
//direct load from a raw, compressed ynd file (openIV-compatible format)
|
||||
|
||||
RpfResourceFileEntry resentry = new RpfResourceFileEntry();
|
||||
|
||||
//hopefully this format has an RSC7 header...
|
||||
uint rsc7 = BitConverter.ToUInt32(data, 0);
|
||||
if (rsc7 == 0x37435352) //RSC7 header present!
|
||||
{
|
||||
int version = BitConverter.ToInt32(data, 4);
|
||||
resentry.SystemFlags = BitConverter.ToUInt32(data, 8);
|
||||
resentry.GraphicsFlags = BitConverter.ToUInt32(data, 12);
|
||||
if (data.Length > 16)
|
||||
{
|
||||
int newlen = data.Length - 16; //trim the header from the data passed to the next step.
|
||||
byte[] newdata = new byte[newlen];
|
||||
Buffer.BlockCopy(data, 16, newdata, 0, newlen);
|
||||
data = newdata;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = null; //shouldn't happen... empty..
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//direct load from file without the rpf header..
|
||||
//assume it's in resource meta format
|
||||
resentry.SystemFlags = RpfResourceFileEntry.GetFlagsFromSize(data.Length, 0);
|
||||
resentry.GraphicsFlags = RpfResourceFileEntry.GetFlagsFromSize(0, 2); //graphics type 2 for ymap
|
||||
}
|
||||
|
||||
var oldresentry = RpfFileEntry as RpfResourceFileEntry;
|
||||
if (oldresentry != null) //update the existing entry with the new one
|
||||
{
|
||||
oldresentry.SystemFlags = resentry.SystemFlags;
|
||||
oldresentry.GraphicsFlags = resentry.GraphicsFlags;
|
||||
resentry.Name = oldresentry.Name;
|
||||
resentry.NameHash = oldresentry.NameHash;
|
||||
resentry.NameLower = oldresentry.NameLower;
|
||||
resentry.ShortNameHash = oldresentry.ShortNameHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
RpfFileEntry = resentry; //just stick it in there for later...
|
||||
}
|
||||
|
||||
data = ResourceBuilder.Decompress(data);
|
||||
|
||||
|
||||
Load(data, resentry);
|
||||
RpfFile.LoadResourceFile(this, data, 2);
|
||||
|
||||
Loaded = true;
|
||||
LoadQueued = true;
|
||||
}
|
||||
|
||||
|
||||
public void Load(byte[] data, RpfFileEntry entry)
|
||||
{
|
||||
Name = entry.Name;
|
||||
|
@ -9,12 +9,9 @@ using System.Threading.Tasks;
|
||||
namespace CodeWalker.GameFiles
|
||||
{
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
public class YtypFile : PackedFile
|
||||
public class YtypFile : GameFile, PackedFile
|
||||
{
|
||||
|
||||
public RpfFileEntry RpfFileEntry { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public Meta Meta { get; set; }
|
||||
public PsoFile Pso { get; set; }
|
||||
@ -40,11 +37,29 @@ namespace CodeWalker.GameFiles
|
||||
|
||||
|
||||
|
||||
public YtypFile() : base(null, GameFileType.Ytyp)
|
||||
{
|
||||
}
|
||||
public YtypFile(RpfFileEntry entry) : base(entry, GameFileType.Ytyp)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (RpfFileEntry != null) ? RpfFileEntry.Name : string.Empty;
|
||||
}
|
||||
|
||||
|
||||
public void Load(byte[] data)
|
||||
{
|
||||
//direct load from a raw, compressed ytyp file (openIV-compatible format)
|
||||
|
||||
RpfFile.LoadResourceFile(this, data, 2);
|
||||
|
||||
Loaded = true;
|
||||
}
|
||||
|
||||
public void Load(byte[] data, RpfFileEntry entry)
|
||||
{
|
||||
Name = entry.Name;
|
||||
@ -226,61 +241,7 @@ namespace CodeWalker.GameFiles
|
||||
|
||||
}
|
||||
|
||||
public void Load(byte[] data) //REFACTOR THIS WITH YMAP!!
|
||||
{
|
||||
//direct load from a raw, compressed ymap file (openIV-compatible format)
|
||||
|
||||
RpfResourceFileEntry resentry = new RpfResourceFileEntry();
|
||||
|
||||
//hopefully this format has an RSC7 header...
|
||||
uint rsc7 = BitConverter.ToUInt32(data, 0);
|
||||
if (rsc7 == 0x37435352) //RSC7 header present!
|
||||
{
|
||||
int version = BitConverter.ToInt32(data, 4);
|
||||
resentry.SystemFlags = BitConverter.ToUInt32(data, 8);
|
||||
resentry.GraphicsFlags = BitConverter.ToUInt32(data, 12);
|
||||
if (data.Length > 16)
|
||||
{
|
||||
int newlen = data.Length - 16; //trim the header from the data passed to the next step.
|
||||
byte[] newdata = new byte[newlen];
|
||||
Buffer.BlockCopy(data, 16, newdata, 0, newlen);
|
||||
data = newdata;
|
||||
}
|
||||
else
|
||||
{
|
||||
data = null; //shouldn't happen... empty..
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//direct load from file without the rpf header..
|
||||
//assume it's in resource meta format
|
||||
resentry.SystemFlags = RpfResourceFileEntry.GetFlagsFromSize(data.Length, 0);
|
||||
resentry.GraphicsFlags = RpfResourceFileEntry.GetFlagsFromSize(0, 2); //graphics type 2 for ymap
|
||||
}
|
||||
|
||||
var oldresentry = RpfFileEntry as RpfResourceFileEntry;
|
||||
if (oldresentry != null) //update the existing entry with the new one
|
||||
{
|
||||
oldresentry.SystemFlags = resentry.SystemFlags;
|
||||
oldresentry.GraphicsFlags = resentry.GraphicsFlags;
|
||||
resentry.Name = oldresentry.Name;
|
||||
resentry.NameHash = oldresentry.NameHash;
|
||||
resentry.NameLower = oldresentry.NameLower;
|
||||
resentry.ShortNameHash = oldresentry.ShortNameHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
RpfFileEntry = resentry; //just stick it in there for later...
|
||||
}
|
||||
|
||||
data = ResourceBuilder.Decompress(data);
|
||||
|
||||
|
||||
Load(data, resentry);
|
||||
|
||||
//Loaded = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -610,17 +610,20 @@ namespace CodeWalker.GameFiles
|
||||
{
|
||||
if (entry == null)
|
||||
{
|
||||
entry = CreateResourceFileEntry(data, 0);
|
||||
entry = CreateResourceFileEntry(ref data, 0);
|
||||
}
|
||||
file = new T();
|
||||
file.Load(data, entry);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static T GetResourceFile<T>(byte[] data) where T : class, PackedFile, new()
|
||||
{
|
||||
T file = null;
|
||||
RpfFileEntry entry = CreateResourceFileEntry(data, 0);
|
||||
RpfFileEntry entry = CreateResourceFileEntry(ref data, 0);
|
||||
if ((data != null) && (entry != null))
|
||||
{
|
||||
file = new T();
|
||||
@ -628,27 +631,55 @@ namespace CodeWalker.GameFiles
|
||||
}
|
||||
return file;
|
||||
}
|
||||
public static void LoadResourceFile<T>(T file, byte[] data, uint ver) where T : class, PackedFile
|
||||
{
|
||||
//direct load from a raw, compressed resource file (openIV-compatible format)
|
||||
|
||||
RpfResourceFileEntry resentry = CreateResourceFileEntry(ref data, ver);
|
||||
|
||||
if (file is GameFile)
|
||||
{
|
||||
GameFile gfile = file as GameFile;
|
||||
|
||||
public static RpfResourceFileEntry CreateResourceFileEntry(byte[] data, uint ver)
|
||||
var oldresentry = gfile.RpfFileEntry as RpfResourceFileEntry;
|
||||
if (oldresentry != null) //update the existing entry with the new one
|
||||
{
|
||||
oldresentry.SystemFlags = resentry.SystemFlags;
|
||||
oldresentry.GraphicsFlags = resentry.GraphicsFlags;
|
||||
resentry.Name = oldresentry.Name;
|
||||
resentry.NameHash = oldresentry.NameHash;
|
||||
resentry.NameLower = oldresentry.NameLower;
|
||||
resentry.ShortNameHash = oldresentry.ShortNameHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
gfile.RpfFileEntry = resentry; //just stick it in there for later...
|
||||
}
|
||||
}
|
||||
|
||||
data = ResourceBuilder.Decompress(data);
|
||||
|
||||
file.Load(data, resentry);
|
||||
|
||||
}
|
||||
public static RpfResourceFileEntry CreateResourceFileEntry(ref byte[] data, uint ver)
|
||||
{
|
||||
var resentry = new RpfResourceFileEntry();
|
||||
|
||||
//hopefully this format has an RSC7 header...
|
||||
//hopefully this data has an RSC7 header...
|
||||
uint rsc7 = BitConverter.ToUInt32(data, 0);
|
||||
if (rsc7 == 0x37435352) //RSC7 header present!
|
||||
{
|
||||
int version = BitConverter.ToInt32(data, 4);//use this instead of what was given...
|
||||
resentry.SystemFlags = BitConverter.ToUInt32(data, 8);
|
||||
resentry.GraphicsFlags = BitConverter.ToUInt32(data, 12);
|
||||
//if (data.Length > 16)
|
||||
//{
|
||||
// int newlen = data.Length - 16; //trim the header from the data passed to the next step.
|
||||
// byte[] newdata = new byte[newlen];
|
||||
// Buffer.BlockCopy(data, 16, newdata, 0, newlen);
|
||||
// data = newdata;
|
||||
//}
|
||||
if (data.Length > 16)
|
||||
{
|
||||
int newlen = data.Length - 16; //trim the header from the data passed to the next step.
|
||||
byte[] newdata = new byte[newlen];
|
||||
Buffer.BlockCopy(data, 16, newdata, 0, newlen);
|
||||
data = newdata;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// data = null; //shouldn't happen... empty..
|
||||
@ -659,7 +690,7 @@ namespace CodeWalker.GameFiles
|
||||
//direct load from file without the rpf header..
|
||||
//assume it's in resource meta format
|
||||
resentry.SystemFlags = RpfResourceFileEntry.GetFlagsFromSize(data.Length, 0);
|
||||
resentry.GraphicsFlags = RpfResourceFileEntry.GetFlagsFromSize(0, ver); //graphics type 2 for ymap
|
||||
resentry.GraphicsFlags = RpfResourceFileEntry.GetFlagsFromSize(0, ver);
|
||||
}
|
||||
|
||||
resentry.Name = "";
|
||||
|
@ -4220,7 +4220,7 @@ namespace CodeWalker.Project
|
||||
{
|
||||
byte[] data = File.ReadAllBytes(filename);
|
||||
|
||||
ymt.LoadRSC(data);
|
||||
ymt.Load(data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3775,7 +3775,7 @@ namespace CodeWalker
|
||||
{
|
||||
byte[] data = File.ReadAllBytes(filename);
|
||||
|
||||
ymt.LoadRSC(data);
|
||||
ymt.Load(data);
|
||||
}
|
||||
|
||||
private void LoadScenarioTreeNodes(YmtFile ymt, TreeNode node)
|
||||
|
Loading…
Reference in New Issue
Block a user