Module-separated Resources Guide

Users who are viewing this thread

Janus

*spicy* *camper*
Administrator
Simple Section - The Basics

I'm making this post since there doesn't seem to be a guide yet to having your mod keep all of it's resources within it's folder in the Modules directory, rather than overwriting BRF and texture files in the root M&B installation.

This method will keep your mod's resources (BRFs and textures) separate, so that they don't conflict with other mods and they won't globally affect all mods including the Native game. This method was made available by Armagan in v.710.

1. Navigate to your mod's folder in Modules and make a couple of subfolders: "Textures" and "Resource" (note the lack of an "s" on the end), so it's like "Mount&Blade\Modules\MyMod\Resource".

2. Stick your BRF files in the new "Resource" folder, and your textures in the "Textures" folder.

3. Now you'll need to edit your mod's module_info.txt file to have it load them from the right place. With the file open in notepad, Look for the "scan_module_textures = 0" line and change it to "scan_module_textures = 1". This change makes the game look in the mod's "Textures" folder first when trying to find a texture, before even attempting to load from the default textures.
At this point you need to find the line for each BRF resource file in your new "Resource" folder. The lines which load the resource files will read something like "load_resource = materials". For each line referring to a file you've included, change the start of the line from "load_resource" to "load_module_resource". For instance, if you have an edited version of materials.brf for your mod, change the "load_resource = materials" to read "load_module_resource = materials". These changes tell the game to look for each of these resource files from your mod's "Resource" folder instead of loading them from the default root "CommonRes" folder.

That's basically it. From that point your mod will use it's own separate texture and BRF files.

If you want examples of mods that use this method successfully, check out the latest versions of the Last Days mod and Arena Expansion mod.

If you have other files besides BRF files or textures, such as sounds and music, these cannot yet be kept separate in a mod folder.

EDIT: another thing to note, if you add in your own new BRF files which have their own names (i.e. "mycoolitems.brf"), these need to be referenced in the module_info.txt file as well. Just add in a new line below the other "load_resource" lines, in this case "load_module_resource = mycoolitems". Be sure to add these new references BELOW the others, as placing them at the top can cause M&B to crash when your start it. The game needs to load the initial materials, shaders, and so forth (ala "load_resource = materials") before any mesh-related BRF files (such as you would be adding) are loaded.


EDIT 1-13-06:
Intermediate Section - No Need to Override Default Mesh Files

This section describes modifying your mesh BRFs (not the texture and materials BRFs) so that they don't override the default vanilla files, but instead only contain your new meshes and simply add on to whatever else is already loaded in the module. It assumes you have added your new meshes to standard files such as "item_meshes1.brf", "weapon_meshes1.brf", or other such files.

This is actually not very difficult. Just open the file in question in BRFView and, one by one, select each original (vanilla M&B) mesh in the list and click the "Delete Mesh" button at the bottom to remove it. Be careful about clicking the items, as the current BRFview version will crash if you click an empty spot in the list (click and miss one of the names). Minor annoyance there. Once you've deleted all the original meshes and left only the new ones you added, be sure to Save the file.
Alternately instead of deleting all vanilla items, you can simply start with an empty BRF file and add all of your new items to it. If you want an empty BRF file to act as a clean slate for adding your own meshes in BRFview, you can download one here.

Now rename your updated file to something unique such as "my_cool_items_1.brf". Edit your module_info.txt to switch back to "load_resource" for the file which will no longer be overridden (whichever one you just got through renaming) so that the vanilla resource will be loaded again. Then add in a "load_module_resource" line for your renamed BRF file after all other "load_resource" and "load_module_resource" lines, for example "load_module_resource = my_cool_items_1".

That's all there is to it. Your mod will now take up less space, be less likely to conflict with other resources, and will be easier for others to use in their own mods along with other resources (assuming you allow others to use your stuff).

Advanced Section - Better Material/Texture Separation

This additional section is for people who are adding their own new separate DDS texture files, who have had to edit "materials.brf" and "texture_names.brf". This guide assumes you have already successfully done so by following the hex-editing in n008's guide here; if not, you should follow through that and have successfully hex-edited the files where they don't crash M&B when loaded. If you can't get that part figured out, these further instructions will be of no use to you.

Alright, you've hex-edited the materials.brf and texture_names.brf files to include new stuff, right? Open your modified copy of "materials.brf" back up in your hex editor.

Now move the selection cursor to 4 bytes after the end of the word "material" by clicking in the right side at that place. The start of the file before the cursor should have this many characters (note only 3 "dots" after it; the "w" is included in those 4 bytes):
Code:
. . . . m a t e r i a l w . . .
Now by clicking right after that and dragging the cursor, select everything from that point all the way down to 4 bytes before the start of your additions to the file. It might take a little hunting to find the start of your additions. Simply delete everything you have selected there.
You'll now need to change the byte just after the word "material" at the start of the file to reflect how many materials are now listed (same as you did in n008's tutorial). If you had 8 materials added, the hex value should of course be changed to 08 (shows up as a "dot"). That number of course tells the game engine how many entries to try to read.
The "materials.brf" file is now cleaned out, good job.

Now open "texture_names.brf", making sure the first characters (which are left alone) look something like:
Code:
. . . . t e x t u r e A . . .
Use the same method as above of selecting all of the original definitions and deleting them, leaving only the ones you had added. Update the byte after "texture" to reflect the correct number as you did above.

Once you've hex-edited those, you're almost done. Rename both files by adding something like "mymod_" to the beginning of the filenames.

Now all that's left is to change your module_info.txt to switch it back to using "load_resource" instead of "load_module_resource" for the lines pertaining to those 2 files. Therefore the first 4 resource lines should again read:
Code:
load_resource = textures_face_gen
load_resource = shaders
load_resource = texture_names
load_resource = materials
Now add in 2 more "load_module_resource" lines to point to your newly renamed files. These 2 new lines must be added above lines for mesh BRFs that use the textures which are referenced in your new files.
Therefore the end product should look something like this at the end of the load_resource section:
Code:
load_module_resource = mymod_texture_names
load_module_resource = mymod_materials
load_module_resource = my_cool_items_1

If anybody has problems with this method or needs clarification, feel free to post in this thread for help.
It's additionally possible to combine all of your BRFs into one single BRF if you so desired (including meshes, materials, and texture names), but I won't cover that. There's actually not too much point to it, especially since the current version of BRFview will balk and not load it since it can't yet handle material or texture definitions within mesh BRFs. Still, if anyone is interested and understands the hex editing well enough I'll tell you how to do so. Compared to figuring out the other hex-editing, it's actually simple.
 
Nah, not stickied, but a link would definitely fit well in the stickied "Mount & Blade Mod Makers Q&A Thread" I think. :)
 
Updated to include further Intermediate and Advanced sections on better separating your resources from the default files, rather than simply overriding them.
Credit goes to Thorgrim for his Map Icons, that's how I realized the materials and texture names could be completely separated in this way.

I hope somebody else at least finds this useful. I'll be personally be updating my Arena Expansion to use these methods and am using them in the Age of Ash mod. I helped Winter get his various resources (from 4 different sources at least) for Storymod all working in harmony by using these further methods.
 
Cool, great work Janus.

Comment:
for part 2, instead of manually deleting everything for every single mesh you make, you could just add your mesh to an empty brf.

How to make an empty brf? Just delete everything and save.
 
Delete every mesh by hex editing, or what? I'm not getting how you're recommending it be done.
I'm assuming most people add all their new meshes to a single BRF file rather than doing them separately, at least that's what I've noticed people doing.

Still, might be handy to have an empty mesh BRF file available to simply add new stuff to. I think I'll post one of those here for people to download if they want a clean slate to add their stuff to.

EDIT: added link to the empty BRF file in the second section as an alternative. Link is here:
http://www.mbrepository.com/age_of_ash/forum/download.php?id=15
 
Thank you, Janus; I was beating my head against the wall when Armagan added this. This is nice and clear.
 
Lol nice work, if i had found it before i figured things already out, it would have helped me. ;)

Here are useable Materials and Texture_Name BRF Files.
http://rapidshare.de/files/11986956/LuBus.rar.html

You should already know how to use them if you have read janus post i think. :P

If not just change LuBu in the files to your item name(brf file)
And change the number 4 points before the name (its a 4)
To the number of characters your name has.
Dont forget to add +4 in texture_names because of .dds

Oh and if you was super lazy i post my empty BRF here too, in case you should have trouble to locate it in janus post... :lol:

http://rapidshare.de/files/11986774/free.rar.html
 
Back
Top Bottom