Writing a mod loader
Mod loaders are the way of loading in the patturns, notes and effects into the MODULE class, and tell the driver to load the samples.
All loaders need to implement the IModLoader interface.
The following functions have to be implemented:
- Init(); used to set the loader up
- Test(); test to see if this loader can load the request module
- Load(int curious); Load the module, the curious value can be used to find addtional "hidden" data in the mod
- Cleanup(); Clear up after testing or loading
- LoadTitle(); get the title of the mod
The following varibles should also be set:
Testing the data
- m_ModuleType module type name
- m_ModuleVersion version of the module loader
When we get the binary stream of the mod we need to work out what type of mod it is, this is done by testing the data against all the mod loaders till one tells us it can load it.
Because of this you must take care to fully check the data stream to see if it is a mod your loader can process.
loading from the stream
Once the a loader has passed the Test() it will then be asked to load the module, this is done via Load(int).
IModLoader has alot of built in functions to aid in the loading of modules, the important ones are listed bellow:
- m_Reader this variable contains the binary mod data to be read and has a number of functions to get bytes, shorts, etc in the different endians
- m_Module this should contain the loaded module that your loader processed
- m_LoadError fill this in if the load fails
MikMod provides an internal mod tracking format it calls UNITRK, SharpMik fully supports this and recreates the functions that should be used to create and read the UniTrk data.
To aid in the creation of the tracks m_Tracker can be found in the iModLoader, this can be used directly or you can use the many helper functions that have been added to iModLoader to make it easier. Please refer to the code to for more imformation.