summaryrefslogtreecommitdiff
path: root/tools/HPMHookGen/HPMHookGen.pl
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-06-15 20:52:44 +0200
committerHaru <haru@dotalux.com>2015-08-15 00:51:42 +0200
commit51b7adcf4e5b2a347081ec9a6903102c4909a404 (patch)
tree39a080440b4bd78b786c8f9372f7883b55fd3ba9 /tools/HPMHookGen/HPMHookGen.pl
parentf8edb93a6a26cd81eeaad0eac23e33da7740c8b4 (diff)
downloadhercules-51b7adcf4e5b2a347081ec9a6903102c4909a404.tar.gz
hercules-51b7adcf4e5b2a347081ec9a6903102c4909a404.tar.bz2
hercules-51b7adcf4e5b2a347081ec9a6903102c4909a404.tar.xz
hercules-51b7adcf4e5b2a347081ec9a6903102c4909a404.zip
HPM compatibility improvements
Improved compatibility, portability and standards conformance. - Since it is not possible to portably and reliably re-use the core's symbols in plugins, symbols are no longer exported unless explicitly required, in the UNIX builds. This mimics the Windows behavior and adds HPM compatibility to OSes such as FreeBSD. Credits to Andrei Karas for making this possible. - For convenience, it is no longer necessary to call GET_SYMBOL, since the plugin will automatically import all the available symbols when it's loaded, depending on the included headers. - Plugins are now supposed to include the "common/hercules.h" header before including anything else. Incluing common/HPMi.h, common/cbasetypes.h or conf/core.h is no longer necessary, as those are guaranteed to be automatically included by hercules.h. - HPM API version bumped to 1.1. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'tools/HPMHookGen/HPMHookGen.pl')
-rwxr-xr-xtools/HPMHookGen/HPMHookGen.pl91
1 files changed, 65 insertions, 26 deletions
diff --git a/tools/HPMHookGen/HPMHookGen.pl b/tools/HPMHookGen/HPMHookGen.pl
index 0b1df8388..d1b96efb3 100755
--- a/tools/HPMHookGen/HPMHookGen.pl
+++ b/tools/HPMHookGen/HPMHookGen.pl
@@ -264,8 +264,9 @@ my %keys = (
login => [ ],
char => [ ],
map => [ ],
- common => [ ],
+ all => [ ],
);
+my %fileguards = ( );
foreach my $file (@files) { # Loop through the xml files
my $xml = new XML::Simple;
@@ -279,22 +280,28 @@ foreach my $file (@files) { # Loop through the xml files
my $key = $data->{compounddef}->{$filekey}->{compoundname}->[0];
my $original = $key;
my @servertypes = ();
+ my $servermask = 'SERVER_TYPE_NONE';
if ($servertype ne "common") {
push @servertypes, $1;
+ $servermask = 'SERVER_TYPE_' . uc($1);
} elsif ($key eq "mapindex_interface") {
push @servertypes, ("map", "char"); # Currently not used by the login server
+ $servermask = 'SERVER_TYPE_MAP|SERVER_TYPE_CHAR';
} else {
push @servertypes, ("map", "char", "login");
+ $servermask = 'SERVER_TYPE_ALL';
}
+ my @filepath = split(/[\/\\]/, $loc->{file});
+ my $foldername = uc($filepath[-2]);
+ my $filename = uc($filepath[-1]); $filename =~ s/-/_/g; $filename =~ s/\.[^.]*$//;
+ my $guardname = "${foldername}_${filename}_H";
# Some known interfaces with different names
if ($key =~ /battleground/) {
$key = "bg";
} elsif ($key =~ /guild_storage/) {
$key = "gstorage";
- } elsif ($key =~ /inter_homunculus/) { # to avoid replace to homun
- $key = "inter_homunculus";
- } elsif ($key =~ /homunculus/) {
+ } elsif ($key eq "homunculus_interface") {
$key = "homun";
} elsif ($key eq "irc_bot_interface") {
$key = "ircbot";
@@ -416,6 +423,11 @@ foreach my $file (@files) { # Loop through the xml files
foreach $servertype (@servertypes) {
push(@{ $keys{$servertype} }, $key) if $key2original{$key};
}
+ push(@{ $keys{all} }, $key) if $key2original{$key};
+ $fileguards{$key} = {
+ guard => $guardname,
+ type => $servermask,
+ };
}
foreach my $servertype (keys %keys) {
@@ -423,14 +435,61 @@ foreach my $servertype (keys %keys) {
# Some interfaces use different names
my %exportsymbols = map {
$_ => &{ sub ($) {
- return 'battlegrounds' if $servertype eq 'map' and $_ =~ /^bg$/;
- return 'pc_groups' if $servertype eq 'map' and $_ =~ /^pcg$/;
+ return 'battlegrounds' if $_ =~ /^bg$/;
+ return 'pc_groups' if $_ =~ /^pcg$/;
return $_;
}}($_);
} @$keysref;
my ($maxlen, $idx) = (0, 0);
my $fname;
+
+ if ($servertype eq 'all') {
+ $fname = "../../src/common/HPMSymbols.inc.h";
+ open(FH, ">", $fname)
+ or die "cannot open > $fname: $!";
+
+ print FH <<"EOF";
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+//
+// NOTE: This file was auto-generated and should never be manually edited,
+// as it will get overwritten.
+
+#if !defined(HERCULES_CORE)
+EOF
+
+ foreach my $key (@$keysref) {
+ print FH <<"EOF";
+#ifdef $fileguards{$key}->{guard} /* $key */
+struct $key2original{$key} *$key;
+#endif // $fileguards{$key}->{guard}
+EOF
+ }
+
+ print FH <<"EOF";
+#endif // ! HERCULES_CORE
+
+HPExport const char *HPM_shared_symbols(int server_type)
+{
+EOF
+
+ foreach my $key (@$keysref) {
+ print FH <<"EOF";
+#ifdef $fileguards{$key}->{guard} /* $key */
+if ((server_type&($fileguards{$key}->{type})) && !HPM_SYMBOL("$exportsymbols{$key}", $key)) return "$exportsymbols{$key}";
+#endif // $fileguards{$key}->{guard}
+EOF
+ }
+
+ print FH <<"EOF";
+ return NULL;
+}
+EOF
+ close FH;
+ next;
+ }
+
$fname = "../../src/plugins/HPMHooking/HPMHooking_${servertype}.HookingPoints.inc";
open(FH, ">", $fname)
or die "cannot open > $fname: $!";
@@ -484,26 +543,6 @@ EOF
}
close FH;
- $fname = "../../src/plugins/HPMHooking/HPMHooking_${servertype}.GetSymbol.inc";
- open(FH, ">", $fname)
- or die "cannot open > $fname: $!";
-
- print FH <<"EOF";
-// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
-// See the LICENSE file
-//
-// NOTE: This file was auto-generated and should never be manually edited,
-// as it will get overwritten.
-
-EOF
- foreach my $key (@$keysref) {
-
- print FH <<"EOF";
-if( !($key = GET_SYMBOL("$exportsymbols{$key}") ) ) return "$exportsymbols{$key}";
-EOF
- }
- close FH;
-
$fname = "../../src/plugins/HPMHooking/HPMHooking_${servertype}.HPMHooksCore.inc";
open(FH, ">", $fname)
or die "cannot open > $fname: $!";