h_rootobj.cpp 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <precomp.h>
  2. #include <api/script/objcontroller.h>
  3. #include "h_rootobj.h"
  4. H_RootObject::H_RootObject(ScriptObject *o) {
  5. inited = 0;
  6. me = NULL;
  7. H_hook(o);
  8. }
  9. H_RootObject::H_RootObject() {
  10. inited = 0;
  11. me = NULL;
  12. }
  13. void H_RootObject::H_hook(ScriptObject *o) {
  14. ASSERT(!inited);
  15. me = o;
  16. addMonitorObject(o, &rootObjectGuid);
  17. if (count++ == 0) {
  18. onnotify_id = WASABI_API_MAKI->maki_addDlfRef(o->vcpu_getController(), L"onNotify", this);
  19. }
  20. inited=1;
  21. }
  22. H_RootObject::~H_RootObject() {
  23. if (!inited) return;
  24. WASABI_API_MAKI->maki_remDlfRef(this);
  25. //count--;
  26. }
  27. int H_RootObject::eventCallback(ScriptObject *object, int dlfid, scriptVar **params, int nparams) {
  28. if (object != getHookedObject()) return 0;
  29. if (dlfid == onnotify_id) { hook_onNotify(GET_SCRIPT_STRING(*params[0]), GET_SCRIPT_STRING(*params[1]), GET_SCRIPT_INT(*params[2]), GET_SCRIPT_INT(*params[3])); return 1; }
  30. return 0;
  31. }
  32. int H_RootObject::onnotify_id=0;
  33. int H_RootObject::inited=0;
  34. int H_RootObject::count=0;