Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
Support latest BEA, multiple UVs for bfres, bounding box/shadow fixes…
Browse files Browse the repository at this point in the history
…, and more
  • Loading branch information
KillzXGaming committed Oct 18, 2024
1 parent 44a88b4 commit bdec926
Show file tree
Hide file tree
Showing 16 changed files with 1,634 additions and 65 deletions.
22 changes: 22 additions & 0 deletions File_Format_Library/FileFormats/Archives/BEA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ public void Save(System.IO.Stream stream)
asset.FileName = node.FileName;
asset.FileData = node.CompressedData;
asset.UncompressedSize = node.FileData.Length;
asset.FileID1 = node.FileID1;
asset.FileID2 = node.FileID2;
asset.FileHash = node.FileHash;
asset.Unknown3 = node.Unknown3;
asset.FileType = node.FileType;

beaFile.FileList.Add(asset.FileName, asset);
beaFile.FileDictionary.Add(asset.FileName);
}
Expand All @@ -204,6 +210,9 @@ public FolderEntry(string Name)
public class FileEntry : ArchiveFileInfo
{
BEA ArchiveFile;



public FileEntry(BEA bea)
{
ArchiveFile = bea;
Expand Down Expand Up @@ -233,6 +242,11 @@ public override IFileFormat OpenFile()
public ushort unk1;
public ushort unk2;
public bool IsCompressed;
public ulong FileID1;
public ulong FileID2;
public uint FileHash;
public string FileType = "";
public uint Unknown3;

public override byte[] FileData
{
Expand All @@ -248,6 +262,8 @@ public void CreateEntry(byte[] data, bool compress)
unk1 = 2;
unk2 = 12;
FileData = data;
FileID1 = (ulong)new Random().Next(0, int.MaxValue);
FileID2 = (ulong)new Random().Next(0, int.MaxValue);
}

public override Dictionary<string, string> ExtensionImageKeyLookup
Expand Down Expand Up @@ -309,6 +325,12 @@ public FileEntry SetupFileEntry(ASST asset)
fileEntry.unk2 = asset.unk2;
fileEntry.IsCompressed = asset.IsCompressed;
fileEntry.CompressedData = asset.FileData;
fileEntry.Unknown3 = asset.Unknown3;
fileEntry.FileID1 = asset.FileID1;
fileEntry.FileID2 = asset.FileID2;
fileEntry.FileHash = asset.FileHash;
fileEntry.FileType = asset.FileType;

return fileEntry;
}
}
Expand Down
96 changes: 96 additions & 0 deletions File_Format_Library/FileFormats/Archives/BEA/ASST.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using Syroot.BinaryData;
using System.IO;
using System.Text;

namespace BezelEngineArchive_Lib
{
public class ASST : IFileData //File asset
{
private const string _signature = "ASST";

public ushort unk = 2;
public ushort unk2 = 12;
public string FileName;
public long UncompressedSize;
public bool IsCompressed = true;

public ulong FileID1;
public ulong FileID2;

public uint FileHash;
public uint Unknown3;

public byte[] FileData;

public uint FileSize;
public long FileOffset;

public string FileType = "";

public BezelEngineArchive ParentArchive;

void IFileData.Load(FileLoader loader)
{
loader.CheckSignature(_signature);
loader.LoadBlockHeader();
unk = loader.ReadUInt16();
unk2 = loader.ReadUInt16();
FileSize = loader.ReadUInt32();
UncompressedSize = loader.ReadUInt32();

if (loader.Archive.VersionMajor2 >= 5)
{
FileType = Encoding.ASCII.GetString(loader.ReadBytes(8));
}

Unknown3 = loader.ReadUInt32();

if (loader.Archive.VersionMajor2 >= 6)
{
FileID1 = loader.ReadUInt64();
FileID2 = loader.ReadUInt64();
}

FileOffset = loader.ReadInt64();
FileName = loader.LoadString();

using (loader.TemporarySeek(FileOffset, SeekOrigin.Begin)) {
FileData = loader.ReadBytes((int)FileSize);
}

if (UncompressedSize == FileSize)
IsCompressed = false;
}
void IFileData.Save(FileSaver saver)
{
saver.WriteSignature(_signature);
saver.SaveBlockHeader();
saver.Write(unk);
saver.Write(unk2);
saver.Write((uint)FileData.Length);
saver.Write((uint)UncompressedSize);

if (saver.Archive.VersionMajor2 >= 5)
{
if (FileType.Length > 8)
throw new Exception($"Invalid file type length! Must be equal or less than 12 bytes! {FileType}!");

saver.Write(Encoding.ASCII.GetBytes(FileType));
saver.Write(new byte[8 - FileType.Length]);
}

saver.Write(Unknown3);

if (saver.Archive.VersionMajor2 >= 6)
{
saver.Write(FileID1);
saver.Write(FileID2);
}

saver.SaveBlock(FileData, (uint)saver.Archive.RawAlignment, () => saver.Write(FileData));
saver.SaveRelocateEntryToSection(saver.Position, 1, 1, 0, 1, "Asst File Name Offset");
saver.SaveString(FileName);
}
}
}
182 changes: 182 additions & 0 deletions File_Format_Library/FileFormats/Archives/BEA/BevelEngineArchive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using Syroot.BinaryData;
using System.IO;

namespace BezelEngineArchive_Lib
{
public class BezelEngineArchive : IFileData
{
private const string _signature = "SCNE";

public BezelEngineArchive(Stream stream, bool leaveOpen = false)
{
using (FileLoader loader = new FileLoader(this, stream, leaveOpen))
{
loader.Execute();
}
}

public BezelEngineArchive(string fileName)
{
using (FileLoader loader = new FileLoader(this, fileName))
{
loader.Execute();
}
}

public ushort ByteOrder { get; private set; }
public uint VersionMajor { get; set; }
public uint VersionMajor2 { get; set; }
public uint VersionMinor { get; set; }
public uint VersionMinor2 { get; set; }
public uint Alignment { get; set; }
public uint TargetAddressSize { get; set; }
public string Name { get; set; }
public string CompressionName { get; set; }

public ResDict FileDictionary { get; set; } //Todo, Need to setup ResDict to grab indexes quicker
public Dictionary<string, ASST> FileList { get; set; } //Use a dictionary for now so i can look up files quickly

/// <summary>s
/// Gets or sets the alignment to use for raw data blocks in the file.
/// </summary>
public int RawAlignment { get; set; }

public List<string> ReferenceList = new List<string>();

public void Save(Stream stream, bool leaveOpen = false)
{
using (FileSaver saver = new FileSaver(this, stream, leaveOpen))
{
saver.Execute();
}
}

public void Save(string FileName)
{
using (FileSaver saver = new FileSaver(this, FileName))
{
saver.Execute();
}
}

internal uint SaveVersion()
{
return VersionMajor << 24 | VersionMajor2 << 16 | VersionMinor << 8 | VersionMinor2;
}

private void SetVersionInfo(uint Version)
{
VersionMajor = Version >> 24;
VersionMajor2 = Version >> 16 & 0xFF;
VersionMinor = Version >> 8 & 0xFF;
VersionMinor2 = Version & 0xFF;
}

internal Stream _stream;

void IFileData.Load(FileLoader loader)
{
_stream = loader.BaseStream;

loader.CheckSignature(_signature);
uint padding = loader.ReadUInt32();
uint Version = loader.ReadUInt32();
SetVersionInfo(Version);
ByteOrder = loader.ReadUInt16();
Alignment = (uint)loader.ReadByte();
TargetAddressSize = (uint)loader.ReadByte();
uint Padding = loader.ReadUInt32(); //Usually name offset for file with other switch formats
ushort Padding2 = loader.ReadUInt16();
ushort BlockOffset = loader.ReadUInt16(); //Goes to ASST section which seems to have block headers
uint RelocationTableOffset = loader.ReadUInt32();
uint DataOffset = loader.ReadUInt32(); //data or end of file offset
var FileCount = loader.ReadUInt32();
var RefCount = loader.ReadUInt32();

ulong FileInfoOffset = 0;

if (VersionMajor2 >= 5)
{
var AssetOffset = loader.ReadUInt64(); //asset offset
FileInfoOffset = loader.ReadUInt64();
FileDictionary = loader.LoadDict();
Name = loader.LoadString();
CompressionName = loader.LoadString();
ulong RefOffset = loader.ReadUInt64();

ReferenceList = loader.LoadCustom(() =>
{
List<string> list = new List<string>();
for (int i = 0; i < (int)RefCount; i++)
list.Add(loader.LoadString());
return list;

}, (long)RefOffset);
}
else
{
FileInfoOffset = loader.ReadUInt64();
FileDictionary = loader.LoadDict();
ulong unk = loader.ReadUInt64();
Name = loader.LoadString();
}

FileList = loader.LoadCustom(() =>
{
Dictionary<string, ASST> asstList = new Dictionary<string, ASST>();
for (int i = 0; i < (int)FileCount; i++)
{
var asset = loader.Load<ASST>();
asstList.Add(asset.FileName, asset);
}
return asstList;
}, (long)FileInfoOffset);
}
void IFileData.Save(FileSaver saver)
{
RawAlignment = (1 << (int)Alignment);

saver.WriteSignature(_signature);
saver.Write(0);
saver.Write(SaveVersion());
saver.Write(ByteOrder);
saver.Write((byte)Alignment);
saver.Write((byte)TargetAddressSize);
saver.Write(0);
saver.Write((ushort)0);
saver.SaveFirstBlock();
saver.SaveRelocationTablePointer();
saver.SaveFileSize();
saver.Write((uint)FileList.Count);
saver.Write(ReferenceList == null ? 0u : (uint)ReferenceList.Count);

if (VersionMajor2 >= 5)
{
saver.SaveAssetBlock();

saver.SaveRelocateEntryToSection(saver.Position, 1, 1, 0, 1, "Asst Offset Array");
saver.SaveFileAsstPointer();
saver.SaveRelocateEntryToSection(saver.Position, 1, 1, 0, 1, "DIC");
saver.SaveFileDictionaryPointer();
saver.SaveRelocateEntryToSection(saver.Position, 1, 1, 0, 1, "FileName");
saver.SaveString(Name);
saver.SaveRelocateEntryToSection(saver.Position, 1, 1, 0, 1, "CompressionName");
saver.SaveString(CompressionName);
saver.SaveRelocateEntryToSection(saver.Position, 1, 1, 0, 1, "Ref Offset");
saver.SaveAssetRefPointer();
}
else
{
saver.SaveRelocateEntryToSection(saver.Position, 1, 1, 0, 1, "Asst Offset Array");
saver.SaveFileAsstPointer();
saver.SaveRelocateEntryToSection(saver.Position, 1, 1, 0, 1, "DIC");
saver.SaveFileDictionaryPointer();
saver.Write(0L);
saver.SaveRelocateEntryToSection(saver.Position, 1, 1, 0, 1, "FileName");
saver.SaveString(Name);
}
}
}
}
Loading

0 comments on commit bdec926

Please sign in to comment.