2019-06-18 22:55:32 -04:00
/ *
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Copyright ( C ) 2015 - 2019 Project Meteor Dev Team
This file is part of Project Meteor Server .
Project Meteor Server is free software : you can redistribute it and / or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
Project Meteor Server 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 Affero General Public License for more details .
You should have received a copy of the GNU Affero General Public License
along with Project Meteor Server . If not , see < https : www . gnu . org / licenses / > .
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* /
2019-06-19 00:05:18 -04:00
using Meteor.Common ;
2019-06-19 01:10:15 -04:00
using Meteor.Map.packets.send.player ;
2016-01-17 01:50:38 -05:00
using MySql.Data.MySqlClient ;
using System ;
using System.Collections.Generic ;
2016-01-25 01:10:43 -05:00
using System.IO ;
2016-01-17 01:50:38 -05:00
using System.Text ;
using System.Text.RegularExpressions ;
2019-06-19 01:10:15 -04:00
namespace Meteor.Map.utils
2016-01-17 01:50:38 -05:00
{
class SQLGeneration
{
2016-02-21 20:48:07 -05:00
2016-06-14 21:29:10 +01:00
public static void GenerateZones ( )
2016-01-17 01:50:38 -05:00
{
using ( MySqlConnection conn = new MySqlConnection ( String . Format ( "Server={0}; Port={1}; Database={2}; UID={3}; Password={4}" , ConfigConstants . DATABASE_HOST , ConfigConstants . DATABASE_PORT , ConfigConstants . DATABASE_NAME , ConfigConstants . DATABASE_USERNAME , ConfigConstants . DATABASE_PASSWORD ) ) )
{
try
{
conn . Open ( ) ;
//Load Last 5 Completed
string query = @ "
INSERT INTO server_zones VALUES ( @id , NULL , @placename , false , false , false , false ) ";
MySqlCommand cmd = new MySqlCommand ( query , conn ) ;
cmd . Parameters . AddWithValue ( "@id" , 100 ) ;
cmd . Parameters . AddWithValue ( "@placename" , "" ) ;
cmd . Prepare ( ) ;
Dictionary < uint , string > placenames = new Dictionary < uint , string > ( ) ;
string line2 ;
Regex csvSplit2 = new Regex ( "(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)" , RegexOptions . Compiled ) ;
System . IO . StreamReader file2 = new System . IO . StreamReader ( "D:\\Coding\\FFXIV Related\\FFXIV Tool\\2012.09.19.0001.decode.csv\\xtx_placeName.csv" ) ;
while ( ( line2 = file2 . ReadLine ( ) ) ! = null )
{
MatchCollection matches = csvSplit2 . Matches ( line2 ) ;
uint id ;
string name ;
try
{
id = UInt32 . Parse ( matches [ 0 ] . Value . Trim ( ',' ) ) ;
name = matches [ 2 ] . Value . Trim ( ',' ) ;
}
2019-05-04 20:53:08 -04:00
catch ( FormatException )
2016-01-17 01:50:38 -05:00
{ continue ; }
placenames . Add ( id , name ) ;
}
string line ;
Regex csvSplit = new Regex ( "(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)" , RegexOptions . Compiled ) ;
System . IO . StreamReader file = new System . IO . StreamReader ( "D:\\Coding\\FFXIV Related\\FFXIV Tool\\2012.09.19.0001.decode.csv\\_zoneParam.csv" ) ;
while ( ( line = file . ReadLine ( ) ) ! = null )
{
MatchCollection matches = csvSplit . Matches ( line ) ;
uint id ;
uint pId ;
try
{
id = UInt32 . Parse ( matches [ 0 ] . Value . Trim ( ',' ) ) ;
pId = UInt32 . Parse ( matches [ 1 ] . Value . Trim ( ',' ) ) ;
}
2019-05-04 20:53:08 -04:00
catch ( FormatException )
2016-01-17 01:50:38 -05:00
{ continue ; }
cmd . Parameters [ "@id" ] . Value = id ;
cmd . Parameters [ "@placename" ] . Value = placenames [ pId ] ;
2016-06-14 05:09:30 +01:00
Program . Log . Debug ( "Wrote: {0}" , id ) ;
2016-01-17 01:50:38 -05:00
cmd . ExecuteNonQuery ( ) ;
}
}
catch ( MySqlException e )
2016-06-08 22:29:04 +01:00
{
2016-06-12 20:12:59 +01:00
Program . Log . Error ( e . ToString ( ) ) ;
2016-06-08 22:29:04 +01:00
}
2016-01-17 01:50:38 -05:00
finally
{
conn . Dispose ( ) ;
}
}
}
2016-06-14 21:29:10 +01:00
public static void GenerateActors ( )
2016-01-17 01:50:38 -05:00
{
using ( MySqlConnection conn = new MySqlConnection ( String . Format ( "Server={0}; Port={1}; Database={2}; UID={3}; Password={4}" , ConfigConstants . DATABASE_HOST , ConfigConstants . DATABASE_PORT , ConfigConstants . DATABASE_NAME , ConfigConstants . DATABASE_USERNAME , ConfigConstants . DATABASE_PASSWORD ) ) )
{
try
{
conn . Open ( ) ;
//Load Last 5 Completed
string query = @ "
INSERT INTO gamedata_actor_templates VALUES ( @id , @displayNameId , NULL ) ";
MySqlCommand cmd = new MySqlCommand ( query , conn ) ;
cmd . Parameters . AddWithValue ( "@id" , 100 ) ;
cmd . Parameters . AddWithValue ( "@displayNameId" , 100 ) ;
cmd . Prepare ( ) ;
string line , line2 ;
Regex csvSplit = new Regex ( "(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)" , RegexOptions . Compiled ) ;
System . IO . StreamReader file = new System . IO . StreamReader ( "D:\\Coding\\FFXIV Related\\FFXIV Tool\\2012.09.19.0001.decode.csv\\actorclass.csv" ) ;
while ( ( line = file . ReadLine ( ) ) ! = null )
{
MatchCollection matches = csvSplit . Matches ( line ) ;
uint id ;
uint nameId ;
try
{
id = UInt32 . Parse ( matches [ 0 ] . Value . Trim ( ',' ) ) ;
nameId = UInt32 . Parse ( matches [ 6 ] . Value . Trim ( ',' ) ) ;
}
2019-05-04 20:53:08 -04:00
catch ( FormatException )
2016-01-17 01:50:38 -05:00
{ continue ; }
cmd . Parameters [ "@id" ] . Value = id ;
cmd . Parameters [ "@displayNameId" ] . Value = nameId ;
2016-06-14 05:09:30 +01:00
Program . Log . Debug ( "Wrote: {0} : {1}" , id , nameId ) ;
2016-01-17 01:50:38 -05:00
cmd . ExecuteNonQuery ( ) ;
}
}
catch ( MySqlException e )
2016-06-08 22:29:04 +01:00
{
2016-06-12 20:12:59 +01:00
Program . Log . Error ( e . ToString ( ) ) ;
2016-06-08 22:29:04 +01:00
}
2016-01-17 01:50:38 -05:00
finally
{
conn . Dispose ( ) ;
}
}
}
2016-06-14 21:29:10 +01:00
public static void GenerateActorAppearance ( )
2016-01-17 01:50:38 -05:00
{
uint NUMFIELDS = 39 ;
using ( MySqlConnection conn = new MySqlConnection ( String . Format ( "Server={0}; Port={1}; Database={2}; UID={3}; Password={4}" , ConfigConstants . DATABASE_HOST , ConfigConstants . DATABASE_PORT , ConfigConstants . DATABASE_NAME , ConfigConstants . DATABASE_USERNAME , ConfigConstants . DATABASE_PASSWORD ) ) )
{
try
{
conn . Open ( ) ;
//Load Last 5 Completed
string query = @ "
INSERT INTO gamedata_actor_appearance VALUES ( @id , ";
for ( int i = 0 ; i < NUMFIELDS - 1 ; i + + )
query + = "@v" + i + ", " ;
query + = "@v" + ( NUMFIELDS - 1 ) + ")" ;
MySqlCommand cmd = new MySqlCommand ( query , conn ) ;
cmd . Parameters . AddWithValue ( "@id" , 0 ) ;
for ( int i = 0 ; i < NUMFIELDS ; i + + )
cmd . Parameters . AddWithValue ( "@v" + i , 100 ) ;
cmd . Prepare ( ) ;
string line ;
Regex csvSplit = new Regex ( "(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)" , RegexOptions . Compiled ) ;
//System.IO.StreamReader file = new System.IO.StreamReader("D:\\Coding\\FFXIV Related\\FFXIV Tool\\2012.09.19.0001.decode.csv\\actorclass.csv");
System . IO . StreamReader file = new System . IO . StreamReader ( "D:\\Coding\\FFXIV Related\\FFXIV Tool\\2012.09.19.0001.decode.csv\\actorclass_graphic.csv" ) ;
while ( ( line = file . ReadLine ( ) ) ! = null )
{
MatchCollection matches = csvSplit . Matches ( line ) ;
uint id ;
try
{
id = UInt32 . Parse ( matches [ 0 ] . Value . Trim ( ',' ) ) ;
for ( int i = 0 ; i < NUMFIELDS ; i + + )
cmd . Parameters [ "@v" + i ] . Value = matches [ i + 7 ] . Value . Trim ( ',' ) ;
}
2019-05-04 20:53:08 -04:00
catch ( FormatException )
2016-01-17 01:50:38 -05:00
{ continue ; }
cmd . Parameters [ "@id" ] . Value = id ;
2016-06-14 05:09:30 +01:00
Program . Log . Debug ( "Wrote: {0}" , id ) ;
2016-01-17 01:50:38 -05:00
cmd . ExecuteNonQuery ( ) ;
}
}
catch ( MySqlException e )
2016-06-08 22:29:04 +01:00
{
2016-06-12 20:12:59 +01:00
Program . Log . Error ( e . ToString ( ) ) ;
2016-06-08 22:29:04 +01:00
}
2016-01-17 01:50:38 -05:00
finally
{
conn . Dispose ( ) ;
}
}
}
2016-06-14 21:29:10 +01:00
public static void GenerateAchievementIds ( )
2016-01-17 01:50:38 -05:00
{
using ( MySqlConnection conn = new MySqlConnection ( String . Format ( "Server={0}; Port={1}; Database={2}; UID={3}; Password={4}" , ConfigConstants . DATABASE_HOST , ConfigConstants . DATABASE_PORT , ConfigConstants . DATABASE_NAME , ConfigConstants . DATABASE_USERNAME , ConfigConstants . DATABASE_PASSWORD ) ) )
{
try
{
conn . Open ( ) ;
//Load Last 5 Completed
string query = @ "
INSERT INTO gamedata_achievements VALUES ( @id , @name , @otherId , @rewardPoints ) ";
MySqlCommand cmd = new MySqlCommand ( query , conn ) ;
cmd . Parameters . AddWithValue ( "@id" , 100 ) ;
cmd . Parameters . AddWithValue ( "@name" , "Battle" ) ;
cmd . Parameters . AddWithValue ( "@otherId" , 0 ) ;
cmd . Parameters . AddWithValue ( "@rewardPoints" , 0 ) ;
cmd . Prepare ( ) ;
int otherId = 1 ;
string line , line2 ;
Regex csvSplit = new Regex ( "(?:^|,)(\"(?:[^\"]+|\"\")*\"|[^,]*)" , RegexOptions . Compiled ) ;
System . IO . StreamReader file = new System . IO . StreamReader ( "D:\\Coding\\FFXIV Related\\FFXIV Tool\\2012.09.19.0001.decode.csv\\achievement.csv" ) ;
System . IO . StreamReader file2 = new System . IO . StreamReader ( "D:\\Coding\\FFXIV Related\\FFXIV Tool\\2012.09.19.0001.decode.csv\\xtx_achievement.csv" ) ;
while ( ( line = file . ReadLine ( ) ) ! = null )
{
line2 = file2 . ReadLine ( ) ;
MatchCollection matches = csvSplit . Matches ( line ) ;
MatchCollection matches2 = csvSplit . Matches ( line2 ) ;
uint id ;
string name ;
uint points ;
try
{
id = UInt32 . Parse ( matches2 [ 0 ] . Value . Trim ( ',' ) ) ;
name = matches2 [ 9 ] . Value . Trim ( ',' ) ;
points = UInt32 . Parse ( matches [ 3 ] . Value . Trim ( ',' ) ) ;
}
2019-05-04 20:53:08 -04:00
catch ( FormatException )
2016-01-17 01:50:38 -05:00
{ continue ; }
if ( id = = 100 )
otherId = SetCompletedAchievementsPacket . CATEGORY_BATTLE ;
else if ( id = = 200 )
otherId = SetCompletedAchievementsPacket . CATEGORY_CHARACTER ;
else if ( id = = 400 )
otherId = SetCompletedAchievementsPacket . CATEGORY_CURRENCY ;
else if ( id = = 500 )
otherId = SetCompletedAchievementsPacket . CATEGORY_ITEMS ;
else if ( id = = 600 )
otherId = SetCompletedAchievementsPacket . CATEGORY_SYNTHESIS ;
else if ( id = = 700 )
otherId = SetCompletedAchievementsPacket . CATEGORY_GATHERING ;
else if ( id = = 900 )
otherId = SetCompletedAchievementsPacket . CATEGORY_MATERIA ;
else if ( id = = 1000 )
otherId = SetCompletedAchievementsPacket . CATEGORY_QUESTS ;
else if ( id = = 1200 )
otherId = SetCompletedAchievementsPacket . CATEGORY_SEASONAL_EVENTS ;
else if ( id = = 1300 )
otherId = SetCompletedAchievementsPacket . CATEGORY_DUNGEONS ;
else if ( id = = 1400 )
otherId = SetCompletedAchievementsPacket . CATEGORY_EXPLORATION ;
else if ( id = = 1500 )
otherId = SetCompletedAchievementsPacket . CATEGORY_GRAND_COMPANY ;
2016-06-14 05:09:30 +01:00
Program . Log . Debug ( "Wrote: {0} : {1} : {2} : {3}" , id , name , otherId , points ) ;
2016-01-17 01:50:38 -05:00
cmd . Parameters [ "@id" ] . Value = id ;
cmd . Parameters [ "@name" ] . Value = name ;
cmd . Parameters [ "@otherId" ] . Value = otherId ;
cmd . Parameters [ "@rewardPoints" ] . Value = points ;
cmd . ExecuteNonQuery ( ) ;
otherId + + ;
}
}
catch ( MySqlException e )
2016-06-08 22:29:04 +01:00
{
2016-06-12 20:12:59 +01:00
Program . Log . Error ( e . ToString ( ) ) ;
2016-06-08 22:29:04 +01:00
}
2016-01-17 01:50:38 -05:00
finally
{
conn . Dispose ( ) ;
}
}
}
2016-01-25 01:10:43 -05:00
2016-07-31 21:07:37 -04:00
public static void GetStaticActors ( )
2016-01-25 01:10:43 -05:00
{
using ( MemoryStream s = new MemoryStream ( File . ReadAllBytes ( "D:\\luadec\\script\\staticactorr9w.luab" ) ) )
{
using ( BinaryReader binReader = new BinaryReader ( s ) )
{
using ( StreamWriter w = File . AppendText ( "D:\\myfile.txt" ) )
{
while ( binReader . BaseStream . Position ! = binReader . BaseStream . Length )
{
2016-06-14 21:29:10 +01:00
uint id = Utils . SwapEndian ( binReader . ReadUInt32 ( ) ) | 0xA0F00000 ;
2016-01-25 01:10:43 -05:00
List < byte > list = new List < byte > ( ) ;
byte readByte ;
while ( ( readByte = binReader . ReadByte ( ) ) ! = 0 )
{ //or whatever your condition is
list . Add ( readByte ) ;
}
string output = Encoding . UTF8 . GetString ( list . ToArray ( ) ) ;
string output2 = String . Format ( "mStaticActors.Add(0x{0:x}, new {2}(0x{0:x}, \"{1}\"));" , id , output . Substring ( 1 + output . LastIndexOf ( "/" ) ) , output . Split ( '/' ) [ 1 ] ) ;
2016-06-12 20:12:59 +01:00
Program . Log . Debug ( output2 ) ;
2016-01-25 01:10:43 -05:00
w . WriteLine ( output2 ) ;
}
}
}
}
return ;
}
2016-07-31 21:07:37 -04:00
public static void GenerateScriptsForNPCs ( )
{
using ( MySqlConnection conn = new MySqlConnection ( String . Format ( "Server={0}; Port={1}; Database={2}; UID={3}; Password={4}" , ConfigConstants . DATABASE_HOST , ConfigConstants . DATABASE_PORT , ConfigConstants . DATABASE_NAME , ConfigConstants . DATABASE_USERNAME , ConfigConstants . DATABASE_PASSWORD ) ) )
{
try
{
conn . Open ( ) ;
//Load Last 5 Completed
string query = @ "
SELECT uniqueId FROM server_spawn_locations WHERE zoneId = 206 ";
MySqlCommand cmd = new MySqlCommand ( query , conn ) ;
using ( MySqlDataReader reader = cmd . ExecuteReader ( ) )
{
while ( reader . Read ( ) )
{
string name = reader . GetString ( "uniqueId" ) ;
if ( name = = null | | name . Equals ( "" ) )
continue ;
string nameCapital = name . Substring ( 0 , 1 ) . ToUpper ( ) + name . Substring ( 1 ) ;
string template = File . ReadAllText ( "D:\\Coding\\FFXIV Related\\ffxiv-classic-map-server\\FFXIVClassic Map Server\\bin\\Debug\\scripts\\unique\\wil0Town01\\PopulaceStandard\\bertram.lua" ) ;
template = template . Replace ( "defaultWil" , "defaultFst" ) ;
template = template . Replace ( "DftWil" , "DftFst" ) ;
template = template . Replace ( "Bertram" , nameCapital ) ;
File . WriteAllText ( String . Format ( "D:\\Coding\\FFXIV Related\\ffxiv-classic-map-server\\FFXIVClassic Map Server\\bin\\Debug\\scripts\\unique\\fst0Town01a\\PopulaceStandard\\{0}.lua" , name ) , template ) ;
}
}
}
catch ( MySqlException e )
{
Program . Log . Error ( e . ToString ( ) ) ;
}
finally
{
conn . Dispose ( ) ;
}
}
}
2016-01-17 01:50:38 -05:00
}
}