MenuFileUtility.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. using System;
  2. using System.Text;
  3. using System.IO;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.Rendering;
  8. namespace COM3D2.MeidoPhotoStudio.Plugin
  9. {
  10. internal static class MenuFileUtility
  11. {
  12. private static readonly HashSet<string> accMpn = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
  13. {
  14. "accashi", "acchana", "acchat", "acchead", "accheso", "acckami", "acckamisub", "acckubi", "acckubiwa",
  15. "accmimi", "accnip", "accsenaka", "accshippo", "accude", "accxxx", "bra", "glove", "headset", "megane",
  16. "mizugi", "onepiece", "panz", "shoes", "skirt", "stkg", "wear",
  17. };
  18. private enum IMode
  19. {
  20. None, ItemChange, TexChange
  21. }
  22. public static event EventHandler MenuFilesReadyChange;
  23. public static bool MenuFilesReady { get; private set; } = false;
  24. static MenuFileUtility()
  25. {
  26. GameMain.Instance.StartCoroutine(CheckMenuDataBaseJob());
  27. }
  28. private static IEnumerator CheckMenuDataBaseJob()
  29. {
  30. if (MenuFilesReady) yield break;
  31. while (!GameMain.Instance.MenuDataBase.JobFinished()) yield return null;
  32. MenuFilesReady = true;
  33. MenuFilesReadyChange?.Invoke(null, EventArgs.Empty);
  34. yield break;
  35. }
  36. private static bool ProcScriptBin(byte[] menuBuf, ModelInfo modelInfo)
  37. {
  38. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(menuBuf), Encoding.UTF8))
  39. {
  40. string menuHeader = binaryReader.ReadString();
  41. NDebug.Assert(
  42. menuHeader == "CM3D2_MENU", "ProcScriptBin 例外 : ヘッダーファイルが不正です。" + menuHeader
  43. );
  44. binaryReader.ReadInt32(); // file version
  45. binaryReader.ReadString(); // txt path
  46. binaryReader.ReadString(); // name
  47. binaryReader.ReadString(); // category
  48. binaryReader.ReadString(); // description
  49. binaryReader.ReadInt32(); // idk (as long)
  50. string menuPropString = String.Empty;
  51. string menuPropStringTemp = String.Empty;
  52. // string tempString3 = String.Empty;
  53. string slotName = String.Empty;
  54. try
  55. {
  56. while (true)
  57. {
  58. int numberOfProps = (int)binaryReader.ReadByte();
  59. menuPropStringTemp = menuPropString;
  60. menuPropString = String.Empty;
  61. if (numberOfProps != 0)
  62. {
  63. for (int i = 0; i < numberOfProps; i++)
  64. {
  65. menuPropString = $"{menuPropString}\"{binaryReader.ReadString()}\"";
  66. }
  67. if (menuPropString != string.Empty)
  68. {
  69. string header = UTY.GetStringCom(menuPropString);
  70. string[] menuProps = UTY.GetStringList(menuPropString);
  71. if (header == "end")
  72. {
  73. break;
  74. }
  75. else if (header == "マテリアル変更")
  76. {
  77. int matNo = int.Parse(menuProps[2]);
  78. string materialFile = menuProps[3];
  79. modelInfo.MaterialChanges.Add(new MaterialChange(matNo, materialFile));
  80. }
  81. else if (header == "additem")
  82. {
  83. modelInfo.ModelFile = menuProps[1];
  84. }
  85. }
  86. }
  87. else
  88. {
  89. break;
  90. }
  91. }
  92. }
  93. catch
  94. {
  95. return false;
  96. }
  97. }
  98. return true;
  99. }
  100. private static void ProcModScriptBin(byte[] cd, GameObject go)
  101. {
  102. BinaryReader binaryReader = new BinaryReader(new MemoryStream(cd), Encoding.UTF8);
  103. string str1 = binaryReader.ReadString();
  104. NDebug.Assert(str1 == "CM3D2_MOD", "ProcModScriptBin 例外 : ヘッダーファイルが不正です。" + str1);
  105. binaryReader.ReadInt32();
  106. binaryReader.ReadString();
  107. binaryReader.ReadString();
  108. binaryReader.ReadString();
  109. binaryReader.ReadString();
  110. binaryReader.ReadString();
  111. string mpnValue = binaryReader.ReadString();
  112. MPN mpn = MPN.null_mpn;
  113. try
  114. {
  115. mpn = (MPN)Enum.Parse(typeof(MPN), mpnValue);
  116. }
  117. catch { }
  118. if (mpn != MPN.null_mpn)
  119. {
  120. binaryReader.ReadString();
  121. }
  122. string s = binaryReader.ReadString();
  123. int num2 = binaryReader.ReadInt32();
  124. Dictionary<string, byte[]> dictionary = new Dictionary<string, byte[]>();
  125. for (int i = 0; i < num2; i++)
  126. {
  127. string key = binaryReader.ReadString();
  128. int count = binaryReader.ReadInt32();
  129. byte[] value = binaryReader.ReadBytes(count);
  130. dictionary.Add(key, value);
  131. }
  132. binaryReader.Close();
  133. using (StringReader stringReader = new StringReader(s))
  134. {
  135. IMode mode = IMode.None;
  136. string slotname = String.Empty;
  137. Material material = null;
  138. int num3 = 0;
  139. string line;
  140. bool change = false;
  141. while ((line = stringReader.ReadLine()) != null)
  142. {
  143. string[] array = line.Split(new[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  144. if (array[0] == "アイテム変更" || array[0] == "マテリアル変更")
  145. {
  146. mode = IMode.ItemChange;
  147. }
  148. else if (array[0] == "テクスチャ変更")
  149. {
  150. mode = IMode.TexChange;
  151. }
  152. if (mode == IMode.ItemChange)
  153. {
  154. if (array[0] == "スロット名")
  155. {
  156. slotname = array[1];
  157. change = true;
  158. }
  159. if (change)
  160. {
  161. if (array[0] == "マテリアル番号")
  162. {
  163. num3 = int.Parse(array[1]);
  164. foreach (Transform transform in go.GetComponentsInChildren<Transform>(true))
  165. {
  166. Renderer component = transform.GetComponent<Renderer>();
  167. if (component != null && component.materials != null)
  168. {
  169. Material[] materials = component.materials;
  170. for (int k = 0; k < materials.Length; k++)
  171. {
  172. if (k == num3)
  173. {
  174. material = materials[k];
  175. break;
  176. }
  177. }
  178. }
  179. }
  180. }
  181. if (material != null)
  182. {
  183. if (array[0] == "テクスチャ設定")
  184. {
  185. ChangeTex(num3, array[1], array[2].ToLower(), dictionary, go);
  186. }
  187. else if (array[0] == "色設定")
  188. {
  189. material.SetColor(array[1],
  190. new Color(
  191. float.Parse(array[2]) / 255f,
  192. float.Parse(array[3]) / 255f,
  193. float.Parse(array[4]) / 255f,
  194. float.Parse(array[5]) / 255f
  195. )
  196. );
  197. }
  198. else if (array[0] == "数値設定")
  199. {
  200. material.SetFloat(array[1], float.Parse(array[2]));
  201. }
  202. }
  203. }
  204. }
  205. else if (mode == IMode.TexChange)
  206. {
  207. int matno = int.Parse(array[2]);
  208. ChangeTex(matno, array[3], array[4].ToLower(), dictionary, go);
  209. }
  210. }
  211. }
  212. }
  213. private static void ChangeTex(
  214. int matno, string prop, string filename, Dictionary<string, byte[]> matDict, GameObject go
  215. )
  216. {
  217. TextureResource textureResource = null;
  218. byte[] buf = matDict[filename.ToLowerInvariant()];
  219. textureResource = new TextureResource(2, 2, TextureFormat.ARGB32, null, buf);
  220. List<Renderer> list = new List<Renderer>(3);
  221. go.transform.GetComponentsInChildren<Renderer>(true, list);
  222. foreach (Renderer r in list)
  223. {
  224. if (r != null && r.material != null)
  225. {
  226. if (matno < r.materials.Length)
  227. {
  228. r.materials[matno].SetTexture(prop, null);
  229. Texture2D texture2D = textureResource.CreateTexture2D();
  230. texture2D.name = filename;
  231. r.materials[matno].SetTexture(prop, texture2D);
  232. }
  233. }
  234. }
  235. }
  236. private static GameObject LoadSkinMesh_R(string modelFileName, int layer)
  237. {
  238. byte[] buffer = null;
  239. using (AFileBase afileBase = GameUty.FileOpen(modelFileName, null))
  240. {
  241. if (afileBase.IsValid() && afileBase.GetSize() != 0)
  242. {
  243. buffer = afileBase.ReadAll();
  244. }
  245. else
  246. {
  247. Debug.LogError("invalid model");
  248. return null;
  249. }
  250. }
  251. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer), Encoding.UTF8))
  252. {
  253. GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  254. gameObject.layer = 1;
  255. GameObject gameObject2 = null;
  256. Hashtable hashtable = new Hashtable();
  257. string text = binaryReader.ReadString();
  258. if (text != "CM3D2_MESH")
  259. {
  260. NDebug.Assert("LoadSkinMesh_R 例外 : ヘッダーファイルが不正です。" + text, false);
  261. }
  262. int num = binaryReader.ReadInt32();
  263. string str = binaryReader.ReadString();
  264. gameObject.name = "_SM_" + str;
  265. string b = binaryReader.ReadString();
  266. int num2 = binaryReader.ReadInt32();
  267. List<GameObject> list = new List<GameObject>();
  268. for (int i = 0; i < num2; i++)
  269. {
  270. GameObject gameObject3 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  271. gameObject3.layer = layer;
  272. gameObject3.name = binaryReader.ReadString();
  273. list.Add(gameObject3);
  274. if (gameObject3.name == b)
  275. {
  276. gameObject2 = gameObject3;
  277. }
  278. hashtable[gameObject3.name] = gameObject3;
  279. bool flag = binaryReader.ReadByte() != 0;
  280. if (flag)
  281. {
  282. GameObject gameObject4 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  283. gameObject4.name = gameObject3.name + "_SCL_";
  284. gameObject4.transform.parent = gameObject3.transform;
  285. hashtable[gameObject3.name + "&_SCL_"] = gameObject4;
  286. }
  287. }
  288. for (int j = 0; j < num2; j++)
  289. {
  290. int num3 = binaryReader.ReadInt32();
  291. if (num3 >= 0)
  292. {
  293. list[j].transform.parent = list[num3].transform;
  294. }
  295. else
  296. {
  297. list[j].transform.parent = gameObject.transform;
  298. }
  299. }
  300. for (int k = 0; k < num2; k++)
  301. {
  302. Transform transform = list[k].transform;
  303. float x = binaryReader.ReadSingle();
  304. float y = binaryReader.ReadSingle();
  305. float z = binaryReader.ReadSingle();
  306. transform.localPosition = new Vector3(x, y, z);
  307. float x2 = binaryReader.ReadSingle();
  308. float y2 = binaryReader.ReadSingle();
  309. float z2 = binaryReader.ReadSingle();
  310. float w = binaryReader.ReadSingle();
  311. transform.localRotation = new Quaternion(x2, y2, z2, w);
  312. if (2001 <= num)
  313. {
  314. bool flag2 = binaryReader.ReadBoolean();
  315. if (flag2)
  316. {
  317. float x3 = binaryReader.ReadSingle();
  318. float y3 = binaryReader.ReadSingle();
  319. float z3 = binaryReader.ReadSingle();
  320. transform.localScale = new Vector3(x3, y3, z3);
  321. }
  322. }
  323. }
  324. int num4 = binaryReader.ReadInt32();
  325. int num5 = binaryReader.ReadInt32();
  326. int num6 = binaryReader.ReadInt32();
  327. SkinnedMeshRenderer skinnedMeshRenderer = gameObject2.AddComponent<SkinnedMeshRenderer>();
  328. skinnedMeshRenderer.updateWhenOffscreen = true;
  329. skinnedMeshRenderer.skinnedMotionVectors = false;
  330. skinnedMeshRenderer.lightProbeUsage = LightProbeUsage.Off;
  331. skinnedMeshRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
  332. skinnedMeshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
  333. Transform[] array2 = new Transform[num6];
  334. for (int l = 0; l < num6; l++)
  335. {
  336. string text2 = binaryReader.ReadString();
  337. if (!hashtable.ContainsKey(text2))
  338. {
  339. Debug.LogError("nullbone= " + text2);
  340. }
  341. else
  342. {
  343. GameObject gameObject5;
  344. if (hashtable.ContainsKey(text2 + "&_SCL_"))
  345. {
  346. gameObject5 = (GameObject)hashtable[text2 + "&_SCL_"];
  347. }
  348. else
  349. {
  350. gameObject5 = (GameObject)hashtable[text2];
  351. }
  352. array2[l] = gameObject5.transform;
  353. }
  354. }
  355. skinnedMeshRenderer.bones = array2;
  356. Mesh mesh = new Mesh();
  357. skinnedMeshRenderer.sharedMesh = mesh;
  358. Mesh mesh2 = mesh;
  359. // bodyskin.listDEL.Add(mesh2);
  360. Matrix4x4[] array4 = new Matrix4x4[num6];
  361. for (int m = 0; m < num6; m++)
  362. {
  363. for (int n = 0; n < 16; n++)
  364. {
  365. array4[m][n] = binaryReader.ReadSingle();
  366. }
  367. }
  368. mesh2.bindposes = array4;
  369. Vector3[] array5 = new Vector3[num4];
  370. Vector3[] array6 = new Vector3[num4];
  371. Vector2[] array7 = new Vector2[num4];
  372. BoneWeight[] array8 = new BoneWeight[num4];
  373. for (int num8 = 0; num8 < num4; num8++)
  374. {
  375. float num9 = binaryReader.ReadSingle();
  376. float num10 = binaryReader.ReadSingle();
  377. float new_z = binaryReader.ReadSingle();
  378. array5[num8].Set(num9, num10, new_z);
  379. num9 = binaryReader.ReadSingle();
  380. num10 = binaryReader.ReadSingle();
  381. new_z = binaryReader.ReadSingle();
  382. array6[num8].Set(num9, num10, new_z);
  383. num9 = binaryReader.ReadSingle();
  384. num10 = binaryReader.ReadSingle();
  385. array7[num8].Set(num9, num10);
  386. }
  387. mesh2.vertices = array5;
  388. mesh2.normals = array6;
  389. mesh2.uv = array7;
  390. int num11 = binaryReader.ReadInt32();
  391. if (num11 > 0)
  392. {
  393. Vector4[] array9 = new Vector4[num11];
  394. for (int num12 = 0; num12 < num11; num12++)
  395. {
  396. float x4 = binaryReader.ReadSingle();
  397. float y4 = binaryReader.ReadSingle();
  398. float z4 = binaryReader.ReadSingle();
  399. float w2 = binaryReader.ReadSingle();
  400. array9[num12] = new Vector4(x4, y4, z4, w2);
  401. }
  402. mesh2.tangents = array9;
  403. }
  404. for (int num13 = 0; num13 < num4; num13++)
  405. {
  406. array8[num13].boneIndex0 = binaryReader.ReadUInt16();
  407. array8[num13].boneIndex1 = binaryReader.ReadUInt16();
  408. array8[num13].boneIndex2 = binaryReader.ReadUInt16();
  409. array8[num13].boneIndex3 = binaryReader.ReadUInt16();
  410. array8[num13].weight0 = binaryReader.ReadSingle();
  411. array8[num13].weight1 = binaryReader.ReadSingle();
  412. array8[num13].weight2 = binaryReader.ReadSingle();
  413. array8[num13].weight3 = binaryReader.ReadSingle();
  414. }
  415. mesh2.boneWeights = array8;
  416. mesh2.subMeshCount = num5;
  417. for (int num19 = 0; num19 < num5; num19++)
  418. {
  419. int num20 = binaryReader.ReadInt32();
  420. int[] array10 = new int[num20];
  421. for (int num21 = 0; num21 < num20; num21++)
  422. {
  423. array10[num21] = (int)binaryReader.ReadUInt16();
  424. }
  425. mesh2.SetTriangles(array10, num19);
  426. }
  427. int num22 = binaryReader.ReadInt32();
  428. Material[] array11 = new Material[num22];
  429. for (int num23 = 0; num23 < num22; num23++)
  430. {
  431. Material material = ImportCM.ReadMaterial(binaryReader);
  432. array11[num23] = material;
  433. }
  434. skinnedMeshRenderer.materials = array11;
  435. return gameObject;
  436. }
  437. }
  438. public static GameObject LoadModel(string menuFile)
  439. {
  440. return LoadModel(new ItemData { MenuFile = menuFile });
  441. }
  442. public static GameObject LoadModel(ItemData menuItem)
  443. {
  444. byte[] menuBuffer = null;
  445. byte[] modMenuBuffer = null;
  446. if (menuItem.IsOfficialMod)
  447. {
  448. using (FileStream fileStream = new FileStream(menuItem.MenuFile, FileMode.Open))
  449. {
  450. if (fileStream == null || fileStream.Length == 0)
  451. {
  452. Debug.LogError("Could not open mod menu");
  453. return null;
  454. }
  455. else
  456. {
  457. modMenuBuffer = new byte[fileStream.Length];
  458. fileStream.Read(modMenuBuffer, 0, (int)fileStream.Length);
  459. }
  460. }
  461. }
  462. string menu = menuItem.IsOfficialMod ? menuItem.BaseMenuFile : menuItem.MenuFile;
  463. using (AFileBase afileBase = GameUty.FileOpen(menu))
  464. {
  465. if (afileBase == null || !afileBase.IsValid())
  466. {
  467. Debug.LogError("Could not open menu");
  468. return null;
  469. }
  470. else if (afileBase.GetSize() == 0)
  471. {
  472. Debug.LogError("Mod menu is empty");
  473. return null;
  474. }
  475. else
  476. {
  477. menuBuffer = afileBase.ReadAll();
  478. }
  479. }
  480. ModelInfo modelInfo = new ModelInfo();
  481. if (ProcScriptBin(menuBuffer, modelInfo))
  482. {
  483. GameObject gameObject = null;
  484. try
  485. {
  486. gameObject = LoadSkinMesh_R(modelInfo.ModelFile, 1);
  487. }
  488. catch
  489. {
  490. Debug.LogError($"Could not load mesh for '{menuItem.MenuFile}'");
  491. }
  492. if (gameObject != null)
  493. {
  494. foreach (MaterialChange matChange in modelInfo.MaterialChanges)
  495. {
  496. foreach (Transform transform in gameObject.transform.GetComponentInChildren<Transform>(true))
  497. {
  498. Renderer renderer = transform.GetComponent<Renderer>();
  499. if (renderer != null && renderer.material != null
  500. && matChange.MaterialIndex < renderer.materials.Length
  501. )
  502. {
  503. renderer.materials[matChange.MaterialIndex] =
  504. ImportCM.LoadMaterial(matChange.MaterialFile, null);
  505. }
  506. }
  507. }
  508. if (menuItem.IsOfficialMod)
  509. {
  510. ProcModScriptBin(modMenuBuffer, gameObject);
  511. }
  512. }
  513. return gameObject;
  514. }
  515. else
  516. {
  517. Debug.LogWarning($"Could not parse menu file '{menuItem.MenuFile}'");
  518. return null;
  519. }
  520. }
  521. public static bool ParseNativeMenuFile(int menuIndex, ItemData menuItem)
  522. {
  523. MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;
  524. menuDataBase.SetIndex(menuIndex);
  525. if (menuDataBase.GetBoDelOnly()) return false;
  526. menuItem.Category = menuDataBase.GetCategoryMpnText();
  527. if (!accMpn.Contains(menuItem.Category)) return false;
  528. menuItem.MenuFile = menuDataBase.GetMenuFileName().ToLower();
  529. if (!validBG2MenuFile(menuItem.MenuFile)) return false;
  530. menuItem.Name = menuDataBase.GetMenuName();
  531. menuItem.IconFile = menuDataBase.GetIconS();
  532. menuItem.Priority = (int)menuDataBase.GetPriority();
  533. return true;
  534. }
  535. public static bool ParseModMenuFile(string modMenuFile, ItemData menuItem)
  536. {
  537. if (!validBG2MenuFile(modMenuFile)) return false;
  538. byte[] buf = null;
  539. try
  540. {
  541. using (FileStream fileStream = new FileStream(modMenuFile, FileMode.Open))
  542. {
  543. if (fileStream == null) return false;
  544. if (fileStream.Length == 0L)
  545. {
  546. Debug.LogError($"Mod menu file '{modMenuFile}' is empty");
  547. return false;
  548. }
  549. buf = new byte[fileStream.Length];
  550. fileStream.Read(buf, 0, (int)fileStream.Length);
  551. }
  552. }
  553. catch
  554. {
  555. Debug.LogError($"Could not read mod menu file '{modMenuFile}'");
  556. return false;
  557. }
  558. if (buf == null) return false;
  559. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buf), Encoding.UTF8))
  560. {
  561. try
  562. {
  563. if (binaryReader.ReadString() != "CM3D2_MOD") return false;
  564. else
  565. {
  566. binaryReader.ReadInt32();
  567. string iconName = binaryReader.ReadString();
  568. string baseItemPath = binaryReader.ReadString().Replace(":", " ");
  569. menuItem.BaseMenuFile = Path.GetFileName(baseItemPath);
  570. menuItem.Name = binaryReader.ReadString();
  571. menuItem.Category = binaryReader.ReadString();
  572. if (!accMpn.Contains(menuItem.Category)) return false;
  573. binaryReader.ReadString();
  574. string mpnValue = binaryReader.ReadString();
  575. MPN mpn = MPN.null_mpn;
  576. try
  577. {
  578. mpn = (MPN)Enum.Parse(typeof(MPN), mpnValue, true);
  579. }
  580. catch
  581. {
  582. return false;
  583. }
  584. if (mpn != MPN.null_mpn)
  585. {
  586. binaryReader.ReadString();
  587. }
  588. binaryReader.ReadString();
  589. int size = binaryReader.ReadInt32();
  590. for (int i = 0; i < size; i++)
  591. {
  592. string key = binaryReader.ReadString();
  593. int count = binaryReader.ReadInt32();
  594. byte[] data = binaryReader.ReadBytes(count);
  595. if (string.Equals(key, iconName, StringComparison.InvariantCultureIgnoreCase))
  596. {
  597. Texture2D tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);
  598. tex.LoadImage(data);
  599. menuItem.Icon = tex;
  600. break;
  601. }
  602. }
  603. }
  604. }
  605. catch
  606. {
  607. Debug.LogWarning($"Could not parse mod menu file '{modMenuFile}'");
  608. return false;
  609. }
  610. }
  611. return true;
  612. }
  613. private static bool validBG2MenuFile(string menu)
  614. {
  615. menu = Path.GetFileNameWithoutExtension(menu).ToLower();
  616. return !(menu.EndsWith("_del") || menu.Contains("zurashi") || menu.Contains("mekure")
  617. || menu.Contains("porori") || menu.Contains("moza"));
  618. }
  619. public abstract class MenuItem
  620. {
  621. public string IconFile { get; set; }
  622. public Texture2D Icon { get; set; }
  623. }
  624. public class ItemData : MenuItem
  625. {
  626. public string MenuFile { get; set; }
  627. public string BaseMenuFile { get; set; }
  628. public string Name { get; set; }
  629. public string Category { get; set; }
  630. public int Priority { get; set; }
  631. public bool IsMod { get; set; }
  632. public bool IsOfficialMod { get; set; }
  633. public string ModelFile { get; set; }
  634. }
  635. public class CreativeItem : MenuItem
  636. {
  637. public int ID { get; set; }
  638. public string PrefabName { get; set; }
  639. }
  640. private class ModelInfo
  641. {
  642. public List<MaterialChange> MaterialChanges { get; set; } = new List<MaterialChange>();
  643. public string ModelFile { get; set; }
  644. }
  645. private struct MaterialChange
  646. {
  647. public int MaterialIndex { get; }
  648. public string MaterialFile { get; }
  649. public MaterialChange(int matno, string matf)
  650. {
  651. this.MaterialIndex = matno;
  652. this.MaterialFile = matf;
  653. }
  654. }
  655. }
  656. }