Ejemplo n.º 1
0
        /// <summary>
        /// Updates all of the pointers in the script that point to an offset after the script.
        /// </summary>
        private void UpdatePointersAfterScript()
        {
            int delta = this.endOffset - this.endInternalOffset;
            //
            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 >= (this.endInternalOffset & 0xFFFF) && !eac.PointerChanged[0])
                        {
                            eac.WritePointerSpecial(0, (ushort)(pointer + delta));
                            eac.PointerChanged[0] = true;
                        }
                        pointer = eac.ReadPointerSpecial(1);
                        if (pointer >= (this.endInternalOffset & 0xFFFF) && !eac.PointerChanged[1])
                        {
                            eac.WritePointerSpecial(1, (ushort)(pointer + delta));
                            eac.PointerChanged[1] = true;
                        }
                    }
                    else
                    {
                        pointer = eac.ReadPointer();
                        if (pointer >= (this.endInternalOffset & 0xFFFF) && !eac.PointerChanged[0])
                        {
                            eac.WritePointer((ushort)(pointer + delta));
                            eac.PointerChanged[0] = true;
                        }
                    }
                }
                else
                {
                    pointer = eac.ReadPointer();
                    if (pointer >= (this.endInternalOffset & 0xFFFF) && !eac.PointerChanged[0])
                    {
                        eac.WritePointer((ushort)(pointer + delta));
                        eac.PointerChanged[0] = true;
                    }
                }
            }
        }
Ejemplo n.º 2
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;
                    }
                }
            }
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
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;
            }
        }