oscar-broman / samp-weapon-config

A more consistent and responsive damage system with many new features
Apache License 2.0
92 stars 85 forks source link

Redefine `WEAPON_UNKNOWN` if it's already defined #303

Closed NexiusTailer closed 1 month ago

NexiusTailer commented 1 month ago

If it's already defined in any other libs (mainly in omp-stdlib), undef the old definition and define new one as it's critical for us to have exactly value 55 because weapon-config assumes this ID in many internal checks (omp-stdlib's WEAPON_UNKNOWN is -1, so we cannot keep using it). We also cannot rename this definition in wc to any other name because users may have it added in their scripts.

I still think omp-stdlib should've been changed it on their side before it was merged into the latest omp server release, as it was obviously added without any decent testing with any popular libs which might already have this definition (like in our case, in weapon-config for years), but it's highly unlikely that anything can be done now on stdlib side, since in that case it will break compatibility for those who started using WEAPON_UNKNOWN from the current version of stdlib.

So, having two same definition names for different values under the hood, I think the least bad way to solve it is to "forget" the stdlib value and redefine with our value. Basically, it's exactly what happens now, but now users have useless warning 201: redefinition of constant/macro.

NexiusTailer commented 1 month ago

This also solve #300 and #294

shierru commented 1 month ago

If the user does not use omp-stdlib, but uses for example samp-stdlib, it will now fail because WEAPON_UNKNOWN will not be defined.

We need to add a condition that if WEAPON_UNKNOWN has not been declared before, then declare it, and if it has been declared, then redefine it:

#if !defined WEAPON_UNKNOWN
    #define WEAPON_UNKNOWN (WEAPON:55)
#else
    #undef WEAPON_UNKNOWN
    #define WEAPON_UNKNOWN (WEAPON:55)
#endif

Or you could go like this:

#if defined WEAPON_UNKNOWN
    #undef WEAPON_UNKNOWN
#endif
#define WEAPON_UNKNOWN (WEAPON:55)
NexiusTailer commented 1 month ago

@shierru oh, my bad, thank you