/// <summary> /// Adds/subtracts a value from all of the pointers in the script that point to an offset after the script. /// </summary> /// <param name="delta">The value to add/subtract.</param> private void UpdatePointersAfterScript() { int delta = this.endOffset - this.endInternalOffset; // ScriptIterator it = new ScriptIterator(this); while (!it.IsDone) { EventActionCommand eac = it.Next(); int pointer; if (eac.Opcode == 0x42 || eac.Opcode == 0x67 || eac.Opcode == 0xE9) { if (eac.GetType() == typeof(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; } } } }
/// <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(EventActionCommand reference) { ScriptIterator it = new ScriptIterator(this); while (!it.IsDone) { EventActionCommand eac = it.Next(); int pointer; if (eac.Opcode == 0x42 || eac.Opcode == 0x67 || eac.Opcode == 0xE9) { if (eac.GetType() == typeof(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; } } } }