Script command to check if a specific mod is active?

Willkommen in der Transport Fever Community

Wir begrüßen euch in der Fan-Community zu den Spielen Transport Fever und Train Fever, den Wirtschaftssimulatoren von Urban Games. Die Community steht euch kostenlos zur Verfügung damit ihr euch über das Spiel austauschen und informieren könnt. Wir pflegen hier einen freundlichen und sachlichen Umgang untereinander und unser Team steht euch in allen Fragen gerne beiseite.

 

Die Registrierung und Nutzung ist selbstverständlich kostenlos.

 

Wir wünschen euch viel Spaß und hoffen auf rege Beteiligung.

Das Team der Transport-Fever Community


  • Hey all, I need a postRunFn lua command to check if a specific mod is active in a game. My searches are coming up empty. How can I do this?


    The mod in question doesn't create any resources so I can't use the usual workaround of scanning resource tables.


    I see the console / stdout echo a list of active mods when a savegame is loaded. Is there a command to access that list?


    Thanks!

  • Technical no direct way, you can check for loaded mdls or anything other that can be accessed by api.res.*
    You can test load a unique lua file in the mod res/scripts/ folder with pcall + require.

  • Technical no direct way, you can check for loaded mdls or anything other that can be accessed by api.res.*
    You can test load a unique lua file in the mod res/scripts/ folder with pcall + require.

    Well that's bad news 🙁 The mod has nothing but .fs shader scripts so there is nothing I can work with.


    The only way I know is to have the "other" mod define a global variable and check for it.

    The mod.lua does set a variable, but it seems it's a legacy variable that is no longer available in the code (game.config.shaderMod).

  • That is why CommonAPI1 and 2 has commonapi.mods.getLoaded() (you have to check for commonapi presence, won't work without native dll)


    You get a list of entries like this:

  • Yeah it makes sense. And if Common API 2 was a simple Steam mod I could require it as a dependency to use to it check for the other mod, basically use it as a function library. But it's obviously not reasonable to expect every Steam user to do that (or even GoG, etc).


    I suppose I could try to check the filesystem for the presence of the mod files, I think there are commands for that, but that doesn't mean the mod is actually enabled, so it's still not a solution.


    I've asked UG about this too, so maybe someday they will add a mod detection function to the API. I mean the active mods are the very first thing the stdout shows when loading a savegame, so it should be possible to make that list available in a table in the API. I think this is important when there are mods with well over 100K subscribers causing some issues and other mod authors need to be able to detect them to make compatibility fixes. It might even improve load times too because mods wouldn't need to do a bunch of awkward recursive if/then string searches of res .mdl names etc as a workaround. It could also enable dependency checking, which doesn't exist right now.


    Anyhow I guess all that's probably "old news" for everyone here, I imagine everybody already knows about gaps in the API.


    For now all I can do is remake all the .mtl / .dds files from scratch to produce a material that renders somewhat as intended with or without the other mod loaded. It's just frustrating because this was my first mod, and in my first version I made my own textures. Then I learned I could use opmaps to re-use existing textures (vanilla) in many different ways, much more efficient(!), so I change my materials to opmaps and I deleted my original textures. Then I encountered the issue that the other very popular mod doesn't render opmaps correctly, so now I need to go back to my original concept that I already deleted 🤦‍♂️ Newb learning problems haha 🙈 (Maybe file recovery utility will find something, assuming I didn't use SHIFT-DEL.)


    Anyhow thanks for your help and info here, it's very much appreciated 😌

  • LUA filesystem won't work,

    you would need to resolve the filesystem path. Only res/scripts/ is added to the lua search path for packages. Then you could use debug to get the filepath of a loaded file.


    For ModManager functionality I asked them about ModRep and Filesystem functionality long time ago, they refused that.

    You may get more support from them, simply send them more feedback requests.


    Fun fact, currently I add new apis to commonapi because of lack of better functionality of the game.


    So I have now commonapi._native.utils.resolvePath("res/shaders2/fs/std.fs")

    Here we see, the first file is actual in the zip file, the second is in my mods folder. These functionality is in game, but UG refuses to give us the apis.


    As we don't want to unzip files myself I build a new lua loadfile interface and a wrapper commonapi.utils.getFileDataViaFS, that calls the data function.


    And if you really want to load say a binary file, I even have now raw function:

    Code
    >> a, b,c = commonapi._native.utils.getFileRaw("res/shaders2/fs/std.fs")
    >> a
    "#version 150\
    /// BEGIN AUTOGENERATED HEADER\
    #define CONC(a,b) a##b\
    \
    #define IF(c, t, e) CONC(IF_, c)(t, e)\
     



    There is a simple reason I won't add CommonAPI2 to steam, people refuse to understand CommonAPI2 is game version and platform dependent... it was a nightmare of user feedback.

    If UG releases the "Last Version" of TPF2 I may upload it again. Still this won't help mac users...

  • LUA filesystem won't work,

    you would need to resolve the filesystem path. Only res/scripts/ is added to the lua search path for packages. Then you could use debug to get the filepath of a loaded file.

    Hi, a follow-up question on this point... Is there a script command to check for the presence of a file in the res/textures folders? So far I don't see any commands in the API wiki to check for files. It sounds like you're saying this is not possible.


    You also mention using debug... I have seen some mods with debug.xxx commands in them. Is there a reference somewhere of the available debug commands? I don't see any in the API wiki.


    Thanks!

  • That is the lua debug library.

    https://www.lua.org/pil/contents.html#23


    Technical no, you can't check for presence because you have no api to the virtual filesystem.


    If the mod has loadable lua file in res/scripts, you could load it, use the lua debug library to find the real filepath of a different folder in this mod.

    But well then you already know that the mod is loaded... ;)


    Technical side:


    TPF2 has a mapping of zip files and mods. If TPF2 internally wants a texture, it will use something like virtualfilesystem.getFile("res/something/test.txt"), an gets a file handle.
    (GameScripts, Modules, Cons are loaded like this, even when they are technical lua files)


    If a mod is added when loading a savegame, if a folder res/scripts exists, the true filesystem path will be added to to lua package.path.
    lua require uses package.path to resolve package names to filenames. Result: only files in res/scripts can be required.


    So it's not possible to require a file or load a file if it is in res/construction/station/ or in a texture folder as example. (zip files add even more problems)


    You can use the CommonAPI2 inspect window to resolve files to true filesystem paths, this only works with my native code part. (I added my own internal apis calling TPF2 code)

  • Ah! I should have thought to check the lua library! 🤦‍♂️ For some reason I assumed this was native game code, not a general lua debug library. Thanks for that!


    I should have clarified that my follow-up question wasn't related to the original topic, sorry... It's for a different project where I'd like to check if certain .tga files are present, but it sounds like that's not possible with the default game api 😫 And there seems to be no api.res table for individual resource files (like .tga) so I can't check if one has been loaded.


    Ok thanks anyway. Cheers!