public unsafe static string EncodeBuffer(void *src, int buffSize) { string result; byte[] EncBuf = new byte[BUFFERSIZE]; byte[] TempBuf = new byte[BUFFERSIZE]; byte[] data = new byte[buffSize]; fixed(byte *pb = data) { for (int i = 0; i < buffSize; i++) { *(pb + i) = *((byte *)src + i); } } if (buffSize < BUFFERSIZE) { Array.Copy(data, 0, TempBuf, 0, buffSize); int DestLen = Encode6BitBuf(TempBuf, EncBuf, buffSize, BUFFERSIZE); fixed(byte *pb = EncBuf) { result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen); } } else { result = ""; } return(result); }
/// <summary> /// 解密Byte数组 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Src"></param> /// <param name="Buf"></param> /// <param name="bufsize"></param> /// <returns></returns> public unsafe static void DecodeBuffer <T>(string Src, ref T Buf) { byte[] EncBuf = new byte[BUFFERSIZE]; byte[] bSrc = System.Text.Encoding.Default.GetBytes(Src); Decode6BitBuf(bSrc, EncBuf, bSrc.Length, BUFFERSIZE); Buf = (T)HUtil32.BytesToStuct(EncBuf, Buf.GetType()); }
/// <summary> /// 构造魔法攻击值 /// </summary> /// <param name="StdItem"></param> /// <param name="dr"></param> /// <returns></returns> public static int MakeMC(double Mc, double Mc2, int nItemsPowerRate) { return(HUtil32.MakeLong( (UInt16)HUtil32.Round(Mc * GetActualScMcDcPowerRate(nItemsPowerRate)) , (UInt16)HUtil32.Round(Mc2 * GetActualScMcDcPowerRate(nItemsPowerRate)) )); }
public override string ToString() { fixed(sbyte *pb = this.Name) { return(HUtil32.SBytePtrToString(pb, 0, this.NameLen)); } }
/// <summary> /// 构造物理防御值 /// </summary> /// <param name="StdItem"></param> /// <param name="dr"></param> /// <returns></returns> public static int MakeAC(int Ac, int Ac2, int nItemsACPowerRate) { return(HUtil32.MakeLong( (UInt16)HUtil32.Round(Ac * GetActualAcMacPowerRate(nItemsACPowerRate)) , (UInt16)HUtil32.Round(Ac2 * GetActualAcMacPowerRate(nItemsACPowerRate)) )); }
/// <summary> /// 构造魔法防御值 /// </summary> /// <param name="StdItem"></param> /// <param name="dr"></param> /// <returns></returns> public static int MakeMAC(double Mac, double Mac2, int nItemsACPowerRate) { return(HUtil32.MakeLong( (UInt16)HUtil32.Round(Mac * GetActualAcMacPowerRate(nItemsACPowerRate)) , (UInt16)HUtil32.Round(Mac2 * GetActualAcMacPowerRate(nItemsACPowerRate)) )); }
/// <summary> /// 字符串转sbyte /// </summary> /// <param name="str"></param> /// <returns></returns> public unsafe static sbyte StringToSbyte(string str) { byte[] bMsg = HUtil32.StringToByteAry(str); IntPtr Buff = Marshal.AllocHGlobal(bMsg.Length + sizeof(int)); *(int *)Buff = bMsg.Length; Marshal.Copy(bMsg, 0, (IntPtr)((byte *)Buff + sizeof(int)), bMsg.Length); return((sbyte)Buff); }
/// <summary> /// 解密消息 /// </summary> /// <param name="str"></param> /// <returns></returns> public unsafe static TDefaultMessage DecodeMessage(string str) { byte[] EncBuf = new byte[BUFFERSIZE]; TDefaultMessage Msg; byte[] bSrc = HUtil32.StringToByteAry(str); Decode6BitBuf(bSrc, EncBuf, bSrc.Length, BUFFERSIZE); fixed(byte *pb = EncBuf) { Msg = *(TDefaultMessage *)(pb); } return(Msg); }
/// <summary> /// 加密字符串 /// </summary> /// <param name="str"></param> /// <returns></returns> public unsafe static string EncodeString(string str) { string result; byte[] EncBuf = new byte[BUFFERSIZE]; byte[] bSrc = HUtil32.StringToByteAry(str); int DestLen = Encode6BitBuf(bSrc, EncBuf, bSrc.Length, BUFFERSIZE); fixed(byte *pb = EncBuf) { result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen); } return(result); }
/// <summary> /// 解密Byte数组 /// </summary> /// <param name="Src"></param> /// <param name="Buf"></param> /// <param name="bufsize"></param> /// <returns></returns> public unsafe static string DecodeBuffer(string Src, byte[] Buf, int bufsize) { string result; byte[] EncBuf = new byte[BUFFERSIZE]; byte[] bSrc = System.Text.Encoding.Default.GetBytes(Src); int nLen = Decode6BitBuf(bSrc, EncBuf, bSrc.Length, BUFFERSIZE); fixed(byte *pb = EncBuf) { result = HUtil32.SBytePtrToString((sbyte *)pb, 0, nLen); } return(result); }
/// <summary> /// 加密消息 /// </summary> /// <param name="sMsg"></param> /// <returns></returns> public unsafe static string EncodeMessage(TDefaultMessage sMsg) { string result = string.Empty; byte[] EncBuf = new byte[BUFFERSIZE]; byte[] TempBuf = new byte[BUFFERSIZE]; fixed(byte *pb = TempBuf) { *(TDefaultMessage *)(pb) = sMsg; } int DestLen = Encode6BitBuf(TempBuf, EncBuf, Marshal.SizeOf(typeof(TDefaultMessage)), BUFFERSIZE); fixed(byte *pb = EncBuf) { result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen); } return(result); }
/// <summary> /// 加密Byte数组 /// </summary> /// <param name="Buf"></param> /// <param name="bufsize"></param> /// <returns></returns> public unsafe static string EncodeBuffer(byte[] Buf, int bufsize) { string result; byte[] EncBuf = new byte[BUFFERSIZE]; byte[] TempBuf = new byte[BUFFERSIZE]; if (bufsize < BUFFERSIZE) { Array.Copy(Buf, 0, TempBuf, 0, bufsize); int DestLen = Encode6BitBuf(TempBuf, EncBuf, bufsize, BUFFERSIZE); fixed(byte *pb = EncBuf) { result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen); } } else { result = ""; } return(result); }
/// <summary> /// 解密字符串 /// </summary> /// <param name="str">密文</param> /// <param name="chinese">是否返回中文</param> /// <returns></returns> public unsafe static string DeCodeString(string str, bool chinese = false) { string result; byte[] EncBuf = new byte[BUFFERSIZE]; byte[] bSrc = HUtil32.StringToByteAry(str); int nLen = Decode6BitBuf(bSrc, EncBuf, bSrc.Length, BUFFERSIZE); fixed(byte *pb = EncBuf) { if (chinese) { result = HUtil32.SBytePtrToString((sbyte *)pb, nLen); } else { result = HUtil32.SBytePtrToString((sbyte *)pb, 0, nLen); } } return(result); }
/// <summary> /// 加密实体对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Buf"></param> /// <returns></returns> public unsafe static string EncodeBuffer <T>(T Buf) { string result; byte[] EncBuf = new byte[BUFFERSIZE]; byte[] TempBuf = new byte[BUFFERSIZE]; int bufsize = Marshal.SizeOf(Buf); byte[] data = HUtil32.StructToBytes(Buf); if (bufsize < BUFFERSIZE) { Array.Copy(data, 0, TempBuf, 0, bufsize); int DestLen = Encode6BitBuf(TempBuf, EncBuf, bufsize, EncBuf.Length); fixed(byte *pb = EncBuf) { result = HUtil32.SBytePtrToString((sbyte *)pb, 0, DestLen); } } else { result = ""; } return(result); }
/// <summary> /// 字符串转Sbyte* /// </summary> /// <param name="Source"></param> /// <param name="TagStr"></param> /// <param name="Size"></param> /// <param name="TagLen"></param> public unsafe static void StrToSbyte(this string Source, sbyte *TagStr, byte Size, ref byte TagLen) { HUtil32.StrToSByteArry(Source, TagStr, Size, ref TagLen); }
/// <summary> /// 字符串转Byte数组 /// </summary> /// <param name="Source"></param> /// <returns></returns> public static byte[] ToByte(this string Source) { return(HUtil32.StrToByte(Source)); }