AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Metamod plugin writing (https://forums.alliedmods.net/showthread.php?t=206972)

Killer zm 01-28-2013 07:08

Metamod plugin writing
 
I need a TUT for how to start make an metamod plugin step by step .I use msvc2010 and i tried again and again and always get errors and when is compiled then is not loaded by metamod on server .I tried even metamod/stub_plugin to compile and i dont did it. If anyone want to help me because I'm tired of trying get a good compiled plugin and this stop me from continue coding a metamod plugin.

Bos93 01-28-2013 18:21

Re: Metamod plugin writing
 
Example as mine:

C:\amxx\amxmodx-source
C:\amxx\metamod-1.19
C:\amxx\hlsdk-2.3-p3\

This pattern metamod plugin:

C:\amxx\metamod-1.19\stub_plugin\meta_api.cpp

Or for test:

PHP Code:

#include <extdll.h>
#include <meta_api.h>

plugin_info_t info = {
   
META_INTERFACE_VERSION,            // ifvers
   
"HELLO WORLD",                  // name
   
"1.01",                        // version
   
"2011/01/15",                  // date
   
"--===((((][@KIRjkeeee))))===--",   // author
   
"http://ultra.ucoz.ru",            // url
   
"HELLOWORLD",                  // logtag, all caps please
   
PT_ANYTIME,                     // (when) loadable
   
PT_ANYPAUSE                     // (when) unloadable
};

enginefuncs_t g_engfuncs;

void WINAPI GiveFnptrsToDll(enginefuncs_tpengfuncsFromEngineglobalvars_t *pGlobals)
{
   
memcpy(&g_engfuncspengfuncsFromEnginesizeof(enginefuncs_t));
}

C_DLLEXPORT int Meta_Query(char *interfaceVersionplugin_info_t **pinfomutil_funcs_t *pMetaUtilFuncs)
{
   *
pinfo = &info;
   
ALERT(at_console"[HELLOWORLD]: meta_query\n");
   return(
TRUE);
}

C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME nowMETA_FUNCTIONS *pFunctionTablemeta_globals_t *pMGlobalsgamedll_funcs_t *pGamedllFuncs)
{
   
ALERT(at_console"[HELLOWORLD]: meta_attach\n");
   return(
TRUE);
}

C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME nowPL_UNLOAD_REASON reason)
{
   
ALERT(at_console"[HELLOWORLD]: meta_detach\n");
   return(
TRUE);


To compile it, you must open stub_mm.sln

C:\amxx\metamod-1.19\stub_plugin\msvc\stub_mm.sln

You need to add hlsdk folder

stub_plugin - properties - VC ++

You can add all

C:\amxx\hlsdk-2.3-p3\utils;
C:\amxx\hlsdk-2.3-p3\ricochet;
C:\amxx\hlsdk-2.3-p3\pm_shared;
C:\amxx\hlsdk-2.3-p3\network;
C:\amxx\hlsdk-2.3-p3\game_shared;
C:\amxx\hlsdk-2.3-p3\engine;
C:\amxx\hlsdk-2.3-p3\dmc;
C:\amxx\hlsdk-2.3-p3\dlls;
C:\amxx\hlsdk-2.3-p3\dedicated;
C:\amxx\hlsdk-2.3-p3\common;
C:\amxx\hlsdk-2.3-p3\cl_dll;

( multiplayer )

meta list will display like this:

PHP Code:

meta list
Currently loaded plugins:
      
description      stat pend  file              vers      src   load  unlod
 
1HELLO WORLD    RUN   -    stub_mm.dll       v1.01  ini   ANY   Pause
1 plugins
1 running 

I can not explain it better, because of my bad English

Killer zm 01-29-2013 04:52

Re: Metamod plugin writing
 
I use msvc 2010

and about this

Code:

stub_plugin - properties - VC ++

You can add all

C:\amxx\hlsdk-2.3-p3\utils;
C:\amxx\hlsdk-2.3-p3\ricochet;
C:\amxx\hlsdk-2.3-p3\pm_shared;
C:\amxx\hlsdk-2.3-p3\network;
C:\amxx\hlsdk-2.3-p3\game_shared;
C:\amxx\hlsdk-2.3-p3\engine;
C:\amxx\hlsdk-2.3-p3\dmc;
C:\amxx\hlsdk-2.3-p3\dlls;
C:\amxx\hlsdk-2.3-p3\dedicated;
C:\amxx\hlsdk-2.3-p3\common;
C:\amxx\hlsdk-2.3-p3\cl_dll;

on stub_plugin - properties - VC ++ i found this

Code:

Executable Directories
Include Directories
Reference Directories
Library Directories
Source Directories
Exclude Directories

so where i add that folders ?

Bos93 01-29-2013 06:11

Re: Metamod plugin writing
 
Include Directories

Killer zm 01-29-2013 08:42

Re: Metamod plugin writing
 
i get compiled with this error

Code:

sdk_util.cpp(40): warning C4793: 'UTIL_LogPrintf' : function compiled as native :
    varargs not supported under /clr

sdk_util.cpp(44): warning C4793: 'UTIL_LogPrintf' : function compiled as native :
    Found an intrinsic not supported in managed code

sdk_util.cpp(46): warning C4793: 'UTIL_LogPrintf' : function compiled as native :
      Found an intrinsic not supported in managed code

this is what i found in sdk_util.cpp
Code:

void UTIL_LogPrintf( char *fmt, ... )
{
    va_list            argptr;
    static char        string[1024];
   
    va_start ( argptr, fmt );
    vsnprintf_s ( string, sizeof(string), fmt, argptr );
    va_end  ( argptr );

    // Print to server console
    ALERT( at_logged, "%s", string );
}

and on meta list i get this
[ 5] <stub_mm. badf load stub_mm.dl v - ini - -

Killer zm 01-31-2013 13:39

Re: Metamod plugin writing
 
i tried now with no sdk_util.cpp

i get a clean compile but is still not loading my metamod plugin

Code:

[ 5] <stub_mm.  badf load  stub_mm.dl  v -      ini  -    -
how can i find where is the problem ?
it could be because of using msvc2010 on windows xp sp2 ?
when i compile amxmodx modules, are loaded. So where can be the problem ?

please someone help me ... i'm sick of it ...

K.K.Lv 02-01-2013 10:56

Re: Metamod plugin writing
 
1 Attachment(s)
I will try my best to explain more clear
  • 1.Property of your computer and add some new environment variables. as mine:
    METAMOD
    E:\AMX MOD X\METAMOD\metamod\
    HLSDK
    E:\AMX MOD X\hlsdk\multiplayer\
    and save the setting.
  • 2.Open the "stub_mm" project(just double click the "stub_mm.sln")
    Propertries -> (All configurations) -> Configuration Propertries -> C/C++ -> General -> Additional include directories,for me:
    $(METAMOD);$(HLSDK)\common;$(HLSDK)\engine;$( HLSDK)\dlls;$(HLSDK)\pm_shared
  • 3.For the files:
    sdk_util.cpp -- I think it was useless, so I delete it usually
    h_export.cpp -- read the comment in the file:mrgreen:
    meta_api.cpp -- you just need to edit your stub plugin information here.eg:
    Code:
    plugin_info_t Plugin_info = {     META_INTERFACE_VERSION, // ifvers     "minimal stub"// name     "1.17"// version     "2003/11/15",   // date     "Will Day <[email protected]>",   // author     "http://www.metamod.org/"// url     "STUB"// logtag, all caps please     PT_ANYTIME, // (when) loadable     PT_ANYPAUSE,    // (when) unloadable };

OK, now let's start write out sample code for the metamod, I want to call ClientConnect,and it is a dll function, we can find it at the dllapi.cpp,so we can edit the file like this:
Code:
#include <extdll.h> #include <dllapi.h> #include <meta_api.h> DLL_FUNCTIONS gFunctionTable; BOOL Client_Connect_Pre_Hook(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]) {     SERVER_PRINT("\n\n\tServer running stub_mm extension\n\t\"Client_Connect_Pre_Hook\" was call");     RETURN_META_VALUE(MRES_IGNORED, TRUE);//ignored the return value. } C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable,                               int *interfaceVersion) {     if(!pFunctionTable)     {         //GetEntityAPI2 called with null pFunctionTable         return(FALSE);     }     else if(*interfaceVersion != INTERFACE_VERSION)     {         //! Tell metamod what version we had, so it can figure out who is out of date.         *interfaceVersion = INTERFACE_VERSION;         return(FALSE);     }     memset(&gFunctionTable, 0, sizeof(DLL_FUNCTIONS));     gFunctionTable.pfnClientConnect = Client_Connect_Pre_Hook; // pfnClientConnect     memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS));     return(TRUE); }

and compile it run the server with this plugin, connect to the server and you could see this on the server console
https://forums.alliedmods.net/attach...1&d=1359734058

OvidiuS 02-01-2013 17:47

Re: Metamod plugin writing
 
Nice thread. Any similar tuts for linux?

K.K.Lv 02-02-2013 04:55

Re: Metamod plugin writing
 
sorry for the Linux I only know a little about windows

w00tguy123 02-13-2013 06:53

Re: Metamod plugin writing
 
I'm having the same problem here. The stub plugin compiles fine with or without K.K.Lv's code in MSVC 2010 but refuses to load through metamod-p. I'm sure metamod-p is working properly because it loads other plugins without issue.

Does anyone have a working MSVC project for a basic plugin like the stub example?


All times are GMT -4. The time now is 10:29.

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