Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- using System.Collections;
- using Server.Network;
- namespace Server
- {
- public static class Cliloc
- {
- private static readonly string m_ClilocFile = "Cliloc.enu";
- private static Hashtable m_Table;
- public static Hashtable Table
- {
- get { return m_Table; }
- }
- private static byte[] m_Buffer = new byte[1024];
- public static void Load()
- {
- Console.Write("Cliloc: Loading...");
- m_Table = new Hashtable();
- string path = @"/home/krhonos/runuo/Files/" + m_ClilocFile; //Core.FindDataFile(m_ClilocFile);
- if (path == null)
- {
- Console.WriteLine("Cliloc file was not found");
- Console.WriteLine("Make sure your Scripts/Misc/DataPath.cs is properly configured");
- Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
- throw new Exception(String.Format("Cliloc: {0} not found", path));
- }
- using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
- {
- bin.ReadInt32();
- bin.ReadInt16();
- while (bin.BaseStream.Length != bin.BaseStream.Position)
- {
- int number = bin.ReadInt32();
- bin.ReadByte();
- int length = bin.ReadInt16();
- if (length > m_Buffer.Length)
- m_Buffer = new byte[(length + 1023) & ~1023];
- bin.Read(m_Buffer, 0, length);
- string text = Encoding.UTF8.GetString(m_Buffer, 0, length);
- m_Table[number] = text;
- }
- }
- Console.WriteLine("done");
- }
- public static string Convert(int number, string args)
- {
- string result = (string)m_Table[number];
- if (result == null)
- return String.Format("Missing Cliloc: #{0}", number);
- if (args == null || args == "")
- return result;
- string[] split = args.Split('\t');
- StringBuilder resultBuilder = new StringBuilder(result);
- for (int i = 0; i < split.Length; i++)
- {
- int pos = result.IndexOf(String.Format("~{0}_", i + 1));
- if (pos != -1)
- {
- int endPos = result.IndexOf('~', pos + 1);
- string keyword = result.Substring(pos, endPos - pos + 1);
- resultBuilder.Replace(keyword, split[i]);
- }
- }
- return resultBuilder.ToString();
- }
- public static string Convert(int number, string args, AffixType affixType, string affix)
- {
- bool append = ((affixType & AffixType.Prepend) == 0);
- StringBuilder resultBuilder = new StringBuilder(Convert(number, args));
- if (append)
- resultBuilder.Append(affix);
- else
- resultBuilder.Insert(0, affix);
- return resultBuilder.ToString();
- }
- public static string ConvertEquipmentInfo(Item item, EquipmentInfo info)
- {
- StringBuilder resultBuilder = new StringBuilder();
- bool crafted = false;
- if (info.Crafter != null)
- {
- resultBuilder.AppendFormat("Crafted by {0}", info.Crafter.Name);
- crafted = true;
- }
- if (info.Attributes.Length != 0)
- {
- if (crafted)
- resultBuilder.Append(' ');
- resultBuilder.Append('[');
- for (int i = 0; i < info.Attributes.Length; i++)
- {
- if (i != 0)
- resultBuilder.Append('/');
- EquipInfoAttribute attr = info.Attributes[i];
- resultBuilder.Append(Cliloc.Convert(attr.Number, null));
- if (attr.Charges != -1)
- resultBuilder.AppendFormat(": {0}", attr.Charges);
- }
- resultBuilder.Append(']');
- }
- return resultBuilder.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement