mmsplugin.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * vim: set ts=4 sw=4 tw=99 noet :
  3. * ======================================================
  4. * TF2 Dynamic Schema Injector
  5. * Written by nosoop
  6. * ======================================================
  7. */
  8. #include <stdio.h>
  9. #include "mmsplugin.h"
  10. SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
  11. SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, char const *, char const *, char const *, char const *, bool, bool);
  12. DynSchema g_Plugin;
  13. IServerGameDLL *server = NULL;
  14. PLUGIN_EXPOSE(DynSchema, g_Plugin);
  15. bool DynSchema::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
  16. {
  17. PLUGIN_SAVEVARS();
  18. /* Make sure we build on MM:S 1.4 */
  19. #if defined METAMOD_PLAPI_VERSION
  20. GET_V_IFACE_ANY(GetServerFactory, server, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
  21. #else
  22. GET_V_IFACE_ANY(serverFactory, server, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
  23. #endif
  24. SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, server, this, &DynSchema::Hook_LevelInitPost, true);
  25. return true;
  26. }
  27. bool DynSchema::Unload(char *error, size_t maxlen)
  28. {
  29. SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, server, this, &DynSchema::Hook_LevelInitPost, true);
  30. return true;
  31. }
  32. bool DynSchema::Hook_LevelInitPost(const char *pMapName, char const *pMapEntities,
  33. char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) {
  34. // this hook should fire shortly after the schema is (re)initialized
  35. // TODO determine if the schema was updated, we can do this by:
  36. // - adding a sentinel attribute that we test the existence of later, or
  37. // - check in LevelInitPre if we have a non-null CEconItemSchema::m_pDelayedSchemaData
  38. return true;
  39. }
  40. void DynSchema::AllPluginsLoaded() {
  41. /* This is where we'd do stuff that relies on the mod or other plugins
  42. * being initialized (for example, cvars added and events registered).
  43. */
  44. }
  45. bool DynSchema::Pause(char *error, size_t maxlen) {
  46. return true;
  47. }
  48. bool DynSchema::Unpause(char *error, size_t maxlen) {
  49. return true;
  50. }
  51. const char *DynSchema::GetLicense() {
  52. return "Proprietary";
  53. }
  54. const char *DynSchema::GetVersion() {
  55. return "1.0.0.0";
  56. }
  57. const char *DynSchema::GetDate() {
  58. return __DATE__;
  59. }
  60. const char *DynSchema::GetLogTag() {
  61. return "dynschema";
  62. }
  63. const char *DynSchema::GetAuthor() {
  64. return "nosoop";
  65. }
  66. const char *DynSchema::GetDescription() {
  67. return "Injects user-defined attributes into the game schema";
  68. }
  69. const char *DynSchema::GetName() {
  70. return "TF2 Dynamic Schema";
  71. }
  72. const char *DynSchema::GetURL() {
  73. return "https://git.csrd.science/";
  74. }