summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/HPMHookGen/HPMDataCheckGen.pl68
-rwxr-xr-xtools/HPMHookGen/HPMHookGen.pl11
-rw-r--r--tools/HPMHookGen/Makefile.in30
-rw-r--r--tools/HPMHookGen/doxygen.conf35
-rw-r--r--tools/Script-Checker.applescript151
-rwxr-xr-xtools/itemdbconverter.pl195
6 files changed, 443 insertions, 47 deletions
diff --git a/tools/HPMHookGen/HPMDataCheckGen.pl b/tools/HPMHookGen/HPMDataCheckGen.pl
new file mode 100644
index 000000000..a79811c47
--- /dev/null
+++ b/tools/HPMHookGen/HPMDataCheckGen.pl
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+
+# Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+# See the LICENSE file
+
+use strict;
+use warnings;
+use XML::Simple;
+
+# XML Parser hint (some are faster than others)
+#local $ENV{XML_SIMPLE_PREFERRED_PARSER} = ''; # 0m14.181s
+local $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::Parser'; # 0m4.256s
+#local $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::SAX::Expat'; # 0m14.186s
+#local $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::LibXML::SAX'; # 0m7.055s
+
+my @files = grep { -f } grep { /[^h]\.xml/ } glob 'doxyoutput/xml/struct*.xml';
+my %out;
+
+foreach my $file (@files) {
+ my $xml = new XML::Simple;
+ my $data = $xml->XMLin($file);
+ next unless $data->{compounddef}->{includes}; # means its a struct from a .c file, plugins cant access those so we don't care.
+ next if $data->{compounddef}->{compoundname} =~ /::/; # its a duplicate with a :: name e.g. struct script_state {<...>} ay;
+ my @filepath = split(/[\/\\]/, $data->{compounddef}->{location}->{file});
+ my $foldername = uc($filepath[-2]);
+ my $filename = uc($filepath[-1]); $filename =~ s/-/_/g; $filename =~ s/\.[^.]*$//;
+ my $name = "_${foldername}_${filename}_H_";
+ push @{ $out{$name} }, $data->{compounddef}->{compoundname};
+}
+
+my $fname = '../../src/common/HPMDataCheck.h';
+open(FH, '>', $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.
+#ifndef _HPM_DATA_CHECK_H_
+#define _HPM_DATA_CHECK_H_
+
+
+HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
+EOF
+
+foreach my $key (sort keys %out) {
+ print FH <<"EOF";
+ #ifdef $key
+EOF
+ foreach my $entry (@{ $out{$key} }) {
+ print FH <<"EOF"
+ { "$entry", sizeof(struct $entry) },
+EOF
+ }
+ print FH <<"EOF"
+ #else
+ #define $key
+ #endif // $key
+EOF
+}
+print FH <<"EOF";
+};
+HPExport unsigned int HPMDataCheckLen = ARRAYLENGTH(HPMDataCheck);
+
+#endif /* _HPM_DATA_CHECK_H_ */
+EOF
+close(FH);
diff --git a/tools/HPMHookGen/HPMHookGen.pl b/tools/HPMHookGen/HPMHookGen.pl
index 5333f3f03..b035687e2 100755
--- a/tools/HPMHookGen/HPMHookGen.pl
+++ b/tools/HPMHookGen/HPMHookGen.pl
@@ -7,6 +7,12 @@ use strict;
use warnings;
use XML::Simple;
+# XML Parser hint (some are faster than others)
+#local $ENV{XML_SIMPLE_PREFERRED_PARSER} = ''; # 0m7.138s
+local $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::Parser'; # 0m2.674s
+#local $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::SAX::Expat'; # 0m7.026s
+#local $ENV{XML_SIMPLE_PREFERRED_PARSER} = 'XML::LibXML::SAX'; # 0m4.152s
+
sub trim($) {
my $s = $_[0];
$s =~ s/^\s+//; $s =~ s/\s+$//;
@@ -265,6 +271,8 @@ foreach my $file (@files) { # Loop through the xml files
$key = "ircbot";
} elsif ($key =~ /log_interface/) {
$key = "logs";
+ } elsif ($key =~ /pc_groups_interface/) {
+ $key = "pcg";
} else {
$key =~ s/_interface//;
}
@@ -367,6 +375,7 @@ foreach my $file (@files) { # Loop through the xml files
my %exportsymbols = map {
$_ => &{ sub ($) {
return 'battlegrounds' if $_ =~ /^bg$/;
+ return 'pc_groups' if $_ =~ /^pcg$/;
return $_;
}}($_);
} @keys;
@@ -392,7 +401,7 @@ foreach my $key (@keys) {
foreach my $if (@{ $ifs{$key} }) {
print FH <<"EOF";
- { HP_POP($key\->$if->{name}), HP_POP2($if->{hname}), $idx },
+ { HP_POP($key\->$if->{name}, $if->{hname}) },
EOF
$idx += 2;
diff --git a/tools/HPMHookGen/Makefile.in b/tools/HPMHookGen/Makefile.in
index 10a3c55ba..eb9cad8ff 100644
--- a/tools/HPMHookGen/Makefile.in
+++ b/tools/HPMHookGen/Makefile.in
@@ -1,18 +1,24 @@
@SET_MAKE@
-COMMON_C = $(shell ls ../../src/common/*.c)
-COMMON_H = $(shell ls ../../src/common/*.h)
-MAP_C = $(shell ls ../../src/map/*.c)
-MAP_H = $(shell ls ../../src/map/*.h)
-CHAR_C = $(shell ls ../../src/char/*.c)
-CHAR_H = $(shell ls ../../src/char/*.h)
-LOGIN_C = $(shell ls ../../src/login/*.c)
-LOGIN_H = $(shell ls ../../src/login/*.h)
+COMMON_D = ../../src/common
+MAP_D = ../../src/map
+CHAR_D = ../../src/char
+LOGIN_D = ../../src/login
+PLUGIN_D = ../../src/plugins
+COMMON_C = $(wildcard $(COMMON_D)/*.c)
+COMMON_H = $(filter-out $(COMMON_D)/HPMDataCheck.%,$(wildcard $(COMMON_D)/*.h))
+MAP_C = $(wildcard $(MAP_D)/*.c)
+MAP_H = $(wildcard $(MAP_D)/*.h)
+CHAR_C = $(wildcard $(CHAR_D)/*.c)
+CHAR_H = $(wildcard $(CHAR_D)/*.h)
+LOGIN_C = $(wildcard $(LOGIN_D)/*.c)
+LOGIN_H = $(wildcard $(LOGIN_D)/*.h)
ALL_C = $(COMMON_C) $(MAP_C) $(CHAR_C) $(LOGIN_C)
ALL_H = $(COMMON_H) $(MAP_H) $(CHAR_H) $(LOGIN_H)
-HOOK_INC = $(addprefix ../../src/plugins/HPMHooking., \
- $(addsuffix .inc, HookingPoints sources GetSymbol HPMHooksCore Hooks))
+HOOK_INC = $(addprefix $(PLUGIN_D)/HPMHooking., \
+ $(addsuffix .inc, HookingPoints sources GetSymbol HPMHooksCore Hooks)) \
+ $(COMMON_D)/HPMDataCheck.h
HAVE_DOXYGEN=@HAVE_DOXYGEN@
HAVE_PERL=@HAVE_PERL@
@@ -49,8 +55,10 @@ hooks: $(HOOK_INC)
$(HOOK_INC): generate
generate: doxyoutput
- @echo " Regenerating hook definitions..."
+ @echo " Regenerating HPM Hook definitions..."
@perl HPMHookGen.pl
+ @echo " Regenerating HPM Data Check definitions..."
+ @perl HPMDataCheckGen.pl
doxyoutput: $(ALL_C) $(ALL_H) doxygen.conf
@echo " Extracting functions information..."
diff --git a/tools/HPMHookGen/doxygen.conf b/tools/HPMHookGen/doxygen.conf
index 2f3d1d4f9..e41e9bafe 100644
--- a/tools/HPMHookGen/doxygen.conf
+++ b/tools/HPMHookGen/doxygen.conf
@@ -3,8 +3,6 @@
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "Hercules HPMHookGen"
PROJECT_NUMBER =
-PROJECT_BRIEF =
-PROJECT_LOGO =
OUTPUT_DIRECTORY = doxyoutput
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
@@ -24,27 +22,20 @@ INHERIT_DOCS = NO
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 8
ALIASES =
-TCL_SUBST =
OPTIMIZE_OUTPUT_FOR_C = YES
OPTIMIZE_OUTPUT_JAVA = NO
OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO
EXTENSION_MAPPING = h=C
-MARKDOWN_SUPPORT = NO
-AUTOLINK_SUPPORT = NO
BUILTIN_STL_SUPPORT = NO
CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO
IDL_PROPERTY_SUPPORT = NO
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = NO
-INLINE_GROUPED_CLASSES = NO
-INLINE_SIMPLE_STRUCTS = NO
TYPEDEF_HIDES_STRUCT = NO
-LOOKUP_CACHE_SIZE = 0
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
-EXTRACT_PACKAGE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = NO
EXTRACT_LOCAL_METHODS = NO
@@ -64,7 +55,6 @@ SORT_BRIEF_DOCS = NO
SORT_MEMBERS_CTORS_1ST = NO
SORT_GROUP_NAMES = NO
SORT_BY_SCOPE_NAME = NO
-STRICT_PROTO_MATCHING = NO
GENERATE_TODOLIST = NO
GENERATE_TESTLIST = NO
GENERATE_BUGLIST = NO
@@ -76,7 +66,6 @@ SHOW_FILES = NO
SHOW_NAMESPACES = NO
FILE_VERSION_FILTER =
LAYOUT_FILE =
-CITE_BIB_FILES =
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = NO
@@ -99,8 +88,6 @@ IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
-FILTER_SOURCE_PATTERNS =
-USE_MDFILE_AS_MAINPAGE =
SOURCE_BROWSER = NO
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
@@ -118,14 +105,11 @@ HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
-HTML_EXTRA_STYLESHEET =
-HTML_EXTRA_FILES =
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = YES
HTML_DYNAMIC_SECTIONS = NO
-HTML_INDEX_NUM_ENTRIES = 100
GENERATE_DOCSET = NO
DOCSET_FEEDNAME = "Doxygen generated docs"
DOCSET_BUNDLE_ID = org.doxygen.Project
@@ -155,18 +139,8 @@ TREEVIEW_WIDTH = 250
EXT_LINKS_IN_WINDOW = NO
FORMULA_FONTSIZE = 10
FORMULA_TRANSPARENT = YES
-USE_MATHJAX = NO
-MATHJAX_FORMAT = HTML-CSS
-MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
-MATHJAX_EXTENSIONS =
-MATHJAX_CODEFILE =
SEARCHENGINE = YES
SERVER_BASED_SEARCH = NO
-EXTERNAL_SEARCH = NO
-SEARCHENGINE_URL =
-SEARCHDATA_FILE = searchdata.xml
-EXTERNAL_SEARCH_ID =
-EXTRA_SEARCH_MAPPINGS =
GENERATE_LATEX = NO
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
@@ -175,14 +149,11 @@ COMPACT_LATEX = NO
PAPER_TYPE = a4
EXTRA_PACKAGES =
LATEX_HEADER =
-LATEX_FOOTER =
-LATEX_EXTRA_FILES =
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
LATEX_SOURCE_CODE = NO
-LATEX_BIB_STYLE = plain
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
@@ -198,8 +169,6 @@ XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = NO
-GENERATE_DOCBOOK = NO
-DOCBOOK_OUTPUT = docbook
GENERATE_AUTOGEN_DEF = NO
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
@@ -218,7 +187,6 @@ TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = NO
-EXTERNAL_PAGES = NO
PERL_PATH = /usr/bin/perl
CLASS_DIAGRAMS = NO
MSCGEN_PATH =
@@ -232,7 +200,6 @@ CLASS_GRAPH = NO
COLLABORATION_GRAPH = NO
GROUP_GRAPHS = NO
UML_LOOK = NO
-UML_LIMIT_NUM_FIELDS = 10
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = NO
INCLUDED_BY_GRAPH = NO
@@ -241,10 +208,8 @@ CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = NO
DIRECTORY_GRAPH = NO
DOT_IMAGE_FORMAT = png
-INTERACTIVE_SVG = NO
DOT_PATH =
DOTFILE_DIRS =
-MSCFILE_DIRS =
DOT_GRAPH_MAX_NODES = 50
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
diff --git a/tools/Script-Checker.applescript b/tools/Script-Checker.applescript
new file mode 100644
index 000000000..db1983f4b
--- /dev/null
+++ b/tools/Script-Checker.applescript
@@ -0,0 +1,151 @@
+(*
+ Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+ See the LICENSE file
+ Base Author: Haru @ http://hercules.ws
+*)
+
+(*
+ *************************************************************
+ *************************************************************
+ ******** **************
+ ******** NOTE: This script must be saved as app!!! **************
+ ******** **************
+ *************************************************************
+ *************************************************************
+*)
+
+property allowed_extensions : {"txt", "c", "ath", "herc"}
+property allowed_types : {"TEXT"}
+
+on run
+ try
+ set the resource_path to path to resource "Scripts"
+ tell application "Finder" to set the resource_path to the container of the resource_path
+ on error
+ display alert "Error" message "You need to save this script as an app bundle." buttons {"Cancel"} cancel button 1 as warning
+ end try
+ set the dialog_result to display dialog "You can drag files to this app to have them checked." with title "Hercules Script Checker" buttons {"Cancel", "(Re)build Hercules", "Check Script"} default button 3 cancel button 1
+ if the button returned of the dialog_result is "(Re)build Hercules" then
+ rebuild()
+ else
+ set these_items to choose file of type allowed_extensions with prompt "Choose the script(s) you want to check:" with multiple selections allowed
+ process_items(these_items)
+ end if
+end run
+
+on open these_items
+ process_items(these_items)
+end open
+
+on build_hercules(hercules_repo)
+ try
+ set the resource_path to path to resource "Scripts"
+ tell application "Finder" to set the resource_path to the container of the resource_path
+ on error
+ display alert "Error" message "You need to save this script as an app bundle." buttons {"Cancel"} cancel button 1 as warning
+ end try
+ set the configuration_flags to display dialog "Do you want to use any configuration flags? (i.e. --disable-renewal)" with title "Configuration" default answer "" buttons {"Cancel", "Ok"} default button 2 cancel button 1
+ try
+ set the command_output to do shell script "cd " & (the quoted form of the POSIX path of the hercules_repo) & " && echo './configure " & the text returned of the configuration_flags & " 2>&1' | bash -i"
+ on error
+ display dialog "Configuration failed" with title "Configuration result" buttons {"Abort"} cancel button 1
+ end try
+ tell application "TextEdit"
+ activate
+ set the new_document to make new document
+ set the text of new_document to the command_output
+ end tell
+ display dialog "Configuration successfully completed. Please check the log file for details." with title "Configuration result" buttons {"Abort", "Continue"} default button 2 cancel button 1
+ try
+ set the command_output to do shell script "cd " & (the quoted form of the POSIX path of the hercules_repo) & " && echo 'make clean 2>&1 && make sql -j8 2>&1' | bash -i"
+ on error
+ display dialog "Build failed." with title "Build result" buttons {"Abort"} cancel button 1
+ end try
+ tell application "TextEdit"
+ activate
+ set the new_document to make new document
+ set the text of new_document to the command_output
+ end tell
+ display dialog "Build successfully completed. Please check the log file for details." with title "Build result" buttons {"Abort", "Continue"} default button 2 cancel button 1
+ set the files_to_copy to {"map-server", "script-checker"}
+ set the conf_files_to_copy to {"inter-server.conf", "import", "packet.conf", "script.conf"}
+ set the db_files_to_copy to {"map_index.txt", "item_db2.txt", "const.txt", "mob_db2.txt"}
+ set the db2_files_to_copy to {"map_cache.dat", "item_db.txt", "skill_db.txt", "mob_db.txt"}
+ try
+ set the hercules_path to path to resource "Hercules"
+ do shell script "rm -r " & the quoted form of ((the POSIX path of hercules_path) & "/")
+ end try
+ set the hercules_path to the resource_path
+ tell application "Finder" to make new folder at hercules_path with properties {name:"Hercules"}
+ delay 3
+ set the hercules_path to path to resource "Hercules"
+ repeat with each_file in files_to_copy
+ copy_file(each_file, hercules_repo, hercules_path, ".")
+ end repeat
+ do shell script "mkdir " & the quoted form of ((POSIX path of the hercules_path) & "/conf")
+ repeat with each_file in conf_files_to_copy
+ copy_file(each_file, hercules_repo, hercules_path, "conf")
+ end repeat
+ do shell script "mkdir " & the quoted form of ((POSIX path of the hercules_path) & "/db")
+ repeat with each_file in db_files_to_copy
+ copy_file(each_file, hercules_repo, hercules_path, "db")
+ end repeat
+ do shell script "mkdir " & the quoted form of ((POSIX path of the hercules_path) & "/db/pre-re")
+ repeat with each_file in db2_files_to_copy
+ copy_file(each_file, hercules_repo, hercules_path, "db/pre-re")
+ end repeat
+ do shell script "mkdir " & the quoted form of ((POSIX path of the hercules_path) & "/db/re")
+ repeat with each_file in db2_files_to_copy
+ copy_file(each_file, hercules_repo, hercules_path, "db/re")
+ end repeat
+ display dialog "Build complete" with title "Done" buttons {"Ok"} default button "Ok"
+end build_hercules
+
+on rebuild()
+ set the repo_path to choose folder with prompt "Choose the folder where your Hercules repository is located:"
+ build_hercules(repo_path)
+end rebuild
+
+on copy_file(filename, source, destination, subpath)
+ do shell script "cp -rp " & the quoted form of ((the POSIX path of source) & "/" & subpath & "/" & filename) & " " & the quoted form of ((the POSIX path of destination) & "/" & subpath & "/")
+end copy_file
+
+on process_items(these_items)
+ repeat
+ try
+ set the scriptchecker to the path to resource "script-checker" in directory "Hercules"
+ set the mapserver to the path to resource "map-server" in directory "Hercules"
+ on error
+ display alert "Missing Hercules binaries" message "You need to build Hercules and place it within this app bundle before running the script checker." & linefeed & linefeed & "I can try to build it for you, but only if you have the Xcode command line tools installed." & linefeed & "Do you want to continue?" buttons {"Cancel", "Build"} default button "Build" cancel button "Cancel" as warning
+ rebuild()
+ return false
+ end try
+ exit repeat
+ end repeat
+ repeat with i from 1 to the count of these_items
+ set this_item to item i of these_items
+ set the item_info to info for this_item
+ set this_name to the name of the item_info
+ try
+ set this_extension to the name extension of item_info
+ on error
+ set this_extension to ""
+ end try
+ try
+ set this_filetype to the file type of item_info
+ on error
+ set this_filetype to ""
+ end try
+ if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the allowed_types) or (this_extension is in the allowed_extensions)) then
+ process_item(scriptchecker, this_item)
+ end if
+ end repeat
+end process_items
+
+on process_item(checkerpath, this_item)
+ set the_result to do shell script (the quoted form of the POSIX path of checkerpath & " " & the quoted form of the POSIX path of this_item) & " 2>&1"
+ if the_result is "" then
+ set the_result to "Check passed."
+ end if
+ display dialog ("File: " & POSIX path of this_item) & linefeed & "Result: " & linefeed & the_result with title "Output" buttons {"Abort", "Next"} default button "Next" cancel button "Abort"
+end process_item
diff --git a/tools/itemdbconverter.pl b/tools/itemdbconverter.pl
new file mode 100755
index 000000000..13805c09e
--- /dev/null
+++ b/tools/itemdbconverter.pl
@@ -0,0 +1,195 @@
+#!/usr/bin/perl
+#
+# Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+# See the LICENSE file
+# Base Author: Haru @ http://hercules.ws
+#
+# This script converts an item_db(2).txt to the new item_db(2).conf format.
+# usage example: perl tools/itemdbconverter.pl < db/item_db2.txt > db/item_db2.conf
+#
+use strict;
+use warnings;
+
+sub prettifyscript ($) {
+ my ($orig) = @_;
+ $orig =~ s/^[\s\t]*//; $orig =~ s/[\s\t]*$//;
+ return '' unless $orig =~ /[^\s\t]/;
+ my ($p, $script) = ($orig, '');
+ my ($curly, $lines, $comment) = (2, 0, 0);
+ my ($linebreak, $needindent) = (0, 0);
+ while ($p =~ /[^\s\t]/) {
+ $linebreak = 0;
+ if ($comment && $p =~ s|^\s*\*/\s*||) {
+ $comment = 0;
+ next;
+ } elsif ($p =~ s/^\s*({)\s*//) {
+ $curly++ unless $comment;
+ $comment++ if $comment;
+ $script .= " ";
+ $linebreak = 1;
+ $lines++;
+ } elsif ($p =~ s/^\s*(})\s*//) {
+ $curly-- unless $comment;
+ $comment-- if $comment - 1 > 0;
+ $linebreak = 1;
+ $lines++;
+ } elsif ($p =~ s/^\s*(;)\s*//) {
+ if ($p && (!$comment || $p !~ m|^[\s\t]*(?:\*/)[\s\t]*$|)) {
+ $linebreak = 1;
+ $lines++
+ }
+ } elsif ($p =~ s/^("[^"]*")//) {
+ } elsif ($p =~ s|^\s*/\*\s*||) {
+ $comment = 1;
+ next;
+ } elsif ($p !~ s/^(.)//) {
+ last;
+ }
+ $script .= "\t" x $curly if $needindent;
+ $script .= "//" . ("\t" x ($comment-1)) if ($comment && ($needindent || $script eq ''));
+ $script .= "$1";
+ if ($linebreak) {
+ $script .= "\n";
+ $needindent = 1;
+ } else {
+ $needindent = 0;
+ }
+ }
+ if ($curly != 2) {
+ printf STDERR "Parse error, curly braces count ". ($curly-2) .". returning unmodified script:\n$orig\n\n";
+ return $orig;
+ }
+ if ($lines) {
+ $script = "\n\t\t$script\n\t";
+ } else {
+ $script = " $script ";
+ }
+ return $script;
+}
+
+sub parsedb (@) {
+ my @input = @_;
+ foreach (@input) {
+ chomp $_;
+# ID,AegisName,Name,Type,Buy,Sell,Weight,ATK,DEF,Range,Slots,Job,Upper,Gender,Loc,wLV,eLV,Refineable,View,{ Script },{ OnEquip_Script },{ OnUnequip_Script }
+ if( $_ =~ qr/^
+ (?<prefix>(?:\/\/[^0-9]*)?)
+ (?<ID>[0-9]+)[^,]*,
+ (?<AegisName>[^,]+),
+ (?<Name>[^,]+),[\s\t]*
+ (?<Type>[0-9]+)[^,]*,[\s\t]*
+ (?<Buy>[0-9]*)[^,]*,[\s\t]*
+ (?<Sell>[0-9]*)[^,]*,[\s\t]*
+ (?<Weight>[0-9]*)[^,]*,[\s\t]*
+ (?<ATK>[0-9-]*)[^,:]*(?<hasmatk>:[\s\t]*(?<MATK>[0-9-]*))?[^,]*,[\s\t]*
+ (?<DEF>[0-9-]*)[^,]*,[\s\t]*
+ (?<Range>[0-9]*)[^,]*,[\s\t]*
+ (?<Slots>[0-9]*)[^,]*,[\s\t]*
+ (?<Job>[x0-9A-Fa-f]*)[^,]*,[\s\t]*
+ (?<Upper>[0-9]*)[^,]*,[\s\t]*
+ (?<Gender>[0-9]*)[^,]*,[\s\t]*
+ (?<Loc>[0-9]*)[^,]*,[\s\t]*
+ (?<wLV>[0-9]*)[^,]*,[\s\t]*
+ (?<eLV>[0-9]*)[^,:]*(?<hasmaxlv>:[\s\t]*(?<eLVmax>[0-9]*))?[^,]*,[\s\t]*
+ (?<Refineable>[0-9]*)[^,]*,[\s\t]*
+ (?<View>[0-9]*)[^,]*,[\s\t]*
+ {(?<Script>.*)},
+ {(?<OnEquip>.*)},
+ {(?<OnUnequip>.*)}
+ /x ) {
+ my %cols = map { $_ => $+{$_} } keys %+;
+ print "/*\n" if $cols{prefix};
+ print "$cols{prefix}\n" if $cols{prefix} and $cols{prefix} !~ m|^//[\s\t]*$|;
+ print "{\n";
+ print "\tId: $cols{ID}\n";
+ print "\tAegisName: \"$cols{AegisName}\"\n";
+ print "\tName: \"$cols{Name}\"\n";
+ print "\tType: $cols{Type}\n";
+ print "\tBuy: $cols{Buy}\n" if $cols{Buy} || $cols{Buy} eq '0';
+ print "\tSell: $cols{Sell}\n" if $cols{Sell} || $cols{Sell} eq '0';
+ print "\tWeight: $cols{Weight}\n" if $cols{Weight};
+ print "\tAtk: $cols{ATK}\n" if $cols{ATK};
+ print "\tMatk: $cols{MATK}\n" if $cols{MATK};
+ print "\tDef: $cols{DEF}\n" if $cols{DEF};
+ print "\tRange: $cols{Range}\n" if $cols{Range};
+ print "\tSlots: $cols{Slots}\n" if $cols{Slots};
+ $cols{Job} = '0xFFFFFFFF' unless $cols{Job};
+ print "\tJob: $cols{Job}\n" unless $cols{Job} =~ /0xFFFFFFFF/i;
+ print "\tUpper: $cols{Upper}\n" if $cols{Upper} && (($cols{hasmatk} && $cols{Upper} != 0x3f) || (!$cols{hasmatk} && $cols{Upper} != 7));
+ $cols{Gender} = '2' unless $cols{Gender};
+ print "\tGender: $cols{Gender}\n" unless $cols{Gender} eq '2';
+ print "\tLoc: $cols{Loc}\n" if $cols{Loc};
+ print "\tWeaponLv: $cols{wLV}\n" if $cols{wLV};
+ if ($cols{hasmaxlv} and $cols{eLVmax}) {
+ $cols{eLV} = 0 unless $cols{eLV};
+ print "\tEquipLv: [$cols{eLV}, $cols{eLVmax}]\n";
+ } else {
+ print "\tEquipLv: $cols{eLV}\n" if $cols{eLV};
+ }
+ print "\tRefine: false\n" if !$cols{Refineable} and ($cols{Type} == 4 or $cols{Type} == 5);
+ print "\tView: $cols{View}\n" if $cols{View};
+ $cols{Script} = prettifyscript($cols{Script});
+ print "\tScript: <\"$cols{Script}\">\n" if $cols{Script};
+ $cols{OnEquip} = prettifyscript($cols{OnEquip});
+ print "\tOnEquipScript: <\"$cols{OnEquip}\">\n" if $cols{OnEquip};
+ $cols{OnUnequip} = prettifyscript($cols{OnUnequip});
+ print "\tOnUnequipScript: <\"$cols{OnUnequip}\">\n" if $cols{OnUnequip};
+ print "},\n";
+ print "*/\n" if $cols{prefix};
+ } elsif( $_ =~ /^\/\/(.*)$/ ) {
+ my $s = $1;
+ print "// $s\n" unless $s =~ /^[\s\t]*$/;
+ } elsif( $_ !~ /^\s*$/ ) {
+ print "// Error parsing: $_\n";
+ }
+
+ }
+}
+print <<"EOF";
+item_db: (
+/******************************************************************************
+ ************* Entry structure ************************************************
+ ******************************************************************************
+{
+ // =================== Mandatory fields ===============================
+ Id: ID (int)
+ AegisName: "Aegis_Name" (string, optional if Inherit: true)
+ Name: "Item Name" (string, optional if Inherit: true)
+ // =================== Optional fields ================================
+ Type: Item Type (int, defaults to 3 = etc item)
+ Buy: Buy Price (int, defaults to Sell * 2)
+ Sell: Sell Price (int, defaults to Buy / 2)
+ Weight: Item Weight (int, defaults to 0)
+ Atk: Attack (int, defaults to 0)
+ Matk: Magical Attack (int, defaults to 0, ignored in pre-re)
+ Def: Defense (int, defaults to 0)
+ Range: Attack Range (int, defaults to 0)
+ Slots: Slots (int, defaults to 0)
+ Job: Job mask (int, defaults to all jobs = 0xFFFFFFFF)
+ Upper: Upper mask (int, defaults to any = 0x3f)
+ Gender: Gender (int, defaults to both = 2)
+ Loc: Equip location (int, required value for equipment)
+ WeaponLv: Weapon Level (int, defaults to 0)
+ EquipLv: Equip required level (int, defaults to 0)
+ EquipLv: [min, max] (alternative syntax with min / max level)
+ Refine: Refineable (boolean, defaults to true)
+ View: View ID (int, defaults to 0)
+ BindOnEquip: true/false (boolean, defaults to false)
+ Script: <"
+ Script
+ (it can be multi-line)
+ ">
+ OnEquipScript: <" OnEquip Script (can also be multi-line) ">
+ OnUnequipScript: <" OnUnequip Script (can also be multi-line) ">
+ // =================== Optional fields (item_db2 only) ================
+ Inherit: true/false (boolean, if true, inherit the values
+ that weren't specified, from item_db.conf,
+ else override it and use default values)
+},
+******************************************************************************/
+
+EOF
+
+parsedb(<>);
+
+print ")\n";