@@ -7,36 +7,34 @@ namespace L2Net.PacketConverter.Core
77{
88 public static class Convert
99 {
10- public static string FromByteToHex ( string i )
10+ public static string FromByteToHex ( byte i )
1111 {
12- return FromNoToHex ( System . Convert . ToInt32 ( i ) , 1 ) ;
12+ return FromNumberToHex ( i , 1 ) ;
1313 }
1414
15- public static string FromInt16ToHex ( int i )
15+ public static string FromInt16ToHex ( Int16 i )
1616 {
17- return FromNoToHex ( i , 2 ) ;
17+ return FromNumberToHex ( i , 2 ) ;
1818 }
1919
20- public static string FromInt32ToHex ( int i )
20+ public static string FromInt32ToHex ( Int32 i )
2121 {
22- return FromNoToHex ( i , 4 ) ;
22+ return FromNumberToHex ( i , 4 ) ;
2323 }
2424
2525 public static string FromInt64ToHex ( long i )
2626 {
27- return FromNoToHex ( i , 8 ) ;
27+ return FromNumberToHex ( i , 8 ) ;
2828 }
2929
30- private static string FromNoToHex ( long i , int size )
30+ private static string FromNumberToHex ( long i , int size )
3131 {
32- return FromNoToHex ( System . Convert . ToByte ( i ) , size ) ;
32+ return FromNumberToHex ( BitConverter . GetBytes ( i ) , size ) ;
3333 }
3434
35- private static string FromNoToHex ( byte i , int size )
35+ private static string FromNumberToHex ( byte [ ] i , int size )
3636 {
37- var a = new byte [ size ] ;
38- a [ 0 ] = i ;
39- return BitConverter . ToString ( a ) . NormalizeString ( ) ;
37+ return BitConverter . ToString ( i . Take ( size ) . ToArray ( ) ) . NormalizeString ( ) ;
4038 }
4139
4240 public static byte FromHexToByte ( string hex )
@@ -46,20 +44,22 @@ public static byte FromHexToByte(string hex)
4644
4745 public static int FromHexToInt16 ( string hex )
4846 {
49- return BitConverter . ToInt16 ( FromHexToNo ( hex , 4 ) , 0 ) ;
47+ return BitConverter . ToInt16 ( FromHexToBytes ( hex , 4 ) , 0 ) is Int16 n && n == - 1 ? int . MaxValue : n ;
5048 }
5149
5250 public static int FromHexToInt32 ( string hex )
5351 {
54- return BitConverter . ToInt32 ( FromHexToNo ( hex , 8 ) , 0 ) ;
52+ return
53+ BitConverter . ToInt32 ( FromHexToBytes ( hex , 8 ) , 0 ) is Int32 n && n == - 1 ? Int32 . MaxValue : n ;
5554 }
5655
5756 public static long FromHexToInt64 ( string hex )
5857 {
59- return BitConverter . ToInt64 ( FromHexToNo ( hex , 16 ) , 0 ) ;
58+ return
59+ BitConverter . ToInt64 ( FromHexToBytes ( hex , 16 ) , 0 ) is Int64 n && n == - 1 ? Int64 . MaxValue : n ;
6060 }
6161
62- public static byte [ ] FromHexToNo ( string hex , int size )
62+ public static byte [ ] FromHexToBytes ( string hex , int size )
6363 {
6464 hex = hex . RemoveSeparators ( ) ;
6565 if ( hex . Length < size )
@@ -71,7 +71,7 @@ public static byte[] FromHexToNo(string hex, int size)
7171 }
7272 hex = sb . ToString ( ) ;
7373 }
74- byte [ ] raw = new byte [ size / 2 ] ;
74+ byte [ ] raw = new byte [ size ] ;
7575 for ( int i = 0 ; i < raw . Length / 2 ; i ++ )
7676 {
7777 raw [ i ] = System . Convert . ToByte ( hex . Substring ( i * 2 , 2 ) , 16 ) ;
0 commit comments