1.1 --- a/core/sourcehook/sourcehook_impl.h Sat Oct 15 22:16:50 2011 -0700
1.2 +++ b/core/sourcehook/sourcehook_impl.h Mon Dec 12 15:53:56 2011 -0600
1.3 @@ -1,4 +1,5 @@
1.4 /* ======== SourceHook ========
1.5 +* vim: set ts=4 sw=4 tw=99 noet:
1.6 * Copyright (C) 2004-2010 Metamod:Source Development Team
1.7 * No warranties of any kind
1.8 *
1.9 @@ -254,7 +255,43 @@
1.10 };
1.11
1.12 typedef CStack<CHookContext> HookContextStack;
1.13 -
1.14 +
1.15 + class UnloadListener
1.16 + {
1.17 + public:
1.18 + virtual void ReadyToUnload(Plugin plug) = 0;
1.19 + };
1.20 +
1.21 + class PendingUnload
1.22 + {
1.23 + UnloadListener *listener_;
1.24 + Plugin plug_;
1.25 + bool deactivated_;
1.26 +
1.27 + public:
1.28 + PendingUnload(UnloadListener *listener, Plugin plug)
1.29 + : listener_(listener), plug_(plug), deactivated_(false)
1.30 + { }
1.31 +
1.32 + Plugin plugin() const
1.33 + {
1.34 + return plug_;
1.35 + }
1.36 +
1.37 + UnloadListener *listener() const
1.38 + {
1.39 + return listener_;
1.40 + }
1.41 +
1.42 + void deactivate()
1.43 + {
1.44 + deactivated_ = true;
1.45 + }
1.46 + bool deactivated() const
1.47 + {
1.48 + return deactivated_;
1.49 + }
1.50 + };
1.51
1.52 class CSourceHookImpl : public ISourceHook
1.53 {
1.54 @@ -263,6 +300,7 @@
1.55 CVfnPtrList m_VfnPtrs;
1.56 CHookIDManager m_HookIDMan;
1.57 HookContextStack m_ContextStack;
1.58 + List<PendingUnload *> m_PendingUnloads;
1.59
1.60 bool SetHookPaused(int hookid, bool paused);
1.61 CHookManList::iterator RemoveHookManager(CHookManList::iterator iter);
1.62 @@ -304,10 +342,16 @@
1.63
1.64 void *GetOverrideRetPtr(); //!< Used for setting the override return value
1.65
1.66 - /**
1.67 - * @brief Make sure that a plugin is not used by any other plugins anymore, and unregister all its hook managers
1.68 - */
1.69 - void UnloadPlugin(Plugin plug);
1.70 + /*
1.71 + * @brief Make sure that a plugin is not used by any
1.72 + * other plugins anymore, and unregister all its hook
1.73 + * managers. If any hooks owned by this plugin are
1.74 + * still on the callstack, defers notifying the listener
1.75 + * until the count has dropped to 0.
1.76 + */
1.77 + void UnloadPlugin(Plugin plug, UnloadListener *listener);
1.78 +
1.79 + void ResolvePendingUnloads(bool force = false);
1.80
1.81 void RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc);
1.82