Skip to content

Commit

Permalink
Fix handling of paths modified by penumbra
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveModding committed Jul 12, 2024
1 parent f189429 commit 50ef65f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Meddle/Meddle.Plugin/Utils/ParseUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public unsafe MaterialResourceHandle.ColorTableRow[] ParseColorTableTexture(Text
if (model == null) return null;

var mdlFileName = model->ModelResourceHandle->ResourceHandle.FileName.ToString();
var mdlFileResource = pack.GetFile(mdlFileName);
var mdlFileResource = pack.GetFileOrReadFromDisk(mdlFileName);
if (mdlFileResource == null)
{
return null;
Expand All @@ -101,7 +101,7 @@ public unsafe MaterialResourceHandle.ColorTableRow[] ParseColorTableTexture(Text
var shapeAttributeGroup =
new Model.ShapeAttributeGroup(shapesMask, attributeMask, shapes.ToArray(), attributes.ToArray());

var mdlFile = new MdlFile(mdlFileResource.Value.file.RawData);
var mdlFile = new MdlFile(mdlFileResource);
var mtrlGroups = new List<Material.MtrlGroup>();
for (var j = 0; j < model->MaterialsSpan.Length; j++)
{
Expand All @@ -115,13 +115,13 @@ public unsafe MaterialResourceHandle.ColorTableRow[] ParseColorTableTexture(Text
var mtrlFileName = material->MaterialResourceHandle->ResourceHandle.FileName.ToString();
var shader = material->MaterialResourceHandle->ShpkNameString;

var mtrlFileResource = pack.GetFile(mtrlFileName);
var mtrlFileResource = pack.GetFileOrReadFromDisk(mtrlFileName);
if (mtrlFileResource == null)
{
continue;
}

var mtrlFile = new MtrlFile(mtrlFileResource.Value.file.RawData);
var mtrlFile = new MtrlFile(mtrlFileResource);
var colorTable = material->MaterialResourceHandle->ColorTableSpan;
if (colorTable.Length == 32)
{
Expand Down Expand Up @@ -151,13 +151,13 @@ public unsafe MaterialResourceHandle.ColorTableRow[] ParseColorTableTexture(Text
var textureNames = mtrlFile.GetTexturePaths().Select(x => x.Value).ToArray();
foreach (var textureName in textureNames)
{
var texFileResource = pack.GetFile(textureName);
var texFileResource = pack.GetFileOrReadFromDisk(textureName);
if (texFileResource == null)
{
continue;
}

var texFile = new TexFile(texFileResource.Value.file.RawData);
var texFile = new TexFile(texFileResource);
texGroups.Add(new Meddle.Utils.Export.Texture.TexGroup(textureName, texFile));
}

Expand Down Expand Up @@ -200,14 +200,14 @@ private unsafe List<HavokXml> ParseSkeletons(Human* human)
continue;
}

var skeletonFileResource =
pack.GetFile(skeletonResourceHandle->ResourceHandle.FileName.ToString());
var fileName = skeletonResourceHandle->ResourceHandle.FileName.ToString();
var skeletonFileResource = pack.GetFileOrReadFromDisk(fileName);
if (skeletonFileResource == null)
{
continue;
}

var sklbFile = new SklbFile(skeletonFileResource.Value.file.RawData);
var sklbFile = new SklbFile(skeletonFileResource);
var tempFile = Path.GetTempFileName();
try
{
Expand Down
25 changes: 25 additions & 0 deletions Meddle/Meddle.Plugin/Utils/PathUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Meddle.Utils.Files.SqPack;

namespace Meddle.Plugin.Utils;

public static class PathUtil
{
public static byte[]? GetFileOrReadFromDisk(this SqPack pack, string path)
{
// if path is in format |...|path/to/file, trim the |...| part
if (path[0] == '|')
{
path = path.Substring(path.IndexOf('|', 1) + 1);
}

// if path is rooted, get from disk
if (Path.IsPathRooted(path))
{
var data = File.ReadAllBytes(path);
return data;
}

var file = pack.GetFile(path);
return file?.file.RawData.ToArray();
}
}

0 comments on commit 50ef65f

Please sign in to comment.