Difference between revisions of "Building HPM Plugin for MSVC"

From Hercules Wiki
Jump to: navigation, search
(Change step by step into sub-header, and add support of PCRE_SUPPORT interface)
m (forgot to include pcre.h)
Line 139: Line 139:
 
Under '''Configuration Properties''' click '''Linker''' and open '''General''', On '''Additional Library Directory''', Add '''..\3rdparty\pcre\lib;'''
 
Under '''Configuration Properties''' click '''Linker''' and open '''General''', On '''Additional Library Directory''', Add '''..\3rdparty\pcre\lib;'''
 
[[File:Pcre support step2.png|center|750px]]
 
[[File:Pcre support step2.png|center|750px]]
 +
=== Step 3 ===
 +
And don't forget to include pcre.h in your plugin
 +
#include "../3rdparty/pcre/include/pcre.h"
  
 
= Notes =
 
= Notes =

Revision as of 14:42, 11 December 2015

Contents

Guide

This is a guide on how to prepare your MSVC environment for a new HPM plugin.

Installation

Step 1

Go to src/plugins/ folder, create a new .c file, e.g. dance.c (this name will be used throughout this guide)

Step1.JPG

Step 2

Open dance.c and paste this code

#include <stdio.h>
#include <string.h>
#include "../common/HPMi.h"
#include "../map/script.h"
#include "../map/pc.h"

#include "../common/HPMDataCheck.h"    //Should always be the last include file.

HPExport struct hplugin_info pinfo =
{
    "@dance",		// Plugin name
    SERVER_TYPE_MAP,// Which server types this plugin works with?
    "0.1a",			// Plugin version
    HPM_VERSION,	// HPM Version (don't change, macro is automatically updated)
};

ACMD(dance)
{


      if (!message || !*message) {
		  clif->message(fd, "usage: @dance 1-9");
return -1;
   }
   if ( atoi(message) == 1 ) {
clif->specialeffect(&sd->bl, 413, ALL_CLIENT);
   } else if ( atoi(message) == 2 ) {
clif->specialeffect(&sd->bl, 414, ALL_CLIENT);
   } else if ( atoi(message) == 3 ) {
clif->specialeffect(&sd->bl, 415, ALL_CLIENT);
   } else if ( atoi(message) == 4 ) {
clif->specialeffect(&sd->bl, 426, ALL_CLIENT);
   } else if ( atoi(message) == 5 ) {
clif->specialeffect(&sd->bl, 458, ALL_CLIENT);
   } else if ( atoi(message) == 6 ) {
clif->specialeffect(&sd->bl, 466, ALL_CLIENT);
   } else if ( atoi(message) == 7 ) {
clif->specialeffect(&sd->bl, 501, ALL_CLIENT);
   } else if ( atoi(message) == 8 ) {
clif->specialeffect(&sd->bl, 540, ALL_CLIENT);
   } else if ( atoi(message) == 9 ) {
clif->specialeffect(&sd->bl, 550, ALL_CLIENT);
   }
	else
	{
	clif->message(fd, "usage: @dance 1-9"); 
	}
   return true;
}

/* Server Startup */
HPExport void plugin_init (void)
{
    clif = GET_SYMBOL("clif");
    script = GET_SYMBOL("script");
    skill = GET_SYMBOL("skill");

    addAtcommand("dance",dance);
}

Step 3

Open your MSVC project (e.g. 'Hercules-10.sln)

Step2.JPG

Step 4

Go to the Solution Explorer

Step3.JPG

Step 5

Right click the Hercules project (first item in Solution Explorer), and click Add->New Project

Step4.JPG

Step 6

Select General, and pick Empty Project.

Step5.JPG

Step 7

Enter the name of your plugin in the Name field, and click OK.

Step 8

In the solution explorer it'll display the new project.

Step6.JPG

Step 9

Right click the new project, and open Add->Existing Item

Step7.JPG

Step 10

Browse to src/plugins/ and select the dance.c file, and hit OK.

Step8.JPG

Step 11

It will place the dance.c file under the Source Files folder, drag it to the project you created and drop it (in a manner it be placed out of the source files folder.)

Step9.JPG

(It should look like the image below)

Step10.JPG

Step 12

With the dance.c out of the folders, delete the 3 of them (select the 3, hit delete, hit ok)

Step11.JPG

(It should look like the image below)

Step12.JPG

Step 13

Right click the project you created, open Properties

Step13.JPG

Step 14

Under Configuration Properties click General, change Output Directory to ..\plugins\, Intermediate Directory to $(ProjectName)\$(ConfigurationName)\ and Configuration Type to Dynamic Library (.dll)

Step14.JPG

Step 15

Under Configuration Properties click C/C++ and open General, change Additional Include Directories to ..\src;..\3rdparty;..\3rdparty\msinttypes\include;%(AdditionalIncludeDirectories)

Step15.JPG

Step 16

Under Configuration Properties click Linker and open General, change Output File to $(OutDir)\$(ProjectName).dll

Step16.JPG

Step 17

Under Configuration Properties click C/C++ and open Preprocessor, change Preprocessor Definitions to _WINDLL;PCRE_SUPPORT;%(PreprocessorDefinitions)

Step17.jpg

Step 18

Add your code to the dance.c file, and then right-click the project you created, and select Build

Step 19

Add it to /conf/plugins.conf

plugins_list: [
	/* Enable HPMHooking when plugins in use rely on Hooking */
	//"HPMHooking",
	//"db2sql",
	//"sample",
	//"other",
	"dance", // loads dance plugin
]

PCRE_SUPPORT

Although previously on step-17 has included PCRE_SUPPORT, but it was just to prevent the error message on map-server if the plugin has included npc.h. To properly make use of the PCRE interface, there are 2 additional steps.

Step 1

Under Configuration Properties click Linker and open Input, On Additional Dependencies, Add pcre.lib; at the beginning.

Pcre support step1.png

Step 2

Under Configuration Properties click Linker and open General, On Additional Library Directory, Add ..\3rdparty\pcre\lib;

Pcre support step2.png

Step 3

And don't forget to include pcre.h in your plugin

#include "../3rdparty/pcre/include/pcre.h"

Notes

  • This guide is probably the worst I've ever written, if you can do better please hit the 'Edit' button, will be most welcome. - Ind
  • I used MSVC 2008 when testing this guide.

New Note

  • Sorry for editing this page, I added step by step images for other people to follow so they can easily follow one of the best feature Hercules have, the HPM. - Thanna
  • The tutorial is tested on MSVC 2010.
  • Add additional steps for PCRE_SUPPORT, credit to hemagx for the info, which he claimed that came from Haru