Skip to content

Commit

Permalink
old engine names
Browse files Browse the repository at this point in the history
also higher res old engine textures
  • Loading branch information
NefariousTechSupport committed Aug 4, 2022
1 parent 3f1fac8 commit 060510d
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 26 deletions.
22 changes: 20 additions & 2 deletions AssetExtractor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,34 @@ public static void Main(string[] args)
al.LoadTies();
foreach(KeyValuePair<ulong, CMoby> mobys in al.mobys)
{
string exportFilePath = $"mobys/{Path.ChangeExtension(mobys.Value.name, "obj")}";
string exportFilePath = $"{args[0]}/assets/mobys/{Path.ChangeExtension(mobys.Value.name, "obj")}";
Directory.CreateDirectory(Path.GetDirectoryName(exportFilePath));
Console.WriteLine(exportFilePath);
mobys.Value.ExportToObj(exportFilePath);
}
foreach(KeyValuePair<ulong, CTie> tie in al.ties)
{
string exportFilePath = $"ties/{Path.ChangeExtension(tie.Value.name, "obj")}";
string exportFilePath = $"{args[0]}/assets/ties/{Path.ChangeExtension(tie.Value.name, "obj")}";
Directory.CreateDirectory(Path.GetDirectoryName(exportFilePath));
Console.WriteLine(exportFilePath);
tie.Value.ExportToObj(exportFilePath);
}
foreach(KeyValuePair<uint, CTexture> texture in al.textures)
{
string textureName = texture.Value.name;
if(textureName == string.Empty)
{
textureName = $"Texture_{texture.Value.id}";
}
Console.WriteLine(textureName);
if(textureName[1] == ':')
{
textureName = textureName.Substring(3);
}
string exportFilePath = $"{args[0]}/assets/textures/{textureName}.dds";
Directory.CreateDirectory(Path.GetDirectoryName(exportFilePath));
texture.Value.ExportToDDS(File.Open(exportFilePath, FileMode.Create), false);
}
}
}
}
73 changes: 73 additions & 0 deletions LibLunacy/DebugFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace LibLunacy
{
public class DebugFile
{
IGFile file;

public DebugFile(IGFile file)
{
this.file = file;
}

public DebugInstanceName[] GetMobyInstanceNames()
{
IGFile.SectionHeader mobyinstNames = file.QuerySection(0x73C0);
file.sh.Seek(mobyinstNames.offset);
return FileUtils.ReadStructureArray<DebugInstanceName>(file.sh, mobyinstNames.count);
}
public DebugInstanceName[] GetTieInstanceNames()
{
IGFile.SectionHeader tieinstNames = file.QuerySection(0x72C0);
file.sh.Seek(tieinstNames.offset);
return FileUtils.ReadStructureArray<DebugInstanceName>(file.sh, tieinstNames.count);
}
public DebugAssetName GetMobyPrototypeName(uint i)
{
IGFile.SectionHeader mobyNames = file.QuerySection(0x9480);
file.sh.Seek(mobyNames.offset + i * 0x10);
return FileUtils.ReadStructure<DebugAssetName>(file.sh);
}
public DebugAssetName GetTiePrototypeName(uint i)
{
IGFile.SectionHeader tieNames = file.QuerySection(0x9280);
file.sh.Seek(tieNames.offset + i * 0x10);
return FileUtils.ReadStructure<DebugAssetName>(file.sh);
}
public DebugShaderName GetShaderName(uint i)
{
IGFile.SectionHeader shaderNames = file.QuerySection(0x5D00);
file.sh.Seek(shaderNames.offset + i * 0x30);
return FileUtils.ReadStructure<DebugShaderName>(file.sh);
}

[FileStructure(0x18)]
public struct DebugInstanceName
{
[FileOffset(0x00)] public ulong tuid1;
[FileOffset(0x08)] public ulong tuid2;
[FileOffset(0x10), Reference] public string name;
[FileOffset(0x14)] public uint unk;
}

[FileStructure(0x10)]
public struct DebugAssetName
{
[FileOffset(0x00)] public ulong tuid;
[FileOffset(0x08), Reference] public string name;
}
[FileStructure(0x30)]
public struct DebugShaderName
{
[FileOffset(0x00)] public ulong shaderTuid;
[FileOffset(0x08), Reference] public string shaderName;
[FileOffset(0x10)] public uint albedoTuid;
[FileOffset(0x14)] public uint normalTuid;
[FileOffset(0x18)] public uint expensiveTuid;
[FileOffset(0x1C)] public uint wthTuid;
[FileOffset(0x20), Reference] public string albedoName;
[FileOffset(0x24), Reference] public string normalName;
[FileOffset(0x28), Reference] public string expensiveName;
[FileOffset(0x2C), Reference] public string wthName;
}
}
}
9 changes: 9 additions & 0 deletions LibLunacy/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class FileManager
public Dictionary<string, IGFile?> igfiles = new Dictionary<string, IGFile?>(); //Actual IGFiles
public Dictionary<string, Stream?> rawfiles = new Dictionary<string, Stream?>(); //Raw data, includes files containing nothing but IGFiles

public DebugFile? debug = null;

public bool isOld { get; private set; } //if true, old filesystem, else new filesystem

public void LoadFolder(string folderPath)
Expand All @@ -22,9 +24,16 @@ public void LoadFolder(string folderPath)
LoadFile("main.dat", false);
LoadFile("vertices.dat", false);
LoadFile("gameplay.dat", false);
LoadFile("debug.dat", false);

//Load raw files
LoadFile("textures.dat", true);
LoadFile("texstream.dat", true);

if(igfiles["debug.dat"] != null)
{
debug = new DebugFile(igfiles["debug.dat"]);
}
}
else
{
Expand Down
31 changes: 25 additions & 6 deletions LibLunacy/Gameplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,23 @@ public CTieInstance(TieInstance instance, AssetLoader al, IGFile file)
public Zone(IGFile file, AssetLoader al)
{
IGFile.SectionHeader tieInstSection;
AssetLoader.AssetPointer[] names = null;
AssetLoader.AssetPointer[] newnames = null;
DebugFile.DebugInstanceName[] oldnames = null;

if(al.fm.isOld)
{
tieInstSection = file.QuerySection(0x9240);
if(al.fm.debug != null)
{
oldnames = al.fm.debug.GetTieInstanceNames();
}
}
else
{
IGFile.SectionHeader tieNameSection = file.QuerySection(0x72C0);
file.sh.Seek(tieNameSection.offset);
Console.WriteLine($"names @ {tieNameSection.offset}");
names = FileUtils.ReadStructureArray<AssetLoader.AssetPointer>(file.sh, tieNameSection.count);
newnames = FileUtils.ReadStructureArray<AssetLoader.AssetPointer>(file.sh, tieNameSection.count);

tieInstSection = file.QuerySection(0x7240);
}
Expand All @@ -146,11 +151,12 @@ public Zone(IGFile file, AssetLoader al)
tieInstances.Add((ulong)i, new CTieInstance(ties[i], al, file));
if(al.fm.isOld)
{
tieInstances.Last().Value.name = $"Tie_{i}";
if(al.fm.debug != null) tieInstances.Last().Value.name = oldnames[i].name;
else tieInstances.Last().Value.name = $"Tie_{i}";
}
else
{
tieInstances.Last().Value.name = file.sh.ReadString(names[i].offset);
tieInstances.Last().Value.name = file.sh.ReadString(newnames[i].offset);
}
}

Expand Down Expand Up @@ -276,10 +282,23 @@ public Region(IGFile file, AssetLoader al)
file.sh.Seek(mobyInstSections.offset);
OldMobyInstance[] mobys = FileUtils.ReadStructureArray<OldMobyInstance>(file.sh, mobyInstSections.count);

DebugFile.DebugInstanceName[] names = null;
if(al.fm.debug != null)
{
names = al.fm.debug.GetMobyInstanceNames();
}

for(int i = 0; i < mobys.Length; i++)
{
mobyInstances.Add((ulong)i, new CMobyInstance(mobys[i], al));
mobyInstances.Last().Value.name = $"Moby_{mobys[i].mobyIndex.ToString("X04")}_Instance_{i}";
if(names != null)
{
mobyInstances.Last().Value.name = names[i].name;
}
else
{
mobyInstances.Last().Value.name = $"Moby_{mobys[i].mobyIndex.ToString("X04")}_Instance_{i}";
}
}
}
public Region(AssetLoader al, string regionName)
Expand All @@ -295,7 +314,7 @@ public Region(AssetLoader al, string regionName)
IGFile.SectionHeader mobyNamesSection = prius.QuerySection(0x2504C);
prius.sh.Seek(mobyNamesSection.offset);
NewInstance[] names = FileUtils.ReadStructureArray<NewInstance>(prius.sh, mobyInstSection.count);

for(int i = 0; i < mobys.Length; i++)
{
mobyInstances.Add(names[i].tuid, new CMobyInstance(mobys[i], names[i], al, region));
Expand Down
7 changes: 3 additions & 4 deletions LibLunacy/Moby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public CMoby(IGFile file, AssetLoader al, uint index = 0)
OldMoby omoby = FileUtils.ReadStructure<OldMoby>(file.sh);

bangles = omoby.bangles;
name = $"Moby_{index.ToString("X04")}";
scale = omoby.scale;
boundingSpherePosition = omoby.boundingSpherePosition;
boundingSphereRadius = omoby.boundingSphereRotation;
Expand Down Expand Up @@ -165,6 +164,9 @@ public CMoby(IGFile file, AssetLoader al, uint index = 0)
indexStream = new StreamHelper(indexms, file.sh._endianness);

id = index;

if(al.fm.debug != null) name = al.fm.debug.GetMobyPrototypeName(index).name;
else name = $"Moby_{index.ToString("X04")}";
}

LoadDependancies(al);
Expand Down Expand Up @@ -243,12 +245,9 @@ public void ExportToObj(string filePath)
obj.Append($"mtllib unused.mtl\n");
for(int i = 0; i < bangles.Length; i++)
{
Console.WriteLine($"Bangle {i+1}/{bangles.Length}");
obj.Append($"o Bangle_{i}\n");
for(int j = 0; j < bangles[i].count; j++)
{
Console.WriteLine($"Submesh {j+1}/{bangles[i].count}");

GetBuffers(bangles[i].meshes[j], out uint[] indices, out float[] vPositions, out float[] vTexCoords);

for(int k = 0; k < bangles[i].meshes[j].vertexCount; k++)
Expand Down
55 changes: 49 additions & 6 deletions LibLunacy/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public struct NewReferences
[FileOffset(0x10)] public uint albedoTuid;
[FileOffset(0x14)] public uint normalTuid;
[FileOffset(0x18)] public uint expensiveTuid;
[FileOffset(0x28), Reference] public string albedoName;
[FileOffset(0x2C), Reference] public string normalName;
[FileOffset(0x30), Reference] public string expensiveName;

public uint TextureCount => 3;
}
Expand All @@ -46,9 +49,37 @@ public CShader(IGFile file, AssetLoader al, uint index = 0)
{
OldShader oshader = FileUtils.ReadStructure<OldShader>(file.sh);

if(oshader.albedoOffset != 0) albedo = al.textures[oshader.albedoOffset];
if(oshader.normalOffset != 0) normal = al.textures[oshader.normalOffset];
if(oshader.expensiveOffset != 0) expensive = al.textures[oshader.expensiveOffset];
DebugFile.DebugShaderName name = new DebugFile.DebugShaderName();

if(al.fm.debug != null)
{
name = al.fm.debug.GetShaderName(index);
}

if(oshader.albedoOffset != 0)
{
albedo = al.textures[oshader.albedoOffset];
if(al.fm.debug != null)
{
albedo.name = name.albedoName;
}
}
if(oshader.normalOffset != 0)
{
normal = al.textures[oshader.normalOffset];
if(al.fm.debug != null)
{
normal.name = name.normalName;
}
}
if(oshader.expensiveOffset != 0)
{
expensive = al.textures[oshader.expensiveOffset];
if(al.fm.debug != null)
{
expensive.name = name.expensiveName;
}
}
}
else
{
Expand All @@ -58,9 +89,21 @@ public CShader(IGFile file, AssetLoader al, uint index = 0)
file.sh.Seek(refSection.offset, SeekOrigin.Begin);
NewReferences refs = FileUtils.ReadStructure<NewReferences>(file.sh);

if(refs.albedoTuid != 0 && al.textures.ContainsKey(refs.albedoTuid)) albedo = al.textures[refs.albedoTuid];
if(refs.normalTuid != 0 && al.textures.ContainsKey(refs.normalTuid)) normal = al.textures[refs.normalTuid];
if(refs.expensiveTuid != 0 && al.textures.ContainsKey(refs.expensiveTuid)) expensive = al.textures[refs.expensiveTuid];
if(refs.albedoTuid != 0 && al.textures.ContainsKey(refs.albedoTuid))
{
albedo = al.textures[refs.albedoTuid];
albedo.name = refs.albedoName;
}
if(refs.normalTuid != 0 && al.textures.ContainsKey(refs.normalTuid))
{
normal = al.textures[refs.normalTuid];
normal.name = refs.normalName;
}
if(refs.expensiveTuid != 0 && al.textures.ContainsKey(refs.expensiveTuid))
{
expensive = al.textures[refs.expensiveTuid];
expensive.name = refs.expensiveName;
}
}
}
}
Expand Down
Loading

0 comments on commit 060510d

Please sign in to comment.