Fix LM3 dictionaries if in an archive and also fix model exporting materials.
This commit is contained in:
parent
317e4f7367
commit
c3b1dd845a
@ -546,34 +546,56 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
|
||||
{
|
||||
byte[] Data = new byte[DecompressedSize];
|
||||
|
||||
string DataFile = ParentDictionary.FileName.Replace(".dict", ".data");
|
||||
|
||||
string FolderPath = System.IO.Path.GetDirectoryName(ParentDictionary.FilePath);
|
||||
string DataFile = System.IO.Path.Combine(FolderPath, $"{ParentDictionary.FileName.Replace(".dict", ".data")}");
|
||||
string DataPath = System.IO.Path.Combine(FolderPath, $"{DataFile}");
|
||||
|
||||
if (System.IO.File.Exists(DataFile))
|
||||
{
|
||||
using (var reader = new FileReader(DataFile))
|
||||
using (var reader = new FileReader(DataPath)) {
|
||||
return ReadDataFile(reader);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ParentDictionary.IFileInfo.ArchiveParent != null)
|
||||
{
|
||||
reader.SeekBegin(Offset);
|
||||
if (ParentDictionary.IsCompressed)
|
||||
{
|
||||
ushort Magic = reader.ReadUInt16();
|
||||
reader.SeekBegin(Offset);
|
||||
|
||||
Data = reader.ReadBytes((int)CompressedSize);
|
||||
if (Magic == 0x9C78 || Magic == 0xDA78)
|
||||
return STLibraryCompression.ZLIB.Decompress(Data);
|
||||
else //Unknown compression
|
||||
return Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return reader.ReadBytes((int)DecompressedSize);
|
||||
}
|
||||
foreach (var file in ParentDictionary.IFileInfo.ArchiveParent.Files)
|
||||
if (file.FileName == DataFile)
|
||||
{
|
||||
using (var reader = new FileReader(file.FileData))
|
||||
{
|
||||
return ReadDataFile(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Data;
|
||||
}
|
||||
|
||||
private byte[] ReadDataFile(FileReader reader)
|
||||
{
|
||||
byte[] Data;
|
||||
|
||||
reader.SeekBegin(Offset);
|
||||
if (ParentDictionary.IsCompressed)
|
||||
{
|
||||
ushort Magic = reader.ReadUInt16();
|
||||
reader.SeekBegin(Offset);
|
||||
|
||||
Data = reader.ReadBytes((int)CompressedSize);
|
||||
if (Magic == 0x9C78 || Magic == 0xDA78)
|
||||
return STLibraryCompression.ZLIB.Decompress(Data);
|
||||
else //Unknown compression
|
||||
return Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return reader.ReadBytes((int)DecompressedSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,12 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
|
||||
private void ExportModel(string FileName)
|
||||
{
|
||||
var model = new STGenericModel();
|
||||
model.Materials = new List<STGenericMaterial>();
|
||||
List<STGenericMaterial> Materials = new List<STGenericMaterial>();
|
||||
foreach (STGenericObject mesh in DataDictionary.Renderer.Meshes)
|
||||
if (mesh.GetMaterial() != null)
|
||||
Materials.Add(mesh.GetMaterial());
|
||||
|
||||
model.Materials = Materials;
|
||||
model.Objects = DataDictionary.Renderer.Meshes;
|
||||
|
||||
ExportModelSettings settings = new ExportModelSettings();
|
||||
@ -124,8 +129,9 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
|
||||
public void ExportModel(string fileName, DAE.ExportSettings settings)
|
||||
{
|
||||
List<STGenericMaterial> Materials = new List<STGenericMaterial>();
|
||||
foreach (STGenericMaterial mat in Nodes[0].Nodes)
|
||||
Materials.Add(mat);
|
||||
foreach (STGenericObject mesh in RenderedMeshes)
|
||||
if (mesh.GetMaterial() != null)
|
||||
Materials.Add(mesh.GetMaterial());
|
||||
|
||||
var model = new STGenericModel();
|
||||
model.Materials = Materials;
|
||||
|
@ -49,8 +49,9 @@ namespace FirstPlugin.LuigisMansion3
|
||||
public void ExportModel(string fileName, DAE.ExportSettings settings)
|
||||
{
|
||||
List<STGenericMaterial> Materials = new List<STGenericMaterial>();
|
||||
foreach (STGenericMaterial mat in Nodes[0].Nodes)
|
||||
Materials.Add(mat);
|
||||
foreach (STGenericObject mesh in DataDictionary.Renderer.Meshes)
|
||||
if (mesh.GetMaterial() != null)
|
||||
Materials.Add(mesh.GetMaterial());
|
||||
|
||||
var model = new STGenericModel();
|
||||
model.Materials = Materials;
|
||||
@ -165,8 +166,9 @@ namespace FirstPlugin.LuigisMansion3
|
||||
public void ExportModel(string fileName, DAE.ExportSettings settings)
|
||||
{
|
||||
List<STGenericMaterial> Materials = new List<STGenericMaterial>();
|
||||
foreach (STGenericMaterial mat in Nodes[0].Nodes)
|
||||
Materials.Add(mat);
|
||||
foreach (STGenericObject mesh in RenderedMeshes)
|
||||
if (mesh.GetMaterial() != null)
|
||||
Materials.Add(mesh.GetMaterial());
|
||||
|
||||
var model = new STGenericModel();
|
||||
model.Materials = Materials;
|
||||
|
Loading…
Reference in New Issue
Block a user