Difference between revisions of "Building HPM Plugin for MSVC"

From Hercules Wiki
Jump to: navigation, search
(Guide)
m (dunno why it doesn't work ... I even deleted the old one already, and yet it still shows up ?)
 
(22 intermediate revisions by 5 users not shown)
Line 1: Line 1:
This is a guide on how to prepare your MSVC environment for a new [[HPM]] plugin.
 
 
= Guide =
 
= Guide =
1. Go to '''src/plugins/''' folder, create a new '''.c''' file, e.g. '''dance.c''' (this name will be used throughout this guide)
+
There are 2 guides on how to prepare your MSVC environment for a new [[HPM]] plugin. You can choose to follow either one.
 +
== New Method ==
 +
=== Step 1 ===
 +
Download the '''YourProject.c''' file in the '''\src\plugins\''' folder
 +
[[File:MSVC step0.png|center|750px]]
 +
=== Step 2 ===
 +
If using MSVC 2010, navigate to \vcproj-10\
 +
[[File:MSVC step1.png|center|750px]]
 +
=== Step 3 ===
 +
Select '''plugin-sample.vcxproj''', copy paste it
 +
[[File:MSVC step2.png|center|750px]]
 +
=== Step 4 ===
 +
Rename '''plugin-sample - Copy.vcxproj''' into '''YourProject.vcxproj'''<br>
 +
While renaming, Highlight the word '''YourProject''' and Copy it by ''Ctrl+C''
 +
[[File:MSVC step3.png|center|750px]]
 +
=== Step 5 ===
 +
Right-Click on '''YourFile.vcxproj''', Select '''Edit with Notepad++''', or Microsoft Notepad
 +
[[File:MSVC step4.png|center|750px]]
 +
=== Step 6 ===
 +
Find this line
 +
<ProjectName>plugin-sample</ProjectName>
 +
[[File:MSVC step5.png|center|750px]]
 +
Rename '''plugin-sample''' to '''YourProject''' by ''Ctrl+V''
 +
[[File:MSVC step5 .png|center|750px]]
 +
=== Step 7 ===
 +
Find this line
 +
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">sample</TargetName>
 +
[[File:MSVC step6.png|center|750px]]
 +
Rename '''sample''' to '''YourProject''' by ''Ctrl+V''
 +
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">YourProject</TargetName>
 +
[[File:MSVC step6 .png|center|750px]]
 +
=== Step 8 ===
 +
Find this line
 +
<ClCompile Include="..\src\plugins\sample.c" />
 +
[[File:MSVC step7.png|center|750px]]
 +
Rename '''sample''' to '''YourProject''' by ''Ctrl+V''
 +
[[File:MSVC step7 .png|center|750px]]
 +
=== Step 9 ===
 +
Press '''Ctrl+S''' to save the file.
 +
=== Step 10 ===
 +
Open MSVC, Right-click '''Hercules-10''', Select '''Add'' -> '''Existing Project...'''
 +
[[File:MSVC step9.png|center|750px]]
 +
=== Step 11 ===
 +
Select '''YourProject.vcxproj''' in the '''\vcproj-10\''' folder
 +
[[File:MSVC step10.png|center|600px]]
 +
=== Step 12 ===
 +
Right-click '''Hercules-10''', Select '''Build-Solution'''
 +
[[File:MSVC step11.png|center|600px]]
 +
== Old Method ==
 +
=== Step 1 ===
 +
Go to '''src/plugins/''' folder, create a new '''.c''' file, e.g. '''dance.c''' (this name will be used throughout this guide)
 
[[File:step1.JPG|center|750px]]
 
[[File:step1.JPG|center|750px]]
2. Open dance.c and paste this code
+
=== Step 2 ===
 
+
Open dance.c and paste this code
 
<pre>
 
<pre>
 +
#include "common/hercules.h" // Should always be the first Hercules file included! (if you don't make it first, you won't be able to use interfaces)
 
#include <stdio.h>
 
#include <stdio.h>
 
#include <string.h>
 
#include <string.h>
#include "../common/HPMi.h"
+
#include "common/HPMi.h"
#include "../map/script.h"
+
#include "map/script.h"
#include "../map/pc.h"
+
#include "map/pc.h"
 +
#include "common/HPMDataCheck.h" // should always be the last file included! (if you don't make it last, it'll intentionally break compile time)
  
HPExport struct hplugin_info pinfo =
+
HPExport struct hplugin_info pinfo = {
{
+
"dance", // Plugin name
    "@dance", // Plugin name
+
SERVER_TYPE_MAP,// Which server types this plugin works with?
    SERVER_TYPE_MAP,// Which server types this plugin works with?
+
"0.2", // Plugin version
    "0.1a", // Plugin version
+
HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
    HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
+
 
};
 
};
  
ACMD(dance)
+
ACMD(dance) {
{
+
if (!message || !*message) {
 
+
clif->message(fd, "usage: @dance 1-9");
 
+
return -1;
      if (!message || !*message) {
+
}
  clif->message(fd, "usage: @dance 1-9");
+
if ( atoi(message) == 1 ) {
return -1;
+
clif->specialeffect(&sd->bl, 413, ALL_CLIENT);
  }
+
} else if ( atoi(message) == 2 ) {
  if ( atoi(message) == 1 ) {
+
clif->specialeffect(&sd->bl, 414, ALL_CLIENT);
clif->specialeffect(&sd->bl, 413, ALL_CLIENT);
+
} else if ( atoi(message) == 3 ) {
  } else if ( atoi(message) == 2 ) {
+
clif->specialeffect(&sd->bl, 415, ALL_CLIENT);
clif->specialeffect(&sd->bl, 414, ALL_CLIENT);
+
} else if ( atoi(message) == 4 ) {
  } else if ( atoi(message) == 3 ) {
+
clif->specialeffect(&sd->bl, 426, ALL_CLIENT);
clif->specialeffect(&sd->bl, 415, ALL_CLIENT);
+
} else if ( atoi(message) == 5 ) {
  } else if ( atoi(message) == 4 ) {
+
clif->specialeffect(&sd->bl, 458, ALL_CLIENT);
clif->specialeffect(&sd->bl, 426, ALL_CLIENT);
+
} else if ( atoi(message) == 6 ) {
  } else if ( atoi(message) == 5 ) {
+
clif->specialeffect(&sd->bl, 466, ALL_CLIENT);
clif->specialeffect(&sd->bl, 458, ALL_CLIENT);
+
} else if ( atoi(message) == 7 ) {
  } else if ( atoi(message) == 6 ) {
+
clif->specialeffect(&sd->bl, 501, ALL_CLIENT);
clif->specialeffect(&sd->bl, 466, ALL_CLIENT);
+
} else if ( atoi(message) == 8 ) {
  } else if ( atoi(message) == 7 ) {
+
clif->specialeffect(&sd->bl, 540, ALL_CLIENT);
clif->specialeffect(&sd->bl, 501, ALL_CLIENT);
+
} else if ( atoi(message) == 9 ) {
  } else if ( atoi(message) == 8 ) {
+
clif->specialeffect(&sd->bl, 550, ALL_CLIENT);
clif->specialeffect(&sd->bl, 540, ALL_CLIENT);
+
} else {
  } else if ( atoi(message) == 9 ) {
+
clif->message(fd, "usage: @dance 1-9");  
clif->specialeffect(&sd->bl, 550, ALL_CLIENT);
+
  }
+
else
+
{
+
clif->message(fd, "usage: @dance 1-9");  
+
 
}
 
}
  return true;
+
return true;
 
}
 
}
  
 
/* Server Startup */
 
/* Server Startup */
HPExport void plugin_init (void)
+
HPExport void plugin_init (void) {
{
+
addAtcommand("dance",dance);
    clif = GET_SYMBOL("clif");
+
    script = GET_SYMBOL("script");
+
    skill = GET_SYMBOL("skill");
+
 
+
    addAtcommand("dance",dance);
+
 
}
 
}
 
</pre>
 
</pre>
3. Open your MSVC project (e.g. '''Hercules-10.sln'')
+
 
 +
=== Step 3 ===
 +
Open your MSVC project (e.g. '''Hercules-10.sln'')
 
[[File:step2.JPG|center|750px]]
 
[[File:step2.JPG|center|750px]]
4. Go to the '''Solution Explorer'''
+
=== Step 4 ===
 +
Go to the '''Solution Explorer'''
 
[[File:step3.JPG|center|750px]]
 
[[File:step3.JPG|center|750px]]
5. Right click the Hercules project (first item in '''Solution Explorer'''), and click '''Add->New Project'''
+
=== Step 5 ===
 +
Right click the Hercules project (first item in '''Solution Explorer'''), and click '''Add->New Project'''
 
[[File:step4.JPG|center|750px]]
 
[[File:step4.JPG|center|750px]]
6. Select '''General''', and pick '''Empty Project'''.
+
=== Step 6 ===
 +
Select '''General''', and pick '''Empty Project'''.
 
[[File:step5.JPG|center|750px]]
 
[[File:step5.JPG|center|750px]]
7. Enter the name of your plugin in the '''Name''' field, and click OK.<br />
+
=== Step 7 ===
 
+
Enter the name of your plugin in the '''Name''' field, and click OK.
8. In the solution explorer it'll display the new project.
+
=== Step 8 ===
 +
In the solution explorer it'll display the new project.
 
[[File:step6.JPG|center|750px]]
 
[[File:step6.JPG|center|750px]]
9. Right click the new project, and open '''Add->Existing Item'''
+
=== Step 9 ===
 +
Right click the new project, and open '''Add->Existing Item'''
 
[[File:step7.JPG|center|750px]]
 
[[File:step7.JPG|center|750px]]
10. Browse to '''src/plugins/''' and select the '''dance.c''' file, and hit OK.
+
=== Step 10 ===
 +
Browse to '''src/plugins/''' and select the '''dance.c''' file, and hit OK.
 
[[File:step8.JPG|center|750px]]
 
[[File:step8.JPG|center|750px]]
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.)
+
=== 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.)
 
[[File:step9.JPG|center|750px]]
 
[[File:step9.JPG|center|750px]]
 
(It should look like the image below)
 
(It should look like the image below)
 
[[File:step10.JPG|center|750px]]
 
[[File:step10.JPG|center|750px]]
12. With the '''dance.c''' out of the folders, delete the 3 of them (select the 3, hit delete, hit ok)
+
=== Step 12 ===
 +
With the '''dance.c''' out of the folders, delete the 3 of them (select the 3, hit delete, hit ok)
 
[[File:step11.JPG|center|750px]]
 
[[File:step11.JPG|center|750px]]
 
(It should look like the image below)
 
(It should look like the image below)
 
[[File:step12.JPG|center|750px]]
 
[[File:step12.JPG|center|750px]]
13. Right click the project you created, open '''Properties'''
+
=== Step 13 ===
 +
Right click the project you created, open '''Properties'''
 
[[File:step13.JPG|center|750px]]
 
[[File:step13.JPG|center|750px]]
14. Under '''Configuration Properties''' click '''General''', change '''Output Directory''' to '''..\plugins''', '''Intermediate Directory''' to '''$(ProjectName)\$(ConfigurationName)''' and  '''Configuration Type''' to '''Dynamic Library (.dll)'''
+
=== Step 14 ===
 +
Under '''Configuration Properties''' click '''General''', change '''Output Directory''' to '''..\plugins\''', '''Intermediate Directory''' to '''$(ProjectName)\$(ConfigurationName)\''' and  '''Configuration Type''' to '''Dynamic Library (.dll)'''
 
[[File:step14.JPG|center|750px]]
 
[[File:step14.JPG|center|750px]]
15. Under '''Configuration Properties''' click '''C/C++''' and open '''General''', change '''Additional Include Directories''' to '''..\src\common;..\3rdparty\msinttypes\include'''
+
=== Step 15 ===
 +
Under '''Configuration Properties''' click '''C/C++''' and open '''General''', change '''Additional Include Directories''' to '''..\src;..\3rdparty;..\3rdparty\msinttypes\include;%(AdditionalIncludeDirectories)'''
 
[[File:step15.JPG|center|750px]]
 
[[File:step15.JPG|center|750px]]
16. Under '''Configuration Properties''' click '''Linker''' and open '''General''', change '''Output File''' to '''$(OutDir)\dance.dll''' (change dance.dll with your actual name, if you used a different one)
+
=== Step 16 ===
 +
Under '''Configuration Properties''' click '''Linker''' and open '''General''', change '''Output File''' to '''$(OutDir)\$(ProjectName).dll'''
 
[[File:step16.JPG|center|750px]]
 
[[File:step16.JPG|center|750px]]
17. Add your code to the '''dance.c''' file, and then right-click the project you created, and select '''Build'''
+
=== Step 17 ===
 
+
Under '''Configuration Properties''' click '''C/C++''' and open '''Preprocessor''', change '''Preprocessor Definitions''' to '''_WINDLL;PCRE_SUPPORT;%(PreprocessorDefinitions)'''
 
+
[[File:step17.jpg|center|750px]]
18. Add it to ''' /conf/plugins.conf'''
+
=== Step 18 ===
 +
Under '''Configuration Properties''' click '''C/C++''' and open '''Advanced''', on '''Disable Specific Warnings''' add '''4996;%(DisableSpecificWarnings)'''
 +
<br>This step can prevent errors like ''sscanf'' or ''sprintf'' that only happen with Microsoft compiler.
 +
[[File:step18.png|center|750px]]
  
 +
=== Step 19 ===
 +
Add your code to the '''dance.c''' file, and then right-click the project you created, and select '''Build'''
 +
=== Step 20 ===
 +
Add it to ''' /conf/plugins.conf'''
 
<pre>
 
<pre>
 
plugins_list: [
 
plugins_list: [
Line 108: Line 169:
 
//"sample",
 
//"sample",
 
//"other",
 
//"other",
"dance", // dance.c
+
"dance", // loads dance plugin
 
]
 
]
 
</pre>
 
</pre>
Line 119: Line 180:
 
* 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
 
* 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.
 
* The tutorial is tested on MSVC 2010.
 +
* Another method idea by hemagx, sorry for publish it first - AnnieRuru.
  
 
[[Category:Installation]]
 
[[Category:Installation]]

Latest revision as of 12:35, 20 December 2015

Contents

Guide

There are 2 guides on how to prepare your MSVC environment for a new HPM plugin. You can choose to follow either one.

New Method

Step 1

Download the YourProject.c file in the \src\plugins\ folder

MSVC step0.png

Step 2

If using MSVC 2010, navigate to \vcproj-10\

MSVC step1.png

Step 3

Select plugin-sample.vcxproj, copy paste it

MSVC step2.png

Step 4

Rename plugin-sample - Copy.vcxproj into YourProject.vcxproj
While renaming, Highlight the word YourProject and Copy it by Ctrl+C

MSVC step3.png

Step 5

Right-Click on YourFile.vcxproj, Select Edit with Notepad++, or Microsoft Notepad

MSVC step4.png

Step 6

Find this line

<ProjectName>plugin-sample</ProjectName>
MSVC step5.png

Rename plugin-sample to YourProject by Ctrl+V

MSVC step5 .png

Step 7

Find this line

<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">sample</TargetName>
MSVC step6.png

Rename sample to YourProject by Ctrl+V

<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">YourProject</TargetName>
MSVC step6 .png

Step 8

Find this line

<ClCompile Include="..\src\plugins\sample.c" />
MSVC step7.png

Rename sample to YourProject by Ctrl+V

MSVC step7 .png

Step 9

Press Ctrl+S to save the file.

Step 10

Open MSVC, Right-click Hercules-10', Select Add -> Existing Project...

MSVC step9.png

Step 11

Select YourProject.vcxproj in the \vcproj-10\ folder

MSVC step10.png

Step 12

Right-click Hercules-10, Select Build-Solution

MSVC step11.png

Old Method

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 "common/hercules.h" // Should always be the first Hercules file included! (if you don't make it first, you won't be able to use interfaces)
#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 file included! (if you don't make it last, it'll intentionally break compile time)

HPExport struct hplugin_info pinfo = {
	"dance",		// Plugin name
	SERVER_TYPE_MAP,// Which server types this plugin works with?
	"0.2",			// 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) {
	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

Under Configuration Properties click C/C++ and open Advanced, on Disable Specific Warnings add 4996;%(DisableSpecificWarnings)
This step can prevent errors like sscanf or sprintf that only happen with Microsoft compiler.

Step18.png

Step 19

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

Step 20

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
]

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.
  • Another method idea by hemagx, sorry for publish it first - AnnieRuru.