Skip to content

Commit

Permalink
[HaRepacker] Fix compile errors from the previous merge
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Feb 13, 2022
1 parent d42d208 commit 7074251
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 65 deletions.
23 changes: 19 additions & 4 deletions HaRepacker/GUI/SaveForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using System.Windows.Forms;
using MapleLib.WzLib;
using MapleLib.WzLib.WzProperties;
using System.IO;
using MapleLib.WzLib.Util;
using System.Diagnostics;
Expand Down Expand Up @@ -75,7 +74,9 @@ private void SaveForm_Load(object sender, EventArgs e)
{
encryptionBox.SelectedIndex = MainForm.GetIndexByWzMapleVersion(wzf.MapleVersion);
versionBox.Value = wzf.Version;
checkBox_64BitFile.Checked = wzf.Is64BitWZFile;

checkBox_64BitFile.Checked = wzf.Is64BitWzFile;
versionBox.Enabled = wzf.Is64BitWzFile ? false : true; // disable checkbox if its checked as 64-bit, since the version will always be 777
}
else
{ // Data.wz uses BMS encryption... no sepcific version indicated
Expand Down Expand Up @@ -136,7 +137,7 @@ private void SaveButton_Click(object sender, EventArgs e)
{
if (versionBox.Value < 0)
{
Warning.Error(HaRepacker.Properties.Resources.SaveVersionError);
Warning.Error(Properties.Resources.SaveVersionError);
return;
}

Expand All @@ -148,7 +149,7 @@ private void SaveButton_Click(object sender, EventArgs e)
HaRepacker.Properties.Resources.WzFilter)
})
{
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
if (dialog.ShowDialog() != DialogResult.OK)
return;

bool bSaveAs64BitWzFile = checkBox_64BitFile.Checked;
Expand Down Expand Up @@ -245,5 +246,19 @@ private void PrepareAllImgs(WzDirectory dir)
PrepareAllImgs(subdir);
}
}

/// <summary>
/// On checkBox_64BitFile checked changed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void checkBox_64BitFile_CheckedChanged(object sender, EventArgs e)
{
if (bIsLoading)
return;

CheckBox checkbox_64 = (CheckBox)sender;
versionBox.Enabled = checkbox_64.Checked != true; // disable checkbox if its checked as 64-bit, since the version will always be 777
}
}
}
1 change: 1 addition & 0 deletions HaRepacker/GUI/SaveForm.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 35 additions & 19 deletions HaRepacker/GUI/SaveForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@
</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>75, 12</value>
<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>
</data>
<data name="encryptionBox.Size" type="System.Drawing.Size, System.Drawing">
<value>178, 21</value>
<value>338, 29</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 @@ -141,10 +145,13 @@
<value>5</value>
</data>
<data name="saveButton.Location" type="System.Drawing.Point, System.Drawing">
<value>1, 93</value>
<value>2, 150</value>
</data>
<data name="saveButton.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="saveButton.Size" type="System.Drawing.Size, System.Drawing">
<value>263, 27</value>
<value>461, 44</value>
</data>
<data name="saveButton.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
Expand All @@ -165,10 +172,13 @@
<value>4</value>
</data>
<data name="versionBox.Location" type="System.Drawing.Point, System.Drawing">
<value>75, 39</value>
<value>112, 63</value>
</data>
<data name="versionBox.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 5, 4, 5</value>
</data>
<data name="versionBox.Size" type="System.Drawing.Size, System.Drawing">
<value>178, 22</value>
<value>339, 29</value>
</data>
<data name="versionBox.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
Expand All @@ -192,10 +202,13 @@
<value>True</value>
</data>
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
<value>27, 41</value>
<value>40, 66</value>
</data>
<data name="label1.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
</data>
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>45, 13</value>
<value>62, 21</value>
</data>
<data name="label1.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
Expand All @@ -219,10 +232,13 @@
<value>True</value>
</data>
<data name="label2.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 15</value>
<value>18, 24</value>
</data>
<data name="label2.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 0, 4, 0</value>
</data>
<data name="label2.Size" type="System.Drawing.Size, System.Drawing">
<value>62, 13</value>
<value>84, 21</value>
</data>
<data name="label2.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
Expand All @@ -242,20 +258,17 @@
<data name="&gt;&gt;label2.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="checkBox_64BitFile.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="checkBox_64BitFile.Location" type="System.Drawing.Point, System.Drawing">
<value>75, 70</value>
<value>44, 105</value>
</data>
<data name="checkBox_64BitFile.Size" type="System.Drawing.Size, System.Drawing">
<value>166, 17</value>
<value>411, 24</value>
</data>
<data name="checkBox_64BitFile.TabIndex" type="System.Int32, mscorlib">
<value>6</value>
<value>0</value>
</data>
<data name="checkBox_64BitFile.Text" xml:space="preserve">
<value>Save as 64-bit client WZ file</value>
<value>Save as 64-bit WZ file (GMS v230+, KMS v1.2.357+)</value>
</data>
<data name="&gt;&gt;checkBox_64BitFile.Name" xml:space="preserve">
<value>checkBox_64BitFile</value>
Expand All @@ -273,10 +286,10 @@
<value>True</value>
</metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>6, 13</value>
<value>9, 21</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>265, 121</value>
<value>463, 195</value>
</data>
<data name="$this.Font" type="System.Drawing.Font, System.Drawing">
<value>Segoe UI, 8pt</value>
Expand Down Expand Up @@ -2681,6 +2694,9 @@
+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
6 changes: 3 additions & 3 deletions MapleLib/WzLib/Util/WzBinaryWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class WzBinaryWriter : BinaryWriter
{
#region Properties
public WzMutableKey WzKey { get; set; }
public uint Hash { get; }
public uint Hash { get; set; }
public Hashtable StringCache { get; set; }
public WzHeader Header { get; set; }
public bool LeaveOpen { get; internal set; }
Expand Down Expand Up @@ -59,8 +59,8 @@ public WzBinaryWriter(Stream output, byte[] WzIv, bool leaveOpen)
/// ?InternalSerializeString@@YAHPAGPAUIWzArchive@@EE@Z
/// </summary>
/// <param name="s"></param>
/// <param name="withoutOffset"></param>
/// <param name="withOffset"></param>
/// <param name="withoutOffset">0x73</param>
/// <param name="withOffset">0x1B</param>
public void WriteStringValue(string s, int withoutOffset, int withOffset)
{
if (s.Length > 4 && StringCache.ContainsKey(s))
Expand Down
63 changes: 26 additions & 37 deletions MapleLib/WzLib/WzFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override WzObjectType ObjectType
/// </summary>
public MapleStoryLocalisation MapleLocaleVersion { get { return mapleLocaleVersion; } private set { } }

public bool Is64BitWZFile { get { return b64BitClient; } private set { } }
public bool Is64BitWzFile { get { return b64BitClient; } private set { } }

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

Expand All @@ -109,14 +109,8 @@ public override void Dispose()
{
if (wzDir == null || wzDir.reader == null)
return;
try
{
wzDir.reader.Close();
}
finally
{
wzDir.reader = null;
}
wzDir.reader.Close();
wzDir.reader = null;
Header = null;
path = null;
name = null;
Expand Down Expand Up @@ -225,12 +219,10 @@ internal WzFileParseStatus ParseMainWzDirectory(bool lazyParse = false)
this.Header.Ident = reader.ReadString(4);
this.Header.FSize = reader.ReadUInt64();
this.Header.FStart = reader.ReadUInt32();

//this.Header.Copyright = reader.ReadNullTerminatedString();
this.Header.Copyright = reader.ReadString((int)(Header.FStart - 17U));

byte unk1 = reader.ReadByte();
byte[] unk2 = reader.ReadBytes((int)(Header.FStart - (ulong)reader.BaseStream.Position));

reader.Header = this.Header;

Check64BitClient(reader); // update b64BitClient flag
Expand All @@ -256,10 +248,10 @@ internal WzFileParseStatus ParseMainWzDirectory(bool lazyParse = false)

for (int j = maplestoryVerDetectedFromClient; j < MAX_PATCH_VERSION; j++)
{
if (TryDecodeWithWZVersionNumber(reader, wzVersionHeader, j, lazyParse))
{
return WzFileParseStatus.Success;
}
if (TryDecodeWithWZVersionNumber(reader, wzVersionHeader, j, lazyParse))
{
return WzFileParseStatus.Success;
}
}
//parseErrorMessage = "Error with game version hash : The specified game version is incorrect and WzLib was unable to determine the version itself";
return WzFileParseStatus.Error_Game_Ver_Hash;
Expand All @@ -268,7 +260,6 @@ internal WzFileParseStatus ParseMainWzDirectory(bool lazyParse = false)
{
this.versionHash = CheckAndGetVersionHash(wzVersionHeader, mapleStoryPatchVersion);
reader.Hash = this.versionHash;

WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv, this);
directory.ParseDirectory();
this.wzDir = directory;
Expand Down Expand Up @@ -322,7 +313,7 @@ private void Check64BitClient(WzBinaryReader reader)
private bool TryDecodeWithWZVersionNumber(WzBinaryReader reader, int useWzVersionHeader, int useMapleStoryPatchVersion, bool lazyParse)
{
this.mapleStoryPatchVersion = (short)useMapleStoryPatchVersion;

this.versionHash = CheckAndGetVersionHash(useWzVersionHeader, mapleStoryPatchVersion);
if (this.versionHash == 0) // ugly hack, but that's the only way if the version number isnt known (nexon stores this in the .exe)
return false;
Expand Down Expand Up @@ -358,8 +349,8 @@ private bool TryDecodeWithWZVersionNumber(WzBinaryReader reader, int useWzVersio

switch (checkByte)
{
case WzImage.WzImageHeaderByte_WithoutOffset: // 0x73
case WzImage.WzImageHeaderByte_WithOffset:
case 0x73:
case 0x1b:
{
WzDirectory directory = new WzDirectory(reader, this.name, this.versionHash, this.WzIv, this);
directory.ParseDirectory(lazyParse);
Expand Down Expand Up @@ -451,13 +442,13 @@ private static short GetMapleStoryVerFromExe(string wzFilePath, out MapleStoryLo
if (msExeFileInfos.Length > 0 && msExeFileInfos[0].Exists)
{
exeFileInfo.Add(msExeFileInfos[0]);
}
foreach (FileInfo msExeFileInfo in exeFileInfo)
}

foreach (FileInfo msExeFileInfo in exeFileInfo)
{
var versionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(currentDirectory.FullName, msExeFileInfo.FullName));

if ((versionInfo.FileMajorPart == 1 && versionInfo.FileMinorPart == 0 && versionInfo.FileBuildPart == 0)
if ((versionInfo.FileMajorPart == 1 && versionInfo.FileMinorPart == 0 && versionInfo.FileBuildPart == 0)
|| (versionInfo.FileMajorPart == 0 && versionInfo.FileMinorPart == 0 && versionInfo.FileBuildPart == 0)) // older client uses 1.0.0.1
continue;

Expand Down Expand Up @@ -494,10 +485,12 @@ private static uint CheckAndGetVersionHash(int wzVersionHeader, int maplestoryPa
int VersionHash = 0;
string VersionNumberStr = VersionNumber.ToString();

for (int i = 0; i < VersionNumberStr.Length; i++)
int l = VersionNumberStr.Length;
for (int i = 0; i < l; i++)
{
VersionHash = (32 * VersionHash) + (int)VersionNumberStr[i] + 1;
}

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

Expand Down Expand Up @@ -534,9 +527,9 @@ private void CreateWZVersionHash()
/// Saves a wz file to the disk, AKA repacking.
/// </summary>
/// <param name="path">Path to the output wz file</param>
/// <param name="bSaveAs64BitWzFile">Save as WZ file for the 64-bit client</param>
/// <param name="override_saveAs64BitWZ"></param>
/// <param name="savingToPreferredWzVer"></param>
public void SaveToDisk(string path, bool? bSaveAs64BitWzFile, WzMapleVersion savingToPreferredWzVer = WzMapleVersion.UNKNOWN)
public void SaveToDisk(string path, bool? override_saveAs64BitWZ, WzMapleVersion savingToPreferredWzVer = WzMapleVersion.UNKNOWN)
{
// WZ IV
if (savingToPreferredWzVer == WzMapleVersion.UNKNOWN)
Expand All @@ -549,25 +542,26 @@ public void SaveToDisk(string path, bool? bSaveAs64BitWzFile, WzMapleVersion sav

// MapleStory UserKey
bool bIsWzUserKeyDefault = MapleCryptoConstants.IsDefaultMapleStoryUserKey(); // check if its saving to the same UserKey.
//
// Save WZ as 64-bit wz format
bool bSaveAs64BitWZ = override_saveAs64BitWZ != null ? (bool)override_saveAs64BitWZ : b64BitClient;

CreateWZVersionHash();
wzDir.SetVersionHash(versionHash);

string tempFile = Path.GetFileNameWithoutExtension(path) + ".TEMP";
File.Create(tempFile).Close();
using (FileStream fs = new FileStream(tempFile, FileMode.Append, FileAccess.Write))
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, versionHash))
using (WzBinaryWriter wzWriter = new WzBinaryWriter(File.Create(path), WzIv))
{
wzWriter.Hash = versionHash;

uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + (b64BitClient ? 0 : 2u)));
uint totalLen = wzDir.GetImgOffsets(wzDir.GetOffsets(Header.FStart + (bSaveAs64BitWZ ? 0 : 2u)));
Header.FSize = totalLen - Header.FStart;
for (int i = 0; i < 4; i++)
{
Expand All @@ -582,12 +576,7 @@ public void SaveToDisk(string path, bool? bSaveAs64BitWzFile, WzMapleVersion sav
{
wzWriter.Write(new byte[(int)extraHeaderLength]);
}

if (bSaveAs64BitWzFile != null)
{
if (bSaveAs64BitWzFile == false)
wzWriter.Write(wzVersionHeader);
} else if (!b64BitClient)
if (!bSaveAs64BitWZ)
wzWriter.Write(wzVersionHeader);

wzWriter.Header = Header;
Expand Down
Loading

0 comments on commit 7074251

Please sign in to comment.