Пример #1
0
        /// <summary>
        /// Updates all of the pointers in the script pointing directly to a given command's offset.
        /// </summary>
        /// <param name="reference">The reference command in the script.</param>
        private void UpdatePointersToCommand(Command reference)
        {
            ScriptIterator it = new ScriptIterator(this);

            while (!it.IsDone)
            {
                Command eac = it.Next();
                int     pointer;
                if (eac.Opcode == 0x42 || eac.Opcode == 0x67 || eac.Opcode == 0xE9)
                {
                    if (eac is EventCommand || eac.Opcode == 0xE9)
                    {
                        pointer = eac.ReadPointerSpecial(0);
                        if (pointer == (reference.InternalOffset & 0xFFFF) && !eac.PointerChanged[0])
                        {
                            eac.WritePointerSpecial(0, (ushort)(reference.Offset & 0xFFFF));
                            eac.PointerChanged[0] = true;
                        }
                        pointer = eac.ReadPointerSpecial(1);
                        if (pointer == (reference.InternalOffset & 0xFFFF) && !eac.PointerChanged[1])
                        {
                            eac.WritePointerSpecial(1, (ushort)(reference.Offset & 0xFFFF));
                            eac.PointerChanged[1] = true;
                        }
                    }
                    else
                    {
                        pointer = eac.ReadPointer();
                        if (pointer == (reference.InternalOffset & 0xFFFF) && !eac.PointerChanged[0])
                        {
                            eac.WritePointer((ushort)(reference.Offset & 0xFFFF));
                            eac.PointerChanged[0] = true;
                        }
                    }
                }
                else
                {
                    pointer = eac.ReadPointer();
                    if (pointer == (reference.InternalOffset & 0xFFFF) && !eac.PointerChanged[0])
                    {
                        eac.WritePointer((ushort)(reference.Offset & 0xFFFF));
                        eac.PointerChanged[0] = true;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Updates this script's buffer data and all command offsets and pointers in this script.
        /// </summary>
        public void Refresh()
        {
            if (Commands == null)
            {
                return;
            }

            // First, write command properties to buffer
            WriteToBuffer();

            // Refresh offsets to exact values
            int offset = BaseOffset;

            foreach (var command in Commands)
            {
                command.Offset = offset;
                offset        += command.Length;
            }

            // Reset flags indicating pointers changed
            var it = new ScriptIterator(this);

            while (!it.IsDone)
            {
                var command = it.Next();
                command.PointerChanged = new bool[256];
            }

            // Update all pointers to each command in this script
            it = new ScriptIterator(this);
            while (!it.IsDone)
            {
                var command = it.Next();
                if (!IsUndoing && State.Instance.AutoPointerUpdate)
                {
                    UpdatePointersToCommand(command);
                }
                command.InternalOffset = command.Offset;
            }

            // Update all pointers after this script
            if (!IsUndoing && State.Instance.AutoPointerUpdate)
            {
                UpdatePointersAfterScript();
            }
        }
Пример #3
0
        public void Refresh()
        {
            if (Commands == null)
            {
                return;
            }
            WriteToBuffer();
            // refresh offsets
            int offset = BaseOffset;

            foreach (EventCommand esc in Commands)
            {
                esc.RefreshOffsets(offset);
                offset += esc.Length;
            }
            // update internal pointers
            Command        eac;
            ScriptIterator it = new ScriptIterator(this);

            while (!it.IsDone)
            {
                eac = it.Next();
                eac.PointerChanged = new bool[256];
            }
            // if undo/redo, pointers update by raw script change
            if (!Undoing && State.Instance.AutoPointerUpdate)
            {
                UpdatePointersAfterScript();
            }
            it = new ScriptIterator(this);
            while (!it.IsDone)
            {
                eac = it.Next();
                if (!Undoing && State.Instance.AutoPointerUpdate)
                {
                    UpdatePointersToCommand(eac);
                }
                eac.InternalOffset = eac.Offset;
            }
        }