Beispiel #1
0
        public void WriteScripts(AsmCollection asmCollection)
        {
            ArchiveFileEntry jsmEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".jsm");

            if (jsmEntry == null)
            {
                return;
            }

            JsmHeader           header     = new JsmHeader();
            List <JsmGroup>     groups     = new List <JsmGroup>(8);
            List <JsmScript>    scripts    = new List <JsmScript>(32);
            List <JsmOperation> operations = new List <JsmOperation>(512);

            foreach (AsmModule module in asmCollection.GetOrderedModules())
            {
                JsmGroup group = new JsmGroup(module.ExecutionOrder, module.Label, (byte)module.Count, (JsmModuleType)module.Type);
                header.IncrementCount(group.Type);
                groups.Add(group);
            }

            foreach (AsmModule module in asmCollection.GetOrderedModulesByIndex())
            {
                foreach (AsmEvent evt in module.GetOrderedEvents())
                {
                    JsmScript script = new JsmScript((ushort)operations.Count, evt.Flag);
                    scripts.Add(script);

                    foreach (JsmOperation command in evt)
                    {
                        operations.Add(command);
                    }
                }
            }

            scripts.Add(new JsmScript((ushort)operations.Count, false));

            header.ScriptsOffset    = (ushort)(8 + groups.Count * 2);
            header.OperationsOffset = (ushort)(header.ScriptsOffset + scripts.Count * 2);

            using (JsmFileWriter jsmWriter = new JsmFileWriter(jsmEntry.OpenWritableCapacityStream()))
                jsmWriter.WriteScripts(header, groups, scripts, operations);

            //ArchiveFileEntry symEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".sym");
            //if (symEntry == null)
            //    return;

            //using (SymFileWriter symWriter = new SymFileWriter(symEntry.OpenWritableCapacityStream()))
            //{
            //}
        }
Beispiel #2
0
        public void WriteScripts(AsmCollection scripts)
        {
            XmlElement node = _root.EnsureChildElement("Scripts");

            node.RemoveAll();

            bool isExists = scripts != null;

            node.SetBoolean("IsExists", isExists);

            if (!isExists)
            {
                return;
            }

            string scriptsFile = Path.ChangeExtension(_xmlPath, ".sct");

            using (Stream output = new FileStream(scriptsFile, FileMode.Create, FileAccess.Write, FileShare.None))
                using (BinaryWriter bw = new BinaryWriter(output, Encoding.UTF8))
                {
                    bw.Write("FF8S");
                    bw.Write(scripts.Count);

                    foreach (AsmModule module in scripts.GetOrderedModulesByIndex())
                    {
                        bw.Write(module.ExecutionOrder);
                        bw.Write(module.Label);
                        bw.Write(module.Title);
                        bw.Write((int)module.Type);
                        bw.Write(module.Count);

                        foreach (AsmEvent script in module.GetOrderedEvents())
                        {
                            bw.Write(script.Title);
                            bw.Write(script.Count);

                            foreach (JsmOperation operation in script)
                            {
                                bw.Write(operation.Operation);
                            }
                        }
                    }
                }
        }
Beispiel #3
0
        public bool ReadScripts(Location location)
        {
            if (_root == null)
            {
                return(false);
            }

            XmlElement node = _root["Scripts"];

            if (node == null)
            {
                return(false);
            }

            if (!node.GetBoolean("IsExists"))
            {
                return(true);
            }

            string scriptsFile = Path.ChangeExtension(_xmlPath, ".sct");

            if (!File.Exists(scriptsFile))
            {
                return(false);
            }

            using (Stream input = new FileStream(scriptsFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (BinaryReader br = new BinaryReader(input, Encoding.UTF8))
                {
                    string magicNumber = br.ReadString();
                    if (magicNumber != "FF8S")
                    {
                        throw Exceptions.CreateException("Неверное магическое число: '{0}'", magicNumber);
                    }

                    int           groupsCount    = br.ReadInt32();
                    AsmModule     previousModule = null;
                    AsmCollection groups         = new AsmCollection(groupsCount);
                    for (ushort g = 0; g < groupsCount; g++)
                    {
                        ushort        executionOrder = br.ReadUInt16();
                        ushort        label          = br.ReadUInt16();
                        string        title          = br.ReadString();
                        JsmModuleType type           = (JsmModuleType)br.ReadInt32();
                        int           scriptsCount   = br.ReadInt32();

                        AsmModule module = AsmModuleFactory.Create(type);
                        module.Index          = g;
                        module.ExecutionOrder = executionOrder;
                        module.Label          = label;
                        module.Title          = title;
                        module.PreviousModule = previousModule;
                        if (previousModule != null)
                        {
                            previousModule.NextModule = module;
                        }
                        previousModule = module;
                        groups.Add(label, module);
                        for (int s = 0; s < scriptsCount; s++)
                        {
                            string scriptLabel     = br.ReadString();
                            int    operationsCount = br.ReadInt32();

                            AsmEvent script = new AsmEvent(module, operationsCount)
                            {
                                Label = (ushort)(label + s + 1), Title = scriptLabel
                            };
                            module.SetEventByIndex(s, script);
                            for (int o = 0; o < operationsCount; o++)
                            {
                                JsmOperation operation = new JsmOperation(br.ReadUInt32());
                                script.Add(operation);
                            }
                        }
                    }
                    location.Scripts = groups;
                }

            location.SaveRequest &= ~LocationProperty.Scripts;
            location.Importable  |= LocationProperty.Scripts;
            return(true);
        }
Beispiel #4
0
        public bool ReadScripts(Location location)
        {
            ArchiveFileEntry jsmEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".jsm");

            if (jsmEntry == null)
            {
                return(true);
            }

            AsmCollection result;

            using (JsmFileReader jsmReader = new JsmFileReader(jsmEntry.OpenReadableContentStream()))
            {
                AsmModule previousModule = null;
                result = new AsmCollection(jsmReader.Groups.Length);
                for (ushort g = 0, s = 0, o = 0; g < jsmReader.Groups.Length; g++)
                {
                    JsmGroup  jsmGroup = jsmReader.Groups[g];
                    AsmModule asmGroup = AsmModuleFactory.Create(jsmGroup.Type);
                    asmGroup.Index          = g;
                    asmGroup.ExecutionOrder = jsmGroup.ExecutionOrder;
                    asmGroup.Label          = jsmGroup.Label;
                    asmGroup.Title          = jsmGroup.Label.ToString("D3");
                    asmGroup.PreviousModule = previousModule;
                    if (previousModule != null)
                    {
                        previousModule.NextModule = asmGroup;
                    }
                    previousModule = asmGroup;
                    result.Add(asmGroup.Label, asmGroup);

                    for (int i = 0; i < jsmGroup.ScriptsCount; i++)
                    {
                        JsmScript jsmScript = jsmReader.Scripts[s++];
                        AsmEvent  asmScript = new AsmEvent(asmGroup, jsmScript.OperationsCount)
                        {
                            Flag  = jsmScript.Flag,
                            Label = (ushort)(asmGroup.Label + i)
                        };
                        asmGroup.SetEventByIndex(i, asmScript);

                        for (int k = 0; k < jsmScript.OperationsCount; k++)
                        {
                            JsmOperation jsmOperation = jsmReader.Opertations[o++];
                            asmScript.Add(jsmOperation);
                        }
                    }
                }
            }

            ArchiveFileEntry symEntry = (ArchiveFileEntry)_locationDirectory.Childs.TryGetValue(_name + ".sym");

            if (symEntry == null)
            {
                location.Scripts = result;
                return(true);
            }

            using (SymFileReader symReader = new SymFileReader(symEntry.OpenReadableContentStream()))
            {
                foreach (AsmModule module in result.GetOrderedModules())
                {
                    module.Title = symReader.Labels[module.Label];

                    foreach (AsmEvent evt in module.GetOrderedEvents())
                    {
                        evt.Title = symReader.Labels[evt.Label];
                    }
                }
            }

            location.Scripts = result;

            location.SaveRequest &= ~LocationProperty.Scripts;
            location.Importable  &= ~LocationProperty.Scripts;
            return(true);
        }
Beispiel #5
0
 public AsmInterpreter(AsmCollection scripts)
 {
     _scripts = Exceptions.CheckArgumentNull(scripts, "scripts");
 }