don't click here

Sonic R Hacking

Discussion in 'Engineering & Reverse Engineering' started by MainMemory, Dec 1, 2009.

  1. Thanks. Unfortunately the game is locked at 640x480...
     
  2. total

    total

    Member
    67
    0
    0
    Ok, I made some progress here.
    Code (Text):
    1. --------------------------------------
    2. Sonic R models format (WIP). By softman
    3. ---------------------------------------
    4. struct VERTEX_PART   // 16 bytes
    5. {
    6.    word x, y, z    // integer part of float
    7.    byte unknown[10]
    8. }
    9.  
    10. struct MDL_PART_TRI  // variable size? (16 bytes...)
    11. {
    12.    word a, b, c
    13.    word ta, tb, tc   // texture coordinates. Hopefully...
    14.    dword null
    15. }
    16.  
    17. // consists of 6 points (probably quad split in 2 triangles,
    18. // but I'm not sure...)
    19. struct MDL_PART_POLY  // variable size? (20 bytes...)
    20. {
    21.    word a, b, c, d, e, f
    22.    word unk1, unk2
    23.    dword null
    24. }
    25.  
    26. // =========================================
    27. // FILE LAYOUTS
    28.  
    29. // Every chunk (part of the object) begins with dword
    30. OBJECT BEGIN
    31.    dword num_verts
    32.    [data]   // VERTEX_PART*num_verts
    33.    ...
    34.  
    35.    dword num_parts
    36.    [data]
    37.    /*
    38.    MDL_PART_x * num_parts. This is the most confusing part,
    39.    because there is no way to find out (for now) which part is
    40.    supposed to go next. So, you can only rip someting by hands
    41.    (take a look at first three words of the struct). Most of the time
    42.    the first struct is TRI, but the rest is somewhat strange
    43.    (many parts of variable size for example)
    44.    */
    45.    ...
    46.    dword unknown
    47. OBJECT END
    48. NEXT OBJECT...
    49. // =========================================
    I used .obj format for testing. Like so:
    Code (Text):
    1. v  x1, y1, z1
    2. v  x2, y2, z2
    3. ...
    4. # n vertices
    5.  
    6. g some_label
    7. f a, b, c, d, e, f
    8.  
    9. f a2, b2, c2, d2, e2, f2
    10. ...
    11. # n polygons (that is why I named struct as "POLY")
    I only tested sonic_h.bin model.
    Here is sonic's body part (partialy correct)
    [​IMG]

    Finally, here are offsets (decimal) for every sonic's part in sonic_h.bin
    Code (Text):
    1. 0:   body (34 vertices)
    2. 1268:   head (61 vertices)
    3. 3540:   left hand (28 vertices)
    4. 4180:   left boot (40 vertices)
    5. 5192:   left shoulder (12 vertices)
    6. 5456:   left leg (12 vertices)
    7. 5720:   right hand
    8. 6360:   right boot
    9. 7372:   right shoulder
    10. 7636:   right leg
    11. 7900:   tail (6 vertices)
    You can test this by zeroing entire object (except for the first dword of structs) as well as to try a different model.

    I'll try to find out more on this, but do not expect anything real very soon. But sure, any help would be appreciated :)
     
  3. Endgame

    Endgame

    Formerly The Growler Member
    Forgive my ignorance, but would a glidewrapper be able to work for Sonic R (either zeckensack's Glide wrapper, or nGlide)? It'd make it look better than in 640x480.
     
  4. Skeledroid

    Skeledroid

    Member
    227
    0
    0
    I imagine if you created a DLL with the same name, etc. and rewrote all its calls -- you could do whatever you want with the video output.
     
  5. I was just thinking, could you be able to add HD textures with a program of sorts? Hmm...
     
  6. xdaniel

    xdaniel

    Member
    [​IMG]

    Binary + source: http://magicstone.de/dzd/random/sonicr/SonicR-1.rar

    rmodel.c and rmodel.h for details, also some of the "unknowns" in the vertex struct are normals, I haven't changed the naming yet, though. The drawing functions tell you where they are. Camera is controlled via mouse and WASD & TFGH (slower), F9 resets the camera position, numpad +/- select which model part to render (defaults to all).

    Probably somewhat buggy and all, but hey, it works.

    Ah, oh yeah, command line is: "SonicR.exe <model file> <texture file>"
     
  7. total

    total

    Member
    67
    0
    0
    Wow, that was surprisingly fast. Thank you!
    Well, I had some doubts on it, because there were .grd files (which are probably vertex colors or normals).
     
  8. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,750
    340
    63
    SonLVL
    If you're up to making an editor, then I guess I don't have to. :v:
     
  9. xdaniel

    xdaniel

    Member
    total: I'm honestly not 100% sure either, but it sure looks like they're normals. Will look into those .grd files some more.

    MainMemory: I suck when it comes to making editors for 3D games, so you shouldn't count on me here. I guess I'll try - maybe in C#, which I'm "learning" at the moment -, but it's probably gonna end in failure :P
     
  10. Wow, that was quick :D

    I may try to port some of these to SADX. If you get an export function working :P
     
  11. xdaniel

    xdaniel

    Member
    Exporting the individual body parts shouldn't be much of a problem, proper animations and all are something else entirely. Well, I am looking into the limb structures and animation currently - the, in Sonic's case, san*.bin files - but limb rotations are giving me a headache... they come out backwards or something?

    [​IMG]

    (Also, disregard the lighting, it's junk. And this is san5.bin, btw, Sonic's standing pose ex. from the character select)
     
  12. total

    total

    Member
    67
    0
    0
    hey, I also looked in them :P
    That is what I figured out:
    Code (Text):
    1. struct keyframe&nbsp;&nbsp;// obj_transform*num_objects?
    2. {
    3. &nbsp;&nbsp; obj_transform model[num_objects]
    4. }
    5.  
    6. struct obj_transform // 24?
    7. {
    8. &nbsp;&nbsp; dword unknown[3]&nbsp;&nbsp; // more likely positions, but nothing happens if changed...maybe
    9. &nbsp;&nbsp; dword rot_x, rot_y, rot_z
    10. }
    As for rotations, have you tried this?
    [​IMG]
    [​IMG]
    And here are some macros
    Code (Text):
    1. /*----------------------------------------------------------------------------------*/
    2.  
    3. #define&nbsp;&nbsp;&nbsp;&nbsp; M_PI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3.1415926535897932
    4. #define&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;toFIXED(a)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((FIXED)(65536.0 * (a)))
    5. #define&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;POStoFIXED(x,y,z)&nbsp;&nbsp;&nbsp;&nbsp;{toFIXED(x),toFIXED(y),toFIXED(z)}
    6. #define&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ATTRIBUTE(f,s,t,c,g,a,d,o)&nbsp;&nbsp;&nbsp;&nbsp;{f,(s)|(((d)>>16)&0x1c)|(o),t,(a)|(((d)>>24)&0xc0),c,g,(d)&0x3f}
    7. #define&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SPR_ATTRIBUTE(t,c,g,a,d)&nbsp;&nbsp;&nbsp;&nbsp;{t,(a)|(((d)>>24)&0xc0),c,g,(d)&0x0f3f}
    8. #define&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DEGtoANG(d)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;((ANGLE)((65536.0 * (d)) / 360.0))
    9. #define&nbsp;&nbsp;&nbsp;&nbsp; RADtoANG(d)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((ANGLE)((65536.0 * (d)) / (2*M_PI)))
    10. #define&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RGB(r,g,b)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(0x8000|((b)<<10)|((g)<<5)|(r))
    11. #define&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DGTtoRGB(c)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(0x8000|(((c)&0x0f00)<<3)|(((c)&0x4000)>>4)|(((c)&0x00f0)<<2)|(((c)&0x2000)>>8)|(((c)&0x000f)<<1)|(((c)&0x1000)>>12))
    Also, the last dword in the file is somehow related to other animations...
     
  13. total

    total

    Member
    67
    0
    0
    So, grd files are vertices "colors" (let's name it "shading factor"). Every value (one per vertex) varies from 0x0000 (darkest\black) to 0xFFFF (brightest\white)
    Code (Text):
    1. // repeats 48 times
    2. struct light_data&nbsp;&nbsp; // num_verts*sizeof(word)
    3. {
    4. &nbsp;&nbsp; word verts_shading[num_verts]
    5. }
    6. --------
    looking forward for v0.2 of model viewer, xdaniel :)

    PS: I'll make bin2obj soon...maybe
     
  14. Aquaslash

    Aquaslash

    <The Has-been Legend> Moderator
    oh snap, this is what I get for not paying attention. This is QUITE awesome, though how do you display full models like that Sonic there (unless it can't be done in this build)
     
  15. total

    total

    Member
    67
    0
    0
    sr_bin2obj is done.
    Download

    Example:
    [​IMG]
     
  16. Just tested it out. On Sonic's model, there are UV errors on all of his body parts, yet when you look at them in the uv editor, they look fine.
     
  17. xdaniel

    xdaniel

    Member
    Download v0.2: http://magicstone.de/dzd/random/sonicr/SonicR-2.rar

    Honestly haven't worked on it at all the last few days (only rebuild it earlier), so no new screenshot; limb rotations are still wrong. If anyone wants to try and mess with them, check rm_PositionModel in rmodel.c for how I interpret them currently. It's most likely quite off :P

    In addition to the controls from v0.1, you can now select the animation frame to use by pressing F1 and F2 to go through them. Also, the command line changed: "SonicR.exe <model file> <animation file> <texture file>", so ex. "SonicR.exe sonic_h.bin san5.bin player00.raw".

    Will look into it again over the weekend, maybe.
     
  18. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,750
    340
    63
    SonLVL
    Well, I tried, but it fails on the second model, and I don't know what I did wrong. code
     
  19. total

    total

    Member
    67
    0
    0
    why not use BinaryReader instead?
    ---
    And for those, who interested (anyone?), I'm no longer working on sr_bin2obj, because .obj is crap. I like maxscript+custom_binary_format better.

    ps: and seriously, since there is almost no interest in this, should I bother writing anything here?
     
  20. I for one am interested. It's nice to see someone working on this at last :)