Skip to content

Commit

Permalink
implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Monera committed Aug 29, 2023
1 parent 765a6a4 commit 2916413
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 21 deletions.
2 changes: 2 additions & 0 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ class ExtensionConfig(object):
os.path.join(self.sm_root, 'sourcepawn', 'include'),
os.path.join(self.sm_root, 'public', 'amtl', 'amtl'),
os.path.join(self.sm_root, 'public', 'amtl'),
os.path.join(self.mms_root, 'core'),
os.path.join(self.mms_root, 'core', 'sourcehook'),
]
return compiler

Expand Down
2 changes: 1 addition & 1 deletion AMBuilder
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
import os, sys

projectName = 'sample'
projectName = 'ehinfo'

# smsdk_ext.cpp will be automatically added later
sourceFiles = [
Expand Down
8 changes: 4 additions & 4 deletions PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ builder.SetBuildFolder('package')
# Add any folders you need to this list
folder_list = [
'addons/sourcemod/extensions',
#'addons/sourcemod/scripting/include',
'addons/sourcemod/scripting/include',
#'addons/sourcemod/gamedata',
#'addons/sourcemod/configs',
]
Expand All @@ -29,9 +29,9 @@ def CopyFiles(src, dest, files):
builder.AddCopy(source_path, dest_entry)

# Include files
#CopyFiles('include', 'addons/sourcemod/scripting/include',
# [ 'sample.inc', ]
#)
CopyFiles('include', 'addons/sourcemod/scripting/include',
[ 'ehinfo.inc', ]
)

# GameData files
#CopyFiles('gamedata', 'addons/sourcemod/gamedata',
Expand Down
80 changes: 78 additions & 2 deletions extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,82 @@
* @brief Implement extension code here.
*/

Sample g_Sample; /**< Global singleton for extension's main interface */
EHInfo g_EHInfo; /**< Global singleton for extension's main interface */

SMEXT_LINK(&g_Sample);
SMEXT_LINK(&g_EHInfo);

// native bool IsEventHooked(Handle plugin, const char[] name);

struct EventHook
{
EventHook()
{
pPreHook = NULL;
pPostHook = NULL;
postCopy = false;
refCount = 0;
}
IChangeableForward *pPreHook;
IChangeableForward *pPostHook;
bool postCopy;
unsigned int refCount;
std::string name;

static inline bool matches(const char *name, const EventHook *hook)
{
return strcmp(name, hook->name.c_str()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};

typedef SourceHook::List<EventHook *> EventHookList;

cell_t IsEventHookedEx(IPluginContext *pContext, const cell_t *params)
{
Handle_t plugin;
const char *name;
HandleError *err;

plugin = static_cast<Handle_t>(params[1]);
pContext->LocalToString(params[2], const_cast<char **>(&name));
pContext->LocalToPhysAddr(params[3], reinterpret_cast<cell_t **>(&err));

IPlugin *pPlugin = plsys->PluginFromHandle(plugin, err);
if(pPlugin == NULL)
{
return static_cast<cell_t>(false);
}

EventHookList *pHookList;
if(!pPlugin->GetProperty("EventHooks", reinterpret_cast<void **>(&pHookList)))
{
return static_cast<cell_t>(false);
}

EventHookList::iterator it;
for(it = pHookList->begin(); it != pHookList->end(); it++)
{
EventHook *pHook = (*it);

if(EventHook::matches(name, pHook))
{
return static_cast<cell_t>(true);
}
}

return static_cast<cell_t>(false);
}

const sp_nativeinfo_t natives[] =
{
{"IsEventHookedEx", IsEventHookedEx},
{NULL, NULL},
};

void EHInfo::SDK_OnAllLoaded()
{
sharesys->AddNatives(myself, natives);
}
11 changes: 6 additions & 5 deletions extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@

/**
* @file extension.h
* @brief Sample extension code header.
* @brief Extension code header.
*/

#include "smsdk_ext.h"

#include <sm_stringhashmap.h>
#include <sh_list.h>

/**
* @brief Sample implementation of the SDK Extension.
* Note: Uncomment one of the pre-defined virtual functions in order to use it.
* @brief Implementation of the SDK Extension.
*/
class Sample : public SDKExtension
class EHInfo : public SDKExtension
{
public:
/**
Expand All @@ -66,7 +67,7 @@ class Sample : public SDKExtension
* @brief This is called once all known extensions have been loaded.
* Note: It is is a good idea to add natives here, if any are provided.
*/
//virtual void SDK_OnAllLoaded();
virtual void SDK_OnAllLoaded();

/**
* @brief Called when the pause state is changed.
Expand Down
51 changes: 51 additions & 0 deletions include/ehinfo.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#if defined _pluginsyswrapper_included_
#endinput
#endif
#define _pluginsyswrapper_included_

public Extension __ext_pluginsyswrapper =
{
name = "PluginSys Wrapper",
file = "pluginsyswrapper.ext",
autoload = 1,
required = 1,
};

enum HandleError
{
HandleError_None = 0, /**< No error */
HandleError_Changed, /**< The handle has been freed and reassigned */
HandleError_Type, /**< The handle has a different type registered */
HandleError_Freed, /**< The handle has been freed */
HandleError_Index, /**< generic internal indexing error */
HandleError_Access, /**< No access permitted to free this handle */
HandleError_Limit, /**< The limited number of handles has been reached */
HandleError_Identity, /**< The identity token was not usable */
HandleError_Owner, /**< Owners do not match for this operation */
HandleError_Version, /**< Unrecognized security structure version */
HandleError_Parameter, /**< An invalid parameter was passed */
HandleError_NoInherit, /**< This type cannot be inherited */
};

/**
* @brief Checks if the event is hooked by the plugin.
*
* @param plugin Handle of the plugin.
* @param name Name of the event.
* @param err Error, set on handle failure.
* @return True if the event is hooked, false otherwise.
*/
native bool IsEventHookedEx(Handle plugin, const char[] name, HandleError &err);

/**
* @brief Checks if the event is hooked by the plugin.
*
* @param plugin Handle of the plugin.
* @param name Name of the event.
* @return True if the event is hooked, false otherwise.
*/
stock bool IsEventHooked(Handle plugin, const char[] name)
{
HandleError err;
return IsEventHookedEx(plugin, name, err);
}
18 changes: 9 additions & 9 deletions smsdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
*/

/* Basic information exposed publicly */
#define SMEXT_CONF_NAME "Sample Extension"
#define SMEXT_CONF_DESCRIPTION "Sample extension to help developers"
#define SMEXT_CONF_VERSION "0.0.0.0"
#define SMEXT_CONF_AUTHOR "AlliedModders"
#define SMEXT_CONF_URL "http://www.sourcemod.net/"
#define SMEXT_CONF_LOGTAG "SAMPLE"
#define SMEXT_CONF_NAME "EventHook Info"
#define SMEXT_CONF_DESCRIPTION "Extension that gives information about hooked events of a plugin"
#define SMEXT_CONF_VERSION "1.0.0.0"
#define SMEXT_CONF_AUTHOR "Monera"
#define SMEXT_CONF_URL ""
#define SMEXT_CONF_LOGTAG "EHINFO"
#define SMEXT_CONF_LICENSE "GPL"
#define SMEXT_CONF_DATESTRING __DATE__

Expand All @@ -56,10 +56,10 @@
* @brief Sets whether or not this plugin required Metamod.
* NOTE: Uncomment to enable, comment to disable.
*/
//#define SMEXT_CONF_METAMOD
#define SMEXT_CONF_METAMOD

/** Enable interfaces you want to use here by uncommenting lines */
//#define SMEXT_ENABLE_FORWARDSYS
#define SMEXT_ENABLE_FORWARDSYS
//#define SMEXT_ENABLE_HANDLESYS
//#define SMEXT_ENABLE_PLAYERHELPERS
//#define SMEXT_ENABLE_DBMANAGER
Expand All @@ -71,7 +71,7 @@
//#define SMEXT_ENABLE_LIBSYS
//#define SMEXT_ENABLE_MENUS
//#define SMEXT_ENABLE_ADTFACTORY
//#define SMEXT_ENABLE_PLUGINSYS
#define SMEXT_ENABLE_PLUGINSYS
//#define SMEXT_ENABLE_ADMINSYS
//#define SMEXT_ENABLE_TEXTPARSERS
//#define SMEXT_ENABLE_USERMSGS
Expand Down

0 comments on commit 2916413

Please sign in to comment.