Ejemplo n.º 1
0
        public byte[] GetFinalData()
        {
            byte[] data = new byte[raw.Length];
            ByteHelper.ReplaceBytes(data, 0, raw);
            if (gameSave.GameType == GameTypes.Colosseum)
            {
                SaveColosseum(data);
                EncryptColosseum(data, ByteHelper.SubByteArray(0x1DFEC, data, 20));
            }
            else
            {
                SaveXD(data);
                EncryptXD(data, encryptionKeys);
            }

            return(data);
        }
Ejemplo n.º 2
0
        public override byte[] GetFinalData()
        {
            if (gameSave.GameType == GameTypes.Colosseum)
            {
                ByteHelper.ReplaceBytes(raw, 0, ((ColosseumPokePC)parent.PokePC).GetFinalData());

                SavePCPocket(28140);
            }
            else
            {
                ByteHelper.ReplaceBytes(raw, 0, ((XDPokePC)parent.PokePC).GetFinalData());

                SavePCPocket(47200);
            }

            return(raw);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Serializes message to byte array
        /// </summary>
        /// <returns></returns>
        public byte[] ToBytes()
        {
            var flags = GenerateFlags(this);

            var dataLength    = Data.Length;
            var isAckRequest  = (flags & (byte)EMessageFlag.AckRequest) > 0;
            var isAckResponse = (flags & (byte)EMessageFlag.AckResponse) > 0;

            var packetSize = 1                          // Flags
                             + 2                        // OpCode
                             + 4                        // Data Length
                             + dataLength               // Data
                             + (isAckRequest ? 4 : 0)   // Ack Request id
                             + (isAckResponse ? 5 : 0); // Ack Response id (int + byte);

            var messagePacket = new byte[packetSize];

            var pointer = 0;

            messagePacket[0] = flags;
            pointer++;             // Write Flags
            ByteHelper.CopyBytes(OpCode, messagePacket, pointer);
            pointer += 2;          // Write OpCode
            ByteHelper.CopyBytes(dataLength, messagePacket, pointer);
            pointer += 4;          // Data Length
            Array.Copy(Data, 0, messagePacket, pointer, dataLength);
            pointer += dataLength; // Data

            if (isAckRequest)
            {
                ByteHelper.CopyBytes(AckRequestId.Value, messagePacket, pointer);
                pointer += 4;
            }

            if (isAckResponse)
            {
                ByteHelper.CopyBytes(AckResponseId.Value, messagePacket, pointer);
                pointer += 4;

                // Status code
                messagePacket[pointer] = (byte)Status;
                pointer++;
            }

            return(messagePacket);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Set an LED to blink mode until it is deactivated again. LED will blink for blinkAmount times, then deactivate. Interval is in ms.
        /// </summary>
        /// <param name="led"></param>
        /// <param name="interval"></param>
        public void BlinkLED(short led, byte red, byte green, byte blue, short interval, byte blinkAmount)
        {
            byte[] ledByte      = ByteHelper.ToBytes(led);
            byte[] intervalByte = ByteHelper.ToBytes(interval);

            ledBlinkAmountMsg[0] = LED_BLINK_AMOUNT;
            ledBlinkAmountMsg[1] = ledByte[0];
            ledBlinkAmountMsg[2] = ledByte[1];
            ledBlinkAmountMsg[3] = red;
            ledBlinkAmountMsg[4] = green;
            ledBlinkAmountMsg[5] = blue;
            ledBlinkAmountMsg[6] = intervalByte[0];
            ledBlinkAmountMsg[7] = intervalByte[1];
            ledBlinkAmountMsg[8] = blinkAmount;

            Write(ledBlinkAmountMsg);
        }
Ejemplo n.º 5
0
        public byte[] ToBytes()
        {
            var len = ByteHelper.ConvertToBytes(BodyLength);

            var data = new List <byte>();

            data.AddRange(len);

            data.Add(Type);

            if (Content != null)
            {
                data.AddRange(Content);
            }

            return(data.ToArray());
        }
Ejemplo n.º 6
0
        public static DHCPv6PacketTrueOption FromByteArray(Byte[] data, Int32 offset)
        {
            if (data == null || data.Length < offset + 4 + _expectedDataLength)
            {
                throw new ArgumentException(nameof(data));
            }

            UInt16 code   = ByteHelper.ConvertToUInt16FromByte(data, offset);
            UInt16 length = ByteHelper.ConvertToUInt16FromByte(data, offset + 2);

            if (length != _expectedDataLength)
            {
                throw new ArgumentException(nameof(data));
            }

            return(new DHCPv6PacketTrueOption(code));
        }
Ejemplo n.º 7
0
 //flag是用来判断传进来的msg前面是否需要加上uName:,也就是判断是不是系统信息,是系统信息的话就设置flag为false
 public static void PushMessage(Packet pct, Dictionary <String, Socket> clientList)
 {
     byte[] data = ByteHelper.Serialize(pct);
     if (string.IsNullOrWhiteSpace(pct.toNo))
     {
         foreach (var item in clientList)
         {
             Socket brdcastSocket = (Socket)item.Value;
             //String msgTemp = null;
             //Byte[] castBytes = new Byte[4096];
             try
             {
                 var len  = data.Length;
                 int leng = BitConverter.GetBytes(data.Length).Length;
                 brdcastSocket.Send(BitConverter.GetBytes(data.Length));
                 brdcastSocket.Send(data);
             }
             catch (Exception e)
             {
                 brdcastSocket.Close();
                 brdcastSocket = null;
                 File.AppendAllText("D:\\Exception.txt", e.ToString() + "\r\nPushMessage\r\n" + DateTime.Now.ToString() + "\r\n");
                 continue;
             }
         }
     }
     else
     {
         var toClient = clientList[pct.toNo];
         if (toClient != null)
         {
             Socket brdcastSocket = (Socket)toClient;
             try
             {
                 brdcastSocket.Send(BitConverter.GetBytes(data.Length));
                 brdcastSocket.Send(data);
             }
             catch (Exception e)
             {
                 toClient.Close();
                 brdcastSocket = null;
                 File.AppendAllText("D:\\Exception.txt", e.ToString() + "\r\nPushMessage\r\n" + DateTime.Now.ToString() + "\r\n");
             }
         }
     }
 }
Ejemplo n.º 8
0
        public GeobaseLocationView FindLocationByIp(string ipString)
        {
            var stopwatch = Stopwatch.StartNew();

            var ipUint         = IpHelper.IpStringToUint(ipString);
            int locactionIndex = -1;

            // binary search
            int min = 0;
            int max = (RangesFromTo.Item2 - RangesFromTo.Item1) / RangesLengh - 1;  // equal to Records

            while (min <= max)
            {
                int mid = (min + max) / 2;

                var offset = RangesFromTo.Item1 + mid * RangesLengh;
                var ipFrom = ByteHelper.GetUInt(Bytes, ref offset, true);
                var ipTo   = ByteHelper.GetUInt(Bytes, ref offset, true);

                if (ipFrom <= ipUint && ipTo >= ipUint)
                {
                    locactionIndex = (int)ByteHelper.GetUInt(Bytes, ref offset, true);
                    break;
                }
                else if (ipUint < ipFrom)
                {
                    max = mid - 1;
                }
                else
                {
                    min = mid + 1;
                }
            }

            if (locactionIndex < 0)
            {
                Debug.WriteLine("GeobaseEngineDirrect, FindLocationByIp, ip = " + ipString + " time: " + stopwatch.Elapsed.TotalMilliseconds + " ms. Result: NOT FOUND");
                return(null);
            }

            var locationOffset = LocationsFromTo.Item1 + LocationLengh * locactionIndex;

            Debug.WriteLine("GeobaseEngineDirrect, FindLocationByIp, ip = " + ipString + " time: " + stopwatch.Elapsed.TotalMilliseconds + " ms");

            return(GetLocation(Bytes, (int)locationOffset));
        }
Ejemplo n.º 9
0
        public bool TwriteDWord(PPIReadWritePara writePara)
        {
            //if (writeValue > uint.MaxValue)
            //{
            //    return false;
            //}//最大写入值0xffffffff,4,294,967,295
            int  i = 0;
            byte fcs;

            PPIAddress ppiAddress = new PPIAddress();

            byte[] TWritebyte = ppiAddress.TWritebyte;


            writePara.ByteAddress = writePara.ByteAddress * 8;

            //偏移量,byte 28,29,30 存储器偏移量指针 (存储器地址 *8 ):
            //  如 VB100,存储器地址为 100,偏移量指针为 800,转换成 16
            //进制就是 320H,则 Byte 28~29 这三个字节就是: 00 03 20

            // buffer[11] = Convert.ToByte(address & 0xff);//地位,如320H,结果为20
            //buffer[10] = Convert.ToByte((address / 0x100) & 0xff);//0x100 ->256
            //buffer[9] = Convert.ToByte(address / 0x10000);
            TWritebyte[28] = Convert.ToByte(writePara.ByteAddress / 0x10000);
            TWritebyte[29] = Convert.ToByte((writePara.ByteAddress / 0x100) & 0xff); //0x100 ->256;
            TWritebyte[30] = Convert.ToByte(writePara.ByteAddress & 0xff);           //低位,如320H,结果为20;

            TWritebyte[36] = Convert.ToByte(writePara.WriteValue / 0x1000000);
            TWritebyte[37] = Convert.ToByte((writePara.WriteValue / 0x10000) & 0xff);
            TWritebyte[38] = Convert.ToByte((writePara.WriteValue / 0x100) & 0xff);
            TWritebyte[39] = Convert.ToByte(writePara.WriteValue % 256);

            for (i = 4, fcs = 0; i < TWritebyte.Length - 2; i++)
            {
                fcs += TWritebyte[i];
            }

            int tt = Convert.ToInt32(fcs) % 256;//添加的代码 mod 256

            TWritebyte[TWritebyte.Length - 2] = Convert.ToByte(tt);


            byte[] SendData = ByteHelper.MergerArray(new byte[] { Convert.ToByte(writePara.ComNum) }, TWritebyte);

            return(WriteData(writePara.TcpClient, SendData, ppiAddress, writePara.ComNum));
        }
Ejemplo n.º 10
0
        public void TestReverseEndianness()
        {
            byte[] arr = ByteHelper.GetRandom(32);
            byte[] rra = arr.ReverseEndianness();
            for (var i = 0; i < 32; i++)
            {
                Assert.AreEqual(arr[i], rra[31 - i]);
            }

            arr = ByteHelper.GetRandom(64);
            rra = arr.ReverseEndianness();
            for (var i = 0; i < 32; i++)
            {
                Assert.AreEqual(arr[i], rra[31 - i]);
                Assert.AreEqual(arr[i + 32], rra[63 - i]);
            }
        }
Ejemplo n.º 11
0
        public void TestWriteSessionId()
        {
            Guid value     = new Guid();
            var  name      = "test";
            var  attribute = XFireAttributeFactory.Instance.GetAttribute(value.GetType());

            using (var ms = new MemoryStream())
            {
                using (var writer = new BinaryWriter(ms))
                {
                    attribute.WriteAll(writer, name, value);
                }

                var expected = ByteHelper.CombineByteArray(new byte[] { 0x04, 0x74, 0x65, 0x73, 0x74, 0x03 }, value.ToByteArray());
                Assert.IsTrue(ms.ToArray().SequenceEqual(expected));
            }
        }
Ejemplo n.º 12
0
 public void LoadPart2(byte[] data)
 {
     if (raw == null)
     {
         raw = new byte[36 * 16];
     }
     ByteHelper.ReplaceBytes(raw, 36 * 12, data);
     for (int i = 0; i < 4; i++)
     {
         Mail mail = new Mail(ByteHelper.SubByteArray(i * 36, data, 36));
         mail.Mailbox = this;
         if (mail.MailItemID != 0)
         {
             this.boxMail.Add(mail);
         }
     }
 }
Ejemplo n.º 13
0
        public DaycareData(GCGameSave gameSave, byte[] data, GCSaveData parent)
            : base(gameSave, data, parent)
        {
            if (parent.Inventory.Items == null)
            {
                parent.Inventory.AddItemInventory();
            }

            if (gameSave.GameType == GameTypes.Colosseum)
            {
                ((ColosseumPokePC)parent.PokePC).AddDaycare(ByteHelper.SubByteArray(0, data, 0x140));
            }
            else
            {
                ((XDPokePC)parent.PokePC).AddDaycare(ByteHelper.SubByteArray(0, data, 0xCC));
            }
        }
Ejemplo n.º 14
0
        public static void SendRequest(this SerialPort serialPort, Command command)
        {
            Log.Information("SendRequest -- command : {@Command}", command);

            // cf. Request Packets’ Format (p. 6)
            byte commandByte = CommandHelper.GetByte(command);

            byte[] packetBytes = { Constants.SYNC_BYTE, commandByte };

            string hexString = ByteHelper.ToHexString(packetBytes);

            Log.Information("SendRequest -- packetBytes : {@HexString}", hexString);

            //TODO: Add payload

            serialPort.Write(packetBytes, 0, packetBytes.Length);
        }
        public void StringSpeedTest_Comparison()
        {
            var str1       = "111";
            var str2       = "222";
            var iterations = 1000000;

            var strA = Encoding.ASCII.GetBytes(str1);
            var strB = new ArraySegment <byte>(Encoding.ASCII.GetBytes(str2));

            var stopwatch = Stopwatch.StartNew();

            int comparisonResult = 0;

            for (int i = 1; i < iterations; i++)
            {
                comparisonResult = ByteHelper.CompareStringsAsBytes(strA, strB);

                strA = Encoding.ASCII.GetBytes(str1 + i);
                strB = new ArraySegment <byte>(Encoding.ASCII.GetBytes(str2 + i));
            }

            stopwatch.Stop();
            Console.WriteLine("ByteHelper.CompareStringsAsBytes time: " + stopwatch.Elapsed.TotalMilliseconds + " ms., result: " + comparisonResult);
            stopwatch.Restart();

            for (int i = 1; i < iterations; i++)
            {
                comparisonResult = string.CompareOrdinal(str1 + i, str2 + i);
            }

            stopwatch.Stop();
            Console.WriteLine("string.CompareOrdinal time: " + stopwatch.Elapsed.TotalMilliseconds + " ms., result: " + comparisonResult);
            stopwatch.Restart();

            var strB2 = Encoding.ASCII.GetBytes(str2);

            for (int i = 1; i < iterations; i++)
            {
                comparisonResult = ByteHelper.CompareStrings(str1 + i, strB2, 3, 0);
                strB2            = Encoding.ASCII.GetBytes(str2 + i);
            }

            stopwatch.Stop();
            Console.WriteLine("ByteHelper.CompareStrings time: " + stopwatch.Elapsed.TotalMilliseconds + " ms., result: " + comparisonResult);
            stopwatch.Restart();
        }
Ejemplo n.º 16
0
        public static DHCPv6PacketOptionRequestOption FromByteArray(Byte[] data, Int32 offset)
        {
            UInt16 length = ByteHelper.ConvertToUInt16FromByte(data, offset + 2);

            Int32 pointer = offset + 4;

            UInt16[] options = new UInt16[length / 2];
            for (int i = 0; i < length / 2; i++)
            {
                UInt16 optionCode = ByteHelper.ConvertToUInt16FromByte(data, pointer);
                options[i] = optionCode;

                pointer += 2;
            }

            return(new DHCPv6PacketOptionRequestOption(options));
        }
Ejemplo n.º 17
0
        public byte[] GetAsBytes()
        {
            byte[] bytes = new byte[Size];

            ByteHelper.WriteShort(X, bytes, 0x0);
            ByteHelper.WriteShort(Y, bytes, 0x2);
            ByteHelper.WriteShort(Z, bytes, 0x4);
            ByteHelper.WriteShort(Unk, bytes, 0x6);
            ByteHelper.WriteShort(S, bytes, 0x8);
            ByteHelper.WriteShort(T, bytes, 0xA);
            ByteHelper.WriteByte(R, bytes, 0xC);
            ByteHelper.WriteByte(G, bytes, 0xD);
            ByteHelper.WriteByte(B, bytes, 0xE);
            ByteHelper.WriteByte(A, bytes, 0xF);

            return(bytes);
        }
Ejemplo n.º 18
0
        public void ApplyValues()
        {
            Random random = new Random();

            UInt16 index  = (UInt16)random.Next(0, 10);
            UInt16 slotId = (UInt16)random.Next(0, 10);
            UInt16 portId = (UInt16)random.Next(0, 10);

            Byte[] macAddress = random.NextBytes(6);

            String macAddressInput = ByteHelper.ToString(macAddress, false);

            Mock <ISerializer> serializerMock = new Mock <ISerializer>(MockBehavior.Strict);

            serializerMock.Setup(x => x.Deserialze <UInt16>(index.ToString())).Returns(index).Verifiable();
            serializerMock.Setup(x => x.Deserialze <UInt16>(slotId.ToString())).Returns(slotId).Verifiable();
            serializerMock.Setup(x => x.Deserialze <UInt16>(portId.ToString())).Returns(portId).Verifiable();
            serializerMock.Setup(x => x.Deserialze <String>(macAddressInput)).Returns(macAddressInput).Verifiable();

            var resolver = new DHCPv6SimpleZyxelIESResolver();

            resolver.ApplyValues(new Dictionary <String, String> {
                { "Index", index.ToString() },
                { "SlotId", slotId.ToString() },
                { "PortId", portId.ToString() },
                { "DeviceMacAddress", macAddressInput },
            }, serializerMock.Object);

            Assert.Equal(index, resolver.Index);
            Assert.Equal(slotId, resolver.SlotId);
            Assert.Equal(portId, resolver.PortId);
            Assert.Equal(macAddress, resolver.DeviceMacAddress);

            serializerMock.Verify();

            Dictionary <String, String> expectedValues = new Dictionary <string, string>
            {
                { "Index", index.ToString() },
                { "SlotId", slotId.ToString() },
                { "PortId", portId.ToString() },
                { "DeviceMacAddress", macAddressInput },
            };

            Assert.Equal(expectedValues.ToArray(), resolver.GetValues().ToArray());
            Assert.Equal(expectedValues, resolver.GetValues(), new NonStrictDictionaryComparer <String, String>());
        }
Ejemplo n.º 19
0
        private void Udp_DGramRecieved1(object sender, BUDPGram dgram)
        {
            if (resultList == null)
            {
                resultList = new CommandResultManager();
            }

            var group = resultList.Add(dgram.iep, dgram.data);

            group.Archor.Value = ByteHelper.byteToHexStr(dgram.data);

            valueList.Add(dgram.iep, dgram.data);
            AddLog(string.Format("收到 :: {0}", group.ToString()));


            archorList = OnDataReceive(group);
        }
Ejemplo n.º 20
0
        private bool AnalyzePackageData(byte[] data, out UnPackageError unPackageError)
        {
            bool _result = false;

            try
            {
                FullPackageData       = ByteHelper.ToHexStringWithBlank(data);
                TransactionIdentifier = ArrayHelper.Copy(data, 0, 2); //事物标识符
                ProtocolIdentifier    = ArrayHelper.Copy(data, 2, 4); //协议标识符
                Length         = ArrayHelper.Copy(data, 4, 6);        //长度
                SlaveID        = data[6];                             //从设备地址
                OrderCmd       = data[7];                             //功能码
                unPackageError = UnPackageError.Normal;
                if (data.Length == 9)
                {
                    byte _errorCode = data[8];//错误代码
                    if (_errorCode == 0x01 || _errorCode == 0x02 || _errorCode == 0x03 || _errorCode == 0x04)
                    {
                        unPackageError = (UnPackageError)_errorCode;
                    }
                }
                else
                {
                    //00 77 00 00 00 05 02 01 02 1F 00--Read Coils
                    //00 74 --事物标识符
                    //00 00 --协议标识符
                    //00 05 --长度
                    //02--从机地址
                    //01--功能码
                    //02 --数据长度
                    //1F 00--数据

                    DataLength = data[8];                                   //数据长度
                    Data       = ArrayHelper.Copy(data, 9, 9 + DataLength); //实际数据

                    _result = true;
                }
            }
            catch (Exception ex)
            {
                throw CreateUnPackageException("AnalyzePackageData", ex, data);
            }

            return(_result);
        }
Ejemplo n.º 21
0
        private void SaveColosseum(byte[] data)
        {
            ByteHelper.ReplaceBytes(data, 120, playerData.GetFinalData());
            ByteHelper.ReplaceBytes(data, 2960, pcData.GetFinalData());
            ByteHelper.ReplaceBytes(data, 33136, daycareData.GetFinalData());
            ByteHelper.ReplaceBytes(data, 33456, memoData.GetFinalData());

            byte[] previousChecksum       = ByteHelper.SubByteArray(0x1dfec, data, 20);
            int    previousHeaderChecksum = BigEndian.ToSInt32(data, 12);

            BigEndian.WriteUInt32(0, data, 12);
            SHA1 sha1 = SHA1.Create();

            byte[] checksum = new byte[20];
            checksum = sha1.ComputeHash(ByteHelper.SubByteArray(0, data, 0x1dfd8));

            byte[] D      = new byte[8];
            byte[] H      = new byte[8];
            byte[] tmpBuf = new byte[8];

            ByteHelper.ReplaceBytes(H, 0, ByteHelper.SubByteArray(0, checksum, 8));
            ByteHelper.ReplaceBytes(D, 0, ByteHelper.SubByteArray(0x18, data, 8));

            for (int i = 0; i < 8; i++)
            {
                D[i] ^= (byte)~H[i];
            }

            ByteHelper.ReplaceBytes(tmpBuf, 0, D);

            int newHC = 0;

            for (int i = 0; i < 0x18; i += 4)
            {
                newHC -= BigEndian.ToSInt32(data, i);
            }

            newHC -= BigEndian.ToSInt32(tmpBuf, 0);
            newHC -= BigEndian.ToSInt32(tmpBuf, 4);

            BigEndian.WriteSInt32(newHC, data, 12);

            ByteHelper.ReplaceBytes(data, 0x1dfd8, randomBytes);
            ByteHelper.ReplaceBytes(data, 0x1dfec, checksum);
        }
Ejemplo n.º 22
0
        public override MotorBaseResponse Decode(OriginalBytes obytes)
        {
            if (obytes.Data.Length != 164)
            {
                return(null);
            }
            byte             commandCode    = obytes.Data[6];
            byte             additionalCode = obytes.Data[7];
            MotorC40Response m40r           = new MotorC40Response(commandCode, additionalCode);

            if (m40r.AdditionCode == 0xAA)
            {
                //读回应
                m40r.CommandCode  = obytes.Data[6];
                m40r.AdditionCode = obytes.Data[7];
                Array.Copy(obytes.Data, 8, m40r.CodeArea.DataLength, 0, 2);
                m40r.CodeArea.Data = new byte[m40r.CodeArea.Length];
                Array.Copy(obytes.Data, 10, m40r.CodeArea.Data, 0, m40r.CodeArea.Length);
                Array.Copy(obytes.Data, 10 + m40r.CodeArea.Length, m40r.CodeArea.CRC16Code, 0, 2);

                m40r.SystemFlowStatus    = m40r.CodeArea.Data[0];
                m40r.Motor1Switch        = m40r.CodeArea.Data[1];
                m40r.Motor1Status        = m40r.CodeArea.Data[2];
                m40r.Motor1completeSteps = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 3);
                m40r.Motor1Steps         = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 7);

                m40r.Motor2Switch        = m40r.CodeArea.Data[11];
                m40r.Motor2Status        = m40r.CodeArea.Data[12];
                m40r.Motor2completeSteps = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 13);
                m40r.Motor2Steps         = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 17);

                m40r.Voltage1    = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 21);
                m40r.Voltage2    = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 25);
                m40r.Temperature = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 29);
                m40r.M1V1        = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 33);
                m40r.M1V2        = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 37);
                m40r.M2V1        = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 41);
                m40r.M2V2        = ByteHelper.BytesToInt2(m40r.CodeArea.Data, 45);

                Array.Copy(m40r.CodeArea.Data, 100, m40r.ErrorAlarmCodes, 0, 50);
            }

            m40r.BasePackage = new CIIBasePackage(m40r.CodeArea, false);
            return(m40r);
        }
Ejemplo n.º 23
0
        public byte[] GetAsBytes()
        {
            byte[] bytes = new byte[Size];

            ByteHelper.WriteUInt(OverlayStart, bytes, 0x0);
            ByteHelper.WriteUInt(OverlayEnd, bytes, 0x4);
            ByteHelper.WriteUInt(Loc1Start, bytes, 0x8);
            ByteHelper.WriteUInt(Loc1End, bytes, 0xC);
            ByteHelper.WriteUInt(Loc2Start, bytes, 0x10);
            ByteHelper.WriteUInt(Loc2End, bytes, 0x14);
            ByteHelper.WriteUInt(Loc3Start, bytes, 0x18);
            ByteHelper.WriteUInt(Loc3End, bytes, 0x1C);
            ByteHelper.WriteUInt(Seg1Start, bytes, 0x20);
            ByteHelper.WriteUInt(Seg1End, bytes, 0x24);
            ByteHelper.WriteUInt(Seg2Start, bytes, 0x28);
            ByteHelper.WriteUInt(Seg2End, bytes, 0x2C);
            ByteHelper.WriteUInt(Seg3Start, bytes, 0x30);
            ByteHelper.WriteUInt(Seg3End, bytes, 0x34);
            ByteHelper.WriteUInt(Seg4Start, bytes, 0x38);
            ByteHelper.WriteUInt(Seg4End, bytes, 0x3C);
            ByteHelper.WriteUInt(Seg5Start, bytes, 0x40);
            ByteHelper.WriteUInt(Seg5End, bytes, 0x44);
            ByteHelper.WriteUInt(Seg6Start, bytes, 0x48);
            ByteHelper.WriteUInt(Seg6End, bytes, 0x4C);
            ByteHelper.WriteUInt(Seg7Start, bytes, 0x50);
            ByteHelper.WriteUInt(Seg7End, bytes, 0x54);
            ByteHelper.WriteUInt(Seg8Start, bytes, 0x58);
            ByteHelper.WriteUInt(Seg8End, bytes, 0x5C);
            ByteHelper.WriteUInt(Seg9Start, bytes, 0x60);
            ByteHelper.WriteUInt(Seg9End, bytes, 0x64);
            ByteHelper.WriteUInt(SegAStart, bytes, 0x68);
            ByteHelper.WriteUInt(SegAEnd, bytes, 0x6C);
            ByteHelper.WriteUInt(SegBStart, bytes, 0x70);
            ByteHelper.WriteUInt(SegBEnd, bytes, 0x74);
            ByteHelper.WriteUInt(SegCStart, bytes, 0x78);
            ByteHelper.WriteUInt(SegCEnd, bytes, 0x7C);
            ByteHelper.WriteUInt(SegDStart, bytes, 0x80);
            ByteHelper.WriteUInt(SegDEnd, bytes, 0x84);
            ByteHelper.WriteUInt(SegEStart, bytes, 0x88);
            ByteHelper.WriteUInt(SegEEnd, bytes, 0x8C);
            ByteHelper.WriteUInt(SegFStart, bytes, 0x90);
            ByteHelper.WriteUInt(SegFEnd, bytes, 0x94);

            return(bytes);
        }
Ejemplo n.º 24
0
        public void SetFinalStorageData(byte[] data)
        {
            // Data is the size of the combined 2 boxes A and B

            for (int i = 0; i < 30; i++)
            {
                int boxIndex = (i % 6) + (i / 6) * 12 + (!boxA ? 6 : 0);

                if (pokemonList[i] != null)
                {
                    ByteHelper.ReplaceBytes(data, boxIndex * 84, pokemonList[i].GetFinalData());
                }
                else
                {
                    ByteHelper.ReplaceBytes(data, boxIndex * 84, new byte[84]);
                }
            }
        }
Ejemplo n.º 25
0
 public DHCPv6PacketIdentityAssociationPrefixDelegationSuboption(
     TimeSpan preferedLifetime, TimeSpan validLifetime, Byte prefixLength, IPv6Address address,
     IEnumerable <DHCPv6PacketSuboption> suboptions)
     : base((UInt16)DHCPv6PacketSuboptionsType.IdentityAssociationPrefixDelegation,
            ByteHelper.ConcatBytes(
                ByteHelper.GetBytes((UInt32)preferedLifetime.TotalSeconds),
                ByteHelper.GetBytes((UInt32)validLifetime.TotalSeconds),
                new Byte[] { prefixLength },
                address.GetBytes(),
                ByteHelper.ConcatBytes(suboptions.Select(x => x.GetByteStream()))
                ))
 {
     Address           = address;
     PreferredLifetime = preferedLifetime;
     ValidLifetime     = validLifetime;
     PrefixLength      = prefixLength;
     Suboptions        = new List <DHCPv6PacketSuboption>(suboptions);
 }
Ejemplo n.º 26
0
        public StrategyMemoData(GCGameSave gameSave, byte[] data, GCSaveData parent)
            : base(gameSave, data, parent)
        {
            this.entries = new List <StrategyMemoEntry>();
            ushort numEntries = Math.Min((ushort)500, BigEndian.ToUInt16(data, 0));

            //numEntries = 500;
            for (int i = 0; i < numEntries; i++)
            {
                entries.Add(new StrategyMemoEntry(ByteHelper.SubByteArray(4 + i * 12, data, 12), gameSave.GameType == GameTypes.XD));

                // Remove invalid entries caused by Trigger's PC corruption.
                if (entries[entries.Count - 1].SpeciesID == 0)
                {
                    entries.RemoveAt(entries.Count - 1);
                }
            }
        }
Ejemplo n.º 27
0
        public string[] GetCommand(string[] Stcds, string NFOINDEX, out string CommandCode)
        {
            CommandCode = "4C";
            string[] commands      = new string[Stcds.Length];
            string   _11000000AA04 = Get4C();

            for (int i = 0; i < Stcds.Length; i++)
            {
                var model = from rtu in list where rtu.STCD == Stcds[i] select rtu;
                if (model.Count() > 0)
                {
                    Package package = Package.Create_0x4CPackage(Stcds[i], 1, UInt16.Parse(model.First().PassWord), _11000000AA04);
                    commands[i] = ByteHelper.ByteToHexStr(package.GetFrames()[1].ToBytes());
                }
            }

            return(commands);
        }
Ejemplo n.º 28
0
        public bool LoadFromBytes(byte[] bytes)
        {
            int count = bytes.Length / 4;

            Script = new uint[count];

            for (int i = 0; i < count; i++)
            {
                Script[i] = ByteHelper.ReadUInt(bytes, i * 4);

                if (AdvancedObjectIndex == -1 && (Script[i] & 0xFF000000) == 0xD0000000)
                {
                    AdvancedObjectIndex = (int)(Script[i] & 0x000000FF);
                }
            }

            return(true);
        }
Ejemplo n.º 29
0
        public void AreEqual_False()
        {
            Random random = new Random();

            Byte[] input = new Byte[1024];
            random.NextBytes(input);

            Byte[] copy = new Byte[1024];

            for (int i = 0; i < input.Length - 1; i++)
            {
                copy[i] = input[i];
            }

            Boolean result = ByteHelper.AreEqual(input, copy);

            Assert.False(result);
        }
Ejemplo n.º 30
0
        public static DHCPv6PacketUserClassOption FromByteArray(Byte[] data, Int32 offset)
        {
            UInt16 length = ByteHelper.ConvertToUInt16FromByte(data, offset + 2);

            Int32         pointer     = 0;
            List <Byte[]> userClasses = new List <byte[]>();

            while (pointer < length)
            {
                UInt16 classLength = ByteHelper.ConvertToUInt16FromByte(data, offset + 4 + pointer);
                Byte[] classData   = ByteHelper.CopyData(data, offset + 4 + pointer + 2, classLength);
                userClasses.Add(classData);

                pointer += 2 + classLength;
            }

            return(new DHCPv6PacketUserClassOption(userClasses));
        }