AnnieRuru 957 Posted March 11, 2014 http://upaste.me/868111089e57a3d30 there is something funny about this plugin 1. if I uncomment the //#ifdef PCRE_SUPPORT even though I have PCRE compiled, but it always go under the #else statement ... dunno why 2. and the only way to make this work porperly is also uncomment the #ifdef PCRE_SUPPORT inside npc.h !! https://github.com/HerculesWS/Hercules/blob/master/src/map/npc.h#L285 maybe its my compiler problem ? microsoft visual basic 2010 Quote Share this post Link to post Share on other sites
0 AnnieRuru 957 Posted December 11, 2015 after 1 year ++.... https://github.com/HerculesWS/Hercules/issues/909#issuecomment-163911353 finally able to solve this #include "common/hercules.h"#include <stdio.h>#include <string.h>#include <stdlib.h>#include "map/script.h"#include "../3rdparty/pcre/include/pcre.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 = { "regexp", // Plugin name SERVER_TYPE_MAP,// Which server types this plugin works with? "0.1", // Plugin version HPM_VERSION, // HPM Version (don't change, macro is automatically updated)};BUILDIN(regexp) { pcre *re; pcre_extra *pcreExtra; const char *error; int erroffset, r, offset = 0; int subStrVec[30]; const char* pattern = script_getstr(st,2); const char* subject = script_getstr(st,3); if (script_hasdata(st,4)) offset = script_getnum(st,4); re = pcre_compile(pattern, 0, &error, &erroffset, NULL); pcreExtra = pcre_study(re, 0, &error); r = pcre_exec(re, pcreExtra, subject, (int)strlen(subject), offset, 0, subStrVec, 30); pcre_free(re); if (pcreExtra != NULL) pcre_free(pcreExtra); if (r < 0) script_pushint(st,0); else script_pushint(st,(r > 0) ? r : 30 / 3); return true;}HPExport void plugin_init (void) { addScriptCommand( "regexp", "ss?", regexp );}I also edited the wiki to reflect the changehttp://herc.ws/wiki/Building_HPM_Plugin_for_MSVC#PCRE_SUPPORT 1 Angelmelody reacted to this Quote Share this post Link to post Share on other sites
0 Samuel 83 Posted March 11, 2014 http://upaste.me/868111089e57a3d30 there is something funny about this plugin 1. if I uncomment the //#ifdef PCRE_SUPPORT even though I have PCRE compiled, but it always go under the #else statement ... dunno why 2. and the only way to make this work probably is also uncomment the #ifdef PCRE_SUPPORT inside npc.h !! https://github.com/HerculesWS/Hercules/blob/master/src/map/npc.h#L285 maybe its my compiler problem ? microsoft visual basic 2010 Yeah, seems to be windows compiler problem.. This is what I'm experiencing with installing the server side manners plugin by odin.. When I tried to compile the same plugin with linux, it compiled properly but the plugin doesn't load ( but it seems to be the plugin source itself)... Quote Share this post Link to post Share on other sites
0 安赫尔 9 Posted March 11, 2014 I cant compile it In GCC CC regexp.cregexp.c: In function ‘buildin_regexp’:regexp.c:47: error: ‘libpcre’ undeclared (first use in this function)regexp.c:47: error: (Each undeclared identifier is reported only onceregexp.c:47: error: for each function it appears in.)regexp.c: In function ‘plugin_init’:regexp.c:71: error: ‘libpcre’ undeclared (first use in this function)make[1]: *** [../../plugins/regexp.so] Error 1make[1]: Leaving directory `/root/rosfus/trunk/src/plugins'make: *** [plugins] Error 2 In MSVC 2010 1>------ 已启动全部重新生成: 项目: regexp, 配置: Release Win32 ------1>生成启动时间为 2014/3/12 7:19:52。1>InitializeBuildStatus:1> 正在创建“regexpregexp.unsuccessfulbuild”,因为已指定“AlwaysCreate”。1>ClCompile:1> regexp.c1>..srcpluginsregexp.c(47): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(47): error C2223: “->compile”的左侧必须指向结构/联合1>..srcpluginsregexp.c(48): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(48): error C2223: “->study”的左侧必须指向结构/联合1>..srcpluginsregexp.c(50): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(50): error C2223: “->exec”的左侧必须指向结构/联合1>..srcpluginsregexp.c(52): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(52): error C2223: “->free”的左侧必须指向结构/联合1>..srcpluginsregexp.c(54): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(54): error C2223: “->free”的左侧必须指向结构/联合1>..srcpluginsregexp.c(71): error C2065: “libpcre”: 未声明的标识符1>..srcpluginsregexp.c(71): warning C4047: “=”:“int”与“void *”的间接级别不同1>1>生成失败。1>1>已用时间 00:00:03.55========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ========== Quote Share this post Link to post Share on other sites
0 Samuel 83 Posted March 11, 2014 [member=安赫尔] Hmm, did you run ./configure in linux, if yes, did you see if pcre being said yes during the configuration.. Then, when it comes to plugins, i think you need to add this in the makefile when compiling pcre plugins, ../../plugins/pluginname@DLLEXT@: pluginname.c $(ALL_H)@echo " CC $<"@$(CC) -lpcre @DEFS@ @CFLAGS@ @CPPFLAGS@ @LDFLAGS@ @SOFLAGS@ -o $@ $< Quote Share this post Link to post Share on other sites
0 AnnieRuru 957 Posted March 12, 2014 so its not my compiler problem, many member else experiencing this issue seems to me like the pcre are not compatible with plugins @samuel I'm using windows with microsoft visual express so I also try fix odin server side manner http://upaste.me/a7a2110923a939b03 and my compiler throw this error 2>whisp.obj : error LNK2019: unresolved external symbol __imp__pcre_exec referenced in function _filter_chat2>whisp.obj : error LNK2019: unresolved external symbol __imp__pcre_study referenced in function _read_manner2>whisp.obj : error LNK2019: unresolved external symbol __imp__pcre_compile referenced in function _read_manner2>whisp.obj : error LNK2001: unresolved external symbol __imp__pcre_free2>..pluginswhisp.dll : fatal error LNK1120: 4 unresolved externalsthat is the reason I'm actually using libpcre->compile, libpcre->study and so on because it has already defined in npc_chat.chttps://github.com/HerculesWS/Hercules/blob/master/src/map/npc_chat.c#L436 that's why ... @安赫尔 yes, like I said in my 2nd point to make this plugin works, comment the line inside npc.h line 285, change #ifdef PCRE_SUPPORT into //#ifdef PCRE_SUPPORT line 348, change #endif into //#endif then this plugin will work but doing like this will defeat the purpose of making a plugin, because plugin means you don't have to touch the source ? the patch is actually working though http://upaste.me/c4861109339c41185 but not the plugin ... maybe I should do a pull request ... Quote Share this post Link to post Share on other sites
0 Samuel 83 Posted March 12, 2014 Well, this error LNK2019: unresolved external symbol also happens with some source I'm converting into plugin.. It's like that it was already defined in the included source, but plugins can't get it or something.. I remember that I tried to define the unresolved external symbol within the plugin code itself and the warning disappeared.. Quote Share this post Link to post Share on other sites
0 AnnieRuru 957 Posted March 12, 2014 I remember that I tried to define the unresolved external symbol within the plugin code itself and the warning disappeared.. //===== Hercules Plugin ======================================//= *regexp Script Command//===== By: ==================================================//= AnnieRuru//===== Current Version: =====================================//= 1.0//===== Compatible With: ===================================== //= Hercules 2014-03-12//===== Description: =========================================//= check the string match with regular expression//===== Topic ================================================//= none//===== Additional Comments: ================================= //= rip off from rathena *preg_match//============================================================#include <stdio.h>#include <string.h>#include <stdlib.h>#include "../map/npc.h"#include "../map/script.h"#include "../common/HPMi.h"#include "../../3rdparty/pcre/include/pcre.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 = { "regexp", // Plugin name SERVER_TYPE_MAP,// Which server types this plugin works with? "0.1", // Plugin version HPM_VERSION, // HPM Version (don't change, macro is automatically updated)};BUILDIN(regexp) {#ifdef PCRE_SUPPORT pcre *re; pcre_extra *pcreExtra; const char *error; int erroffset, r, offset = 0; int subStrVec[30]; const char* pattern = script_getstr(st,2); const char* subject = script_getstr(st,3); if (script_hasdata(st,4)) offset = script_getnum(st,4); re = libpcre->compile(pattern, 0, &error, &erroffset, NULL); pcreExtra = libpcre->study(re, 0, &error); r = libpcre->exec(re, pcreExtra, subject, (int)strlen(subject), offset, 0, subStrVec, 30); libpcre->free(re); if (pcreExtra != NULL) libpcre->free(pcreExtra); if (r < 0) script_pushint(st,0); else script_pushint(st,(r > 0) ? r : 30 / 3); return true;#else ShowError( "buildin_regexp: Cannot run because PCRE library are disabled.n" ); script_pushint(st,0); return false;#endif}HPExport void plugin_init (void) {#ifdef PCRE_SUPPORT script = GET_SYMBOL("script"); libpcre = GET_SYMBOL("libpcre"); addScriptCommand( "regexp", "ss?", regexp );#else ShowError( "buildin_regexp: Cannot run because PCRE library are disabled.n" );#endif}yeah ... yeah ... the error disappearedbut you also get the ShowError warning saying that it is disabled Quote Share this post Link to post Share on other sites
0 Samuel 83 Posted March 12, 2014 Well seems to be a limitation for the plugin system as of now.. Although I hope there would be great updates with it, Quote Share this post Link to post Share on other sites
0 Dastgir 1246 Posted December 11, 2015 after 1 year ++....https://github.com/HerculesWS/Hercules/issues/909#issuecomment-163911353finally able to solve this #include "common/hercules.h"#include <stdio.h>#include <string.h>#include <stdlib.h>#include "map/script.h"#include "../3rdparty/pcre/include/pcre.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 = { "regexp", // Plugin name SERVER_TYPE_MAP,// Which server types this plugin works with? "0.1", // Plugin version HPM_VERSION, // HPM Version (don't change, macro is automatically updated)};BUILDIN(regexp) { pcre *re; pcre_extra *pcreExtra; const char *error; int erroffset, r, offset = 0; int subStrVec[30]; const char* pattern = script_getstr(st,2); const char* subject = script_getstr(st,3); if (script_hasdata(st,4)) offset = script_getnum(st,4); re = pcre_compile(pattern, 0, &error, &erroffset, NULL); pcreExtra = pcre_study(re, 0, &error); r = pcre_exec(re, pcreExtra, subject, (int)strlen(subject), offset, 0, subStrVec, 30); pcre_free(re); if (pcreExtra != NULL) pcre_free(pcreExtra); if (r < 0) script_pushint(st,0); else script_pushint(st,(r > 0) ? r : 30 / 3); return true;}HPExport void plugin_init (void) { addScriptCommand( "regexp", "ss?", regexp );}I also edited the wiki to reflect the changehttp://herc.ws/wiki/Building_HPM_Plugin_for_MSVC#PCRE_SUPPORT For Linux: http://upaste.me/2220e2^ this change is required. Quote Share this post Link to post Share on other sites
0 AnnieRuru 957 Posted December 11, 2015 @@Dastgir do that in the wiki ... its useless to tell in the topic because not everyone will read this, but everyone in the wiki will see what you posted Quote Share this post Link to post Share on other sites
0 hemagx 69 Posted December 11, 2015 @@AnnieRuru you have to know it's not solution, and temporary fix till Haroun fix the current issue with HPMHookGen. Quote Share this post Link to post Share on other sites
0 Dastgir 1246 Posted December 11, 2015 @@Dastgir do that in the wiki ... its useless to tell in the topic because not everyone will read this, but everyone in the wiki will see what you posted As hemagx said, This is temporary solution, till HpmHook is fixed. Quote Share this post Link to post Share on other sites
0 AnnieRuru 957 Posted December 11, 2015 (edited) oh thanks for the yellbox ... I was just about to edit the title though ok time to try out the command prontera,159,183,5 script pcre_match 1_F_MARIA,{ input .@t$; if ( "([a-z])$" ~= .@t$ ) npctalk "It's a "+ $@regexmatch$[0]; close;L_1: npctalk "It's a "+ $@p2$; end;OnInit: defpattern 1, "^[^:]+: (|d{2})?([a-z]).$", "L_1"; activatepset 1; end;}prontera,155,183,5 script regexp 1_F_MARIA,{ input .@t$; if ( regexp("([a-z])$", .@t$ ) ) npctalk "It's a ... "; close;} Haru's regular expression ...this is bug ... why that only accept a,z,- ... three characters only regexp in this plugin is accurate, can accept anything between abcde...z but cannot export the result set the symbol for the end line, has to be $ defpattern ... works great as many members already using it but the symbol for the end line, has to be .$ omg, so many patterns ! Edited December 11, 2015 by AnnieRuru 1 Neffletics reacted to this Quote Share this post Link to post Share on other sites
0 Neffletics 9 Posted May 10, 2020 Thank you, Annie! I found more details on your blog. ~ Quote Share this post Link to post Share on other sites
http://upaste.me/868111089e57a3d30
there is something funny about this plugin
1.
if I uncomment the //#ifdef PCRE_SUPPORT
even though I have PCRE compiled, but it always go under the #else statement ... dunno why
2.
and the only way to make this work porperly is also
uncomment the #ifdef PCRE_SUPPORT inside npc.h !!
https://github.com/HerculesWS/Hercules/blob/master/src/map/npc.h#L285
maybe its my compiler problem ? microsoft visual basic 2010
Share this post
Link to post
Share on other sites