Skip to content

Commit

Permalink
[MapleLib] Fix for KMS v.1.360.1.0
Browse files Browse the repository at this point in the history
tested on the following WZ:
KMS v.1.360.1.0
GMS v230
MSEA v211
  • Loading branch information
lastbattle committed Feb 19, 2022
1 parent 7074251 commit 1e8bb63
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
51 changes: 18 additions & 33 deletions HaRepacker/GUI/SaveForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,10 @@
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="encryptionBox.Location" type="System.Drawing.Point, System.Drawing">
<value>112, 19</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="encryptionBox.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
<value>75, 12</value>
</data>
<data name="encryptionBox.Size" type="System.Drawing.Size, System.Drawing">
<value>338, 29</value>
<value>227, 21</value>
</data>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="encryptionBox.TabIndex" type="System.Int32, mscorlib">
Expand All @@ -145,13 +141,10 @@
<value>5</value>
</data>
<data name="saveButton.Location" type="System.Drawing.Point, System.Drawing">
<value>2, 150</value>
</data>
<data name="saveButton.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
<value>1, 93</value>
</data>
<data name="saveButton.Size" type="System.Drawing.Size, System.Drawing">
<value>461, 44</value>
<value>343, 27</value>
</data>
<data name="saveButton.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
Expand All @@ -172,13 +165,10 @@
<value>4</value>
</data>
<data name="versionBox.Location" type="System.Drawing.Point, System.Drawing">
<value>112, 63</value>
</data>
<data name="versionBox.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
<value>75, 39</value>
</data>
<data name="versionBox.Size" type="System.Drawing.Size, System.Drawing">
<value>339, 29</value>
<value>227, 22</value>
</data>
<data name="versionBox.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
Expand All @@ -202,13 +192,10 @@
<value>True</value>
</data>
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
<value>40, 66</value>
</data>
<data name="label1.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
<value>27, 41</value>
</data>
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>62, 21</value>
<value>45, 13</value>
</data>
<data name="label1.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
Expand All @@ -232,13 +219,10 @@
<value>True</value>
</data>
<data name="label2.Location" type="System.Drawing.Point, System.Drawing">
<value>18, 24</value>
</data>
<data name="label2.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
<value>12, 15</value>
</data>
<data name="label2.Size" type="System.Drawing.Size, System.Drawing">
<value>84, 21</value>
<value>62, 13</value>
</data>
<data name="label2.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
Expand All @@ -259,10 +243,14 @@
<value>1</value>
</data>
<data name="checkBox_64BitFile.Location" type="System.Drawing.Point, System.Drawing">
<value>44, 105</value>
<value>29, 65</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="checkBox_64BitFile.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>2, 2, 2, 2</value>
</data>
<data name="checkBox_64BitFile.Size" type="System.Drawing.Size, System.Drawing">
<value>411, 24</value>
<value>304, 23</value>
</data>
<data name="checkBox_64BitFile.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
Expand All @@ -286,10 +274,10 @@
<value>True</value>
</metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>9, 21</value>
<value>6, 13</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>463, 195</value>
<value>344, 121</value>
</data>
<data name="$this.Font" type="System.Drawing.Font, System.Drawing">
<value>Segoe UI, 8pt</value>
Expand Down Expand Up @@ -2694,9 +2682,6 @@
+B8AAA==
</value>
</data>
<data name="$this.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>Save</value>
</data>
Expand Down
27 changes: 21 additions & 6 deletions MapleLib/WzLib/WzFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ public class WzFile : WzObject
internal WzHeader header;
internal string name = "";
internal ushort wzVersionHeader = 0;
internal const ushort wzVersionHeader64bit = 777;
internal const ushort wzVersionHeader64bit_start = 777;
internal uint versionHash = 0;
internal short mapleStoryPatchVersion = 0;
internal WzMapleVersion maplepLocalVersion;
internal MapleStoryLocalisation mapleLocaleVersion = MapleStoryLocalisation.Not_Known;

internal bool b64BitClient = false; // KMS update after Q4 2021, ver 1.2.357
private bool b64BitClient_withVerHeader = false; //

internal byte[] WzIv;
#endregion

Expand Down Expand Up @@ -229,16 +232,22 @@ internal WzFileParseStatus ParseMainWzDirectory(bool lazyParse = false)

// the value of wzVersionHeader is less important. It is used for reading/writing from/to WzFile Header, and calculating the versionHash.
// it can be any number if the client is 64-bit. Assigning 777 is just for convenience when calculating the versionHash.
this.wzVersionHeader = b64BitClient ? wzVersionHeader64bit : reader.ReadUInt16();
this.wzVersionHeader = b64BitClient && !b64BitClient_withVerHeader ? wzVersionHeader64bit_start : reader.ReadUInt16();

if (mapleStoryPatchVersion == -1)
{
// for 64-bit client, return immediately if version 777 works correctly.
if (b64BitClient && TryDecodeWithWZVersionNumber(reader, wzVersionHeader, wzVersionHeader64bit, lazyParse))
// -- the latest KMS update seems to have changed it to 778? 779?
if (b64BitClient)
{
return WzFileParseStatus.Success;
for (ushort maplestoryVerToDecode = wzVersionHeader64bit_start; maplestoryVerToDecode < wzVersionHeader64bit_start + 10; maplestoryVerToDecode++)
{
if (TryDecodeWithWZVersionNumber(reader, wzVersionHeader, maplestoryVerToDecode, lazyParse))
{
return WzFileParseStatus.Success;
}
}
}

// Attempt to get version from MapleStory.exe first
short maplestoryVerDetectedFromClient = GetMapleStoryVerFromExe(this.path, out this.mapleLocaleVersion);

Expand Down Expand Up @@ -298,6 +307,12 @@ private void Check64BitClient(WzBinaryReader reader)
b64BitClient = true;
}
}
} else if (this.wzVersionHeader == 0x21) // or 33
{
b64BitClient = true;
// but read the header
// the latest KMS seems to include this back in again.. damn
this.b64BitClient_withVerHeader = true; // ugly hack, but until i've found a better way without breaking compatibility of old WZs.
}
}
else
Expand Down Expand Up @@ -491,7 +506,7 @@ private static uint CheckAndGetVersionHash(int wzVersionHeader, int maplestoryPa
VersionHash = (32 * VersionHash) + (int)VersionNumberStr[i] + 1;
}

if (wzVersionHeader == wzVersionHeader64bit)
if (wzVersionHeader == wzVersionHeader64bit_start)
return (uint)VersionHash; // always 59192

int a = (VersionHash >> 24) & 0xFF;
Expand Down

0 comments on commit 1e8bb63

Please sign in to comment.