EditMod.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using UnityEngine;
  6. public class EditMod : MonoBehaviour
  7. {
  8. private void Awake()
  9. {
  10. }
  11. private void OnGUI()
  12. {
  13. if (this.m_eModMode == EditMod.MOD_MODE.MOD_TEX)
  14. {
  15. GUI.TextField(new Rect(10f, 10f, 100f, 20f), this.m_mpn.ToString(), 255);
  16. if (GUI.Button(new Rect(120f, 10f, 100f, 20f), "ExportBase"))
  17. {
  18. this.ModExportBase();
  19. }
  20. this.strModPath = GUI.TextField(new Rect(240f, 10f, 400f, 20f), this.strModPath, 255);
  21. if (GUI.Button(new Rect(650f, 10f, 100f, 20f), "Compile"))
  22. {
  23. this.ModCompileDir(this.strModPath);
  24. }
  25. }
  26. else if (this.m_eModMode == EditMod.MOD_MODE.MOD_MQO)
  27. {
  28. this.strModPath = GUI.TextField(new Rect(390f, 10f, 400f, 20f), this.strModPath, 255);
  29. if (GUI.Button(new Rect(800f, 10f, 100f, 20f), "Compile"))
  30. {
  31. this.ModCompileDirMqo(this.strModPath);
  32. }
  33. }
  34. }
  35. private void ModExportBase()
  36. {
  37. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  38. maid.ExportModBaseMenu(this.m_mpn);
  39. }
  40. private void ModExportMqo(string f_strOutFileName)
  41. {
  42. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  43. maid.ExportModBaseMqo(this.m_mpn, f_strOutFileName);
  44. NDebug.MessageBox("MOD Export Complete", "MODの元ファイルを出力しました。");
  45. }
  46. private void ModCompileDir(string f_strModPath)
  47. {
  48. if (!Directory.Exists(f_strModPath))
  49. {
  50. NUty.WinMessageBox(NUty.GetWindowHandle(), "コンパイル対象のパスが見つかりません。", "MOD Compile Error", 0);
  51. return;
  52. }
  53. string[] files = Directory.GetFiles(f_strModPath, "mod_*.txt", SearchOption.TopDirectoryOnly);
  54. foreach (string f_strModMenu in files)
  55. {
  56. this.ModCompileMenu(f_strModMenu);
  57. }
  58. }
  59. private void ModCompileDirMqo(string f_strModPath)
  60. {
  61. if (!Directory.Exists(f_strModPath))
  62. {
  63. NUty.WinMessageBox(NUty.GetWindowHandle(), "コンパイル対象のパスが見つかりません。", "MQO Compile Error", 0);
  64. return;
  65. }
  66. string[] files = Directory.GetFiles(f_strModPath, "*.*", SearchOption.TopDirectoryOnly);
  67. foreach (string text in files)
  68. {
  69. if (text.Contains(".menu.txt"))
  70. {
  71. ModCompile.CompileMenuScript(text);
  72. }
  73. else if (text.Contains(".mqo"))
  74. {
  75. ModCompile.ConvMqoToModel(text);
  76. }
  77. else if (text.Contains(".png"))
  78. {
  79. ModCompile.ExportTexture(text);
  80. }
  81. else if (text.Contains(".mate.txt"))
  82. {
  83. ModCompile.ExportMaterial(text);
  84. }
  85. }
  86. NDebug.MessageBox("MOD Compile Complete", "MODファイルのコンパイルが終了しました。");
  87. }
  88. private bool ModCompileMenu(string f_strModMenu)
  89. {
  90. byte[] array = null;
  91. try
  92. {
  93. using (FileStream fileStream = new FileStream(f_strModMenu, FileMode.Open))
  94. {
  95. if (fileStream == null)
  96. {
  97. NUty.WinMessageBox(NUty.GetWindowHandle(), "コンパイル対象のメニューがありません。\n" + f_strModMenu, "MOD Compile Error", 0);
  98. return false;
  99. }
  100. array = new byte[fileStream.Length];
  101. fileStream.Read(array, 0, (int)fileStream.Length);
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. NUty.WinMessageBox(NUty.GetWindowHandle(), "ModCompileMenu MODアイテムメニューファイルが読み込めませんでした。\n " + f_strModMenu + "\n" + ex.Message, "MOD Compile Error", 0);
  107. return false;
  108. }
  109. string text = string.Empty;
  110. string value = string.Empty;
  111. string text2 = string.Empty;
  112. string value2 = string.Empty;
  113. string value3 = string.Empty;
  114. string value4 = string.Empty;
  115. string value5 = string.Empty;
  116. string text3 = string.Empty;
  117. Dictionary<string, EditMod.TexSet> dictionary = new Dictionary<string, EditMod.TexSet>();
  118. string @string = Encoding.UTF8.GetString(array);
  119. using (StringReader stringReader = new StringReader(@string))
  120. {
  121. string text4;
  122. while ((text4 = stringReader.ReadLine()) != null)
  123. {
  124. string[] array2 = text4.Split(new char[]
  125. {
  126. '\t',
  127. ' '
  128. }, StringSplitOptions.RemoveEmptyEntries);
  129. if (array2.Length != 0)
  130. {
  131. if (array2[0].IndexOf("/") != 0)
  132. {
  133. if (array2[0] == "基本アイテム")
  134. {
  135. text2 = array2[1];
  136. }
  137. else if (array2[0] == "アイテム名")
  138. {
  139. value2 = array2[1];
  140. }
  141. else if (array2[0] == "カテゴリ名")
  142. {
  143. value4 = array2[1];
  144. }
  145. else if (array2[0] == "説明")
  146. {
  147. value3 = array2[1];
  148. }
  149. else if (array2[0] == "アイコン")
  150. {
  151. array2[1] = array2[1].ToLower();
  152. value = array2[1];
  153. string text5 = Path.GetDirectoryName(f_strModMenu) + "\\";
  154. text5 += array2[1];
  155. FileStream fileStream2 = new FileStream(text5, FileMode.Open);
  156. if (fileStream2 == null)
  157. {
  158. NUty.WinMessageBox(NUty.GetWindowHandle(), "アイコンファイルが開けません。\n" + text5, "MOD Compile Error", 0);
  159. return false;
  160. }
  161. byte[] array3 = new byte[fileStream2.Length];
  162. fileStream2.Read(array3, 0, (int)fileStream2.Length);
  163. if (!dictionary.ContainsKey(array2[1].ToLower()))
  164. {
  165. dictionary.Add(array2[1].ToLower(), new EditMod.TexSet
  166. {
  167. nSize = (int)fileStream2.Length,
  168. byData = array3
  169. });
  170. }
  171. fileStream2.Close();
  172. fileStream2.Dispose();
  173. }
  174. else if (array2[0] == "色セット")
  175. {
  176. value5 = array2[1];
  177. if (array2.Length >= 3)
  178. {
  179. text3 = array2[2];
  180. }
  181. }
  182. else if (array2[0] == "テクスチャ設定")
  183. {
  184. array2[2] = array2[2].ToLower();
  185. string text6 = Path.GetDirectoryName(f_strModMenu) + "\\";
  186. text6 += array2[2];
  187. FileStream fileStream3 = new FileStream(text6, FileMode.Open);
  188. if (fileStream3 == null)
  189. {
  190. NUty.WinMessageBox(NUty.GetWindowHandle(), "テクスチャが開けません。\n" + text6, "MOD Compile Error", 0);
  191. return false;
  192. }
  193. byte[] array4 = new byte[fileStream3.Length];
  194. fileStream3.Read(array4, 0, (int)fileStream3.Length);
  195. if (!dictionary.ContainsKey(array2[2].ToLower()))
  196. {
  197. dictionary.Add(array2[2].ToLower(), new EditMod.TexSet
  198. {
  199. nSize = (int)fileStream3.Length,
  200. byData = array4
  201. });
  202. }
  203. fileStream3.Close();
  204. fileStream3.Dispose();
  205. }
  206. else if (array2[0] == "テクスチャ変更")
  207. {
  208. string text7 = array2[4].ToLower();
  209. string text8 = Path.GetDirectoryName(f_strModMenu) + "\\";
  210. string[] array5;
  211. if (text7.Contains("*"))
  212. {
  213. array5 = Directory.GetFiles(text8, text7, SearchOption.AllDirectories);
  214. }
  215. else
  216. {
  217. array5 = new string[]
  218. {
  219. text8 + text7
  220. };
  221. }
  222. foreach (string text9 in array5)
  223. {
  224. if (!File.Exists(text9))
  225. {
  226. NUty.WinMessageBox(NUty.GetWindowHandle(), "テクスチャが見つかりません。\n" + text9, "MOD Compile Error", 0);
  227. return false;
  228. }
  229. FileStream fileStream4 = new FileStream(text9, FileMode.Open);
  230. if (fileStream4 == null)
  231. {
  232. NUty.WinMessageBox(NUty.GetWindowHandle(), "テクスチャが開けません。\n" + text9, "MOD Compile Error", 0);
  233. return false;
  234. }
  235. byte[] array7 = new byte[fileStream4.Length];
  236. fileStream4.Read(array7, 0, (int)fileStream4.Length);
  237. if (!dictionary.ContainsKey(Path.GetFileName(text9).ToLower()))
  238. {
  239. dictionary.Add(Path.GetFileName(text9).ToLower(), new EditMod.TexSet
  240. {
  241. nSize = (int)fileStream4.Length,
  242. byData = array7
  243. });
  244. }
  245. fileStream4.Close();
  246. fileStream4.Dispose();
  247. }
  248. }
  249. foreach (string str in array2)
  250. {
  251. text = text + str + "\t";
  252. }
  253. text += "\n";
  254. }
  255. }
  256. }
  257. }
  258. MemoryStream memoryStream = new MemoryStream();
  259. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  260. binaryWriter.Write("CM3D2_MOD");
  261. binaryWriter.Write(1170);
  262. binaryWriter.Write(value);
  263. binaryWriter.Write(text2.ToLower());
  264. binaryWriter.Write(value2);
  265. binaryWriter.Write(value4);
  266. binaryWriter.Write(value3);
  267. if (string.IsNullOrEmpty(value5))
  268. {
  269. binaryWriter.Write(MPN.null_mpn.ToString());
  270. }
  271. else
  272. {
  273. binaryWriter.Write(value5);
  274. binaryWriter.Write(text3.ToLower());
  275. }
  276. binaryWriter.Write(text);
  277. binaryWriter.Write(dictionary.Count);
  278. foreach (KeyValuePair<string, EditMod.TexSet> keyValuePair in dictionary)
  279. {
  280. binaryWriter.Write(keyValuePair.Key);
  281. binaryWriter.Write(keyValuePair.Value.byData.Length);
  282. binaryWriter.Write(keyValuePair.Value.byData);
  283. }
  284. string text10 = Path.GetDirectoryName(f_strModMenu) + "\\_compiled\\";
  285. Directory.CreateDirectory(text10);
  286. text10 += Path.GetFileNameWithoutExtension(f_strModMenu);
  287. text10 += ".mod";
  288. File.WriteAllBytes(text10, memoryStream.ToArray());
  289. memoryStream.Close();
  290. memoryStream.Dispose();
  291. memoryStream = null;
  292. NUty.WinMessageBox(NUty.GetWindowHandle(), "MODコンパイル完了\n" + text10, "MOD Compile Completed", 0);
  293. return true;
  294. }
  295. private void Update()
  296. {
  297. if (!this.bPush && Input.GetKey(KeyCode.M) && Input.GetKey(KeyCode.O) && Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.Q))
  298. {
  299. if (this.m_eModMode != EditMod.MOD_MODE.MOD_TEX)
  300. {
  301. this.m_eModMode = EditMod.MOD_MODE.MOD_TEX;
  302. }
  303. else
  304. {
  305. this.m_eModMode = EditMod.MOD_MODE.MOD_NON;
  306. }
  307. this.bPush = true;
  308. }
  309. else if (!this.bPush && Input.GetKey(KeyCode.M) && Input.GetKey(KeyCode.O) && Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.Q))
  310. {
  311. if (this.m_eModMode != EditMod.MOD_MODE.MOD_MQO)
  312. {
  313. this.m_eModMode = EditMod.MOD_MODE.MOD_MQO;
  314. }
  315. else
  316. {
  317. this.m_eModMode = EditMod.MOD_MODE.MOD_NON;
  318. }
  319. this.bPush = true;
  320. }
  321. else if (!Input.GetKey(KeyCode.M) && !Input.GetKey(KeyCode.O) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.Q))
  322. {
  323. this.bPush = false;
  324. }
  325. }
  326. private string strModPath = string.Empty;
  327. private EditMod.MOD_MODE m_eModMode;
  328. public MPN m_mpn;
  329. private string m_strOutFileName = string.Empty;
  330. private bool bPush;
  331. private enum MOD_MODE
  332. {
  333. MOD_NON,
  334. MOD_TEX,
  335. MOD_MQO
  336. }
  337. private class TexSet
  338. {
  339. public int nSize;
  340. public byte[] byData;
  341. }
  342. }