Hello! I just encountered the same problem and searched on this board for help. Surprisingly, this is the only mention I could find. I was stumped on this for a while, but just found the solution: typedefs.
Like you, I had the same hook declared in two different files and I was also getting errors about objects already existing. The reason why is that the SH_DECL_HOOK
macro actually declares some variables that you can't see, and there are two with identical names created when you have two of those definitions. Since the name of these variables is derived from the interface name and function, if we can change the name, it'll work fine.
That's where typedefs come in. Typedefs are basically just an alias for a type name. If you set up an alias for the interface in one of the two files with a different name, you can declare the hooks using that new name instead and it won't conflict. It doesn't matter what your alias is as long as it's different from the old name.
At the top of one of your two files, add this line, replacing the two parts of it:
typedef <EXISTING TYPE NAME> <YOUR NEW TYPE NAME>;
Then, in the rest of just that file, replace any names of the original type (IServerEntity
in your case) with your new alias name in any hook-related macros. From there it should compile fine.
Add this line to the top of ONE of the two files: typedef IServerEntity IServerEntityFileOne;
Then, replace "IServerEntity
" with "IServerEntityFileOne
" everywhere else hook-related in that one file.