Skip to content

Commit

Permalink
Make public static value 'StartupArguments' a private value in MainForm
Browse files Browse the repository at this point in the history
Fix outbound and inbound packets being added while ignored. Fixes #12
Fix exception caused by invalid encoding name, switch to static numbers instead
Rename 'ascii' to 'encoding'
Push to version 2.0.2.6
Change 'Import' to 'Import .pcap file'
  • Loading branch information
diamondo25 committed Aug 23, 2015
1 parent 20e6dbc commit d0dda9d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 60 deletions.
39 changes: 19 additions & 20 deletions MainForm.Designer.cs

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

8 changes: 5 additions & 3 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public partial class MainForm : Form
private StructureForm mStructureForm = new StructureForm();
private PropertyForm mPropertyForm = new PropertyForm();

public static string[] StartupArguments = null;
private string[] _startupArguments = null;

public MainForm()
public MainForm(string[] startupArguments)
{
InitializeComponent();
Text = "MapleShark " + Program.AssemblyVersion;

_startupArguments = startupArguments;
}

public SearchForm SearchForm { get { return mSearchForm; } }
Expand Down Expand Up @@ -142,7 +144,7 @@ private void MainForm_Load(object pSender, EventArgs pArgs)
rightPane2.Show();


foreach (string arg in StartupArguments)
foreach (string arg in _startupArguments)
{
SessionForm session = NewSession();
session.OpenReadOnly(arg);
Expand Down
10 changes: 5 additions & 5 deletions MapleKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ public static byte[] GetKeyForVersion(byte locale, ushort version, byte subversi
}

// Get first version known
for (; version > 0; version--)
for (ushort v = version; v > 0; v--)
{
for (byte subVersion = subversion; subVersion >= 0; subVersion--)
for (byte sv = subversion; sv >= 0; sv--)
{
var tuple = new KeyValuePair<ushort, byte>(version, subVersion);
var tuple = new KeyValuePair<ushort, byte>(v, sv);
if (MapleStoryKeys[locale].ContainsKey(tuple))
{
byte[] key = MapleStoryKeys[locale][tuple];
byte[] ret = new byte[32];
for (int i = 0; i < 8; i++)
ret[i * 4] = key[i];

Console.WriteLine("Using key for version {0}.{1}", version, subVersion);
Console.WriteLine("Using key for version {0}.{1}", v, sv);
return ret;
}
if (subVersion == 0) break;
if (sv == 0) break;
}
}
Console.WriteLine("Version {0}.{1} for locale {2} not found!", version, subversion, locale);
Expand Down
5 changes: 1 addition & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ private static void Main(string[] pArgs)
}
};


MainForm.StartupArguments = pArgs;

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

if (new frmSplash().ShowDialog() == DialogResult.OK)
Application.Run(new MainForm());
Application.Run(new MainForm(pArgs));
}


Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MapleShark")]
[assembly: AssemblyCopyright("Copyright © Astaelan, Diamondo25 '11 - '14")]
[assembly: AssemblyCopyright("Copyright © Astaelan, Diamondo25 '11 - '15")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.2.5")]
[assembly: AssemblyFileVersion("2.0.2.5")]
[assembly: AssemblyVersion("2.0.2.6")]
[assembly: AssemblyFileVersion("2.0.2.6")]
5 changes: 4 additions & 1 deletion SessionForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public enum Results

private string mFilename = null;
private bool mTerminated = false;
//private bool mSavedAfterTermination = false;
private ushort mLocalPort = 0;
private ushort mRemotePort = 0;
private ushort mProxyPort = 0;
Expand Down Expand Up @@ -350,6 +349,9 @@ private void ProcessTCPPacket(TcpPacket pTCPPacket, ref uint pSequence, Dictiona
refreshOpcodes = true;
}
if (definition != null && !mViewIgnoredMenu.Checked && definition.Ignore) continue;
if (packet.Outbound && !mViewOutboundMenu.Checked) continue;
if (!packet.Outbound && !mViewInboundMenu.Checked) continue;

mPacketList.Items.Add(packet);
if (mPacketList.SelectedItems.Count == 0) packet.EnsureVisible();
}
Expand Down Expand Up @@ -496,6 +498,7 @@ public void RefreshPackets()
MaplePacket packet = mPackets[index];
if (packet.Outbound && !mViewOutboundMenu.Checked) continue;
if (!packet.Outbound && !mViewInboundMenu.Checked) continue;

Definition definition = Config.Instance.GetDefinition(mBuild, mLocale, packet.Outbound, packet.Opcode);
packet.Name = definition == null ? "" : definition.Name;
if (!mOpcodes.Exists(kv => kv.First == packet.Outbound && kv.Second == packet.Opcode)) mOpcodes.Add(new Pair<bool, ushort>(packet.Outbound, packet.Opcode));
Expand Down
55 changes: 31 additions & 24 deletions StructureSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,39 @@ namespace MapleShark
public sealed class StructureSegment
{
private byte[] mBuffer;
private Encoding ascii = Encoding.UTF8;
private Encoding encoding = Encoding.UTF8;

public StructureSegment(byte[] pBuffer, int pStart, int pLength, byte locale)
{
mBuffer = new byte[pLength];
switch (locale)
try
{
case MapleLocale.KOREA:
case MapleLocale.KOREA_TEST:
ascii = Encoding.GetEncoding("EUC_KR");
break;
case MapleLocale.JAPAN:
ascii = Encoding.GetEncoding("Shift_JIS");
break;
case MapleLocale.CHINA:
ascii = Encoding.GetEncoding("GB18030");
break;
case MapleLocale.TESPIA:
ascii = Encoding.Default;
break;
case MapleLocale.TAIWAN:
ascii = Encoding.GetEncoding("BIG5-HKSCS");
break;
default:
ascii = Encoding.UTF8;
break;
switch (locale)
{
case MapleLocale.KOREA:
case MapleLocale.KOREA_TEST:
encoding = Encoding.GetEncoding(51949); // EUC_KR
break;
case MapleLocale.JAPAN:
encoding = Encoding.GetEncoding(50222); // Shift_JIS
break;
case MapleLocale.CHINA:
encoding = Encoding.GetEncoding(54936); // GB18030
break;
case MapleLocale.TESPIA:
encoding = Encoding.Default;
break;
case MapleLocale.TAIWAN:
encoding = Encoding.GetEncoding("BIG5-HKSCS");
break;
default:
encoding = Encoding.UTF8;
break;
}
}
catch
{
encoding = Encoding.UTF8;
}
Buffer.BlockCopy(pBuffer, pStart, mBuffer, 0, pLength);
}
Expand Down Expand Up @@ -117,8 +124,8 @@ public string String
{
if (mBuffer.Length == 0) return null;
if (mBuffer[0] == 0x00) return "";
for (int index = 0; index < mBuffer.Length; ++index) if (mBuffer[index] == 0x00) return ascii.GetString(mBuffer, 0, index);
return ascii.GetString(mBuffer, 0, mBuffer.Length);
for (int index = 0; index < mBuffer.Length; ++index) if (mBuffer[index] == 0x00) return encoding.GetString(mBuffer, 0, index);
return encoding.GetString(mBuffer, 0, mBuffer.Length);
}
}

Expand All @@ -130,7 +137,7 @@ public string StringIgnore
Buffer.BlockCopy(mBuffer, 0, sBuffer, 0, mBuffer.Length);
if (sBuffer.Length == 0) return null;
for (int index = 0; index < sBuffer.Length; ++index) if (sBuffer[index] >= 0x00 && sBuffer[index] < 0x20) sBuffer[index] = 0x2E;
return ascii.GetString(sBuffer, 0, sBuffer.Length);
return encoding.GetString(sBuffer, 0, sBuffer.Length);
}
}

Expand Down

0 comments on commit d0dda9d

Please sign in to comment.