Esempio n. 1
0
        public override int Serialize(byte[] codeplugContents, int address)
        {
            var contents    = new byte[CONTENTS_LENGTH].AsSpan();
            var nextAddress = address + CONTENTS_LENGTH + BlockSizeAdjustment;

            contents[EXTERNAL_CODEPLUG_VECTOR]     = (byte)(ExternalCodeplugVector / 0x100);
            contents[EXTERNAL_CODEPLUG_VECTOR + 1] = (byte)(ExternalCodeplugVector % 0x100);
            Encoding.ASCII.GetBytes(Serial).AsSpan().CopyTo(contents.Slice(SERIAL, 10));
            Encoding.ASCII.GetBytes(Model).AsSpan().CopyTo(contents.Slice(MODEL, 16));
            contents[CODEPLUG_VERSION]           = (byte)(InternalCodeplugVersion / 0x100);
            contents[CODEPLUG_VERSION + 1]       = (byte)(InternalCodeplugVersion % 0x100);
            contents[INTERNAL_CODEPLUG_SIZE]     = (byte)(InternalCodeplugSize / 0x100);
            contents[INTERNAL_CODEPLUG_SIZE + 1] = (byte)(InternalCodeplugSize % 0x100);
            Unknown1.AsSpan().CopyTo(contents.Slice(UNKNOWN1));
            nextAddress = SerializeChild(Block02, BLOCK_02_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block56, BLOCK_56_VECTOR, codeplugContents, nextAddress, contents);
            Unknown2.AsSpan().CopyTo(contents.Slice(UNKNOWN2));
            nextAddress = SerializeChild(Block10, BLOCK_10_VECTOR, codeplugContents, nextAddress, contents);
            Unknown3.AsSpan().CopyTo(contents.Slice(UNKNOWN3));
            AuthCode.AsSpan().CopyTo(contents.Slice(AUTH_CODE));
            Serializer(codeplugContents, address, contents);
            return(nextAddress);
        }
Esempio n. 2
0
        public override int Serialize(byte[] codeplugContents, int address)
        {
            var contents    = new byte[CONTENTS_LENGTH].AsSpan();
            var nextAddress = address + CONTENTS_LENGTH + BlockSizeAdjustment;

            Unknown1.AsSpan().CopyTo(contents.Slice(UNKNOWN1));
            Encoding.ASCII.GetBytes(Serial).AsSpan().CopyTo(contents.Slice(SERIAL, 10));
            Encoding.ASCII.GetBytes(Model).AsSpan().CopyTo(contents.Slice(MODEL, 16));
            contents[TIMESTAMP]            = SetDigits(TimeStamp.Year - 2000);
            contents[TIMESTAMP + 1]        = SetDigits(TimeStamp.Month);
            contents[TIMESTAMP + 2]        = SetDigits(TimeStamp.Day);
            contents[TIMESTAMP + 3]        = SetDigits(TimeStamp.Hour);
            contents[TIMESTAMP + 4]        = SetDigits(TimeStamp.Minute);
            contents[PROGRAMMING_SOURCE]   = (byte)ProgrammingSource;
            contents[CODEPLUG_VERSION]     = (byte)(ExternalCodeplugVersion / 0x100);
            contents[CODEPLUG_VERSION + 1] = (byte)(ExternalCodeplugVersion % 0x100);
            //External Code Block Size set at end, since size is not yet known.
            nextAddress = SerializeChild(Block31, BLOCK_31_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block3D, BLOCK_3D_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block36, BLOCK_36_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block55, BLOCK_55_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block54, BLOCK_54_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block51, BLOCK_51_VECTOR, codeplugContents, nextAddress, contents);
            if (DynamicRadio != null)
            {
                Debug.WriteLine($"Serialize {nextAddress:X4} XX Dynamic Radio Block - {String.Join(" ", Array.ConvertAll(DynamicRadio, x => x.ToString("X2")))}");
                DynamicRadioVector = nextAddress + 8;
                DynamicRadio.CopyTo(codeplugContents.AsSpan(nextAddress));
                nextAddress += DynamicRadio.Length;
            }
            else
            {
                DynamicRadioVector = 0;
            }
            contents[DYNAMIC_RADIO_VECTOR]     = (byte)(DynamicRadioVector / 0x100);
            contents[DYNAMIC_RADIO_VECTOR + 1] = (byte)(DynamicRadioVector % 0x100);
            nextAddress = SerializeChild(Block39, BLOCK_39_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block3B, BLOCK_3B_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block34, BLOCK_34_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block35, BLOCK_35_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block3C, BLOCK_3C_VECTOR, codeplugContents, nextAddress, contents);
            nextAddress = SerializeChild(Block73, BLOCK_73_VECTOR, codeplugContents, nextAddress, contents);
            Unknown2.AsSpan().CopyTo(contents.Slice(UNKNOWN2));
            if (DynamicModeSelect != null)
            {
                Debug.WriteLine($"Serialize {nextAddress:X4} XX Dynamic Mode Select Block - {String.Join(" ", Array.ConvertAll(DynamicModeSelect, x => x.ToString("X2")))}");
                DynamicModeSelectVector = nextAddress + 8;
                DynamicModeSelect.CopyTo(codeplugContents.AsSpan(nextAddress));
                nextAddress += DynamicModeSelect.Length;
            }
            else
            {
                DynamicModeSelectVector = 0;
            }
            contents[DYNAMIC_MODE_SELECT_VECTOR]     = (byte)(DynamicModeSelectVector / 0x100);
            contents[DYNAMIC_MODE_SELECT_VECTOR + 1] = (byte)(DynamicModeSelectVector % 0x100);
            Unknown3.AsSpan().CopyTo(contents.Slice(UNKNOWN3));

            ExternalCodeplugSize                 = nextAddress - address;
            contents[EXTERNAL_CODEPLUG_SIZE]     = (byte)(ExternalCodeplugSize / 0x100);
            contents[EXTERNAL_CODEPLUG_SIZE + 1] = (byte)(ExternalCodeplugSize % 0x100);

            Serializer(codeplugContents, address, contents);
            return(nextAddress);
        }