Added C array formatting option to pkgdsprod decoder.

This commit is contained in:
Greg Edwards 2021-03-12 23:50:51 -05:00
parent 3840a90332
commit cbe2c5d6f9
3 changed files with 61 additions and 15 deletions

View File

@ -9,9 +9,19 @@
<form id="theForm" runat="server">
<div>
<p>Uplaod your Generation IV box upload, battle video, or dressup capture:</p>
<asp:FileUpload ID="fuBox" runat="server" />
<asp:Button ID="btnSend" Text="Send" OnClick="btnSend_Click" runat="server" />
<div>
<asp:Label Text="Format:" AssociatedControlID="rblFormat" runat="server" />
<asp:RadioButtonList ID="rblFormat" RepeatDirection="Horizontal" runat="server">
<asp:ListItem Text="Hex dump" Value="hd" Selected="True" />
<asp:ListItem Text="C array" Value="ca" />
</asp:RadioButtonList>
</div>
<div>
<asp:FileUpload ID="fuBox" runat="server" />
<asp:Button ID="btnSend" Text="Send" OnClick="btnSend_Click" runat="server" />
</div>
</div>
<asp:Literal ID="litMessage" runat="server" />
<asp:PlaceHolder ID="phDecoded" Visible="false" runat="server">
<div>

View File

@ -34,11 +34,20 @@ namespace PkmnFoundations.GTS.debug
CryptMessage(data);
litDecoded.Text = RenderHex(data.ToHexStringLower());
switch (rblFormat.SelectedValue)
{
case "hd":
default:
litDecoded.Text = RenderHex(data.ToHexStringLower());
break;
case "ca":
litDecoded.Text = RenderCArray(data.ToHexStringLower());
break;
}
phDecoded.Visible = true;
}
private String RenderHex(String hex)
private string RenderHex(string hex)
{
StringBuilder builder = new StringBuilder();
for (int x = 0; x < hex.Length; x += 16)
@ -55,6 +64,22 @@ namespace PkmnFoundations.GTS.debug
return builder.ToString();
}
private string RenderCArray(string hex)
{
StringBuilder builder = new StringBuilder();
for (int x = 0; x < hex.Length; x += 2)
{
if (x > 0)
{
builder.Append(", ");
if (x % 16 == 0) builder.Append("<br />\r\n");
}
builder.Append("0x");
builder.Append(hex.Substring(x, Math.Min(2, hex.Length - x)));
}
return builder.ToString();
}
private void CryptMessage(byte[] message)
{
if (message.Length < 5) return;

View File

@ -7,11 +7,13 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace PkmnFoundations.GTS.debug {
public partial class BoxUp {
namespace PkmnFoundations.GTS.debug
{
public partial class BoxUp
{
/// <summary>
/// HeaderColour1 control.
/// </summary>
@ -20,7 +22,7 @@ namespace PkmnFoundations.GTS.debug {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::PkmnFoundations.Web.HeaderColour HeaderColour1;
/// <summary>
/// theForm control.
/// </summary>
@ -29,7 +31,16 @@ namespace PkmnFoundations.GTS.debug {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm theForm;
/// <summary>
/// rblFormat control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.RadioButtonList rblFormat;
/// <summary>
/// fuBox control.
/// </summary>
@ -38,7 +49,7 @@ namespace PkmnFoundations.GTS.debug {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.FileUpload fuBox;
/// <summary>
/// btnSend control.
/// </summary>
@ -47,7 +58,7 @@ namespace PkmnFoundations.GTS.debug {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Button btnSend;
/// <summary>
/// litMessage control.
/// </summary>
@ -56,7 +67,7 @@ namespace PkmnFoundations.GTS.debug {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal litMessage;
/// <summary>
/// phDecoded control.
/// </summary>
@ -65,7 +76,7 @@ namespace PkmnFoundations.GTS.debug {
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.PlaceHolder phDecoded;
/// <summary>
/// litDecoded control.
/// </summary>