ImportCM.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Text;
  6. using TriLib;
  7. using UnityEngine;
  8. using UnityEngine.Rendering;
  9. public class ImportCM : MonoBehaviour
  10. {
  11. private static ImportCM.BoneUse RemoveNoWeightBone(Dictionary<string, ImportCM.BoneUse> dic, Transform parent)
  12. {
  13. bool flag = false;
  14. if (parent.name == "Skirt")
  15. {
  16. return null;
  17. }
  18. ImportCM.BoneUse[] array = new ImportCM.BoneUse[parent.childCount];
  19. for (int i = 0; i < parent.childCount; i++)
  20. {
  21. ImportCM.BoneUse boneUse = array[i] = ImportCM.RemoveNoWeightBone(dic, parent.GetChild(i));
  22. flag |= (boneUse == null || boneUse.use);
  23. }
  24. foreach (ImportCM.BoneUse boneUse2 in array)
  25. {
  26. if (boneUse2 != null && boneUse2.bone != null && boneUse2.delete)
  27. {
  28. UnityEngine.Object.DestroyImmediate(boneUse2.bone.gameObject);
  29. boneUse2.bone = null;
  30. }
  31. }
  32. if (flag)
  33. {
  34. return null;
  35. }
  36. ImportCM.BoneUse boneUse2;
  37. if (dic.TryGetValue(parent.name, out boneUse2))
  38. {
  39. boneUse2.delete = (!boneUse2.use && !flag);
  40. return boneUse2;
  41. }
  42. return null;
  43. }
  44. public static GameObject LoadSkinMesh_R(string filename, TMorph morph, string slotname, TBodySkin bodyskin, int layer)
  45. {
  46. try
  47. {
  48. using (AFileBase afileBase = GameUty.FileOpen(filename, null))
  49. {
  50. if (ImportCM.m_skinTempFile == null)
  51. {
  52. ImportCM.m_skinTempFile = new byte[Math.Max(500000, afileBase.GetSize())];
  53. }
  54. else if (ImportCM.m_skinTempFile.Length < afileBase.GetSize())
  55. {
  56. ImportCM.m_skinTempFile = new byte[afileBase.GetSize()];
  57. }
  58. afileBase.Read(ref ImportCM.m_skinTempFile, afileBase.GetSize());
  59. }
  60. }
  61. catch (Exception ex)
  62. {
  63. NDebug.Assert("ファイルが開けませんでした。" + filename + "\n" + ex.Message, false);
  64. }
  65. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_skinTempFile), Encoding.UTF8);
  66. TBodySkin.OriVert oriVert = bodyskin.m_OriVert;
  67. GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  68. gameObject.layer = layer;
  69. GameObject gameObject2 = null;
  70. Hashtable hashtable = new Hashtable();
  71. string text = binaryReader.ReadString();
  72. if (text != "CM3D2_MESH")
  73. {
  74. NDebug.Assert("LoadSkinMesh_R 例外 : ヘッダーファイルが不正です。" + text, false);
  75. }
  76. int num = binaryReader.ReadInt32();
  77. string str = binaryReader.ReadString();
  78. gameObject.name = "_SM_" + str;
  79. string b = binaryReader.ReadString();
  80. Dictionary<string, ImportCM.BoneUse> dictionary = new Dictionary<string, ImportCM.BoneUse>();
  81. int num2 = binaryReader.ReadInt32();
  82. List<GameObject> list = new List<GameObject>();
  83. for (int i = 0; i < num2; i++)
  84. {
  85. GameObject gameObject3 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  86. gameObject3.layer = layer;
  87. gameObject3.name = binaryReader.ReadString();
  88. list.Add(gameObject3);
  89. if (gameObject3.name == b)
  90. {
  91. gameObject2 = gameObject3;
  92. }
  93. hashtable[gameObject3.name] = gameObject3;
  94. dictionary[gameObject3.name] = new ImportCM.BoneUse(gameObject3.name, -1, gameObject3.transform);
  95. bool flag = binaryReader.ReadByte() != 0;
  96. if (flag)
  97. {
  98. GameObject gameObject4 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  99. gameObject4.name = gameObject3.name + "_SCL_";
  100. gameObject4.transform.parent = gameObject3.transform;
  101. hashtable[gameObject3.name + "&_SCL_"] = gameObject4;
  102. dictionary[gameObject4.name] = new ImportCM.BoneUse(gameObject4.name, -1, gameObject4.transform);
  103. }
  104. }
  105. for (int j = 0; j < num2; j++)
  106. {
  107. int num3 = binaryReader.ReadInt32();
  108. if (num3 >= 0)
  109. {
  110. list[j].transform.parent = list[num3].transform;
  111. }
  112. else
  113. {
  114. list[j].transform.parent = gameObject.transform;
  115. }
  116. }
  117. for (int k = 0; k < num2; k++)
  118. {
  119. Transform transform = list[k].transform;
  120. float x = binaryReader.ReadSingle();
  121. float y = binaryReader.ReadSingle();
  122. float z = binaryReader.ReadSingle();
  123. transform.localPosition = new Vector3(x, y, z);
  124. float x2 = binaryReader.ReadSingle();
  125. float y2 = binaryReader.ReadSingle();
  126. float z2 = binaryReader.ReadSingle();
  127. float w = binaryReader.ReadSingle();
  128. transform.localRotation = new Quaternion(x2, y2, z2, w);
  129. if (2001 <= num)
  130. {
  131. bool flag2 = binaryReader.ReadBoolean();
  132. if (flag2)
  133. {
  134. float x3 = binaryReader.ReadSingle();
  135. float y3 = binaryReader.ReadSingle();
  136. float z3 = binaryReader.ReadSingle();
  137. transform.localScale = new Vector3(x3, y3, z3);
  138. }
  139. }
  140. }
  141. int num4 = binaryReader.ReadInt32();
  142. int num5 = binaryReader.ReadInt32();
  143. int num6 = binaryReader.ReadInt32();
  144. oriVert.VCount = num4;
  145. oriVert.nSubMeshCount = num5;
  146. SkinnedMeshRenderer skinnedMeshRenderer = gameObject2.AddComponent<SkinnedMeshRenderer>();
  147. skinnedMeshRenderer.updateWhenOffscreen = true;
  148. skinnedMeshRenderer.skinnedMotionVectors = false;
  149. skinnedMeshRenderer.lightProbeUsage = LightProbeUsage.Off;
  150. skinnedMeshRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
  151. skinnedMeshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
  152. if (!bodyskin.body.boMAN)
  153. {
  154. if (slotname == "head")
  155. {
  156. skinnedMeshRenderer.castShadows = false;
  157. }
  158. if (bodyskin.Category == "chikubi")
  159. {
  160. skinnedMeshRenderer.castShadows = false;
  161. }
  162. if (bodyskin.Category.IndexOf("seieki_") == 0)
  163. {
  164. skinnedMeshRenderer.castShadows = false;
  165. }
  166. }
  167. bodyskin.listDEL.Add(gameObject2);
  168. ImportCM.BoneUse[] array = new ImportCM.BoneUse[num6];
  169. Transform[] array2 = new Transform[num6];
  170. for (int l = 0; l < num6; l++)
  171. {
  172. string text2 = binaryReader.ReadString();
  173. if (!hashtable.ContainsKey(text2))
  174. {
  175. Debug.LogError("nullbone= " + text2);
  176. }
  177. else
  178. {
  179. GameObject gameObject5;
  180. if (hashtable.ContainsKey(text2 + "&_SCL_"))
  181. {
  182. gameObject5 = (GameObject)hashtable[text2 + "&_SCL_"];
  183. }
  184. else
  185. {
  186. gameObject5 = (GameObject)hashtable[text2];
  187. }
  188. array2[l] = gameObject5.transform;
  189. ImportCM.BoneUse[] array3 = array;
  190. int num7 = l;
  191. ImportCM.BoneUse boneUse = new ImportCM.BoneUse(gameObject5.name, l, gameObject5.transform);
  192. dictionary[gameObject5.name] = boneUse;
  193. array3[num7] = boneUse;
  194. }
  195. }
  196. skinnedMeshRenderer.bones = array2;
  197. Mesh mesh = new Mesh();
  198. skinnedMeshRenderer.sharedMesh = mesh;
  199. Mesh mesh2 = mesh;
  200. bodyskin.listDEL.Add(mesh2);
  201. Matrix4x4[] array4 = new Matrix4x4[num6];
  202. for (int m = 0; m < num6; m++)
  203. {
  204. for (int n = 0; n < 16; n++)
  205. {
  206. array4[m][n] = binaryReader.ReadSingle();
  207. }
  208. }
  209. mesh2.bindposes = array4;
  210. Vector3[] array5 = new Vector3[num4];
  211. Vector3[] array6 = new Vector3[num4];
  212. Vector2[] array7 = new Vector2[num4];
  213. BoneWeight[] array8 = new BoneWeight[num4];
  214. for (int num8 = 0; num8 < num4; num8++)
  215. {
  216. float num9 = binaryReader.ReadSingle();
  217. float num10 = binaryReader.ReadSingle();
  218. float new_z = binaryReader.ReadSingle();
  219. array5[num8].Set(num9, num10, new_z);
  220. num9 = binaryReader.ReadSingle();
  221. num10 = binaryReader.ReadSingle();
  222. new_z = binaryReader.ReadSingle();
  223. array6[num8].Set(num9, num10, new_z);
  224. num9 = binaryReader.ReadSingle();
  225. num10 = binaryReader.ReadSingle();
  226. array7[num8].Set(num9, num10);
  227. }
  228. mesh2.vertices = array5;
  229. mesh2.normals = array6;
  230. mesh2.uv = array7;
  231. oriVert.vOriVert = array5;
  232. oriVert.vOriNorm = array6;
  233. int num11 = binaryReader.ReadInt32();
  234. if (num11 > 0)
  235. {
  236. Vector4[] array9 = new Vector4[num11];
  237. for (int num12 = 0; num12 < num11; num12++)
  238. {
  239. float x4 = binaryReader.ReadSingle();
  240. float y4 = binaryReader.ReadSingle();
  241. float z4 = binaryReader.ReadSingle();
  242. float w2 = binaryReader.ReadSingle();
  243. array9[num12] = new Vector4(x4, y4, z4, w2);
  244. }
  245. mesh2.tangents = array9;
  246. }
  247. for (int num13 = 0; num13 < num4; num13++)
  248. {
  249. int num14 = (int)binaryReader.ReadUInt16();
  250. array8[num13].boneIndex0 = num14;
  251. int num15 = num14;
  252. num14 = (int)binaryReader.ReadUInt16();
  253. array8[num13].boneIndex1 = num14;
  254. int num16 = num14;
  255. num14 = (int)binaryReader.ReadUInt16();
  256. array8[num13].boneIndex2 = num14;
  257. int num17 = num14;
  258. num14 = (int)binaryReader.ReadUInt16();
  259. array8[num13].boneIndex3 = num14;
  260. int num18 = num14;
  261. array[num15].use = true;
  262. array[num16].use = true;
  263. array[num17].use = true;
  264. array[num18].use = true;
  265. array8[num13].weight0 = binaryReader.ReadSingle();
  266. array8[num13].weight1 = binaryReader.ReadSingle();
  267. array8[num13].weight2 = binaryReader.ReadSingle();
  268. array8[num13].weight3 = binaryReader.ReadSingle();
  269. }
  270. ImportCM.BoneUse boneUse2;
  271. if (dictionary.TryGetValue("Bip01", out boneUse2))
  272. {
  273. ImportCM.RemoveNoWeightBone(dictionary, boneUse2.bone);
  274. }
  275. mesh2.boneWeights = array8;
  276. mesh2.subMeshCount = num5;
  277. oriVert.bwWeight = array8;
  278. oriVert.nSubMeshCount = num5;
  279. oriVert.nSubMeshOriTri = new int[num5][];
  280. for (int num19 = 0; num19 < num5; num19++)
  281. {
  282. int num20 = binaryReader.ReadInt32();
  283. int[] array10 = new int[num20];
  284. for (int num21 = 0; num21 < num20; num21++)
  285. {
  286. array10[num21] = (int)binaryReader.ReadUInt16();
  287. }
  288. oriVert.nSubMeshOriTri[num19] = array10;
  289. mesh2.SetTriangles(array10, num19);
  290. }
  291. int num22 = binaryReader.ReadInt32();
  292. Material[] array11 = new Material[num22];
  293. for (int num23 = 0; num23 < num22; num23++)
  294. {
  295. Material material = ImportCM.ReadMaterial(binaryReader, bodyskin, null);
  296. array11[num23] = material;
  297. }
  298. skinnedMeshRenderer.materials = array11;
  299. for (;;)
  300. {
  301. string a = binaryReader.ReadString();
  302. if (a == "end")
  303. {
  304. break;
  305. }
  306. if (a == "morph")
  307. {
  308. morph.LoadMoprhData2(binaryReader);
  309. }
  310. }
  311. binaryReader.Close();
  312. return gameObject;
  313. }
  314. public static Material LoadMaterial(string f_strFileName, TBodySkin bodyskin, Material existmat = null)
  315. {
  316. try
  317. {
  318. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName, null))
  319. {
  320. NDebug.Assert(afileBase.IsValid(), "LoadMaterial マテリアルコンテナが読めません。 :" + f_strFileName);
  321. if (ImportCM.m_matTempFile == null)
  322. {
  323. ImportCM.m_matTempFile = new byte[Math.Max(10000, afileBase.GetSize())];
  324. }
  325. else if (ImportCM.m_matTempFile.Length < afileBase.GetSize())
  326. {
  327. ImportCM.m_matTempFile = new byte[afileBase.GetSize()];
  328. }
  329. afileBase.Read(ref ImportCM.m_matTempFile, afileBase.GetSize());
  330. }
  331. }
  332. catch (Exception ex)
  333. {
  334. Debug.LogError(string.Concat(new string[]
  335. {
  336. "LoadMaterial マテリアルコンテナが読み込めませんでした。 : ",
  337. f_strFileName,
  338. " : ",
  339. ex.Message,
  340. " : StackTrace :\n",
  341. ex.StackTrace
  342. }));
  343. throw ex;
  344. }
  345. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_matTempFile), Encoding.UTF8);
  346. string text = binaryReader.ReadString();
  347. if (text != "CM3D2_MATERIAL")
  348. {
  349. NDebug.Assert("ProcScriptBin 例外 : ヘッダーファイルが不正です。" + text, false);
  350. }
  351. int num = binaryReader.ReadInt32();
  352. string text2 = binaryReader.ReadString();
  353. Material result = ImportCM.ReadMaterial(binaryReader, bodyskin, existmat);
  354. binaryReader.Close();
  355. return result;
  356. }
  357. public static Material ReadMaterial(BinaryReader r, TBodySkin bodyskin = null, Material existmat = null)
  358. {
  359. if (ImportCM.m_hashPriorityMaterials == null)
  360. {
  361. ImportCM.m_hashPriorityMaterials = new Dictionary<int, KeyValuePair<string, float>>();
  362. string[] list = GameUty.FileSystem.GetList("prioritymaterial", AFileSystemBase.ListType.AllFile);
  363. if (list != null && 0 < list.Length)
  364. {
  365. for (int i = 0; i < list.Length; i++)
  366. {
  367. if (Path.GetExtension(list[i]) == ".pmat")
  368. {
  369. string text = list[i];
  370. using (AFileBase afileBase = GameUty.FileOpen(text, null))
  371. {
  372. NDebug.Assert(afileBase.IsValid(), text + "を開けませんでした");
  373. byte[] buffer = afileBase.ReadAll();
  374. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer), Encoding.UTF8))
  375. {
  376. string a = binaryReader.ReadString();
  377. if (a != "CM3D2_PMATERIAL")
  378. {
  379. NDebug.Assert("ヘッダーエラー\n" + text, false);
  380. }
  381. int num = binaryReader.ReadInt32();
  382. int key = binaryReader.ReadInt32();
  383. string key2 = binaryReader.ReadString();
  384. float value = binaryReader.ReadSingle();
  385. NDebug.Assert(!ImportCM.m_hashPriorityMaterials.ContainsKey(key), "すでにハッシュが登録されています");
  386. ImportCM.m_hashPriorityMaterials.Add(key, new KeyValuePair<string, float>(key2, value));
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. string name = r.ReadString();
  394. string text2 = r.ReadString();
  395. string text3 = r.ReadString();
  396. Material material2;
  397. if (existmat == null)
  398. {
  399. Material material;
  400. if (!ImportCM.m_dicCacheMaterial.TryGetValue(text3, out material))
  401. {
  402. string text4 = "DefMaterial/" + text3;
  403. material = (Resources.Load(text4, typeof(Material)) as Material);
  404. if (material == null)
  405. {
  406. NDebug.Assert("DefMaterialが見つかりません。" + text4, false);
  407. }
  408. ImportCM.m_dicCacheMaterial[text3] = material;
  409. }
  410. material2 = UnityEngine.Object.Instantiate<Material>(material);
  411. if (bodyskin != null)
  412. {
  413. bodyskin.listDEL.Add(material2);
  414. }
  415. }
  416. else
  417. {
  418. material2 = existmat;
  419. if (material2.shader.name != text2)
  420. {
  421. NDebug.Warning("マテリアル入れ替えエラー。違うシェーダーに入れようとしました。 " + text2 + " -> " + material2.shader.name);
  422. }
  423. }
  424. material2.name = name;
  425. int hashCode = material2.name.GetHashCode();
  426. if (ImportCM.m_hashPriorityMaterials != null && ImportCM.m_hashPriorityMaterials.ContainsKey(hashCode))
  427. {
  428. KeyValuePair<string, float> keyValuePair = ImportCM.m_hashPriorityMaterials[hashCode];
  429. if (keyValuePair.Key == material2.name)
  430. {
  431. material2.SetFloat("_SetManualRenderQueue", keyValuePair.Value);
  432. material2.renderQueue = (int)keyValuePair.Value;
  433. }
  434. }
  435. for (;;)
  436. {
  437. string text5 = r.ReadString();
  438. if (text5 == "end")
  439. {
  440. break;
  441. }
  442. string name2 = r.ReadString();
  443. if (text5 == "tex")
  444. {
  445. string a2 = r.ReadString();
  446. if (a2 == "null")
  447. {
  448. material2.SetTexture(name2, null);
  449. }
  450. else if (a2 == "tex2d")
  451. {
  452. string text6 = r.ReadString();
  453. string text7 = r.ReadString();
  454. Texture2D texture2D = ImportCM.CreateTexture(text6 + ".tex");
  455. texture2D.name = text6;
  456. texture2D.wrapMode = TextureWrapMode.Clamp;
  457. material2.SetTexture(name2, texture2D);
  458. if (bodyskin != null)
  459. {
  460. bodyskin.listDEL.Add(texture2D);
  461. }
  462. Vector2 value2;
  463. value2.x = r.ReadSingle();
  464. value2.y = r.ReadSingle();
  465. material2.SetTextureOffset(name2, value2);
  466. Vector2 value3;
  467. value3.x = r.ReadSingle();
  468. value3.y = r.ReadSingle();
  469. material2.SetTextureScale(name2, value3);
  470. }
  471. else if (a2 == "texRT")
  472. {
  473. string text8 = r.ReadString();
  474. string text9 = r.ReadString();
  475. }
  476. }
  477. else if (text5 == "col")
  478. {
  479. Color value4;
  480. value4.r = r.ReadSingle();
  481. value4.g = r.ReadSingle();
  482. value4.b = r.ReadSingle();
  483. value4.a = r.ReadSingle();
  484. material2.SetColor(name2, value4);
  485. }
  486. else if (text5 == "vec")
  487. {
  488. Vector4 value5;
  489. value5.x = r.ReadSingle();
  490. value5.y = r.ReadSingle();
  491. value5.z = r.ReadSingle();
  492. value5.w = r.ReadSingle();
  493. material2.SetVector(name2, value5);
  494. }
  495. else if (text5 == "f")
  496. {
  497. float value6 = r.ReadSingle();
  498. material2.SetFloat(name2, value6);
  499. }
  500. else
  501. {
  502. Debug.LogError("マテリアルが読み込めません。不正なマテリアルプロパティ型です " + text5);
  503. }
  504. }
  505. return material2;
  506. }
  507. public static GameObject LoadOnlyBone_R(byte[] bs)
  508. {
  509. GameObject gameObject = new GameObject();
  510. gameObject.layer = 10;
  511. BinaryReader binaryReader = new BinaryReader(new MemoryStream(bs));
  512. Hashtable hashtable = new Hashtable();
  513. string text = binaryReader.ReadString();
  514. if (text != "CM3D2_MESH")
  515. {
  516. NDebug.Assert("LoadOnlyBone_R 例外 : ヘッダーファイルが不正です。" + text, false);
  517. }
  518. int num = binaryReader.ReadInt32();
  519. string str = binaryReader.ReadString();
  520. gameObject.name = "_BO_" + str;
  521. string text2 = binaryReader.ReadString();
  522. int num2 = binaryReader.ReadInt32();
  523. List<GameObject> list = new List<GameObject>();
  524. for (int i = 0; i < num2; i++)
  525. {
  526. GameObject gameObject2 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  527. gameObject2.layer = 10;
  528. gameObject2.name = binaryReader.ReadString();
  529. list.Add(gameObject2);
  530. hashtable[gameObject2.name] = gameObject2;
  531. bool flag = binaryReader.ReadByte() != 0;
  532. if (flag)
  533. {
  534. GameObject gameObject3 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  535. gameObject2.layer = 10;
  536. gameObject3.name = gameObject2.name + "_SCL_";
  537. gameObject3.transform.parent = gameObject2.transform;
  538. hashtable[gameObject2.name + "&_SCL_"] = gameObject3;
  539. }
  540. }
  541. for (int j = 0; j < num2; j++)
  542. {
  543. int num3 = binaryReader.ReadInt32();
  544. if (num3 >= 0)
  545. {
  546. list[j].transform.parent = list[num3].transform;
  547. }
  548. else
  549. {
  550. list[j].transform.parent = gameObject.transform;
  551. }
  552. }
  553. for (int k = 0; k < num2; k++)
  554. {
  555. Transform transform = list[k].transform;
  556. float x = binaryReader.ReadSingle();
  557. float y = binaryReader.ReadSingle();
  558. float z = binaryReader.ReadSingle();
  559. transform.localPosition = new Vector3(x, y, z);
  560. float x2 = binaryReader.ReadSingle();
  561. float y2 = binaryReader.ReadSingle();
  562. float z2 = binaryReader.ReadSingle();
  563. float w = binaryReader.ReadSingle();
  564. transform.localRotation = new Quaternion(x2, y2, z2, w);
  565. if (2001 <= num)
  566. {
  567. bool flag2 = binaryReader.ReadBoolean();
  568. if (flag2)
  569. {
  570. float x3 = binaryReader.ReadSingle();
  571. float y3 = binaryReader.ReadSingle();
  572. float z3 = binaryReader.ReadSingle();
  573. transform.localScale = new Vector3(x3, y3, z3);
  574. }
  575. }
  576. }
  577. binaryReader.Close();
  578. gameObject.AddComponent(typeof(Animation));
  579. return gameObject;
  580. }
  581. public static Dictionary<string, ImportCM.OldSkirtBoneRev> LoadOldSkirtBoneRev(string f_strModelName)
  582. {
  583. Dictionary<string, ImportCM.OldSkirtBoneRev> dictionary = null;
  584. if (f_strModelName.Contains("dress020_onep"))
  585. {
  586. dictionary = new Dictionary<string, ImportCM.OldSkirtBoneRev>();
  587. for (int i = 1; i <= 12; i++)
  588. {
  589. dictionary.Add("Skirt" + i.ToString("00") + "_A_yure_skirt_h_", new ImportCM.OldSkirtBoneRev
  590. {
  591. bRecursiv = true,
  592. vRotRevInit = new Vector3((i != 7 && i != 8) ? 90f : -90f, 0f, 0f),
  593. vRotRevAfter = new Vector3((i != 7 && i != 8) ? -90f : 90f, 0f, 0f)
  594. });
  595. }
  596. }
  597. else if (f_strModelName.Contains("dress131_onep"))
  598. {
  599. dictionary = new Dictionary<string, ImportCM.OldSkirtBoneRev>();
  600. for (int j = 1; j <= 12; j++)
  601. {
  602. dictionary.Add("Skirt" + j.ToString("00") + "_A_yure_skirt_", new ImportCM.OldSkirtBoneRev
  603. {
  604. bRecursiv = true,
  605. vRotRevInit = new Vector3(0f, 0f, 0f),
  606. vRotRevAfter = new Vector3(180f, 0f, 0f)
  607. });
  608. }
  609. }
  610. return dictionary;
  611. }
  612. public static Texture2D CreateTexture(string f_strFileName)
  613. {
  614. return ImportCM.LoadTexture(GameUty.FileSystem, f_strFileName, true).CreateTexture2D();
  615. }
  616. public static Texture2D CreateTexture(AFileSystemBase f_fileSystem, string f_strFileName)
  617. {
  618. return ImportCM.LoadTexture(f_fileSystem, f_strFileName, true).CreateTexture2D();
  619. }
  620. public static TextureResource LoadTexture(AFileSystemBase f_fileSystem, string f_strFileName, bool usePoolBuffer)
  621. {
  622. try
  623. {
  624. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName, f_fileSystem))
  625. {
  626. NDebug.Assert(afileBase.IsValid(), "LoadTexture テクスチャコンテナが読めません。 :" + f_strFileName);
  627. if (ImportCM.m_texTempFile == null)
  628. {
  629. ImportCM.m_texTempFile = new byte[Math.Max(500000, afileBase.GetSize())];
  630. }
  631. else if (ImportCM.m_texTempFile.Length < afileBase.GetSize())
  632. {
  633. ImportCM.m_texTempFile = new byte[afileBase.GetSize()];
  634. }
  635. afileBase.Read(ref ImportCM.m_texTempFile, afileBase.GetSize());
  636. }
  637. }
  638. catch (Exception ex)
  639. {
  640. Debug.LogError(string.Concat(new string[]
  641. {
  642. "LoadTexture テクスチャコンテナが読み込めませんでした。 : ",
  643. f_strFileName,
  644. " : ",
  645. ex.Message,
  646. " : StackTrace :\n",
  647. ex.StackTrace
  648. }));
  649. throw ex;
  650. }
  651. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_texTempFile), Encoding.UTF8);
  652. string text = binaryReader.ReadString();
  653. if (text != "CM3D2_TEX")
  654. {
  655. NDebug.Assert("ProcScriptBin 例外 : ヘッダーファイルが不正です。" + text, false);
  656. }
  657. int num = binaryReader.ReadInt32();
  658. string text2 = binaryReader.ReadString();
  659. int width = 0;
  660. int height = 0;
  661. TextureFormat textureFormat = TextureFormat.ARGB32;
  662. Rect[] array = null;
  663. if (1010 <= num)
  664. {
  665. if (1011 <= num)
  666. {
  667. int num2 = binaryReader.ReadInt32();
  668. if (0 < num2)
  669. {
  670. array = new Rect[num2];
  671. for (int i = 0; i < num2; i++)
  672. {
  673. float x = binaryReader.ReadSingle();
  674. float y = binaryReader.ReadSingle();
  675. float width2 = binaryReader.ReadSingle();
  676. float height2 = binaryReader.ReadSingle();
  677. array[i] = new Rect(x, y, width2, height2);
  678. }
  679. }
  680. }
  681. width = binaryReader.ReadInt32();
  682. height = binaryReader.ReadInt32();
  683. textureFormat = (TextureFormat)binaryReader.ReadInt32();
  684. }
  685. int num3 = binaryReader.ReadInt32();
  686. byte[] array2;
  687. if (usePoolBuffer && textureFormat == TextureFormat.ARGB32)
  688. {
  689. if (ImportCM.m_texTempImg == null)
  690. {
  691. ImportCM.m_texTempImg = new byte[Math.Max(500000, num3)];
  692. }
  693. else if (ImportCM.m_texTempImg.Length < num3)
  694. {
  695. ImportCM.m_texTempImg = new byte[num3];
  696. }
  697. binaryReader.Read(ImportCM.m_texTempImg, 0, num3);
  698. array2 = ImportCM.m_texTempImg;
  699. }
  700. else
  701. {
  702. array2 = new byte[num3];
  703. binaryReader.Read(array2, 0, num3);
  704. }
  705. if (num == 1000)
  706. {
  707. width = ((int)array2[16] << 24 | (int)array2[17] << 16 | (int)array2[18] << 8 | (int)array2[19]);
  708. height = ((int)array2[20] << 24 | (int)array2[21] << 16 | (int)array2[22] << 8 | (int)array2[23]);
  709. }
  710. binaryReader.Close();
  711. return new TextureResource(width, height, textureFormat, array, array2);
  712. }
  713. public static AnimationClip LoadAniClip(string f_strFileName, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false)
  714. {
  715. try
  716. {
  717. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName, null))
  718. {
  719. NDebug.Assert(afileBase.IsValid(), "LoadAniClip アニメーションファイルが開けません。 :" + f_strFileName);
  720. if (ImportCM.m_aniTempFile == null)
  721. {
  722. ImportCM.m_aniTempFile = new byte[Math.Max(500000, afileBase.GetSize())];
  723. }
  724. else if (ImportCM.m_aniTempFile.Length < afileBase.GetSize())
  725. {
  726. ImportCM.m_aniTempFile = new byte[afileBase.GetSize()];
  727. }
  728. afileBase.Read(ref ImportCM.m_aniTempFile, afileBase.GetSize());
  729. }
  730. }
  731. catch (Exception ex)
  732. {
  733. Debug.LogError(string.Concat(new string[]
  734. {
  735. "LoadAniClip アニメーションファイルが読み込めませんでした。 : ",
  736. f_strFileName,
  737. " : ",
  738. ex.Message,
  739. " : StackTrace :\n",
  740. ex.StackTrace
  741. }));
  742. throw ex;
  743. }
  744. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_aniTempFile), Encoding.UTF8);
  745. string text = binaryReader.ReadString();
  746. if (text != "CM3D2_ANIM")
  747. {
  748. NDebug.Assert("LoadAniClip 例外 : ヘッダーファイルが不正です。" + text, false);
  749. }
  750. int num = binaryReader.ReadInt32();
  751. AnimationClip animationClip = new AnimationClip();
  752. if (animationClip != null)
  753. {
  754. animationClip.legacy = true;
  755. }
  756. string text2 = string.Empty;
  757. int num2 = 0;
  758. for (;;)
  759. {
  760. byte b = binaryReader.ReadByte();
  761. if (b == 0)
  762. {
  763. break;
  764. }
  765. if (b == 1)
  766. {
  767. text2 = binaryReader.ReadString();
  768. num2++;
  769. }
  770. else if (b >= 100)
  771. {
  772. int num3 = binaryReader.ReadInt32();
  773. Keyframe[] array = new Keyframe[num3];
  774. AnimationCurve animationCurve = new AnimationCurve();
  775. for (int i = 0; i < num3; i++)
  776. {
  777. array[i].time = binaryReader.ReadSingle();
  778. array[i].value = binaryReader.ReadSingle();
  779. array[i].inTangent = binaryReader.ReadSingle();
  780. array[i].outTangent = binaryReader.ReadSingle();
  781. }
  782. animationCurve.keys = array;
  783. bool flag = true;
  784. string text3 = text2 + "*";
  785. if (!no_chara)
  786. {
  787. if (b >= 104 && b <= 106 && !text3.Contains("Bip01*") && !text3.Contains("_IK_") && !text3.Contains("ManBip*") && !text3.Contains("Hip_L") && !text3.Contains("Hip_R"))
  788. {
  789. flag = false;
  790. }
  791. if (!load_l_mune_anime && text3.Contains("Mune_L"))
  792. {
  793. flag = false;
  794. }
  795. if (!load_r_mune_anime && text3.Contains("Mune_R"))
  796. {
  797. flag = false;
  798. }
  799. }
  800. if (flag)
  801. {
  802. animationClip.SetCurve(text2, AnmParse.proptypes[(int)(b - 100)], AnmParse.properties[(int)(b - 100)], animationCurve);
  803. }
  804. }
  805. else
  806. {
  807. Debug.LogError("com " + b);
  808. }
  809. }
  810. binaryReader.Close();
  811. return animationClip;
  812. }
  813. public static AnimationClip LoadAniClip(byte[] file_byte, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false)
  814. {
  815. if (ImportCM.m_aniTempFile == null)
  816. {
  817. ImportCM.m_aniTempFile = new byte[Math.Max(500000, file_byte.Length)];
  818. }
  819. else if (ImportCM.m_aniTempFile.Length < file_byte.Length)
  820. {
  821. ImportCM.m_aniTempFile = new byte[file_byte.Length];
  822. }
  823. Buffer.BlockCopy(file_byte, 0, ImportCM.m_aniTempFile, 0, file_byte.Length);
  824. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_aniTempFile), Encoding.UTF8);
  825. string text = binaryReader.ReadString();
  826. if (text != "CM3D2_ANIM")
  827. {
  828. NDebug.Assert("LoadAniClip 例外 : ヘッダーファイルが不正です。" + text, false);
  829. }
  830. int num = binaryReader.ReadInt32();
  831. AnimationClip animationClip = new AnimationClip();
  832. if (animationClip != null)
  833. {
  834. animationClip.legacy = true;
  835. }
  836. string text2 = string.Empty;
  837. int num2 = 0;
  838. for (;;)
  839. {
  840. byte b = binaryReader.ReadByte();
  841. if (b == 0)
  842. {
  843. break;
  844. }
  845. if (b == 1)
  846. {
  847. text2 = binaryReader.ReadString();
  848. num2++;
  849. }
  850. else if (b >= 100)
  851. {
  852. int num3 = binaryReader.ReadInt32();
  853. Keyframe[] array = new Keyframe[num3];
  854. AnimationCurve animationCurve = new AnimationCurve();
  855. for (int i = 0; i < num3; i++)
  856. {
  857. array[i].time = binaryReader.ReadSingle();
  858. array[i].value = binaryReader.ReadSingle();
  859. array[i].inTangent = binaryReader.ReadSingle();
  860. array[i].outTangent = binaryReader.ReadSingle();
  861. }
  862. animationCurve.keys = array;
  863. bool flag = true;
  864. string text3 = text2 + "*";
  865. if (!no_chara)
  866. {
  867. if (!no_chara && b >= 104 && b <= 106 && !text3.Contains("Bip01*") && !text3.Contains("_IK_") && !text3.Contains("ManBip*") && !text3.Contains("Hip_L") && !text3.Contains("Hip_R"))
  868. {
  869. flag = false;
  870. }
  871. if (!load_l_mune_anime && text3.Contains("Mune_L"))
  872. {
  873. flag = false;
  874. }
  875. if (!load_r_mune_anime && text3.Contains("Mune_R"))
  876. {
  877. flag = false;
  878. }
  879. if (flag)
  880. {
  881. animationClip.SetCurve(text2, AnmParse.proptypes[(int)(b - 100)], AnmParse.properties[(int)(b - 100)], animationCurve);
  882. }
  883. }
  884. }
  885. else
  886. {
  887. Debug.LogError("com " + b);
  888. }
  889. }
  890. binaryReader.Close();
  891. return animationClip;
  892. }
  893. public static AnimationClip LoadAniClipNative(AFileSystemBase fileSystem, string fileName, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false)
  894. {
  895. AnimationClip result = null;
  896. using (AFileBase afileBase = GameUty.FileOpen(fileName, fileSystem))
  897. {
  898. if (afileBase == null || !afileBase.IsValid())
  899. {
  900. Debug.LogError(fileName + " はありませんでした。");
  901. return null;
  902. }
  903. result = GameMain.Instance.AnmParse.LoadAnmClip(afileBase, load_l_mune_anime, load_r_mune_anime, no_chara);
  904. }
  905. return result;
  906. }
  907. public static AnimationClip LoadAniClipNative(byte[] file_byte, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false)
  908. {
  909. return GameMain.Instance.AnmParse.LoadAnmClip(file_byte, load_l_mune_anime, load_r_mune_anime, no_chara);
  910. }
  911. public static DynamicBone TryLoadDynamicBone(GameObject f_goRoot, Transform f_trHairRoot, string f_strFileName, TBody body, float[] f_aryDefStiffness)
  912. {
  913. try
  914. {
  915. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName + ".phy", null))
  916. {
  917. if (afileBase == null || !afileBase.IsValid())
  918. {
  919. return null;
  920. }
  921. if (ImportCM.m_byPhyTempFile == null)
  922. {
  923. ImportCM.m_byPhyTempFile = new byte[Math.Max(50000, afileBase.GetSize())];
  924. }
  925. else if (ImportCM.m_byPhyTempFile.Length < afileBase.GetSize())
  926. {
  927. ImportCM.m_byPhyTempFile = new byte[afileBase.GetSize()];
  928. }
  929. afileBase.Read(ref ImportCM.m_byPhyTempFile, afileBase.GetSize());
  930. }
  931. }
  932. catch (Exception ex)
  933. {
  934. Debug.LogError(string.Concat(new string[]
  935. {
  936. "TryLoadDynamicBone 物理定義ファイルが読み込めませんでした。 : ",
  937. f_strFileName,
  938. ".phy : ",
  939. ex.Message,
  940. " : StackTrace :\n",
  941. ex.StackTrace
  942. }));
  943. throw ex;
  944. }
  945. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_byPhyTempFile), Encoding.UTF8);
  946. DynamicBone dynamicBone = f_goRoot.AddComponent<DynamicBone>();
  947. if (f_aryDefStiffness != null && f_aryDefStiffness.Length == 3)
  948. {
  949. dynamicBone.m_ValueFromBone[2, 0] = f_aryDefStiffness[0];
  950. dynamicBone.m_ValueFromBone[2, 1] = f_aryDefStiffness[1];
  951. dynamicBone.m_ValueFromBone[2, 2] = f_aryDefStiffness[2];
  952. }
  953. dynamicBone.m_Root = f_trHairRoot;
  954. dynamicBone.SerializeRead(binaryReader);
  955. dynamicBone.m_strNowReadPhysicsFileName = f_strFileName;
  956. dynamicBone.m_hitFloorPlane = body.m_hitFloorPlane;
  957. binaryReader.Close();
  958. return dynamicBone;
  959. }
  960. public static bool LoadDynamicCollilder(DynamicBone f_db, string f_strFileName, Transform f_trBodyBoneRoot, Maid f_maid)
  961. {
  962. try
  963. {
  964. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName + ".col", null))
  965. {
  966. if (afileBase == null || !afileBase.IsValid())
  967. {
  968. Debug.LogError(f_strFileName + ".col が開けません。");
  969. return false;
  970. }
  971. if (ImportCM.m_byPhyTempFile == null)
  972. {
  973. ImportCM.m_byPhyTempFile = new byte[Math.Max(50000, afileBase.GetSize())];
  974. }
  975. else if (ImportCM.m_byPhyTempFile.Length < afileBase.GetSize())
  976. {
  977. ImportCM.m_byPhyTempFile = new byte[afileBase.GetSize()];
  978. }
  979. afileBase.Read(ref ImportCM.m_byPhyTempFile, afileBase.GetSize());
  980. }
  981. }
  982. catch (Exception ex)
  983. {
  984. Debug.LogError(string.Concat(new string[]
  985. {
  986. "LoadDynamicCollilder 物理Colliderファイルが読み込めませんでした。 : ",
  987. f_strFileName,
  988. ".col : ",
  989. ex.Message,
  990. " : StackTrace :\n",
  991. ex.StackTrace
  992. }));
  993. throw ex;
  994. }
  995. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_byPhyTempFile), Encoding.UTF8);
  996. f_db.SerializeReadCollider(binaryReader, f_trBodyBoneRoot, Path.GetFileNameWithoutExtension(f_strFileName), f_maid);
  997. binaryReader.Close();
  998. return true;
  999. }
  1000. public static DynamicSkirtBone TryLoadDynamicSkirtBone(GameObject f_goRoot, Transform f_trSkirtRoot, string f_strFileName, TBody body)
  1001. {
  1002. try
  1003. {
  1004. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName + ".psk", null))
  1005. {
  1006. if (afileBase == null || !afileBase.IsValid())
  1007. {
  1008. return null;
  1009. }
  1010. if (ImportCM.m_byPhyTempFile == null)
  1011. {
  1012. ImportCM.m_byPhyTempFile = new byte[Math.Max(50000, afileBase.GetSize())];
  1013. }
  1014. else if (ImportCM.m_byPhyTempFile.Length < afileBase.GetSize())
  1015. {
  1016. ImportCM.m_byPhyTempFile = new byte[afileBase.GetSize()];
  1017. }
  1018. afileBase.Read(ref ImportCM.m_byPhyTempFile, afileBase.GetSize());
  1019. }
  1020. }
  1021. catch (Exception ex)
  1022. {
  1023. Debug.LogError(string.Concat(new string[]
  1024. {
  1025. "TryLoadSkirtDynamicBone スカート物理定義ファイルが読み込めませんでした。 : ",
  1026. f_strFileName,
  1027. ".psk : ",
  1028. ex.Message,
  1029. " : StackTrace :\n",
  1030. ex.StackTrace
  1031. }));
  1032. throw ex;
  1033. }
  1034. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_byPhyTempFile), Encoding.UTF8);
  1035. DynamicSkirtBone dynamicSkirtBone = f_goRoot.AddComponent<DynamicSkirtBone>();
  1036. dynamicSkirtBone.SerializeRead(binaryReader);
  1037. binaryReader.Close();
  1038. return dynamicSkirtBone;
  1039. }
  1040. public static GameObject LoadGeneralModelFile(string f_strPathFileName)
  1041. {
  1042. GameObject gameObject = null;
  1043. GameObject result;
  1044. using (AssetLoader assetLoader = new AssetLoader())
  1045. {
  1046. try
  1047. {
  1048. AssetLoaderOptions assetLoaderOptions = AssetLoaderOptions.CreateInstance();
  1049. assetLoaderOptions.AutoPlayAnimations = true;
  1050. gameObject = assetLoader.LoadFromFile(f_strPathFileName, assetLoaderOptions, null);
  1051. }
  1052. catch (Exception ex)
  1053. {
  1054. Debug.LogError(ex.ToString());
  1055. }
  1056. result = gameObject;
  1057. }
  1058. return result;
  1059. }
  1060. private static byte[] m_skinTempFile = null;
  1061. private static byte[] m_matTempFile = null;
  1062. private static Dictionary<int, KeyValuePair<string, float>> m_hashPriorityMaterials = null;
  1063. private static Dictionary<string, Material> m_dicCacheMaterial = new Dictionary<string, Material>();
  1064. private static byte[] m_texTempFile = null;
  1065. private static byte[] m_texTempImg = null;
  1066. public static byte[] m_aniTempFile = null;
  1067. public static byte[] m_byPhyTempFile = null;
  1068. private class BoneUse
  1069. {
  1070. public BoneUse(string f_name, int f_idx, Transform f_bone)
  1071. {
  1072. this.name = f_name;
  1073. this.idx = f_idx;
  1074. this.bone = f_bone;
  1075. }
  1076. public bool use;
  1077. public string name;
  1078. public int idx;
  1079. public Transform bone;
  1080. public bool delete;
  1081. }
  1082. public class OldSkirtBoneRev
  1083. {
  1084. public bool bRecursiv = true;
  1085. public Vector3 vRotRevInit;
  1086. public Vector3 vRotRevAfter;
  1087. }
  1088. }