Character model replacement - X-Hax/SADXModdingGuide GitHub Wiki

This tutorial is WIP.
To-do: screenshots, new weld method, better cutscene head tutorial, light dash color hack might be possible without dll.

Introduction

Proper character replacement in Sonic Adventure DX will require some effort. Being an early Dreamcast title, the game does not support skinned / weighted models, this means that characters are made of dozens of different model parts. The leg/arm/shoe parts only appear connected because the game welds them together every frame. This welding process is what makes character replacement difficult, and why almost every mod "cheat" by not replacing the leg/arm models, or by merging the shoes into one object (that can hence no longer bends.)

In this tutorial, we will learn how to do a proper character replacement in an effort to improve the quality of future mods. This will require for now the need of a DLL mod, this might seem impossible for you but it's actually very easy to set up. If you don't want to weld your model (please do!), you should avoid replacing the leg/arm parts, or disable welds altogether (see below).

Requirements:

Getting character models

SADX models are located in CHRMODELS.DLL (or CHRMODELS_orig.DLL if you have the Mod Loader), use SA TOOLS to extract them:

  1. If you've never used SA TOOLS yet, extract it wherever you want.
  2. Run SAToolsHub and follow the guide to set up a SADX project.
  3. Navigate to figure\character_to_replace\models in the software, and order by type for conveniency

Once you're in the correct folder, you will notice:

  • .sa1mdl files: these are models used by the character (main model, upgrade models, etc)
  • .saanim files: these are motion data

Since we're editing character models, we will need to edit most .sa1mdl files

Editing character models

I strongly recommend you edit models using Blender and the SA Addon. It allows you to open .sa1mdl files directly in blender and save them as such. It also makes editing faster as you don't need to extract each part into .obj and import them manually in SAMDL. Just import in the blender, edit, export back. You also loose less information with only one conversion.

Main model

Find the main model, it usually contains "kihonXX", for example sonic's main model is s_kihon10_sonic.nja.sa1mdl

Note that the game often has copies of several models to be used for morphing and other stuff. For example, every character has a duplicate head (sonic_z, tails_head_z...) which you will need to replace with the head from your main model, unmodified. Click here for a list of what all the models are for.

Please follow the addon guide to import the model, its textures, and eventually animations.

You can now edit the main model, the morph target models and all additional models to your liking. Here's an example of how to replace a mesh on Blender.

To change textures, navigate into SADXPC Game Files in the Tools Hub, and copy the texture pack you want (SONIC.PVM for example.) into your project's system folder. You can then modify textures and use them in SAMDL. Note that if you're using HD textures, you should save your texture pack as PVMX.

Sonic's Light Dash Aura

The colour of the Light Dash Aura model is hardcoded.

If you want to edit it you need a DLL mod and use the following hack:

void __cdecl SetLSDColor()
{
        // #FF32A852 would translate to SetMaterialAndSpriteColor(1.0f, 0.19f, 0.65f, 0.32f);
        // To get a float color (range 0-1): 32 in hexadecimal is 50, divided by 255 it gives us 0.19.
	SetMaterialAndSpriteColor_Float(alpha, red, green, blue);
}

WriteCall(reinterpret_cast<void*>(0x4A1705), SetLSDColor);

Getting the models ingame

Once you've edited all the models/textures you needed to change it is time to try out your mod.

Disabling welds

The game links the vertices of the different character parts together to simulate skinning, we call that welding. To know which vertices to merge together, they hardcoded lists of vertex ids. So if you've modified a welded model (hand, arm, leg, shoe), the vertex ids will be all wrong and will either crash or look completely wrong.

For now, we will disable welding. Your model will appear disjointed in game like it is in SAMDL.

  1. Create a Codes.lst file in your mod folder (Skip if you already have one)
  2. Open mod.ini and add Codes=Codes.lst (Skip if you already have one)
  3. Open Codes.lst and choose one of the patches below
  4. Open the Mod Manager and click "save" to apply the code
Patch "Disable Sonic Welds" Required
write8 7D0B50 0xC3

Patch "Disable Tails Welds" Required
write8 7C6D80 0xC3

Patch "Disable Knuckles Welds" Required
write8 7C94D0 0xC3

Patch "Disable Amy Welds" Required
write8 7CCB90 0xC3

Patch "Disable Big Welds" Required
write8 7CE860 0xC3

Patch "Disable Gamma Welds" Required
write8 7CB560 0xC3

Disabling morphs

The game directly moves the vertices of a few character models to simulate wind (usually ears and quills), this is what we call "morphs". If your edited character does not match the original face, the effect might break your model.

  1. Create a Codes.lst file in your mod folder (Skip if you already have one)
  2. Open mod.ini and add Codes=Codes.lst (Skip if you already have one)
  3. Open Codes.lst and choose one of the patches below
  4. Open the Mod Manager and click "save" to apply the code
Patch "Disable Sonic Morph" Required
write8 4937B0 0xC3
write8 493500 0xC3

Patch "Disable Tails Morph" Required
write8 45B840 0xC3

Patch "Disable Knuckles Morph" Required
write8 473CE0 0xC3

Patch "Disable Amy Morph" Required
write8 485C50 0xC3
write8 485F40 0xC3

Patch "Disable Big Morph" Required
write8 48C720 0xC3
writenop 491325 5
writenop 491355 5

Disabling cutscene head

Each character except Gamma has a special head model (with an added mouth) for cutscenes. Each event head model has a set of expressions (surprised, smiling, frowning...) in the form of vertex animation (shape motion).

They are mainly used for cutscenes ("watch out, you gonna crash!") and one of the head is used when taking damage. If you don't remove them, the game will revert to Sonic's face or crash if you've edited the cutscene head model but not the individual faces.

  1. Create a Codes.lst file in your mod folder (Skip if you already have one)
  2. Open mod.ini and add Codes=Codes.lst (Skip if you already have one)
  3. Open Codes.lst and choose one of the patches below
  4. Open the Mod Manager and click "save" to apply the code
Patch "Disable Sonic cutscene head" Required
write8 493730 0xC3
Patch "Disable Tails cutscene head" Required
write8 45E470 0xC3
Patch "Disable Knuckles cutscene head" Required
write8 475660 0xC3
Patch "Disable Amy cutscene head" Required
write8 4867C0 0xC3
Patch "Disable Big cutscene head" Required
write8 48C6A0 0xC3
Patch "Disable Tikal cutscene head" Required
write8 7B37D0 0xC3

Building the mod

  1. In Tools Hub, click the build button
  2. Select "characters" then "manual" and hit export.
  3. Copy the resulting files into your mod's folder.

Now you can run the game and see the unwelded model in game.

You should now improve your models, make sure everything is alright with or without upgrade, and polish everything before welding. Try not to modify the models after the welds are done: if the vertex order change you'll have to remake the welds.

Welding the models together

This is where you need a DLL mod. We are going to link together every part that should appear linked. Make sure you followed the Create-a-DLL-Mod and that the dll is building fine.

Then add this line to the init function:

WriteJump(InitSonicWeldInfo, InitSonicWeldInfo_r);

And this function:

void InitSonicWeldInfo_r()
{
	
}

We are now hooking the function where the game sets up the weld information.

One weld info contains the base model, modelA and modelB and a list of indices

  • The base model is the first model (object 0 in general)
  • modelA and modelB are the two models linked together
  • the list of indices contains the vertex id of modelA that should be linked to modelB, for each linked vertex (modelA, modelB, modelA, modelB...)
uint16_t Sonic_UpperLegIndices[] = {
	0, 2,
	1, 3,
	4, 6,
	5, 7,
};

In this example:

  1. the vertex 0 of model A (first leg model) is connected to vertex 2 of modelB (second leg model).
  2. the vertex 1 of model A (first leg model) is connected to vertex 3 of modelB (second leg model).
  3. the vertex 4 of model A (first leg model) is connected to vertex 6 of modelB (second leg model).
  4. the vertex 5 of model A (first leg model) is connected to vertex 7 of modelB (second leg model).

The vertex indices of models can be seen in SAMDL and in Blender if you enable the feature.

The left upper leg weld is weld number 4 so it gives, in code:

SonicWeldInfo[4].BaseModel = SONIC_OBJECTS[0];
SonicWeldInfo[4].ModelA = SONIC_OBJECTS[12];
SonicWeldInfo[4].ModelB = SONIC_OBJECTS[13];
SonicWeldInfo[4].VertexPairCount = (uint8_t)(LengthOfArray(Sonic_UpperLegIndices_DC) / 2);
SonicWeldInfo[4].WeldType = 2;
SonicWeldInfo[4].anonymous_5 = 0;
SonicWeldInfo[4].VertexBuffer = 0;
SonicWeldInfo[4].VertIndexes = Sonic_UpperLegIndices_DC;

This links model 12 and 13 (see model list here) together, using the vertices we set in Sonic_UpperLegIndices_DC.

You can see example applications of welds in this guide, SA1Chars, ShadowSA1 or Female Sonic. Note that the last two examples use a trampoline to call the original weld init function so that Metal Sonic welds stay intact.

If you fill a weld with zeros, it will be ignored, so you can weld models one by one.

Editing cutscene faces

Editing the cutscene head is time consuming, and no proper tutorial exist:

  1. Locate the cutscene head model in figure\[CHARACTER]\models. Search for a head model with two nodes, that will be the cutscene head.
  2. Locate the cutscene head shape motion in figure\[CHARACTER]\models. The file will contain .nas.
  3. In SA TOOLS, run SplitShapeMotion.exe, and give it the model and motion you located, it will create a new file containing all the faces.
  4. Edit the cutscene head model you found earlier to your liking, make sure the model is finalized before editing the set of faces.
  5. Open one of the faces extracted by splitShapeMotion in the Blender Addon, note what the expression is so that you can reproduce it. When ready, replace the model with your modified cutscene head model, then edit it by only moving vertices. Once done, save the file.
  6. When all your models are done, drag and drop the folder containing all the faces into BuildShapeMotion.exe, it will create the new set inside the folder.
  7. Replace the original file with the built one, then build the mod using SAToolsHub

Final notes

SA TOOLS exports INI files that you don't need. If you've only edited characters, you can remove all the inis except chrmodels_orig.ini, and remove them from your mod.ini.

You can ask for help on the public discord, we will gladly help you with your welds!

⚠️ **GitHub.com Fallback** ⚠️