ModCompile.cs 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text;
  6. using System.Xml;
  7. using UnityEngine;
  8. public class ModCompile : MonoBehaviour
  9. {
  10. private void Start()
  11. {
  12. }
  13. public static bool CompileMenuScript(string f_strInMenuTextPathFileName)
  14. {
  15. string text = Path.GetDirectoryName(f_strInMenuTextPathFileName) + "\\_compiled";
  16. if (!Directory.Exists(text))
  17. {
  18. Directory.CreateDirectory(text);
  19. }
  20. string path = text + "\\" + Path.GetFileNameWithoutExtension(f_strInMenuTextPathFileName);
  21. for (int i = 0; i < 114; i++)
  22. {
  23. string[] aryDefCategoryName = ModCompile.m_aryDefCategoryName;
  24. int num = i;
  25. MPN mpn = (MPN)i;
  26. aryDefCategoryName[num] = mpn.ToString().ToLower();
  27. }
  28. ModCompile.m_aryDefSlotName = new string[(TBody.m_strDefSlotName.Length - 1) / 3];
  29. for (int j = 0; j < TBody.m_strDefSlotName.Length - 1; j++)
  30. {
  31. try
  32. {
  33. if (j % 3 == 0)
  34. {
  35. ModCompile.m_aryDefSlotName[j / 3] = TBody.m_strDefSlotName[j].ToLower();
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. NDebug.MessageBox("MOD Compile", ex.Message);
  41. }
  42. }
  43. string a = string.Empty;
  44. string text2 = string.Empty;
  45. string value = string.Empty;
  46. string value2 = string.Empty;
  47. Dictionary<int, string> dictionary = new Dictionary<int, string>();
  48. StreamReader streamReader = new StreamReader(f_strInMenuTextPathFileName, Encoding.UTF8);
  49. string text3;
  50. while ((text3 = streamReader.ReadLine()) != null)
  51. {
  52. if (!(text3 == string.Empty))
  53. {
  54. if (text3.IndexOf("/") != 0)
  55. {
  56. string a2 = UTY.GetStringCom(text3).ToLower();
  57. string[] stringList = UTY.GetStringList(text3);
  58. if (a2 == "name")
  59. {
  60. value = stringList[1];
  61. }
  62. else if (a2 == "setumei")
  63. {
  64. value2 = stringList[1];
  65. }
  66. else if (a2 == "メニューフォルダ")
  67. {
  68. a = stringList[1].ToLower();
  69. }
  70. else if (a2 == "additem")
  71. {
  72. if (stringList.Length != 3 && stringList.Length != 5 && stringList.Length != 6)
  73. {
  74. NDebug.MessageBox("MOD Compile", "AddItemは引数が3or5or6つ必要です。<AddItem> <モデルファイル名.model> <MPN> [[<アタッチ/ボーンにアタッチ>] <アタッチMPN> <アタッチ先位置名>]");
  75. return false;
  76. }
  77. string text4 = stringList[2].ToLower();
  78. string value3 = string.Empty;
  79. foreach (string text5 in ModCompile.m_aryDefSlotName)
  80. {
  81. if (text4 == text5)
  82. {
  83. value3 = text5;
  84. break;
  85. }
  86. }
  87. if (string.IsNullOrEmpty(value3))
  88. {
  89. NDebug.MessageBox("MOD Compile", "additem の " + text4 + " スロットはありません。" + f_strInMenuTextPathFileName);
  90. }
  91. }
  92. else if (a2 == "delitem")
  93. {
  94. if (stringList.Length >= 2)
  95. {
  96. string chk = stringList[1].ToLower();
  97. string value4 = Array.Find<string>(ModCompile.m_aryDefSlotName, (string s) => s == chk);
  98. if (string.IsNullOrEmpty(value4))
  99. {
  100. NDebug.MessageBox("MOD Compile", "delitem の " + chk + " カテゴリはありません。" + f_strInMenuTextPathFileName);
  101. }
  102. }
  103. }
  104. else if (a2 == "category")
  105. {
  106. text2 = stringList[1].ToLower();
  107. string chk = text2.ToLower();
  108. string text6 = Array.Find<string>(ModCompile.m_aryDefCategoryName, (string s) => s == chk);
  109. if (!string.IsNullOrEmpty(text6))
  110. {
  111. if (text2 != string.Empty && text6 != text2)
  112. {
  113. NDebug.MessageBox("MOD Compile", "category SaveItemName不明です。カテゴリ " + chk + " はありません。 " + f_strInMenuTextPathFileName);
  114. }
  115. text2 = text6;
  116. }
  117. }
  118. else if (a2 == "tex" || a2 == "テクスチャ変更")
  119. {
  120. int key = int.Parse(stringList[2]);
  121. string text7 = stringList[4];
  122. if (stringList.Length == 6)
  123. {
  124. string text8 = stringList[5];
  125. if (dictionary.ContainsKey(key))
  126. {
  127. if (dictionary[key] != text8)
  128. {
  129. NDebug.MessageBox("MOD Compile", string.Concat(new string[]
  130. {
  131. f_strInMenuTextPathFileName,
  132. "\n同じマテリアル番号が登場しましたが、過去のマテリアル番号と無限色タイプ名が違います。",
  133. text7,
  134. " にも ",
  135. dictionary[key],
  136. " を指定して下さい。"
  137. }));
  138. return false;
  139. }
  140. }
  141. else
  142. {
  143. dictionary.Add(key, text8);
  144. }
  145. }
  146. else if (dictionary.ContainsKey(key))
  147. {
  148. NDebug.MessageBox("MOD Compile", string.Concat(new string[]
  149. {
  150. f_strInMenuTextPathFileName,
  151. "\n同じマテリアル番号が登場しましたが、過去のマテリアル番号と無限色タイプ名が違います。",
  152. text7,
  153. " にも ",
  154. dictionary[key],
  155. " を指定して下さい。"
  156. }));
  157. }
  158. }
  159. else if (a2 == "アイテムパラメータ" && stringList.Length != 4)
  160. {
  161. NDebug.MessageBox("MOD Compile", "アイテムパラメータ 命令の引数が不正です。SlotNameを明示的に指定しする必要があります。アイテムパラメータ <スロット名> <変数名> <値> の順です。" + text3);
  162. }
  163. }
  164. }
  165. }
  166. if (a == string.Empty)
  167. {
  168. NDebug.MessageBox("MOD Compile", "メニューフォルダの指定がありません " + f_strInMenuTextPathFileName);
  169. a = Path.GetFileName(Path.GetDirectoryName(Path.GetDirectoryName(f_strInMenuTextPathFileName))).ToLower();
  170. }
  171. if (string.IsNullOrEmpty(text2))
  172. {
  173. NDebug.MessageBox("MOD Compile", "SaveItemNameが空です。 " + f_strInMenuTextPathFileName);
  174. }
  175. MemoryStream memoryStream = new MemoryStream();
  176. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  177. StreamReader streamReader2 = new StreamReader(f_strInMenuTextPathFileName, Encoding.UTF8);
  178. short num2 = 0;
  179. while ((text3 = streamReader2.ReadLine()) != null)
  180. {
  181. num2 += 1;
  182. if (!(text3 == string.Empty))
  183. {
  184. if (text3.IndexOf("/") != 0)
  185. {
  186. string[] stringList2 = UTY.GetStringList(text3);
  187. byte b = (byte)stringList2.Length;
  188. if (b != 0)
  189. {
  190. binaryWriter.Write(b);
  191. for (int l = 0; l < (int)b; l++)
  192. {
  193. string text9 = stringList2[l];
  194. if (l == 0)
  195. {
  196. text9 = text9.ToLower();
  197. }
  198. if (text9.Contains("\\"))
  199. {
  200. NDebug.MessageBox("MOD Compile", string.Concat(new string[]
  201. {
  202. "致命的エラー)¥ではなくスラッシュを使用してください [",
  203. text9,
  204. "] @",
  205. f_strInMenuTextPathFileName,
  206. " LineNo=",
  207. num2.ToString()
  208. }));
  209. }
  210. binaryWriter.Write(text9);
  211. }
  212. }
  213. }
  214. }
  215. }
  216. binaryWriter.Write(0);
  217. streamReader2.Close();
  218. streamReader2.Dispose();
  219. MemoryStream memoryStream2 = new MemoryStream();
  220. BinaryWriter binaryWriter2 = new BinaryWriter(memoryStream2);
  221. binaryWriter2.Write("CM3D2_MENU");
  222. binaryWriter2.Write(ModCompile.FILE_FORMAT_VERSION);
  223. binaryWriter2.Write(f_strInMenuTextPathFileName.ToLower());
  224. binaryWriter2.Write(value);
  225. binaryWriter2.Write(text2);
  226. binaryWriter2.Write(value2);
  227. binaryWriter2.Write((int)memoryStream.Length);
  228. binaryWriter2.Write(memoryStream.ToArray());
  229. File.WriteAllBytes(path, memoryStream2.ToArray());
  230. memoryStream2.Close();
  231. memoryStream2.Dispose();
  232. return true;
  233. }
  234. public static void ConvMqoToModel(string f_strMqoFile)
  235. {
  236. ModCompile.<ConvMqoToModel>c__AnonStorey8 <ConvMqoToModel>c__AnonStorey = new ModCompile.<ConvMqoToModel>c__AnonStorey8();
  237. string text = Path.GetDirectoryName(f_strMqoFile) + "\\_compiled";
  238. if (!Directory.Exists(text))
  239. {
  240. Directory.CreateDirectory(text);
  241. }
  242. string path = text + "\\" + Path.GetFileNameWithoutExtension(f_strMqoFile) + ".model";
  243. StreamReader streamReader = new StreamReader(f_strMqoFile, Encoding.UTF8, false);
  244. short num = 0;
  245. SortedDictionary<string, int> sortedDictionary = new SortedDictionary<string, int>();
  246. int num2 = 0;
  247. float num3 = 1f;
  248. string text2 = string.Empty;
  249. List<string> list = new List<string>();
  250. <ConvMqoToModel>c__AnonStorey.listExObj = new List<ModCompile.ExObjIn>();
  251. ModCompile.ExObjIn exObjIn = null;
  252. string text3;
  253. while ((text3 = streamReader.ReadLine()) != null)
  254. {
  255. num += 1;
  256. if (!(text3 == string.Empty))
  257. {
  258. if (text3.IndexOf("/") != 0)
  259. {
  260. string[] stringList = UTY.GetStringList(text3);
  261. if (stringList.Length != 0)
  262. {
  263. if (stringList[0] == "IncludeXml")
  264. {
  265. if (Path.GetExtension(stringList[1]) == ".mqx")
  266. {
  267. text2 = stringList[1];
  268. }
  269. }
  270. else if (stringList[0] == "Object")
  271. {
  272. exObjIn = new ModCompile.ExObjIn(stringList[1]);
  273. <ConvMqoToModel>c__AnonStorey.listExObj.Add(exObjIn);
  274. }
  275. else if (stringList[0] == "uid")
  276. {
  277. if (exObjIn.nUid == 0)
  278. {
  279. exObjIn.nUid = int.Parse(stringList[1]);
  280. }
  281. }
  282. else if (stringList[0] == "depth")
  283. {
  284. exObjIn.nDepth = int.Parse(stringList[1]);
  285. }
  286. else if (stringList[0] == "rotation")
  287. {
  288. float x = float.Parse(stringList[1]);
  289. float y = float.Parse(stringList[2]);
  290. float z = float.Parse(stringList[3]);
  291. exObjIn.qRotLocal = Quaternion.Euler(x, y, z);
  292. }
  293. else if (stringList[0] == "translation")
  294. {
  295. float x2 = float.Parse(stringList[1]);
  296. float y2 = float.Parse(stringList[2]);
  297. float z2 = float.Parse(stringList[3]);
  298. exObjIn.vPosLocal = new Vector3(x2, y2, z2);
  299. }
  300. else if (stringList[0] == "vertex")
  301. {
  302. int num4 = int.Parse(stringList[1]);
  303. if (num4 != 0)
  304. {
  305. Vector3[] array = new Vector3[num4];
  306. for (int i2 = 0; i2 < num4; i2++)
  307. {
  308. string[] stringList2 = UTY.GetStringList(streamReader.ReadLine());
  309. float num5 = float.Parse(stringList2[0]) * num3;
  310. float z3 = float.Parse(stringList2[1]) * num3;
  311. float num6 = float.Parse(stringList2[2]) * num3;
  312. array[i2] = new Vector3(-num5, -num6, z3);
  313. }
  314. exObjIn.vVtxs = array;
  315. }
  316. }
  317. else if (stringList[0] == "face")
  318. {
  319. int num7 = int.Parse(stringList[1]);
  320. if (num7 != 0)
  321. {
  322. int[] array2 = new int[num7 * 3];
  323. int[] array3 = new int[num7];
  324. exObjIn.nFaceCount = num7;
  325. for (int j = 0; j < num7; j++)
  326. {
  327. string text4 = streamReader.ReadLine();
  328. text4 = text4.Replace('(', ' ');
  329. text4 = text4.Replace(')', ' ');
  330. string[] stringList3 = UTY.GetStringList(text4);
  331. if (stringList3[0] != "3")
  332. {
  333. NDebug.MessageBox("MOD Compile", "err)三角形以外のポリゴンがまざっている可能性があります");
  334. return;
  335. }
  336. if (stringList3.Length != 16)
  337. {
  338. NDebug.MessageBox("MOD Compile", "err) " + text4);
  339. }
  340. else
  341. {
  342. if (stringList3[1] != "V")
  343. {
  344. NDebug.MessageBox("MOD Compile", "err) 'V' このフォーマットには対応していません");
  345. return;
  346. }
  347. if (stringList3[5] != "M")
  348. {
  349. NDebug.MessageBox("MOD Compile", "err) 'M' このフォーマットには対応していません");
  350. return;
  351. }
  352. int num8 = int.Parse(stringList3[6]);
  353. array3[j] = num8;
  354. if (num2 < num8 + 1)
  355. {
  356. num2 = num8 + 1;
  357. }
  358. ModCompile.ExFace exFace = new ModCompile.ExFace();
  359. for (int k = 0; k < 3; k++)
  360. {
  361. exFace.idx[k] = int.Parse(stringList3[2 + k]);
  362. }
  363. for (int l = 0; l < 3; l++)
  364. {
  365. Vector2 vector = new Vector2(float.Parse(stringList3[10 + l * 2]), 1f - float.Parse(stringList3[10 + l * 2 + 1]));
  366. vector.y -= 1f;
  367. exFace.uv[l] = vector;
  368. }
  369. if (!exObjIn.dicFaces.ContainsKey(num8))
  370. {
  371. exObjIn.dicFaces.Add(num8, new List<ModCompile.ExFace>());
  372. }
  373. exObjIn.dicFaces[num8].Add(exFace);
  374. }
  375. }
  376. }
  377. }
  378. else if (stringList[0] == "Material")
  379. {
  380. int num9 = int.Parse(stringList[1]);
  381. if (num9 != 0)
  382. {
  383. for (int m = 0; m < num9; m++)
  384. {
  385. string[] stringList4 = UTY.GetStringList(streamReader.ReadLine());
  386. list.Add(stringList4[0]);
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. if (string.IsNullOrEmpty(text2))
  395. {
  396. NDebug.MessageBox("MOD Compile", "MQOにIncludeXmlがありません。");
  397. return;
  398. }
  399. streamReader.Close();
  400. streamReader.Dispose();
  401. ModCompile.ExObjIn exObjIn2 = <ConvMqoToModel>c__AnonStorey.listExObj.Find((ModCompile.ExObjIn o) => o.vVtxs != null && o.strName.Contains("[main]"));
  402. if (exObjIn2 == null)
  403. {
  404. NDebug.MessageBox("MOD Compile", "MQOのメインオブジェクトが見つかりません。[main]と名前の付いたオブジェクトが必要です。");
  405. return;
  406. }
  407. exObjIn2.strName = exObjIn2.strName.Substring(6);
  408. List<ModCompile.ExObjIn> list2 = <ConvMqoToModel>c__AnonStorey.listExObj.FindAll((ModCompile.ExObjIn o) => o.vVtxs != null && o.strName.Contains("[morph]"));
  409. list2.ForEach(delegate(ModCompile.ExObjIn a)
  410. {
  411. a.strName = a.strName.Substring(7);
  412. });
  413. ModCompile.ExObjIn exObjIn3 = <ConvMqoToModel>c__AnonStorey.listExObj[0];
  414. <ConvMqoToModel>c__AnonStorey.listExObj.RemoveAt(0);
  415. for (int n = 0; n < <ConvMqoToModel>c__AnonStorey.listExObj.Count; n++)
  416. {
  417. int nMyDepth = <ConvMqoToModel>c__AnonStorey.listExObj[n].nDepth;
  418. int num10 = <ConvMqoToModel>c__AnonStorey.listExObj.FindLastIndex(n, (ModCompile.ExObjIn a) => a.nDepth == nMyDepth - 1);
  419. if (num10 != -1)
  420. {
  421. <ConvMqoToModel>c__AnonStorey.listExObj[n].oParent = <ConvMqoToModel>c__AnonStorey.listExObj[num10];
  422. }
  423. }
  424. List<ModCompile.ExObjIn> list3 = <ConvMqoToModel>c__AnonStorey.listExObj.FindAll((ModCompile.ExObjIn a) => Array.FindAll<string>(ModCompile.scl_plus, (string b) => a.strName.Contains(b)).Length != 0);
  425. foreach (ModCompile.ExObjIn exObjIn4 in list3)
  426. {
  427. exObjIn4.nSclCount++;
  428. }
  429. exObjIn2.vSharedUVs = new Vector2[exObjIn2.vVtxs.Length];
  430. foreach (KeyValuePair<int, List<ModCompile.ExFace>> keyValuePair in exObjIn2.dicFaces)
  431. {
  432. foreach (ModCompile.ExFace exFace2 in keyValuePair.Value)
  433. {
  434. for (int num11 = 0; num11 < 3; num11++)
  435. {
  436. exObjIn2.vSharedUVs[exFace2.idx[num11]] = exFace2.uv[num11];
  437. }
  438. }
  439. }
  440. List<ModCompile.ExBone> list4 = new List<ModCompile.ExBone>();
  441. string path2 = Path.GetDirectoryName(f_strMqoFile) + "\\" + text2;
  442. XmlDocument xmlDocument = new XmlDocument();
  443. xmlDocument.Load(new StreamReader(path2, Encoding.UTF8, false));
  444. XmlNode xmlNode = xmlDocument.SelectSingleNode("/MetasequoiaDocument/Plugin.56A31D20.71F282AB/BoneSet");
  445. XmlNodeList childNodes = xmlNode.ChildNodes;
  446. for (int num12 = 0; num12 < childNodes.Count; num12++)
  447. {
  448. XmlNode xmlNode2 = childNodes[num12];
  449. ModCompile.ExBone exBone = new ModCompile.ExBone(int.Parse(xmlNode2.Attributes["id"].Value), xmlNode2.Attributes["name"].Value);
  450. exBone.vPosLocalS.x = float.Parse(xmlNode2.Attributes["rtX"].Value);
  451. exBone.vPosLocalS.y = float.Parse(xmlNode2.Attributes["rtY"].Value);
  452. exBone.vPosLocalS.z = float.Parse(xmlNode2.Attributes["rtZ"].Value);
  453. exBone.bDummy = (xmlNode2.Attributes["isDummy"].Value != "0");
  454. IEnumerator enumerator4 = xmlNode2.ChildNodes.GetEnumerator();
  455. try
  456. {
  457. while (enumerator4.MoveNext())
  458. {
  459. object obj = enumerator4.Current;
  460. XmlNode xmlNode3 = (XmlNode)obj;
  461. if (xmlNode3.Name == "P")
  462. {
  463. exBone.nParentId = int.Parse(xmlNode3.Attributes["id"].Value);
  464. }
  465. else if (xmlNode3.Name == "C")
  466. {
  467. exBone.listChildId.Add(int.Parse(xmlNode3.Attributes["id"].Value));
  468. }
  469. else if (xmlNode3.Name == "W")
  470. {
  471. ModCompile.ExWeight exWeight = new ModCompile.ExWeight();
  472. exWeight.nObjIdx = int.Parse(xmlNode3.Attributes["oi"].Value);
  473. exWeight.nVtxIdx = int.Parse(xmlNode3.Attributes["vi"].Value);
  474. exWeight.fWeight = float.Parse(xmlNode3.Attributes["w"].Value);
  475. exBone.listWeights.Add(exWeight);
  476. }
  477. }
  478. }
  479. finally
  480. {
  481. IDisposable disposable;
  482. if ((disposable = (enumerator4 as IDisposable)) != null)
  483. {
  484. disposable.Dispose();
  485. }
  486. }
  487. list4.Add(exBone);
  488. }
  489. using (List<ModCompile.ExBone>.Enumerator enumerator5 = list4.GetEnumerator())
  490. {
  491. while (enumerator5.MoveNext())
  492. {
  493. ModCompile.<ConvMqoToModel>c__AnonStorey4 <ConvMqoToModel>c__AnonStorey3 = new ModCompile.<ConvMqoToModel>c__AnonStorey4();
  494. <ConvMqoToModel>c__AnonStorey3.ebDummy = enumerator5.Current;
  495. if (<ConvMqoToModel>c__AnonStorey3.ebDummy.strName == "dummy")
  496. {
  497. ModCompile.<ConvMqoToModel>c__AnonStorey5 <ConvMqoToModel>c__AnonStorey4 = new ModCompile.<ConvMqoToModel>c__AnonStorey5();
  498. <ConvMqoToModel>c__AnonStorey4.<>f__ref$4 = <ConvMqoToModel>c__AnonStorey3;
  499. ModCompile.ExBone exBone2 = list4.Find((ModCompile.ExBone b) => b.nId == <ConvMqoToModel>c__AnonStorey4.<>f__ref$4.ebDummy.nParentId);
  500. List<int> listChildId = exBone2.listChildId;
  501. for (int num13 = 0; num13 < listChildId.Count; num13++)
  502. {
  503. if (listChildId[num13] == <ConvMqoToModel>c__AnonStorey3.ebDummy.nId)
  504. {
  505. listChildId[num13] = <ConvMqoToModel>c__AnonStorey3.ebDummy.listChildId[0];
  506. }
  507. }
  508. <ConvMqoToModel>c__AnonStorey4.listChildOfDummy = <ConvMqoToModel>c__AnonStorey3.ebDummy.listChildId;
  509. int nC;
  510. for (nC = 0; nC < <ConvMqoToModel>c__AnonStorey4.listChildOfDummy.Count; nC++)
  511. {
  512. List<ModCompile.ExBone> list5 = list4.FindAll((ModCompile.ExBone b) => b.nId == <ConvMqoToModel>c__AnonStorey4.listChildOfDummy[nC]);
  513. foreach (ModCompile.ExBone exBone3 in list5)
  514. {
  515. exBone3.nParentId = <ConvMqoToModel>c__AnonStorey3.ebDummy.nParentId;
  516. }
  517. }
  518. }
  519. }
  520. }
  521. string path3 = Path.GetDirectoryName(f_strMqoFile) + "\\" + Path.GetFileNameWithoutExtension(f_strMqoFile) + ".binpo.txt";
  522. StreamReader streamReader2 = new StreamReader(path3, Encoding.UTF8, false);
  523. if (streamReader2 == null)
  524. {
  525. NDebug.MessageBox("MOD Compile", "BindPoses[.binpo.txt]がありません。");
  526. return;
  527. }
  528. while ((text3 = streamReader2.ReadLine()) != null)
  529. {
  530. if (!(text3 == string.Empty))
  531. {
  532. if (text3.IndexOf("/") != 0)
  533. {
  534. string[] t = UTY.GetStringList(text3);
  535. if (t.Length != 0)
  536. {
  537. ModCompile.ExBone exBone4 = list4.Find((ModCompile.ExBone b) => b.strName == t[0]);
  538. if (exBone4 == null)
  539. {
  540. NDebug.MessageBox("MOD Compile", "BindPosesの中にボーン" + t[0] + "がみつかりません。");
  541. return;
  542. }
  543. exBone4.bUseBindPose = true;
  544. for (int num14 = 0; num14 < 16; num14++)
  545. {
  546. exBone4.matBindPose[num14] = float.Parse(t[1 + num14]);
  547. }
  548. }
  549. }
  550. }
  551. }
  552. streamReader2.Close();
  553. streamReader2.Dispose();
  554. list4.RemoveAll((ModCompile.ExBone b) => (b.bDummy || b.listWeights.Count == 0) && !b.bUseBindPose);
  555. exObjIn2.bwSharedBonwWeight = new BoneWeight[exObjIn2.vVtxs.Length];
  556. for (int num15 = 0; num15 < list4.Count; num15++)
  557. {
  558. ModCompile.ExBone exBone5 = list4[num15];
  559. for (int num16 = 0; num16 < exBone5.listWeights.Count; num16++)
  560. {
  561. ModCompile.ExWeight exWeight2 = exBone5.listWeights[num16];
  562. if (exWeight2.nObjIdx == exObjIn2.nUid)
  563. {
  564. try
  565. {
  566. BoneWeight boneWeight = exObjIn2.bwSharedBonwWeight[exWeight2.nVtxIdx - 1];
  567. if (boneWeight.weight0 < 0.001f)
  568. {
  569. boneWeight.boneIndex0 = num15;
  570. boneWeight.weight0 = exWeight2.fWeight / 100f;
  571. }
  572. else if (boneWeight.weight1 < 0.001f)
  573. {
  574. boneWeight.boneIndex1 = num15;
  575. boneWeight.weight1 = exWeight2.fWeight / 100f;
  576. }
  577. else if (boneWeight.weight2 < 0.001f)
  578. {
  579. boneWeight.boneIndex2 = num15;
  580. boneWeight.weight2 = exWeight2.fWeight / 100f;
  581. }
  582. else if (boneWeight.weight3 < 0.001f)
  583. {
  584. boneWeight.boneIndex3 = num15;
  585. boneWeight.weight3 = exWeight2.fWeight / 100f;
  586. }
  587. else
  588. {
  589. NDebug.MessageBox("MOD Compile", "頂点に対するボーンの数が4つを超えました。" + exBone5.strName);
  590. }
  591. exObjIn2.bwSharedBonwWeight[exWeight2.nVtxIdx - 1] = boneWeight;
  592. }
  593. catch (Exception ex)
  594. {
  595. NDebug.MessageBox("MOD Compile", ex.Message);
  596. }
  597. }
  598. }
  599. }
  600. Hashtable hashtable = new Hashtable();
  601. MemoryStream memoryStream = new MemoryStream();
  602. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  603. binaryWriter.Write("CM3D2_MESH");
  604. binaryWriter.Write(1300);
  605. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(f_strMqoFile);
  606. binaryWriter.Write(fileNameWithoutExtension);
  607. binaryWriter.Write(exObjIn2.strName);
  608. binaryWriter.Write(<ConvMqoToModel>c__AnonStorey.listExObj.Count);
  609. for (int num17 = 0; num17 < <ConvMqoToModel>c__AnonStorey.listExObj.Count; num17++)
  610. {
  611. ModCompile.ExObjIn exObjIn5 = <ConvMqoToModel>c__AnonStorey.listExObj[num17];
  612. if (hashtable.ContainsKey(exObjIn5.strName))
  613. {
  614. binaryWriter.Close();
  615. NDebug.MessageBox("MOD Compile", "Compile ERROR!重複ネームあり " + exObjIn5.strName + "\n" + f_strMqoFile);
  616. return;
  617. }
  618. hashtable[exObjIn5.strName] = num17;
  619. binaryWriter.Write(exObjIn5.strName);
  620. binaryWriter.Write((byte)exObjIn5.nSclCount);
  621. }
  622. int i;
  623. for (i = 0; i < <ConvMqoToModel>c__AnonStorey.listExObj.Count; i++)
  624. {
  625. int value = <ConvMqoToModel>c__AnonStorey.listExObj.FindIndex((ModCompile.ExObjIn o) => o == <ConvMqoToModel>c__AnonStorey.listExObj[i].oParent);
  626. binaryWriter.Write(value);
  627. }
  628. for (int num18 = 0; num18 < <ConvMqoToModel>c__AnonStorey.listExObj.Count; num18++)
  629. {
  630. ModCompile.ExObjIn exObjIn6 = <ConvMqoToModel>c__AnonStorey.listExObj[num18];
  631. binaryWriter.Write(exObjIn6.vPosLocal.x);
  632. binaryWriter.Write(exObjIn6.vPosLocal.y);
  633. binaryWriter.Write(exObjIn6.vPosLocal.z);
  634. binaryWriter.Write(exObjIn6.qRotLocal.x);
  635. binaryWriter.Write(exObjIn6.qRotLocal.y);
  636. binaryWriter.Write(exObjIn6.qRotLocal.z);
  637. binaryWriter.Write(exObjIn6.qRotLocal.w);
  638. }
  639. int num19 = exObjIn2.vVtxs.Length;
  640. binaryWriter.Write(num19);
  641. binaryWriter.Write(num2);
  642. int count = list4.Count;
  643. binaryWriter.Write(count);
  644. for (int num20 = 0; num20 < count; num20++)
  645. {
  646. binaryWriter.Write(list4[num20].strName);
  647. }
  648. for (int num21 = 0; num21 < count; num21++)
  649. {
  650. Matrix4x4 matBindPose = list4[num21].matBindPose;
  651. for (int num22 = 0; num22 < 16; num22++)
  652. {
  653. binaryWriter.Write(matBindPose[num22]);
  654. }
  655. }
  656. Mesh mesh = new Mesh();
  657. mesh.vertices = exObjIn2.vVtxs;
  658. mesh.subMeshCount = num2;
  659. List<int> list6 = new List<int>();
  660. foreach (KeyValuePair<int, List<ModCompile.ExFace>> keyValuePair2 in exObjIn2.dicFaces)
  661. {
  662. List<int> list7 = new List<int>();
  663. for (int num23 = 0; num23 < keyValuePair2.Value.Count; num23++)
  664. {
  665. for (int num24 = 0; num24 < 3; num24++)
  666. {
  667. list7.Add(keyValuePair2.Value[num23].idx[num24]);
  668. }
  669. }
  670. mesh.SetTriangles(list7.ToArray(), keyValuePair2.Key);
  671. }
  672. mesh.RecalculateNormals();
  673. Vector3[] vVtxs = exObjIn2.vVtxs;
  674. Vector3[] normals = mesh.normals;
  675. Vector2[] vSharedUVs = exObjIn2.vSharedUVs;
  676. BoneWeight[] bwSharedBonwWeight = exObjIn2.bwSharedBonwWeight;
  677. for (int num25 = 0; num25 < num19; num25++)
  678. {
  679. binaryWriter.Write(vVtxs[num25].x);
  680. binaryWriter.Write(vVtxs[num25].y);
  681. binaryWriter.Write(vVtxs[num25].z);
  682. binaryWriter.Write(normals[num25].x);
  683. binaryWriter.Write(normals[num25].y);
  684. binaryWriter.Write(normals[num25].z);
  685. binaryWriter.Write(vSharedUVs[num25].x);
  686. binaryWriter.Write(vSharedUVs[num25].y);
  687. }
  688. binaryWriter.Write(0);
  689. for (int num26 = 0; num26 < num19; num26++)
  690. {
  691. binaryWriter.Write((ushort)bwSharedBonwWeight[num26].boneIndex0);
  692. binaryWriter.Write((ushort)bwSharedBonwWeight[num26].boneIndex1);
  693. binaryWriter.Write((ushort)bwSharedBonwWeight[num26].boneIndex2);
  694. binaryWriter.Write((ushort)bwSharedBonwWeight[num26].boneIndex3);
  695. binaryWriter.Write(bwSharedBonwWeight[num26].weight0);
  696. binaryWriter.Write(bwSharedBonwWeight[num26].weight1);
  697. binaryWriter.Write(bwSharedBonwWeight[num26].weight2);
  698. binaryWriter.Write(bwSharedBonwWeight[num26].weight3);
  699. }
  700. for (int num27 = 0; num27 < num2; num27++)
  701. {
  702. List<ModCompile.ExFace> list8 = exObjIn2.dicFaces[num27];
  703. binaryWriter.Write(list8.Count * 3);
  704. for (int num28 = 0; num28 < list8.Count; num28++)
  705. {
  706. for (int num29 = 0; num29 < 3; num29++)
  707. {
  708. binaryWriter.Write((ushort)list8[num28].idx[num29]);
  709. }
  710. }
  711. }
  712. int count2 = exObjIn2.dicFaces.Count;
  713. binaryWriter.Write(count2);
  714. if (count2 != list.Count)
  715. {
  716. NDebug.MessageBox("MOD Compile", "マテリアル数が不正です。");
  717. return;
  718. }
  719. for (int num30 = 0; num30 < count2; num30++)
  720. {
  721. string text5 = Path.GetDirectoryName(f_strMqoFile) + "\\" + list[num30] + ".mate.txt";
  722. if (!File.Exists(text5))
  723. {
  724. NDebug.MessageBox("MOD Compile", "マテリアルが見つかりません。\n" + text5);
  725. return;
  726. }
  727. try
  728. {
  729. ModCompile.WriteMaterial(text5, binaryWriter);
  730. }
  731. catch (Exception ex2)
  732. {
  733. NDebug.MessageBox("MOD Compile", "マテリアルが不正です。" + text5 + "\n" + ex2.Message);
  734. return;
  735. }
  736. }
  737. foreach (ModCompile.ExObjIn exObjIn7 in list2)
  738. {
  739. Mesh mesh2 = new Mesh();
  740. mesh2.vertices = exObjIn7.vVtxs;
  741. mesh2.triangles = mesh.triangles;
  742. mesh2.RecalculateNormals();
  743. Vector3[] vVtxs2 = exObjIn7.vVtxs;
  744. Vector3[] normals2 = mesh2.normals;
  745. if (exObjIn7.vVtxs.Length != exObjIn2.vVtxs.Length)
  746. {
  747. NDebug.MessageBox("MOD Compile", "モーフターゲットと頂点数が異なります。" + exObjIn7.strName);
  748. return;
  749. }
  750. bool[] array4 = new bool[num19];
  751. binaryWriter.Write("morph");
  752. binaryWriter.Write(exObjIn7.strName.ToLower());
  753. int num31 = 0;
  754. for (int num32 = 0; num32 < num19; num32++)
  755. {
  756. float magnitude = (vVtxs2[num32] - vVtxs[num32]).magnitude;
  757. float magnitude2 = (normals2[num32] - normals[num32]).magnitude;
  758. if (magnitude > 0.0001f || magnitude2 > 0.01f)
  759. {
  760. num31++;
  761. array4[num32] = true;
  762. }
  763. else
  764. {
  765. array4[num32] = false;
  766. }
  767. }
  768. binaryWriter.Write(num31);
  769. for (int num33 = 0; num33 < num19; num33++)
  770. {
  771. if (array4[num33])
  772. {
  773. binaryWriter.Write((ushort)num33);
  774. binaryWriter.Write(vVtxs2[num33].x - vVtxs[num33].x);
  775. binaryWriter.Write(vVtxs2[num33].y - vVtxs[num33].y);
  776. binaryWriter.Write(vVtxs2[num33].z - vVtxs[num33].z);
  777. binaryWriter.Write(normals2[num33].x - normals[num33].x);
  778. binaryWriter.Write(normals2[num33].y - normals[num33].y);
  779. binaryWriter.Write(normals2[num33].z - normals[num33].z);
  780. }
  781. }
  782. }
  783. binaryWriter.Write("end");
  784. binaryWriter.Close();
  785. File.WriteAllBytes(path, memoryStream.ToArray());
  786. memoryStream.Close();
  787. memoryStream.Dispose();
  788. }
  789. private static void WriteMaterial(string f_strInMateTextFile, BinaryWriter w)
  790. {
  791. string value = string.Empty;
  792. string text = string.Empty;
  793. string text2 = string.Empty;
  794. List<ModCompile.MateTex2d> list = new List<ModCompile.MateTex2d>();
  795. List<ModCompile.MateCol> list2 = new List<ModCompile.MateCol>();
  796. List<ModCompile.MateVec4> list3 = new List<ModCompile.MateVec4>();
  797. List<ModCompile.MateFloat> list4 = new List<ModCompile.MateFloat>();
  798. StreamReader streamReader = new StreamReader(f_strInMateTextFile, Encoding.UTF8, false);
  799. string text3;
  800. while ((text3 = streamReader.ReadLine()) != null)
  801. {
  802. if (!(text3 == string.Empty))
  803. {
  804. if (text3.IndexOf("/") != 0)
  805. {
  806. string[] stringList = UTY.GetStringList(text3);
  807. if (stringList.Length != 0)
  808. {
  809. if (stringList[0] == "MaterialName")
  810. {
  811. value = stringList[1];
  812. }
  813. else if (stringList[0] == "ShaderName")
  814. {
  815. text = stringList[1];
  816. }
  817. else if (stringList[0] == "Shader")
  818. {
  819. text2 = stringList[1];
  820. }
  821. else if (stringList[0] == "tex2d")
  822. {
  823. list.Add(new ModCompile.MateTex2d(stringList[1], stringList[2], new Vector2(float.Parse(stringList[3]), float.Parse(stringList[4])), new Vector2(float.Parse(stringList[5]), float.Parse(stringList[6]))));
  824. }
  825. else if (stringList[0] == "col")
  826. {
  827. list2.Add(new ModCompile.MateCol(stringList[1], new Color(float.Parse(stringList[2]), float.Parse(stringList[3]), float.Parse(stringList[4]))));
  828. }
  829. else if (stringList[0] == "vec")
  830. {
  831. list3.Add(new ModCompile.MateVec4(stringList[1], new Vector4(float.Parse(stringList[2]), float.Parse(stringList[3]), float.Parse(stringList[4]), float.Parse(stringList[4]))));
  832. }
  833. else if (stringList[0] == "float")
  834. {
  835. list4.Add(new ModCompile.MateFloat(stringList[1], float.Parse(stringList[2])));
  836. }
  837. }
  838. }
  839. }
  840. }
  841. streamReader.Close();
  842. streamReader.Dispose();
  843. w.Write(value);
  844. w.Write(text);
  845. string text4 = string.Empty;
  846. int length = text.Length;
  847. for (int i = 0; i < length; i++)
  848. {
  849. if (text[i] != '/')
  850. {
  851. text4 += text[i].ToString();
  852. }
  853. else
  854. {
  855. text4 += "__";
  856. }
  857. }
  858. w.Write(text4);
  859. foreach (ModCompile.MateTex2d mateTex2d in list)
  860. {
  861. w.Write("tex");
  862. w.Write(mateTex2d.strPropName);
  863. w.Write("tex2d");
  864. w.Write(mateTex2d.strTexName);
  865. w.Write(mateTex2d.strTexName);
  866. w.Write(mateTex2d.vOffset.x);
  867. w.Write(mateTex2d.vOffset.y);
  868. w.Write(mateTex2d.vScale.x);
  869. w.Write(mateTex2d.vScale.y);
  870. }
  871. foreach (ModCompile.MateCol mateCol in list2)
  872. {
  873. w.Write("col");
  874. w.Write(mateCol.strPropName);
  875. Color col = mateCol.col;
  876. w.Write(col.r);
  877. w.Write(col.g);
  878. w.Write(col.b);
  879. w.Write(col.a);
  880. }
  881. foreach (ModCompile.MateVec4 mateVec in list3)
  882. {
  883. w.Write("vec");
  884. w.Write(mateVec.strPropName);
  885. Vector4 vVec = mateVec.vVec4;
  886. w.Write(vVec.x);
  887. w.Write(vVec.y);
  888. w.Write(vVec.z);
  889. w.Write(vVec.w);
  890. }
  891. foreach (ModCompile.MateFloat mateFloat in list4)
  892. {
  893. w.Write("f");
  894. w.Write(mateFloat.strPropName);
  895. w.Write(mateFloat.fValue);
  896. }
  897. w.Write("end");
  898. }
  899. public static void ExportTexture(string f_strInTexPathFileName)
  900. {
  901. string str = Path.GetDirectoryName(f_strInTexPathFileName) + "\\_compiled";
  902. string path = str + "\\" + Path.GetFileNameWithoutExtension(f_strInTexPathFileName) + ".tex";
  903. MemoryStream memoryStream = new MemoryStream();
  904. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  905. byte[] array = File.ReadAllBytes(f_strInTexPathFileName);
  906. binaryWriter.Write("CM3D2_TEX");
  907. binaryWriter.Write(ModCompile.FILE_FORMAT_VERSION);
  908. binaryWriter.Write(f_strInTexPathFileName);
  909. binaryWriter.Write(array.Length);
  910. binaryWriter.Write(array);
  911. binaryWriter.Close();
  912. File.WriteAllBytes(path, memoryStream.ToArray());
  913. memoryStream.Close();
  914. memoryStream.Dispose();
  915. }
  916. public static bool ExportMaterial(string f_strInMatePathFileName)
  917. {
  918. string text = Path.GetDirectoryName(f_strInMatePathFileName) + "\\_compiled";
  919. if (!Directory.Exists(text))
  920. {
  921. Directory.CreateDirectory(text);
  922. }
  923. string path = text + "\\" + Path.GetFileNameWithoutExtension(f_strInMatePathFileName);
  924. MemoryStream memoryStream = new MemoryStream();
  925. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  926. binaryWriter.Write("CM3D2_MATERIAL");
  927. binaryWriter.Write(ModCompile.FILE_FORMAT_VERSION);
  928. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(f_strInMatePathFileName);
  929. binaryWriter.Write(fileNameWithoutExtension);
  930. try
  931. {
  932. ModCompile.WriteMaterial(f_strInMatePathFileName, binaryWriter);
  933. }
  934. catch (Exception ex)
  935. {
  936. NDebug.MessageBox("MOD Compile", "マテリアルが不正です。" + Path.GetFileName(f_strInMatePathFileName) + "\n" + ex.Message);
  937. return false;
  938. }
  939. File.WriteAllBytes(path, memoryStream.ToArray());
  940. memoryStream.Close();
  941. memoryStream.Dispose();
  942. return true;
  943. }
  944. private static string[] m_aryDefCategoryName = new string[114];
  945. private static string[] m_aryDefSlotName;
  946. private static int FILE_FORMAT_VERSION = 1000;
  947. private static string[] scl_plus = new string[]
  948. {
  949. "Pelvis",
  950. "Spine",
  951. "Thigh",
  952. "Calf",
  953. "Clavicle",
  954. "Neck"
  955. };
  956. private class ExWeight
  957. {
  958. public int nObjIdx;
  959. public int nVtxIdx;
  960. public float fWeight;
  961. }
  962. private class ExBone
  963. {
  964. public ExBone(int id, string name)
  965. {
  966. this.nId = id;
  967. this.strName = name;
  968. }
  969. public int nId;
  970. public string strName;
  971. public int nParentId;
  972. public List<int> listChildId = new List<int>();
  973. public ModCompile.ExBone bnParent;
  974. public ModCompile.ExBone[] aryChild;
  975. public Vector3 vPosLocalS;
  976. public Vector3 vPosLocalE;
  977. public Vector3 vPosWorldS;
  978. public bool bDummy;
  979. public Quaternion qRotLocal;
  980. public Vector3 vScale;
  981. public Matrix4x4 matBindPose = default(Matrix4x4);
  982. public bool bUseBindPose;
  983. public List<ModCompile.ExWeight> listWeights = new List<ModCompile.ExWeight>();
  984. }
  985. private class ExFace
  986. {
  987. public int[] idx = new int[3];
  988. public Vector2[] uv = new Vector2[3];
  989. }
  990. private class ExObjIn
  991. {
  992. public ExObjIn(string name)
  993. {
  994. this.strName = name;
  995. }
  996. public string strName;
  997. public ModCompile.ExObjIn oParent;
  998. public List<ModCompile.ExObjIn> listChild = new List<ModCompile.ExObjIn>();
  999. public Vector3 vPosLocal;
  1000. public Quaternion qRotLocal;
  1001. public Vector3[] vVtxs;
  1002. public int nFaceCount;
  1003. public int nUid;
  1004. public int nDepth;
  1005. public Dictionary<int, List<ModCompile.ExFace>> dicFaces = new Dictionary<int, List<ModCompile.ExFace>>();
  1006. public int nSclCount;
  1007. public Vector3[] vSharedNormals;
  1008. public Vector2[] vSharedUVs;
  1009. public BoneWeight[] bwSharedBonwWeight;
  1010. }
  1011. private class MateTex2d
  1012. {
  1013. public MateTex2d(string f_strPropName, string f_strTexName, Vector2 f_vOffset, Vector2 f_vScale)
  1014. {
  1015. this.strPropName = f_strPropName;
  1016. this.strTexName = f_strTexName;
  1017. this.vOffset = f_vOffset;
  1018. this.vScale = f_vScale;
  1019. }
  1020. public string strPropName;
  1021. public string strTexName;
  1022. public Vector2 vOffset;
  1023. public Vector2 vScale = new Vector2(1f, 1f);
  1024. }
  1025. private class MateCol
  1026. {
  1027. public MateCol(string f_strPropName, Color f_col)
  1028. {
  1029. this.strPropName = f_strPropName;
  1030. this.col = f_col;
  1031. }
  1032. public string strPropName;
  1033. public Color col;
  1034. }
  1035. private class MateVec4
  1036. {
  1037. public MateVec4(string f_strPropName, Vector4 f_v)
  1038. {
  1039. this.strPropName = f_strPropName;
  1040. this.vVec4 = f_v;
  1041. }
  1042. public string strPropName;
  1043. public Vector4 vVec4;
  1044. }
  1045. private class MateFloat
  1046. {
  1047. public MateFloat(string f_strPropName, float f_value)
  1048. {
  1049. this.strPropName = f_strPropName;
  1050. this.fValue = f_value;
  1051. }
  1052. public string strPropName;
  1053. public float fValue;
  1054. }
  1055. }