Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cs"></param>
        public ActorScriptSection(CustomSection cs)
        {
            var stream           = new MemoryStream((byte[])cs.Content);
            var reader           = new Reader(stream);
            var previousSection  = ActorScriptSubsection.Labels;
            var preSectionOffset = reader.Offset;

            while (reader.TryReadVarUInt7(out var id)) //At points where TryRead is used, the stream can safely end.
            {
                if (id != 0 && (ActorScriptSubsection)id < previousSection)
                {
                    throw new ModuleLoadException($"Sections out of order; section {(ActorScriptSubsection)id} encounterd after {previousSection}.", preSectionOffset);
                }
                var payloadLength = reader.ReadVarUInt32();

                switch ((ActorScriptSubsection)id)
                {
                case ActorScriptSubsection.Labels:
                {
                    var count = reader.ReadVarUInt32();
                    Labels = new LabelMap((int)count);
                    for (int i = 0; i < count; i++)
                    {
                        var index      = reader.ReadVarUInt32();
                        var nameLength = reader.ReadVarUInt32();
                        var name       = reader.ReadString(nameLength);
                        Labels.Add(index, name);
                    }
                }
                break;
                }

                previousSection = (ActorScriptSubsection)id;
            }
        }
Exemple #2
0
        public void CustomSection_PrecedingSectionValidity()
        {
            var custom = new CustomSection();

            foreach (var value in Enum.GetValues(typeof(Section)).Cast <Section>())
            {
                //All values of Section should be accepted.
                custom.PrecedingSection = value;
            }

            ExceptionAssert.Expect <ArgumentOutOfRangeException>(() => custom.PrecedingSection = (Section)255);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cs"></param>
        public NameSection(CustomSection cs)
        {
            var stream           = new MemoryStream((byte[])cs.Content);
            var reader           = new Reader(stream);
            var previousSection  = NameSubsection.Module;
            var preSectionOffset = reader.Offset;

            while (reader.TryReadVarUInt7(out var id)) //At points where TryRead is used, the stream can safely end.
            {
                if (id != 0 && (NameSubsection)id < previousSection)
                {
                    throw new ModuleLoadException($"Sections out of order; section {(NameSubsection)id} encounterd after {previousSection}.", preSectionOffset);
                }
                var payloadLength = reader.ReadVarUInt32();

                switch ((NameSubsection)id)
                {
                case NameSubsection.Module:
                {
                    var nameLength = reader.ReadVarUInt32();
                    Name = reader.ReadString(nameLength);
                }
                break;

                case NameSubsection.Function:
                {
                    var count = reader.ReadVarUInt32();
                    Functions = new FunctionMap((int)count);
                    for (int i = 0; i < count; i++)
                    {
                        var index      = reader.ReadVarUInt32();
                        var nameLength = reader.ReadVarUInt32();
                        var name       = reader.ReadString(nameLength);
                        Functions.Add(index, name);
                    }
                }
                break;

                case NameSubsection.Local:
                {
                    var fun_count = reader.ReadVarUInt32();
                    Locals = new LocalMap((int)fun_count);
                    for (int f = 0; f < fun_count; f++)
                    {
                        var fun_index = reader.ReadVarUInt32();

                        var count   = reader.ReadVarUInt32();
                        var nameMap = new NameMap((int)count);
                        Locals.Add(fun_index, nameMap);
                        for (int i = 0; i < count; i++)
                        {
                            var index      = reader.ReadVarUInt32();
                            var nameLength = reader.ReadVarUInt32();
                            var name       = reader.ReadString(nameLength);
                            nameMap.Add(index, name);
                        }
                    }
                }
                break;
                }

                previousSection = (NameSubsection)id;
            }
        }