To assist with overriding world data I've added three new console commands to DFU that dump various world data into JSON files. The files go into the folder where you can find the DFU settings file and do nothing at all. They are just put there for you to move them wherever you like and copy JSON chunks from.
- dumpblock - Dump a RMB block to JSON file. e.g. "dumpblock RESIAM10.RMB"
- dumplocblocks - Dump the names of blocks for each location, or locations for a block, to JSON file. With no argument you get a list of blocks for all locations which will take a while so be patient. Providing a blockname gives a list of all locations split by region that contain that block. e.g. "dumplocblocks RESIAM10.RMB"
- dumpbuilding - Dump the RmbSubRecord of current building player is inside to JSON file. e.g. "dumpbuilding"
Along with the other asset replacement functionality availiable for modding DFU, I've added the WorldDataReplacement class to enable selective replacement of the world data from classic gamefiles. Currently it only allows buildings within a map block record (RMB) to be replaced. This could be expanded in future if a compelling use case is found. The way it works is that you create a JSON file containing data for the BuildingReplacementData struct in the WorldDataReplacement class and place it in StreamingAssets/WorldData. It needs to be named like this:
Code: Select all
string.Format("{0}-{1}-building{2}.json", blockName, blockIndex, recordIndex)
= blockName-blockIndex-building#.json
For example, the file I created for the Archaeologists mod is called RESIAM10.RMB-543-building10.json and overrides building 10 of RMB block RESIAM10. (refer to it as an
example, and compare it with the default data dumped by command to see what I changed)
To create a JSON BuildingReplacementData file simply start with the JSON file produced by the dumpbuilding command as detailed below and edit the values. You will need to put the top level guild faction id and the building type of 11 which is for a guild hall, but this can be any of DFLocation.BuildingTypes. Quality is only important for shops as far as I know, so put a 10 or 11 middle of the road number in here. The remaining two members of the structure are RmbSubRecord which is where the specific building data goes and AutoMapData which is optional but allows the map data for the block to be adjusted to be consistent with the updated building.
Code: Select all
{
"FactionId": 1010,
"BuildingType": 11,
"Quality": 11,
"RmbSubRecord": {
... Rmb block dump in here ...
},
"AutoMapData": [
... paste automap byte array dump in here (optional) ...
]
}
RmbSubRecord
You should start by using the dumpbuilding command to get a file with same name as you need with the RmbSubRecord JSON data from classic data files. Put the file in StreamingAssets/WorldData to have it replace dynamically when you run the game and test it works. Later you'll need to package it with the mod, but for development, testing and debugging streaming assets is the way to go.
The subrecord has 2 sections 'Exterior' and 'Interior', I am only changing and discussing the interior. This is split into following: Header, Block3dObjectRecords, BockFlatObjectRecords, BlockSection3Records, BlockPeopleRecords, and BlockDoorRecords. To add new things to the building (i.e. npc's, furniture etc), add json blocks to the following sections and increment the apprpriate count in the header.
- Block3dObjectRecords - 3d models, including the walls etc. Add new furniture like beds, shelves, chairs, tables in here. I found AlexanderSig's list of models he's replacing was really helpful to find the model id's, and you can also use the DF modeling tool as well.
- BockFlatObjectRecords - Flat sprites used for decorations etc.
- BlockPeopleRecords - Flat sprites used for npcs. The position field is filled from the position within the blocks file, just set it to a unique number within the list for the name seeding code. (start with 1 and count up...)
Next duplicate one of the existing things from one of these lists and change the coords a bit, increment count in header, and then check that you see the duplicated thing in game and the file is overriding the classic world data okay.
From here it's simply a case of adding all of the models, flats and npcs one by one. Getting them all in the right place is a case of trial an error. There's probably a way to calculate it but I gave up because DF coords and Unity coords are on different scales and each child is relative to parent coords in editor. Basically I calculated a rough position (i.e. in the right building) and then adjusted the coords, saved JSON file, exited and re-entered the building ingame - iterate like this until each thing is positions how you want. After a bit of practice it's not too bad. Someone could write an editor utility, but I wont be - it really is easy enough to edit data in JSON format.
AutoMapData
This is optional and to find the original data you will have to run dumpblock for the block the building is in. Each block has a 64x64 byte array for the automap. Cut this data out and reformat into 64 lines of 64 byte values that line up. I did this using editor find and replace but it was awkward. All 1 & 2 digit bytes need replacing with 3 character equivalents (e.g. '0' -> ' 0', '19' -> ' 19') so it all lines up, then put a newline after each bunch of 64 numbers. Then you can see the whole map chunk and should be able to easily edit the building shape and type. For a guild hall you will be changing 19's to 12's which makes each pixel blue rather than grey. You may also want to fix the shape if it's wrong (like the one I used) or alter it if you replaced the building model.
Once this block of data is edited, simply paste into the relevant part of the building JSON and test it.