From 19fd9964a03dba97cf4fef890a4ad5d9d37b9744 Mon Sep 17 00:00:00 2001
From: LivingInPortal <denniswu81229@gmail.com>
Date: Mon, 22 Feb 2016 07:42:44 +0800
Subject: [PATCH] Fix the origin extension can only interact with edict

---
 extension.cpp          | 59 +++++++-----------------------------------
 extension.h            |  2 +-
 include/outputinfo.inc | 10 +++----
 smsdk_config.h         |  2 +-
 4 files changed, 16 insertions(+), 57 deletions(-)

diff --git a/extension.cpp b/extension.cpp
index 26f2d0a..8ed1771 100644
--- a/extension.cpp
+++ b/extension.cpp
@@ -36,8 +36,6 @@
  * @brief Implement extension code here.
  */
 
-CGlobalVars *gpGlobals = NULL;
-
 Outputinfo g_Outputinfo;		/**< Global singleton for extension's main interface */
 
 SMEXT_LINK(&g_Outputinfo);
@@ -108,47 +106,14 @@ private:
 	CBaseEntityOutput( CBaseEntityOutput& ); // protect from accidental copying
 };
 
-BEGIN_SIMPLE_DATADESC( CEventAction )
-	DEFINE_FIELD( m_iTarget, FIELD_STRING ),
-	DEFINE_FIELD( m_iTargetInput, FIELD_STRING ),
-	DEFINE_FIELD( m_iParameter, FIELD_STRING ),
-	DEFINE_FIELD( m_flDelay, FIELD_FLOAT ),
-	DEFINE_FIELD( m_nTimesToFire, FIELD_INTEGER ),
-	DEFINE_FIELD( m_iIDStamp, FIELD_INTEGER ),
-END_DATADESC()
-
-BEGIN_SIMPLE_DATADESC( CBaseEntityOutput )
-	//DEFINE_CUSTOM_FIELD( m_Value, variantFuncs ),
-END_DATADESC()
-
 int CBaseEntityOutput::NumberOfElements(void)
 {
 	int count = 0;
-
-	if (m_ActionList == NULL)
-		return -1;
-
 	for (CEventAction *ev = m_ActionList; ev != NULL; ev = ev->m_pNext)
+	{
 		count++;
-
-	return (count);
-}
-
-inline CBaseEntity *GetCBaseEntity(int Num)
-{
-#if SOURCE_ENGINE >= SE_LEFT4DEAD
-	edict_t *pEdict = (edict_t *)(gpGlobals->pEdicts + Num);
-#else
-	edict_t *pEdict = engine->PEntityOfEntIndex(Num);
-#endif
-	if(!pEdict || pEdict->IsFree())
-		return NULL;
-
-	IServerUnknown *pUnk;
-	if((pUnk = pEdict->GetUnknown()) == NULL)
-		return NULL;
-
-	return pUnk->GetBaseEntity();
+	}
+	return count;
 }
 
 inline int GetDataMapOffset(CBaseEntity *pEnt, const char *pName)
@@ -184,7 +149,7 @@ cell_t GetOutputCount(IPluginContext *pContext, const cell_t *params)
 	char *pOutput;
 	pContext->LocalToString(params[2], &pOutput);
 
-	CBaseEntity *pEntity = GetCBaseEntity(params[1]);
+	CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(gamehelpers->IndexToReference(params[1]));
 	CBaseEntityOutput *pEntityOutput = GetOutput(pEntity, pOutput);
 
 	if(pEntityOutput == NULL)
@@ -198,7 +163,7 @@ cell_t GetOutputTarget(IPluginContext *pContext, const cell_t *params)
 	char *pOutput;
 	pContext->LocalToString(params[2], &pOutput);
 
-	CBaseEntity *pEntity = GetCBaseEntity(params[1]);
+	CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(gamehelpers->IndexToReference(params[1]));
 	CBaseEntityOutput *pEntityOutput = GetOutput(pEntity, pOutput);
 
 	if(pEntityOutput == NULL || pEntityOutput->m_ActionList == NULL)
@@ -225,7 +190,7 @@ cell_t GetOutputTargetInput(IPluginContext *pContext, const cell_t *params)
 	char *pOutput;
 	pContext->LocalToString(params[2], &pOutput);
 
-	CBaseEntity *pEntity = GetCBaseEntity(params[1]);
+	CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(gamehelpers->IndexToReference(params[1]));
 	CBaseEntityOutput *pEntityOutput = GetOutput(pEntity, pOutput);
 
 	if (pEntityOutput == NULL || pEntityOutput->m_ActionList == NULL)
@@ -252,7 +217,7 @@ cell_t GetOutputParameter(IPluginContext *pContext, const cell_t *params)
 	char *pOutput;
 	pContext->LocalToString(params[2], &pOutput);
 
-	CBaseEntity *pEntity = GetCBaseEntity(params[1]);
+	CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(gamehelpers->IndexToReference(params[1]));
 	CBaseEntityOutput *pEntityOutput = GetOutput(pEntity, pOutput);
 
 	if (pEntityOutput == NULL || pEntityOutput->m_ActionList == NULL)
@@ -279,7 +244,7 @@ cell_t GetOutputDelay(IPluginContext *pContext, const cell_t *params)
 	char *pOutput;
 	pContext->LocalToString(params[2], &pOutput);
 
-	CBaseEntity *pEntity = GetCBaseEntity(params[1]);
+	CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(gamehelpers->IndexToReference(params[1]));
 	CBaseEntityOutput *pEntityOutput = GetOutput(pEntity, pOutput);
 
 	if (pEntityOutput == NULL || pEntityOutput->m_ActionList == NULL)
@@ -311,10 +276,4 @@ const sp_nativeinfo_t MyNatives[] =
 void Outputinfo::SDK_OnAllLoaded()
 {
 	sharesys->AddNatives(myself, MyNatives);
-}
-
-bool Outputinfo::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late)
-{
-	gpGlobals = ismm->GetCGlobals();
-	return true;
-}
+}
\ No newline at end of file
diff --git a/extension.h b/extension.h
index d6d09a6..96d3a07 100644
--- a/extension.h
+++ b/extension.h
@@ -91,7 +91,7 @@ public:
 	 * @param late			Whether or not Metamod considers this a late load.
 	 * @return				True to succeed, false to fail.
 	 */
-	virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
+	//virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
 
 	/**
 	 * @brief Called when Metamod is detaching, after the extension version is called.
diff --git a/include/outputinfo.inc b/include/outputinfo.inc
index a24b3cd..3624c3e 100644
--- a/include/outputinfo.inc
+++ b/include/outputinfo.inc
@@ -3,11 +3,11 @@
 #endif
 #define _OutputInfo_Included
 
-native GetOutputCount(int Entity, const char[] sOutput);
-native GetOutputTarget(int Entity, const char[] sOutput, int Index, char[] sTarget);
-native GetOutputTargetInput(int Entity, const char[] sOutput, int Index, char[] sTargetInput);
-native GetOutputParameter(int Entity, const char[] sOutput, int Index, char[] sParameter);
-native Float:GetOutputDelay(int Entity, const char[] sOutput, int Index);
+native int GetOutputCount(int Entity, const char[] sOutput);
+native int GetOutputTarget(int Entity, const char[] sOutput, int Index, char[] sTarget);
+native int GetOutputTargetInput(int Entity, const char[] sOutput, int Index, char[] sTargetInput);
+native int GetOutputParameter(int Entity, const char[] sOutput, int Index, char[] sParameter);
+native float GetOutputDelay(int Entity, const char[] sOutput, int Index);
 
 /**
  * Do not edit below this line!
diff --git a/smsdk_config.h b/smsdk_config.h
index 5786ba0..79885dc 100644
--- a/smsdk_config.h
+++ b/smsdk_config.h
@@ -56,7 +56,7 @@
  * @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