public CXChildVisitResult VisitStruct(CXCursor cursor, CXCursor parent, IntPtr data) { if (clang.Location_isInSystemHeader(clang.getCursorLocation(cursor)) != 0) { return(CXChildVisitResult.CXChildVisit_Continue); } if (clang.getCursorKind(cursor) != CXCursorKind.CXCursor_StructDecl) { return(CXChildVisitResult.CXChildVisit_Continue); } if (!clang.getCursorSpelling(cursor).ToString().Contains("Entry")) { return(CXChildVisitResult.CXChildVisit_Continue); } var structure = new CStructureInfo(); structure.Name = clang.getCursorSpelling(cursor).ToString(); structure.NormalizedName = structure.Name .Replace("GameObject", "Gameobject") .Replace("PvP", "Pvp") .Replace("PVP", "Pvp") .Replace("QuestXP", "QuestXp") .Replace("WMO", "Wmo") .Replace("AddOn", "Addon") .Replace("LFG", "Lfg") .Replace("POI", "Poi") .Replace("UI", "Ui") .Replace("_", ""); var suffixIndex = structure.NormalizedName.LastIndexOf("Entry"); if (suffixIndex != -1) { structure.NormalizedName = structure.NormalizedName.Remove(suffixIndex); } var handle = GCHandle.Alloc(structure); clang.visitChildren(cursor, VisitField, new CXClientData(GCHandle.ToIntPtr(handle))); handle.Free(); structure.Members.Add(new CStructureMemberInfo() { TypeName = "int32", Name = "VerifiedBuild" }); Structures.Add(structure); var localeStruct = structure.CreateLocaleTable(); if (localeStruct != null) { Structures.Add(localeStruct); } return(CXChildVisitResult.CXChildVisit_Continue); }
public CXChildVisitResult VisitStruct(CXCursor cursor, CXCursor parent, IntPtr data) { if (clang.Location_isInSystemHeader(clang.getCursorLocation(cursor)) != 0) { return(CXChildVisitResult.CXChildVisit_Continue); } if (clang.getCursorKind(cursor) != CXCursorKind.CXCursor_StructDecl) { return(CXChildVisitResult.CXChildVisit_Continue); } if (!clang.getCursorSpelling(cursor).ToString().Contains("Entry")) { return(CXChildVisitResult.CXChildVisit_Continue); } var structure = new CStructureInfo(); structure.Name = clang.getCursorSpelling(cursor).ToString().Replace("Entry", "") .Replace("GameObject", "Gameobject") .Replace("PvP", "Pvp") .Replace("QuestXP", "QuestXp") .Replace("WMO", "Wmo") .Replace("AddOn", "Addon"); var handle = GCHandle.Alloc(structure); clang.visitChildren(cursor, VisitField, new CXClientData(GCHandle.ToIntPtr(handle))); handle.Free(); var id = structure.Members.Find(m => m.Name.Equals("ID")); if (id == null) { structure.Members.Insert(0, new CStructureMemberInfo() { TypeName = "uint32", Name = "ID" }); } structure.Members.Add(new CStructureMemberInfo() { TypeName = "int16", Name = "VerifiedBuild" }); Structures.Add(structure); var localeStruct = structure.CreateLocaleTable(); if (localeStruct != null) { Structures.Add(localeStruct); } return(CXChildVisitResult.CXChildVisit_Continue); }
public CStructureInfo CreateLocaleTable() { var stringFields = Members.Where(m => m.FormattedTypeName == "LocalizedString*") .Select(m => { var m2 = new CStructureMemberInfo() { TypeName = m.TypeName, Name = m.Name.Replace("_lang", "").Replace("_loc", ""), ArraySize = m.ArraySize }; var indexOfArray = m.Name.LastIndexOf('['); if (indexOfArray != -1) { m2.Name = m2.Name.Insert(indexOfArray, "_lang"); } else { m2.Name += "_lang"; } return(m2); }).ToList(); if (stringFields.Count == 0) { return(null); } stringFields.Insert(0, new CStructureMemberInfo() { TypeName = "uint32", Name = "ID" }); stringFields.Insert(1, new CStructureMemberInfo() { TypeName = "char[4]", Name = "locale" }); stringFields.Add(new CStructureMemberInfo() { TypeName = "int16", Name = "VerifiedBuild" }); var localeStruct = new CStructureInfo(); localeStruct.Name = Name + "Locale"; localeStruct.Members = stringFields; localeStruct.IsLocale = true; return(localeStruct); }
public void ParseStructure(string name) { var structure = new CStructureInfo(); structure.Name = name.Replace("Entry", ""); structure.Members = new List<CStructureMemberInfo>(); _stream.ReadLine(); var line = _stream.ReadLine(); while (line != "};") { line = line.Trim(); var comment = line.IndexOf("//"); if (comment != -1) line = line.Substring(0, comment); if (!line.Contains('(')) { var tokens = line.Split(' ', ';', '/').Where(t => t.Length != 0).ToArray(); if (tokens.Length >= 2) { var member = new CStructureMemberInfo(); member.TypeName = tokens[0]; member.Name = tokens[1].Replace("_lang", "").Replace("_loc", ""); structure.Members.Add(member); } } line = _stream.ReadLine(); } if (name.Contains("Entry")) { structure.Members.Add(new CStructureMemberInfo() { TypeName = "int16", Name = "VerifiedBuild" }); Structures.Add(structure); var localeStruct = structure.CreateLocaleTable(); if (localeStruct != null) Structures.Add(localeStruct); } }
public CStructureInfo CreateLocaleTable() { var stringFields = Members.Where(m => m.TypeName == "LocalizedString*") .Select(m => { var m2 = new CStructureMemberInfo() { TypeName = m.TypeName, Name = m.Name.Replace("_lang", "").Replace("_loc", "") }; var indexOfArray = m.Name.LastIndexOf('['); if (indexOfArray != -1) m2.Name = m2.Name.Insert(indexOfArray, "_lang"); else m2.Name += "_lang"; return m2; }).ToList(); if (stringFields.Count == 0) return null; stringFields.Insert(0, Members.First()); stringFields.Insert(1, new CStructureMemberInfo() { TypeName = "char[4]", Name = "locale" }); stringFields.Add(new CStructureMemberInfo() { TypeName = "int16", Name = "VerifiedBuild" }); var localeStruct = new CStructureInfo(); localeStruct.Name = Name + "Locale"; localeStruct.Members = stringFields; return localeStruct; }
private static void DumpStructure(StreamWriter output, StreamWriter hotfixesCpp, StreamWriter hotfixesH, CStructureInfo structure) { output.WriteLine("--"); output.WriteLine($"-- Table structure for table `{structure.GetTableName()}`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine($"DROP TABLE IF EXISTS `{structure.GetTableName()}`;"); output.WriteLine("/*!40101 SET @saved_cs_client = @@character_set_client */;"); output.WriteLine("/*!40101 SET character_set_client = utf8 */;"); output.WriteLine($"CREATE TABLE `{structure.GetTableName()}` ("); var cppBuilder = new LimitedLineLengthStringBuilder() { WrappedLinePrefix = " \"", WrappedLineSuffix = "\"" }; if (!structure.IsLocale) { cppBuilder.AppendLine(); cppBuilder.AppendLine($" // {structure.Name}.db2"); cppBuilder.Append($" PrepareStatement(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}"); hotfixesH.WriteLine(); } else { cppBuilder.Append($" PREPARE_LOCALE_STMT(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant().Replace("_LOCALE", "")}"); } cppBuilder.Append(", \"SELECT "); foreach (var member in structure.Members) { DumpStructureMember(output, cppBuilder, member); } cppBuilder.Remove(cppBuilder.Length - 2, 2); if (!structure.GetTableName().IsSqlKeyword()) { cppBuilder.Append($" FROM {structure.GetTableName()}"); } else { cppBuilder.Append($" FROM `{structure.GetTableName()}`"); } if (!structure.IsLocale) { output.WriteLine($" PRIMARY KEY (`ID`)"); cppBuilder.Append($" ORDER BY ID DESC"); } else { cppBuilder.Append(" WHERE locale = ?"); output.WriteLine($" PRIMARY KEY (`ID`,`locale`)"); } output.WriteLine(") ENGINE=MyISAM DEFAULT CHARSET=utf8;"); output.WriteLine("/*!40101 SET character_set_client = @saved_cs_client */;"); output.WriteLine(); output.WriteLine("--"); output.WriteLine($"-- Dumping data for table `{structure.GetTableName()}`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine($"LOCK TABLES `{structure.GetTableName()}` WRITE;"); output.WriteLine($"/*!40000 ALTER TABLE `{structure.GetTableName()}` DISABLE KEYS */;"); output.WriteLine($"/*!40000 ALTER TABLE `{structure.GetTableName()}` ENABLE KEYS */;"); output.WriteLine("UNLOCK TABLES;"); output.WriteLine(); cppBuilder.Nonbreaking().Append("\", CONNECTION_SYNCH);"); hotfixesCpp.WriteLine(cppBuilder.Finalize()); hotfixesH.WriteLine($" HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()},"); }
private static void DumpStructure(StreamWriter output, StreamWriter hotfixesCpp, StreamWriter hotfixesH, StreamWriter infoH, CStructureInfo structure) { output.WriteLine("--"); output.WriteLine($"-- Table structure for table `{structure.GetTableName()}`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine($"DROP TABLE IF EXISTS `{structure.GetTableName()}`;"); output.WriteLine("/*!40101 SET @saved_cs_client = @@character_set_client */;"); output.WriteLine("/*!50503 SET character_set_client = utf8mb4 */;"); output.WriteLine($"CREATE TABLE `{structure.GetTableName()}` ("); var cppBuilder = new LimitedLineLengthStringBuilder() { WrappedLinePrefix = " \"", WrappedLineSuffix = "\"" }; var infoBuilder = new StringBuilder(); if (!structure.IsLocale) { cppBuilder.AppendLine(); cppBuilder.AppendLine($" // {structure.NormalizedName}.db2"); cppBuilder.Append($" PrepareStatement(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}"); hotfixesH.WriteLine(); infoH.WriteLine($"struct {structure.NormalizedName}LoadInfo"); infoH.WriteLine("{"); infoH.WriteLine(" static DB2LoadInfo const* Instance()"); infoH.WriteLine(" {"); infoH.WriteLine($" static DB2FieldMeta const fields[] ="); infoH.WriteLine(" {"); } else { cppBuilder.Append($" PREPARE_LOCALE_STMT(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant().Replace("_LOCALE", "")}"); } cppBuilder.Append(", \"SELECT "); foreach (var member in structure.Members) { DumpStructureMember(output, cppBuilder, infoBuilder, member); } cppBuilder.Remove(cppBuilder.Length - 2, 2); if (!structure.GetTableName().IsSqlKeyword()) { cppBuilder.Append($" FROM {structure.GetTableName()}"); } else { cppBuilder.Append($" FROM `{structure.GetTableName()}`"); } cppBuilder.Append(" WHERE (`VerifiedBuild` > 0) = ?"); if (!structure.IsLocale) { output.WriteLine($" PRIMARY KEY (`ID`,`VerifiedBuild`)"); } else { cppBuilder.Append(" AND locale = ?"); output.WriteLine(" PRIMARY KEY (`ID`,`locale`,`VerifiedBuild`)"); } output.Write(") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"); if (!structure.IsLocale) { output.WriteLine(";"); } else { output.WriteLine(); output.WriteLine("/*!50500 PARTITION BY LIST COLUMNS(locale)"); output.WriteLine("(PARTITION deDE VALUES IN ('deDE') ENGINE = InnoDB,"); output.WriteLine(" PARTITION esES VALUES IN ('esES') ENGINE = InnoDB,"); output.WriteLine(" PARTITION esMX VALUES IN ('esMX') ENGINE = InnoDB,"); output.WriteLine(" PARTITION frFR VALUES IN ('frFR') ENGINE = InnoDB,"); output.WriteLine(" PARTITION itIT VALUES IN ('itIT') ENGINE = InnoDB,"); output.WriteLine(" PARTITION koKR VALUES IN ('koKR') ENGINE = InnoDB,"); output.WriteLine(" PARTITION ptBR VALUES IN ('ptBR') ENGINE = InnoDB,"); output.WriteLine(" PARTITION ruRU VALUES IN ('ruRU') ENGINE = InnoDB,"); output.WriteLine(" PARTITION zhCN VALUES IN ('zhCN') ENGINE = InnoDB,"); output.WriteLine(" PARTITION zhTW VALUES IN ('zhTW') ENGINE = InnoDB) */;"); } output.WriteLine("/*!40101 SET character_set_client = @saved_cs_client */;"); output.WriteLine(); output.WriteLine("--"); output.WriteLine($"-- Dumping data for table `{structure.GetTableName()}`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine($"LOCK TABLES `{structure.GetTableName()}` WRITE;"); output.WriteLine($"/*!40000 ALTER TABLE `{structure.GetTableName()}` DISABLE KEYS */;"); output.WriteLine($"/*!40000 ALTER TABLE `{structure.GetTableName()}` ENABLE KEYS */;"); output.WriteLine("UNLOCK TABLES;"); output.WriteLine(); cppBuilder.Nonbreaking().Append("\", CONNECTION_SYNCH);"); hotfixesCpp.WriteLine(cppBuilder.Finalize()); hotfixesH.WriteLine($" HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()},"); if (!structure.IsLocale) { if (!structure.GetTableName().IsSqlKeyword()) { hotfixesCpp.WriteLine($" PREPARE_MAX_ID_STMT(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}, \"SELECT MAX(ID) + 1 FROM {structure.GetTableName()}\", CONNECTION_SYNCH);"); } else { hotfixesCpp.WriteLine($" PREPARE_MAX_ID_STMT(HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}, \"SELECT MAX(ID) + 1 FROM `{structure.GetTableName()}`\", CONNECTION_SYNCH);"); } hotfixesH.WriteLine($" HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant()}_MAX_ID,"); } if (!structure.IsLocale) { infoH.Write(infoBuilder.ToString()); infoH.WriteLine(" };"); infoH.WriteLine($" static DB2LoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, {structure.Name.Replace("Entry", "")}Meta::Instance(), HOTFIX_SEL_{structure.GetTableName().ToUpperInvariant().Replace("_LOCALE", "")});"); infoH.WriteLine(" return &loadInfo;"); infoH.WriteLine(" }"); infoH.WriteLine("};"); infoH.WriteLine(); } }
private static void DumpStructure(StreamWriter output, StreamWriter hotfixesCpp, StreamWriter hotfixesH, CStructureInfo structure) { output.WriteLine("--"); output.WriteLine("-- Table structure for table `" + structure.GetTableName() + "`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine("DROP TABLE IF EXISTS `" + structure.GetTableName() + "`;"); output.WriteLine("/*!40101 SET @saved_cs_client = @@character_set_client */;"); output.WriteLine("/*!40101 SET character_set_client = utf8 */;"); output.WriteLine("CREATE TABLE `" + structure.GetTableName() + "` ("); var cppBuilder = new LimitedLineLengthStringBuilder() { WrappedLinePrefix = " \"", WrappedLineSuffix = "\"" }; if (!structure.Name.Contains("Locale")) { cppBuilder.AppendLine(); cppBuilder.AppendFormatLine(" // {0}.db2", structure.Name); cppBuilder.Append(" PrepareStatement(HOTFIX_SEL_"); hotfixesH.WriteLine(); } else cppBuilder.Append(" PREPARE_LOCALE_STMT(HOTFIX_SEL_"); cppBuilder.Append(String.Format("{0}, \"SELECT ", structure.GetTableName().ToUpperInvariant().Replace("_LOCALE", ""))); foreach (var member in structure.Members) DumpStructureMember(output, cppBuilder, member); cppBuilder.Remove(cppBuilder.Length - 2, 2); cppBuilder.Append(String.Format(" FROM {0}", structure.GetTableName())); if (!structure.Name.Contains("Locale")) { output.WriteLine(String.Format(" PRIMARY KEY (`{0}`)", structure.Members.First().Name)); cppBuilder.Append(String.Format(" ORDER BY {0} DESC", structure.Members.First().Name)); } else { cppBuilder.Append(" WHERE locale = ?"); output.WriteLine(String.Format(" PRIMARY KEY (`{0}`,`locale`)", structure.Members.First().Name)); } output.WriteLine(") ENGINE=MyISAM DEFAULT CHARSET=utf8;"); output.WriteLine("/*!40101 SET character_set_client = @saved_cs_client */;"); output.WriteLine(); output.WriteLine("--"); output.WriteLine("-- Dumping data for table `" + structure.GetTableName() + "`"); output.WriteLine("--"); output.WriteLine(); output.WriteLine("LOCK TABLES `" + structure.GetTableName() + "` WRITE;"); output.WriteLine("/*!40000 ALTER TABLE `" + structure.GetTableName() + "` DISABLE KEYS */;"); output.WriteLine("/*!40000 ALTER TABLE `" + structure.GetTableName() + "` ENABLE KEYS */;"); output.WriteLine("UNLOCK TABLES;"); output.WriteLine(); cppBuilder.Nonbreaking().Append("\", CONNECTION_SYNCH);"); hotfixesCpp.WriteLine(cppBuilder.Finalize()); hotfixesH.WriteLine(String.Format(" HOTFIX_SEL_{0},", structure.GetTableName().ToUpperInvariant())); }