Guide:Entity swap tutorial: Difference between revisions

Imported images from google doc
(Added needs images tag)
(Imported images from google doc)
Line 1:
This guide will teach you how to achieve entity swaps in [[Sly 2]] and [[Sly 3]], and show you what can be done with the technique.
 
{{Needs images|Need to import all the images from the original Google Doc, and/or take new screenshots to update them.}}
 
== Introduction ==
Line 14 ⟶ 12:
Not being able to apply the entity swaps on boot used to be a problem for PNACH mods, until we learned that you can conditionally apply patches using “if” conditions we call "E codes".
 
[[File:Entity swap pnach example 1.png]]
{{No image}}
 
This is a pretty rough visual explanation of how the conditions work, so I’ll explain it further. Almost every entity swap-related PNACH requires these 2 highlighted lines; it first needs to check whether you’re loading into the right map, and then checks when your game isn’t loading anymore. E0 means 16-bit multiple skip:
 
[[File:Pnach E codes.png]]
{{No image}}
 
In the '''{{color|#849656|green section}}''', it checks how many lines of code it will execute below itself. '''{{color|#34c39a|The last 2 bytes}}''' are reserved for your mod. Let’s say you need to check that the Map ID is 20, you would write '''{{color|#34c39a|0014}}''' at the end. Remember that everything in PNACH is in hexadecimal (if it helps, the Windows calculator has a built-in DEC to HEX converter if you switch it to Programmer mode).
Line 34 ⟶ 32:
Example of a finished mod that swaps the bear with Jean Bison:
 
[[File:Entity swap example screenshot.png|600px]]
{{No image}}
 
== Entity Swap Tutorial ==
Line 51 ⟶ 49:
The music box in the game's memory is called FK$Xmusic_box. In this GIF, I search for the music box, left-click on it and press CTRL+B to view it in the Memory Viewer. Then I press the scroll bar’s up-arrow twice to show exactly what we need. Here I’ve visualised what all the values mean:
 
[[File:Entity swap FKX entry.png]]
{{No image}}
 
'''{{color|cornflowerblue|white|Blue is the entity’s spawning rule}}''' <small>(-0x1C from the string)</small>
Line 63 ⟶ 61:
For this swap, we are only going to need the '''{{color|darkred|white|entity}}''', so left click on the first red number like in the visualization above, then right click and select "Add this address to the list". A window will pop up; you should give it a description so you remember what it is later (in this case I will simply call it "Music Box"), then change its type to 4 Bytes. That way it will get the full entity array that I highlighted in red. Click OK and close the Memory Viewer. Your address list should look something like this:
 
[[File:Entity swap CE screnshot 1.png]]
{{No image}}
 
=== Scanning for the new entity ===
Line 70 ⟶ 68:
The [[Sly 2:Smart guards|flashlight guards]] in episodes 6 and 7 are called <code>FK$Xnpc_moose_guard</code>. So I repeat the entire process; scan for that string, CTRL+B, scroll up twice, left click the first byte of the entity and add to the list as 4 Bytes. (remember to name your addresses) Now your list should look like this:
 
[[File:Entity swap CE screnshot 2.png]]
{{No image}}
 
=== Performing the magic ===
Before we replace anything, we do a crucial step to avoid crashing. Right click both addresses and show them as hexadecimal. Like so:
 
[[File:Entity swap CE screnshot 3.png]]
{{No image}}
 
Now for the final step; copy the guard’s value and paste it into the music box’s value. If all done correctly, you should now be able to throw guard(s) out of Sly’s hand instead of the usual music boxes.
Line 84 ⟶ 82:
For this mod, we need the code to check the Map ID, and the loading state before swapping the music box with a guard. Here’s how we do it:
 
[[File:Entity swap pnach example 2.png]]
{{No image}}
I already explained how the E codes work, but I will quickly explain this image. First, memory addresses that you find in Cheat Engine always start with 0x20 or 0x21 because the base address of the emulated PS2 memory is 0x20000000. This means that in the pnach we can use the first digit for something else because because the emulator already knows to take the rest of it and add 0x20000000 to get the real address. For E codes, that digit tells the emulator which kind of conditional it is: {{color|black|lightgreen|0}} means "equal", {{color|black|lightgreen|1}} means "not equal", {{color|black|lightgreen|2}} means "less than" and {{color|black|lightgreen|3}} means "greater than".