예제 #1
0
        public override void SetEventByIndex(int index, AsmEvent script)
        {
            switch (index)
            {
            case 0:
                Construct = script;
                break;

            case 1:
                Initialize = script;
                break;

            case 2:
                Talk = script;
                break;

            case 3:
                Push = script;
                break;

            default:
                Scripts[script.Label] = script;
                break;
            }
        }
예제 #2
0
파일: AsmDoor.cs 프로젝트: rebootus/Esthar
        public override void SetEventByIndex(int index, AsmEvent script)
        {
            switch (index)
            {
            case 0:
                Construct = script;
                break;

            case 1:
                Initialize = script;
                break;

            case 2:
                Open = script;
                break;

            case 3:
                Close = script;
                break;

            case 4:
                On = script;
                break;

            case 5:
                Off = script;
                break;

            default:
                Scripts[script.Label] = script;
                break;
            }
        }
예제 #3
0
        public AsmSegment(AsmEvent evt, int offset, int length)
        {
            Exceptions.CheckArgumentOutOfRangeException(length, "length", 1, 10000);

            Event  = evt;
            Offset = offset;
            Length = length;
        }
예제 #4
0
        protected AsmCommandOld(JsmCommand command, int offset, AsmEvent script)
        {
            if (offset < 0 || offset >= script.Count)
            {
                throw new ArgumentOutOfRangeException("offset");
            }

            Script = Exceptions.CheckArgumentNull(script, "script");
            Offset = offset;

            Operation = Script.GetOperation(command, offset);
        }
예제 #5
0
        public virtual void SetEventByIndex(int index, AsmEvent script)
        {
            switch (index)
            {
            case 0:
                Construct = script;
                break;

            case 1:
                Initialize = script;
                break;

            default:
                Scripts[script.Label] = script;
                break;
            }
        }
예제 #6
0
        private void GetJumps(AsmEvent evt, out List <int> jumpFrom, out List <int> jumpTo)
        {
            jumpFrom = new List <int>();
            jumpTo   = new List <int>();

            for (int i = 0; i < evt.Count; i++)
            {
                JsmOperation opetation = evt[i];
                switch (opetation.Command)
                {
                case JsmCommand.JMP:
                case JsmCommand.JPF:
                    jumpFrom.Add(i);
                    jumpTo.Add(Math.Max(0, i + opetation.Argument));     // JMP -5479
                    break;
                }
            }
        }
예제 #7
0
        public static AsmValueSource Create(AsmEvent evt, int offset)
        {
            JsmOperation operation = evt[offset];

            switch (operation.Command)
            {
            case JsmCommand.PSHN_L:
                return(new AsmStaticValueSource(operation));

            case JsmCommand.PSHI_L:
            case JsmCommand.PSHM_B:
            case JsmCommand.PSHM_W:
            case JsmCommand.PSHM_L:
            case JsmCommand.PSHSM_B:
            case JsmCommand.PSHSM_W:
            case JsmCommand.PSHSM_L:
            case JsmCommand.PSHAC:
            case JsmCommand.CAL:
                return(new AsmUnknownValueSource(evt, offset));

            default:
                return(new AsmUnknownValueSource(evt, offset));
            }
        }
예제 #8
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);
        }
예제 #9
0
 public AsmCommandStackOld(AsmEvent script, int offset)
 {
     _script = script;
     _offset = offset;
 }
예제 #10
0
 public AsmCommandFactory(AsmSegment segment)
 {
     _event  = segment.Event;
     _offset = segment.Offset;
     _length = segment.Length;
 }
예제 #11
0
 public AsmCommandFactory(AsmEvent evt)
 {
     _event  = evt;
     _offset = 0;
     _length = evt.Count;
 }
예제 #12
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);
        }
예제 #13
0
        private void CreateSegmentsByJumps(AsmEvent evt, List <int> jumpFrom, List <int> jumpTo)
        {
            jumpFrom = jumpFrom.Order().ToList();
            jumpTo   = jumpTo.Order().ToList();

            AsmSegments segments = new AsmSegments(jumpFrom.Count);

            if (segments.Capacity == 0)
            {
                segments.Add(new AsmSegment(evt, 0, evt.Count));
                evt.Segments = segments;
                return;
            }

            int left      = 0;
            int fromIndex = 0;
            int toIndex   = 0;

            while (true)
            {
                int right;
                if (fromIndex < jumpFrom.Count)
                {
                    if (toIndex < jumpTo.Count)
                    {
                        int fromValue = jumpFrom[fromIndex];
                        int toValue   = jumpTo[toIndex];
                        if (fromValue < toValue)
                        {
                            right = fromValue;
                            fromIndex++;
                        }
                        else if (toValue < fromValue)
                        {
                            right = toValue - 1;
                            toIndex++;
                        }
                        else
                        {
                            right = toValue - 1;
                            toIndex++;
                        }
                    }
                    else
                    {
                        right = jumpFrom[fromIndex++];
                    }
                }
                else if (toIndex < jumpTo.Count)
                {
                    right = jumpTo[toIndex++];
                    if (left == right)
                    {
                        continue;
                    }
                }
                else
                {
                    if (left < evt.Count)
                    {
                        segments.Add(new AsmSegment(evt, left, evt.Count - left));
                    }
                    break;
                }

                int length = right - left + 1;
                if (length != 0)
                {
                    segments.Add(new AsmSegment(evt, left, length));
                }
                left = right + 1;
            }

            evt.Segments = segments;
        }
예제 #14
0
 public abstract void Write(AsmEvent evt, int offset);