Permalink
Browse files

Add FireEntityOutput native. (#587)

* AcceptEntityOutput native

* define fix

* MSVC fix and renamed native

* Added requested changes.

* tab/space fix
1 parent 61f4684 commit 08238a803642352ab5e9490e5c78d252cc7e0eff @Benoist3012 Benoist3012 committed with psychonic Feb 16, 2017
@@ -4,6 +4,7 @@ import os
project = SM.HL2Project(builder, 'sdktools.ext')
project.sources += [
'extension.cpp',
+ 'variant-t.cpp',
'inputnatives.cpp',
'output.cpp',
'outputnatives.cpp',
@@ -2,7 +2,7 @@
* vim: set ts=4 :
* =============================================================================
* SourceMod SDKTools Extension
- * Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
+ * Copyright (C) 2004-2017 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
@@ -38,6 +38,7 @@
#include "vglobals.h"
#include "tempents.h"
#include "vsound.h"
+#include "variant-t.h"
#include "output.h"
#include "hooks.h"
#include "gamerulesnatives.h"
@@ -114,6 +115,7 @@ bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late)
sharesys->AddNatives(myself, g_TRNatives);
sharesys->AddNatives(myself, g_StringTableNatives);
sharesys->AddNatives(myself, g_VoiceNatives);
+ sharesys->AddNatives(myself, g_VariantTNatives);
sharesys->AddNatives(myself, g_EntInputNatives);
sharesys->AddNatives(myself, g_TeamNatives);
sharesys->AddNatives(myself, g_EntOutputNatives);
@@ -30,12 +30,10 @@
*/
#include "extension.h"
+#include "variant-t.h"
#include <datamap.h>
-#define SIZEOF_VARIANT_T 20
-
ICallWrapper *g_pAcceptInput = NULL;
-unsigned char g_Variant_t[SIZEOF_VARIANT_T] = {0};
#define ENTINDEX_TO_CBASEENTITY(ref, buffer) \
buffer = gamehelpers->ReferenceToEntity(ref); \
@@ -44,26 +42,6 @@ unsigned char g_Variant_t[SIZEOF_VARIANT_T] = {0};
return pContext->ThrowNativeError("Entity %d (%d) is not a CBaseEntity", gamehelpers->ReferenceToIndex(ref), ref); \
}
-/* Hack to init the variant_t object for the first time */
-class VariantFirstTimeInit
-{
-public:
- VariantFirstTimeInit()
- {
- *(unsigned int *)(&g_Variant_t[12]) = INVALID_EHANDLE_INDEX;
- }
-} g_VariantFirstTimeInit;
-
-inline void _init_variant_t()
-{
- unsigned char *vptr = g_Variant_t;
-
- *(int *)vptr = 0;
- vptr += sizeof(int)*3;
- *(unsigned long *)vptr = INVALID_EHANDLE_INDEX;
- vptr += sizeof(unsigned long);
- *(fieldtype_t *)vptr = FIELD_VOID;
-}
static cell_t AcceptEntityInput(IPluginContext *pContext, const cell_t *params)
{
@@ -139,136 +117,8 @@ static cell_t AcceptEntityInput(IPluginContext *pContext, const cell_t *params)
return (ret) ? 1 : 0;
}
-static cell_t SetVariantBool(IPluginContext *pContext, const cell_t *params)
-{
- unsigned char *vptr = g_Variant_t;
-
- *(bool *)vptr = (params[1]) ? true : false;
- vptr += sizeof(int)*3 + sizeof(unsigned long);
- *(fieldtype_t *)vptr = FIELD_BOOLEAN;
-
- return 1;
-}
-
-static cell_t SetVariantString(IPluginContext *pContext, const cell_t *params)
-{
- char *str;
- unsigned char *vptr = g_Variant_t;
-
- pContext->LocalToString(params[1], &str);
-
- *(string_t *)vptr = MAKE_STRING(str);
- vptr += sizeof(int)*3 + sizeof(unsigned long);
- *(fieldtype_t *)vptr = FIELD_STRING;
-
- return 1;
-}
-
-static cell_t SetVariantInt(IPluginContext *pContext, const cell_t *params)
-{
- unsigned char *vptr = g_Variant_t;
-
- *(int *)vptr = params[1];
- vptr += sizeof(int)*3 + sizeof(unsigned long);
- *(fieldtype_t *)vptr = FIELD_INTEGER;
-
- return 1;
-}
-
-static cell_t SetVariantFloat(IPluginContext *pContext, const cell_t *params)
-{
- unsigned char *vptr = g_Variant_t;
-
- *(float *)vptr = sp_ctof(params[1]);
- vptr += sizeof(int)*3 + sizeof(unsigned long);
- *(fieldtype_t *)vptr = FIELD_FLOAT;
-
- return 1;
-}
-
-static cell_t SetVariantVector3D(IPluginContext *pContext, const cell_t *params)
-{
- cell_t *val;
- unsigned char *vptr = g_Variant_t;
-
- pContext->LocalToPhysAddr(params[1], &val);
-
- *(float *)vptr = sp_ctof(val[0]);
- vptr += sizeof(float);
- *(float *)vptr = sp_ctof(val[1]);
- vptr += sizeof(float);
- *(float *)vptr = sp_ctof(val[2]);
- vptr += sizeof(float) + sizeof(unsigned long);
- *(fieldtype_t *)vptr = FIELD_VECTOR;
-
- return 1;
-}
-
-static cell_t SetVariantPosVector3D(IPluginContext *pContext, const cell_t *params)
-{
- cell_t *val;
- unsigned char *vptr = g_Variant_t;
-
- pContext->LocalToPhysAddr(params[1], &val);
-
- *(float *)vptr = sp_ctof(val[0]);
- vptr += sizeof(float);
- *(float *)vptr = sp_ctof(val[1]);
- vptr += sizeof(float);
- *(float *)vptr = sp_ctof(val[2]);
- vptr += sizeof(float) + sizeof(unsigned long);
- *(fieldtype_t *)vptr = FIELD_POSITION_VECTOR;
-
- return 1;
-}
-
-static cell_t SetVariantColor(IPluginContext *pContext, const cell_t *params)
-{
- cell_t *val;
- unsigned char *vptr = g_Variant_t;
-
- pContext->LocalToPhysAddr(params[1], &val);
-
- *(unsigned char *)vptr = val[0];
- vptr += sizeof(unsigned char);
- *(unsigned char *)vptr = val[1];
- vptr += sizeof(unsigned char);
- *(unsigned char *)vptr = val[2];
- vptr += sizeof(unsigned char);
- *(unsigned char *)vptr = val[3];
- vptr += sizeof(unsigned char) + sizeof(int)*2 + sizeof(unsigned long);
- *(fieldtype_t *)vptr = FIELD_COLOR32;
-
- return 1;
-}
-
-static cell_t SetVariantEntity(IPluginContext *pContext, const cell_t *params)
-{
- CBaseEntity *pEntity;
- unsigned char *vptr = g_Variant_t;
- CBaseHandle bHandle;
-
- ENTINDEX_TO_CBASEENTITY(params[1], pEntity);
- bHandle = reinterpret_cast<IHandleEntity *>(pEntity)->GetRefEHandle();
-
- vptr += sizeof(int)*3;
- *(unsigned long *)vptr = (unsigned long)(bHandle.ToInt());
- vptr += sizeof(unsigned long);
- *(fieldtype_t *)vptr = FIELD_EHANDLE;
-
- return 1;
-}
-
sp_nativeinfo_t g_EntInputNatives[] =
{
{"AcceptEntityInput", AcceptEntityInput},
- {"SetVariantBool", SetVariantBool},
- {"SetVariantString", SetVariantString},
- {"SetVariantInt", SetVariantInt},
- {"SetVariantFloat", SetVariantFloat},
- {"SetVariantVector3D", SetVariantVector3D},
- {"SetVariantPosVector3D", SetVariantPosVector3D},
- {"SetVariantColor", SetVariantColor},
- {"SetVariantEntity", SetVariantEntity},
{NULL, NULL},
};
Oops, something went wrong.

0 comments on commit 08238a8

Please sign in to comment.