Raised This Month: $12 Target: $400
 3% 

Passing dynamic array of enum structs to functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Forgetest
Member
Join Date: Aug 2020
Old 10-27-2023 , 04:28   Passing dynamic array of enum structs to functions
Reply With Quote #1

So to begin with, I got a simple structure to help simply my code a bit, where there's a function accepting a dynamic array of enum struct:
PHP Code:
enum struct SDKCallParamsWrapper {
    
SDKType type;
    
SDKPassMethod pass;
    
int decflags;
    
int encflags;
}

methodmap GameDataWrapper GameData {
    public 
Handle CreateSDKCallOrFail(
            
SDKCallType type,
            
SDKFuncConfSource src,
            const 
char[] name,
            const 
SDKCallParamsWrapper[] params = {},
            
int numParams 0,
            
bool hasReturnValue false,
            const 
SDKCallParamsWrapper ret = {}) {
        static const 
char k_sSDKFuncConfSource[SDKFuncConfSource][] = { "offset""signature""address" };
        
Handle result;
        
StartPrepSDKCall(type);
        if (!
PrepSDKCall_SetFromConf(thissrcname))
            
SetFailState("Missing %s \"%s\""k_sSDKFuncConfSource[src], name);
        for (
int i 0numParams; ++i)
            
PrepSDKCall_AddParameter(params[i].typeparams[i].passparams[i].decflagsparams[i].encflags);
        if (
hasReturnValue)
            
PrepSDKCall_SetReturnInfo(ret.typeret.passret.decflagsret.encflags);
        if (!(
result EndPrepSDKCall()))
            
SetFailState("Failed to prep sdkcall \"%s\""name);
        return 
result;
    }

Should be clear that SDKCall setups are really static, so the following style is preferred in my opinion:
PHP Code:
gd.CreateSDKCallOrFail(SDKCall_Entity,
        
SDKConf_Virtual,
        
"a function",
        { {
SDKType_CBasePlayerSDKPass_Pointer} },
        
1); 
However, it will end up a compile error: must be a constant expression; assumed zero, as well as a warning: tag mismatch (expected "SDKType", got "SDKPassMethod"), from the same line.

I tried to correct any error I could find but not really there seems to be, and things get weird when the following compiles:
PHP Code:
SDKCallParamsWrapper params[] = {
    {
SDKType_CBasePlayerSDKPass_Pointer}
};
gd.CreateSDKCallOrFail(SDKCall_EntitySDKConf_Virtual"a function"paramssizeof(params)); 
Although it looks clean but still requires a unique variable name.

I'm assuming there're still some issues with SM enum struct, or anyone could tell if I just messed up?
Forgetest is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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