From 4de731e9008cbf5960a8e337c850cda77f439261 Mon Sep 17 00:00:00 2001 From: Haru Date: Fri, 7 Aug 2015 16:20:12 +0200 Subject: Added HPMHooking support for common interfaces Signed-off-by: Haru --- src/common/HPM.c | 10 +++++++++- src/plugins/HPMHooking.c | 14 ++++++++++++++ tools/HPMHookGen/HPMHookGen.pl | 41 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/common/HPM.c b/src/common/HPM.c index caf0f9471..d82faee1f 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -12,6 +12,7 @@ #include "common/core.h" #include "common/db.h" #include "common/malloc.h" +#include "common/mapindex.h" #include "common/mmo.h" #include "common/showmsg.h" #include "common/socket.h" @@ -767,8 +768,13 @@ void hplugins_share_defaults(void) { HPM->share(&arg_c,"arg_c"); HPM->share(SERVER_NAME,"SERVER_NAME"); HPM->share(&SERVER_TYPE,"SERVER_TYPE"); - HPM->share(DB, "DB"); HPM->share(HPMiMalloc, "iMalloc"); + HPM->share(cmdline,"cmdline"); + /* console */ + HPM->share(console,"console"); + /* db */ + HPM->share(DB, "DB"); + /* nullpo */ HPM->share(nullpo,"nullpo"); /* showmsg */ HPM->share(showmsg,"showmsg"); @@ -786,6 +792,8 @@ void hplugins_share_defaults(void) { HPM->share(libconfig,"libconfig"); /* sysinfo */ HPM->share(sysinfo,"sysinfo"); + /* utils */ + HPM->share(HCache,"HCache"); } void hpm_init(void) { diff --git a/src/plugins/HPMHooking.c b/src/plugins/HPMHooking.c index e15cc363d..68910f503 100644 --- a/src/plugins/HPMHooking.c +++ b/src/plugins/HPMHooking.c @@ -39,6 +39,7 @@ #include "char/loginif.h" #include "char/mapif.h" #include "char/pincode.h" +#include "common/mapindex.h" #elif defined (HPMHOOKING_MAP) #define HPM_SERVER_TYPE SERVER_TYPE_MAP #define HPM_CORE_INCLUDE "HPMHooking/HPMHooking_map.HPMHooksCore.inc" @@ -80,6 +81,7 @@ #include "map/storage.h" #include "map/trade.h" #include "map/unit.h" +#include "common/mapindex.h" #else #define HPM_SERVER_TYPE SERVER_TYPE_UNKNOWN #define HPM_CORE_INCLUDE "HPMHooking/HPMHooking.HPMHooksCore.inc" @@ -89,6 +91,18 @@ #define HPM_SOURCES_INCLUDE "HPMHooking/HPMHooking.sources.inc" #error HPMHooking plugin needs to be compiled for a specific server type. Please make sure your Makefiles are up to date. #endif +#include "common/conf.h" +#include "common/console.h" +#include "common/db.h" +#include "common/malloc.h" +#include "common/nullpo.h" +#include "common/showmsg.h" +#include "common/socket.h" +#include "common/sql.h" +#include "common/strlib.h" +#include "common/sysinfo.h" +#include "common/timer.h" +#include "common/utils.h" #include "common/HPMDataCheck.h" diff --git a/tools/HPMHookGen/HPMHookGen.pl b/tools/HPMHookGen/HPMHookGen.pl index a77b50a3b..0b1df8388 100755 --- a/tools/HPMHookGen/HPMHookGen.pl +++ b/tools/HPMHookGen/HPMHookGen.pl @@ -222,13 +222,20 @@ sub parse($$) { $rtinit = ' = HCS_STATUS_FAIL'; } elsif ($x =~ /^enum\s+bg_queue_types$/) { # Known enum bg_queue_types $rtinit = ' = BGQT_INVALID'; - } elsif ($x =~ /^struct\s+.*$/ or $x eq 'DBData') { # Structs + } elsif ($x =~ /^(?:enum\s+)?DBOptions$/) { # Known enum DBOptions + $rtinit = ' = DB_OPT_BASE'; + } elsif ($x eq 'DBComparator' or $x eq 'DBHasher' or $x eq 'DBReleaser') { # DB function pointers + $rtinit = ' = NULL'; + } elsif ($x =~ /^struct\s+.*$/ or $x eq 'DBData' or $x eq 'DBKey') { # Structs and unions $rtinit = ''; $rtmemset = 1; + } elsif ($x =~ /^float|double$/) { # Floating point variables + $rtinit = ' = 0.'; } elsif ($x =~ /^(?:(?:un)?signed\s+)?(?:char|int|long|short)$/ or $x =~ /^(?:long|short)\s+(?:int|long)$/ or $x =~ /^u?int(?:8|16|32|64)$/ or $x eq 'defType' + or $x eq 'size_t' ) { # Numeric variables $rtinit = ' = 0'; } else { # Anything else @@ -257,6 +264,7 @@ my %keys = ( login => [ ], char => [ ], map => [ ], + common => [ ], ); foreach my $file (@files) { # Loop through the xml files @@ -265,11 +273,19 @@ foreach my $file (@files) { # Loop through the xml files my $filekey = (keys %{ $data->{compounddef} })[0]; my $loc = $data->{compounddef}->{$filekey}->{location}->[0]; - next unless $loc->{file} =~ /src\/(map|char|login)\//; + next unless $loc->{file} =~ /src\/(map|char|login|common)\//; + next if $loc->{file} =~ /\/HPM.*\.h/; # Don't allow hooking into the HPM itself my $servertype = $1; - my $key = $data->{compounddef}->{$filekey}->{compoundname}->[0]; my $original = $key; + my @servertypes = (); + if ($servertype ne "common") { + push @servertypes, $1; + } elsif ($key eq "mapindex_interface") { + push @servertypes, ("map", "char"); # Currently not used by the login server + } else { + push @servertypes, ("map", "char", "login"); + } # Some known interfaces with different names if ($key =~ /battleground/) { @@ -286,8 +302,23 @@ foreach my $file (@files) { # Loop through the xml files $key = "logs"; } elsif ($key eq "pc_groups_interface") { $key = "pcg"; + } elsif ($key eq "pcre_interface") { + $key = "libpcre"; } elsif ($key eq "char_interface") { $key = "chr"; + } elsif ($key eq "db_interface") { + $key = "DB"; + } elsif ($key eq "malloc_interface") { + $key = "iMalloc"; + } elsif ($key eq "socket_interface") { + $key = "sockt"; + } elsif ($key eq "sql_interface") { + $key = "SQL"; + } elsif ($key eq "stringbuf_interface") { + $key = "StrBuf"; + } elsif ($key eq "console_input_interface") { + # TODO + next; } else { $key =~ s/_interface//; } @@ -382,7 +413,9 @@ foreach my $file (@files) { # Loop through the xml files push(@{ $ifs{$key} }, $if); } } - push(@{ $keys{$servertype} }, $key) if $key2original{$key}; + foreach $servertype (@servertypes) { + push(@{ $keys{$servertype} }, $key) if $key2original{$key}; + } } foreach my $servertype (keys %keys) { -- cgit v1.2.3-60-g2f50