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
This commit is contained in:
Elmsroth 2020-06-25 16:30:23 +02:00 committed by GitHub
parent a310b51fd8
commit 58bfcf8afb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 531 additions and 0 deletions

View File

@ -16,3 +16,7 @@ debug
release
*.ilk
ad_debug.exe
MangosStrings_LanguageHGenerator/php-cli/includes/config.inc.php
MangosStrings_LanguageHGenerator/out/
MangosStrings_LanguageHGenerator/.vs

View File

@ -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 ...)

View File

@ -0,0 +1,120 @@
<?php
/**
* 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 <https://getmangos.eu>
*
* 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";
?>

View File

@ -0,0 +1,60 @@
<?php
function spaces($nbSpaces)
{
$str = "";
for($i = 0; $i < $nbSpaces ; ++$i)
{
$str .= SPACE;
}
return $str;
}
function get_nth_char($string, $index) {
return substr($string, strlen($string) - $index - 1, 1);
}
/**
* Checks if a folder exist and return canonicalized absolute pathname (sort version)
* @param string $folder the path being checked.
* @return mixed returns the canonicalized absolute pathname on success otherwise FALSE is returned
*/
function folder_exist($folder)
{
// Get canonicalized absolute pathname
$path = realpath($folder);
// If it exist, check if it's a directory
return ($path !== false AND is_dir($path)) ? $path : false;
}
function displayChoices()
{
echo "\t[0] - Mangos Zero" .NEWLINE;
echo "\t[1] - Mangos One" .NEWLINE;
echo "\t[2] - Mangos Two" .NEWLINE;
echo "\t[3] - Mangos Three" .NEWLINE;
echo "\t[4] - Mangos Four" .NEWLINE;
}
function getConfig($input)
{
switch($input)
{
case 0 :
case 1 :
case 2 :
case 3 :
case 4 :
{
return SHARED_CONFIGS[$input];
}
default :
{
return null;
}
}
}
?>

View File

@ -0,0 +1,55 @@
<?php
/**
* 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 <https://getmangos.eu>
*
* 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", '');
?>

View File

@ -0,0 +1,9 @@
<?php
define("NEWLINE", "\n");
define("TAB", "\t");
define("SPACE", " ");
define("OS_WINDOWS", 1);
define("OS_LINUX", 2);
?>

View File

@ -0,0 +1,4 @@
<?php
echo "=== END OF SCRIPT ===";
?>

View File

@ -0,0 +1,20 @@
<?php
echo "=== START OF SCRIPT ===\n";
require_once "constants.php";
// Determine which OS is running the script
$CURRENT_OS = null;
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
{
$CURRENT_OS = OS_WINDOWS;
}
else
{
$CURRENT_OS = OS_LINUX;
}
echo "This script is running under a " . ($CURRENT_OS == OS_WINDOWS ? "WINDOWS" : "LINUX" ) ." operating system.". NEWLINE;
require_once "config.inc.php";
require_once "Common.Functions.php";
?>

View File

@ -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 <https://getmangos.eu>
*
* 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

View File

@ -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 <https://getmangos.eu>
*
* 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

View File

@ -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 <https://getmangos.eu>
*
* 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

View File

@ -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 <https://getmangos.eu>
*
* 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

View File

@ -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 <https://getmangos.eu>
*
* 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