Raised This Month: $32 Target: $400
 8% 

Metamod plugin writing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Killer zm
Senior Member
Join Date: Jun 2011
Old 01-28-2013 , 07:08   Metamod plugin writing
Reply With Quote #1

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.

Last edited by Killer zm; 01-28-2013 at 07:08.
Killer zm is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 01-28-2013 , 18:21   Re: Metamod plugin writing
Reply With Quote #2

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
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
Killer zm
Senior Member
Join Date: Jun 2011
Old 01-29-2013 , 04:52   Re: Metamod plugin writing
Reply With Quote #3

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 ?
Killer zm is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 01-29-2013 , 06:11   Re: Metamod plugin writing
Reply With Quote #4

Include Directories
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
Killer zm
Senior Member
Join Date: Jun 2011
Old 01-29-2013 , 08:42   Re: Metamod plugin writing
Reply With Quote #5

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 - -

Last edited by Killer zm; 01-31-2013 at 13:23.
Killer zm is offline
Killer zm
Senior Member
Join Date: Jun 2011
Old 01-31-2013 , 13:39   Re: Metamod plugin writing
Reply With Quote #6

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 ...
Killer zm is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 02-01-2013 , 10:56   Re: Metamod plugin writing
Reply With Quote #7

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
    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
Attached Thumbnails
Click image for larger version

Name:	photo.jpg
Views:	2386
Size:	7.4 KB
ID:	115391  
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 02-01-2013 , 17:47   Re: Metamod plugin writing
Reply With Quote #8

Nice thread. Any similar tuts for linux?
OvidiuS is offline
Send a message via Skype™ to OvidiuS
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 02-02-2013 , 04:55   Re: Metamod plugin writing
Reply With Quote #9

sorry for the Linux I only know a little about windows
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
w00tguy123
New Member
Join Date: Feb 2013
Old 02-13-2013 , 06:53   Re: Metamod plugin writing
Reply With Quote #10

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?
w00tguy123 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 02:00.


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