Skip to content

Commit 3fb09e8

Browse files
committed
add pointer sdktools type
1 parent 8612720 commit 3fb09e8

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

extensions/sdktools/vcaller.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ inline void DecodePassMethod(ValveType vtype, SDKPassMethod method, PassType &ty
6363
type = PassType_Basic;
6464
if (vtype == Valve_POD
6565
|| vtype == Valve_Float
66-
|| vtype == Valve_Bool)
66+
|| vtype == Valve_Bool
67+
|| vtype == Valve_Pointer)
6768
{
6869
flags = PASSFLAG_BYVAL | PASSFLAG_ASPOINTER;
6970
} else {
@@ -394,8 +395,8 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
394395
}
395396

396397
//note: varargs pawn args are passed by-ref
397-
cell_t *cell;
398-
pContext->LocalToPhysAddr(params[startparam], &cell);
398+
intptr_t *cell;
399+
pContext->LocalToPhysAddr(params[startparam], reinterpret_cast<cell_t**>(&cell));
399400
void *thisptr = reinterpret_cast<void*>(*cell);
400401

401402
if (thisptr == nullptr)
@@ -429,7 +430,8 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
429430
{
430431
startparam += 2;
431432
} else if (vc->retinfo->vtype == Valve_Vector
432-
|| vc->retinfo->vtype == Valve_QAngle)
433+
|| vc->retinfo->vtype == Valve_QAngle
434+
|| vc->retinfo->vtype == Valve_Pointer)
433435
{
434436
startparam += 1;
435437
}
@@ -506,7 +508,8 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
506508
pContext->StringToLocalUTF8(params[retparam], *addr, *(char **)vc->retbuf, &written);
507509
return (cell_t)written;
508510
} else if (vc->retinfo->vtype == Valve_Vector
509-
|| vc->retinfo->vtype == Valve_QAngle)
511+
|| vc->retinfo->vtype == Valve_QAngle
512+
|| vc->retinfo->vtype == Valve_Pointer)
510513
{
511514
if (numparams < 2)
512515
{

extensions/sdktools/vdecoder.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ size_t ValveParamToBinParam(ValveType type,
164164
return sizeof(float);
165165
}
166166
}
167+
case Valve_Pointer:
168+
{
169+
info->type = PassType_Basic;
170+
info->flags = flags;
171+
if (flags & PASSFLAG_ASPOINTER)
172+
{
173+
needs_extra = true;
174+
info->size = sizeof(void*);
175+
return sizeof(void*) * 2;
176+
} else {
177+
info->size = sizeof(void*);
178+
return sizeof(void*);
179+
}
180+
}
167181
}
168182

169183
return 0;
@@ -278,6 +292,20 @@ DataStatus EncodeValveParam(IPluginContext *pContext,
278292

279293
return Data_Okay;
280294
}
295+
case Valve_Pointer: // buffer -> sourcepawn
296+
{
297+
intptr_t *addr;
298+
pContext->LocalToPhysAddr(param, reinterpret_cast<cell_t**>(&addr));
299+
300+
if (data->flags & PASSFLAG_ASPOINTER)
301+
{
302+
buffer = *(intptr_t **)buffer;
303+
}
304+
305+
*addr = *(intptr_t *)buffer;
306+
307+
return Data_Okay;
308+
}
281309
}
282310

283311
return Data_Fail;
@@ -573,6 +601,23 @@ DataStatus DecodeValveParam(IPluginContext *pContext,
573601
*(char **)buffer = addr;
574602
return Data_Okay;
575603
}
604+
case Valve_Pointer: // sourcepawn -> buffer
605+
{
606+
intptr_t *addr;
607+
pContext->LocalToPhysAddr(param, reinterpret_cast<cell_t**>(&addr));
608+
609+
if (data->decflags & VDECODE_FLAG_BYREF)
610+
{
611+
addr = reinterpret_cast<intptr_t*>(*addr);
612+
}
613+
if (data->flags & PASSFLAG_ASPOINTER)
614+
{
615+
*(void **)buffer = (unsigned char *)_buffer + pCall->stackEnd + data->obj_offset;
616+
buffer = *(void **)buffer;
617+
}
618+
*(intptr_t *)buffer = *addr;
619+
return Data_Okay;
620+
}
576621
}
577622

578623
return Data_Fail;

extensions/sdktools/vdecoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enum ValveType
5454
Valve_String, /**< String */
5555
Valve_Bool, /**< Boolean */
5656
Valve_Object, /**< Object, not matching one of the above types */
57+
Valve_Pointer, /**< 64 bit or 32 bit array */
5758
};
5859

5960
enum DataStatus

plugins/include/sdktools.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ enum SDKType
8888
SDKType_Float, /**< Float (any) */
8989
SDKType_Edict, /**< edict_t (always as pointer) */
9090
SDKType_String, /**< NULL-terminated string (always as pointer) */
91-
SDKType_Bool /**< Boolean (any) */
91+
SDKType_Bool, /**< Boolean (any) */
92+
SDKType_Object,
93+
SDKType_Pointer, /**< Pointer (pass in an array) */
9294
};
9395

9496
enum SDKPassMethod

0 commit comments

Comments
 (0)