1
0
mirror of synced 2025-01-19 01:14:08 +01:00

Automatically open ctex files for narc if a bfres is opened. Fix aces texture mapping

This commit is contained in:
KillzXGaming 2020-04-14 16:31:36 -04:00
parent 33ae4c5635
commit 134b8e295c
3 changed files with 79 additions and 13 deletions

View File

@ -135,7 +135,7 @@ namespace FirstPlugin
public bool AddFile(ArchiveFileInfo archiveFileInfo) public bool AddFile(ArchiveFileInfo archiveFileInfo)
{ {
FileEntry file = new FileEntry(); FileEntry file = new FileEntry(this);
file.FileName = archiveFileInfo.FileName; file.FileName = archiveFileInfo.FileName;
file.CreateEntry(archiveFileInfo.FileData, true); file.CreateEntry(archiveFileInfo.FileData, true);
files.Add(file); files.Add(file);
@ -203,9 +203,31 @@ namespace FirstPlugin
} }
public class FileEntry : ArchiveFileInfo public class FileEntry : ArchiveFileInfo
{ {
public FileEntry() BEA ArchiveFile;
public FileEntry(BEA bea)
{ {
ArchiveFile = bea;
}
private bool IsTexturesLoaded = false;
public override IFileFormat OpenFile()
{
var FileFormat = base.OpenFile();
bool IsModel = FileFormat is BFRES;
if (IsModel && !IsTexturesLoaded)
{
IsTexturesLoaded = true;
foreach (var file in ArchiveFile.Files)
{
if (Utils.GetExtension(file.FileName) == ".ftxb")
{
file.FileFormat = file.OpenFile();
}
}
}
return base.OpenFile();
} }
public ushort unk1; public ushort unk1;
@ -281,7 +303,7 @@ namespace FirstPlugin
public FileEntry SetupFileEntry(ASST asset) public FileEntry SetupFileEntry(ASST asset)
{ {
FileEntry fileEntry = new FileEntry(); FileEntry fileEntry = new FileEntry(this);
fileEntry.FileName = asset.FileName; fileEntry.FileName = asset.FileName;
fileEntry.unk1 = asset.unk; fileEntry.unk1 = asset.unk;
fileEntry.unk2 = asset.unk2; fileEntry.unk2 = asset.unk2;

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
using Toolbox.Library; using Toolbox.Library;
using Toolbox.Library.IO; using Toolbox.Library.IO;
using Toolbox.Library.Forms; using Toolbox.Library.Forms;
using System.Windows.Forms; using System.Windows.Forms;
namespace FirstPlugin namespace FirstPlugin
{ {
@ -77,23 +77,45 @@ namespace FirstPlugin
} }
} }
public FileEntry(string Name) public NARC ArchiveFile;
public FileEntry(NARC narc, string Name)
{ {
ArchiveFile = narc;
FileName = Name.Replace(" ", string.Empty).RemoveIllegaleFolderNameCharacters(); FileName = Name.Replace(" ", string.Empty).RemoveIllegaleFolderNameCharacters();
} }
public override byte[] FileData public override byte[] FileData
{ {
get get { return DecompressBlock(); }
{
return DecompressBlock();
}
set set
{ {
} }
} }
private bool IsTexturesLoaded = false;
public override IFileFormat OpenFile()
{
var FileFormat = base.OpenFile();
bool IsModel = FileFormat is BFRES;
if (IsModel && !IsTexturesLoaded)
{
IsTexturesLoaded = true;
foreach (var file in ArchiveFile.Files)
{
if (Utils.GetExtension(file.FileName) == ".cbntx")
{
Console.WriteLine($"Opening cbntx {file.FileName}");
file.FileFormat = file.OpenFile();
}
}
}
return base.OpenFile();
}
private byte[] DecompressBlock() private byte[] DecompressBlock()
{ {
byte[] data = GetBlock(); byte[] data = GetBlock();
@ -128,7 +150,7 @@ namespace FirstPlugin
if (IsGZIP) if (IsGZIP)
data = STLibraryCompression.GZIP.Decompress(filedata); data = STLibraryCompression.GZIP.Decompress(filedata);
else else
data = STLibraryCompression.ZLIB.Decompress(filedata, false); data = STLibraryCompression.ZLIB.Decompress(filedata, false);
} }
@ -153,7 +175,7 @@ namespace FirstPlugin
List<byte> Data = new List<byte>(); List<byte> Data = new List<byte>();
for (ushort i = 0; i < header.FATB.FileCount; i++) for (ushort i = 0; i < header.FATB.FileCount; i++)
{ {
FileEntries.Add(new FileEntry(names[i]) FileEntries.Add(new FileEntry(this, names[i])
{ {
entry = header.FATB.FileEntries[i], entry = header.FATB.FileEntries[i],
fileImage = header.FIMG, fileImage = header.FIMG,
@ -183,7 +205,6 @@ namespace FirstPlugin
//EFE for REing format https://github.com/Gericom/EveryFileExplorer/blob/f9f00d193c9608d71c9a23d9f3ab7e752f4ada2a/NDS/NitroSystem/FND/NARC.cs //EFE for REing format https://github.com/Gericom/EveryFileExplorer/blob/f9f00d193c9608d71c9a23d9f3ab7e752f4ada2a/NDS/NitroSystem/FND/NARC.cs
public class Header public class Header
{ {
public string Signature; public string Signature;
@ -278,7 +299,7 @@ namespace FirstPlugin
Size = reader.ReadUInt32(); Size = reader.ReadUInt32();
dataBlock = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); dataBlock = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position));
} }
} }
public class FileNameTable public class FileNameTable
{ {
public string Signature; public string Signature;

View File

@ -792,6 +792,29 @@ namespace FirstPlugin
texture.Type = MatTexture.TextureType.Shadow; texture.Type = MatTexture.TextureType.Shadow;
} }
} }
else if (mat.ShaderAssign.ShaderArchiveName == "ssg")
{
bool IsAlbedo0 = texture.SamplerName == "_a0";
bool IsNormal = texture.SamplerName == "_n0";
bool IsEmissive = texture.SamplerName == "_e0";
bool IsSpecular = texture.SamplerName == "_s0";
if (IsAlbedo0)
{
m.HasDiffuseMap = true;
texture.Type = MatTexture.TextureType.Diffuse;
}
if (IsNormal)
{
m.HasNormalMap = true;
texture.Type = MatTexture.TextureType.Normal;
}
if (IsSpecular)
{
m.HasSpecularMap = true;
texture.Type = MatTexture.TextureType.Specular;
}
}
else if (Runtime.activeGame == Runtime.ActiveGame.Bezel) else if (Runtime.activeGame == Runtime.ActiveGame.Bezel)
{ {
bool IsAlbedo0 = useSampler == "_a0"; bool IsAlbedo0 = useSampler == "_a0";