public override void Load() { bool result = false; FileInfo file = new FileInfo(Path.Combine(FileManager.UoFolderPath, "Prof.txt")); if (file.Exists) { if (file.Length > 0x100000) //1megabyte limit of string file { throw new InternalBufferOverflowException($"{file.FullName} exceeds the maximum 1Megabyte allowed size for a string text file, please, check that the file is correct and not corrupted -> {file.Length} file size"); } //what if file doesn't exist? we skip section completely...directly into advanced selection TextFileParser read = new TextFileParser(File.ReadAllText(file.FullName), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' }); while (!read.IsEOF()) { List <string> strings = read.ReadTokens(); if (strings.Count > 0) { if (strings[0].ToLower() == "begin") { result = ParseFilePart(read); if (!result) { break; } } } } } Professions[new ProfessionInfo { Name = "Advanced", Localization = 1061176, Description = 1061226, Graphic = 5545, TopLevel = true, Type = PROF_TYPE.PROFESSION, DescriptionIndex = -1, TrueName = "advanced" }] = null; foreach (KeyValuePair <ProfessionInfo, List <ProfessionInfo> > kvp in Professions) { kvp.Key.Childrens = null; if (kvp.Value != null) { foreach (ProfessionInfo info in kvp.Value) { info.Childrens = null; } } } }
public override void Load() { bool result = false; FileInfo file = new FileInfo(Path.Combine(FileManager.UoFolderPath, "Prof.txt")); if (file.Exists) { //what if file doesn't exist? we skip section completely...directly into advanced selection TextFileParser read = new TextFileParser(file, new char[] { ' ', '\t', ',' }, new char[] { '#', ';' }, new char[] { '"', '"' }); while (!read.IsEOF()) { List <string> strings = read.ReadTokens(); if (strings.Count > 0) { if (strings[0].ToLower() == "begin") { result = ParseFilePart(read); if (!result) { break; } } } } } Professions[new ProfessionInfo() { Name = "Advanced", Localization = 1061176, Description = 1061226, Graphic = 5545, TopLevel = true, Type = PROF_TYPE.PROFESSION, DescriptionIndex = -1, TrueName = "advanced" }] = null; foreach (KeyValuePair <ProfessionInfo, List <ProfessionInfo> > kvp in Professions) { kvp.Key.Childrens = null; if (kvp.Value != null) { foreach (ProfessionInfo info in kvp.Value) { info.Childrens = null; } } } }
public static void Load() { string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string chair = Path.Combine(path, "chair.txt"); if (!File.Exists(chair)) { using (StreamWriter writer = new StreamWriter(chair)) { foreach (var item in _defaultTable) { writer.WriteLine($"{item.Graphic},{item.Direction1},{item.Direction2},{item.Direction3},{item.Direction4},{item.OffsetY},{item.MirrorOffsetY}"); } } } TextFileParser chairParse = new TextFileParser(File.ReadAllText(chair), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' }); while (!chairParse.IsEOF()) { List <string> ss = chairParse.ReadTokens(); if (ss != null && ss.Count >= 7) { ushort.TryParse(ss[0], out ushort graphic); sbyte.TryParse(ss[1], out sbyte d1); sbyte.TryParse(ss[2], out sbyte d2); sbyte.TryParse(ss[3], out sbyte d3); sbyte.TryParse(ss[4], out sbyte d4); sbyte.TryParse(ss[5], out sbyte offsetY); sbyte.TryParse(ss[6], out sbyte mirrorOffsetY); Table.Add(graphic, new SittingInfoData(graphic, d1, d2, d3, d4, offsetY, mirrorOffsetY, false)); } } }
public void Parse_Long_Text() { string s = " \"a # quoted\tstring\" a non quoted string #ignoredstring "; char[] delimiters = new char[] { ' ', '\t' }; char[] comments = new char[] { '#' }; char[] quotes = new char[] { '"', '"' }; bool trim = true; ClassicUO.Utility.TextFileParser parser = new TextFileParser(s, delimiters, comments, quotes); List <string> tokens = parser.ReadTokens(trim); Assert.NotEmpty(tokens); Assert.Equal(5, tokens.Count); Assert.Equal("a # quoted\tstring", tokens[0]); Assert.Equal("a", tokens[1]); Assert.Equal("non", tokens[2]); Assert.Equal("quoted", tokens[3]); Assert.Equal("string", tokens[4]); }
public static void Load() { string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string buff = Path.Combine(path, "buff.txt"); if (File.Exists(buff)) { var tempList = new List <ushort>(); TextFileParser buffParser = new TextFileParser(File.ReadAllText(buff), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' }); while (!buffParser.IsEOF()) { var buffToken = buffParser.ReadTokens(); if (buffToken != null && buffToken.Count != 0) { if (ushort.TryParse(buffToken[0], out ushort graphic)) { tempList.Add(graphic); } } } _table = tempList.ToArray(); } else { _table = _defaultTable; } }
public static void Load() { string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string cave = Path.Combine(path, "cave.txt"); string vegetation = Path.Combine(path, "vegetation.txt"); string trees = Path.Combine(path, "tree.txt"); if (!File.Exists(cave)) { using (StreamWriter writer = new StreamWriter(cave)) { for (int i = 0x053B; i < 0x0553 + 1; i++) { if (i != 0x0550) { writer.WriteLine(i); } } } } if (!File.Exists(vegetation)) { using (StreamWriter writer = new StreamWriter(vegetation)) { ushort[] vegetationTiles = { 0x0D45, 0x0D46, 0x0D47, 0x0D48, 0x0D49, 0x0D4A, 0x0D4B, 0x0D4C, 0x0D4D, 0x0D4E, 0x0D4F, 0x0D50, 0x0D51, 0x0D52, 0x0D53, 0x0D54, 0x0D5C, 0x0D5D, 0x0D5E, 0x0D5F, 0x0D60, 0x0D61, 0x0D62, 0x0D63, 0x0D64, 0x0D65, 0x0D66, 0x0D67, 0x0D68, 0x0D69, 0x0D6D, 0x0D73, 0x0D74, 0x0D75, 0x0D76, 0x0D77, 0x0D78, 0x0D79, 0x0D7A, 0x0D7B, 0x0D7C, 0x0D7D, 0x0D7E, 0x0D7F, 0x0D80, 0x0D83, 0x0D87, 0x0D88, 0x0D89, 0x0D8A, 0x0D8B, 0x0D8C, 0x0D8D, 0x0D8E, 0x0D8F, 0x0D90, 0x0D91, 0x0D93, 0x12B6, 0x12B7, 0x12BC, 0x12BD, 0x12BE, 0x12BF, 0x12C0, 0x12C1, 0x12C2, 0x12C3, 0x12C4, 0x12C5, 0x12C6, 0x12C7, 0x0CB9, 0x0CBC, 0x0CBD, 0x0CBE, 0x0CBF, 0x0CC0, 0x0CC1, 0x0CC3, 0x0CC5, 0x0CC6, 0x0CC7, 0x0CF3, 0x0CF4, 0x0CF5, 0x0CF6, 0x0CF7, 0x0D04, 0x0D06, 0x0D07, 0x0D08, 0x0D09, 0x0D0A, 0x0D0B, 0x0D0C, 0x0D0D, 0x0D0E, 0x0D0F, 0x0D10, 0x0D11, 0x0D12, 0x0D13, 0x0D14, 0x0D15, 0x0D16, 0x0D17, 0x0D18, 0x0D19, 0x0D28, 0x0D29, 0x0D2A, 0x0D2B, 0x0D2D, 0x0D34, 0x0D36, 0x0DAE, 0x0DAF, 0x0DBA, 0x0DBB, 0x0DBC, 0x0DBD, 0x0DBE, 0x0DC1, 0x0DC2, 0x0DC3, 0x0C83, 0x0C84, 0x0C85, 0x0C86, 0x0C87, 0x0C88, 0x0C89, 0x0C8A, 0x0C8B, 0x0C8C, 0x0C8D, 0x0C8E, 0x0C93, 0x0C94, 0x0C98, 0x0C9F, 0x0CA0, 0x0CA1, 0x0CA2, 0x0CA3, 0x0CA4, 0x0CA7, 0x0CAC, 0x0CAD, 0x0CAE, 0x0CAF, 0x0CB0, 0x0CB1, 0x0CB2, 0x0CB3, 0x0CB4, 0x0CB5, 0x0CB6, 0x0C45, 0x0C46, 0x0C49, 0x0C47, 0x0C48, 0x0C4A, 0x0C4B, 0x0C4C, 0x0C4D, 0x0C4E, 0x0C37, 0x0C38, 0x0CBA, 0x0D2F, 0x0D32, 0x0D33, 0x0D3F, 0x0D40, 0x0CE9 }; for (int i = 0; i < vegetationTiles.Length; i++) { ushort g = vegetationTiles[i]; if (TileDataLoader.Instance.StaticData[g].IsImpassable) { continue; } writer.WriteLine(g); } } } if (!File.Exists(trees)) { using (StreamWriter writer = new StreamWriter(trees)) using (StreamWriter writerveg = new StreamWriter(vegetation, true)) { ushort[] treeTiles = { 0x0CCA, 0x0CCB, 0x0CCC, 0x0CCD, 0x0CD0, 0x0CD3, 0x0CD6, 0x0CD8, 0x0CDA, 0x0CDD, 0x0CE0, 0x0CE3, 0x0CE6, 0x0D41, 0x0D42, 0x0D43, 0x0D44, 0x0D57, 0x0D58, 0x0D59, 0x0D5A, 0x0D5B, 0x0D6E, 0x0D6F, 0x0D70, 0x0D71, 0x0D72, 0x0D84, 0x0D85, 0x0D86, 0x0D94, 0x0D98, 0x0D9C, 0x0DA0, 0x0DA4, 0x0DA8, 0x0C9E, 0x0CA8, 0x0CAA, 0x0CAB, 0x0CC9, 0x0CF8, 0x0CFB, 0x0CFE, 0x0D01, 0x12B6, 0x12B7, 0x12B8, 0x12B9, 0x12BA, 0x12BB, 0x12BC, 0x12BD }; for (int i = 0; i < treeTiles.Length; i++) { ushort graphic = treeTiles[i]; byte flag = 1; switch (graphic) { case 0x0C9E: case 0x0CA8: case 0x0CAA: case 0x0CAB: case 0x0CC9: case 0x0CF8: case 0x0CFB: case 0x0CFE: case 0x0D01: case 0x12B6: case 0x12B7: case 0x12B8: case 0x12B9: case 0x12BA: case 0x12BB: flag = 0; break; } if (!TileDataLoader.Instance.StaticData[graphic].IsImpassable) { writerveg.WriteLine(graphic); } else { writer.WriteLine($"{graphic}={flag}"); } } } } TextFileParser caveParser = new TextFileParser (File.ReadAllText(cave), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' }); while (!caveParser.IsEOF()) { List <string> ss = caveParser.ReadTokens(); if (ss != null && ss.Count != 0) { if (ushort.TryParse(ss[0], out ushort graphic)) { _filteredTiles[graphic] |= STATIC_TILES_FILTER_FLAGS.STFF_CAVE; CaveTiles.Add(graphic); } } } TextFileParser stumpsParser = new TextFileParser (File.ReadAllText(trees), new[] { ' ', '\t', ',', '=' }, new[] { '#', ';' }, new[] { '"', '"' }); while (!stumpsParser.IsEOF()) { List <string> ss = stumpsParser.ReadTokens(); if (ss != null && ss.Count >= 2) { STATIC_TILES_FILTER_FLAGS flag = STATIC_TILES_FILTER_FLAGS.STFF_STUMP; if (byte.TryParse(ss[1], out byte f) && f != 0) { flag |= STATIC_TILES_FILTER_FLAGS.STFF_STUMP_HATCHED; } if (ushort.TryParse(ss[0], out ushort graphic)) { _filteredTiles[graphic] |= flag; TreeTiles.Add(graphic); } } } TextFileParser vegetationParser = new TextFileParser (File.ReadAllText(vegetation), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' }); while (!vegetationParser.IsEOF()) { List <string> ss = vegetationParser.ReadTokens(); if (ss != null && ss.Count != 0) { if (ushort.TryParse(ss[0], out ushort graphic)) { _filteredTiles[graphic] |= STATIC_TILES_FILTER_FLAGS.STFF_VEGETATION; } } } }
public static void BuildContainerFile(bool force) { string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, "containers.txt"); if (!File.Exists(path) || force) { MakeDefault(); using (StreamWriter writer = new StreamWriter(File.Create(path))) { writer.WriteLine("# FORMAT"); writer.WriteLine("# GRAPHIC OPEN_SOUND_ID CLOSE_SOUND_ID LEFT TOP RIGHT BOTTOM ICONIZED_GRAPHIC [0 if not exists] MINIMIZER_AREA_X [0 if not exists] MINIMIZER_AREA_Y [0 if not exists]"); writer.WriteLine("# LEFT = X, TOP = Y, RIGHT = X + WIDTH, BOTTOM = Y + HEIGHT"); writer.WriteLine(); writer.WriteLine(); foreach (KeyValuePair <ushort, ContainerData> e in _data) { writer.WriteLine($"{e.Value.Graphic} {e.Value.OpenSound} {e.Value.ClosedSound} {e.Value.Bounds.X} {e.Value.Bounds.Y} {e.Value.Bounds.Width} {e.Value.Bounds.Height} {e.Value.IconizedGraphic} {e.Value.MinimizerArea.X} {e.Value.MinimizerArea.Y}"); } } } _data.Clear(); TextFileParser containersParser = new TextFileParser(File.ReadAllText(path), new[] { ' ', '\t', ',' }, new[] { '#', ';' }, new[] { '"', '"' }); while (!containersParser.IsEOF()) { List <string> ss = containersParser.ReadTokens(); if (ss != null && ss.Count != 0) { if (ushort.TryParse(ss[0], out ushort graphic) && ushort.TryParse(ss[1], out ushort open_sound_id) && ushort.TryParse(ss[2], out ushort close_sound_id) && int.TryParse(ss[3], out int x) && int.TryParse(ss[4], out int y) && int.TryParse(ss[5], out int w) && int.TryParse(ss[6], out int h)) { ushort iconized_graphic = 0; int minimizer_x = 0, minimizer_y = 0; if (ss.Count >= 8 && ushort.TryParse(ss[7], out iconized_graphic)) { if (ss.Count >= 9 && int.TryParse(ss[8], out minimizer_x)) { if (ss.Count >= 10 && int.TryParse(ss[9], out minimizer_y)) { // nice! } } } _data[graphic] = new ContainerData ( graphic, open_sound_id, close_sound_id, x, y, w, h, iconized_graphic, minimizer_x, minimizer_y ); } } } }
private bool ParseFilePart(TextFileParser file) { List <string> childrens = new List <string>(); PROF_TYPE type = PROF_TYPE.NO_PROF; string name = string.Empty; string trueName = string.Empty; int nameClilocID = 0; int descriptionClilocID = 0; int descriptionIndex = 0; ushort gump = 0; bool topLevel = false; int[,] skillIndex = new int[4, 2] { { 0xFF, 0 }, { 0xFF, 0 }, { 0xFF, 0 }, { 0xFF, 0 } }; int[] stats = new int[3] { 0, 0, 0 }; bool exit = false; while (!file.IsEOF() && !exit) { List <string> strings = file.ReadTokens(); if (strings.Count < 1) { continue; } int code = GetKeyCode(strings[0]); switch ((PM_CODE)code) { case PM_CODE.BEGIN: case PM_CODE.END: { exit = true; break; } case PM_CODE.NAME: { name = strings[1]; break; } case PM_CODE.TRUENAME: { trueName = strings[1]; break; } case PM_CODE.DESC: { int.TryParse(strings[1], out descriptionIndex); break; } case PM_CODE.TOPLEVEL: { topLevel = GetKeyCode(strings[1]) == (int)PM_CODE.TRUE; break; } case PM_CODE.GUMP: { ushort.TryParse(strings[1], out gump); break; } case PM_CODE.TYPE: { if (GetKeyCode(strings[1]) == (int)PM_CODE.CATEGORY) { type = PROF_TYPE.CATEGORY; } else { type = PROF_TYPE.PROFESSION; } break; } case PM_CODE.CHILDREN: { for (int j = 1; j < strings.Count; j++) { childrens.Add(strings[j]); } break; } case PM_CODE.SKILL: { if (strings.Count > 2) { int idx = 0; for (int i = 0, len = skillIndex.GetLength(0); i < len; i++) { if (skillIndex[i, 0] == 0xFF) { idx = i; break; } } for (int j = 0; j < SkillsLoader.Instance.SkillsCount; j++) { SkillEntry skill = SkillsLoader.Instance.Skills[j]; if (strings[1] == skill.Name || ((SkillEntry.HardCodedName)skill.Index).ToString().ToLower() == strings[1].ToLower()) { skillIndex[idx, 0] = j; int.TryParse(strings[2], out skillIndex[idx, 1]); break; } } } break; } case PM_CODE.STAT: { if (strings.Count > 2) { code = GetKeyCode(strings[1]); int.TryParse(strings[2], out int val); if ((PM_CODE)code == PM_CODE.STR) { stats[0] = val; } else if ((PM_CODE)code == PM_CODE.INT) { stats[1] = val; } else if ((PM_CODE)code == PM_CODE.DEX) { stats[2] = val; } } break; } case PM_CODE.NAME_CLILOC_ID: { int.TryParse(strings[1], out nameClilocID); name = ClilocLoader.Instance.GetString(nameClilocID, true, name); break; } case PM_CODE.DESCRIPTION_CLILOC_ID: { int.TryParse(strings[1], out descriptionClilocID); break; } } } ProfessionInfo info = null; List <ProfessionInfo> list = null; if (type == PROF_TYPE.CATEGORY) { info = new ProfessionInfo { Childrens = childrens }; list = new List <ProfessionInfo>(); } else if (type == PROF_TYPE.PROFESSION) { info = new ProfessionInfo { StatsVal = stats, SkillDefVal = skillIndex }; } bool result = type != PROF_TYPE.NO_PROF; if (info != null) { info.Localization = nameClilocID; info.Description = descriptionClilocID; info.Name = name; info.TrueName = trueName; info.DescriptionIndex = descriptionIndex; info.TopLevel = topLevel; info.Graphic = gump; info.Type = type; if (topLevel) { Professions[info] = list; } else { foreach (KeyValuePair <ProfessionInfo, List <ProfessionInfo> > kvp in Professions) { if (kvp.Key.Childrens != null && kvp.Value != null && kvp.Key.Childrens.Contains(trueName)) { Professions[kvp.Key].Add(info); result = true; break; } } } } return(result); }
//GET AUTO LOOT LIST FROM FILE OR CREATE IT public static void LoadFile() { string path = Path.Combine(CUOEnviroment.ExecutablePath, "Data", "Client"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string ALlist = Path.Combine(path, "ALlist.txt"); string ALlistlow = Path.Combine(path, "ALlistlow.txt"); if (!File.Exists(ALlist)) { using (StreamWriter writer = new StreamWriter(ALlist)) { ushort[] items = { //NOTE - some stuff is commented out, because its above the 0x5780 (22400) LootAboveID //NOTE - some stuff is commented out, because mobs may have them equipped //STRANGELANDS //Drink //0xAD1D, 0xB069, //Food 0x1E88, 0x1E89, 0x1E90, 0x1E91, //Jars //0xAD20, 0xAD21, 0xAD22, 0xAD23, 0xAD24, //Books 0x0FBD, 0x0FBE, 0x1C13, 0x42BF, //NON STRANGELANDS ---------------------------------------------------------- //cores 0xf91, //extracts 0xefc, //phylactery 0x240, //skillscrolls 0x227a, //skillballs 0x5740, //mcd 0x42BF, //------- //backpack dye 0xeff, //shield & hair dye 0xf03, //furniture dye //0x7161, //headwear dye 0xf02, //runebook dye 0xefe, //------- //tmap 0x14EB, 0x14EC, //deed 0x14EF, 0x14F0, //------- //hanging lantern OFF BECAUSE SOME MOBS MAY HAVE EM EQUIPPED //0x0A15, 0x0A16, 0x0A17, 0x0A18, //0x0A1A, 0x0A1B, 0x0A1C, 0x0A1D, //lantern OFF BECAUSE SOME MOBS MAY HAVE EM EQUIPPED //0x0A22, 0x0A23,0x0A24, 0x0A25, //------- //cloth (folded, cut cloth) 0x175D, 0x175E, 0x175F, 0x1760, 0x1761, 0x1762, 0x1763, 0x1764, 0x1765, 0x1766, 0x1767, 0x1768, //------- //footwear OFF BECAUSE SOME MOBS MAY HAVE EM EQUIPPED //0x170B, 0x170C, 0x170D, 0x170E, 0x170F, 0x1710, 0x1711, 0x1712, //------- //statue (small) 0x42BB, //statue (big) //0xA615, //------- //skull (bossloot) //0xA9B5, ////------- //chain links //0xA8C6, }; for (int i = 0; i < items.Length; i++) { ushort graphic = items[i]; ushort amount = 9999; writer.WriteLine($"{graphic}={amount}"); } } } if (!File.Exists(ALlistlow)) { using (StreamWriter writer = new StreamWriter(ALlistlow)) { ushort[] items = { //ADD LOW PRIO STUFF HERE 0xeed, //gold 0x4202,0x0E73, //modded gold 0xF7A, 0xF7B, 0xF8C, 0xF8D, 0xF84, 0xF85, 0xF86, 0xF88, //mage reags 0xf3f //arrow }; for (int i = 0; i < items.Length; i++) { ushort graphic = items[i]; ushort amount = 9999; writer.WriteLine($"{graphic}={amount}"); } } } TextFileParser ALlistParser = new TextFileParser(File.ReadAllText(ALlist), new[] { ' ', '\t', ',', '=' }, new[] { '#', ';' }, new[] { '"', '"' }); TextFileParser ALlistParserLow = new TextFileParser(File.ReadAllText(ALlistlow), new[] { ' ', '\t', ',', '=' }, new[] { '#', ';' }, new[] { '"', '"' }); while (!ALlistParser.IsEOF()) { var ss = ALlistParser.ReadTokens(); if (ss != null && ss.Count != 0) { if (ushort.TryParse(ss[0], out ushort graphic)) { ALList.Add(graphic); } if (ushort.TryParse(ss[1], out ushort amount)) { ALList.Add(amount); } } } while (!ALlistParserLow.IsEOF()) { var ss = ALlistParserLow.ReadTokens(); if (ss != null && ss.Count != 0) { if (ushort.TryParse(ss[0], out ushort graphic)) { ALListLow.Add(graphic); } if (ushort.TryParse(ss[1], out ushort amount)) { ALListLow.Add(amount); } } } }