AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [Sharing memory 4 fun] (https://forums.alliedmods.net/showthread.php?t=233903)

Mathias. 01-21-2014 18:39

[Sharing memory 4 fun]
 
core.sp
Spoiler


mycore.inc
Spoiler


plugin1.sp
Spoiler


plugin2.sp
Spoiler


I did not put all the checks and memory cleanup when one of the plugin unload but I will do it later and also GetRawDataStructByName only return the first one found. I will edit it later.

striker07 01-21-2014 18:39

Re: [Sharing memory 4 fun]
 
Thanks :)

Mitchell 01-21-2014 18:59

Re: [Sharing memory 4 fun]
 
Very cool. Seems like an easy alternative that making a bunch of natives.

Mathias. 01-21-2014 19:02

Re: [Sharing memory 4 fun]
 
It can be useful if you want to create run time libraries for plugins. (in sourcepawn)

nergal 01-03-2015 11:03

Re: [Sharing memory 4 fun]
 
I have no fucking idea what this does but I converted it to the new syntax for no reason lol.

I prob converted it wrong but here it is

PHP Code:

#include <sourcemod>
#include <mycore>

ArrayList array_Data null;

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
array_Data = new ArrayList(struct_data);
    
CreateNative("AddDataStruct"Native_AddDataStruct);
    
CreateNative("GetDataStructByName"Native_GetDataStructByName);
    
CreateNative("GetRawDataStructByName"Native_GetRawDataStructByName);
}

public 
int Native_AddDataStruct(Handle pluginint numParams)
{
    
int data[struct_data];
    
GetNativeArray(1datastruct_data);
    
data[m_plugin] = plugin;

    
array_Data.PushArray(data); //PushArrayArray(array_Data, data);
    
PrintToServer("[DEBUG] core: key '%s' by plugin ID '%d'"data[m_key], plugin);
}

public 
int Native_GetDataStructByName(Handle pluginint numParams)
{
    
char key[32];
    
GetNativeString(1key32);
    
PrintToServer("[DEBUG] core: Looking for a data from '%s'..."key);

    
int data[struct_data];

    for (
int iarray_Data.Lengthi++) //GetArraySize(array_Data); i++)
    
{
        
array_Data.GetArray(idata); //GetArrayArray(array_Data, i, data);

        
PrintToServer("[DEBUG] core: is key '%s' equal to '%s' and plugin ID %d equal to  '%d'?"data[m_key], keyplugindata[m_plugin]);

        if (
data[m_plugin] == plugin && StrEqual(data[m_key], keytrue))
        {
            
PrintToServer("[DEBUG] core: key '%s' was found!"key);
            
SetNativeArray(2datastruct_data);
            return 
view_as<int>(true);
        }
        continue;
    }
    
PrintToServer("[DEBUG] core: raw data was not found!");
    return 
view_as<int>(false);
}

public 
int Native_GetRawDataStructByName(Handle pluginint numParams)
{
    
char key[32];
    
GetNativeString(1key32);

    
PrintToServer("[DEBUG] core: Looking for a raw data from '%s'..."key);

    
int data[struct_data];

    for (
int iarray_Data.Lengthi++) //(new i; i < GetArraySize(array_Data); i++)
    
{
        
array_Data.GetArray(idata); //GetArrayArray(array_Data, i, data);
        
PrintToServer("[DEBUG] core: is key '%s' equal to '%s'?"data[m_key], key);

        if (
StrEqual(data[m_key], keytrue))
        {
            
PrintToServer("[DEBUG] core: key '%s' was found from plugin ID '%d'!"keydata[m_plugin]);
            
SetNativeArray(2datastruct_data);
            return 
view_as<int>(true);
        }
    }
    
PrintToServer("[DEBUG] core: raw data was not found!");
    return 
view_as<int>(false);
}







#if defined _mycore_included
 #endinput
#endif
#define _mycore_included

// ignore m_plugin this is used by core

enum struct_data
{
    
Handle m_plugin,
    
char m_key[32],
    
int m_value
};

// Add structure
native void AddDataStruct(int data[struct_data]);

// Find structure declared only by my plugin
native bool GetDataStructByName(const char key[32], int data[struct_data]);

// Find any structures by any plugin
native bool GetRawDataStructByName(const char key[32], int data[struct_data]); 


__int128 01-05-2015 15:41

Re: [Sharing memory 4 fun]
 
does it even compile? I though we could not use the new declaration type into enums


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

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