AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Copyback Vector (https://forums.alliedmods.net/showthread.php?t=312147)

Accelerator 11-18-2018 10:03

Copyback Vector
 
Hello. I am trying to call a function that, after executing get a position in a variable:
PHP Code:

cell_t L4D2_GetRandomSpawnPosition(IPluginContext *pContext, const cell_t *params)
{
    if (
g_pZombieManager == NULL)
    {
        return 
pContext->ThrowNativeError("ZombieManager unsupported or not available; file a bug report");
    }

    static 
ICallWrapper *pWrapper NULL;

    if (!
pWrapper)
    {
        
REGISTER_NATIVE_ADDR("GetRandomSpawnPosition"
            
PassInfo pass[4]; \
            
pass[0].flags PASSFLAG_BYVAL; \
            
pass[0].size sizeof(ZombieClassType); \
            
pass[0].type PassType_Basic; \
            
pass[1].flags PASSFLAG_BYVAL; \
            
pass[1].size sizeof(int); \
            
pass[1].type PassType_Basic; \
            
pass[2].flags PASSFLAG_BYVAL; \
            
pass[2].size sizeof(CBaseEntity *); \
            
pass[2].type PassType_Basic; \
            
pass[3].flags PASSFLAG_BYVAL; \
            
pass[3].size sizeof(Vector*); \
            
pass[3].type PassType_Basic; \
            
pWrapper g_pBinTools->CreateCall(addrCallConv_ThisCallNULLpass4));
    }

    
int client params[3];
    
CBaseEntity pClient NULL;
    if (
client != -1)
    {
        
pClient UTIL_GetCBaseEntity(clienttrue);
        if(
pClient == NULL
        {
            return 
pContext->ThrowNativeError("Invalid client entity");        
        }
    }

    
Vector vector;
    
vector[0] = sp_ctof(0.0);
    
vector[1] = sp_ctof(0.0);
    
vector[2] = sp_ctof(0.0);

    
unsigned char vstksizeof(void*) + sizeof(ZombieClassType) + sizeof(int) + sizeof(CBaseEntity *) + sizeof(Vector*) ];
    
unsigned char *vptr vstk;

    *(
void **)vptr g_pZombieManager;
    
vptr += sizeof(void *);
    
    *(
cell_t*)vptr params[1];
    
vptr += sizeof(ZombieClassType);

    *(
int *)vptr params[2];
    
vptr += sizeof(int *);

    *(
CBaseEntity **)vptr pClient;
    
vptr += sizeof(CBaseEntity *);

    *(
Vector**)vptr = &vector;

    
pWrapper->Execute(vstkNULL);

    const 
void *buffer = (const unsigned char *)vstk pWrapper->GetParamInfo(3)->offset;

    
Vector *NULL;
    
= *(Vector**)buffer;

    
cell_taddr;
    
pContext->LocalToPhysAddr(params[4], &addr);

    
addr[0]=sp_ftoc(v->x);
    
addr[1]=sp_ftoc(v->y);
    
addr[2]=sp_ftoc(v->z);
    return 
0;


It works in linux, but in windows I get a server crash on pWrapper->Execute(vstk, NULL);... How can I assign a different solution so that after the call, the function returns an updated variable (like for example VENCODE_FLAG_COPYBACK in sdktools)?

gubka 12-20-2018 05:39

Re: Copyback Vector
 
Like i uderstand, some calls like even Terminate require some __asm work, maybe the issue in that particular function is similar?


All times are GMT -4. The time now is 17:32.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.