Skip to content

Commit

Permalink
[MapleLib] fix '_outlink' directory for 64-bit wz directory format.
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Dec 12, 2022
1 parent 6413a64 commit dfffdbd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
8 changes: 8 additions & 0 deletions MapleLib/WzFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class WzFileManager : IDisposable
#endregion

#region Fields
public static WzFileManager fileManager; // static, to allow access from anywhere

private readonly string baseDir;
/// <summary>
/// Gets the base directory of the WZ file.
Expand Down Expand Up @@ -80,6 +82,8 @@ public WzFileManager()
{
this.baseDir = string.Empty;
this._bInitAs64Bit = false;

fileManager = this;
}

/// <summary>
Expand All @@ -91,6 +95,8 @@ public WzFileManager(string directory, bool _bInitAs64Bit)
{
this.baseDir = directory;
this._bInitAs64Bit = _bInitAs64Bit;

fileManager = this;
}
#endregion

Expand Down Expand Up @@ -532,6 +538,8 @@ public List<WzDirectory> GetWzDirectoriesFromBase(string baseName)
/// <returns></returns>
public WzObject FindWzImageByName(string baseWzName, string imageName)
{
baseWzName = baseWzName.ToLower();

List<WzDirectory> wzFiles = GetWzDirectoriesFromBase(baseWzName);
foreach (WzDirectory wzFile in wzFiles)
{
Expand Down
39 changes: 34 additions & 5 deletions MapleLib/WzLib/WzFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,11 @@ internal List<string> GetPathsFromProperty(WzImageProperty prop, string curPath)
public WzObject GetObjectFromPath(string path, bool checkFirstDirectoryName = true)
{
string[] seperatedPath = path.Split("/".ToCharArray());
if (seperatedPath.Length == 1)
return WzDirectory;

WzObject checkObjInOtherWzFile = null;

if (checkFirstDirectoryName)
{
if (seperatedPath[0].ToLower() != wzDir.name.ToLower() && seperatedPath[0].ToLower() != wzDir.name.Substring(0, wzDir.name.Length - 3).ToLower())
Expand All @@ -841,14 +845,39 @@ public WzObject GetObjectFromPath(string path, bool checkFirstDirectoryName = tr
// look up the list of other currently loaded WzFile/ WzDirectory
// Map/Tile/logMarble.img/bsc/1


return null;
// this is a fix for 64-bit wz file format where items are stored in many multiple WZ files

int nSubstractFolderCount = 0;
if (WzFileManager.fileManager != null)
{
if (seperatedPath.Length >= 1)
{
checkObjInOtherWzFile = WzFileManager.fileManager.FindWzImageByName(seperatedPath[0], seperatedPath[1]); // Map/xxx.img
nSubstractFolderCount = 1;

if (checkObjInOtherWzFile == null && seperatedPath.Length >= 2) // Map/Obj/xxx.img -> Obj.wz
{
checkObjInOtherWzFile = WzFileManager.fileManager.FindWzImageByName(seperatedPath[0] + Path.DirectorySeparatorChar + seperatedPath[1], seperatedPath[2]);
nSubstractFolderCount = 2;
}
else
return null;

seperatedPath = seperatedPath.Where((item, index) => index >= nSubstractFolderCount)
.Select(item => item)
.ToArray();
}
} else
return null;
}
}

if (seperatedPath.Length == 1)
return WzDirectory;
WzObject curObj = WzDirectory;
WzObject curObj;
if (checkObjInOtherWzFile != null)
curObj = checkObjInOtherWzFile;
else
curObj = WzDirectory;

for (int i = 1; i < seperatedPath.Length; i++)
{
if (curObj == null)
Expand Down

0 comments on commit dfffdbd

Please sign in to comment.