Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using System.Collections;
  5. using Server.Network;
  6.  
  7. namespace Server
  8. {
  9. public static class Cliloc
  10. {
  11. private static readonly string m_ClilocFile = "Cliloc.enu";
  12.  
  13. private static Hashtable m_Table;
  14.  
  15. public static Hashtable Table
  16. {
  17. get { return m_Table; }
  18. }
  19.  
  20. private static byte[] m_Buffer = new byte[1024];
  21.  
  22. public static void Load()
  23. {
  24. Console.Write("Cliloc: Loading...");
  25.  
  26. m_Table = new Hashtable();
  27.  
  28. string path = @"/home/krhonos/runuo/Files/" + m_ClilocFile; //Core.FindDataFile(m_ClilocFile);
  29.  
  30. if (path == null)
  31. {
  32. Console.WriteLine("Cliloc file was not found");
  33. Console.WriteLine("Make sure your Scripts/Misc/DataPath.cs is properly configured");
  34. Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
  35.  
  36. throw new Exception(String.Format("Cliloc: {0} not found", path));
  37. }
  38.  
  39. using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
  40. {
  41. bin.ReadInt32();
  42. bin.ReadInt16();
  43.  
  44. while (bin.BaseStream.Length != bin.BaseStream.Position)
  45. {
  46. int number = bin.ReadInt32();
  47. bin.ReadByte();
  48. int length = bin.ReadInt16();
  49.  
  50. if (length > m_Buffer.Length)
  51. m_Buffer = new byte[(length + 1023) & ~1023];
  52.  
  53. bin.Read(m_Buffer, 0, length);
  54. string text = Encoding.UTF8.GetString(m_Buffer, 0, length);
  55.  
  56. m_Table[number] = text;
  57. }
  58. }
  59.  
  60. Console.WriteLine("done");
  61. }
  62.  
  63. public static string Convert(int number, string args)
  64. {
  65. string result = (string)m_Table[number];
  66.  
  67. if (result == null)
  68. return String.Format("Missing Cliloc: #{0}", number);
  69.  
  70. if (args == null || args == "")
  71. return result;
  72.  
  73. string[] split = args.Split('\t');
  74. StringBuilder resultBuilder = new StringBuilder(result);
  75.  
  76. for (int i = 0; i < split.Length; i++)
  77. {
  78. int pos = result.IndexOf(String.Format("~{0}_", i + 1));
  79.  
  80. if (pos != -1)
  81. {
  82. int endPos = result.IndexOf('~', pos + 1);
  83. string keyword = result.Substring(pos, endPos - pos + 1);
  84.  
  85. resultBuilder.Replace(keyword, split[i]);
  86. }
  87. }
  88.  
  89. return resultBuilder.ToString();
  90. }
  91.  
  92. public static string Convert(int number, string args, AffixType affixType, string affix)
  93. {
  94. bool append = ((affixType & AffixType.Prepend) == 0);
  95.  
  96. StringBuilder resultBuilder = new StringBuilder(Convert(number, args));
  97.  
  98. if (append)
  99. resultBuilder.Append(affix);
  100. else
  101. resultBuilder.Insert(0, affix);
  102.  
  103. return resultBuilder.ToString();
  104. }
  105.  
  106. public static string ConvertEquipmentInfo(Item item, EquipmentInfo info)
  107. {
  108. StringBuilder resultBuilder = new StringBuilder();
  109.  
  110. bool crafted = false;
  111.  
  112. if (info.Crafter != null)
  113. {
  114. resultBuilder.AppendFormat("Crafted by {0}", info.Crafter.Name);
  115. crafted = true;
  116. }
  117.  
  118. if (info.Attributes.Length != 0)
  119. {
  120. if (crafted)
  121. resultBuilder.Append(' ');
  122.  
  123. resultBuilder.Append('[');
  124.  
  125. for (int i = 0; i < info.Attributes.Length; i++)
  126. {
  127. if (i != 0)
  128. resultBuilder.Append('/');
  129.  
  130. EquipInfoAttribute attr = info.Attributes[i];
  131.  
  132. resultBuilder.Append(Cliloc.Convert(attr.Number, null));
  133.  
  134. if (attr.Charges != -1)
  135. resultBuilder.AppendFormat(": {0}", attr.Charges);
  136. }
  137.  
  138. resultBuilder.Append(']');
  139. }
  140.  
  141. return resultBuilder.ToString();
  142. }
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement