[Release] Vehicle Resource Merge Tool

FiveM Merge

About

fivem-merge is a library made with Node.js which can pack multiple vehicle resources into one resource.
Also comes with a CLI tool.

Prerequisites

node-current
Node.js and NPM is required.

Installation

fivem-merge version
With npm:

$ npm install -g fivem-merge

With yarn:

$ yarn global add fivem-merge

Usage

With shell inside your server’s resource directory:

$ vmerge --help
$ vmerge car1 car2 carEtc --output cars
fivem-merge is also a library and therefore can be used in Node.js
const vmerge = require('fivem-merge');
vmerge([ './car1', './car2', './carEtc' ], {
  outputPath: './cars'
}) // => Promise<undefined|error>

Examples

With shell inside your server’s resource directory:

$ # merges the 18lamborghini and the 17lamborghini resources into a new resource called lamborghinis
$ vmerge 18lamborghini 17lamborghini --output lamborghinis
$ # merges fd vehicle resources into one pack
$ vmerge fd1 fd2 fd3 fd4 --output fd
$ # use relative directories and --output shortname -o
$ vmerge ./resources/coolcar ./resources/bestcar -o ./resources/[vehicles]/goodcars
$ # merge resources into an already merged resource
$ vmerge ./src/car1 ./src/car2 ./resources/vehicles -o ./resources/newVehicles && rmdir ./resources/vehicles && mv ./resources/newVehicles ./resources/vehicles
$ # if you don't want meta files to be linted automatically, add the `--no-lint` parameter
For Node.js
const vmerge = require('fivem-merge');
/**
 * an array of vehicle resources to merge together
 * @type {string[]}
 */
const resourcesToMerge
/** @type {Object} */
const options = {
  /**
   * whether output XML files should be linted for human readability
   * @type {Boolean}
   * @default true
   */
  lintOutput: true,
  /**
   * the output directory of the merge resource
   * @type {string}
   */
  outputPath: './vehicles',
}

vmerge(resourcesToMerge, options)

How it works

The fivem-merge API creates a temp directory with a fxmanifest.lua containing a files table and data_file statements of all your selected resources’ manifests combined (also compatible with FXv1 __resource.lua).
All data files will be merged into the data folder. Unused or empty data files will be omitted.
Streamed files will then get moved into their own stream/<gamename> folder. If there are any vehicles with the same game or file name, an error will be emitted and will exit. You will need to manually fix this.
Once all these operations have been complete, the temp directory will get moved to your --output directory.

Keep in mind

fivem-merge is currently in an unstable release version, you will probably find bugs.
In case you do encounter a breaking error, getting frustrated and uninstalling the package doesn’t help.
Instead, open an issue for support and so we can fix it, or if you’re a developer make a pull request.

fivem-merge cannot merge scripts (including any vehicle_names.lua).
If any of your resources contain anything unmerge-able, a warning will be emitted with details to merge manually.

Due to my limited knowledge (and limited documentation), fivem-merge currently only supports the following data files:

  • HANDLING_FILE
  • VEHICLE_METADATA_FILE
  • CARCOLS_FILE
  • VEHICLE_VARIATION_FILE
  • VEHICLE_LAYOUTS_FILE
  • CONTENT_UNLOCKING_META_FILE

An error will be emitted and the application will exit with code 1 if the API meets a data file not of the above.
If you would like to help make other data files supported, message me on Discord or make a pull request.

NOTICE

This tool is intended to be used by server owners whom have source files to their vehicles to easily pack them automatically.
I do not recommend nor condone deleting the original files after using this tool, being intended for build operations and is currently in a non-stable version.

Contributions

3 Likes

Looks like a great tool! Can’t wait to try it!

1 Like

Hey! Tried to run it, this happened. Tips?
npm i fivem-merge-cli
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! errno -4058
npm ERR! enoent Error while executing:
npm ERR! enoent undefined ls-remote -h -t ssh://git@github.com/TFNRP/fivem-merge.git
npm ERR! enoent
npm ERR! enoent
npm ERR! enoent spawn git ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

My bad! That happened because a bad dependency remote being used from GitHub instead of NPM.
A fix has been implemented, apologies for not noticing this sooner.
(trouble reinstalling? try latest npm i -g fivem-merge-cli@latest)

Update

The fivem-merge-cli library has been deprecated and bundled with fivem-merge instead.
Make sure you uninstall and install the other library:

npm r -g fivem-merge-cli && npm i -g fivem-merge

If you’re interested, fivem-merge can also be used as a Node.js package and can be required.

Install in your package:

npm i fivem-merge

Require it:

// CommonJS
const vMerge = require('fivem-merge')

// ES6
import * as vmerge from 'fivem-merge'

Please keep in mind this package is currently in an unstable 0.0.x release version and is in constant development.

We’ve sifted out some bugs, including a common crashing issue when the merged resource loads (which was inevitably caused by JavaScript interpreting arrays with indexes in XML parsing).

Please remeber to open an issue if you encounter any problems with this resource.
It is the guaranteed way to get your problem seen by others and fixed faster, and helps contribute to the package for ease of use for everyone.

Changelog

v0.0.6

Fix (feature)

1c7379b completely rewrite meta merging, no longer merges duplicate items

Fix

9762896 add support for +hi.ytd files
8ee94a6 fix Item tag arrays being translated to an index

Fix (CLI)

9c4d38c incorrect --verbose shortname (should be -V)

v0.0.5

Feature (CLI)

a1c652f add cli

v0.0.4

Fix

b16563f continue if data file unsupported
83b21c0 add CExtraContentFileMounter file name

Chore

2426abf lint

v0.1.6 has been released, introducing the ability to merge every resource in a directory recursively.

Now you no longer have to do

vmerge ./vehicles/car1 ./vehicles/car2 ./vehicles/car3 -o ./output

and can instead

vmerge ./vehicles -o ./output
Changelog

v0.1.6

New feature

  • b6f12ab recurse non-resource directories

Fix

  • 90e0a08 cli: fix option shortname being ignored

Refactor

  • f80d933 linting and consistent-return compliance
  • 6263677 cli: lint cli

Chore

Documentation

  • 242b965 add some documentation and typings

v0.2.6 has been released, fixing a major issue for anyone who was using linting.
If your manifest contains an invalid path to a data file, the script will also attempt to check if it exists elsewhere.

Changelog

v0.2.6

Feature

  • 8d64bbd check if data file exists in /data/ when unspecified in manifest

Fix

  • 4362200 paths should also be type of string
  • 721ab35 bad linting causing meta arrays where they shouldn’t

Chore