There are currently only two known ways how to create a mod with a modification of an existing JS functions.
- The first is copying the entire file and modifying it.
- This obfuscates which lines are changed if a mod is maintained for multiple releases. The replaced file has to be updated with every commit to that
file in the "public" mod, otherwise the new commit is not present in the modified copy.
- It also means that players can't launch two mods that modify the same file, because one mod will overwrite and thereby remove the diff of the other mod.
Examples: fgod, delenda est
- The second approach is creating a new file file_mod.js to refer to the functions, variables and prototypes defined in file.js. This approach removes the two disadvantages mentioned above, but as wraitii correctly noted in D1410, this approach has never been verified to be platform independent:
With the NTFS file system and CDFS file systems, the names are usually returned in alphabetical order. With FAT file systems, the names are usually returned in the order the files were written to the disk
There is no single person to blame for making such a recommendation, because many people throughout years have come up with this approach independently.
- sanderd17 https://trac.wildfiregames.com/wiki/ModdingGuiAndSimulation?version=1
- nani's autociv mod
- myself somewhere on the forums, implemented by fcxSanya
- (Lefo after reading fgod mod code?)