AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Can SDKCall Return String? (https://forums.alliedmods.net/showthread.php?t=327663)

ABCDEFGH23 10-02-2020 20:51

Can SDKCall Return String?
 
PHP Code:


ConditionNames
:

"TF_COND_AIMING"(0)
"TF_COND_ZOOMED"(4)
"TF_COND_DISGUISING"(8)
"TF_COND_DISGUISED"(0xC//12
"TF_COND_STEALTHED"(0x10//16
"TF_COND_INVULNERABLE"(0x14//20
.
.


PHP Code:

GetTFConditionName(int condition){
if(
condition 129)return 0;
return 
DS:ConditionNames[condition*4];



PHP Code:

"GetTFConditionName"
{
"library" "server"
"windows"    "\x55\x8B\xEC\x8B\x45\x08\x3D\x82\x00\x00\x00"
"linux"        "@_Z18GetTFConditionName7ETFCond"
"mac"        "@_Z18GetTFConditionName7ETFCond"


PHP Code:

Handle hTestHandle;

public 
void OnPluginStart(){

Handle Config LoadGameConfigFile("TextFile");

StartPrepSDKCall(SDKCall_Static);
PrepSDKCall_SetFromConf(ConfigSDKConf_Signature"GetTFConditionName");
PrepSDKCall_SetReturnInfo(SDKType_StringSDKPass_Pointer);

/*
i tried SDKType_PlainOldData, SDKPass_Pointer,
SDKType_PlainOldData, SDKPass_ByRef,
even SDKType_PlainOldData, SDKPass_ByVal,
well it worked, but it prints DWORD size, like this "TF_C", "Y{'Q"
+ SDKType_String, SDKPass_ByRef, ByVal, Pointer = runtime error
*/

PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain);
hTestHandleEndPrepSDKCall();

//PrintToServer("%d", hTestHandle) -> 49..1, Valid Handle

CloseHandle(Config);

RegConsoleCmd("sm_string_test"stringtest);

}
public 
Action stringtest(int clientint args){

char test[30];

test SDKCall(hTestHandle5); //compile error

PrintToConsole(client"%s"test);

return 
Plugin_Handled;



Solved!!!!!!!!! YES!!!! Many Thank YOU!!!!

PHP Code:


//-------------Solved-------------

Handle hGetTFConditionName;
Handle hStrCopy;

public 
void OnPluginStart(){

Handle Config LoadGameConfigFile("TextFile");

StartPrepSDKCall(SDKCall_Static);
PrepSDKCall_SetFromConf(ConfigSDKConf_Signature"GetTFConditionName");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldDataSDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain);
hGetTFConditionName EndPrepSDKCall();

StartPrepSDKCall(SDKCall_Static);
PrepSDKCall_SetFromConf(ConfigSDKConf_Signature"V_strncpy");
PrepSDKCall_AddParameter(SDKType_StringSDKPass_Pointer);
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain);
hStrCopy EndPrepSDKCall();

CloseHandle(Config);

RegConsoleCmd("sm_string_test"stringtest);

}

public 
Action stringtest(int clientint args){

char test[30];
SDKCall(hStrCopytestSDKCall(hGetTFConditionName33), 30); 
PrintToConsole(client"%s"test); //worked!

return Plugin_Handled;

}
//------------------------------- 


Silvers 10-02-2020 22:25

Re: Can SDKCall Return String?
 
Yep. This is what I use in Info Editor plugin to return strings from an SDKCall:

PHP Code:

    StartPrepSDKCall(SDKCall_Raw);
    if( 
PrepSDKCall_SetFromConf(hGameDataSDKConf_Signature"KeyValues::GetString") == false )
        
SetFailState("Could not load the \"KeyValues::GetString\" gamedata signature.");
    
PrepSDKCall_AddParameter(SDKType_StringSDKPass_Pointer);
    
PrepSDKCall_AddParameter(SDKType_StringSDKPass_Pointer);
    
PrepSDKCall_SetReturnInfo(SDKType_StringSDKPass_Pointer);
    
SDK_KV_GetString EndPrepSDKCall();
    if( 
SDK_KV_GetString == null )
        
SetFailState("Could not prep the \"KeyValues::GetString\" function.");


        
char key[MAX_STRING_LENGTH];
        
char value[MAX_STRING_LENGTH];
        
SDKCall(SDK_KV_GetStringg_PointerMissionvaluesizeof(value), key"N/A"); 

The "key" var is what it's looking for, the "value" var is what it's returning and the "N/A" is the default returned if not found. I think SM wiki explains all this which is where I learnt to SDKCall and return strings.

ABCDEFGH23 10-03-2020 00:13

Re: Can SDKCall Return String?
 
Many Thank You!


All times are GMT -4. The time now is 22:30.

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