Raised This Month: $52 Target: $400
 13% 

Tutorial: Getting started with metamod plugins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
verideth
Junior Member
Join Date: Jun 2016
Old 12-28-2016 , 22:45   Tutorial: Getting started with metamod plugins
Reply With Quote #1

Requirements:
Intermediate C++ knowledge
A desire to learn

Hey guys, so recently I got into MM:Source development, but have noticed the hard difficulty to get setup. Well, I've decided to make a tutorial on how it all works. And just want you guys to sit back, put your worries away, and read!

So, the game I'm modding is GMod, so my setup will be different, but assuming you have basic C++ background knowledge, the entrypoint of a program is what is ran when it first starts. Currently, I'm making a gmod module, and the entry point is GMOD_MODULE_OPEN, another example of an entrypoint is BOOL WINAPI DllMain, and int main().

So first off, if you don't know c++. I suggest you go learn it at http://www.learncpp.com/
I understand reading isn't the most exciting thing, but hey, we gotta do what we gotta do.

So, I assume you have now setup your entrypoint and basic dll file and are ready to develop.

The first thing to know about source engine (not goldsrc, when I was reversing goldsrc, I found its actually COMPLETELY different from source), is that everything must be a pointer. This means, that almost every class has virtual functions, and abstract classes. For example,
PHP Code:
CBasePlayerply blah blah blah 
CBasePlayer has all virtual functions, and is an abstract class. So ply MUST be a pointer.

2nd, using interfaces is what you're going to what to do. Interfaces are mostly just versions and are needed to use functions in source engine.

Okay, we've got all the basic ideas from source engine out of the way, so now lets actually get to programming some stuff!

First, lets print to console. Pretty easy? Not so simple when you have ABSOLUTELY NO IDEA WHATS GOING ON (like I did when I first started modding source engine )

So, relax, and take it easy. Getting mads never the way to succeed. First, lets goto source mods page. And lets go ahead and get the SDK to make mods with. Choose whatever version suits you, but for now I'm going to use hl2sdk-gmod because I'm making a plugin for gmod. You can find this at https://github.com/alliedmodders/hl2sdk/tree/gmod

So, first things first. Lets setup the include directories. If you don't have basic knowledge of how to use VS. All you do is right click your project, which is the thing with the 2 pluses in the solution explorer, and then click properties. A new window should pop up. You should see a little drop down tab named C/C++. Lets open that. Click on general, and then in additional include directories include these files.

PHP Code:
C:\Users\Verideth\Desktop\hl2sdk-gmod\game\client\hl2;
C:\Users\Verideth\Desktop\hl2sdk-gmod\vstdlib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\vpc_scripts;
C:\Users\Verideth\Desktop\hl2sdk-gmod\vgui2;
C:\Users\Verideth\Desktop\hl2sdk-gmod\utils;
C:\Users\Verideth\Desktop\hl2sdk-gmod\tier1;
C:\Users\Verideth\Desktop\hl2sdk-gmod\tier0;
C:\Users\Verideth\Desktop\hl2sdk-gmod\raytrace;
C:\Users\Verideth\Desktop\hl2sdk-gmod\mathlib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\materialsystem;
C:\Users\Verideth\Desktop\hl2sdk-gmod\lib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\gcsdk;
C:\Users\Verideth\Desktop\hl2sdk-gmod\game\shared;
C:\Users\Verideth\Desktop\hl2sdk-gmod\game\server;
C:\Users\Verideth\Desktop\hl2sdk-gmod\game\client;
C:\Users\Verideth\Desktop\hl2sdk-gmod\game;
C:\Users\Verideth\Desktop\hl2sdk-gmod\fgdlib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\dx9sdk;
C:\Users\Verideth\Desktop\hl2sdk-gmod\dx10sdk;
C:\Users\Verideth\Desktop\hl2sdk-gmod\devtools;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\engine;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\fgdlib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\filesystem;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\Friends;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\g15;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\game;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\haptics;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\inputsystem;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\jpeglib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\keyframe;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\materialsystem;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\mathlib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\matsys_controls;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\maya
;C:\Users\Verideth\Desktop\hl2sdk-gmod\public\mdllib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\p4lib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\particles;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\phonemeextractor;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\scenefilecache;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\shaderapi;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\shaderlib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\SoundEmitterSystem;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\soundsystem;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\sourcevr;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\steam;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\tier0;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\tier1;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\tier2;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\tier3;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\togl;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\toolframework;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\tools;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\unicode;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\unitlib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\vgui_controls;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\vaudio;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\vgui;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\VGuiMatSurface;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\video;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\vphysics;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\vstdlib;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\vtf
;C:\Users\Verideth\Desktop\hl2sdk-gmod\public\zip;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\datamodel;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\datacache;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\bitmap;
C:\Users\Verideth\Desktop\hl2sdkgmod\public\avi;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public\appframework;
C:\Users\Verideth\Desktop\hl2sdk-gmod\public;
C:\Users\Verideth\Desktop\hl2sdkgmod\common;
C:\Users\Verideth\Desktop\hl2sdk-gmod
Of course, replacing hl2sdk-gmod with whatever branch you downloaded.

Okay, next go into linker->general->additional library directories.
Type in this

PHP Code:
C:\Users\Verideth\Desktop\hl2sdk-gmod\lib\public; 
Once again, replacing hl2sdk-gmod with whatever branch you downloaded

Finally, go into input and type in

PHP Code:
tier0.lib
tier1
.lib
tier2
.lib
tier3
.lib
bitmap
.lib
choreoobjects
.lib
dmxloader
.lib
mathlib
.lib
matsys_controls
.lib
nvtristrip
.lib
particles
.lib
raytrace
.lib
steam_api
.lib
vgui_controls
.lib
vmpi
.lib
vstdlib
.lib
vtf
.lib 
This should link up all the libraries needed to make a mod. Now, you don't have to link ALL of these, I just do it to be 100% sure.

Okay, everythings setup. Now what?

Lets make a simple print to console.

Create a header file in VS and name it YourNameGoesHere.h

Inside of this, type in the following

PHP Code:
#include "cbase.h" // Base source stuff
#include <iostream> // input output stream (I include this just as practice in almost all my C++ projects, whether it uses it or not)
#include <string> // string
#include "Color.h" // color 
Okay, we have this. Lets make a namespace (just for neatness) inside of our header file (optional), then we can finally get to work!

Here we go, finally about to become a metamod master.

Lets make a function that prints to console

PHP Code:
    void PrintToConsole(const charmsg, ...)
    {
        
ConColorMsg(Color(2525255200), msg); // You can also do Msg if you just want a plain white print, I just do ConColorMsg for good looks :D
    

Okay, lets try it! Load up your game, call it like PrintToConsole("INITALIZE"); and build!

Open up console and you should see


Awe yea! Your first metamod!

Lets get into something a little more advanced, such as maybe using interfaces to set view angles? That sounds like a good beginner challenge. Lets do it

Inside your header add this to the top

PHP Code:
#define LOADINTERFACE(_module_, _version_, _out_) Sys_LoadInterface(_module_, _version_, NULL, reinterpret_cast<void**>(& _out_ )) 
This will make it so you can easily gather interfaces (we'll finally get to the cool stuff!)

Inside, make a little function called void SetViewAngles()

And lets get to work!

Make sure to include mathlib/vector.h!

Okay, your function should look like this:

PHP Code:
    void SetViewAngles()
    {
        
IVEngineClientengClient// make a variable called engClient
        
bool loadEngClient = !!(LOADINTERFACE("engine.dll"VENGINE_CLIENT_INTERFACE_VERSIONengClient)); // get the interface for engClient. You can check if its the interface by opening up engine.dll (/bin/) and then ctrl+f'ing the definition of VENGINE_CLIENT_INTERFACE_VERSION, which is "VEngineClient013" (INTERFACE VERSIONS DIFFER OVER GAMES)
        
        
if (loadEngClient// check if it found the interface
        
{
            
engClient->SetViewAngles(QAngle(505050)); // set the view angles!
        
}
    } 
Congrats! Call that in the entrypoint and your view angles should go wonky!

Quote:
Heres how mine look, lets see what wonky results you can do next!

Well, that covers it. You now can make some metamod plugins!

A few tasks you can do:
Set view angles to go all over the place really fast
Change health
Get some more wacky results! Be creative!

Thanks! And I hope you learnt something!

If theres anything I can add, please tell me
__________________
Love programming!
Add me if you need any help http://steamcommunity.com/id/desslian/
verideth is offline
iamf2p
Member
Join Date: Nov 2018
Old 10-16-2019 , 06:53   Re: Tutorial: Getting started with metamod plugins
Reply With Quote #2

good stuff
iamf2p is offline
Reply


Thread Tools
Display Modes

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 01:58.


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