mmsplugin.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "econmanager.h"
  11. #include "natives.h"
  12. #include <map>
  13. SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, 0, bool, char const *, char const *, char const *, char const *, bool, bool);
  14. DynSchema g_Plugin;
  15. SMEXT_LINK(&g_Plugin);
  16. bool DynSchema::SDK_OnLoad(char *error, size_t maxlen, bool late)
  17. {
  18. SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &DynSchema::Hook_LevelInitPost, true);
  19. sharesys->AddNatives(myself, g_EconAttributeNatives);
  20. g_EconInjectedAttributeType = g_pHandleSys->CreateType("EconInjectedAttribute", &g_EconInjectedAttributeHandler, 0, NULL, NULL, myself->GetIdentity(), NULL);
  21. /* Prepare our manager */
  22. if (!g_EconManager.Init(error, maxlen)) {
  23. return false;
  24. }
  25. return true;
  26. }
  27. void DynSchema::SDK_OnUnload() {
  28. SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &DynSchema::Hook_LevelInitPost, true);
  29. g_pHandleSys->RemoveType(g_EconInjectedAttributeType, myself->GetIdentity());
  30. }
  31. bool DynSchema::Hook_LevelInitPost(const char *pMapName, char const *pMapEntities,
  32. char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) {
  33. // reinstall attributes as needed
  34. g_EconManager.InstallAttributes();
  35. return true;
  36. }