Gamemode SDK for C/C++ (GDK)

C++ ia mnio del reslo papra?
Reply

Quote:
Originally Posted by Malganys
View Post
Hi,

recently I downloaded sampgdk and have this warnings and 1 error:
Code:
C:\Users\Malganys\Desktop\C++\include\plugin.h	In file included from C:\Users\Malganys\Desktop\C++\include/plugin.h
22		C:\Users\Malganys\Desktop\C++\include\a_samp.h	                 from C:\Users\Malganys\Desktop\C++\include/a_samp.h
2		C:\Users\Malganys\Desktop\C++\Programa.cpp	                 from C:\Users\Malganys\Desktop\C++\Programa.cpp
185	47	C:\Users\Malganys\Desktop\C++\include\sdk\amx\amx.h	[Warning] 'packed' attribute ignored for field of type 'char [20]' [-Wattributes]
215	25	C:\Users\Malganys\Desktop\C++\include\sdk\amx\amx.h	[Note] in expansion of macro 'PACKED'
185	47	C:\Users\Malganys\Desktop\C++\include\sdk\amx\amx.h	[Warning] 'packed' attribute ignored for field of type 'char' [-Wattributes]
265	25	C:\Users\Malganys\Desktop\C++\include\sdk\amx\amx.h	[Note] in expansion of macro 'PACKED'
185	47	C:\Users\Malganys\Desktop\C++\include\sdk\amx\amx.h	[Warning] 'packed' attribute ignored for field of type 'char' [-Wattributes]
266	25	C:\Users\Malganys\Desktop\C++\include\sdk\amx\amx.h	[Note] in expansion of macro 'PACKED'
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib32\libmingw32.a(lib32_libmingw32_a-crt0_c.o)	In function `main':
18		h:\crossdev\src\mingw-w64-v3-svn\mingw-w64-crt\crt\crt0_c.c	undefined reference to `WinMain@16'
C:\Users\Malganys\Desktop\C++\collect2.exe	[Error] ld returned 1 exit status
Warning lines:
Code:
#if defined __GNUC__
  #define PACKED        __attribute__((packed))
#else
  #define PACKED
#endif
yeah but the ERROR you have is about your project lacking a WinMain, Windows Main entry point
Reply

I dont know if i should post this here but anyway. Everytime i include RakNet with the SDK i get this error:

pawn Code:
Error   1   error C2371: 'int32_t' : nueva definiciуn; tipos bбsicos distintos  c:\...\visual studio 2013\projects\server\server\sdk\amx\amx.h  60  1
Error   2   error C2371: 'uint32_t' : nueva definiciуn; tipos bбsicos distintos c:\...\visual studio 2013\projects\server\server\sdk\amx\amx.h  61  1
Reply

If you look into amx.h you'll find this code:

Code:
#if defined HAVE_STDINT_H
  #include <stdint.h>
#else
  #if defined __LCC__ || defined __DMC__ || defined LINUX
    #if defined HAVE_INTTYPES_H
      #include <inttypes.h>
    #else
      #include <stdint.h>
    #endif
  #elif !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
    /* The ISO C99 defines the int16_t and int_32t types. If the compiler got
     * here, these types are probably undefined.
     */
    #if defined __MACH__
      #include <ppc/types.h>
      typedef unsigned short int  uint16_t;
      typedef unsigned long int   uint32_t;
    #elif defined __FreeBSD__
      #include <inttypes.h>
    #else
      typedef short int           int16_t;
      typedef unsigned short int  uint16_t;
      #if defined SN_TARGET_PS2
        typedef int               int32_t;
        typedef unsigned int      uint32_t;
      #else
        typedef long int          int32_t;
        typedef unsigned long int uint32_t;
      #endif
      #if defined __WIN32__ || defined _WIN32 || defined WIN32
        typedef __int64	          int64_t;
        typedef unsigned __int64  uint64_t;
        #define HAVE_I64
      #elif defined __GNUC__
        typedef long long         int64_t;
        typedef unsigned long long uint64_t;
        #define HAVE_I64
      #endif
    #endif
  #endif
  #define HAVE_STDINT_H
#endif
which basically checks if your platform/compiler has fixed-size integer types ([u]intX_t).

Since you're using Visual Studio it thinks you don't have those, however, Visual C++ since VS 2010 provides stdint.h (probably because they started implementing C++11 in that version), so you can simply define HAVE_STDINT_H and the errors will go away.
Reply

Thanks.
Reply

Yep, the line in server.cfg
Код:
plugins crashdetect streamer Whirlpool sscanf mysql GM
Reply

Quote:
Originally Posted by JustBored
Посмотреть сообщение
Yep, the line in server.cfg
Код:
plugins crashdetect streamer Whirlpool sscanf mysql GM
Why are you using mysql plugin while c++ has its own mysql library?
Reply

So... any idea why im having this crash?
Reply

Looks like you are not providing all mysql_connect parameters. You also have to provide the optional ones.
Reply

Quote:
Originally Posted by JustBored
Посмотреть сообщение
Im having an issue with the GDK, i've been trying to use the mysql_connect function from the BlueG plugin but everytime i call the function the samp-server crashes: this is my code
When i declare the function:

pawn Код:
namespace Hooks
{
    class MySQLHooks
    {
        public: static cell mysql_connect(char *host, char *user, char* db, char *pass);
//more functions
    };
    cell MySQLHooks::mysql_connect(char *host, char *user, char* db, char *pass)
    {
        return (cell)sampgdk_InvokeNative(sampgdk_FindNative("mysql_connect"), "ssss", host, user, db, pass);
    }
//more functions
};
And the part where i use the function:

pawn Код:
struct connectiondata
{
    char *host = "localhost";
    char *db = "tdm";
    char *password = "";
    char *user = "root";
    cell ConnectionHandle = 0;
};
connectiondata *ConnectionData;

PLUGIN_EXPORT bool PLUGIN_CALL OnGameModeInit()
{
    logprintf("Inited");
    ConnectionData->ConnectionHandle = Hooks::MySQLHooks::mysql_connect(ConnectionData->host, ConnectionData->user, ConnectionData->db, ConnectionData->password); //this is the line where the plugin crashes
    if (Hooks::MySQLHooks::mysql_ping(ConnectionData->ConnectionHandle))
    {
        logprintf("The MySQL system inited correctly: (HOST: %s | User: %s | DB: %s | Password: %s", ConnectionData->host, ConnectionData->user, ConnectionData->db, ConnectionData->password);
    }
    else
    {
        logprintf("I coudnt connect to the MySQL system.");
    }
    return true;
}
Because you are using a wrong format with sampgdk_InvokeNative.
String is not like other one cell length types. If you use a string you MUST mention the length of string in format string.
You can do this like "S[FIXED_LENGTH]" or "[S[*num_argument_that_contains_sizeof_string]".
So try to use "S[1024]S[1024]S[1024]S[1024]".
Reply

I provide them but it keeps crashing, after some debugging i figure out that it crashes when i call the function (not the one from the gdk)
pawn Код:
cell Hooks::MySQLHooks::mysql_connect(char *host, char *user, char* db, char *pass, int port)
    {
        sampgdk::logprintf("hi");
        AMX_NATIVE native = sampgdk_FindNative("mysql_connect");
        if (native != NULL)
        {
            sampgdk::logprintf("it exists");
        }
        else sampgdk::logprintf(" it doesnt");
        return (cell)sampgdk_InvokeNative(sampgdk_FindNative("mysql_connect"), "ssssi", host, user, db, pass, port);
    }
The hi message doesnt even appear.
Reply

Here's the syntax of mysql_connect in PAWN

pawn Код:
mysql_connect(host[], user[], database[], password[], port = 3306, bool:autoreconnect = true, pool_size = 2)
But you've only filled the 5 first parameters. There are 2 more that aren't filled.
Reply

Quote:
Originally Posted by S4t3K
Посмотреть сообщение
Here's the syntax of mysql_connect in PAWN

pawn Код:
mysql_connect(host[], user[], database[], password[], port = 3306, bool:autoreconnect = true, pool_size = 2)
But you've only filled the 5 first parameters. There are 2 more that aren't filled.
Im using the plugin version R7 and in the include the parameters of mysql_connect are
pawn Код:
(const host[], const user[], const database[], const password[], port = 3306)
Anyway i used the debugger of VS and im getting a Violation Access error when im calling the hooked function
Reply

Quote:
Originally Posted by JustBored
Посмотреть сообщение
I provide them but it keeps crashing, after some debugging i figure out that it crashes when i call the function (not the one from the gdk)
pawn Код:
cell Hooks::MySQLHooks::mysql_connect(char *host, char *user, char* db, char *pass, int port)
    {
        sampgdk::logprintf("hi");
        AMX_NATIVE native = sampgdk_FindNative("mysql_connect");
        if (native != NULL)
        {
            sampgdk::logprintf("it exists");
        }
        else sampgdk::logprintf(" it doesnt");
        return (cell)sampgdk_InvokeNative(sampgdk_FindNative("mysql_connect"), "ssssi", host, user, db, pass, port);
    }
The hi message doesnt even appear.
Do you really know C++ !?
pawn Код:
connectiondata *ConnectionData;
This isn't even initialized, so it's null!
Reply

Quote:
Originally Posted by samiras
Посмотреть сообщение
Do you really know C++ !?
pawn Код:
connectiondata *ConnectionData;
This isn't even initialized, so it's null!
Oh yeah lol i didnt noticed about that i forgot to initialize the structure
Reply

Finally, was waiting for 4.2
Reply

Hello! Unfortunatelly I have CentOS server and want to compile your GDK from the box.
What I have done:
updated GCC to 4.7.6 with devtoolset-1.1
updated python to 2.7
installed cmake
First of all try to make project and success with it.
Next step I turned on the following options:
PHP код:
option(SAMPGDK_STATIC "Build static library instead" ON)
option(SAMPGDK_BUILD_PLUGINS "Build example plugins" ON)
option(SAMPGDK_BUILD_AMALGAMATION "Build amalgamation" ON
And tried to recompile again:

PHP код:
[  0%] Built target sampgdk_init
[  2%] Generating lib/sampgdk/a_vehicles.c
[  4%] Generating include/sampgdk/a_http.h
[  6%] Generating include/sampgdk/a_objects.h
[  8%] Generating include/sampgdk/a_players.h
10%] Generating include/sampgdk/a_samp.h
12%] Generating include/sampgdk/a_vehicles.h
14%] Generating lib/sampgdk/a_http.api
16%] Generating lib/sampgdk/a_objects.api
18%] Generating lib/sampgdk/a_players.api
20%] Generating lib/sampgdk/a_samp.api
22%] Generating lib/sampgdk/a_vehicles.api
24%] Generating lib/sampgdk/sampgdk.sym
26%] Generating lib/sampgdk/a_http.c
28%] Generating lib/sampgdk/a_objects.c
30%] Generating lib/sampgdk/a_players.c
32%] Generating lib/sampgdk/a_samp.c
Scanning dependencies of target sampgdk
34%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/amx.c.o
36%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/amxhooks.c.o
38%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/array.c.o
40%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/callback.c.o
42%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/fakeamx.c.o
44%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/hook.c.o
46%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/log.c.o
48%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/logprintf.c.o
51%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/native.c.o
53%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/param.c.o
55%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/plugin.c.o
57%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/timer.c.o
59%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/internal/init.c.o
61%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/a_samp.idl.c.o
63%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/core.c.o
65%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/interop.c.o
67%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/version.c.o
69%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/a_http.c.o
71%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/a_objects.c.o
73%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/a_players.c.o
75%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/a_samp.c.o
77%] Building C object CMakeFiles/sampgdk.dir/lib/sampgdk/a_vehicles.c.o
Linking C 
static library libsampgdk.a
77%] Built target sampgdk
79%] Generating amalgamation
79%] Built target sampgdk_amalgam
81%] Packaging amalgamation files
Archiving file
: /home/batman/sampx/build/lib/sampgdk/sampgdk.c
Archiving file
: /home/batman/sampx/build/lib/sampgdk/sampgdk.h
Archiving file
: /home/batman/sampx/sampgdk/doc/how-to-use-amalgamation.txt
Done
81%] Built target sampgdk_amalgam_package
Scanning dependencies of target helloworld
83%] Building CXX object plugins/helloworld/CMakeFiles/helloworld.dir/helloworld.cpp.o
85%] Building CXX object plugins/helloworld/CMakeFiles/helloworld.dir/home/batman/sampx/samp-plugin-sdk/amxplugin.cpp.o
Linking CXX shared module helloworld
.so
/usr/bin/ldskipping incompatible /opt/centos/devtoolset-1.1/root/usr/lib/gcc/x86_64-redhat-linux/4.7.2/libstdc++_nonshared.a when searching for -lstdc++_nonshared
/usr/bin/ldcannot find -lstdc++_nonshared
collect2
errorld returned 1 exit status
make
[2]: *** [plugins/helloworld/helloworld.soError 1
make
[1]: *** [plugins/helloworld/CMakeFiles/helloworld.dir/allError 2
make
: *** [allError 2 
Could you help me with this issue?
Many thanks for future investigation
Reply

Meanwhile I have reached my windows desctop and successfully followed step-by-step of configuring helloworld example.
Thank you
Reply

I have a problem when linking to the static library, getting the following runtime error when i connect.
Код:
[debug] Run time error 20: "Invalid index parameter (bad entry point)"
This happens as soon as a player connects to the server, not when the server is started.

I don't get this error when i link to the dynamic lib. I've double checked all the project settings, i'm linking to the correct lib, and SAMPGDK_STATIC is defined. Also using the amalgamation.

Note: The function main() exists in the blank mode i have loaded. So that's not what is causing it.
Reply

Quote:
Originally Posted by iggy1
Посмотреть сообщение
I have a problem when linking to the static library, getting the following runtime error when i connect.
Код:
[debug] Run time error 20: "Invalid index parameter (bad entry point)"
This happens as soon as a player connects to the server, not when the server is started.

I don't get this error when i link to the dynamic lib. I've double checked all the project settings, i'm linking to the correct lib, and SAMPGDK_STATIC is defined. Also using the amalgamation.

Note: The function main() exists in the blank mode i have loaded. So that's not what is causing it.
If you're using amalgamation, you don't need anything else than sampgdk.c, sampgdk.h, and the plugin SDK.
You just need to define before including sampgdk the following macro: SAMPGDK_AMALGAMATION
Then, you're free to use sampgdk without (using) including the sampgdk (shared) library

Here's an example of the plugin, using SAMPGDK Amalgamation
PHP код:
#define SAMPGDK_AMALGAMATION
#include <sampgdk.h>
PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) { return sampgdk::Load(ppData); }
PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() { return sampgdk::Supports() | SUPPORTS_PROCESS_TICK;}
PLUGIN_EXPORT void PLUGIN_CALL Unload() { sampgdk::Unload(); }
PLUGIN_EXPORT void PLUGIN_CALL ProcessTick() { sampgdk::ProcessTick(); } 
You don't need "main", "dllMain", etc. to make this dll works, since the moment you have the functions above declared & defined, as well the samphp.def included into the project, and configured correctly.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)