Program.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Newtonsoft.Json;
  6. namespace CacheReader
  7. {
  8. public class CachedItem
  9. {
  10. public string texName;
  11. public string m_strMenuName;
  12. public string m_strInfo;
  13. public string m_mpn;
  14. public string m_strCateName;
  15. public string m_eColorSetMPN;
  16. public string m_strMenuNameInColorSet;
  17. public string m_pcMultiColorID;
  18. public bool m_boDelOnly;
  19. public float m_fPriority;
  20. public bool m_bMan;
  21. }
  22. public class CacheData
  23. {
  24. public int version;
  25. public string menuHash;
  26. public string modMenuHash;
  27. public Dictionary<string, CachedItem> cachedItems;
  28. }
  29. internal class Program
  30. {
  31. private static List<string> mpnList = new List<string>
  32. {
  33. "null_mpn",
  34. "MuneL",
  35. "MuneS",
  36. "MuneTare",
  37. "RegFat",
  38. "ArmL",
  39. "Hara",
  40. "RegMeet",
  41. "KubiScl",
  42. "UdeScl",
  43. "EyeScl",
  44. "EyeSclX",
  45. "EyeSclY",
  46. "EyePosX",
  47. "EyePosY",
  48. "EyeClose",
  49. "EyeBallPosX",
  50. "EyeBallPosY",
  51. "EyeBallSclX",
  52. "EyeBallSclY",
  53. "EarNone",
  54. "EarElf",
  55. "EarRot",
  56. "EarScl",
  57. "NosePos",
  58. "NoseScl",
  59. "FaceShape",
  60. "FaceShapeSlim",
  61. "MayuShapeIn",
  62. "MayuShapeOut",
  63. "MayuX",
  64. "MayuY",
  65. "MayuRot",
  66. "HeadX",
  67. "HeadY",
  68. "DouPer",
  69. "sintyou",
  70. "koshi",
  71. "kata",
  72. "west",
  73. "MuneUpDown",
  74. "MuneYori",
  75. "MuneYawaraka",
  76. "body",
  77. "moza",
  78. "head",
  79. "hairf",
  80. "hairr",
  81. "hairt",
  82. "hairs",
  83. "hairaho",
  84. "haircolor",
  85. "skin",
  86. "acctatoo",
  87. "accnail",
  88. "underhair",
  89. "hokuro",
  90. "mayu",
  91. "lip",
  92. "eye",
  93. "eye_hi",
  94. "eye_hi_r",
  95. "chikubi",
  96. "chikubicolor",
  97. "eyewhite",
  98. "nose",
  99. "facegloss",
  100. "wear",
  101. "skirt",
  102. "mizugi",
  103. "bra",
  104. "panz",
  105. "stkg",
  106. "shoes",
  107. "headset",
  108. "glove",
  109. "acchead",
  110. "accha",
  111. "acchana",
  112. "acckamisub",
  113. "acckami",
  114. "accmimi",
  115. "accnip",
  116. "acckubi",
  117. "acckubiwa",
  118. "accheso",
  119. "accude",
  120. "accashi",
  121. "accsenaka",
  122. "accshippo",
  123. "accanl",
  124. "accvag",
  125. "megane",
  126. "accxxx",
  127. "handitem",
  128. "acchat",
  129. "onepiece",
  130. "set_maidwear",
  131. "set_mywear",
  132. "set_underwear",
  133. "set_body",
  134. "folder_eye",
  135. "folder_mayu",
  136. "folder_underhair",
  137. "folder_skin",
  138. "folder_eyewhite",
  139. "kousoku_upper",
  140. "kousoku_lower",
  141. "seieki_naka",
  142. "seieki_hara",
  143. "seieki_face",
  144. "seieki_mune",
  145. "seieki_hip",
  146. "seieki_ude",
  147. "seieki_ashi"
  148. };
  149. private static Dictionary<int, string> mpns =
  150. mpnList.ToDictionary(v => mpnList.IndexOf(v), v => v);
  151. private static Dictionary<int, string> parts = new Dictionary<int, string>
  152. {
  153. [-1] = "NONE",
  154. [0]="EYE_L",
  155. [1] = "EYE_R",
  156. [2]="HAIR",
  157. [3]="EYE_BROW",
  158. [4]="UNDER_HAIR",
  159. [5]="SKIN",
  160. [6]="NIPPLE",
  161. [7]="HAIR_OUTLINE",
  162. [8]="SKIN_OUTLINE",
  163. [9]="EYE_WHITE",
  164. [10]="MAX"
  165. };
  166. public static void Main(string[] args)
  167. {
  168. if (args.Length < 1)
  169. return;
  170. var path = args[0];
  171. if (!File.Exists(path))
  172. return;
  173. var data = new CacheData();
  174. using var br = new BinaryReader(File.OpenRead(path));
  175. try
  176. {
  177. data.version = br.ReadInt32();
  178. var menuFilesHashSize = br.ReadInt32();
  179. var menuFilesHash = br.ReadBytes(menuFilesHashSize);
  180. data.menuHash = Convert.ToBase64String(menuFilesHash);
  181. var modMenuFilesHashSize = br.ReadInt32();
  182. var modMenuFilesHash = br.ReadBytes(modMenuFilesHashSize);
  183. data.modMenuHash = Convert.ToBase64String(modMenuFilesHash);
  184. data.cachedItems = new Dictionary<string, CachedItem>();
  185. while (true)
  186. {
  187. var key = br.ReadNullableString();
  188. Console.WriteLine(key);
  189. var item = new CachedItem
  190. {
  191. texName = br.ReadNullableString(),
  192. m_strMenuName = br.ReadNullableString(),
  193. m_strInfo = br.ReadNullableString(),
  194. m_mpn =
  195. mpns.TryGetValue(br.ReadInt32(), out var val)
  196. ? val
  197. : "INVALID",
  198. m_strCateName = br.ReadNullableString(),
  199. m_eColorSetMPN =
  200. mpns.TryGetValue(br.ReadInt32(), out val)
  201. ? val
  202. : "INVALID",
  203. m_strMenuNameInColorSet = br.ReadNullableString(),
  204. m_pcMultiColorID =
  205. parts.TryGetValue(br.ReadInt32(), out val)
  206. ? val
  207. : "INVALID",
  208. m_boDelOnly = br.ReadBoolean(),
  209. m_fPriority = br.ReadSingle(),
  210. m_bMan = br.ReadBoolean()
  211. };
  212. data.cachedItems[key] = item;
  213. }
  214. }
  215. catch (FormatException e)
  216. {
  217. Console.WriteLine($"Failed to deserialize cache because {e.Message}");
  218. }
  219. catch (EndOfStreamException)
  220. {
  221. // End of file, no need to read more
  222. }
  223. File.WriteAllText("data.json", JsonConvert.SerializeObject(data, Formatting.Indented));
  224. }
  225. }
  226. internal static class BinaryExtensions
  227. {
  228. public static string ReadNullableString(this BinaryReader br)
  229. {
  230. return br.ReadBoolean() ? br.ReadString() : null;
  231. }
  232. public static void WriteNullableString(this BinaryWriter bw, string value)
  233. {
  234. bw.Write(value != null);
  235. if (value != null)
  236. bw.Write(value);
  237. }
  238. }
  239. }