using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; using TriLib; using UnityEngine; using UnityEngine.Rendering; public class ImportCM : MonoBehaviour { private static ImportCM.BoneUse RemoveNoWeightBone(Dictionary dic, Transform parent) { bool flag = false; if (parent.name == "Skirt") { return null; } ImportCM.BoneUse[] array = new ImportCM.BoneUse[parent.childCount]; for (int i = 0; i < parent.childCount; i++) { ImportCM.BoneUse boneUse = array[i] = ImportCM.RemoveNoWeightBone(dic, parent.GetChild(i)); flag |= (boneUse == null || boneUse.use); } foreach (ImportCM.BoneUse boneUse2 in array) { if (boneUse2 != null && boneUse2.bone != null && boneUse2.delete) { UnityEngine.Object.DestroyImmediate(boneUse2.bone.gameObject); boneUse2.bone = null; } } if (flag) { return null; } ImportCM.BoneUse boneUse2; if (dic.TryGetValue(parent.name, out boneUse2)) { boneUse2.delete = (!boneUse2.use && !flag); return boneUse2; } return null; } public static GameObject LoadSkinMesh_R(string filename, TMorph morph, string slotname, TBodySkin bodyskin, int layer) { try { using (AFileBase afileBase = GameUty.FileOpen(filename, null)) { if (ImportCM.m_skinTempFile == null) { ImportCM.m_skinTempFile = new byte[Math.Max(500000, afileBase.GetSize())]; } else if (ImportCM.m_skinTempFile.Length < afileBase.GetSize()) { ImportCM.m_skinTempFile = new byte[afileBase.GetSize()]; } afileBase.Read(ref ImportCM.m_skinTempFile, afileBase.GetSize()); } } catch (Exception ex) { NDebug.Assert("ファイルが開けませんでした。" + filename + "\n" + ex.Message, false); } bool flag = filename.Contains("crc_") || filename.Contains("crx_") || filename.Contains("gp03_"); BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_skinTempFile), Encoding.UTF8); TBodySkin.OriVert oriVert = bodyskin.m_OriVert; GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject; gameObject.layer = layer; GameObject gameObject2 = null; Hashtable hashtable = new Hashtable(); string text = binaryReader.ReadString(); if (text != "CM3D2_MESH") { NDebug.Assert("LoadSkinMesh_R 例外 : ヘッダーファイルが不正です。" + text, false); } int num = binaryReader.ReadInt32(); string str = binaryReader.ReadString(); gameObject.name = "_SM_" + str; string b = binaryReader.ReadString(); Dictionary dictionary = new Dictionary(); int num2 = binaryReader.ReadInt32(); List list = new List(); for (int i = 0; i < num2; i++) { GameObject gameObject3 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject; gameObject3.layer = layer; gameObject3.name = binaryReader.ReadString(); list.Add(gameObject3); if (gameObject3.name == b) { gameObject2 = gameObject3; } hashtable[gameObject3.name] = gameObject3; dictionary[gameObject3.name] = new ImportCM.BoneUse(gameObject3.name, -1, gameObject3.transform); bool flag2 = binaryReader.ReadByte() != 0; if (flag2) { GameObject gameObject4 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject; gameObject4.name = gameObject3.name + "_SCL_"; gameObject4.transform.parent = gameObject3.transform; hashtable[gameObject3.name + "&_SCL_"] = gameObject4; dictionary[gameObject4.name] = new ImportCM.BoneUse(gameObject4.name, -1, gameObject4.transform); } } for (int j = 0; j < num2; j++) { int num3 = binaryReader.ReadInt32(); if (num3 >= 0) { list[j].transform.parent = list[num3].transform; } else { list[j].transform.parent = gameObject.transform; } } for (int k = 0; k < num2; k++) { Transform transform = list[k].transform; float x = binaryReader.ReadSingle(); float y = binaryReader.ReadSingle(); float z = binaryReader.ReadSingle(); transform.localPosition = new Vector3(x, y, z); float x2 = binaryReader.ReadSingle(); float y2 = binaryReader.ReadSingle(); float z2 = binaryReader.ReadSingle(); float w = binaryReader.ReadSingle(); transform.localRotation = new Quaternion(x2, y2, z2, w); if (2001 <= num) { bool flag3 = binaryReader.ReadBoolean(); if (flag3) { float x3 = binaryReader.ReadSingle(); float y3 = binaryReader.ReadSingle(); float z3 = binaryReader.ReadSingle(); transform.localScale = new Vector3(x3, y3, z3); } } } int num4 = binaryReader.ReadInt32(); int num5 = binaryReader.ReadInt32(); int num6 = binaryReader.ReadInt32(); oriVert.VCount = num4; oriVert.nSubMeshCount = num5; SkinnedMeshRenderer skinnedMeshRenderer = gameObject2.AddComponent(); skinnedMeshRenderer.updateWhenOffscreen = true; skinnedMeshRenderer.skinnedMotionVectors = false; skinnedMeshRenderer.lightProbeUsage = LightProbeUsage.Off; skinnedMeshRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off; skinnedMeshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion; if (!bodyskin.body.boMAN) { if (slotname == "head") { skinnedMeshRenderer.castShadows = false; } if (bodyskin.Category == "chikubi") { skinnedMeshRenderer.castShadows = false; } if (bodyskin.Category.IndexOf("seieki_") == 0) { skinnedMeshRenderer.castShadows = false; } } bodyskin.listDEL.Add(gameObject2); ImportCM.BoneUse[] array = new ImportCM.BoneUse[num6]; Transform[] array2 = new Transform[num6]; for (int l = 0; l < num6; l++) { string text2 = binaryReader.ReadString(); if (!hashtable.ContainsKey(text2)) { Debug.LogError("nullbone= " + text2); } else { GameObject gameObject5; if (hashtable.ContainsKey(text2 + "&_SCL_")) { gameObject5 = (GameObject)hashtable[text2 + "&_SCL_"]; } else { gameObject5 = (GameObject)hashtable[text2]; } array2[l] = gameObject5.transform; ImportCM.BoneUse[] array3 = array; int num7 = l; ImportCM.BoneUse boneUse = new ImportCM.BoneUse(gameObject5.name, l, gameObject5.transform); dictionary[gameObject5.name] = boneUse; array3[num7] = boneUse; } } skinnedMeshRenderer.bones = array2; Mesh mesh = new Mesh(); skinnedMeshRenderer.sharedMesh = mesh; Mesh mesh2 = mesh; bodyskin.listDEL.Add(mesh2); Matrix4x4[] array4 = new Matrix4x4[num6]; for (int m = 0; m < num6; m++) { for (int n = 0; n < 16; n++) { array4[m][n] = binaryReader.ReadSingle(); } } mesh2.bindposes = array4; Vector3[] array5 = new Vector3[num4]; Vector3[] array6 = new Vector3[num4]; Vector2[] array7 = new Vector2[num4]; Vector2[] array8 = null; Vector2[] array9 = null; Vector2[] array10 = null; BoneWeight[] array11 = new BoneWeight[num4]; bool flag4 = false; bool flag5 = false; bool flag6 = false; bool flag7 = false; bool flag8 = false; bool flag9 = false; bool flag10 = false; if (2101 <= num) { if (flag4 = binaryReader.ReadBoolean()) { array8 = new Vector2[num4]; } if (flag5 = binaryReader.ReadBoolean()) { array9 = new Vector2[num4]; } if (flag6 = binaryReader.ReadBoolean()) { array10 = new Vector2[num4]; } flag7 = binaryReader.ReadBoolean(); flag8 = binaryReader.ReadBoolean(); flag9 = binaryReader.ReadBoolean(); flag10 = binaryReader.ReadBoolean(); } for (int num8 = 0; num8 < num4; num8++) { float num9 = binaryReader.ReadSingle(); float num10 = binaryReader.ReadSingle(); float new_z = binaryReader.ReadSingle(); array5[num8].Set(num9, num10, new_z); num9 = binaryReader.ReadSingle(); num10 = binaryReader.ReadSingle(); new_z = binaryReader.ReadSingle(); array6[num8].Set(num9, num10, new_z); num9 = binaryReader.ReadSingle(); num10 = binaryReader.ReadSingle(); array7[num8].Set(num9, num10); if (flag4) { num9 = binaryReader.ReadSingle(); num10 = binaryReader.ReadSingle(); array8[num8].Set(num9, num10); } if (flag5) { num9 = binaryReader.ReadSingle(); num10 = binaryReader.ReadSingle(); array9[num8].Set(num9, num10); } if (flag6) { num9 = binaryReader.ReadSingle(); num10 = binaryReader.ReadSingle(); array10[num8].Set(num9, num10); } if (flag7) { num9 = binaryReader.ReadSingle(); num10 = binaryReader.ReadSingle(); } if (flag8) { num9 = binaryReader.ReadSingle(); num10 = binaryReader.ReadSingle(); } if (flag9) { num9 = binaryReader.ReadSingle(); num10 = binaryReader.ReadSingle(); } if (flag10) { num9 = binaryReader.ReadSingle(); num10 = binaryReader.ReadSingle(); } } mesh2.vertices = array5; mesh2.normals = array6; mesh2.uv = array7; mesh2.uv2 = array8; mesh2.uv3 = array9; mesh2.uv4 = array10; oriVert.vOriVert = array5; oriVert.vOriNorm = array6; if (bodyskin.SlotId == TBody.SlotID.body) { oriVert.vOriUV = mesh2.uv; } int num11 = binaryReader.ReadInt32(); if (num11 > 0) { Vector4[] array12 = new Vector4[num11]; for (int num12 = 0; num12 < num11; num12++) { float x4 = binaryReader.ReadSingle(); float y4 = binaryReader.ReadSingle(); float z4 = binaryReader.ReadSingle(); float w2 = binaryReader.ReadSingle(); array12[num12] = new Vector4(x4, y4, z4, w2); } mesh2.tangents = array12; } for (int num13 = 0; num13 < num4; num13++) { int num14 = (int)binaryReader.ReadUInt16(); array11[num13].boneIndex0 = num14; int num15 = num14; num14 = (int)binaryReader.ReadUInt16(); array11[num13].boneIndex1 = num14; int num16 = num14; num14 = (int)binaryReader.ReadUInt16(); array11[num13].boneIndex2 = num14; int num17 = num14; num14 = (int)binaryReader.ReadUInt16(); array11[num13].boneIndex3 = num14; int num18 = num14; array[num15].use = true; array[num16].use = true; array[num17].use = true; array[num18].use = true; array11[num13].weight0 = binaryReader.ReadSingle(); array11[num13].weight1 = binaryReader.ReadSingle(); array11[num13].weight2 = binaryReader.ReadSingle(); array11[num13].weight3 = binaryReader.ReadSingle(); } ImportCM.BoneUse boneUse2; if (!flag && dictionary.TryGetValue("Bip01", out boneUse2)) { ImportCM.RemoveNoWeightBone(dictionary, boneUse2.bone); } mesh2.boneWeights = array11; mesh2.subMeshCount = num5; oriVert.bwWeight = array11; oriVert.nSubMeshCount = num5; oriVert.nSubMeshOriTri = new int[num5][]; for (int num19 = 0; num19 < num5; num19++) { int num20 = binaryReader.ReadInt32(); int[] array13 = new int[num20]; for (int num21 = 0; num21 < num20; num21++) { array13[num21] = (int)binaryReader.ReadUInt16(); } oriVert.nSubMeshOriTri[num19] = array13; mesh2.SetTriangles(array13, num19); } int num22 = binaryReader.ReadInt32(); Material[] array14 = new Material[num22]; for (int num23 = 0; num23 < num22; num23++) { Material material = ImportCM.ReadMaterial(binaryReader, bodyskin, null, num); array14[num23] = material; } skinnedMeshRenderer.materials = array14; for (;;) { string a = binaryReader.ReadString(); if (a == "end") { break; } if (a == "morph") { morph.LoadMoprhData2(binaryReader, num); } } if (2100 <= num) { int num24 = binaryReader.ReadInt32(); if (num24 != 0) { oriVert.skinThick = new SkinThickness(); oriVert.skinThick.Deserialize(binaryReader); } } binaryReader.Close(); return gameObject; } public static Material LoadMaterial(string f_strFileName, TBodySkin bodyskin, Material existmat = null) { try { using (AFileBase afileBase = GameUty.FileOpen(f_strFileName, null)) { NDebug.Assert(afileBase.IsValid(), "LoadMaterial マテリアルコンテナが読めません。 :" + f_strFileName); if (ImportCM.m_matTempFile == null) { ImportCM.m_matTempFile = new byte[Math.Max(10000, afileBase.GetSize())]; } else if (ImportCM.m_matTempFile.Length < afileBase.GetSize()) { ImportCM.m_matTempFile = new byte[afileBase.GetSize()]; } afileBase.Read(ref ImportCM.m_matTempFile, afileBase.GetSize()); } } catch (Exception ex) { Debug.LogError(string.Concat(new string[] { "LoadMaterial マテリアルコンテナが読み込めませんでした。 : ", f_strFileName, " : ", ex.Message, " : StackTrace :\n", ex.StackTrace })); throw ex; } BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_matTempFile), Encoding.UTF8); string text = binaryReader.ReadString(); if (text != "CM3D2_MATERIAL") { NDebug.Assert("ProcScriptBin 例外 : ヘッダーファイルが不正です。" + text, false); } int parentVer = binaryReader.ReadInt32(); string text2 = binaryReader.ReadString(); Material result = ImportCM.ReadMaterial(binaryReader, bodyskin, existmat, parentVer); binaryReader.Close(); return result; } public static Material ReadMaterial(BinaryReader r, TBodySkin bodyskin = null, Material existmat = null, int parentVer = 0) { if (ImportCM.m_hashPriorityMaterials == null) { ImportCM.m_hashPriorityMaterials = new Dictionary>(); string[] list = GameUty.FileSystem.GetList("prioritymaterial", AFileSystemBase.ListType.AllFile); if (list != null && 0 < list.Length) { for (int i = 0; i < list.Length; i++) { if (Path.GetExtension(list[i]) == ".pmat") { string text = list[i]; using (AFileBase afileBase = GameUty.FileOpen(text, null)) { NDebug.Assert(afileBase.IsValid(), text + "を開けませんでした"); byte[] buffer = afileBase.ReadAll(); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer), Encoding.UTF8)) { string a = binaryReader.ReadString(); if (a != "CM3D2_PMATERIAL") { NDebug.Assert("ヘッダーエラー\n" + text, false); } int num = binaryReader.ReadInt32(); int key = binaryReader.ReadInt32(); string key2 = binaryReader.ReadString(); float value = binaryReader.ReadSingle(); NDebug.Assert(!ImportCM.m_hashPriorityMaterials.ContainsKey(key), "すでにハッシュが登録されています"); ImportCM.m_hashPriorityMaterials.Add(key, new KeyValuePair(key2, value)); } } } } } } string text2 = r.ReadString(); string text3 = r.ReadString(); string text4 = r.ReadString(); Material material; if (text2.IndexOf("gp03_") == 0) { text3 = text3.Replace("CM3D2", "GP03").Replace("/", "_"); Shader shader = Resources.Load("Shaders/GP03/" + text3) as Shader; NDebug.Assert(shader != null, "GP03 Shader not found. -> " + text3); if (existmat == null) { material = new Material(shader); } else { material = existmat; material.shader = shader; } material.name = text2; if (r.ReadBoolean()) { float num2 = r.ReadSingle(); material.SetFloat("_SetManualRenderQueue", num2); material.renderQueue = (int)num2; } } else { if (existmat == null) { Material material2; if (!ImportCM.m_dicCacheMaterial.TryGetValue(text4, out material2)) { string text5 = "DefMaterial/" + text4; material2 = (Resources.Load(text5, typeof(Material)) as Material); if (material2 == null) { NDebug.Assert("DefMaterialが見つかりません。" + text5, false); } ImportCM.m_dicCacheMaterial[text4] = material2; } material = UnityEngine.Object.Instantiate(material2); if (bodyskin != null) { bodyskin.listDEL.Add(material); } } else { material = existmat; if (material.shader.name != text3) { NDebug.Warning("マテリアル入れ替えエラー。違うシェーダーに入れようとしました。 " + text3 + " -> " + material.shader.name); } } material.name = text2; int hashCode = material.name.GetHashCode(); if (ImportCM.m_hashPriorityMaterials != null && ImportCM.m_hashPriorityMaterials.ContainsKey(hashCode)) { KeyValuePair keyValuePair = ImportCM.m_hashPriorityMaterials[hashCode]; if (keyValuePair.Key == material.name) { material.SetFloat("_SetManualRenderQueue", keyValuePair.Value); material.renderQueue = (int)keyValuePair.Value; } } } for (;;) { string text6 = r.ReadString(); if (text6 == "end") { break; } string name = r.ReadString(); if (text6 == "tex") { string a2 = r.ReadString(); if (a2 == "null") { material.SetTexture(name, null); } else if (a2 == "tex2d") { string text7 = r.ReadString(); string text8 = r.ReadString(); Texture2D texture2D = ImportCM.CreateTexture(text7 + ".tex"); texture2D.name = text7; texture2D.wrapMode = TextureWrapMode.Clamp; material.SetTexture(name, texture2D); if (bodyskin != null) { bodyskin.listDEL.Add(texture2D); } Vector2 value2; value2.x = r.ReadSingle(); value2.y = r.ReadSingle(); material.SetTextureOffset(name, value2); Vector2 value3; value3.x = r.ReadSingle(); value3.y = r.ReadSingle(); material.SetTextureScale(name, value3); } else if (a2 == "texRT") { string text9 = r.ReadString(); string text10 = r.ReadString(); } } else if (text6 == "col") { Color value4; value4.r = r.ReadSingle(); value4.g = r.ReadSingle(); value4.b = r.ReadSingle(); value4.a = r.ReadSingle(); material.SetColor(name, value4); } else if (text6 == "vec") { Vector4 value5; value5.x = r.ReadSingle(); value5.y = r.ReadSingle(); value5.z = r.ReadSingle(); value5.w = r.ReadSingle(); material.SetVector(name, value5); } else if (text6 == "f") { float value6 = r.ReadSingle(); material.SetFloat(name, value6); } else if (text6 == "range") { float value7 = r.ReadSingle(); material.SetFloat(name, value7); } else if (text6 == "tex_offset") { Vector2 value8; value8.x = r.ReadSingle(); value8.y = r.ReadSingle(); material.SetTextureOffset(name, value8); } else if (text6 == "tex_scale") { Vector2 value9; value9.x = r.ReadSingle(); value9.y = r.ReadSingle(); material.SetTextureScale(name, value9); } else if (text6 == "keyword") { int num3 = r.ReadInt32(); for (int j = 0; j < num3; j++) { string keyword = r.ReadString(); bool flag = r.ReadBoolean(); if (flag) { material.EnableKeyword(keyword); } else { material.DisableKeyword(keyword); } } } else { Debug.LogError("マテリアルが読み込めません。不正なマテリアルプロパティ型です " + text6); } } return material; } public static GameObject LoadOnlyBone_R(byte[] bs) { GameObject gameObject = new GameObject(); gameObject.layer = 10; BinaryReader binaryReader = new BinaryReader(new MemoryStream(bs)); Hashtable hashtable = new Hashtable(); string text = binaryReader.ReadString(); if (text != "CM3D2_MESH") { NDebug.Assert("LoadOnlyBone_R 例外 : ヘッダーファイルが不正です。" + text, false); } int num = binaryReader.ReadInt32(); string str = binaryReader.ReadString(); gameObject.name = "_BO_" + str; string text2 = binaryReader.ReadString(); int num2 = binaryReader.ReadInt32(); List list = new List(); for (int i = 0; i < num2; i++) { GameObject gameObject2 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject; gameObject2.layer = 10; gameObject2.name = binaryReader.ReadString(); list.Add(gameObject2); hashtable[gameObject2.name] = gameObject2; bool flag = binaryReader.ReadByte() != 0; if (flag) { GameObject gameObject3 = UnityEngine.Object.Instantiate(Resources.Load("seed")) as GameObject; gameObject2.layer = 10; gameObject3.name = gameObject2.name + "_SCL_"; gameObject3.transform.parent = gameObject2.transform; hashtable[gameObject2.name + "&_SCL_"] = gameObject3; } } for (int j = 0; j < num2; j++) { int num3 = binaryReader.ReadInt32(); if (num3 >= 0) { list[j].transform.parent = list[num3].transform; } else { list[j].transform.parent = gameObject.transform; } } for (int k = 0; k < num2; k++) { Transform transform = list[k].transform; float x = binaryReader.ReadSingle(); float y = binaryReader.ReadSingle(); float z = binaryReader.ReadSingle(); transform.localPosition = new Vector3(x, y, z); float x2 = binaryReader.ReadSingle(); float y2 = binaryReader.ReadSingle(); float z2 = binaryReader.ReadSingle(); float w = binaryReader.ReadSingle(); transform.localRotation = new Quaternion(x2, y2, z2, w); if (2001 <= num) { bool flag2 = binaryReader.ReadBoolean(); if (flag2) { float x3 = binaryReader.ReadSingle(); float y3 = binaryReader.ReadSingle(); float z3 = binaryReader.ReadSingle(); transform.localScale = new Vector3(x3, y3, z3); } } } binaryReader.Close(); gameObject.AddComponent(typeof(Animation)); return gameObject; } public static Dictionary LoadOldSkirtBoneRev(string f_strModelName) { Dictionary dictionary = null; if (f_strModelName.Contains("dress020_onep")) { dictionary = new Dictionary(); for (int i = 1; i <= 12; i++) { dictionary.Add("Skirt" + i.ToString("00") + "_A_yure_skirt_h_", new ImportCM.OldSkirtBoneRev { bRecursiv = true, vRotRevInit = new Vector3((i != 7 && i != 8) ? 90f : -90f, 0f, 0f), vRotRevAfter = new Vector3((i != 7 && i != 8) ? -90f : 90f, 0f, 0f) }); } } else if (f_strModelName.Contains("dress131_onep")) { dictionary = new Dictionary(); for (int j = 1; j <= 12; j++) { dictionary.Add("Skirt" + j.ToString("00") + "_A_yure_skirt_", new ImportCM.OldSkirtBoneRev { bRecursiv = true, vRotRevInit = new Vector3(0f, 0f, 0f), vRotRevAfter = new Vector3(180f, 0f, 0f) }); } } return dictionary; } public static Texture2D CreateTexture(string f_strFileName) { return ImportCM.LoadTexture(GameUty.FileSystem, f_strFileName, true).CreateTexture2D(); } public static Texture2D CreateTexture(AFileSystemBase f_fileSystem, string f_strFileName) { return ImportCM.LoadTexture(f_fileSystem, f_strFileName, true).CreateTexture2D(); } public static TextureResource LoadTexture(AFileSystemBase f_fileSystem, string f_strFileName, bool usePoolBuffer) { try { using (AFileBase afileBase = GameUty.FileOpen(f_strFileName, f_fileSystem)) { if (!afileBase.IsValid()) { NDebug.Assert("LoadTexture テクスチャコンテナが読めません。 :" + f_strFileName, false); } if (ImportCM.m_texTempFile == null) { ImportCM.m_texTempFile = new byte[Math.Max(500000, afileBase.GetSize())]; } else if (ImportCM.m_texTempFile.Length < afileBase.GetSize()) { ImportCM.m_texTempFile = new byte[afileBase.GetSize()]; } afileBase.Read(ref ImportCM.m_texTempFile, afileBase.GetSize()); } } catch (Exception ex) { Debug.LogError(string.Concat(new string[] { "LoadTexture テクスチャコンテナが読み込めませんでした。 : ", f_strFileName, " : ", ex.Message, " : StackTrace :\n", ex.StackTrace })); throw ex; } BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_texTempFile), Encoding.UTF8); string text = binaryReader.ReadString(); if (text != "CM3D2_TEX") { NDebug.Assert("ProcScriptBin 例外 : ヘッダーファイルが不正です。" + text, false); } int num = binaryReader.ReadInt32(); string text2 = binaryReader.ReadString(); int width = 0; int height = 0; TextureFormat textureFormat = TextureFormat.ARGB32; Rect[] array = null; if (1010 <= num) { if (1011 <= num) { int num2 = binaryReader.ReadInt32(); if (0 < num2) { array = new Rect[num2]; for (int i = 0; i < num2; i++) { float x = binaryReader.ReadSingle(); float y = binaryReader.ReadSingle(); float width2 = binaryReader.ReadSingle(); float height2 = binaryReader.ReadSingle(); array[i] = new Rect(x, y, width2, height2); } } } width = binaryReader.ReadInt32(); height = binaryReader.ReadInt32(); textureFormat = (TextureFormat)binaryReader.ReadInt32(); } int num3 = binaryReader.ReadInt32(); byte[] array2; if (usePoolBuffer && textureFormat == TextureFormat.ARGB32) { if (ImportCM.m_texTempImg == null) { ImportCM.m_texTempImg = new byte[Math.Max(500000, num3)]; } else if (ImportCM.m_texTempImg.Length < num3) { ImportCM.m_texTempImg = new byte[num3]; } binaryReader.Read(ImportCM.m_texTempImg, 0, num3); array2 = ImportCM.m_texTempImg; } else { array2 = new byte[num3]; binaryReader.Read(array2, 0, num3); } if (num == 1000) { width = ((int)array2[16] << 24 | (int)array2[17] << 16 | (int)array2[18] << 8 | (int)array2[19]); height = ((int)array2[20] << 24 | (int)array2[21] << 16 | (int)array2[22] << 8 | (int)array2[23]); } binaryReader.Close(); return new TextureResource(width, height, textureFormat, array, array2); } public static AnimationClip LoadAniClip(string f_strFileName, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false) { try { using (AFileBase afileBase = GameUty.FileOpen(f_strFileName, null)) { NDebug.Assert(afileBase.IsValid(), "LoadAniClip アニメーションファイルが開けません。 :" + f_strFileName); if (ImportCM.m_aniTempFile == null) { ImportCM.m_aniTempFile = new byte[Math.Max(500000, afileBase.GetSize())]; } else if (ImportCM.m_aniTempFile.Length < afileBase.GetSize()) { ImportCM.m_aniTempFile = new byte[afileBase.GetSize()]; } afileBase.Read(ref ImportCM.m_aniTempFile, afileBase.GetSize()); } } catch (Exception ex) { Debug.LogError(string.Concat(new string[] { "LoadAniClip アニメーションファイルが読み込めませんでした。 : ", f_strFileName, " : ", ex.Message, " : StackTrace :\n", ex.StackTrace })); throw ex; } BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_aniTempFile), Encoding.UTF8); string text = binaryReader.ReadString(); if (text != "CM3D2_ANIM") { NDebug.Assert("LoadAniClip 例外 : ヘッダーファイルが不正です。" + text, false); } int num = binaryReader.ReadInt32(); AnimationClip animationClip = new AnimationClip(); if (animationClip != null) { animationClip.legacy = true; } string text2 = string.Empty; int num2 = 0; for (;;) { byte b = binaryReader.ReadByte(); if (b == 0) { break; } if (b == 1) { text2 = binaryReader.ReadString(); num2++; } else if (b >= 100) { int num3 = binaryReader.ReadInt32(); Keyframe[] array = new Keyframe[num3]; AnimationCurve animationCurve = new AnimationCurve(); for (int i = 0; i < num3; i++) { array[i].time = binaryReader.ReadSingle(); array[i].value = binaryReader.ReadSingle(); array[i].inTangent = binaryReader.ReadSingle(); array[i].outTangent = binaryReader.ReadSingle(); } animationCurve.keys = array; bool flag = true; string text3 = text2 + "*"; if (!no_chara) { 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")) { flag = false; } if (!load_l_mune_anime && text3.Contains("Mune_L")) { flag = false; } if (!load_r_mune_anime && text3.Contains("Mune_R")) { flag = false; } } if (flag) { animationClip.SetCurve(text2, AnmParse.proptypes[(int)(b - 100)], AnmParse.properties[(int)(b - 100)], animationCurve); } } else { Debug.LogError("com " + b); } } binaryReader.Close(); return animationClip; } public static AnimationClip LoadAniClip(byte[] file_byte, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false) { if (ImportCM.m_aniTempFile == null) { ImportCM.m_aniTempFile = new byte[Math.Max(500000, file_byte.Length)]; } else if (ImportCM.m_aniTempFile.Length < file_byte.Length) { ImportCM.m_aniTempFile = new byte[file_byte.Length]; } Buffer.BlockCopy(file_byte, 0, ImportCM.m_aniTempFile, 0, file_byte.Length); BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_aniTempFile), Encoding.UTF8); string text = binaryReader.ReadString(); if (text != "CM3D2_ANIM") { NDebug.Assert("LoadAniClip 例外 : ヘッダーファイルが不正です。" + text, false); } int num = binaryReader.ReadInt32(); AnimationClip animationClip = new AnimationClip(); if (animationClip != null) { animationClip.legacy = true; } string text2 = string.Empty; int num2 = 0; for (;;) { byte b = binaryReader.ReadByte(); if (b == 0) { break; } if (b == 1) { text2 = binaryReader.ReadString(); num2++; } else if (b >= 100) { int num3 = binaryReader.ReadInt32(); Keyframe[] array = new Keyframe[num3]; AnimationCurve animationCurve = new AnimationCurve(); for (int i = 0; i < num3; i++) { array[i].time = binaryReader.ReadSingle(); array[i].value = binaryReader.ReadSingle(); array[i].inTangent = binaryReader.ReadSingle(); array[i].outTangent = binaryReader.ReadSingle(); } animationCurve.keys = array; bool flag = true; string text3 = text2 + "*"; if (!no_chara) { 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")) { flag = false; } if (!load_l_mune_anime && text3.Contains("Mune_L")) { flag = false; } if (!load_r_mune_anime && text3.Contains("Mune_R")) { flag = false; } if (flag) { animationClip.SetCurve(text2, AnmParse.proptypes[(int)(b - 100)], AnmParse.properties[(int)(b - 100)], animationCurve); } } } else { Debug.LogError("com " + b); } } binaryReader.Close(); return animationClip; } public static AnimationClip LoadAniClipNative(AFileSystemBase fileSystem, string fileName, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false) { AnimationClip result = null; using (AFileBase afileBase = GameUty.FileOpen(fileName, fileSystem)) { if (afileBase == null || !afileBase.IsValid()) { Debug.LogError(fileName + " はありませんでした。"); return null; } result = GameMain.Instance.AnmParse.LoadAnmClip(afileBase, load_l_mune_anime, load_r_mune_anime, no_chara); } return result; } public static AnimationClip LoadAniClipNative(byte[] file_byte, bool load_l_mune_anime, bool load_r_mune_anime, bool no_chara = false) { return GameMain.Instance.AnmParse.LoadAnmClip(file_byte, load_l_mune_anime, load_r_mune_anime, no_chara); } public static DynamicBone TryLoadDynamicBone(GameObject f_goRoot, Transform f_trHairRoot, string f_strFileName, TBody body, float[] f_aryDefStiffness) { try { using (AFileBase afileBase = GameUty.FileOpen(f_strFileName + ".phy", null)) { if (afileBase == null || !afileBase.IsValid()) { return null; } if (ImportCM.m_byPhyTempFile == null) { ImportCM.m_byPhyTempFile = new byte[Math.Max(50000, afileBase.GetSize())]; } else if (ImportCM.m_byPhyTempFile.Length < afileBase.GetSize()) { ImportCM.m_byPhyTempFile = new byte[afileBase.GetSize()]; } afileBase.Read(ref ImportCM.m_byPhyTempFile, afileBase.GetSize()); } } catch (Exception ex) { Debug.LogError(string.Concat(new string[] { "TryLoadDynamicBone 物理定義ファイルが読み込めませんでした。 : ", f_strFileName, ".phy : ", ex.Message, " : StackTrace :\n", ex.StackTrace })); throw ex; } BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_byPhyTempFile), Encoding.UTF8); DynamicBone dynamicBone = f_goRoot.AddComponent(); if (f_aryDefStiffness != null && f_aryDefStiffness.Length == 3) { dynamicBone.m_ValueFromBone[2, 0] = f_aryDefStiffness[0]; dynamicBone.m_ValueFromBone[2, 1] = f_aryDefStiffness[1]; dynamicBone.m_ValueFromBone[2, 2] = f_aryDefStiffness[2]; } dynamicBone.m_Root = f_trHairRoot; dynamicBone.SerializeRead(binaryReader); dynamicBone.m_strNowReadPhysicsFileName = f_strFileName; dynamicBone.m_hitFloorPlane = body.m_hitFloorPlane; binaryReader.Close(); return dynamicBone; } public static bool LoadDynamicCollilder(DynamicBone f_db, string f_strFileName, Transform f_trBodyBoneRoot, Maid f_maid) { try { using (AFileBase afileBase = GameUty.FileOpen(f_strFileName + ".col", null)) { if (afileBase == null || !afileBase.IsValid()) { Debug.LogError(f_strFileName + ".col が開けません。"); return false; } if (ImportCM.m_byPhyTempFile == null) { ImportCM.m_byPhyTempFile = new byte[Math.Max(50000, afileBase.GetSize())]; } else if (ImportCM.m_byPhyTempFile.Length < afileBase.GetSize()) { ImportCM.m_byPhyTempFile = new byte[afileBase.GetSize()]; } afileBase.Read(ref ImportCM.m_byPhyTempFile, afileBase.GetSize()); } } catch (Exception ex) { Debug.LogError(string.Concat(new string[] { "LoadDynamicCollilder 物理Colliderファイルが読み込めませんでした。 : ", f_strFileName, ".col : ", ex.Message, " : StackTrace :\n", ex.StackTrace })); throw ex; } BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_byPhyTempFile), Encoding.UTF8); f_db.SerializeReadCollider(binaryReader, f_trBodyBoneRoot, Path.GetFileNameWithoutExtension(f_strFileName), f_maid); binaryReader.Close(); return true; } public static DynamicSkirtBone TryLoadDynamicSkirtBone(GameObject f_goRoot, Transform f_trSkirtRoot, string f_strFileName, TBody body) { try { using (AFileBase afileBase = GameUty.FileOpen(f_strFileName + ".psk", null)) { if (afileBase == null || !afileBase.IsValid()) { return null; } if (ImportCM.m_byPhyTempFile == null) { ImportCM.m_byPhyTempFile = new byte[Math.Max(50000, afileBase.GetSize())]; } else if (ImportCM.m_byPhyTempFile.Length < afileBase.GetSize()) { ImportCM.m_byPhyTempFile = new byte[afileBase.GetSize()]; } afileBase.Read(ref ImportCM.m_byPhyTempFile, afileBase.GetSize()); } } catch (Exception ex) { Debug.LogError(string.Concat(new string[] { "TryLoadSkirtDynamicBone スカート物理定義ファイルが読み込めませんでした。 : ", f_strFileName, ".psk : ", ex.Message, " : StackTrace :\n", ex.StackTrace })); throw ex; } BinaryReader binaryReader = new BinaryReader(new MemoryStream(ImportCM.m_byPhyTempFile), Encoding.UTF8); DynamicSkirtBone dynamicSkirtBone = f_goRoot.AddComponent(); dynamicSkirtBone.SerializeRead(binaryReader); binaryReader.Close(); return dynamicSkirtBone; } public static GameObject LoadGeneralModelFile(string f_strPathFileName) { GameObject gameObject = null; GameObject result; using (AssetLoader assetLoader = new AssetLoader()) { try { AssetLoaderOptions assetLoaderOptions = AssetLoaderOptions.CreateInstance(); assetLoaderOptions.AutoPlayAnimations = true; gameObject = assetLoader.LoadFromFile(f_strPathFileName, assetLoaderOptions, null); } catch (Exception ex) { Debug.LogError(ex.ToString()); } result = gameObject; } return result; } public static CharacterMgr.Preset ImportPresetGP03(Maid maid, out byte[] preCrc, string fileName = null) { if (string.IsNullOrEmpty(fileName)) { fileName = "gp03_export_" + maid.status.saveDataGuidGP03 + ".brd"; } CharacterMgr.Preset result; using (AFileBase afileBase = GameUty.FileOpen(fileName, null)) { if (afileBase == null || !afileBase.IsValid()) { NDebug.MessageBox("Import Error", "GP03_BRIDGE import gp03 error! -> " + fileName); preCrc = null; result = null; } else { byte[] buffer = afileBase.ReadAll(); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer))) { string a = binaryReader.ReadString(); if (a != "GP03_BRIDGE") { NDebug.MessageBox("Import Error", "import gp03 preset header error!"); preCrc = null; result = null; } else { int num = binaryReader.ReadInt32(); string text = binaryReader.ReadString(); int count = binaryReader.ReadInt32(); byte[] buffer2 = binaryReader.ReadBytes(count); int count2 = binaryReader.ReadInt32(); preCrc = binaryReader.ReadBytes(count2); using (BinaryReader binaryReader2 = new BinaryReader(new MemoryStream(buffer2))) { CharacterMgr.Preset preset = GameMain.Instance.CharacterMgr.PresetLoad(binaryReader2, fileName); foreach (MaidProp maidProp in preset.listMprop) { if (string.IsNullOrEmpty(maidProp.strFileName)) { maidProp.nFileNameRID = 0; string strFileName; if (CM3.dicDelItem.TryGetValue((MPN)maidProp.idx, out strFileName)) { maidProp.strFileName = strFileName; maidProp.nFileNameRID = maidProp.strFileName.ToLower().GetHashCode(); maidProp.boDut = true; } } } result = preset; } } } } } return result; } public static int CheckBrdVerGP03(string saveMaidGuid) { string fileName = "gp03_export_" + saveMaidGuid + ".brd"; int result; using (AFileBase afileBase = GameUty.FileOpen(fileName, null)) { if (afileBase == null || !afileBase.IsValid()) { Debug.Log("GP03_BRIDGE ver check gp03 error! -> " + saveMaidGuid); result = 0; } else { byte[] buffer = afileBase.ReadAll(); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer))) { string a = binaryReader.ReadString(); if (a != "GP03_BRIDGE") { Debug.LogError("import gp03 preset header error!"); result = 0; } else { int num = binaryReader.ReadInt32(); result = num; } } } } return result; } public static void ImportSavedAttachDataGP03(string fileName, TBodySkin tbskin) { using (AFileBase afileBase = GameUty.FileOpen(fileName, null)) { if (afileBase == null || !afileBase.IsValid()) { NDebug.MessageBox("Import Error", "SAVED_ATTACH_DATA import gp03 error! -> " + fileName); } else { byte[] buffer = afileBase.ReadAll(); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer))) { string a = binaryReader.ReadString(); if (a != "SAVED_ATTACH_DATA") { NDebug.MessageBox("Import Error", "import gp03 saved attach data header error!"); } int num = binaryReader.ReadInt32(); int num2 = binaryReader.ReadInt32(); for (int i = 0; i < num2; i++) { SavedAttachData savedAttachData = new SavedAttachData(); savedAttachData.Deserialize(binaryReader); if (tbskin.m_savedAttachPos == null) { tbskin.m_savedAttachPos = new List(); } tbskin.m_savedAttachPos.Add(savedAttachData); } } } } } public static void AddSaveDataReferenceToMaidGP03(string addSaveDataGuid, string saveMaidGuid) { HashSet hashSet = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid); hashSet.Add(addSaveDataGuid); ImportCM.WriteSaveDataReferenceMaidGP03(saveMaidGuid, hashSet); } public static void RemoveSaveDataReferenceToMaidGP03(string addSaveDataGuid, string saveMaidGuid) { HashSet hashSet = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid); hashSet.Remove(addSaveDataGuid); if (!ImportCM.WriteSaveDataReferenceMaidGP03(saveMaidGuid, hashSet)) { } } public static void DeleteSaveDataNoReferenceMaidGP03(string saveMaidGuid) { HashSet hashSet = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid); if (hashSet.Count == 0) { ImportCM.DeleteSaveDataMaidGP03(saveMaidGuid); } } private static void DeleteSaveDataMaidGP03(string saveMaidGuid) { string path = UTY.gameProjectPath + "\\SaveData\\_gp03_import\\" + saveMaidGuid; UTY.DirectorySafeDelete(path, new string[] { "brd", "model", "menu", "tex", "mat", "sad", "dbcol", "dbconf", "sref" }, SearchOption.TopDirectoryOnly); } private static HashSet ReadSaveDataReferenceMaidGP03(string saveMaidGuid) { HashSet hashSet = new HashSet(); string text = UTY.gameProjectPath + "\\SaveData\\_gp03_import\\" + saveMaidGuid; if (!Directory.Exists(text)) { return hashSet; } string path = text + "\\gp03_" + saveMaidGuid + ".sref"; if (File.Exists(path)) { byte[] buffer = File.ReadAllBytes(path); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer))) { string a = binaryReader.ReadString(); if (a == "GP03_MAID_REF_DATA") { int num = binaryReader.ReadInt32(); int num2 = binaryReader.ReadInt32(); for (int i = 0; i < num2; i++) { hashSet.Add(binaryReader.ReadString()); } } else { NDebug.Assert("reference add error.", true); } } } return hashSet; } private static bool WriteSaveDataReferenceMaidGP03(string saveMaidGuid, HashSet savedGuids) { string text = UTY.gameProjectPath + "\\SaveData\\_gp03_import\\" + saveMaidGuid; if (!Directory.Exists(text)) { return false; } string path = text + "\\gp03_" + saveMaidGuid + ".sref"; using (MemoryStream memoryStream = new MemoryStream()) { BinaryWriter binaryWriter = new BinaryWriter(memoryStream); binaryWriter.Write("GP03_MAID_REF_DATA"); binaryWriter.Write(2000); binaryWriter.Write(savedGuids.Count); foreach (string value in savedGuids) { binaryWriter.Write(value); } File.WriteAllBytes(path, memoryStream.ToArray()); } return savedGuids.Count != 0; } public static void CleanupFileMaidGP03() { try { string[] array = GameMain.Instance.EnumSavePathFileName(); if (array != null) { List list = new List(); foreach (string pathFileName in array) { GameMain.SerializeHeader saveDataHeader = GameMain.Instance.GetSaveDataHeader(pathFileName); if (saveDataHeader != null) { if (!string.IsNullOrEmpty(saveDataHeader.saveDataGUID)) { list.Add(saveDataHeader.saveDataGUID); } } } DirectoryInfo directoryInfo = new DirectoryInfo(UTY.gameProjectPath + "\\SaveData\\_gp03_import"); if (directoryInfo != null) { DirectoryInfo[] directories = directoryInfo.GetDirectories(); DirectoryInfo[] array3 = directories; for (int j = 0; j < array3.Length; j++) { DirectoryInfo directoryInfo2 = array3[j]; int num = directoryInfo2.FullName.LastIndexOf('\\'); string saveMaidGuid = directoryInfo2.FullName.Remove(0, num + 1); if (ImportCM.CheckBrdVerGP03(saveMaidGuid) >= 2001) { HashSet guidsInMaid = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid); if (guidsInMaid.Count == 0) { ImportCM.DeleteSaveDataMaidGP03(saveMaidGuid); GameUty.ReloadCrcImportPath(); } else if (list.Find((string a) => guidsInMaid.Contains(a)) == null) { ImportCM.DeleteSaveDataMaidGP03(saveMaidGuid); GameUty.ReloadCrcImportPath(); } else { int count = guidsInMaid.Count; List list2 = new List(); using (HashSet.Enumerator enumerator = guidsInMaid.GetEnumerator()) { while (enumerator.MoveNext()) { string sg = enumerator.Current; if (list.Find((string a) => string.Compare(a, sg, true) == 0) == null) { list2.Add(sg); } } } foreach (string item in list2) { guidsInMaid.Remove(item); } if (count != guidsInMaid.Count) { ImportCM.WriteSaveDataReferenceMaidGP03(saveMaidGuid, guidsInMaid); } } } } } } } catch (Exception ex) { Debug.LogError("error gp03 maid cleanup."); } } private static byte[] m_skinTempFile = null; private static byte[] m_matTempFile = null; private static Dictionary> m_hashPriorityMaterials = null; private static Dictionary m_dicCacheMaterial = new Dictionary(); private static byte[] m_texTempFile = null; private static byte[] m_texTempImg = null; public static byte[] m_aniTempFile = null; public static byte[] m_byPhyTempFile = null; private class BoneUse { public BoneUse(string f_name, int f_idx, Transform f_bone) { this.name = f_name; this.idx = f_idx; this.bone = f_bone; } public bool use; public string name; public int idx; public Transform bone; public bool delete; } public class OldSkirtBoneRev { public bool bRecursiv = true; public Vector3 vRotRevInit; public Vector3 vRotRevAfter; } }