12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574 |
- 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<string, ImportCM.BoneUse> 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<string, ImportCM.BoneUse> dictionary = new Dictionary<string, ImportCM.BoneUse>();
- int num2 = binaryReader.ReadInt32();
- List<GameObject> list = new List<GameObject>();
- 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>();
- 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<int, KeyValuePair<string, float>>();
- 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<string, float>(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<Material>(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<string, float> 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<GameObject> list = new List<GameObject>();
- 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<string, ImportCM.OldSkirtBoneRev> LoadOldSkirtBoneRev(string f_strModelName)
- {
- Dictionary<string, ImportCM.OldSkirtBoneRev> dictionary = null;
- if (f_strModelName.Contains("dress020_onep"))
- {
- dictionary = new Dictionary<string, ImportCM.OldSkirtBoneRev>();
- 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<string, ImportCM.OldSkirtBoneRev>();
- 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<DynamicBone>();
- 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>();
- 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<SavedAttachData>();
- }
- tbskin.m_savedAttachPos.Add(savedAttachData);
- }
- }
- }
- }
- }
- public static void AddSaveDataReferenceToMaidGP03(string addSaveDataGuid, string saveMaidGuid)
- {
- HashSet<string> hashSet = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid);
- hashSet.Add(addSaveDataGuid);
- ImportCM.WriteSaveDataReferenceMaidGP03(saveMaidGuid, hashSet);
- }
- public static void RemoveSaveDataReferenceToMaidGP03(string addSaveDataGuid, string saveMaidGuid)
- {
- HashSet<string> hashSet = ImportCM.ReadSaveDataReferenceMaidGP03(saveMaidGuid);
- hashSet.Remove(addSaveDataGuid);
- if (!ImportCM.WriteSaveDataReferenceMaidGP03(saveMaidGuid, hashSet))
- {
- }
- }
- public static void DeleteSaveDataNoReferenceMaidGP03(string saveMaidGuid)
- {
- HashSet<string> 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<string> ReadSaveDataReferenceMaidGP03(string saveMaidGuid)
- {
- HashSet<string> hashSet = new HashSet<string>();
- 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<string> 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<string> list = new List<string>();
- 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<string> 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<string> list2 = new List<string>();
- using (HashSet<string>.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<int, KeyValuePair<string, float>> m_hashPriorityMaterials = null;
- private static Dictionary<string, Material> m_dicCacheMaterial = new Dictionary<string, Material>();
- 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;
- }
- }
|