From 58bfcf8afbefe720b2dc9df5fb9e9f2f3b39d7a2 Mon Sep 17 00:00:00 2001 From: Elmsroth Date: Thu, 25 Jun 2020 16:30:23 +0200 Subject: [PATCH] Add mangos string Language.h generator (#104) * Delete unused Language.h enums * Initialize project for mangos string Language.h source file generation * Add missing newline at end of files --- src/tools/.gitignore | 4 + .../README.md | 54 ++++++++ .../php-cli/GenerateLanguage.h.php | 120 ++++++++++++++++++ .../php-cli/includes/Common.Functions.php | 60 +++++++++ .../php-cli/includes/config.inc.php.default | 55 ++++++++ .../php-cli/includes/constants.php | 9 ++ .../php-cli/includes/finish.inc.php | 4 + .../php-cli/includes/init.inc.php | 20 +++ .../templates/MangosFour_Language.h.tpl | 41 ++++++ .../templates/MangosOne_Language.h.tpl | 41 ++++++ .../templates/MangosThree_Language.h.tpl | 41 ++++++ .../templates/MangosTwo_Language.h.tpl | 41 ++++++ .../templates/MangosZero_Language.h.tpl | 41 ++++++ 13 files changed, 531 insertions(+) create mode 100644 src/tools/MangosStrings_LanguageHGenerator/README.md create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/GenerateLanguage.h.php create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/Common.Functions.php create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/config.inc.php.default create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/constants.php create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/finish.inc.php create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/init.inc.php create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosFour_Language.h.tpl create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosOne_Language.h.tpl create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosThree_Language.h.tpl create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosTwo_Language.h.tpl create mode 100644 src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosZero_Language.h.tpl diff --git a/src/tools/.gitignore b/src/tools/.gitignore index 7b922ae1..d489ba5b 100644 --- a/src/tools/.gitignore +++ b/src/tools/.gitignore @@ -16,3 +16,7 @@ debug release *.ilk ad_debug.exe + +MangosStrings_LanguageHGenerator/php-cli/includes/config.inc.php +MangosStrings_LanguageHGenerator/out/ +MangosStrings_LanguageHGenerator/.vs \ No newline at end of file diff --git a/src/tools/MangosStrings_LanguageHGenerator/README.md b/src/tools/MangosStrings_LanguageHGenerator/README.md new file mode 100644 index 00000000..4238251f --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/README.md @@ -0,0 +1,54 @@ + +## MaNGOS Strings enums generator for C++ source (`Language.h`) +---- + +There are lots of enums in the source files of *MaNGOS* project. + +The biggest file is `Language.h` header file that is more hundreds of enum declarations. + +All the enum tags in this `Language.h` refers to an entry (integer) which is stored in the `mangos_string` table in the *world* database. + +The main goal of this tool is to help MaNGOS devs & contributors to maintain `Language.h`file easily by pulling available mangos strings from DB, instead of upatding teh file manually. +Other advantages are : +- All mangos strings in DB are present in `Language.h` +- Deleted mangos strings from DB would also be deleted from the file +- Default English content would always be displayed as a comment after the enum int value +- The `Language.h` file will be more homogeneous since all `=` signs will be aligned + +## Prerequisites +---- + +### PHP version + +- PHP must be installed *(These scripts have been tested sith PHP 7.3.5)* +- PHP executable must be added to your PATH variable (Warning Windows user!) - To check that, type `php -v`in a command prompt, if it returns teh PHP version, you're good to go ! +- PHP PDO extension must be enabled *(most of the time it is the case in most recent installations)*. + +## How to use ? +---- + +This tool should be used when a you want to add new mangos string in the C++ sources. + +**/!\ WARNING :** Before using the generator, the mangos string should have been added in the `mangos_string` table of teh wodl DB of the core you're targeting + +### PHP version + +**FIRST TIME USE :** + +1. Make a copy of the `php-cli/includes/config.inc.php.default` file in the same folder and name it `config.inc.php`. +1. Edit `config.inc.php` fiel to fil your config + +**REGULAR USE :** + +1. Open a terminal and go in the `php-cli` folder of this project +1. Type `php GenerateLanguage.h.php` +1. Select the core version you're targeting and press enter +1. You're done, the file has been generated + +Be sure the output file has been correctly generated in the correct source folder in order to rebuild the core. +If not, try to copy it manually since it has been generated in the `out` folder if no output directory has been set in the `config.inc.php` file. + +## How to contribute ? +---- + +You can develop other versions of this generator using other languages (e.g : python, C, perl ...) diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/GenerateLanguage.h.php b/src/tools/MangosStrings_LanguageHGenerator/php-cli/GenerateLanguage.h.php new file mode 100644 index 00000000..1f86ff5a --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/GenerateLanguage.h.php @@ -0,0 +1,120 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + + /* Generator Initiated by By @Elmsroth */ + + require_once "includes/init.inc.php"; + + echo "Which core version should the script generate the 'Language.h' file ?" .NEWLINE; + + displayChoices(); + + $input = readline("Enter your choice : "); + + $config = getConfig($input); + if($config == null) + { + echo "ERROR - Unknow selection : $input" .NEWLINE; + goto end; + } + + // Start MYSQL connection + $connStr = 'mysql:host='.DB_HOST.':'.DB_PORT.';dbname='.$config["DB"]; + $worldPDO = new PDO($connStr, DB_USER, DB_PASS); + + echo "> Generating 'Language.h' source file..." . NEWLINE; + + $sqlQueryText = "SELECT `entry`, `content_default`, `source_enum_tag` FROM `mangos_string` WHERE `source_enum_wrapper`='MangosStrings' ORDER By `entry` ASC;" ; + + $template = file_get_contents("templates/MangosZero_Language.h.tpl"); + + if($template === false) + { + goto end; + } + + $stm = $worldPDO->query($sqlQueryText); + $rows = $stm->fetchAll(PDO::FETCH_ASSOC); + + $fileContent = ""; + + $maxTagLength = 0; + + // find max tag Length + foreach($rows as $row) + { + $tagLen = strlen($row["source_enum_tag"]); + if($tagLen>$maxTagLength) + { + $maxTagLength = $tagLen; + } + } + + foreach($rows as $row) + { + $tagLen = strlen($row["source_enum_tag"]); + $line = TAB . $row["source_enum_tag"] . spaces($maxTagLength - $tagLen + 2) . "= " .$row["entry"] ."," . spaces(4) . "/* " .$row["content_default"] ." */" . NEWLINE; + $fileContent .= $line; + } + + + $output = str_replace ("{CONTENT}", $fileContent, $template); + + $outputDir = trim(OUTPUT_DIR); + // If output dir is empty we will have to create output folder + if($outputDir == "") + { + $outputDir = "../out/MangosZero/"; + if(folder_exist($outputDir) === false) + { + mkdir($outputDir, 0777, true); + } + } + else + { + if($CURRENT_OS == OS_WINDOWS) + { + $outputDir = str_replace("\\", "/", $outputDir); + } + } + + // Check for missing trailing slash + if( get_nth_char($outputDir, strlen($outputDir)) != "/") + { + $outputDir .= "/"; + } + + $outFile = $outputDir ."Language.h"; + + file_put_contents($outFile,$output); + + echo "> OUT file = ".$outFile .NEWLINE; + + // Write the file + + +end: + require_once "includes/finish.inc.php"; +?> diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/Common.Functions.php b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/Common.Functions.php new file mode 100644 index 00000000..a841c1ec --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/Common.Functions.php @@ -0,0 +1,60 @@ + diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/config.inc.php.default b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/config.inc.php.default new file mode 100644 index 00000000..a886344b --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/config.inc.php.default @@ -0,0 +1,55 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + + /* Generator Initiated by By Elmsroth */ + + /* + DATABASE CONFIG + */ + define("DB_HOST","localhost"); + define("DB_PORT", 3306); + // The user should be granted access to all mangos schemas for all core DBs you might have + define("DB_USER", "mangos_zero"); + define("DB_PASS", "passWQiopword1xG2196qsdOUdqs"); + define("SHARED_CONFIGS", + [ + 0 => ["DB"=> "world0", "TPL_PREFIX" => "MangosZero_", "OUT_DIR_IF_EMPTY" =>"../out/MangosZero/"], + 1 => ["DB"=> "world1", "TPL_PREFIX" => "MangosOne_", "OUT_DIR_IF_EMPTY" =>"../out/MangosOne/"], + 2 => ["DB"=> "world2", "TPL_PREFIX" => "MangosTwo_", "OUT_DIR_IF_EMPTY" =>"../out/MangosTwo/"], + 3 => ["DB"=> "world3", "TPL_PREFIX" => "MangosThree_", "OUT_DIR_IF_EMPTY" =>"../out/MangosThree/"], + 4 => ["DB"=> "world4", "TPL_PREFIX" => "MangosFour_", "OUT_DIR_IF_EMPTY" =>"../out/MangosFour/"] + ] +); + + /* OUTPUT Directory for generated files + It is a good idea to set the output directory + to be the one where the original source file is located. + If empty, the file will be generated in the "out" folder in the root fodler of this project + */ + + // /!\ WARNING NEVER PUT DOUBLE QUOTES FOR VALUE + define("OUTPUT_DIR", ''); + +?> diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/constants.php b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/constants.php new file mode 100644 index 00000000..80f8f439 --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/constants.php @@ -0,0 +1,9 @@ + diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/finish.inc.php b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/finish.inc.php new file mode 100644 index 00000000..7fdc3ef8 --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/finish.inc.php @@ -0,0 +1,4 @@ + diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/init.inc.php b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/init.inc.php new file mode 100644 index 00000000..72fa520c --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/includes/init.inc.php @@ -0,0 +1,20 @@ + diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosFour_Language.h.tpl b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosFour_Language.h.tpl new file mode 100644 index 00000000..33c6eaa6 --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosFour_Language.h.tpl @@ -0,0 +1,41 @@ +/** + * MaNGOS is a full featured server for World of Warcraft, supporting + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 + * + * Copyright (C) 2005-2020 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + +#ifndef MANGOS_H_MANGOS_LANGUAGE +#define MANGOS_H_MANGOS_LANGUAGE + +enum MangosStrings +{ +{CONTENT} + // FREE IDS 1701-9999 + // Use for not-in-official-sources patches + // 10000-10999 + + // Use for custom patches 11000-11999 + + // NOT RESERVED IDS 12000-1999999999 + // `db_script_string` table index 2000000000-2000999999 (MIN_DB_SCRIPT_STRING_ID-MAX_DB_SCRIPT_STRING_ID) + // For other tables maybe 2001000000-2147483647 (max index) +}; +#endif diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosOne_Language.h.tpl b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosOne_Language.h.tpl new file mode 100644 index 00000000..33c6eaa6 --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosOne_Language.h.tpl @@ -0,0 +1,41 @@ +/** + * MaNGOS is a full featured server for World of Warcraft, supporting + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 + * + * Copyright (C) 2005-2020 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + +#ifndef MANGOS_H_MANGOS_LANGUAGE +#define MANGOS_H_MANGOS_LANGUAGE + +enum MangosStrings +{ +{CONTENT} + // FREE IDS 1701-9999 + // Use for not-in-official-sources patches + // 10000-10999 + + // Use for custom patches 11000-11999 + + // NOT RESERVED IDS 12000-1999999999 + // `db_script_string` table index 2000000000-2000999999 (MIN_DB_SCRIPT_STRING_ID-MAX_DB_SCRIPT_STRING_ID) + // For other tables maybe 2001000000-2147483647 (max index) +}; +#endif diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosThree_Language.h.tpl b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosThree_Language.h.tpl new file mode 100644 index 00000000..33c6eaa6 --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosThree_Language.h.tpl @@ -0,0 +1,41 @@ +/** + * MaNGOS is a full featured server for World of Warcraft, supporting + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 + * + * Copyright (C) 2005-2020 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + +#ifndef MANGOS_H_MANGOS_LANGUAGE +#define MANGOS_H_MANGOS_LANGUAGE + +enum MangosStrings +{ +{CONTENT} + // FREE IDS 1701-9999 + // Use for not-in-official-sources patches + // 10000-10999 + + // Use for custom patches 11000-11999 + + // NOT RESERVED IDS 12000-1999999999 + // `db_script_string` table index 2000000000-2000999999 (MIN_DB_SCRIPT_STRING_ID-MAX_DB_SCRIPT_STRING_ID) + // For other tables maybe 2001000000-2147483647 (max index) +}; +#endif diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosTwo_Language.h.tpl b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosTwo_Language.h.tpl new file mode 100644 index 00000000..33c6eaa6 --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosTwo_Language.h.tpl @@ -0,0 +1,41 @@ +/** + * MaNGOS is a full featured server for World of Warcraft, supporting + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 + * + * Copyright (C) 2005-2020 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + +#ifndef MANGOS_H_MANGOS_LANGUAGE +#define MANGOS_H_MANGOS_LANGUAGE + +enum MangosStrings +{ +{CONTENT} + // FREE IDS 1701-9999 + // Use for not-in-official-sources patches + // 10000-10999 + + // Use for custom patches 11000-11999 + + // NOT RESERVED IDS 12000-1999999999 + // `db_script_string` table index 2000000000-2000999999 (MIN_DB_SCRIPT_STRING_ID-MAX_DB_SCRIPT_STRING_ID) + // For other tables maybe 2001000000-2147483647 (max index) +}; +#endif diff --git a/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosZero_Language.h.tpl b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosZero_Language.h.tpl new file mode 100644 index 00000000..33c6eaa6 --- /dev/null +++ b/src/tools/MangosStrings_LanguageHGenerator/php-cli/templates/MangosZero_Language.h.tpl @@ -0,0 +1,41 @@ +/** + * MaNGOS is a full featured server for World of Warcraft, supporting + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 + * + * Copyright (C) 2005-2020 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * World of Warcraft, and all World of Warcraft or Warcraft art, images, + * and lore are copyrighted by Blizzard Entertainment, Inc. + */ + +#ifndef MANGOS_H_MANGOS_LANGUAGE +#define MANGOS_H_MANGOS_LANGUAGE + +enum MangosStrings +{ +{CONTENT} + // FREE IDS 1701-9999 + // Use for not-in-official-sources patches + // 10000-10999 + + // Use for custom patches 11000-11999 + + // NOT RESERVED IDS 12000-1999999999 + // `db_script_string` table index 2000000000-2000999999 (MIN_DB_SCRIPT_STRING_ID-MAX_DB_SCRIPT_STRING_ID) + // For other tables maybe 2001000000-2147483647 (max index) +}; +#endif