How to use PgcEdit’s Search & Replace Plugin

By Blutach

 

Tools required:

PgcEdit

Search and Replace Plugin (version 2)

 

PgcEdit has implemented a search and replace plugin for advanced users.

 

1.      Preliminary

First, you need to download PgcEdit.  It can go in any convenient folder.  Open it and close it again (this step is unnecessary if you already have used PgcEdit).  This will create a sub-folder called plugins.  Next, download the Search and Replace Plugin, unzip it and place it in the plugins folder.

You can only access the plugin from PgcEdit’s Plugins menu on the menu bar.

 

Search and Replace operates globally – this means it works across the entire DVD (including menu buttons and BOVs) and not just on a PGC or a domain.  There is no undo function, so an incremental backup (File – Backups – New incremental backup) is definitely in order!

I will illustrate the use of the plugin with a few examples.

At present there are two options:

These will be discussed in turn.

 

2.      Search and Replace GUI

The Search and Replace GUI allows you to search hex commands and replace them with a replacement set of your choice.  It allows you to keep selected bytes of the 8 byte command string and just replace the ones you want.  This can be useful if you want to change all references to PGCs or Title numbers for example.  You may also manipulate the bytes of the command, by substituting in the replacement string, references to certain bytes of the search string.

There is also a preset of changing the Set GPRMMD command to a simple Set GPRM command.  You may also program your own “presets”.

Entering a command is easy.  While the Search and Replace GUI is open, you can copy and paste any single command from the main PgcEdit GUI, or you can create your own strings as shown below.

 

Basic syntax:

The syntax of the Search and Replace function needs to be fully understood.  A VM command consists of 8 hexadecimal bytes.  Each of the 8 bytes in a VM Command is separated by a space.  Where you do not wish to change a byte, enter .. (2 dots).  To keep a nibble constant, enter a single dot in the relevant place.

The following 2 links explain Tcl/Tk’s “regular expression” syntax in some detail.

http://www.wellho.net/regex/tcl.html

http://www.tcl.tk/man/tcl8.4/TclCmd/re_syntax.htm

If the syntax you enter is incorrect, PgcEdit will warn you (here we only have 1 nibble in byte 5):

 

Example 1:

Suppose that you wanted to change all (JumpTT) Jump to Title 2 commands to Jump to Title 1.  An absolute Jump TT always starts (in hex) as 30 02 with the 6th byte being the title number.  A conditional JumpTT starts with 30 22 and has entries in bytes 7 and 8 for the condition.

[30 02 00 00 00 02 00 00]  1  (JumpTT) Jump to Title 2
[30 22 00 00 00 02 0A 04]  2  if ( gprm(10) == gprm(4) ) then { (JumpTT) Jump to Title 2 }

To change all these reference that are jumping to title 2 to title 1, you would enter:

Search:          30 .2 00 00 00 02 .. ..

Replace:                     .. .. .. .. .. 01 .. ..

Notes:

 

Example 2:

Change all Exit commands to (CallSS) Call the First Play PGC, Resume Cell 1

Search:                       30 .1 00 00 00 00 .. ..

Replace:                     .. .8 .. .. .1 .. .. ..

Sadly, due to VM command structure, this will work perfectly well in the Titles domain but will create a bad command in the Menu domain (it needs to be a JumpSS), so you will need to check your work afterwards.  Fortunately, PgcEdit highlights in pink bad commands, so a glance through all PGCs can quickly see if there is an issue.  As well, PgcEdit will not change a command if the change will result in an illegal command.  Instead, it will notify you of the errors, so you may make changes to your replace string accordingly and perform a 2nd pass.

Notes:

Advanced syntax:

The plugin allows for some powerful editing.  You may substitute bytes from selected positions in the search string in the replace string, and perform basic mathematical (+, –, *,  and %(remainder)) and logical operations (AND, OR, XOR) on commands.

Let’s illustrate by substituting a Set GPRMMD command with the normal Set (this is a preset, but it is instructive anyway).

Example 3:

Let’s look at 2 basically equivalent commands:

[53 00 03 E8 00 02 00 00]  1  (SetGPRMMD) Set gprm(2) in register mode =(mov) 1000

[71 00 00 02 03 E8 00 00]  2  Set gprm(2) =(mov) 1000

And another 2:

[43 00 00 0F 00 02 00 00]  3  (SetGPRMMD) Set gprm(2) in register mode =(mov) gprm(15)

[61 00 00 02 00 0F 00 00]  4  Set gprm(2) =(mov) gprm(15)

And finally, these 2:

[53 20 03 E8 00 02 0E 0F]  5  if ( gprm(14) == gprm(15) ) then { (SetGPRMMD) Set gprm(2) in register mode =(mov) 1000 }

[71 20 0E 02 03 E8 00 0F]  6  if ( gprm(14) == gprm(15) ) then { Set gprm(2) =(mov) 1000 }

The structure of the hex commands are what is of interest to us right now.  Note the value to which gprm(2) is being set is contained in bytes 3 and 4 in the 1st command, and in bytes 5 and 6 in the 2nd command.  The gprm number is in byte 6 of the 1st command, while it is byte 4 of the 2nd.  Finally, the command itself is 0x1E higher (53 becomes 71).

So, how does this translate?

Search:                      [45]3 .. .. .. .. 0. .. ..

Replace:                    (#1+0x1E) .. #7 #6 #3 #4 .. ..

Notes:

This search and replace pattern will change all Set GPRMMD commands to basic Set commands, while preserving all conditions attached to the commands.

(Note:  For ease of understanding, this example ignores the cases where no comparison is done and RSM or Links are executed – eg. Set gprm(2) =(mov) 1000 ; RSM, button 1 (1024)  In this sort of case, an IF-THEN-ELSE syntax must be applied (as in the actual preset).)

 

3.      Auto Increment

Auto Increment can be used to save you time in the following situations:

Suppose you wanted to author a DVD which jumped to a PGC based on the value of a register.  You might have 6 commands, as follows:

[20 A4 00 0F 00 01 00 06]  1  if ( gprm(15) == 1 ) then { LinkPGCN PGC 6 }
[20 A4 00 0F 00 02 00 07]  2  if ( gprm(15) == 2 ) then { LinkPGCN PGC 7 }
[20 A4 00 0F 00 03 00 08]  3  if ( gprm(15) == 3 ) then { LinkPGCN PGC 8 }
[20 A4 00 0F 00 04 00 09]  4  if ( gprm(15) == 4 ) then { LinkPGCN PGC 9 }
[20 A4 00 0F 00 05 00 0A]  5  if ( gprm(15) == 5 ) then { LinkPGCN PGC 10 }
[20 A4 00 0F 00 06 00 0B]  6  if ( gprm(15) == 6 ) then { LinkPGCN PGC 11 }

In the normal situation, you would author the first one using the Command Editor, and copy it 5 times.  Then, you would go into the 5 copied lines and change the value of gprm(15) and the value of the PGCN.  How tedious!  (This would be especially bad if you were authoring links to say 30 chapters)

Enter Auto Increment.

Simply, enter the first command, and duplicate it as many times as it necessary.  Then highlight all commands as shown below.

Now, call Auto Increment.  The first highlighted command is automatically entered in the dialogue box.  You will need a little knowledge of VM commands, but it should be relatively obvious.

In the screenshot, the key bytes are the last one (06) and the 3rd last one (01), which obviously refer to the PGCN and the value in the GPRM respectively.  All you need to do is change both of these to +1 and click Increment.  PgcEdit does the rest.

 

A more complicated example:

Suppose you were authoring a DVD and you wanted something like this:

[00 B1 00 0F 00 01 00 03]  1  if ( gprm(15) != 1 ) then { Goto line 3 }

[30 02 00 00 00 01 00 00]   2  (JumpTT) Jump to Title 1

[00 00 00 00 00 00 00 00]   3  NOP

[00 B1 00 0F 00 02 00 06]  4  if ( gprm(15) != 2 ) then { Goto line 6 }

[30 02 00 00 00 02 00 00]   5  (JumpTT) Jump to Title 2

[00 00 00 00 00 00 00 00]   6  NOP

[00 B1 00 0F 00 03 00 09]  7  if ( gprm(15) != 3 ) then { Goto line 9 }

[30 02 00 00 00 03 00 00]   8  (JumpTT) Jump to Title 3

[00 00 00 00 00 00 00 00]   9  NOP

Etc.

This is easily done in 2 passes:

First author your PGC with 3 commands:

Now, highlight the 3 commands and click Duplicate as many times as there are titles.

Highlight all commands and start Auto Increment.  We need to adjust the argument for gprm(15) and the Gotos.  The first command is highlighted and it will be obvious which needs to be incremented (in this case, it is byte 6).  Enter a +1 there.  The Gotos need to be augmented by 3, so enter a +3 there.

                                                             

The resulting commands look as follows:

We’re halfway home!  You’ll note only the if .. goto lines have been adjusted.  We now need to adjust the title numbers.  This is easy.  Highlight all commands starting from the 2nd one.  Then execute Auto Increment one more time.  All the title numbers will be adjusted and we are finished.

In case none of these conditions are true, it is wise to author the last NOP as a JumpSS to the First Play PGC.

 

If you get into trouble with any of these functions, click Help for a brief explanation of the function.

 

A little test DVD which you can play with Search and Replace strings is available for download here.

A discussion thread has been established at Doom9 here.  Please feel free to post your own search and replace presets there.

As usual, great thanks to r0lZ for this great addition to PgcEdit.  If you have any questions, please direct them to Doom9’s IFO/VOB Editors forum or Digital Digest’s Authoring and Editing forum.

 

 

Version 1

16 June 2007