Guide:Entity swap tutorial: Difference between revisions

Update time
(Adapted guide from [https://docs.google.com/document/d/1Oyz0P7BcBPtc0V8nRFdpYS45sau8nDdBendP1Hkv7CY Zami's weed doc tutorial])
 
(Update time)
 
(6 intermediate revisions by 2 users not shown)
Line 1:
{{Infobox guide
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.
| sly2 = y
| sly3 = y
| difficulty = Intermediate
| time = 10-15 mins
}}
 
This guide will teach you how to achieveswap entity swapsentities in [[Sly 2]] and [[Sly 3]], and show youthe whatpotential can be done withof the technique in modding.
 
== Introduction ==
Line 5 ⟶ 12:
 
=== Short explanation ===
Sly 2 and Sly 3 have a bunch of strings in memory that all start with '''FK$X''' and end with the name of an entity. The game uses these FK$X strings to find and load entities from the disc. Each FK$X string is accompanied by other data about the entity (such as it's ID, the number of them in the world, etc).
 
During the loading screens, these FK$X entries are populated in memory on a per-level basis. That’s why most entity swaps that are applied on boot will crash (or won’t work at all)-- you have to apply them when the level is loading (or after it has fully loaded). "If" conditional statements in PNACH files makes these mods possible by allowing us to time the patch execution at the point just after the maps have loaded.
Line 12 ⟶ 19:
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).
 
The loading address will always check for “3”, so you can easily copy that line into your mods, just make sure to count the '''{{color|#849656|number of instructions below it}}''' first.
 
The '''{{color|magenta|pink address}}''' at the end is where it’s checking the value from. The address order is super confusing at first but believe it or not, it is not a weird design decision by the emu developers, it’s actually how the raw cheat codes have always worked on a real console.
 
Line 32 ⟶ 40:
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 49 ⟶ 57:
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 61 ⟶ 69:
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 68 ⟶ 76:
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:
 
{{No image}}
[[File:Entity swap CE screnshot 3.png]]
 
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 81 ⟶ 90:
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".
Line 97 ⟶ 106:
 
== Attribution ==
NiV and Frogg originally found this trick/wrote about it in the modding server. Zamizami expanded on it, making the method a lot easier and writing a tutorial in [https://docs.google.com/document/d/1Oyz0P7BcBPtc0V8nRFdpYS45sau8nDdBendP1Hkv7CY a google doc]. This guide was originally adapted from that doc.
 
{{Navbox guides}}
[[Category:Guides]]
[[Category:Guides for Sly 2]]
[[Category:Guides for Sly 3]]