ImportCM.cs 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574
  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. bool flag = filename.Contains("crc_") || filename.Contains("crx_") || filename.Contains("gp03_");
  66. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_skinTempFile), Encoding.UTF8);
  67. TBodySkin.OriVert oriVert = bodyskin.m_OriVert;
  68. GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  69. gameObject.layer = layer;
  70. GameObject gameObject2 = null;
  71. Hashtable hashtable = new Hashtable();
  72. string text = binaryReader.ReadString();
  73. if (text != "CM3D2_MESH")
  74. {
  75. NDebug.Assert("LoadSkinMesh_R 例外 : ヘッダーファイルが不正です。" + text, false);
  76. }
  77. int num = binaryReader.ReadInt32();
  78. string str = binaryReader.ReadString();
  79. gameObject.name = "_SM_" + str;
  80. string b = binaryReader.ReadString();
  81. Dictionary<string, ImportCM.BoneUse> dictionary = new Dictionary<string, ImportCM.BoneUse>();
  82. int num2 = binaryReader.ReadInt32();
  83. List<GameObject> list = new List<GameObject>();
  84. for (int i = 0; i < num2; i++)
  85. {
  86. GameObject gameObject3 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  87. gameObject3.layer = layer;
  88. gameObject3.name = binaryReader.ReadString();
  89. list.Add(gameObject3);
  90. if (gameObject3.name == b)
  91. {
  92. gameObject2 = gameObject3;
  93. }
  94. hashtable[gameObject3.name] = gameObject3;
  95. dictionary[gameObject3.name] = new ImportCM.BoneUse(gameObject3.name, -1, gameObject3.transform);
  96. bool flag2 = binaryReader.ReadByte() != 0;
  97. if (flag2)
  98. {
  99. GameObject gameObject4 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  100. gameObject4.name = gameObject3.name + "_SCL_";
  101. gameObject4.transform.parent = gameObject3.transform;
  102. hashtable[gameObject3.name + "&_SCL_"] = gameObject4;
  103. dictionary[gameObject4.name] = new ImportCM.BoneUse(gameObject4.name, -1, gameObject4.transform);
  104. }
  105. }
  106. for (int j = 0; j < num2; j++)
  107. {
  108. int num3 = binaryReader.ReadInt32();
  109. if (num3 >= 0)
  110. {
  111. list[j].transform.parent = list[num3].transform;
  112. }
  113. else
  114. {
  115. list[j].transform.parent = gameObject.transform;
  116. }
  117. }
  118. for (int k = 0; k < num2; k++)
  119. {
  120. Transform transform = list[k].transform;
  121. float x = binaryReader.ReadSingle();
  122. float y = binaryReader.ReadSingle();
  123. float z = binaryReader.ReadSingle();
  124. transform.localPosition = new Vector3(x, y, z);
  125. float x2 = binaryReader.ReadSingle();
  126. float y2 = binaryReader.ReadSingle();
  127. float z2 = binaryReader.ReadSingle();
  128. float w = binaryReader.ReadSingle();
  129. transform.localRotation = new Quaternion(x2, y2, z2, w);
  130. if (2001 <= num)
  131. {
  132. bool flag3 = binaryReader.ReadBoolean();
  133. if (flag3)
  134. {
  135. float x3 = binaryReader.ReadSingle();
  136. float y3 = binaryReader.ReadSingle();
  137. float z3 = binaryReader.ReadSingle();
  138. transform.localScale = new Vector3(x3, y3, z3);
  139. }
  140. }
  141. }
  142. int num4 = binaryReader.ReadInt32();
  143. int num5 = binaryReader.ReadInt32();
  144. int num6 = binaryReader.ReadInt32();
  145. oriVert.VCount = num4;
  146. oriVert.nSubMeshCount = num5;
  147. SkinnedMeshRenderer skinnedMeshRenderer = gameObject2.AddComponent<SkinnedMeshRenderer>();
  148. skinnedMeshRenderer.updateWhenOffscreen = true;
  149. skinnedMeshRenderer.skinnedMotionVectors = false;
  150. skinnedMeshRenderer.lightProbeUsage = LightProbeUsage.Off;
  151. skinnedMeshRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
  152. skinnedMeshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
  153. if (!bodyskin.body.boMAN)
  154. {
  155. if (slotname == "head")
  156. {
  157. skinnedMeshRenderer.castShadows = false;
  158. }
  159. if (bodyskin.Category == "chikubi")
  160. {
  161. skinnedMeshRenderer.castShadows = false;
  162. }
  163. if (bodyskin.Category.IndexOf("seieki_") == 0)
  164. {
  165. skinnedMeshRenderer.castShadows = false;
  166. }
  167. }
  168. bodyskin.listDEL.Add(gameObject2);
  169. ImportCM.BoneUse[] array = new ImportCM.BoneUse[num6];
  170. Transform[] array2 = new Transform[num6];
  171. for (int l = 0; l < num6; l++)
  172. {
  173. string text2 = binaryReader.ReadString();
  174. if (!hashtable.ContainsKey(text2))
  175. {
  176. Debug.LogError("nullbone= " + text2);
  177. }
  178. else
  179. {
  180. GameObject gameObject5;
  181. if (hashtable.ContainsKey(text2 + "&_SCL_"))
  182. {
  183. gameObject5 = (GameObject)hashtable[text2 + "&_SCL_"];
  184. }
  185. else
  186. {
  187. gameObject5 = (GameObject)hashtable[text2];
  188. }
  189. array2[l] = gameObject5.transform;
  190. ImportCM.BoneUse[] array3 = array;
  191. int num7 = l;
  192. ImportCM.BoneUse boneUse = new ImportCM.BoneUse(gameObject5.name, l, gameObject5.transform);
  193. dictionary[gameObject5.name] = boneUse;
  194. array3[num7] = boneUse;
  195. }
  196. }
  197. skinnedMeshRenderer.bones = array2;
  198. Mesh mesh = new Mesh();
  199. skinnedMeshRenderer.sharedMesh = mesh;
  200. Mesh mesh2 = mesh;
  201. bodyskin.listDEL.Add(mesh2);
  202. Matrix4x4[] array4 = new Matrix4x4[num6];
  203. for (int m = 0; m < num6; m++)
  204. {
  205. for (int n = 0; n < 16; n++)
  206. {
  207. array4[m][n] = binaryReader.ReadSingle();
  208. }
  209. }
  210. mesh2.bindposes = array4;
  211. Vector3[] array5 = new Vector3[num4];
  212. Vector3[] array6 = new Vector3[num4];
  213. Vector2[] array7 = new Vector2[num4];
  214. Vector2[] array8 = null;
  215. Vector2[] array9 = null;
  216. Vector2[] array10 = null;
  217. BoneWeight[] array11 = new BoneWeight[num4];
  218. bool flag4 = false;
  219. bool flag5 = false;
  220. bool flag6 = false;
  221. bool flag7 = false;
  222. bool flag8 = false;
  223. bool flag9 = false;
  224. bool flag10 = false;
  225. if (2101 <= num)
  226. {
  227. if (flag4 = binaryReader.ReadBoolean())
  228. {
  229. array8 = new Vector2[num4];
  230. }
  231. if (flag5 = binaryReader.ReadBoolean())
  232. {
  233. array9 = new Vector2[num4];
  234. }
  235. if (flag6 = binaryReader.ReadBoolean())
  236. {
  237. array10 = new Vector2[num4];
  238. }
  239. flag7 = binaryReader.ReadBoolean();
  240. flag8 = binaryReader.ReadBoolean();
  241. flag9 = binaryReader.ReadBoolean();
  242. flag10 = binaryReader.ReadBoolean();
  243. }
  244. for (int num8 = 0; num8 < num4; num8++)
  245. {
  246. float num9 = binaryReader.ReadSingle();
  247. float num10 = binaryReader.ReadSingle();
  248. float new_z = binaryReader.ReadSingle();
  249. array5[num8].Set(num9, num10, new_z);
  250. num9 = binaryReader.ReadSingle();
  251. num10 = binaryReader.ReadSingle();
  252. new_z = binaryReader.ReadSingle();
  253. array6[num8].Set(num9, num10, new_z);
  254. num9 = binaryReader.ReadSingle();
  255. num10 = binaryReader.ReadSingle();
  256. array7[num8].Set(num9, num10);
  257. if (flag4)
  258. {
  259. num9 = binaryReader.ReadSingle();
  260. num10 = binaryReader.ReadSingle();
  261. array8[num8].Set(num9, num10);
  262. }
  263. if (flag5)
  264. {
  265. num9 = binaryReader.ReadSingle();
  266. num10 = binaryReader.ReadSingle();
  267. array9[num8].Set(num9, num10);
  268. }
  269. if (flag6)
  270. {
  271. num9 = binaryReader.ReadSingle();
  272. num10 = binaryReader.ReadSingle();
  273. array10[num8].Set(num9, num10);
  274. }
  275. if (flag7)
  276. {
  277. num9 = binaryReader.ReadSingle();
  278. num10 = binaryReader.ReadSingle();
  279. }
  280. if (flag8)
  281. {
  282. num9 = binaryReader.ReadSingle();
  283. num10 = binaryReader.ReadSingle();
  284. }
  285. if (flag9)
  286. {
  287. num9 = binaryReader.ReadSingle();
  288. num10 = binaryReader.ReadSingle();
  289. }
  290. if (flag10)
  291. {
  292. num9 = binaryReader.ReadSingle();
  293. num10 = binaryReader.ReadSingle();
  294. }
  295. }
  296. mesh2.vertices = array5;
  297. mesh2.normals = array6;
  298. mesh2.uv = array7;
  299. mesh2.uv2 = array8;
  300. mesh2.uv3 = array9;
  301. mesh2.uv4 = array10;
  302. oriVert.vOriVert = array5;
  303. oriVert.vOriNorm = array6;
  304. if (bodyskin.SlotId == TBody.SlotID.body)
  305. {
  306. oriVert.vOriUV = mesh2.uv;
  307. }
  308. int num11 = binaryReader.ReadInt32();
  309. if (num11 > 0)
  310. {
  311. Vector4[] array12 = new Vector4[num11];
  312. for (int num12 = 0; num12 < num11; num12++)
  313. {
  314. float x4 = binaryReader.ReadSingle();
  315. float y4 = binaryReader.ReadSingle();
  316. float z4 = binaryReader.ReadSingle();
  317. float w2 = binaryReader.ReadSingle();
  318. array12[num12] = new Vector4(x4, y4, z4, w2);
  319. }
  320. mesh2.tangents = array12;
  321. }
  322. for (int num13 = 0; num13 < num4; num13++)
  323. {
  324. int num14 = (int)binaryReader.ReadUInt16();
  325. array11[num13].boneIndex0 = num14;
  326. int num15 = num14;
  327. num14 = (int)binaryReader.ReadUInt16();
  328. array11[num13].boneIndex1 = num14;
  329. int num16 = num14;
  330. num14 = (int)binaryReader.ReadUInt16();
  331. array11[num13].boneIndex2 = num14;
  332. int num17 = num14;
  333. num14 = (int)binaryReader.ReadUInt16();
  334. array11[num13].boneIndex3 = num14;
  335. int num18 = num14;
  336. array[num15].use = true;
  337. array[num16].use = true;
  338. array[num17].use = true;
  339. array[num18].use = true;
  340. array11[num13].weight0 = binaryReader.ReadSingle();
  341. array11[num13].weight1 = binaryReader.ReadSingle();
  342. array11[num13].weight2 = binaryReader.ReadSingle();
  343. array11[num13].weight3 = binaryReader.ReadSingle();
  344. }
  345. ImportCM.BoneUse boneUse2;
  346. if (!flag && dictionary.TryGetValue("Bip01", out boneUse2))
  347. {
  348. ImportCM.RemoveNoWeightBone(dictionary, boneUse2.bone);
  349. }
  350. mesh2.boneWeights = array11;
  351. mesh2.subMeshCount = num5;
  352. oriVert.bwWeight = array11;
  353. oriVert.nSubMeshCount = num5;
  354. oriVert.nSubMeshOriTri = new int[num5][];
  355. for (int num19 = 0; num19 < num5; num19++)
  356. {
  357. int num20 = binaryReader.ReadInt32();
  358. int[] array13 = new int[num20];
  359. for (int num21 = 0; num21 < num20; num21++)
  360. {
  361. array13[num21] = (int)binaryReader.ReadUInt16();
  362. }
  363. oriVert.nSubMeshOriTri[num19] = array13;
  364. mesh2.SetTriangles(array13, num19);
  365. }
  366. int num22 = binaryReader.ReadInt32();
  367. Material[] array14 = new Material[num22];
  368. for (int num23 = 0; num23 < num22; num23++)
  369. {
  370. Material material = ImportCM.ReadMaterial(binaryReader, bodyskin, null, num);
  371. array14[num23] = material;
  372. }
  373. skinnedMeshRenderer.materials = array14;
  374. for (;;)
  375. {
  376. string a = binaryReader.ReadString();
  377. if (a == "end")
  378. {
  379. break;
  380. }
  381. if (a == "morph")
  382. {
  383. morph.LoadMoprhData2(binaryReader, num);
  384. }
  385. }
  386. if (2100 <= num)
  387. {
  388. int num24 = binaryReader.ReadInt32();
  389. if (num24 != 0)
  390. {
  391. oriVert.skinThick = new SkinThickness();
  392. oriVert.skinThick.Deserialize(binaryReader);
  393. }
  394. }
  395. binaryReader.Close();
  396. return gameObject;
  397. }
  398. public static Material LoadMaterial(string f_strFileName, TBodySkin bodyskin, Material existmat = null)
  399. {
  400. try
  401. {
  402. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName, null))
  403. {
  404. NDebug.Assert(afileBase.IsValid(), "LoadMaterial マテリアルコンテナが読めません。 :" + f_strFileName);
  405. if (ImportCM.m_matTempFile == null)
  406. {
  407. ImportCM.m_matTempFile = new byte[Math.Max(10000, afileBase.GetSize())];
  408. }
  409. else if (ImportCM.m_matTempFile.Length < afileBase.GetSize())
  410. {
  411. ImportCM.m_matTempFile = new byte[afileBase.GetSize()];
  412. }
  413. afileBase.Read(ref ImportCM.m_matTempFile, afileBase.GetSize());
  414. }
  415. }
  416. catch (Exception ex)
  417. {
  418. Debug.LogError(string.Concat(new string[]
  419. {
  420. "LoadMaterial マテリアルコンテナが読み込めませんでした。 : ",
  421. f_strFileName,
  422. " : ",
  423. ex.Message,
  424. " : StackTrace :\n",
  425. ex.StackTrace
  426. }));
  427. throw ex;
  428. }
  429. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_matTempFile), Encoding.UTF8);
  430. string text = binaryReader.ReadString();
  431. if (text != "CM3D2_MATERIAL")
  432. {
  433. NDebug.Assert("ProcScriptBin 例外 : ヘッダーファイルが不正です。" + text, false);
  434. }
  435. int parentVer = binaryReader.ReadInt32();
  436. string text2 = binaryReader.ReadString();
  437. Material result = ImportCM.ReadMaterial(binaryReader, bodyskin, existmat, parentVer);
  438. binaryReader.Close();
  439. return result;
  440. }
  441. public static Material ReadMaterial(BinaryReader r, TBodySkin bodyskin = null, Material existmat = null, int parentVer = 0)
  442. {
  443. if (ImportCM.m_hashPriorityMaterials == null)
  444. {
  445. ImportCM.m_hashPriorityMaterials = new Dictionary<int, KeyValuePair<string, float>>();
  446. string[] list = GameUty.FileSystem.GetList("prioritymaterial", AFileSystemBase.ListType.AllFile);
  447. if (list != null && 0 < list.Length)
  448. {
  449. for (int i = 0; i < list.Length; i++)
  450. {
  451. if (Path.GetExtension(list[i]) == ".pmat")
  452. {
  453. string text = list[i];
  454. using (AFileBase afileBase = GameUty.FileOpen(text, null))
  455. {
  456. NDebug.Assert(afileBase.IsValid(), text + "を開けませんでした");
  457. byte[] buffer = afileBase.ReadAll();
  458. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer), Encoding.UTF8))
  459. {
  460. string a = binaryReader.ReadString();
  461. if (a != "CM3D2_PMATERIAL")
  462. {
  463. NDebug.Assert("ヘッダーエラー\n" + text, false);
  464. }
  465. int num = binaryReader.ReadInt32();
  466. int key = binaryReader.ReadInt32();
  467. string key2 = binaryReader.ReadString();
  468. float value = binaryReader.ReadSingle();
  469. NDebug.Assert(!ImportCM.m_hashPriorityMaterials.ContainsKey(key), "すでにハッシュが登録されています");
  470. ImportCM.m_hashPriorityMaterials.Add(key, new KeyValuePair<string, float>(key2, value));
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }
  477. string text2 = r.ReadString();
  478. string text3 = r.ReadString();
  479. string text4 = r.ReadString();
  480. Material material;
  481. if (text2.IndexOf("gp03_") == 0)
  482. {
  483. text3 = text3.Replace("CM3D2", "GP03").Replace("/", "_");
  484. Shader shader = Resources.Load("Shaders/GP03/" + text3) as Shader;
  485. NDebug.Assert(shader != null, "GP03 Shader not found. -> " + text3);
  486. if (existmat == null)
  487. {
  488. material = new Material(shader);
  489. }
  490. else
  491. {
  492. material = existmat;
  493. material.shader = shader;
  494. }
  495. material.name = text2;
  496. if (r.ReadBoolean())
  497. {
  498. float num2 = r.ReadSingle();
  499. material.SetFloat("_SetManualRenderQueue", num2);
  500. material.renderQueue = (int)num2;
  501. }
  502. }
  503. else
  504. {
  505. if (existmat == null)
  506. {
  507. Material material2;
  508. if (!ImportCM.m_dicCacheMaterial.TryGetValue(text4, out material2))
  509. {
  510. string text5 = "DefMaterial/" + text4;
  511. material2 = (Resources.Load(text5, typeof(Material)) as Material);
  512. if (material2 == null)
  513. {
  514. NDebug.Assert("DefMaterialが見つかりません。" + text5, false);
  515. }
  516. ImportCM.m_dicCacheMaterial[text4] = material2;
  517. }
  518. material = UnityEngine.Object.Instantiate<Material>(material2);
  519. if (bodyskin != null)
  520. {
  521. bodyskin.listDEL.Add(material);
  522. }
  523. }
  524. else
  525. {
  526. material = existmat;
  527. if (material.shader.name != text3)
  528. {
  529. NDebug.Warning("マテリアル入れ替えエラー。違うシェーダーに入れようとしました。 " + text3 + " -> " + material.shader.name);
  530. }
  531. }
  532. material.name = text2;
  533. int hashCode = material.name.GetHashCode();
  534. if (ImportCM.m_hashPriorityMaterials != null && ImportCM.m_hashPriorityMaterials.ContainsKey(hashCode))
  535. {
  536. KeyValuePair<string, float> keyValuePair = ImportCM.m_hashPriorityMaterials[hashCode];
  537. if (keyValuePair.Key == material.name)
  538. {
  539. material.SetFloat("_SetManualRenderQueue", keyValuePair.Value);
  540. material.renderQueue = (int)keyValuePair.Value;
  541. }
  542. }
  543. }
  544. for (;;)
  545. {
  546. string text6 = r.ReadString();
  547. if (text6 == "end")
  548. {
  549. break;
  550. }
  551. string name = r.ReadString();
  552. if (text6 == "tex")
  553. {
  554. string a2 = r.ReadString();
  555. if (a2 == "null")
  556. {
  557. material.SetTexture(name, null);
  558. }
  559. else if (a2 == "tex2d")
  560. {
  561. string text7 = r.ReadString();
  562. string text8 = r.ReadString();
  563. Texture2D texture2D = ImportCM.CreateTexture(text7 + ".tex");
  564. texture2D.name = text7;
  565. texture2D.wrapMode = TextureWrapMode.Clamp;
  566. material.SetTexture(name, texture2D);
  567. if (bodyskin != null)
  568. {
  569. bodyskin.listDEL.Add(texture2D);
  570. }
  571. Vector2 value2;
  572. value2.x = r.ReadSingle();
  573. value2.y = r.ReadSingle();
  574. material.SetTextureOffset(name, value2);
  575. Vector2 value3;
  576. value3.x = r.ReadSingle();
  577. value3.y = r.ReadSingle();
  578. material.SetTextureScale(name, value3);
  579. }
  580. else if (a2 == "texRT")
  581. {
  582. string text9 = r.ReadString();
  583. string text10 = r.ReadString();
  584. }
  585. }
  586. else if (text6 == "col")
  587. {
  588. Color value4;
  589. value4.r = r.ReadSingle();
  590. value4.g = r.ReadSingle();
  591. value4.b = r.ReadSingle();
  592. value4.a = r.ReadSingle();
  593. material.SetColor(name, value4);
  594. }
  595. else if (text6 == "vec")
  596. {
  597. Vector4 value5;
  598. value5.x = r.ReadSingle();
  599. value5.y = r.ReadSingle();
  600. value5.z = r.ReadSingle();
  601. value5.w = r.ReadSingle();
  602. material.SetVector(name, value5);
  603. }
  604. else if (text6 == "f")
  605. {
  606. float value6 = r.ReadSingle();
  607. material.SetFloat(name, value6);
  608. }
  609. else if (text6 == "range")
  610. {
  611. float value7 = r.ReadSingle();
  612. material.SetFloat(name, value7);
  613. }
  614. else if (text6 == "tex_offset")
  615. {
  616. Vector2 value8;
  617. value8.x = r.ReadSingle();
  618. value8.y = r.ReadSingle();
  619. material.SetTextureOffset(name, value8);
  620. }
  621. else if (text6 == "tex_scale")
  622. {
  623. Vector2 value9;
  624. value9.x = r.ReadSingle();
  625. value9.y = r.ReadSingle();
  626. material.SetTextureScale(name, value9);
  627. }
  628. else if (text6 == "keyword")
  629. {
  630. int num3 = r.ReadInt32();
  631. for (int j = 0; j < num3; j++)
  632. {
  633. string keyword = r.ReadString();
  634. bool flag = r.ReadBoolean();
  635. if (flag)
  636. {
  637. material.EnableKeyword(keyword);
  638. }
  639. else
  640. {
  641. material.DisableKeyword(keyword);
  642. }
  643. }
  644. }
  645. else
  646. {
  647. Debug.LogError("マテリアルが読み込めません。不正なマテリアルプロパティ型です " + text6);
  648. }
  649. }
  650. return material;
  651. }
  652. public static GameObject LoadOnlyBone_R(byte[] bs)
  653. {
  654. GameObject gameObject = new GameObject();
  655. gameObject.layer = 10;
  656. BinaryReader binaryReader = new BinaryReader(new MemoryStream(bs));
  657. Hashtable hashtable = new Hashtable();
  658. string text = binaryReader.ReadString();
  659. if (text != "CM3D2_MESH")
  660. {
  661. NDebug.Assert("LoadOnlyBone_R 例外 : ヘッダーファイルが不正です。" + text, false);
  662. }
  663. int num = binaryReader.ReadInt32();
  664. string str = binaryReader.ReadString();
  665. gameObject.name = "_BO_" + str;
  666. string text2 = binaryReader.ReadString();
  667. int num2 = binaryReader.ReadInt32();
  668. List<GameObject> list = new List<GameObject>();
  669. for (int i = 0; i < num2; i++)
  670. {
  671. GameObject gameObject2 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  672. gameObject2.layer = 10;
  673. gameObject2.name = binaryReader.ReadString();
  674. list.Add(gameObject2);
  675. hashtable[gameObject2.name] = gameObject2;
  676. bool flag = binaryReader.ReadByte() != 0;
  677. if (flag)
  678. {
  679. GameObject gameObject3 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject;
  680. gameObject2.layer = 10;
  681. gameObject3.name = gameObject2.name + "_SCL_";
  682. gameObject3.transform.parent = gameObject2.transform;
  683. hashtable[gameObject2.name + "&_SCL_"] = gameObject3;
  684. }
  685. }
  686. for (int j = 0; j < num2; j++)
  687. {
  688. int num3 = binaryReader.ReadInt32();
  689. if (num3 >= 0)
  690. {
  691. list[j].transform.parent = list[num3].transform;
  692. }
  693. else
  694. {
  695. list[j].transform.parent = gameObject.transform;
  696. }
  697. }
  698. for (int k = 0; k < num2; k++)
  699. {
  700. Transform transform = list[k].transform;
  701. float x = binaryReader.ReadSingle();
  702. float y = binaryReader.ReadSingle();
  703. float z = binaryReader.ReadSingle();
  704. transform.localPosition = new Vector3(x, y, z);
  705. float x2 = binaryReader.ReadSingle();
  706. float y2 = binaryReader.ReadSingle();
  707. float z2 = binaryReader.ReadSingle();
  708. float w = binaryReader.ReadSingle();
  709. transform.localRotation = new Quaternion(x2, y2, z2, w);
  710. if (2001 <= num)
  711. {
  712. bool flag2 = binaryReader.ReadBoolean();
  713. if (flag2)
  714. {
  715. float x3 = binaryReader.ReadSingle();
  716. float y3 = binaryReader.ReadSingle();
  717. float z3 = binaryReader.ReadSingle();
  718. transform.localScale = new Vector3(x3, y3, z3);
  719. }
  720. }
  721. }
  722. binaryReader.Close();
  723. gameObject.AddComponent(typeof(Animation));
  724. return gameObject;
  725. }
  726. public static Dictionary<string, ImportCM.OldSkirtBoneRev> LoadOldSkirtBoneRev(string f_strModelName)
  727. {
  728. Dictionary<string, ImportCM.OldSkirtBoneRev> dictionary = null;
  729. if (f_strModelName.Contains("dress020_onep"))
  730. {
  731. dictionary = new Dictionary<string, ImportCM.OldSkirtBoneRev>();
  732. for (int i = 1; i <= 12; i++)
  733. {
  734. dictionary.Add("Skirt" + i.ToString("00") + "_A_yure_skirt_h_", new ImportCM.OldSkirtBoneRev
  735. {
  736. bRecursiv = true,
  737. vRotRevInit = new Vector3((i != 7 && i != 8) ? 90f : -90f, 0f, 0f),
  738. vRotRevAfter = new Vector3((i != 7 && i != 8) ? -90f : 90f, 0f, 0f)
  739. });
  740. }
  741. }
  742. else if (f_strModelName.Contains("dress131_onep"))
  743. {
  744. dictionary = new Dictionary<string, ImportCM.OldSkirtBoneRev>();
  745. for (int j = 1; j <= 12; j++)
  746. {
  747. dictionary.Add("Skirt" + j.ToString("00") + "_A_yure_skirt_", new ImportCM.OldSkirtBoneRev
  748. {
  749. bRecursiv = true,
  750. vRotRevInit = new Vector3(0f, 0f, 0f),
  751. vRotRevAfter = new Vector3(180f, 0f, 0f)
  752. });
  753. }
  754. }
  755. return dictionary;
  756. }
  757. public static Texture2D CreateTexture(string f_strFileName)
  758. {
  759. return ImportCM.LoadTexture(GameUty.FileSystem, f_strFileName, true).CreateTexture2D();
  760. }
  761. public static Texture2D CreateTexture(AFileSystemBase f_fileSystem, string f_strFileName)
  762. {
  763. return ImportCM.LoadTexture(f_fileSystem, f_strFileName, true).CreateTexture2D();
  764. }
  765. public static TextureResource LoadTexture(AFileSystemBase f_fileSystem, string f_strFileName, bool usePoolBuffer)
  766. {
  767. try
  768. {
  769. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName, f_fileSystem))
  770. {
  771. if (!afileBase.IsValid())
  772. {
  773. NDebug.Assert("LoadTexture テクスチャコンテナが読めません。 :" + f_strFileName, false);
  774. }
  775. if (ImportCM.m_texTempFile == null)
  776. {
  777. ImportCM.m_texTempFile = new byte[Math.Max(500000, afileBase.GetSize())];
  778. }
  779. else if (ImportCM.m_texTempFile.Length < afileBase.GetSize())
  780. {
  781. ImportCM.m_texTempFile = new byte[afileBase.GetSize()];
  782. }
  783. afileBase.Read(ref ImportCM.m_texTempFile, afileBase.GetSize());
  784. }
  785. }
  786. catch (Exception ex)
  787. {
  788. Debug.LogError(string.Concat(new string[]
  789. {
  790. "LoadTexture テクスチャコンテナが読み込めませんでした。 : ",
  791. f_strFileName,
  792. " : ",
  793. ex.Message,
  794. " : StackTrace :\n",
  795. ex.StackTrace
  796. }));
  797. throw ex;
  798. }
  799. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_texTempFile), Encoding.UTF8);
  800. string text = binaryReader.ReadString();
  801. if (text != "CM3D2_TEX")
  802. {
  803. NDebug.Assert("ProcScriptBin 例外 : ヘッダーファイルが不正です。" + text, false);
  804. }
  805. int num = binaryReader.ReadInt32();
  806. string text2 = binaryReader.ReadString();
  807. int width = 0;
  808. int height = 0;
  809. TextureFormat textureFormat = TextureFormat.ARGB32;
  810. Rect[] array = null;
  811. if (1010 <= num)
  812. {
  813. if (1011 <= num)
  814. {
  815. int num2 = binaryReader.ReadInt32();
  816. if (0 < num2)
  817. {
  818. array = new Rect[num2];
  819. for (int i = 0; i < num2; i++)
  820. {
  821. float x = binaryReader.ReadSingle();
  822. float y = binaryReader.ReadSingle();
  823. float width2 = binaryReader.ReadSingle();
  824. float height2 = binaryReader.ReadSingle();
  825. array[i] = new Rect(x, y, width2, height2);
  826. }
  827. }
  828. }
  829. width = binaryReader.ReadInt32();
  830. height = binaryReader.ReadInt32();
  831. textureFormat = (TextureFormat)binaryReader.ReadInt32();
  832. }
  833. int num3 = binaryReader.ReadInt32();
  834. byte[] array2;
  835. if (usePoolBuffer && textureFormat == TextureFormat.ARGB32)
  836. {
  837. if (ImportCM.m_texTempImg == null)
  838. {
  839. ImportCM.m_texTempImg = new byte[Math.Max(500000, num3)];
  840. }
  841. else if (ImportCM.m_texTempImg.Length < num3)
  842. {
  843. ImportCM.m_texTempImg = new byte[num3];
  844. }
  845. binaryReader.Read(ImportCM.m_texTempImg, 0, num3);
  846. array2 = ImportCM.m_texTempImg;
  847. }
  848. else
  849. {
  850. array2 = new byte[num3];
  851. binaryReader.Read(array2, 0, num3);
  852. }
  853. if (num == 1000)
  854. {
  855. width = ((int)array2[16] << 24 | (int)array2[17] << 16 | (int)array2[18] << 8 | (int)array2[19]);
  856. height = ((int)array2[20] << 24 | (int)array2[21] << 16 | (int)array2[22] << 8 | (int)array2[23]);
  857. }
  858. binaryReader.Close();
  859. return new TextureResource(width, height, textureFormat, array, array2);
  860. }
  861. public static AnimationClip LoadAniClip(string f_strFileName, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false)
  862. {
  863. try
  864. {
  865. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName, null))
  866. {
  867. NDebug.Assert(afileBase.IsValid(), "LoadAniClip アニメーションファイルが開けません。 :" + f_strFileName);
  868. if (ImportCM.m_aniTempFile == null)
  869. {
  870. ImportCM.m_aniTempFile = new byte[Math.Max(500000, afileBase.GetSize())];
  871. }
  872. else if (ImportCM.m_aniTempFile.Length < afileBase.GetSize())
  873. {
  874. ImportCM.m_aniTempFile = new byte[afileBase.GetSize()];
  875. }
  876. afileBase.Read(ref ImportCM.m_aniTempFile, afileBase.GetSize());
  877. }
  878. }
  879. catch (Exception ex)
  880. {
  881. Debug.LogError(string.Concat(new string[]
  882. {
  883. "LoadAniClip アニメーションファイルが読み込めませんでした。 : ",
  884. f_strFileName,
  885. " : ",
  886. ex.Message,
  887. " : StackTrace :\n",
  888. ex.StackTrace
  889. }));
  890. throw ex;
  891. }
  892. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_aniTempFile), Encoding.UTF8);
  893. string text = binaryReader.ReadString();
  894. if (text != "CM3D2_ANIM")
  895. {
  896. NDebug.Assert("LoadAniClip 例外 : ヘッダーファイルが不正です。" + text, false);
  897. }
  898. int num = binaryReader.ReadInt32();
  899. AnimationClip animationClip = new AnimationClip();
  900. if (animationClip != null)
  901. {
  902. animationClip.legacy = true;
  903. }
  904. string text2 = string.Empty;
  905. int num2 = 0;
  906. for (;;)
  907. {
  908. byte b = binaryReader.ReadByte();
  909. if (b == 0)
  910. {
  911. break;
  912. }
  913. if (b == 1)
  914. {
  915. text2 = binaryReader.ReadString();
  916. num2++;
  917. }
  918. else if (b >= 100)
  919. {
  920. int num3 = binaryReader.ReadInt32();
  921. Keyframe[] array = new Keyframe[num3];
  922. AnimationCurve animationCurve = new AnimationCurve();
  923. for (int i = 0; i < num3; i++)
  924. {
  925. array[i].time = binaryReader.ReadSingle();
  926. array[i].value = binaryReader.ReadSingle();
  927. array[i].inTangent = binaryReader.ReadSingle();
  928. array[i].outTangent = binaryReader.ReadSingle();
  929. }
  930. animationCurve.keys = array;
  931. bool flag = true;
  932. string text3 = text2 + "*";
  933. if (!no_chara)
  934. {
  935. if (b >= 104 && b <= 106 && !text3.Contains("Bip01*") && !text3.Contains("_IK_") && !text3.Contains("ManBip*") && !text3.Contains("Hip_L") && !text3.Contains("Hip_R") && !text2.Contains("Bone_Face"))
  936. {
  937. flag = false;
  938. }
  939. if (!load_l_mune_anime && text3.Contains("Mune_L"))
  940. {
  941. flag = false;
  942. }
  943. if (!load_r_mune_anime && text3.Contains("Mune_R"))
  944. {
  945. flag = false;
  946. }
  947. }
  948. if (flag)
  949. {
  950. animationClip.SetCurve(text2, AnmParse.proptypes[(int)(b - 100)], AnmParse.properties[(int)(b - 100)], animationCurve);
  951. }
  952. }
  953. else
  954. {
  955. Debug.LogError("com " + b);
  956. }
  957. }
  958. binaryReader.Close();
  959. return animationClip;
  960. }
  961. public static AnimationClip LoadAniClip(byte[] file_byte, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false)
  962. {
  963. if (ImportCM.m_aniTempFile == null)
  964. {
  965. ImportCM.m_aniTempFile = new byte[Math.Max(500000, file_byte.Length)];
  966. }
  967. else if (ImportCM.m_aniTempFile.Length < file_byte.Length)
  968. {
  969. ImportCM.m_aniTempFile = new byte[file_byte.Length];
  970. }
  971. Buffer.BlockCopy(file_byte, 0, ImportCM.m_aniTempFile, 0, file_byte.Length);
  972. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_aniTempFile), Encoding.UTF8);
  973. string text = binaryReader.ReadString();
  974. if (text != "CM3D2_ANIM")
  975. {
  976. NDebug.Assert("LoadAniClip 例外 : ヘッダーファイルが不正です。" + text, false);
  977. }
  978. int num = binaryReader.ReadInt32();
  979. AnimationClip animationClip = new AnimationClip();
  980. if (animationClip != null)
  981. {
  982. animationClip.legacy = true;
  983. }
  984. string text2 = string.Empty;
  985. int num2 = 0;
  986. for (;;)
  987. {
  988. byte b = binaryReader.ReadByte();
  989. if (b == 0)
  990. {
  991. break;
  992. }
  993. if (b == 1)
  994. {
  995. text2 = binaryReader.ReadString();
  996. num2++;
  997. }
  998. else if (b >= 100)
  999. {
  1000. int num3 = binaryReader.ReadInt32();
  1001. Keyframe[] array = new Keyframe[num3];
  1002. AnimationCurve animationCurve = new AnimationCurve();
  1003. for (int i = 0; i < num3; i++)
  1004. {
  1005. array[i].time = binaryReader.ReadSingle();
  1006. array[i].value = binaryReader.ReadSingle();
  1007. array[i].inTangent = binaryReader.ReadSingle();
  1008. array[i].outTangent = binaryReader.ReadSingle();
  1009. }
  1010. animationCurve.keys = array;
  1011. bool flag = true;
  1012. string text3 = text2 + "*";
  1013. if (!no_chara)
  1014. {
  1015. if (b >= 104 && b <= 106 && !text3.Contains("Bip01*") && !text3.Contains("_IK_") && !text3.Contains("ManBip*") && !text3.Contains("Hip_L") && !text3.Contains("Hip_R") && !text2.Contains("Bone_Face"))
  1016. {
  1017. flag = false;
  1018. }
  1019. if (!load_l_mune_anime && text3.Contains("Mune_L"))
  1020. {
  1021. flag = false;
  1022. }
  1023. if (!load_r_mune_anime && text3.Contains("Mune_R"))
  1024. {
  1025. flag = false;
  1026. }
  1027. if (flag)
  1028. {
  1029. animationClip.SetCurve(text2, AnmParse.proptypes[(int)(b - 100)], AnmParse.properties[(int)(b - 100)], animationCurve);
  1030. }
  1031. }
  1032. }
  1033. else
  1034. {
  1035. Debug.LogError("com " + b);
  1036. }
  1037. }
  1038. binaryReader.Close();
  1039. return animationClip;
  1040. }
  1041. public static AnimationClip LoadAniClipNative(AFileSystemBase fileSystem, string fileName, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false)
  1042. {
  1043. AnimationClip result = null;
  1044. using (AFileBase afileBase = GameUty.FileOpen(fileName, fileSystem))
  1045. {
  1046. if (afileBase == null || !afileBase.IsValid())
  1047. {
  1048. Debug.LogError(fileName + " はありませんでした。");
  1049. return null;
  1050. }
  1051. result = GameMain.Instance.AnmParse.LoadAnmClip(afileBase, load_l_mune_anime, load_r_mune_anime, no_chara);
  1052. }
  1053. return result;
  1054. }
  1055. public static AnimationClip LoadAniClipNative(byte[] file_byte, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false)
  1056. {
  1057. return GameMain.Instance.AnmParse.LoadAnmClip(file_byte, load_l_mune_anime, load_r_mune_anime, no_chara);
  1058. }
  1059. public static DynamicBone TryLoadDynamicBone(GameObject f_goRoot, Transform f_trHairRoot, string f_strFileName, TBody body, float[] f_aryDefStiffness)
  1060. {
  1061. try
  1062. {
  1063. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName + ".phy", null))
  1064. {
  1065. if (afileBase == null || !afileBase.IsValid())
  1066. {
  1067. return null;
  1068. }
  1069. if (ImportCM.m_byPhyTempFile == null)
  1070. {
  1071. ImportCM.m_byPhyTempFile = new byte[Math.Max(50000, afileBase.GetSize())];
  1072. }
  1073. else if (ImportCM.m_byPhyTempFile.Length < afileBase.GetSize())
  1074. {
  1075. ImportCM.m_byPhyTempFile = new byte[afileBase.GetSize()];
  1076. }
  1077. afileBase.Read(ref ImportCM.m_byPhyTempFile, afileBase.GetSize());
  1078. }
  1079. }
  1080. catch (Exception ex)
  1081. {
  1082. Debug.LogError(string.Concat(new string[]
  1083. {
  1084. "TryLoadDynamicBone 物理定義ファイルが読み込めませんでした。 : ",
  1085. f_strFileName,
  1086. ".phy : ",
  1087. ex.Message,
  1088. " : StackTrace :\n",
  1089. ex.StackTrace
  1090. }));
  1091. throw ex;
  1092. }
  1093. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_byPhyTempFile), Encoding.UTF8);
  1094. DynamicBone dynamicBone = f_goRoot.AddComponent<DynamicBone>();
  1095. if (f_aryDefStiffness != null && f_aryDefStiffness.Length == 3)
  1096. {
  1097. dynamicBone.m_ValueFromBone[2, 0] = f_aryDefStiffness[0];
  1098. dynamicBone.m_ValueFromBone[2, 1] = f_aryDefStiffness[1];
  1099. dynamicBone.m_ValueFromBone[2, 2] = f_aryDefStiffness[2];
  1100. }
  1101. dynamicBone.m_Root = f_trHairRoot;
  1102. dynamicBone.SerializeRead(binaryReader);
  1103. dynamicBone.m_strNowReadPhysicsFileName = f_strFileName;
  1104. dynamicBone.m_hitFloorPlane = body.m_hitFloorPlane;
  1105. binaryReader.Close();
  1106. return dynamicBone;
  1107. }
  1108. public static bool LoadDynamicCollilder(DynamicBone f_db, string f_strFileName, Transform f_trBodyBoneRoot, Maid f_maid)
  1109. {
  1110. try
  1111. {
  1112. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName + ".col", null))
  1113. {
  1114. if (afileBase == null || !afileBase.IsValid())
  1115. {
  1116. Debug.LogError(f_strFileName + ".col が開けません。");
  1117. return false;
  1118. }
  1119. if (ImportCM.m_byPhyTempFile == null)
  1120. {
  1121. ImportCM.m_byPhyTempFile = new byte[Math.Max(50000, afileBase.GetSize())];
  1122. }
  1123. else if (ImportCM.m_byPhyTempFile.Length < afileBase.GetSize())
  1124. {
  1125. ImportCM.m_byPhyTempFile = new byte[afileBase.GetSize()];
  1126. }
  1127. afileBase.Read(ref ImportCM.m_byPhyTempFile, afileBase.GetSize());
  1128. }
  1129. }
  1130. catch (Exception ex)
  1131. {
  1132. Debug.LogError(string.Concat(new string[]
  1133. {
  1134. "LoadDynamicCollilder 物理Colliderファイルが読み込めませんでした。 : ",
  1135. f_strFileName,
  1136. ".col : ",
  1137. ex.Message,
  1138. " : StackTrace :\n",
  1139. ex.StackTrace
  1140. }));
  1141. throw ex;
  1142. }
  1143. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_byPhyTempFile), Encoding.UTF8);
  1144. f_db.SerializeReadCollider(binaryReader, f_trBodyBoneRoot, Path.GetFileNameWithoutExtension(f_strFileName), f_maid);
  1145. binaryReader.Close();
  1146. return true;
  1147. }
  1148. public static DynamicSkirtBone TryLoadDynamicSkirtBone(GameObject f_goRoot, Transform f_trSkirtRoot, string f_strFileName, TBody body)
  1149. {
  1150. try
  1151. {
  1152. using (AFileBase afileBase = GameUty.FileOpen(f_strFileName + ".psk", null))
  1153. {
  1154. if (afileBase == null || !afileBase.IsValid())
  1155. {
  1156. return null;
  1157. }
  1158. if (ImportCM.m_byPhyTempFile == null)
  1159. {
  1160. ImportCM.m_byPhyTempFile = new byte[Math.Max(50000, afileBase.GetSize())];
  1161. }
  1162. else if (ImportCM.m_byPhyTempFile.Length < afileBase.GetSize())
  1163. {
  1164. ImportCM.m_byPhyTempFile = new byte[afileBase.GetSize()];
  1165. }
  1166. afileBase.Read(ref ImportCM.m_byPhyTempFile, afileBase.GetSize());
  1167. }
  1168. }
  1169. catch (Exception ex)
  1170. {
  1171. Debug.LogError(string.Concat(new string[]
  1172. {
  1173. "TryLoadSkirtDynamicBone スカート物理定義ファイルが読み込めませんでした。 : ",
  1174. f_strFileName,
  1175. ".psk : ",
  1176. ex.Message,
  1177. " : StackTrace :\n",
  1178. ex.StackTrace
  1179. }));
  1180. throw ex;
  1181. }
  1182. BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_byPhyTempFile), Encoding.UTF8);
  1183. DynamicSkirtBone dynamicSkirtBone = f_goRoot.AddComponent<DynamicSkirtBone>();
  1184. dynamicSkirtBone.SerializeRead(binaryReader);
  1185. binaryReader.Close();
  1186. return dynamicSkirtBone;
  1187. }
  1188. public static GameObject LoadGeneralModelFile(string f_strPathFileName)
  1189. {
  1190. GameObject gameObject = null;
  1191. GameObject result;
  1192. using (AssetLoader assetLoader = new AssetLoader())
  1193. {
  1194. try
  1195. {
  1196. AssetLoaderOptions assetLoaderOptions = AssetLoaderOptions.CreateInstance();
  1197. assetLoaderOptions.AutoPlayAnimations = true;
  1198. gameObject = assetLoader.LoadFromFile(f_strPathFileName, assetLoaderOptions, null);
  1199. }
  1200. catch (Exception ex)
  1201. {
  1202. Debug.LogError(ex.ToString());
  1203. }
  1204. result = gameObject;
  1205. }
  1206. return result;
  1207. }
  1208. public static CharacterMgr.Preset ImportPresetGP03(Maid maid, out byte[] preCrc, string fileName = null)
  1209. {
  1210. if (string.IsNullOrEmpty(fileName))
  1211. {
  1212. fileName = "gp03_export_" + maid.status.saveDataGuidGP03 + ".brd";
  1213. }
  1214. CharacterMgr.Preset result;
  1215. using (AFileBase afileBase = GameUty.FileOpen(fileName, null))
  1216. {
  1217. if (afileBase == null || !afileBase.IsValid())
  1218. {
  1219. NDebug.MessageBox("Import Error", "GP03_BRIDGE import gp03 error! -> " + fileName);
  1220. preCrc = null;
  1221. result = null;
  1222. }
  1223. else
  1224. {
  1225. byte[] buffer = afileBase.ReadAll();
  1226. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
  1227. {
  1228. string a = binaryReader.ReadString();
  1229. if (a != "GP03_BRIDGE")
  1230. {
  1231. NDebug.MessageBox("Import Error", "import gp03 preset header error!");
  1232. preCrc = null;
  1233. result = null;
  1234. }
  1235. else
  1236. {
  1237. int num = binaryReader.ReadInt32();
  1238. string text = binaryReader.ReadString();
  1239. int count = binaryReader.ReadInt32();
  1240. byte[] buffer2 = binaryReader.ReadBytes(count);
  1241. int count2 = binaryReader.ReadInt32();
  1242. preCrc = binaryReader.ReadBytes(count2);
  1243. using (BinaryReader binaryReader2 = new BinaryReader(new MemoryStream(buffer2)))
  1244. {
  1245. CharacterMgr.Preset preset = GameMain.Instance.CharacterMgr.PresetLoad(binaryReader2, fileName);
  1246. foreach (MaidProp maidProp in preset.listMprop)
  1247. {
  1248. if (string.IsNullOrEmpty(maidProp.strFileName))
  1249. {
  1250. maidProp.nFileNameRID = 0;
  1251. string strFileName;
  1252. if (CM3.dicDelItem.TryGetValue((MPN)maidProp.idx, out strFileName))
  1253. {
  1254. maidProp.strFileName = strFileName;
  1255. maidProp.nFileNameRID = maidProp.strFileName.ToLower().GetHashCode();
  1256. maidProp.boDut = true;
  1257. }
  1258. }
  1259. }
  1260. result = preset;
  1261. }
  1262. }
  1263. }
  1264. }
  1265. }
  1266. return result;
  1267. }
  1268. public static int CheckBrdVerGP03(string saveMaidGuid)
  1269. {
  1270. string fileName = "gp03_export_" + saveMaidGuid + ".brd";
  1271. int result;
  1272. using (AFileBase afileBase = GameUty.FileOpen(fileName, null))
  1273. {
  1274. if (afileBase == null || !afileBase.IsValid())
  1275. {
  1276. Debug.Log("GP03_BRIDGE ver check gp03 error! -> " + saveMaidGuid);
  1277. result = 0;
  1278. }
  1279. else
  1280. {
  1281. byte[] buffer = afileBase.ReadAll();
  1282. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
  1283. {
  1284. string a = binaryReader.ReadString();
  1285. if (a != "GP03_BRIDGE")
  1286. {
  1287. Debug.LogError("import gp03 preset header error!");
  1288. result = 0;
  1289. }
  1290. else
  1291. {
  1292. int num = binaryReader.ReadInt32();
  1293. result = num;
  1294. }
  1295. }
  1296. }
  1297. }
  1298. return result;
  1299. }
  1300. public static void ImportSavedAttachDataGP03(string fileName, TBodySkin tbskin)
  1301. {
  1302. using (AFileBase afileBase = GameUty.FileOpen(fileName, null))
  1303. {
  1304. if (afileBase == null || !afileBase.IsValid())
  1305. {
  1306. NDebug.MessageBox("Import Error", "SAVED_ATTACH_DATA import gp03 error! -> " + fileName);
  1307. }
  1308. else
  1309. {
  1310. byte[] buffer = afileBase.ReadAll();
  1311. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
  1312. {
  1313. string a = binaryReader.ReadString();
  1314. if (a != "SAVED_ATTACH_DATA")
  1315. {
  1316. NDebug.MessageBox("Import Error", "import gp03 saved attach data header error!");
  1317. }
  1318. int num = binaryReader.ReadInt32();
  1319. int num2 = binaryReader.ReadInt32();
  1320. for (int i = 0; i < num2; i++)
  1321. {
  1322. SavedAttachData savedAttachData = new SavedAttachData();
  1323. savedAttachData.Deserialize(binaryReader);
  1324. if (tbskin.m_savedAttachPos == null)
  1325. {
  1326. tbskin.m_savedAttachPos = new List<SavedAttachData>();
  1327. }
  1328. tbskin.m_savedAttachPos.Add(savedAttachData);
  1329. }
  1330. }
  1331. }
  1332. }
  1333. }
  1334. public static void AddSaveDataReferenceToMaidGP03(string addSaveDataGuid, string saveMaidGuid)
  1335. {
  1336. HashSet<string> hashSet = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid);
  1337. hashSet.Add(addSaveDataGuid);
  1338. ImportCM.WriteSaveDataReferenceMaidGP03(saveMaidGuid, hashSet);
  1339. }
  1340. public static void RemoveSaveDataReferenceToMaidGP03(string addSaveDataGuid, string saveMaidGuid)
  1341. {
  1342. HashSet<string> hashSet = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid);
  1343. hashSet.Remove(addSaveDataGuid);
  1344. if (!ImportCM.WriteSaveDataReferenceMaidGP03(saveMaidGuid, hashSet))
  1345. {
  1346. }
  1347. }
  1348. public static void DeleteSaveDataNoReferenceMaidGP03(string saveMaidGuid)
  1349. {
  1350. HashSet<string> hashSet = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid);
  1351. if (hashSet.Count == 0)
  1352. {
  1353. ImportCM.DeleteSaveDataMaidGP03(saveMaidGuid);
  1354. }
  1355. }
  1356. private static void DeleteSaveDataMaidGP03(string saveMaidGuid)
  1357. {
  1358. string path = UTY.gameProjectPath + "\\SaveData\\_gp03_import\\" + saveMaidGuid;
  1359. UTY.DirectorySafeDelete(path, new string[]
  1360. {
  1361. "brd",
  1362. "model",
  1363. "menu",
  1364. "tex",
  1365. "mat",
  1366. "sad",
  1367. "dbcol",
  1368. "dbconf",
  1369. "sref"
  1370. }, SearchOption.TopDirectoryOnly);
  1371. }
  1372. private static HashSet<string> ReadSaveDataReferenceMaidGP03(string saveMaidGuid)
  1373. {
  1374. HashSet<string> hashSet = new HashSet<string>();
  1375. string text = UTY.gameProjectPath + "\\SaveData\\_gp03_import\\" + saveMaidGuid;
  1376. if (!Directory.Exists(text))
  1377. {
  1378. return hashSet;
  1379. }
  1380. string path = text + "\\gp03_" + saveMaidGuid + ".sref";
  1381. if (File.Exists(path))
  1382. {
  1383. byte[] buffer = File.ReadAllBytes(path);
  1384. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
  1385. {
  1386. string a = binaryReader.ReadString();
  1387. if (a == "GP03_MAID_REF_DATA")
  1388. {
  1389. int num = binaryReader.ReadInt32();
  1390. int num2 = binaryReader.ReadInt32();
  1391. for (int i = 0; i < num2; i++)
  1392. {
  1393. hashSet.Add(binaryReader.ReadString());
  1394. }
  1395. }
  1396. else
  1397. {
  1398. NDebug.Assert("reference add error.", true);
  1399. }
  1400. }
  1401. }
  1402. return hashSet;
  1403. }
  1404. private static bool WriteSaveDataReferenceMaidGP03(string saveMaidGuid, HashSet<string> savedGuids)
  1405. {
  1406. string text = UTY.gameProjectPath + "\\SaveData\\_gp03_import\\" + saveMaidGuid;
  1407. if (!Directory.Exists(text))
  1408. {
  1409. return false;
  1410. }
  1411. string path = text + "\\gp03_" + saveMaidGuid + ".sref";
  1412. using (MemoryStream memoryStream = new MemoryStream())
  1413. {
  1414. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  1415. binaryWriter.Write("GP03_MAID_REF_DATA");
  1416. binaryWriter.Write(2000);
  1417. binaryWriter.Write(savedGuids.Count);
  1418. foreach (string value in savedGuids)
  1419. {
  1420. binaryWriter.Write(value);
  1421. }
  1422. File.WriteAllBytes(path, memoryStream.ToArray());
  1423. }
  1424. return savedGuids.Count != 0;
  1425. }
  1426. public static void CleanupFileMaidGP03()
  1427. {
  1428. try
  1429. {
  1430. string[] array = GameMain.Instance.EnumSavePathFileName();
  1431. if (array != null)
  1432. {
  1433. List<string> list = new List<string>();
  1434. foreach (string pathFileName in array)
  1435. {
  1436. GameMain.SerializeHeader saveDataHeader = GameMain.Instance.GetSaveDataHeader(pathFileName);
  1437. if (saveDataHeader != null)
  1438. {
  1439. if (!string.IsNullOrEmpty(saveDataHeader.saveDataGUID))
  1440. {
  1441. list.Add(saveDataHeader.saveDataGUID);
  1442. }
  1443. }
  1444. }
  1445. DirectoryInfo directoryInfo = new DirectoryInfo(UTY.gameProjectPath + "\\SaveData\\_gp03_import");
  1446. if (directoryInfo != null)
  1447. {
  1448. DirectoryInfo[] directories = directoryInfo.GetDirectories();
  1449. DirectoryInfo[] array3 = directories;
  1450. for (int j = 0; j < array3.Length; j++)
  1451. {
  1452. DirectoryInfo directoryInfo2 = array3[j];
  1453. int num = directoryInfo2.FullName.LastIndexOf('\\');
  1454. string saveMaidGuid = directoryInfo2.FullName.Remove(0, num + 1);
  1455. if (ImportCM.CheckBrdVerGP03(saveMaidGuid) >= 2001)
  1456. {
  1457. HashSet<string> guidsInMaid = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid);
  1458. if (guidsInMaid.Count == 0)
  1459. {
  1460. ImportCM.DeleteSaveDataMaidGP03(saveMaidGuid);
  1461. GameUty.ReloadCrcImportPath();
  1462. }
  1463. else if (list.Find((string a) => guidsInMaid.Contains(a)) == null)
  1464. {
  1465. ImportCM.DeleteSaveDataMaidGP03(saveMaidGuid);
  1466. GameUty.ReloadCrcImportPath();
  1467. }
  1468. else
  1469. {
  1470. int count = guidsInMaid.Count;
  1471. List<string> list2 = new List<string>();
  1472. using (HashSet<string>.Enumerator enumerator = guidsInMaid.GetEnumerator())
  1473. {
  1474. while (enumerator.MoveNext())
  1475. {
  1476. string sg = enumerator.Current;
  1477. if (list.Find((string a) => string.Compare(a, sg, true) == 0) == null)
  1478. {
  1479. list2.Add(sg);
  1480. }
  1481. }
  1482. }
  1483. foreach (string item in list2)
  1484. {
  1485. guidsInMaid.Remove(item);
  1486. }
  1487. if (count != guidsInMaid.Count)
  1488. {
  1489. ImportCM.WriteSaveDataReferenceMaidGP03(saveMaidGuid, guidsInMaid);
  1490. }
  1491. }
  1492. }
  1493. }
  1494. }
  1495. }
  1496. }
  1497. catch (Exception ex)
  1498. {
  1499. Debug.LogError("error gp03 maid cleanup.");
  1500. }
  1501. }
  1502. private static byte[] m_skinTempFile = null;
  1503. private static byte[] m_matTempFile = null;
  1504. private static Dictionary<int, KeyValuePair<string, float>> m_hashPriorityMaterials = null;
  1505. private static Dictionary<string, Material> m_dicCacheMaterial = new Dictionary<string, Material>();
  1506. private static byte[] m_texTempFile = null;
  1507. private static byte[] m_texTempImg = null;
  1508. public static byte[] m_aniTempFile = null;
  1509. public static byte[] m_byPhyTempFile = null;
  1510. private class BoneUse
  1511. {
  1512. public BoneUse(string f_name, int f_idx, Transform f_bone)
  1513. {
  1514. this.name = f_name;
  1515. this.idx = f_idx;
  1516. this.bone = f_bone;
  1517. }
  1518. public bool use;
  1519. public string name;
  1520. public int idx;
  1521. public Transform bone;
  1522. public bool delete;
  1523. }
  1524. public class OldSkirtBoneRev
  1525. {
  1526. public bool bRecursiv = true;
  1527. public Vector3 vRotRevInit;
  1528. public Vector3 vRotRevAfter;
  1529. }
  1530. }