Raised This Month: $51 Target: $400
 12% 

View Poll Results: What do you think of this thread?
Good. 34 60.71%
I don't like it. 5 8.93%
It's nice, but the information is not enough. 17 30.36%
Voters: 56. You may not vote on this poll

[TUTORIAL] Writing an Extension (AMX Mod X Module) + Screenshots [May 15, 2014]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-07-2013 , 10:43   [TUTORIAL] Writing an Extension (AMX Mod X Module) + Screenshots [May 15, 2014]
Reply With Quote #1

It's very importantly to know that an extension is a Dynamic Library (DLL) and not a program (EXE). When compiling a C++ program using GCC, adding -shared parameter will set compiler to compile a DLL file and not an executable one.

Usually, a project for an AMX Mod X module requires a lot of header files, not only the ones provided by the operating system. These headers are placed into a folder, for example. A folder named HLSDK that represents the game headers and another one named METAMOD that represents the METAMOD linkage.

To make sure the headers will be available for the project, add parameters -IHLSDK -IMETAMOD -I. -IAnotherFolderName -IMyHeaders or how many folders you want.

The command line for GCC Linux should look like the one listed below.

Code:
gcc Source.cpp Helper.cpp SomeFolder/SomeSource.cpp -ISomeHeaders -IAnotherHeaders -IHattrick/Headers -shared -o Library.so
If you have some header files around your source files, add parameter -I. to make sure the header files will be included.

If you want to link some libraries to you project, type the library name and its extension beside the source files into the GCC compiling command like listed below. In this example, MySQL.a library will be used.

Code:
gcc Source.cpp Helper.cpp SomeFolder/SomeSource.cpp MySQL.a -ISomeHeaders -IAnotherHeaders -IHattrick/Headers -shared -o Library.so
If you want your library to be attached on different operating systems, like a project compiled on Ubuntu to work on Debian, you will need more flags. For this, you will need to use Makefile file. Place the file named 'Makefile' where the project is (around the source files) and then type in Terminal application the command make. A Makefile should look like the one below.

PHP Code:
# Makefile written by Hattrick (Claudiu HKS)
# Support taken from http://forums.alliedmods.net

PROJECT furien_mod_amxx_i386.so

INCLUDE = -I. \
    -
IHLSDK -IMETAMOD

OBJECTS 
amxxmodule.cpp \
    
Source.cpp

FLAGS 
= -DNDEBUG -O2 -funroll-loops -fomit-frame-pointer -pipe \
    -
fvisibility=hidden -fvisibility-inlines-hidden -DLINUX \
    -
shared -m32 -lm -ldl -DPAWN_CELL_SIZE=32 -DJIT -DASM32 \
    -
DHAVE_STDINT_H -fno-strict-aliasing -fno-exceptions \
    -
fno-rtti --Wno-delete-non-virtual-dtor -static-libgcc \
    -
D_snprintf=snprintf -D_strcpy=strcpy -D_strcat=strcat \
    -
D_snprintf_s=snprintf -D_strncpy=strncpy -D_strncat=strncat \
    -
D_stricmp=strcasecmp -D_strcmp=strcmp -D_strncmp=strncmp \
    -
D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \
    -
Dstricmp=strcasecmp
 
# -DJIT // #define JIT
# -DASM32 // #define ASM32
# -DPAWN_CELL_SIZE=32 // #define PAWN_CELL_SIZE 32
# -DHAVE_STDINT_H // #define HAVE_STDINT_H
# -DLINUX // #define LINUX
 
# Information
# -------------------
# If you will get a message like symbol TRUE is not defined, add parameters:
# -DTRUE=1 -DFALSE=0
# If you will get a message like symbol PCHAR is not defined, add parameter:
# -DPCHAR=char* -DPFLOAT=float* -DFLOAT=float -DPSHORT=short*
# Et cetera.
 
# Now build the project.
default:
    
gcc $(OBJECTS) $(FLAGS) $(INCLUDE) -$(PROJECT
For Windows, if you want your project to be able to run on other operating systems, like a project compiled on Windows 8.1 to be able to work on Windows XP, you will have to edit some properties. Your VCXPROJ file should be looking like the one below.

PHP Code:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{C5A8397C-7CCC-4B4E-A005-36EE6E6B872F}</ProjectGuid>
    <RootNamespace>FurienMod</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v120_xp</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
    <UseOfMfc>false</UseOfMfc>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <TargetName>furien_mod_amxx</TargetName>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Midl>
      <MkTypLibCompatible>true</MkTypLibCompatible>
      <SuppressStartupBanner>true</SuppressStartupBanner>
      <TargetEnvironment>Win32</TargetEnvironment>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </Midl>
    <ClCompile>
      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
      <WarningLevel>EnableAllWarnings</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <BrowseInformation>true</BrowseInformation>
      <SuppressStartupBanner>true</SuppressStartupBanner>
      <StringPooling>true</StringPooling>
      <RuntimeTypeInfo>false</RuntimeTypeInfo>
      <SDLCheck>true</SDLCheck>
      <AdditionalIncludeDirectories>HLSDK;METAMOD</AdditionalIncludeDirectories>
      <PreprocessorDefinitions>_WINDOWS;NDEBUG;_USRDLL;WIN;WIN32;__WIN;__WIN32;_WIN_;_WIN;__WIN32__;_WIN32;_WIN32_;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
    </ClCompile>
    <ResourceCompile>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <Culture>0x041d</Culture>
    </ResourceCompile>
    <Link>
      <SuppressStartupBanner>true</SuppressStartupBanner>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <EnableUAC>false</EnableUAC>
      <SubSystem>Windows</SubSystem>
      <TargetMachine>MachineX86</TargetMachine>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="amxxmodule.cpp" />
    <ClCompile Include="Source.cpp" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="amxxmodule.h" />
    <ClInclude Include="Header.h" />
    <ClInclude Include="moduleconfig.h" />
    <ClInclude Include="resource.h" />
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="Furien Mod.rc" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
For better support, open an already made project and edit it as you like, and then compile it. For example, Fun module by AMX Mod X Development Team. Almost each VCXPROJ setting is important, let's say that <RuntimeLibrary>MultiThreaded</RuntimeLibrary> will make project to link all needed dependencies inside it so these dependencies won't be needed separately on the newer machine where the extension will run.

Where should the compiling command be written? If you use Linux, in Terminal or Root Terminal applications, otherwise in Command Prompt. To install the GCC compiler, type into Terminal for Linux sudo apt-get install g++ and for Windows, install MinGW or Code::Blocks.

If you want to compile on Windows using Visual Studio, you need to edit the project properties by pressing the right button of the mouse on the project name and then selecting Properties.

You will have to edit the additional include directories and the additional dependencies to link new libraries, if any.

Into Additional Include Directories field add for example: .;..;HLSDK;METAMOD.

If you want to link some libraries like Regular Expressions (REGEX.LIB) or MySQL Client (MYSQLCLIENT.LIB) add into Additional Dependencies field, at Linking category, the next ones: REGEX\REGEX.LIB;MYSQL\Libraries\MYSQLCLIENT.L IB.

Do not consider compiler warnings. Only errors will block the process. How to solve errors? Read the messages from the compiler and then edit your source or header files until everything will be fine.

Before starting to compile, type in the Command Prompt or in Terminal cd C:\Projects\Project or cd '/home/Claudiu/Scripting' to be into the folder where the source files are.

The main entry for a DLL is BOOL APIENTRY /* APIENTRY, WINAPI or __stdcall */ DllMain(HINSTANCE hInst, DWORD nReason, LPVOID dummyParam) and for an EXE is void /* void or int */ main(SIZE_T argsCnt, CHAR ** argsList).

Code:
-shared          // Dynamic library
-o                 // Output
-I                 // Includes directory
gcc              // Compiler
-D                // Defines
-static-libgcc   // Links current dependencies to project
The AMX Mod X source files: (Hit Zip)
Attached Files
File Type: zip HLSDK + METAMOD Headers.zip (225.6 KB, 12320 views)
File Type: zip Makefile + VCXPROJ.zip (2.1 KB, 574 views)
__________________

Last edited by claudiuhks; 05-15-2014 at 01:17.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Old 10-08-2013, 23:47
commonbullet
This message has been deleted by commonbullet.
bat
Veteran Member
Join Date: Jul 2012
Old 10-09-2013 , 11:26   Re: [TUTORIAL] Writing an Extension (AMX Mod X Module)
Reply With Quote #2

hmm thanks
__________________
bat is offline
Send a message via Skype™ to bat
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-14-2013 , 14:19   Re: [TUTORIAL] Writing an Extension (AMX Mod X Module)
Reply With Quote #3

Because some persons voted this thread as not detailed enough, another information is given below.

>> Windows MinGW's GCC Compiler <<

1. Installing.

- Type into Google "MinGW for Windows" and download it then install properly with its default settings.

2. Configuring.

- Go to Control Panel\System\Advanced System Settings\Environment Variables.
- Now you see two titles, "User Variables for $USERNAME$" and "System Variables".
- Click on variable "Path" from "System Variables" and then press Edit button.
- Into "Variable Value" field, add the line listed below, at the end.

Code:
;C:\MinGW\bin
- Save everything.

3. Compiling.

- Now you will be able to type in Command Prompt commands like "GCC".

>> Microsoft Visual Studio Compiler <<

1. Installing.

- Type into Google "Microsoft Visual Studio" and download it then install properly with its default settings.

2. Configuring and compiling.

- Open a default AMX Mod X project for a module as "Fun". Usually, you need to open "SLN" files and not "VCXPROJ".
- Press the right button of the mouse on the project's name into the Solution Explorer then select Properties.
- Into "Additional Include Directories", add lines like: .;..;HLSDK;METAMOD;$(AdditionalIncludeDirecto ries).
- If you have any libraries, you may link them typing their names into "Additional Dependencies".
- Be careful, if you want to use library C:\REGEX.LIB then you have to type into Additional Dependencies field C:\REGEX.LIB and not just REGEX.LIB.
- To compile it, run it as Release. To compile it into debug mode, run it as Debug. Usually, when everything is alright, Release version should be used.

>> Linux GCC Compiler <<

1. Compiling.

- You just have to see the command from the first message of this thread to understand. You don't have to edit any environment variables here.
- If you want to use Makefile feature, remove flag -Werror or -Wall from Makefile file and edit it properly. This feature is for advanced users, because many of them may get lost, unfortunately.



__________________

Last edited by claudiuhks; 03-17-2014 at 19:08.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
CryWolf
Veteran Member
Join Date: Jul 2008
Location: Romania
Old 10-14-2013 , 15:34   Re: [TUTORIAL] Writing an Extension (AMX Mod X Module)
Reply With Quote #4

- edited -
__________________
I dont walk trough this world with fear in my heart.
www.dark-arena.com L4D, CS1.6, CZ Servers

Last edited by CryWolf; 10-15-2013 at 11:07. Reason: Some people think, that god have taken them from foot!
CryWolf is offline
Send a message via MSN to CryWolf Send a message via Yahoo to CryWolf
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-15-2013 , 09:26   Re: [TUTORIAL] Writing an Extension (AMX Mod X Module)
Reply With Quote #5

For you to have a better English, I suggest using Google Chrome browser with English language activated. It will underline your wrong words with red color, so you will know if you type correctly or not.

Nope, it is not possible to compile a Linux extension (ELF header) on a Windows machine.

I think you still do not understand what I explained into the first message. Your header files are still not included. As a help for you, I suggest you to do the things listed below.

- Unzip archive into Local Disk C:.
- Make sure directories C:\HLSDK and C:\METAMOD exist.
- Into Additional Include Directories field (Microsoft Visual Studio) add lines:

Code:
.;..;sdk;C:\HLSDK;C:\METAMOD
If you want to run Linux into your Windows machine, install and configure Oracle Virtual Machine. Download ISO file for Linux Ubuntu or Debian by accessing www.ubuntu.com and then link ISO file to the newest Virtual Machine created. Give to the newest Virtual Machine created name Ubuntu or Debian, depending by the OS. I recommend at least 1,024 RAM memory and 8 GB space allocated for it to work properly.

I hope it will work without any error.
__________________

Last edited by claudiuhks; 03-17-2014 at 19:11.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
ScrappeR
Senior Member
Join Date: Dec 2010
Old 10-15-2013 , 10:13   Re: [TUTORIAL] Writing an Extension (AMX Mod X Module)
Reply With Quote #6

Super claudiu but, I have "Microsoft Visual Studio" How to put any module files for Compile it, I can't understand this tuto..

small example Parachute plugin how to compile in file .so thats is. Thanks
__________________

Last edited by ScrappeR; 10-15-2013 at 10:27.
ScrappeR is offline
Old 10-16-2013, 03:13
LordOfNothing
This message has been deleted by ConnorMcLeod. Reason: troll, or posting random confusing code, or posting for posts count
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 10-16-2013 , 03:53   Re: [TUTORIAL] Writing an Extension (AMX Mod X Module)
Reply With Quote #7

Simple but nice job buddy, finally for the 1st time i've managed to compile an amxx module (SemiClip). But strange.. why my compiled .dll size is smaller than your compiled .dll?
Your .dll size - 450KB
My .dll size - 89.5KB

I've tested the exntension on Win7 and it's working. But not sure on WinServer2008
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019
yokomo is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 10-16-2013 , 05:09   Re: [TUTORIAL] Writing an Extension (AMX Mod X Module)
Reply With Quote #8

Quote:
Originally Posted by yokomo View Post
Simple but nice job buddy, finally for the 1st time i've managed to compile an amxx module (SemiClip). But strange.. why my compiled .dll size is smaller than your compiled .dll?
Your .dll size - 450KB
My .dll size - 89.5KB

I've tested the exntension on Win7 and it's working. But not sure on WinServer2008
maybe because of the compile mod: Debug ? or Release ?
TheDS1337 is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-16-2013 , 07:40   Re: [TUTORIAL] Writing an Extension (AMX Mod X Module)
Reply With Quote #9

Quote:
Originally Posted by yokomo View Post
Simple but nice job buddy, finally for the 1st time i've managed to compile an amxx module (SemiClip). But strange.. why my compiled .dll size is smaller than your compiled .dll?
Your .dll size - 450KB
My .dll size - 89.5KB

I've tested the exntension on Win7 and it's working. But not sure on WinServer2008
It should work on Server 2008.
The difference is between Release and Debug. Debug takes more bytes.
The default VCXPROJ file that is provided by AMX Mod X team is configured to work with all OS.
My Special Geoip module uses a VCXPROJ file provided by AMX Mod X and edited by me using Notepad++ with XML language.
__________________

Last edited by claudiuhks; 03-17-2014 at 19:12.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 10-16-2013 , 08:27   Re: [TUTORIAL] Writing an Extension (AMX Mod X Module)
Reply With Quote #10

Quote:
Originally Posted by DeagLe.Studio View Post
maybe because of the compile mod: Debug ? or Release ?
Quote:
Originally Posted by claudiuhks View Post
It should work on Server 2008.
The difference is between Release and Debug. Debug takes more bytes.
The default VCXPROJ file that is provided by AMX Mod X team is configured to work with all OS.
My Semiclip uses a VCXPROJ file provided by AMX Mod X and edited by me using Notepad++ with XML language.
Yes, i'm using "Release". Well thank for the info, wanna try to compile a Parachute extension

**Edit**
Argghh the bad thing happen to me, module can be load on win7, but bad load in WinServer2008. Claudiu can you add some info how to compile so it can support Older Operating system too?
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019

Last edited by yokomo; 10-16-2013 at 10:06.
yokomo 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 14:19.


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