dariowouters / ts-fmod-plugin

A telemetry plugin for ATS/ETS2 to use FMOD sound mods (to a limited extent) for example in TruckersMP
MIT License
45 stars 12 forks source link

Support future game versions #14

Open mwl4 opened 9 months ago

mwl4 commented 9 months ago

Hello,

I can see that it is challenging to predict future game versions and in the same time keep plugin working for the largest number of game binary versions.

To do it effectively, you could first verify what you need, if it fails, then inform user that different plugin version is needed, if it succeeds let it load. To make it happen, you could use __try and __except keywords. https://stackoverflow.com/a/7049836

int FilterException(int code, PEXCEPTION_POINTERS ex) {
    return EXCEPTION_EXECUTE_HANDLER;
}

void SomeCheckingOfNeededGameStuff()
{
  // check if game_ctrl_u object is really game_ctrl
  // check if game_actor_u object is really game_actor
  // etc
  // if anything goes bad and throws exception, it will be catched in __except block.
}

bool ShouldPluginBeRunning()
{
    __try {
        SomeCheckingOfNeededGameStuff();
        return true; // all went fine
    }
    __except(FilterException(GetExceptionCode(), GetExceptionInformation())) {
        return false;
    }
}

Real code might be different, and I am not sure if you can return false just like that from __except block. But I think it should be all possible.

Thank you for understanding.

dariowouters commented 9 months ago

Hey,

Thank you, I don't know much about c++ so I did not know __try/__catch even existed, I think I tried the std try/catch at some point but that was only able to catch std exceptions.

The version checker I added last plugin version only checks 1.xx, I didn't really expect SCS to do a .5 update. And I indeed don't really want to constantly have to update this for every smaller binary change. So it wasn't able to catch the .5 update unfortunately.

I will look into it and hopefully stop the crashes once and for all, thanks again. And sorry for any issues/extra work the plugin crashes have caused for you and the TruckersMP team.