Thursday, July 7, 2011

Sensibeat's Model Swapping Tutorial (Updated)

Updated Version:

Swapping objects (SSF4AE)
I'll swap cammy's first costume hat with the 2nd one.

In sf4explorer I open CMY_02.obj.emo and I "raw dump" (not "extract") the #EMG (cap_lether) (cap_line)
(I name it CMY_02.cap.emg)
[IMG]

I open CMY_01.obj.emo and CMY_02.cap.emg in HxD

In CMY_01.obj.emo I search for the #EMG (F3) containing the "cap"
[IMG]
(note the offset: 670C0)

I go to the next #EMG (F3)
[IMG]

I place the cursor just before that #EMG and I use the "select block" fonction (CTRL+E) using the start offset I noted (670C0):
[IMG]

OK:
[IMG]
(Note the Length: 63F0)

The #EMG selected in CMY_01.obj.emo, I now "Select All" (CTRL+A) CMY_02.cap.emg and I copy it (CTRL+C).
[IMG]
(Note the Length: 50C0)

I paste it (CTRL+V) over the #EMG selected in CMY_01.obj.emo
[IMG]

OK:
[IMG]




Let's do some math in hexadecimal:
Code:
63F0 (Length of former #EMG) - 50C0 (Length of new #EMG) = 1330
1) I need to substract 1330 in the index at the start of the file for every offset of the #EMGs for every object coming after the "cap", as the new object is smaller than the old one.



By opening CMY_01.obj.emo in sf4explorer, I can count that the cap is the 10th #EMG so I have to substract 1330 from the 11th #EMG to the last one (22th #EMG).
[IMG]

The index of the #EMGs starts at offset 28
From there each block of 8 digits is the offset of one #EMGs minus 30 written backwards 2 digits at a time ("little endian"):
01 23 45 69 in little endian will be 69 45 23 01 in big endian
[IMG]
So I'll have to edit the 12 index entries from offset 50 (#EMG 11) to 7F (#EMG 22)
I substract 1330 to the offsets (calculating in hexadecimal and reading offsets in "big endian"):
Code:
00 06 D4 80 - 1330 = 00 06 C1 50  00 06 E4 50 - 1330 = 00 06 D1 20  ...  00 0A F1 60 - 1330 = 00 0A DE 30  
And I rewrite them backwards ("little endian")
[IMG]

2) I need to substract 1330 to 2 more offsets related to the 2nd part of the obj.emo file:
[IMG]
Code:
00 0C A7 00 - 1330 = 00 0C 93 D0  00 0C A5 90 - 1330 = 00 0C 92 60  
[IMG]

Let's go to the 2nd offset (minus 20 written backwards, so 00 0C 92 60 + 20 = 00 0C 92 80), using the goto fonction (CTRL+G):[IMG]

Here's another index I need to substract 1330 to:
[IMG]

From offset C9280 to C92D7, just before the first readable datas (hand_env):
Code:
00 0C A5 E8 - 1330 = 00 0C 92 B8  ...  00 0C A6 D1 - 1330 = 00 0C 93 A1  
[IMG]

Save and that's it for the 1st part:
[IMG]

Next I'll show how to add dds to the col.emb and nml.emb files and how to link objects in the obj.emo file to the right dds.

1) Adding dds to the col.emb (and nml.emb) files

In sf4explorer, I extract the dds for the cap from CMY_02_01.col.emb
That I name CMY_02_01.dds:

[IMG]

I open CMY_01.col.emb and CMY_02_01.dds in HXD
[IMG]

In CMY_01.col.emb, I add a line of "00" at the end of the index, here:
[IMG]

I change this "04" at offset 0C (former number of dds):
[IMG]

Into "05" (new number of dds):
[IMG]

And I edit the index because I moved all the offsets by 10 with my line of "00":
[IMG]

I add another line of "00" at the end of the file, here:
[IMG]
(Note the starting offset of the new dds will be: 155850)

I "select All" (CTRL+A) CMY_02_01.dds and copy it
[IMG]
(Note the Length: 555F0)

I paste it at the end of the file (after the line of "00"):
[IMG]

Then I go back to the start of the file to enter the starting offset of the new dds minus 40 writen in "little endian"
(40 = offset where I'll write the new index entry)
00 15 58 50 - 40 = 00 15 58 10 ("big endian")
That gives in "little endian":
[IMG]




Now I add the new dds length written in "little endian" (00 05 55 F0):
[IMG]

Save and do the exact same thing with the normal map dds in CMY_01.nml.emb, adding the normal map dds that contains the cap from CMY_02.nml.emb

2) Linking objects in the obj.emo file to the right dds

dds are ordered from 0 and the normal map dds follow the texture dds, so if you add 1 texture dds, every normal map dds will change number.
I have now 5 texture dds from #0 to #4
and 5 normal map dds from #5 to #9

I open CMY_01.obj.emo in HxD and do a search on "#EMG" (F3)
Each #EMG has those kind of data outlined here:
[IMG]

They contain the links to the dds:
[IMG]

The numbers in red are links to the texture dds
The numbers in green are links to the normal map dds

I have to change all the links to the normal map dds for the 22 #EMG according to the new order of the dds
(I just have to add 1 to every normal map link as we added 1 texture dds)
[IMG]

And edit the "cap" #EMG to link it to my 2 new dds #4 and #9:
[IMG]

Save and it's over.
[IMG]

Original Version:


Let's put Ryu's hairs on Akuma's (a.k.a. Gouki).


preparation:


From GKI_02.obj.emo I dump and rename (included in swap obj.rar):

  • GKI_01.bsr

  • GKI_01.nml.emb

  • GKI_01.shd.emo
They'll be used in kensou's sf4tool to repack the file.


From RYU_03.cos.emz I dump the hair emg file that I rename as RYU_03.hair.emg (included in swap obj.rar):




Open GKI_02.obj.emo and RYU_03.hair.emg in HxD:
The hair being the last emg of GKI file, we can get the information on it's beginning and ending from these:


[IMG]








Code:


offset 24 = offset of the list of offsets of names following the last emg:
00 0B A2 70 + 20 = 00 0B A2 90 so the emg finishes at [COLOR="red"]00 0B A2 8F [/COLOR](1 before)
offset 58 = 1st offset of last emg (hair):  00 0A 68 D0 + 30 = [COLOR="red"]00 0A 69 00[/COLOR]

Let's use the "Select block" option in HxD:


[IMG]


Now select all of the RYU file and copy/paste it over GKY's selection:


[IMG]


OK:


[IMG]
Notice the 2 offsets that will need to be rewritten at the beginning of the file:






Code:


00 0C 01 70  -20 = 00 0C 01 50  -> backwards: [COLOR="red"]50 01 0C 00[/COLOR] @ offset 24
00 0C 02 20 -> backwards: [COLOR="red"]20 02 0C 00[/COLOR] @ offset 10



Then the 2 offsets at the beginning of the file:


[IMG]


So it's good for the emo's references.



Now let's take a look at the emg's references:


[IMG]
43 -> former emg is 42
01 -> number of the 2nd texture dds
05 -> number of the 2nd normal map dds




Save and Rename the file as GKI_01.obj.emo


Put it in a new folder with:

  • GKI_01.bsr

  • GKI_01.nml.emb

  • GKI_01.shd.emo
and only those 4 files.


Open kensou's sf4tool and go look for your file path in the upper right, then click the left button under the big window:


[IMG]


Notice the files obj.emo and shd.emo are swapped.
Rewrite them in the right order (obj before shd) and click the right button:


[IMG]


Done.


Rename the newpack.emz into GKI_01.cos.emz and test it ingame with the GKI_01_01.col.emz provided (2nd costume 1st color file edited to be played as 1st costume):


[IMG]
You've got Akuma with Ryu's hairs.


For swapping smaller objects:


Basically you just have to copy/paste your emg and fill the rest of the former emg with 00's. Then there're just the emg number and the dds references to change. So the swap can be done on the .cos.emz directly.

10 comments:

Anonymous said...

what

KtWdA said...

Is there any way to have this simplified in a way using matedit?

Hunter K. said...

@KtWdA
not specifically using matedit, but someone could write a similar tool that could do the hex copypasta. However, it wouldn't be able to do any of the additional stuff that's required to make it actually look right (color, animation, etc). No tool would be able to ensure it actually works without crashing, either, which is the main problem with this process. The steps sensibeat laid out are pretty easy, it's the other stuff that's hard to(apparently) impossible.

Rajat said...

i can't understand meaning of these line

"Don't forget to rename the object in the #EMG according to the skin it's swapped onto, here I searched and renamed "cap_lether" and "cap_line" into "cap" (both times) so they'll use the same material in the obj.emm file."

Hunter K. said...

Hi Rajat,
What he means is that you need to rename the swapped object to match the material of the object it replaces, otherwise the game will either give it the wrong material or crash if it can't find the right material.

While this tutorial is still important insofar as it explains how the game works, sloth86's EMGSwap tool makes the process much, much easier. You can find a download link for it on the wiki (aemods.pbworks.com) and a tutorial for it elsewhere on this blog.

Anonymous said...

i dont under stand the numbers & letters im trying to swap guy(yes i extracted him to a sf4 file)with ryu's face plz help

streetfighterrox said...

i dont under stand the numbers & letters im trying to swap guy(yes i extracted him to a sf4 file)with ryu's face plz help

Hunter K. said...

@streetfighterrox
oh, it looks like the tutorial's text was set to the same color as the background (black). See if it makes more sense now :)

Regardless, you can now use sloth86's EMGSwap tool to automate the whole process.

ジェームス said...

I appreciate the tutorial, but my god it got bloody unintelligible when you started to talk about hexadecimal. I have managed to figure out little parts of what you are saying, but it's very, very difficult. I will try again tomorrow.

Hunter K. said...

@ジェームス
lol that's totally understandable. Thankfully, these steps aren't really necessary anymore since there are tools that automate the process, specifically sloth86's EMGSwap and EMOAppend.

It's still good to know how the tools work, particularly if someone in the future wants to write other tools that build on this process, but regular users don't need to do it anymore.

Analytics Tracking Footer