HARepacker v230 Fix WZ 

is it friday yet
Decennium
Joined
Apr 13, 2009
Messages
605
Reaction score
154
Hi,

I noticed in the most recent GMS patched HARepacker resurrected was not working.
Upon discussion with some friends in the community, I was notified that Elem8100 has found the solution(apologies if incorrect).

Apparently the wzVersionHeader is 2 bytes and is no longer part of the decrypted packet stream.
This means, that previously, the header.FStart would start at ~ 62 bytes into the stream. Now after v230, it will start at 60.
Fortunately the rest of the offsets and byte checks remained the same. However, wzVersionHeader is now a fix value of 777 as of V230.

So how to fix?

->Make sure header.FStart is 60 when you ReadUInt32().
->wzVersionHeader is now 777
->Calculate the hashversion for 777
->When saving the file, there is a +2 offset added to header.FStart. This will cause the file, after being saved, to read incorrectly and your .IMG won't be loaded

Some code below;

From internal WzFileParseStatus ParseMainWzDirectory(bool lazyParse = false)
Code:
            this.wzVersionHeader = 0;
            if (!this.b64BitClient)
                if (this.Header.FSize >= 2)
                {
                    this.wzVersionHeader = reader.ReadInt16();
                    Console.WriteLine("Version Header : " + this.wzVersionHeader);
                    if (this.wzVersionHeader < 0xff && this.wzVersionHeader > 0)
                    {

                        Console.WriteLine("GMS < V230 detected");

                    } else
                    {
                        Console.WriteLine("GMS > V230 found");
                        this.wzVersionHeader = 777; //V230
                        reader.BaseStream.Position = this.header.FStart;
                    }
                }
            else
                {
                    this.wzVersionHeader = 777; 
                    reader.BaseStream.Position = this.header.FStart;
                }

Calculating the hasversion by Elem8100 the god (please teach me your ways <3)

Code:
                    //By Elem8100 
                    int sum = 0;
                    string versionStr = useWzVersionHeader.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    for (int j = 0; j < versionStr.Length; j++)
                    {
                        sum <<= 5;
                        sum += (int)versionStr[j] + 1;
                    }
                    this.versionHash = (uint) sum;
                    this.Version = 777;
                    Console.WriteLine("Calculated Hash : " + this.versionHash);

You'll want to call the above code and set the versionhash before reader.Hash = this versionHash is called

Lastly the save function;

Code:
     public void SaveToDisk(string path, WzMapleVersion savingToPreferredWzVer = WzMapleVersion.UNKNOWN)
        {
            Console.WriteLine("Saving...");
            // WZ IV
            if (savingToPreferredWzVer == WzMapleVersion.UNKNOWN)
                WzIv = WzTool.GetIvByMapleVersion(maplepLocalVersion); // get from local WzFile
            else
                WzIv = WzTool.GetIvByMapleVersion(savingToPreferredWzVer); // custom selected

            bool bIsWzIvSimilar = WzIv.SequenceEqual(wzDir.WzIv); // check if its saving to the same IV.
            wzDir.WzIv = WzIv;

            // MapleStory UserKey
            bool bIsWzUserKeyDefault = MapleCryptoConstants.IsDefaultMapleStoryUserKey(); // check if its saving to the same UserKey.
            //

            if (this.wzVersionHeader != 777)
            {
                CreateWZVersionHashv230();
            } 
            
            wzDir.SetVersionHash(versionHash);
            Console.WriteLine("Setting directory hash to : " + wzDir.hash);

            string tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP";
            File.Create(tempFile).Close();
            using (FileStream fs = new FileStream(tempFile, FileMode.Append, FileAccess.Write))
            {
                wzDir.GenerateDataFile(bIsWzIvSimilar ? null : WzIv, bIsWzUserKeyDefault, fs);
            }

            WzTool.StringCache.Clear();

            using (WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), WzIv))
            {
                wzWriter.Hash = versionHash;

                if (wzVersionHeader != 777)
                {
                    uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + 2));
                    Header.FSize = totalLen - Header.FStart;
                } else
                {
                    uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart)); //Header.FStart is where the file starts reading the check byte V230 its 60 
                    Header.FSize = totalLen - Header.FStart;
                }
               
                for (int i = 0; i < 4; i++)
                {
                    wzWriter.Write((byte)Header.Ident[i]);
                }
                wzWriter.Write((long)Header.FSize);
                wzWriter.Write(Header.FStart);
                wzWriter.WriteNullTerminatedString(Header.Copyright);
                long extraHeaderLength = Header.FStart - wzWriter.BaseStream.Position;
                if (extraHeaderLength > 0)
                {
                    wzWriter.Write(new byte[(int)extraHeaderLength]);
                }
                if (!b64BitClient)
                    if (wzVersionHeader != 777) //V230 no need to write this anymore
                    {
                        Console.WriteLine("GMS <V230 Adding Version Header");
                        wzWriter.Write(wzVersionHeader);
                    } 

                wzWriter.Header = Header;
                wzDir.SaveDirectory(wzWriter);
                wzWriter.StringCache.Clear();

                using (FileStream fs = File.OpenRead(tempFile))
                {
                    wzDir.SaveImages(wzWriter, fs);
                }
                File.Delete(tempFile);

                wzWriter.StringCache.Clear();
            }
            Console.WriteLine("Finished saving");
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

Well that should be it. With those changes in MapleLib, your HARepacker should be able to read v230.
Disclaimer : I am EE not SWE. This is my interpretation of the solution and what I implemented. I t may not be the nicest code or maybe what I said wasn't exactly correct so I do apologize.

Also credits due to original owners of maplelib, harepacker, elem8100 etc.. etc...

Compiled version below


Enjoy
 
Your Fix version can't read newest KMS wz.
Nexon seem to make a joke for the wz encoding. They changed it back again.:grr: Good news,return to old way of wz.
Now the wzVersion is 778(or next time is 779 ?), But old HaRepacker or other wz editor can read it again. Not sure how they will change in the future.
 
Last edited:
Your Fix version can't read newest KMS wz.
Nexon seem to make a joke for the wz encoding. They changed it back again.:grr: Good news,return to old way of wz.
Now the wzVersion is 778(or next time is 779 ?), But old HaRepacker or other wz editor can read it again. Not sure how they will change in the future.

Hey,

Yea unfortunately I don't really have KMS wz to test with. The fix version was mostly intended for GMS and hopefully provide some insight to other programmers on what happened in the current patch.
Seems like it'll have to be changed again if the they reverted to the old way. Will probably look into that when the time comes.
 
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.************** Exception Text **************System.NullReferenceException: Object reference not set to an instance of an object. at HaRepacker.Program.PrepareApplication(Boolean from_internal) in C:\Users\Darren\Source\Repos\Harepacker-resurrected\HaRepacker\Program.cs:line 149 at HaRepacker.Program.Main(String[] args) in C:\Users\Darren\Source\Repos\Harepacker-resurrected\HaRepacker\Program.cs:line 67************** Loaded Assemblies **************mscorlib Assembly Version: 4.0.0.0 Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll----------------------------------------HaRepackerResurrected Assembly Version: 4.2.4.0 Win32 Version: 4.2.4.0 CodeBase: file:///C:/Users/wenju/Desktop/AnyCPU/HaRepackerResurrected.exe----------------------------------------MapleLib Assembly Version: 2.0.0.0 Win32 Version: 2.0.0.0 CodeBase: file:///C:/Users/wenju/Desktop/AnyCPU/MapleLib.DLL----------------------------------------System.Drawing Assembly Version: 4.0.0.0 Win32 Version: 4.8.4390.0 built by: NET48REL1LAST_C CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll----------------------------------------System Assembly Version: 4.0.0.0 Win32 Version: 4.8.4488.0 built by: NET48REL1LAST_C CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll----------------------------------------System.Windows.Forms Assembly Version: 4.0.0.0 Win32 Version: 4.8.4488.0 built by: NET48REL1LAST_C CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll----------------------------------------Newtonsoft.Json Assembly Version: 13.0.0.0 Win32 Version: 13.0.1.25517 CodeBase: file:///C:/Users/wenju/Desktop/AnyCPU/Newtonsoft.Json.DLL----------------------------------------System.Core Assembly Version: 4.0.0.0 Win32 Version: 4.8.4470.0 built by: NET48REL1LAST_C CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll----------------------------------------System.Numerics Assembly Version: 4.0.0.0 Win32 Version: 4.8.4084.0 built by: NET48REL1 CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll----------------------------------------System.Runtime.Serialization Assembly Version: 4.0.0.0 Win32 Version: 4.8.4455.0 built by: NET48REL1LAST_C CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll----------------------------------------System.Data Assembly Version: 4.0.0.0 Win32 Version: 4.8.4455.0 built by: NET48REL1LAST_C CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll----------------------------------------System.Xml Assembly Version: 4.0.0.0 Win32 Version: 4.8.4084.0 built by: NET48REL1 CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll----------------------------------------System.Configuration Assembly Version: 4.0.0.0 Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll----------------------------------------************** JIT Debugging **************To enable just-in-time (JIT) debugging, the .config file for thisapplication or computer (machine.config) must have thejitDebugging value set in the system.windows.forms section.The application must also be compiled with debuggingenabled.For example:<configuration> <system.windows.forms jitDebugging="true" /></configuration>When JIT debugging is enabled, any unhandled exceptionwill be sent to the JIT debugger registered on the computerrather than be handled by this dialog box.


It seems i have some problem now using it
yesterday it was working fine but now all my harepacker seems to have this error
why is this so?

Found a fix by

211
i managed to solve this by my own.
had to go to %appdata%
and delete the temporary files of Hacreator.
From some reason it was messed up.
 
Last edited:
HaCreator does not work.

I see these errors in my Event Viewer:

Application: HaCreator.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentOutOfRangeException
at System.IO.FileStream.set_Position(Int64)
at MapleLib.WzLib.WzFile.ParseMainWzDirectory(Boolean)
at MapleLib.WzLib.WzFile.ParseWzFile(Byte[])
at MapleLib.WzLib.WzSettingsManager.LoadSettings()
at HaCreator.Program.Main()

and

Faulting application name: HaCreator.exe, version: 2.2.0.0, time stamp: 0x6205cc9e
Faulting module name: KERNELBASE.dll, version: 10.0.19041.1645, time stamp: 0x630193b4
Exception code: 0xe0434352
Fault offset: 0x0000000000034f69
Faulting process id: 0x2bac
Faulting application start time: 0x01d8531cbe918537
Faulting application path: M:\Games\Maplestory-PS\HA V230 Fix\AnyCPU\HaCreator.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: 907fee36-2249-47a8-972c-a96fcae05559
Faulting package full name:
Faulting package-relative application ID:
 
From what I was told, they removed the 2 modified bytes and the old HA should work now
 
Your Fix version can't read newest KMS wz.
Nexon seem to make a joke for the wz encoding. They changed it back again.:grr: Good news,return to old way of wz.
Now the wzVersion is 778(or next time is 779 ?), But old HaRepacker or other wz editor can read it again. Not sure how they will change in the future.

As Elem stated here you can use the old version for GMS 233
 
Your Fix version can't read newest KMS wz.
Nexon seem to make a joke for the wz encoding. They changed it back again.:grr: Good news,return to old way of wz.
Now the wzVersion is 778(or next time is 779 ?), But old HaRepacker or other wz editor can read it again. Not sure how they will change in the future.

Hey, thanks for this! I've taken note of it, will look to do more testing against a few more KMS versions.




At this stage, things are still rather unstable for me to confidently make a new release, but I will try to have it by Chirstmas.
HaCreator is sort-of working for the 64-bit version of KMS with a few bugs left to be fix.
 
Last edited:
Hey, thanks for this! I've taken note of it, will look to do more testing against a few more KMS versions.




At this stage, things are still rather unstable for me to confidently make a new release :( but I will try to have it by Chirstmas.
HaCreator is sort-of working for the 64-bit version of KMS with a few bugs left to be fix.

I'd love to have HaCreator for v362.
 
Back