MenuModParser.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using UnityEngine;
  5. namespace COM3D2.PropMyItem.Plugin
  6. {
  7. // Token: 0x02000008 RID: 8
  8. public class MenuModParser
  9. {
  10. // Token: 0x06000027 RID: 39 RVA: 0x00002C6C File Offset: 0x00000E6C
  11. public static byte[] LoadMenuInternal(string filename)
  12. {
  13. byte[] result;
  14. try
  15. {
  16. using (AFileBase afileBase = GameUty.FileOpen(filename, null))
  17. {
  18. if (!afileBase.IsValid())
  19. {
  20. throw new Exception();
  21. }
  22. result = afileBase.ReadAll();
  23. }
  24. }
  25. catch (Exception ex)
  26. {
  27. throw ex;
  28. }
  29. return result;
  30. }
  31. // Token: 0x06000028 RID: 40 RVA: 0x00002CC4 File Offset: 0x00000EC4
  32. public static MenuInfo parseMod(string filePath)
  33. {
  34. MenuInfo menuInfo = new MenuInfo();
  35. menuInfo.Priority = 1000f;
  36. byte[] array = null;
  37. try
  38. {
  39. using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
  40. {
  41. if (fileStream == null)
  42. {
  43. return null;
  44. }
  45. array = new byte[fileStream.Length];
  46. fileStream.Read(array, 0, (int)fileStream.Length);
  47. }
  48. }
  49. catch (Exception)
  50. {
  51. }
  52. if (array == null)
  53. {
  54. return null;
  55. }
  56. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(array), Encoding.UTF8))
  57. {
  58. if (binaryReader.ReadString() != "CM3D2_MOD")
  59. {
  60. return null;
  61. }
  62. binaryReader.ReadInt32();
  63. menuInfo.IconName = binaryReader.ReadString();
  64. binaryReader.ReadString();
  65. menuInfo.ItemName = binaryReader.ReadString();
  66. string value = binaryReader.ReadString();
  67. MPN mpn = MPN.null_mpn;
  68. if (!EnumUtil.TryParse<MPN>(value, true, out mpn))
  69. {
  70. return null;
  71. }
  72. menuInfo.MPN = mpn;
  73. binaryReader.ReadString();
  74. if (!EnumUtil.TryParse<MPN>(binaryReader.ReadString(), true, out mpn))
  75. {
  76. return null;
  77. }
  78. if (mpn != MPN.null_mpn)
  79. {
  80. binaryReader.ReadString();
  81. }
  82. string text = binaryReader.ReadString();
  83. if (text.Contains("色セット"))
  84. {
  85. string[] array2 = text.Replace("\r\n", "\n").Split(new char[]
  86. {
  87. '\n'
  88. });
  89. for (int i = 0; i < array2.Length; i++)
  90. {
  91. string[] array3 = array2[i].Split(new char[]
  92. {
  93. '\t'
  94. }, StringSplitOptions.RemoveEmptyEntries);
  95. if (array3.Length > 2 && array3[0] == "色セット" && EnumUtil.TryParse<MPN>(array3[1], true, out menuInfo.ColorSetMPN))
  96. {
  97. menuInfo.ColorSetMenuName = array3[2];
  98. break;
  99. }
  100. }
  101. }
  102. int num = binaryReader.ReadInt32();
  103. for (int j = 0; j < num; j++)
  104. {
  105. string strA = binaryReader.ReadString();
  106. int count = binaryReader.ReadInt32();
  107. byte[] data = binaryReader.ReadBytes(count);
  108. if (string.Compare(strA, menuInfo.IconName, true) == 0)
  109. {
  110. menuInfo.Icon = new Texture2D(1, 1, TextureFormat.RGBA32, false);
  111. menuInfo.Icon.LoadImage(data);
  112. }
  113. }
  114. }
  115. return menuInfo;
  116. }
  117. // Token: 0x06000029 RID: 41 RVA: 0x00002F28 File Offset: 0x00001128
  118. public static MenuInfo ParseMenu(string filePath)
  119. {
  120. MenuInfo menuInfo = new MenuInfo();
  121. MenuInfo result;
  122. using (MemoryStream memoryStream = new MemoryStream(MenuModParser.LoadMenuInternal(Path.GetFileName(filePath)), false))
  123. {
  124. using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8))
  125. {
  126. if (binaryReader.ReadString() != "CM3D2_MENU")
  127. {
  128. result = null;
  129. }
  130. else
  131. {
  132. binaryReader.ReadInt32();
  133. binaryReader.ReadString();
  134. menuInfo.ItemName = binaryReader.ReadString();
  135. binaryReader.ReadString();
  136. binaryReader.ReadString().Replace("《改行》", "\n");
  137. binaryReader.ReadInt32();
  138. for (; ; )
  139. {
  140. int num = (int)binaryReader.ReadByte();
  141. if (num == 0)
  142. {
  143. goto IL_15F;
  144. }
  145. string a = binaryReader.ReadString();
  146. string[] array = new string[num - 1];
  147. for (int i = 0; i < num - 1; i++)
  148. {
  149. array[i] = binaryReader.ReadString();
  150. }
  151. if (!(a == "category"))
  152. {
  153. if (!(a == "priority"))
  154. {
  155. if (!(a == "icon") && !(a == "icons"))
  156. {
  157. if (a == "color_set")
  158. {
  159. if (!EnumUtil.TryParse<MPN>(array[0], true, out menuInfo.ColorSetMPN))
  160. {
  161. goto IL_167;
  162. }
  163. menuInfo.ColorSetMenuName = array[1];
  164. }
  165. }
  166. else
  167. {
  168. menuInfo.IconName = array[0];
  169. }
  170. }
  171. else
  172. {
  173. menuInfo.Priority = float.Parse(array[0]);
  174. }
  175. }
  176. else if (!EnumUtil.TryParse<MPN>(array[0], true, out menuInfo.MPN))
  177. {
  178. break;
  179. }
  180. }
  181. return null;
  182. IL_15F:
  183. return menuInfo;
  184. IL_167:
  185. result = null;
  186. }
  187. }
  188. }
  189. return result;
  190. }
  191. }
  192. }