-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa01960
commit 744a6ae
Showing
12 changed files
with
431 additions
and
145 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MapleLib.PacketLib | ||
{ | ||
public static class HexTool | ||
{ | ||
private static char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; | ||
|
||
/// <summary> | ||
/// Converts a byte value to readable hex representation | ||
/// </summary> | ||
/// <param name="byteValue"></param> | ||
/// <returns></returns> | ||
public static String ToString(byte byteValue) | ||
{ | ||
int tmp = byteValue << 8; | ||
char[] retstr = new char[] { HEX[(tmp >> 12) & 0x0F], HEX[(tmp >> 8) & 0x0F] }; | ||
return new string(retstr); | ||
} | ||
|
||
/// <summary> | ||
/// Converts an array of bytes to readable hex representation | ||
/// </summary> | ||
/// <param name="bytes"></param> | ||
/// <returns></returns> | ||
public static String ToString(byte[] bytes) | ||
{ | ||
StringBuilder hexed = new StringBuilder(); | ||
for (int i = 0; i < bytes.Length; i++) | ||
{ | ||
hexed.Append(ToString(bytes[i])); | ||
hexed.Append(' '); | ||
} | ||
return hexed.ToString(); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Converts an array of bytes to readable hex representation | ||
/// Extension method for PacketWriter | ||
/// </summary> | ||
/// <param name="bytes"></param> | ||
/// <returns></returns> | ||
public static String ToString(this PacketReader reader) | ||
{ | ||
byte[] bytes = reader.ToArray(); | ||
|
||
StringBuilder hexed = new StringBuilder(); | ||
for (int i = 0; i < bytes.Length; i++) | ||
{ | ||
hexed.Append(ToString(bytes[i])); | ||
hexed.Append(' '); | ||
} | ||
return hexed.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Converts an array of bytes to readable hex representation | ||
/// Extension method for PacketWriter | ||
/// </summary> | ||
/// <param name="bytes"></param> | ||
/// <returns></returns> | ||
public static String ToString(this PacketWriter writer) | ||
{ | ||
byte[] bytes = writer.ToArray(); | ||
|
||
StringBuilder hexed = new StringBuilder(); | ||
for (int i = 0; i < bytes.Length; i++) | ||
{ | ||
hexed.Append(ToString(bytes[i])); | ||
hexed.Append(' '); | ||
} | ||
return hexed.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters