Noob-Proof Guide To RPK Structure!
Sections: Tutorials \ Street Legal Modding
Tags: Guide, Help, Noob, Rpk, Script, Slrr, Structure
Okay here is the simplest guide to RPK scripting! By the end of this you'll be scripting like a pro! The first thing to remember is that it looks a lot harder than it really is. This is something ANYONE can do, it just looks confusing which turns a lot of people away! If you still can't do it after this guide, then what can I say, you need serious help
Okay first things first, you need two .exe's: resdecode and resconvert. Chances are, you already have these two files in your slrr folder!
You want to copy BOTH and PASTE them into a new folder. I made a new folder in my documents and put them there.
Now notice I have a third file: resource converter. This takes the work out of converting rpk and rdb files back and forth. You can download the resource converter here: http://streetlegalmods.com/downloads/game/tools/Resource-Converter (if a warning message pops up hit ignore. It's safe I promise).
Okay, now you're ready to get started. For this tutorial, I will be using the rpk from my drag wheel mod as an example. You can use any rpk because they're all very similar. But for simplicity sake, I will use this.
Now we need to convert this rpk to an rdb (readable/writable) file. You're in luck, the resource converter makes this really easy!
Just DRAG the rpk onto the resource converter EXE like this:
The program will open. Everything on the left is in rdb format, and everything on the right is rpk format. If you double click the name of the rpk on the right, it will convert to rdb. So once you double click it will look like this:
Close the resource converter. You will now see you have another file in your folder. This is the rdb that has been converted. Right click it and open with notepad
When it opens it will look like this:
Okay here is where the fun starts. Pay attention to these </FILE> lines. Every snippet of code is separated by these and it is important to not forget them when making new bits of code. Also <FILE RES> and <FILE RSD> go hand-in-hand. (ignore the numbers they don't matter). A good way to tell where a piece of code ends and where another starts is by looking for the RSD bit. So we look at <FILE RSD> and see right below it is the location of the texture I'm using. This is where the piece of code ends. Right below it is another </FILE>, this signifies a new piece of code starts.
I've highlighted the entire piece of code so you can visualize it better.
I have THREE textures, so I need THREE pieces of code locating each of them!
Next we have the "typeof" and "superid" lines. The typeof line tells the game what type of resource this piece of code is.
Common ones you will see:
typeof 5: this is for meshes (.scx files)
typeof 8: this used for scripts (cfg and class files)
typeof 7: this is for textures
typeof 9: this is for the physical mouse click on a mesh
typeof 14: this is for renders (will talk about renders later)
When defining textures we use typeof 7 and for the superid we use 0x00030003
The superid helps the game find the file. I will explain the superid's later..
This right here is a typeid, these are always unique and are always made up by YOU
I completely made up 0x000000C4, 0x00000BD4, and 0x00000DC4. BUT they are all unique! So before you make up a typeid, hit CTRL F and search for it to make sure it isn't used already.
Imagine parking a red car in a car park full of red cars. How will you ever find it? You must make it UNIQUE, if it is exactly the same as all the others you will have problems. This is basically what the game does, it needs to be able to tell two pieces of code apart. A typeid helps the game find what you want it to find.
Ignore alias and isparentcompatible, these are not important. I personally just copy the source file name and paste it in the alias slot, and I never had to touch isparentcompatible.
Hey guess what? You now understand how to read SLRR rpk code, what each line means, and why it's there! Take a moment to pat yourself on the back.
Take a breather now, we're about to learn about "SECTIONS" of code. You learned what a piece of code looks like, now you will learn what a section looks like. This is possibly the most important thing to know.
Remember those three textures above? Notice how I grouped all three together and at the top. They make up a "section" of code. In this example, this is the texture section. I like to put them at the very top for ease.
Everything highlighted is the "texture section", or "section one".
Let's go to section TWO!
Notice that it is very similar except for some numbers and names. These numbers and names are what define a section pretty much.
Here section two is .scx meshes. Notice the typeof 5 line and the superid 0x00030001 line. We use these for meshes. Now look at the typeid's, they are again all unique. I just made up whatever I can think of that is easy to remember because we WILL be using this again later (you might want to write these down if you have bad memory).
Side note: never confuse a superid with a typeid. Think of it this way: a superid is SUPER STRONG, you can't change it (unless you know what you are doing). And a typeid means you need to TYPE a unique name. This stuff gets easier the more you use it, trust me.
Since it is a mesh that we want to script, notice that the sourcefile line at the end points to my meshes folder. This is where all my 3d meshes are located. Now, to help me remember all the typeid's and match them to the file. I tend to make a pattern.
So you'll see there is a pattern with the mesh file number and typeid number.
<FILE 00000004.res >
<FILE 00000004.rsd >
<FILE 00000005.res >
<FILE 00000005.rsd >
<FILE 00000006.res >
<FILE 00000006.rsd >
Again, there are few conditions. Each typeid has to be unique and has to be used only ONCE. But I also make them a pattern: D1 - Rim 1, D2 - Rim 2, D3 - Rim 3 etc.. Just to make it easy to remember. YOU DON'T HAVE TO DO IT THIS WAY, BUT IT IS RECOMMENDED. Also, if I'm lazy I don't bother to make a pattern..
Let's go to section THREE. This part may get confusing, so if you don't understand the first time then don't worry. You might need to take a break and reread this part over.
This is where I realize I should have picked a simpler rpk because section 3 and 4 are sort of mixed, but I'll try my best to not complicate things.
Lets name each section:
Section 1: textures
Section 2: meshes
Section 3: click
Section 4: render
Section 5: script
This section is a mix of 3 & 4 by choice. You can make them separate if it is easier for you. We can tell this is a new section because we look at the "typeof" line, and we see that it is different now. For click (mouse click) we see typeof 9, and for render we see typeof 14. Also the alias says "click" and "render".
So remember when you are scripting a click code, you have to use type of 9 and superid 0x00030007. The typeid is unique once again, "B1". If you search in the file you will not find another "0x000000B1" anywhere. If you do you will have problems!!!
Now look at shape parts\defiantpack\meshes\rim_01.SCX. This is in the "click" section, it basically gives the mesh a clickable shape based on how it's modeled.
Now we are getting close to the end! Have a cookie. Let's talk about section 4 or the render section.
Section 4 (render) is a little bit different and you must be able to differentiate different bits of code here.
Again these have unique typeid's, and they will be used in the cfg.
So let's take a close look at this bit of code:
</FILE> <----- start
<FILE 00000017.res >
typeof 14 <---- remember this? 14 is always for
superid 0x00030002 <---- use this superid for renders too, don't touch this
typeid 0x000000A1 <---- same thing, just a unique id
<FILE 00000017.rsd >
mesh 0x000000D1 <---- this is the only place you want to copy a unique typeid. Go to section 2 (meshes) and look at the typeid for rim_01. These have to match. This render is used for rim_01. The next render is used for rim_02. etc..
flags 8.0 <---- flag 8 gives your part a shadow. No flag no shadow.
lod_amp 3.5 <--- ignore this
texture 0x000000C4 <---- end (the end of a render is always the last texture id) Also go all the way to the very top and look at the id of the first texture. This render uses the texture 0x000000C4, also known as "chrome". Without this, the part will not be chrome!
When exporting something from 3DS MAX to .scx, a texture folder will be printed. Inside this folder tells you the name of the textures and what order they need to be in. In this case, the rim only uses chrome so I only applied 0x000000C4 (chrome to it).
It's important to get these textures in order if you have more than one.
For example, if you export a 3DS MAX file to .scx and it prints out these textures:
Then you would have all three textures in the render in that order! That way, when it renders in the game carbon will be on the bottom, paintable in the middle and chrome on top.
Finally, we have the last section. Let's call it section 5 (script). This part is easy, and very simple. I have highlighted the piece of code for rim 1:
This ties everything together. This section brings all the other sections together through the cfg file and the class and java files.
typeof 8 - script
superid - 0x0002F235 this is the only time you will choose what superid to use. The purpose of this superid is to put the file in a catalog category. Since I used 0x0002F235, this file will show up in the rims section. This link has all the superid categories listed: http://streetlegalmods.com/tutorials/street-legal-modding/221-MWM-Catalog-SuperIDs
Let's say I want these rims to show up in the engine blocks section, I will change the superid from 0x0002F235 to 0x0000025C.
We will copy our unique typeid's into the correct cfg folder. So let's open up rim_01.cfg
I need to paste the render typeid for rim one, click typeid for rim one, and mesh typeid for rim one here.
Aaaaannd you're done!
Remember to go back and convert your new RDB file back to RPK format using the resource converter.