Saturday, August 20, 2022

PARTS_ANIMATIONS.BIN Basic Hex Editing Tutorial

Update: you should check out TVasya's PartAnimatorulator tool, which took this very tutorial as a reference.

(thanks to RedCarDriver for her research on PARTSANIMATIONS.BIN files and some corrections, without such this little tutorial wouldn't have been possible)

PARTS_ANIMATIONS.BIN is a file that handles part animations such as opening hoods, trunks and doors. It's located in CARS\<XNAME> for each car; you could do fine without those for add-on cars, but you wont get any animations for the aformentioned parts.

    Things you will need for this tutorial

    Step 1: Picking a file and changing the XNAME

    You'll need to start from an existing file, since you will be doing some admitedly hackish work with a hex editor and we're working with a file that's not fully documented, there are some limitations; amongst them (and the biggest one) is that you have to pick a PARTS_ANIMATIONS.BIN from an existing car that has an XNAME that's within 2 characters of your add-on's XNAME. That means you have to pick from a car which XNAME is either 2 characters shorter or 2 characters longer than your add-on's XNAME.

    I'll be using my SC300 mod (SC300Z30 - 8 characters) for demonstration purposes (since I didn't bothered for its animations given it has no proper engine model). I'll be picking up the LANCEREVO8 (10 characters) part animations, so I'll just copy its PARTS_ANIMATIONS.BIN into the SC300Z30 folder.


    Open you hex editor and open your PARTS_ANIMATIONS.BIN file
    Make sure your hex editor displays 16 bytes per line. In FrHed said option is in Options > View settings. (uncheck the Adjust number of lines automatically option as well)
    You will see the window is split in two sections: left one is the data displayed as hexadecimal numbers, right one is the data displayed as plain text.


    To change the XNAME displayed in the right side panel (plain text), first click on the first character, then use the Find and Replace function of your hex editor; in FrHed is found in Edit > Find and Replace > Replace (you can also press Ctrl+H to bring up the Find and Replace dialog). Type the XNAME you're going to replace in the Find what textbox, then in the Replace with box type the XNAME you are going to use for your car. Click on the ...following occurances button to replace all instances of the old XNAME.


    Once done, close the dialog.

    Step 2: Padding/Deleting Bytes

    You'll see the XNAME has been changed, however there's a bit tedious yet neccesary step to be done. Since your XNAME might be shorter or longer than the original by up two characters, you'll need to make up for the difference in order to make the file work; otherwise your game will crash upon loading your car. Look for every instance of the XNAME, then either add (make you have Insert mode on, it's usually toggled with the Insert key) or delete the needed bytes after the XNAME's parts (right after the 74 in hex/the "t" in plaintext) in the hex panel; each byte is represented by a two-digit hexadecimal character in it. In my case, I'll have to pad out by 2 bytes for each instance of the XNAME.

    This is how it looks before padding...


    ...and this is it looks after padding. Note where the highlighted 01 00 00 00 set of bytes -the beginning of the next part block- is now shifted by 4 bytes after padding; that 01 has to always be at the beginning of a new line, otherwise the animations won't either work or the game will crash.


    Step 3: Changing the XNAME hash

    In the PARTS_ANIMATIONS file there's also the hash of the XNAME, without the right one, the file simply won't work. To do so, first open NFS-Hasher or Binary's Hasher feature (it can be found at Modder Mode > Tools > Hasher. Enter the XNAME of the car you took the animations file (in my case it would be LANCEREVO8) and take note of the Bin File value; that's the hash of the original car's XNAME.


    Back to the hex editor, use the Find & Replace function to replace the hash of the original car's XNAME with the one of your car's XNAME. (In FrHed, to find and replace a hexadecimal value, you use the <bh:##> notation for each hex number.)


    When you're done, save the file. Boot up your game, and if you did everything right you will have working part animations


    Step 4: Editing Pivot Coordinates

    There are times where the part animations for your car will be off (e.g. using a file from a hatchback for a sedan will yield to the trunk hinging from thin air while opening), in my case, you will see the hood is not quite hinging from where it should be. To solve this you'll have to edit the pivot coordinates from a similar car.

    To do so, first open your PARTS_ANIMATIONS in the hex editor and go all the way to where the hash of your car's XNAME is. Right in the next line is the beginning of the pivot coordinate blocks (the highlighted 00 00 80 3f).


    Each block consists of 4 lines, the last one is the one that matters: it has the coordinates of the pivot in XYZW notation.



    Each block corresponds to a pivot and they come in this order:
    _ZAM_HOOD_REG Hood hinge (regular)
    _ZAM_HOOD_FRONT Hood hinge (front)
    _ZAM_LEFT_HOOD_SPLIT Split hood hinge (left)
    _ZAM_RIGHT_HOOD_SPLIT Split hood hinge (right)
    _ZAM_FRONT_HOOD_SPLIT Split hood hinge (front)
    _ZAM_BACK_HOOD_SPLIT Split hood hinge (back)
    _ZAM_LEFT_DOOR_REG Door hinge (regular-left)
    _ZAM_LEFT_DOOR_SCISSOR Door hinge (scissor-left)
    _ZAM_LEFT_DOOR_SUICIDE Door hinge (suicide-left)
    _ZAM_RIGHT_DOOR_REG Door hinge (regular-right)
    _ZAM_RIGHT_DOOR_SCISSOR Door hinge (scissor-right)
    _ZAM_RIGHT_DOOR_SUICIDE Door hinge (suicide-right)
    _ZAM_TRUNK_REG Trunk hinge
    _ZAM_LEFT_DOOR_WIDE1 Door hinge (widebody-right)
    _ZAM_LEFT_DOOR_WIDE2
    _ZAM_LEFT_DOOR_WIDE3
    _ZAM_LEFT_DOOR_WIDE4
    _ZAM_RIGHT_DOOR_WIDE1 Door hinge (widebody-left)
    _ZAM_RIGHT_DOOR_WIDE2
    _ZAM_RIGHT_DOOR_WIDE3
    _ZAM_RIGHT_DOOR_WIDE4


    To get the pivot coordinates of the part you want, open the mesh of your add-on with a 3D modelling program, make a tiny cube and place it where you want. Depending of your program of choice, you can get the coordinates directly (e.g. the Object Properties panel in Blender or the Exact Transform tool in ZModeler 2) or you might have to resort to some improvisation (like the double cube trick in ZModeler 1 I described in my conversion tutorial -minus the duplicating part step-)

    Once you have the coordinates, go to your hex editor and go to the line of the pivot you want to modify. The coordinates are in floating point little-endian values, where 0 is center, positive values are towards the front/right/top and negative values are towards the back/left/bottom. Some hex editors like HxD allow you to just punch the number directly (via the Data Inspector panel) and they will handle the conversion to hex. Others might require to make the conversion yourself, I recommend using this float to hex online converter to help yourself (set it to swap to big-endian to get the right values, though). Repeat this process for every pivot you want to edit; when you're done, save the file.

    If you did everything correctly, your part animations will now be spot-on.

    Wednesday, October 13, 2021

    How to make NFSHS-styled track slides and vidwalls

    In this tutorial you will learn how to make a track slide and vidwall in a style that's quite close to the one used in the vanilla game's ones.

      Stuff you'll need

      • GIMP [portable version] - image editor(version 2.10 shown; while you will still be good if you're using the latest version -3.0.4 at the time- you can use the GIMP 3 version of the template instead, which has several filters pre-applied as non-destructive effects)
      • My set of track slide/vidwall templates
      • FSHTool [download] - QFS/FSH file unpacker/packer, for slides and vidwalls
      • OPTI Iambic Heavy Italic font [download]
      I will use Code 4's Atlantic Forest Final as the example for this track since it's a great track and deserves a proper slide/vidwall set.

      GIMP's user interface

      If you're not famliarized with GIMP, I will give you a quick rundown of the UI so you can get yourself acquainted with it. Here's the default UI for version 2.10


      1. Toolbox: here's where you will find most of the tools used for editing, like selection, paintbrush, bucket fill, text, etc. By default tools are grouped into several groups (which are indicated by the small arrows on the bottom right of the buttons); to select another tool in the group, right-click on the button to display the available tools in that tool to select them. Also, you can select the foreground and background colors (the black and white squares, respectively)
      2. Tool options/Information/Undo history/Recent files tabs: for this tutorial we're just going to focus on the Tool options; here's where the selected tool's parameters can be configured.
      3. Brushes/Patterns/Fonts/Messages tabs: not important for this tutorial.
      4. Layers/Channels/Paths tabs: here's when you can manage the image layers, channels and paths. We'll just focus on layers and paths.

      Step 1: Uncompressing the .qfs files

      1. Unzip FSHTool into a folder
      2. Copy the data\feart\slides\t##_00.qfs and the data\feart\vidwall\t##.qfs files from the game's folder into the FSHTool folder
        • The ## stands for the track number, here's the list of numbers with their corresponding track:
          Track #
          Track name
          Track folder
          0
          Landstrasse
          GERMANY
          1
          Celtic Ruins
          HILLS
          2
          Route Adonf
          FRANCE
          3
          Durham Road
          UK
          4
          Dolphin Cove
          COASTAL
          5
          Kindiak Park
          PARK
          6
          Snowy Ridge
          SNOWY
          7
          Raceway
          GT1
          8
          Raceway 2
          GT2
          9
          Raceway 3
          GT3
          10
          Hometown
          HOMETOWN
          11
          Redrock Ridge
          REDROCK
          12
          Atlantica
          ATLANTICA
          13
          Rocky Pass
          ROCKYPAS
          14
          Country Woods
          COUNTRY
          15
          Lost Canyons
          LOSTCANY
          16
          Aquatica
          AQUATICA
          17
          Summit
          SUMMIT
          18
          Empire City
          EMPIRE
      3. Now either drag the .qfs files into the FSHTool.exe file to uncompress them; a new folder with the file name will be generated for each file.

      Step 2: Making the slide background image

      1. Take a screenshot of the track in-game; remember to disable the HUD with F5 first.
        • Also I recommend to take it under the highest resolution possible.
      2. Make sure you have installed the OPTI Iambic Heavy Italic font.
      3. Unzip the files of the templates to a folder and open the track_slide.xcf file in GIMP. Select the base layer in the trackimg group by clicking on its name in the Layers pane.

      4. Open the screenshot you took and resize (go to Image > Scale Image) it to 640px wide if neccesary. Then copy it (Ctrl+C) and paste it (Ctrl+V) into the base layer of the template. You'll see there's a white dotted border which is the selection and in the Layers pane there is a Floating Selection layer; that's what we've pasted. Pick the Move (keyboard: M) tool in the toolbox, then click and drag the layer to adjust it; hold Ctrl while dragging to keep it sticked to the image edges.

      5. When you're done, anchor the selection to the layer below (base) by going to Layer > Anchor Layer (Ctrl+H). You will see the yellow dotted border, which is the layer boundary will change size; we don't want that since we'll need all the layers in that group to have the same size.

      6. Select the trackimg group by in the Layers pane, then go to Layer > Mask > Mask to selection. Go back to the base layer. You will see the selection now fits the image; now we'll crop it to that selection by going to Layer > Crop to selection. The layer size is now adjusted to the selection.

      7. It's time to adjust the image contrast; to do so go to Colors > Curves. Adjust the curve a little like this (moving the bottom left point towards the right will make the darkest colors in the image darker and moving the upper right point towards the left will make the brightest colors brighter. When you're done, click OK .

      8. Copy the layer (Ctrl+C), switch to the blur layer and paste it (Ctrl+V) in there. Now go to Filters > Blur > Zoom Motion Blur. Move the crosshair to set where the blur center will be, adjust the blurring factor between 0.100 and 0.150, and set the Clipping to Clip. Click OK when you're done. Copy (Ctrl+C) the layer, switch to the add+blur layer and paste (Ctrl+V) into it. Also, deselect the selection by pressing Ctrl+Shift+A.

      9. Switch to the colortint layer, then click on the foreground color in the toolbox to open up the color picker dialog. Click on the HSV button, then pick a color with around  50 S(aturation) and 75 V(alue). Click OK to select it.

        Now pick the Bucket Fill (Shift+B) tool and click on the image to paint the layer for the color tint. Then pick a color with 100 Saturation and Value, go to the gradientcolor layer and click right in the middle of it to paint the gradient above and below the track picture. You should end up with a similar result as this:

      Step 3: The track name text

      1. Pick the Text (T) tool in the Toolbox, then go to the <track name> layer and triple-click on it to select all the text; type the track name afterwards, the layer name will change as well.

      2. Hide the track name layer by clicking on the eye icon next to it, then go the nameshadow layer and change its name like we did with the track name one; if the name goes out of bounds, just place the mouse on the right side of the textbox till you see a small orange rectangle and click on it to automatically adjust the textbox size to the text.



      3. Unhide the track name layer and go to the textdeg_colorpick layer. Pick the Color Picker (O) tool and click on the white square to set it as the foreground color, then Ctrl+click the cyan square to set it as the background color. Next, pick the Gradient (G) tool, go to the textdeg layer and click-drag over the length of the text, like in the following image. When you're done, press Enter to apply the gradient.
        • You can zoom in and out with Ctrl+mouse wheel or with the + - keys


      Step 4: The track map

      1. Take a screenshot of the track map in-game. To do so:
        • Set the map to Full Screen and at the farthest zoom possible in Heads Up Display Options
        • Start a race, switch to bumper cam and turn 90 degrees facing a dark wall; drive up close to it.
        • For better results, set track time to night and turn off your car lights with the L key
      2. Open the screenshot and pick the Select by Color (Shift+O) tool. Set the threshold to 75 and click on the track map to select it (you might have to zoom in). If there's anything else than the map selected, you can pick the Rectangle Select (R) tool and Ctrl-click and drag to deselect the parts you don't want.



      3. Go to Select > Grow, set how many pixels you want to grow the selection (that will depend on how big and complex your map is, alongside resolution; I will pick 1px for mine) and click OK. You will see the selection is now thicker

      4. Pick the Free Select (F) tool, then deselect the parts of the map you don't need by Ctrl-clicking and making a shape around those; press Enter to confirm the deselection. Then bridge the gap that's missing by Shift+clicking, selecting in a way that bridges the gap and press Enter when done

      5. Go to the Select > To Path, you will see now a red outline lies in place of our selection; that's a path.

      6. Pick the Elliptical Selection (E) tool and make a selection right where the dot of your car is in the map; Ctrl+drag when making the selection to make a perfect circle; move said selection towards the middle of the path we made if neccesary and make a path out of the selection


      7. Now go to Layer > New Layer... (Ctrl+Shift+N). Name the layer course and click on OK. Make sure you have white as foreground color (you can reset the default colors by pressing the D key or clicking on the small two squares on the lower left side of the color selector, then switch the foreground/background colors around by clicking on the arrows on the upper right of the color selector or pressing the X key); then switch to the Paths tab and right-click on the path of the track course, click on Fill Path, choose Solid Color and click on Fill. You will see now there's the path is now filled.

      8. Make a new layer called start and repeat the process with the other path. When you're done, you can hide the paths in the same way you can hide layers. Also, resize the image to 640x480 px if neccesary.

      9. Copy (Ctrl+C) the course layer, then go back to the template file and paste it (Ctrl+V) into the mapbase layer and anchor it. Then go back to the map file, copy the start layer, paste it in the mapbase layer, but this time press Ctrl+Shift+N to make a new layer out of it.

      10. Go to the map group, then pick the United Transform (Shift+T) tool and resize (by clicking and dragging the edge handles) and rotate (by clicking and dragging outside the box) the group as needed. When done, press Enter.

      11. Go to Layer > Crop to Content to crop out the empty space off the map, pick the Alignment (Q) tool and first click on the track image, then Shift+click on the track map. Now press the Align center to target and the Align middle of target buttons to align the track map to the track image.

      12. Go to the mapbase layer, then go to Filters > Distort > Emboss. Use the settings displayed here and click OK.

      13. Go to the start layer, lock the alpha channel by click on the 3rd icon to the right of the "Lock" text right over the layer list (it's the checkerboard one), pick the Gradient (G) tool, set the shape to Conical (symmetrical), pick white as foreground color and a dark gray as background color. Click and drag from the center of the start point like in the image and press Enter when done.

      14. Go to Filters > Blur > Gaussian Blur and use the settings below to smooth out the start point, click OK to apply the blur.

      15. Go back to the mapbase layer, go to Layer > Transparency > Alpha to Selection, then go to Select > Grow and grow the selection by 2 or 3 px. Make a new layer called mapshadow and put it below the mapbase layer (by dragging it below it or using the arrow buttons under the layer list). Pick black as the foreground color and paint the selection with the Bucket Fill (Shift+B) tool, deselect everything by pressing Ctrl+Shift+A, then go to Filters > Blur > Gaussian Blur, set a blur of 3 and click OK. Repeat this process with the start layer.

      16. Make a new layer and name it color, pick a foreground color with 75 saturation and 50 color then use the Bucket Fill (B) tool to color the layer. Set the layer mode to Overlay. We're done with the track slide.

      17. To save the track slide, go to File > Export (Ctrl+E) or File > Export As (Ctrl+Shift+E). Save it as 0000.bmp in the T##_00 folder of the qfs file you uncompressed with FSHTool. When the export options dialog shows up, use the settings shown below and click on Export


      Step 5: Creating the vidwall

      1. Open the track_vidwall.xcf file, then proceed to make the track image like we did in Step 2; the only difference is that you'll have to resize the track image to 381 pixels wide.

      2. Pick the Text (T) tool, select the trackname layer, triple-click on it and type the track name. Then pick the Move (M) tool and move the layer towards the middle vertical cyan dotted line (a guide) until the center snaps to it.

      3. Go to Layer > Transparency > Alpha to Selection, then to Selection > Grow and grow the selection by 5 pixels. Go to the shadow layer, paint it black with the Bucket Fill (Shift+B) tool, deselect everything (Ctrl+Shift+A), then go to Filters > Blur > Gaussian Blur, set the blur to 5 and click OK


      4. Go to the colortint layer, pick a foreground color with 70 Saturation and 50 Value and paint the layer with the Bucket Fill (Shift+B) tool.

      5. To save the vidwall, go to File > Export (Ctrl+E) or File > Export As (Ctrl+Shift+E). Save it as 0000.bmp in the T## folder of the qfs file you uncompressed with FSHTool. When the export options dialog shows up, use the settings shown below and click on Export


      Step 6: Compiling the .qfs files and setting them in-game

      1. Go to the T##_00 folder and drag the index.fsh file into the FSHTool executable (you might need to open a second window to do this)
      2. Go to the T## folder and drag the index.fsh file into the FSHTool executable (you might need to open a second window to do this)
      3. Copy the t##_00.qfs file and paste it into the data\feart\slides folder of NFSHS (make backups first!)
      4. Copy the t##.qfs file and paste it into the data\feart\vidwall folder of NFSHS (make backups first!)
      And that's it! This is how you can make NFSHS-styled track slides and vidwalls. Hope this tutorial has been helpful.

      See you around!

      Monday, May 24, 2021

      Creating alpha channels for the car textures with GIMP

      (download offline version here)


      Note: this tutorial has been written for GIMP 2.6 and 2.8; since version, 2.10 GIMP has a different color space for alpha channels, said values for this version are included.

      NFSHS (and NFS3) car textures (car00.tga) do have something called "alpha channel", which tells the game what kind of colors are assignated for the car. To edit them, people usually has Photoshop or Paint Shop Pro to do the job, but if you are broke (and want to stay legal), there's a third way: GIMP.

      GIMP is basically the free, open-source alternative to Photoshop, with some interesting features. But when it comes to editing alpha channels, it could be a royal PITA to accomplish the task. Luckly, I figured it out and I'm going to tell you how to do it.

      Step 1: Meeting GIMP and asking her out

      The first time you fire up GIMP, it would look like this:

      1. Toolbox: This is the place where are located the painting and selection tools, mostly. The foreground/background color selection is also in there.
      2. Tool Options: Here you can adjust the selected tool parameters.
      3. Layers/Channels/Paths Undo: Here you will see the images layers for edition. We´re are going to focus only on the Layers and Undo (in case you screw up).
      4. Brushes/Patterns/Gradients: IMO these are redundant, since they can be setted up from their respective tools. In fact, the only use I found for them was adding/editting brushes, but we won't make that kind of stuff in here right now.
      The toolbars can be customized to your liking, but we're going to use the default layout for this tutorial.

      Step 2: Let's put the channel together

      At this point, I will assume you will have your shiny new texture map ready for this. But you don't want to risk your precious job in case you screw up, right? Well, I packed a testing texture map file (test.bmp) attached to this tutorial in here.

      The map as you see, is weird (since it's a test map, don't try make sense of it, unless you want to become insane)

      Alright, let's put our hands to work.
      • Go to File > Open (or Ctrl+O, if you regonize the keyboard as the supreme speed king) and look for the "test.bmp" file. Open it (duh).
        Your GIMP screen will look like this:


      • Go to the the layers panel and right click the current layer we're working on (Background) and select "Add Layer Mask...". In the following dialog, under the "Initialize Layer Mask to:" section,  select "White (full opacity)"and hit OK. The layer window will change to this:


        The image thumbnail's clone next to the original image thumbnail's, is the mask layer. When you create (or import) one, GIMP will automatically switch to it, so you can start to work on it right away. When you work on the mask layer, the layer's thumbnail corresponding to the mask layer will have a white outline (well, currently we can't tell that at first glance since the mask is currently white, lol), and the same applies if you work on the image itself. Now click the image's thumbnail to work on the image, we need to select the areas for the colors.


      • Use the Fuzzy Select Tool (keyboard: U) and select the gray area with the white stripe (you can use the Free Select Tool -keyboard: F- as well, that's useful if you want to select a part of the image from it´s surroundings), we´ll pretend this is the main body color. Now switch to the mask layer and click the foreground color in the toolbox. This dialog will pop-up:


      • Write 224 on the R, G and B spaces, then hit OK. That shade of gray you will get is the alpha color for the main body color of the car (RGB: 224,224,224 / HSV: 0,0,88 / HTML:  e0e0e0).
        • If you're using GIMP 2.10, use RGB: 240,240,240 / HSV: 0,0,94 / HTML:  f0f0f0 instead
      • Now select the Bucket Fill tool and click in the selected area. Your image will look like this:


      • Now, since I'm too damn lazy, I will let you finish the alpha channel; the parts remaining are:
        • White stripe: secondary body color (RGB: 96,96,96 / HSV: 0,0,38 / HTML: 606060) [RGB: 165,165,165 / HSV: 0,0,64.7 / HTML: a5a5a5) for GIMP 2.10]
        • Gray drops area: interior color (RGB: 160,160,160 / HSV: 0,0,63 / HTML: a0a0a0) [RGB: 207,207,207 / HSV: 0,0,81 / HTML: cfcfcf) for GIMP 2.10]
        • Gray rectangle: driver's hair color (RGB: 32,32,32 / HSV: 0,0,13 / HTML: 202020) [RGB: 100,100,100 / HSV: 0,0,39 / HTML: 646464) for GIMP 2.10]
        • Blue rectangle: anything you want transparent (RGB: 0,0,0 / HSV: 0,0,0 / HTML: 000000)
      • For NFS3 the following colors should be used:
        • Body color: RGB 100,100,100 / HSV 0,0,39 / HTML 646464 [RGB: 168,168,168 / HSV: 0,0,66 / HTML: a8a8a8 for GIMP 2.10]
        • Secondary body color: RGB 200,200,200 / HSV 0,0,78 / HTML c8c8c8 [RGB: 229,229,229 / HSV: 0,0,89.5 / HTML: e5e5e5 for GIMP 2.10]
        • Transparent: RGB 0,0,0 / HSV 0,0,0 / HTML 000000
      You should have got something like this:

      Now let's proceed to the last step.

      Step 3: Saving the alpha (and the file)

      Now that we have the alpha ready, it's time to save it, alongside the file. Right-click the "Background" layer and select "Apply Layer Mask". Now the alpha will merge with the image. Then go to File > Save / Save As... (keyboard: Ctrl+S / Ctrl+Shift+S) and save it as car00.tga.

      A dialog will appear. Set it this way:


      For NFS3 either you should flip the image vertically with Image > Transform > Flip Vertically or in the Save as TGA dialog you should set the origin to Top left.

      And you're done. Is not that difficult, isn't?

      Additional notes

      If you want to edit an existng file's alpha channel, right-click the "Background" layer, select "Add Layer Mask", check the "Transfer Layer's Alpha Channel" option. Edit as you desire and save as described in Step 3.

      I hope this tutorial will be useful to you. AJ signing out