Skip to content

Commit

Permalink
[MapleLib] Maplestory Localisation version
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Sep 26, 2021
1 parent 172f568 commit ecb990c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
25 changes: 25 additions & 0 deletions MapleLib/ClientLib/MapleStoryLocalisation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MapleLib.ClientLib
{
/// <summary>
/// The localisation number for each regional MapleStory version.
/// </summary>
public enum MapleStoryLocalisation : int
{
MapleStoryKorea = 1,
MapleStoryKoreaTespia = 2,
MapleStoryTespia = 5,
MapleStorySEA = 7,
MapleStoryGlobal = 8,
MapleStoryEurope = 9,

Not_Known = 999,

// TODO: other values
}
}
1 change: 1 addition & 0 deletions MapleLib/MapleLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="ClientLib\MapleStoryLocalisation.cs" />
<Compile Include="Configuration\ApplicationSettings.cs" />
<Compile Include="Configuration\ConfigurationManager.cs" />
<Compile Include="Configuration\UserSettings.cs" />
Expand Down
29 changes: 25 additions & 4 deletions MapleLib/WzLib/WzFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
using System.Linq;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using MapleLib.ClientLib;

namespace MapleLib.WzLib
{
Expand All @@ -43,6 +44,7 @@ public class WzFile : WzObject
internal uint versionHash = 0;
internal short mapleStoryPatchVersion = 0;
internal WzMapleVersion maplepLocalVersion;
internal MapleStoryLocalisation mapleLocaleVersion = MapleStoryLocalisation.Not_Known;
internal byte[] WzIv;
#endregion

Expand Down Expand Up @@ -89,6 +91,12 @@ public override WzObjectType ObjectType

public WzMapleVersion MapleVersion { get { return maplepLocalVersion; } set { maplepLocalVersion = value; } }

/// <summary>
/// The detected MapleStory locale version from 'MapleStory.exe' client.
/// KMST, GMS, EMS, MSEA, CMS, TWMS, etc.
/// </summary>
public MapleStoryLocalisation MapleLocaleVersion { get { return mapleLocaleVersion; } private set { } }

public override WzObject Parent { get { return null; } internal set { } }

public override WzFile WzFileParent { get { return this; } }
Expand Down Expand Up @@ -212,7 +220,7 @@ internal WzFileParseStatus ParseMainWzDirectory(bool lazyParse = false)
if (mapleStoryPatchVersion == -1)
{
// Attempt to get version from MapleStory.exe first
short maplestoryVerDetectedFromClient = GetMapleStoryVerFromExe(this.path);
short maplestoryVerDetectedFromClient = GetMapleStoryVerFromExe(this.path, out this.mapleLocaleVersion);

// this step is actually not needed if we know the maplestory patch version (the client .exe), but since we dont..
// we'll need a bruteforce way around it.
Expand Down Expand Up @@ -326,7 +334,7 @@ internal WzFileParseStatus ParseMainWzDirectory(bool lazyParse = false)
/// Attempts to get the MapleStory patch version number from MapleStory.exe
/// </summary>
/// <returns>0 if the exe could not be found, or version number be detected</returns>
private static short GetMapleStoryVerFromExe(string wzFilePath)
private static short GetMapleStoryVerFromExe(string wzFilePath, out MapleStoryLocalisation mapleLocaleVersion)
{
// https://github.com/lastbattle/Harepacker-resurrected/commit/63e2d72ac006f0a45fc324a2c33c23f0a4a988fa#r56759414
// <3 mechpaul
Expand All @@ -335,10 +343,13 @@ private static short GetMapleStoryVerFromExe(string wzFilePath)

FileInfo wzFileInfo = new FileInfo(wzFilePath);
if (!wzFileInfo.Exists)
{
mapleLocaleVersion = MapleStoryLocalisation.Not_Known; // set
return 0;
}

System.IO.DirectoryInfo currentDirectory = wzFileInfo.Directory;
for (int i = 0; i < 5; i++) // just attempt 5 layers here
for (int i = 0; i < 5; i++) // just attempt 5 directories here
{
FileInfo[] msExeFileInfos = currentDirectory.GetFiles(MAPLESTORY_EXE_NAME, SearchOption.TopDirectoryOnly);
FileInfo[] msTExeFileInfos = currentDirectory.GetFiles(MAPLESTORYT_EXE_NAME, SearchOption.TopDirectoryOnly);
Expand All @@ -357,12 +368,22 @@ private static short GetMapleStoryVerFromExe(string wzFilePath)
{
var versionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(currentDirectory.FullName, msExeFileInfo.FullName));

var windowsVer = versionInfo.FileMajorPart;
int locale = versionInfo.FileMajorPart;
MapleStoryLocalisation localeVersion = MapleStoryLocalisation.Not_Known;
if (Enum.IsDefined(typeof(MapleStoryLocalisation), locale))
{
localeVersion = (MapleStoryLocalisation)locale;
}
var msVersion = versionInfo.FileMinorPart;
var msMinorPatchVersion = versionInfo.FileBuildPart;

mapleLocaleVersion = localeVersion; // set
return (short) msVersion;
}
currentDirectory = currentDirectory.Parent; // check the parent folder on the next run
}

mapleLocaleVersion = MapleStoryLocalisation.Not_Known; // set
return 0;
}

Expand Down

0 comments on commit ecb990c

Please sign in to comment.