Example #1
0
    public static void ReloadParams()
    {
        if (!File.Exists(ParamPath))
        {
            Debug.Log("Data0.bdt not found. This will make treasure editor have less functionality.");
            return;
        }
        BND4 paramBnd = SFUtil.DecryptDS3Regulation(DarkSoulsTools.GetOverridenPath(ParamPath));

        DS3Param = PARAM.Read(paramBnd.Files.Find(x => Path.GetFileName(x.Name) == "ItemLotParam.param").Bytes);
        PARAM.Layout layout = PARAM.Layout.ReadXMLFile($@"{Application.dataPath.Replace('/', '\\')}\dstools\ParamLayouts\DS3\{DS3Param.ID}.xml");
        DS3Param.SetLayout(layout);

        // Build and cache the item name list
        HashSet <int> usedItemIds = new HashSet <int>();

        ItemNameList = new List <Tuple <int, string> >();
        foreach (var row in DS3Param.Rows)
        {
            ItemLotParam param = new ItemLotParam(row);
            foreach (int id in param.ItemID)
            {
                if (!usedItemIds.Contains(id))
                {
                    usedItemIds.Add(id);
                    ItemNameList.Add(new Tuple <int, string>(id, FMGUtils.LookupItemName(id)));
                }
            }
        }
        ItemNameList.Sort((a, b) => StringComparer.InvariantCulture.Compare(a.Item2, b.Item2));
    }
Example #2
0
    public static void ReloadParams()
    {
        if (!File.Exists(ParamPath))
        {
            Debug.Log("DS2 enc_regulation.bnd.dcx not found");
            return;
        }
        if (!BND4.Is(DarkSoulsTools.GetOverridenPath(ParamPath)))
        {
            Debug.Log("Decrypt your regulation by saving in Yapped");
            return;
        }
        BND4 paramBnd = BND4.Read(DarkSoulsTools.GetOverridenPath(ParamPath));

        EnemyParam = PARAM.Read(paramBnd.Files.Find(x => Path.GetFileName(x.Name) == "EnemyParam.param").Bytes);
        PARAM.Layout layout = PARAM.Layout.ReadXMLFile($@"{Application.dataPath.Replace('/', '\\')}\dstools\ParamLayouts\DS2SOTFS\{EnemyParam.ID}.xml");
        EnemyParam.SetLayout(layout);

        // Build and cache the enemy param dictionary
        ParamDictionary = new Dictionary <long, PARAM.Row>();
        foreach (var row in EnemyParam.Rows)
        {
            ParamDictionary.Add(row.ID, row);
        }
    }
Example #3
0
 protected void DrawTreasureEditor()
 {
     ShowTreasures = EditorGUILayout.Foldout(ShowTreasures, "Attached Treasures");
     if (ShowTreasures)
     {
         bool matched   = false;
         var  treasure  = GameObject.Find("/MSBEvents/Treasures");
         var  treasures = DarkSoulsTools.GetChildren(treasure);
         foreach (var t in treasures)
         {
             if (_MSBType == MSBType.MSB1)
             {
             }
             else if (_MSBType == MSBType.MSB3)
             {
                 var comp = t.GetComponent <MSB3TreasureEvent>();
                 if (comp.PartName2 == serializedObject.targetObject.name)
                 {
                     matched = true;
                     EditorGUILayout.LabelField($@"Treasure: {t.name}");
                     EditorGUI.indentLevel++;
                     EditorGUILayout.LabelField($@"Lot Param 1: {comp.ItemLot1}");
                     EditorGUILayout.LabelField($@"Lot Param 2: {comp.ItemLot2}");
                     if (GUILayout.Button("Select Treasure Event"))
                     {
                         Selection.activeGameObject = t;
                     }
                     EditorGUI.indentLevel--;
                 }
             }
             else if (_MSBType == MSBType.MSBBB)
             {
                 var comp = t.GetComponent <MSBBBTreasureEvent>();
                 if (comp != null && comp.PartName2 == serializedObject.targetObject.name)
                 {
                     matched = true;
                     EditorGUILayout.LabelField($@"Treasure: {t.name}");
                     EditorGUI.indentLevel++;
                     EditorGUILayout.LabelField($@"Lot Param 1: {comp.ItemLot1}");
                     EditorGUILayout.LabelField($@"Lot Param 2: {comp.ItemLot2}");
                     if (GUILayout.Button("Select Treasure Event"))
                     {
                         Selection.activeGameObject = t;
                     }
                     EditorGUI.indentLevel--;
                 }
             }
         }
         if (!matched)
         {
             EditorGUILayout.LabelField($@"No attached treasures");
         }
     }
 }
Example #4
0
 public override void OnInspectorGUI()
 {
     serializedObject.Update();
     if (DarkSoulsTools.GetGameType() == DarkSoulsTools.GameType.DarkSoulsIISOTFS)
     {
         DrawLiveConnectionStatusDS2();
     }
     else if (DarkSoulsTools.GetGameType() == DarkSoulsTools.GameType.DarkSoulsIII)
     {
         DrawLiveConnectionStatusDS3();
     }
     DrawRawProperties();
 }
Example #5
0
    // Helper method to lookup nonlocal textures from another bnd
    static Texture2D FindTexture(string path, DarkSoulsTools.GameType gameType)
    {
        string gamePath = DarkSoulsTools.GameFolder(gameType);

        // Map texture reference
        if (path.Contains(@"\map\"))
        {
            var splits = path.Split('\\');
            var mapid  = splits[splits.Length - 3];
            var asset  = AssetDatabase.LoadAssetAtPath <Texture2D>($@"Assets/{gamePath}/{mapid}/{Path.GetFileNameWithoutExtension(path)}.dds");
            if (asset == null)
            {
                // Attempt to load UDSFM texture
                asset = AssetDatabase.LoadAssetAtPath <Texture2D>($@"Assets/{gamePath}/UDSFMMapTextures/{Path.GetFileNameWithoutExtension(path)}.dds");
            }
            return(asset);
        }
        // Chr texture reference
        else if (path.Contains(@"\chr\"))
        {
            var splits = path.Split('\\');
            var chrid  = splits[splits.Length - 3];
            var asset  = AssetDatabase.LoadAssetAtPath <Texture2D>($@"Assets/{gamePath}/Chr/{chrid}/{Path.GetFileNameWithoutExtension(path)}.dds");
            if (asset == null)
            {
                // Attempt to load shared chr textures
                asset = AssetDatabase.LoadAssetAtPath <Texture2D>($@"Assets/{gamePath}/Chr/sharedTextures/{Path.GetFileNameWithoutExtension(path)}.dds");
            }
            return(asset);
        }
        // Obj texture reference
        else if (path.Contains(@"\obj\"))
        {
            var splits = path.Split('\\');
            var objid  = splits[splits.Length - 3];
            var asset  = AssetDatabase.LoadAssetAtPath <Texture2D>($@"Assets/{gamePath}/Obj/{objid}/{Path.GetFileNameWithoutExtension(path)}.dds");
            if (asset == null)
            {
                // Attempt to load shared chr textures
                asset = AssetDatabase.LoadAssetAtPath <Texture2D>($@"Assets/{gamePath}/Obj/sharedTextures/{Path.GetFileNameWithoutExtension(path)}.dds");
            }
            return(asset);
        }
        // Parts texture reference
        else if (path.Contains(@"\parts\"))
        {
            var asset = AssetDatabase.LoadAssetAtPath <Texture2D>($@"Assets/{gamePath}/Parts/textures/{Path.GetFileNameWithoutExtension(path)}.dds");
            return(asset);
        }
        return(null);
    }
Example #6
0
    public static void SaveParams()
    {
        if (GameType != DarkSoulsTools.GameType.DarkSoulsIII || DS3Param == null)
        {
            return;
        }

        BND4 paramBnd = SFUtil.DecryptDS3Regulation(DarkSoulsTools.GetOverridenPath(ParamPath));
        var  param    = paramBnd.Files.Find(x => Path.GetFileName(x.Name) == "ItemLotParam.param");

        param.Bytes = DS3Param.Write();

        // Save a backup if one doesn't exist
        if (!File.Exists(ParamPath + ".backup"))
        {
            File.Copy(ParamPath, ParamPath + ".backup");
        }

        string paramPath = ParamPath;

        if (DarkSoulsTools.GetModProjectPathForFile(ParamPath) != null)
        {
            paramPath = DarkSoulsTools.GetModProjectPathForFile(ParamPath);
        }

        // Write as a temporary file to make sure there are no errors before overwriting current file
        if (File.Exists(paramPath + ".temp"))
        {
            File.Delete(paramPath + ".temp");
        }
        SFUtil.EncryptDS3Regulation(paramPath + ".temp", paramBnd);

        // Make a copy of the previous map
        File.Copy(paramPath, paramPath + ".prev", true);

        // Move temp file as new map file
        File.Delete(paramPath);
        File.Move(paramPath + ".temp", paramPath);
    }
Example #7
0
    static public void ImportFlver(FLVER flver, FLVERAssetLink assetLink, DarkSoulsTools.GameType gameType, string assetName, string texturePath = null, bool mapflver = false)
    {
        Material[] materials = new Material[flver.Materials.Count];
        string     gamePath  = DarkSoulsTools.GameFolder(gameType);

        if (!AssetDatabase.IsValidFolder(assetName))
        {
            AssetDatabase.CreateFolder(Path.GetDirectoryName(assetName + ".blah"), Path.GetFileNameWithoutExtension(assetName + ".blah"));
        }

        Shader shader     = AssetDatabase.LoadAssetAtPath <Shader>("Assets/dstools/Shaders/FLVERShader.shadergraph");
        Shader shaderObj  = AssetDatabase.LoadAssetAtPath <Shader>("Assets/dstools/Shaders/ObjFLVERShader.shadergraph");
        Shader shaderDiff = AssetDatabase.LoadAssetAtPath <Shader>("Assets/dstools/Shaders/FLVERShaderDiffuse.shadergraph");
        var    t          = 0;

        foreach (var m in flver.Materials)
        {
            //string name = m.Name;
            //if (name == null || name == "")
            //{
            string name = Path.GetFileNameWithoutExtension(assetName) + $@"_{t}";
            //}
            //bool normalquery = (m.Textures.Where(x => ((x.Type.ToUpper() == "G_BUMPMAPTEXTURE") || (x.Type.ToUpper() == "G_BUMPMAP"))).Count() >= 1);
            bool normalquery = false;

            Texture2D albedo       = null;
            Texture2D specular     = null;
            Texture2D normal       = null;
            bool      IsMapTexture = mapflver;
            var       MTD          = AssetDatabase.LoadAssetAtPath <MTDAssetLink>($@"Assets/{gamePath}/MTD/{Path.GetFileNameWithoutExtension(m.MTD)}.asset");
            if (texturePath != null)
            {
                foreach (var matParam in m.Textures)
                {
                    var paramNameCheck = matParam.Type.ToUpper();
                    if (paramNameCheck == "G_DIFFUSETEXTURE" || paramNameCheck == "G_DIFFUSE" || paramNameCheck.Contains("ALBEDO"))
                    {
                        var texPath = matParam.Path;
                        if (texPath == "")
                        {
                            texPath = MTD.Textures.Find(x => (x.Name == matParam.Type)).TexturePath;
                            if (texPath == "")
                            {
                                continue;
                            }
                        }
                        if (albedo == null)
                        {
                            albedo = AssetDatabase.LoadAssetAtPath <Texture2D>($@"{texturePath}/{Path.GetFileNameWithoutExtension(texPath)}.dds");
                            if (albedo == null)
                            {
                                albedo = FindTexture(texPath, gameType);
                            }
                        }
                    }
                    if (paramNameCheck == "G_SPECULARTEXTURE" || paramNameCheck == "G_SPECULAR")
                    {
                        specular = AssetDatabase.LoadAssetAtPath <Texture2D>($@"{texturePath}/{Path.GetFileNameWithoutExtension(matParam.Path)}.dds");
                        if (specular == null)
                        {
                            specular = FindTexture(matParam.Path, gameType);
                        }
                    }
                    if (paramNameCheck == "G_BUMPMAPTEXTURE" || paramNameCheck == "G_BUMPMAP" || paramNameCheck.Contains("NORMAL"))
                    {
                        var texPath = matParam.Path;
                        if (texPath == "")
                        {
                            texPath = MTD.Textures.Find(x => (x.Name == matParam.Type)).TexturePath;
                            if (texPath == "")
                            {
                                continue;
                            }
                        }
                        if (normal == null)
                        {
                            normal = AssetDatabase.LoadAssetAtPath <Texture2D>($@"{texturePath}/{Path.GetFileNameWithoutExtension(texPath)}.dds");
                            if (normal == null)
                            {
                                normal = FindTexture(texPath, gameType);
                            }
                        }
                        normalquery = true;
                    }
                }
            }
            Material mat;

            /*if (IsMapTexture && specular != null)
             * {
             *  mat = new Material(shader);
             *  mat.SetTexture("_Albedo", albedo);
             *  mat.SetTexture("_Specular", specular);
             *  mat.SetTexture("_Normal", normal);
             * }
             * else */
            if (!normalquery)
            {
                mat = new Material(shaderDiff);
                mat.SetTexture("_MainTex", albedo);
            }
            else
            {
                mat = new Material(shaderObj);
                mat.SetTexture("_MainTex", albedo);
                mat.SetTexture("_Specular", specular);
                mat.SetTexture("_BumpMap", normal);
            }
            mat.name     = name;
            materials[t] = mat;
            t++;
            AssetDatabase.CreateAsset(mat, assetName + "/" + name + ".mat");
        }

        GameObject root      = new GameObject(Path.GetFileNameWithoutExtension(assetName));
        GameObject meshesObj = new GameObject("Meshes");
        GameObject bonesObj  = new GameObject("Bones");

        meshesObj.transform.parent = root.transform;
        bonesObj.transform.parent  = root.transform;

        // import the skeleton
        Transform[] bones     = new Transform[flver.Bones.Count];
        Matrix4x4[] bindPoses = new Matrix4x4[flver.Bones.Count];
        for (int i = 0; i < flver.Bones.Count; i++)
        {
            var fbone = flver.Bones[i];
            bones[i] = new GameObject(fbone.Name).transform;
            EulerToTransform(new Vector3(fbone.Rotation.X, fbone.Rotation.Y, fbone.Rotation.Z), bones[i]);
            bones[i].localPosition = new Vector3(fbone.Translation.X, fbone.Translation.Y, fbone.Translation.Z);
            bones[i].localScale    = new Vector3(fbone.Scale.X, fbone.Scale.Y, fbone.Scale.Z);
            //SetBoneWorldTransform(bones[i], flver.Bones.ToArray(), i);
            //bindPoses[i] = bones[i].worldToLocalMatrix * root.transform.localToWorldMatrix;
        }

        // Skeleton parenting
        for (int i = 0; i < flver.Bones.Count; i++)
        {
            var fbone = flver.Bones[i];
            if (fbone.ParentIndex == -1)
            {
                //bones[i].parent = root.transform;
                bones[i].SetParent(bonesObj.transform, false);
                bindPoses[i] = bones[i].worldToLocalMatrix * root.transform.localToWorldMatrix;
            }
            else
            {
                //bones[i].parent = bones[fbone.ParentIndex];
                bones[i].SetParent(bones[fbone.ParentIndex], false);
                bindPoses[i] = bones[i].worldToLocalMatrix * root.transform.localToWorldMatrix;
            }
        }

        // Import the meshes
        int index = 0;

        foreach (var m in flver.Meshes)
        {
            var mesh = new Mesh();

            var              verts        = new List <Vector3>();
            var              normals      = new List <Vector3>();
            var              tangents     = new List <Vector4>();
            var              boneweights  = new List <BoneWeight>();
            var              smcount      = 0;
            bool             usestangents = false;
            int              uvcount      = m.Vertices[0].UVs.Count;
            List <Vector2>[] uvs          = new List <Vector2> [uvcount];
            List <Material>  matList      = new List <Material>();

            // Add the mesh to the asset link
            FLVERAssetLink.SubmeshInfo info = new FLVERAssetLink.SubmeshInfo();
            info.Name = flver.Materials[m.MaterialIndex].Name;
            var MTD = AssetDatabase.LoadAssetAtPath <MTDAssetLink>($@"Assets/{gamePath}/MTD/{Path.GetFileNameWithoutExtension(flver.Materials[m.MaterialIndex].MTD)}.asset");
            info.Mtd = MTD;
            assetLink.Submeshes.Add(info);

            int lightmapUVIndex = 1;
            // Use MTD to get lightmap uv index
            if (gameType != DarkSoulsTools.GameType.Sekiro)
            {
                if (MTD != null)
                {
                    lightmapUVIndex = (MTD.LightmapUVIndex != -1) ? MTD.LightmapUVIndex : 1;
                    if (lightmapUVIndex >= uvs.Length)
                    {
                        lightmapUVIndex = 1;
                    }
                }
                else
                {
                    // Do a hardcoded lookup of a material's lightmap UV index from a shitty table :fatcat:
                    if (MaterialLightmapUVIndex.ContainsKey(Path.GetFileNameWithoutExtension(flver.Materials[m.MaterialIndex].MTD)))
                    {
                        lightmapUVIndex = MaterialLightmapUVIndex[Path.GetFileNameWithoutExtension(flver.Materials[m.MaterialIndex].MTD)];
                    }
                }
            }
            for (int i = 0; i < uvs.Length; i++)
            {
                uvs[i] = new List <Vector2>();
            }
            bool isSkinned = false;
            foreach (var v in m.Vertices)
            {
                verts.Add(new Vector3(v.Positions[0].X, v.Positions[0].Y, v.Positions[0].Z));
                normals.Add(new Vector3(v.Normals[0].X, v.Normals[0].Y, v.Normals[0].Z));
                if (v.Tangents.Count > 0)
                {
                    tangents.Add(new Vector4(v.Tangents[0].X, v.Tangents[0].Y, v.Tangents[0].Z, v.Tangents[0].W));
                    usestangents = true;
                }
                else
                {
                    tangents.Add(new Vector4(0, 0, 0, 1));
                }
                for (int i = 0; i < uvs.Length; i++)
                {
                    // Swap lightmap uvs with uv index 1 because lmao unity
                    if (i == 1)
                    {
                        uvs[i].Add(new Vector2(v.UVs[lightmapUVIndex].X, 1.0f - v.UVs[lightmapUVIndex].Y));
                    }
                    else if (i == lightmapUVIndex)
                    {
                        uvs[i].Add(new Vector2(v.UVs[1].X, 1.0f - v.UVs[1].Y));
                    }
                    else
                    {
                        uvs[i].Add(new Vector2(v.UVs[i].X, 1.0f - v.UVs[i].Y));
                    }
                }
                if (v.BoneWeights != null && v.BoneWeights.Count() > 0)
                {
                    isSkinned = true;
                    var weight = new BoneWeight();

                    if (m.Unk1 == 0)
                    {
                        weight.boneIndex0 = v.BoneIndices[0];
                        weight.boneIndex1 = v.BoneIndices[1];
                        weight.boneIndex2 = v.BoneIndices[2];
                        weight.boneIndex3 = v.BoneIndices[3];
                    }
                    else
                    {
                        weight.boneIndex0 = m.BoneIndices[v.BoneIndices[0]];
                        weight.boneIndex1 = m.BoneIndices[v.BoneIndices[1]];
                        weight.boneIndex2 = m.BoneIndices[v.BoneIndices[2]];
                        weight.boneIndex3 = m.BoneIndices[v.BoneIndices[3]];
                    }
                    if (v.BoneWeights[0] < 0.0)
                    {
                        weight.weight0 = 1.0f;
                    }
                    else
                    {
                        weight.weight0 = v.BoneWeights[0];
                    }
                    weight.weight1 = v.BoneWeights[1];
                    weight.weight2 = v.BoneWeights[2];
                    weight.weight3 = v.BoneWeights[3];
                    boneweights.Add(weight);
                }
                else
                {
                    boneweights.Add(new BoneWeight());
                }
            }
            foreach (var fs in m.FaceSets)
            {
                if (fs.Vertices.Count() > 0 && fs.Flags == FLVER.FaceSet.FSFlags.None)
                {
                    matList.Add(materials[m.MaterialIndex]);
                    smcount++;
                }
            }

            mesh.indexFormat  = UnityEngine.Rendering.IndexFormat.UInt32;
            mesh.subMeshCount = smcount;
            mesh.SetVertices(verts);
            mesh.SetNormals(normals);
            if (usestangents)
            {
                mesh.SetTangents(tangents);
            }
            if (isSkinned)
            {
                mesh.boneWeights = boneweights.ToArray();
                mesh.bindposes   = bindPoses;
            }

            for (int i = 0; i < uvs.Length; i++)
            {
                mesh.SetUVs(i, uvs[i]);
            }

            var submesh = 0;
            foreach (var fs in m.FaceSets)
            {
                if (fs.Vertices.Count() == 0)
                {
                    continue;
                }
                if (fs.Flags != FLVER.FaceSet.FSFlags.None)
                {
                    continue;
                }

                mesh.SetTriangles(fs.GetFacesArray(), submesh, true, 0);
                submesh++;
            }
            mesh.RecalculateBounds();

            // Setup a game object asset
            GameObject obj = new GameObject(Path.GetFileNameWithoutExtension(assetName) + $@"_{index}");
            if (isSkinned)
            {
                obj.AddComponent <SkinnedMeshRenderer>();
                obj.GetComponent <SkinnedMeshRenderer>().materials  = matList.ToArray();
                obj.GetComponent <SkinnedMeshRenderer>().bones      = bones;
                obj.GetComponent <SkinnedMeshRenderer>().sharedMesh = mesh;
            }
            else
            {
                obj.AddComponent <MeshRenderer>();
                obj.GetComponent <MeshRenderer>().materials = matList.ToArray();
                obj.AddComponent <MeshFilter>();
                obj.GetComponent <MeshFilter>().mesh = mesh;
            }
            obj.AddComponent <FlverSubmesh>();
            obj.GetComponent <FlverSubmesh>().Link       = assetLink;
            obj.GetComponent <FlverSubmesh>().SubmeshIdx = index;
            obj.transform.parent = meshesObj.transform;

            AssetDatabase.CreateAsset(mesh, assetName + $@"/{Path.GetFileNameWithoutExtension(assetName)}_{index}.mesh");
            index++;
        }

        // If there's no meshes, create an empty one to bind the skeleton to so that Maya works
        // when you export the skeleton (like with c0000).
        if (flver.Meshes.Count == 0)
        {
            var mesh = new Mesh();

            var verts       = new List <Vector3>();
            var normals     = new List <Vector3>();
            var tangents    = new List <Vector4>();
            var boneweights = new List <BoneWeight>();
            for (var i = 0; i < 3; i++)
            {
                verts.Add(new Vector3(0.0f, 0.0f, 0.0f));
                normals.Add(new Vector3(0.0f, 1.0f, 0.0f));
                tangents.Add(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
                var weight = new BoneWeight();
                weight.boneIndex0 = 0;
                weight.weight0    = 1.0f;
                boneweights.Add(weight);
            }

            mesh.indexFormat  = UnityEngine.Rendering.IndexFormat.UInt32;
            mesh.subMeshCount = 1;
            mesh.SetVertices(verts);
            mesh.SetNormals(normals);
            mesh.SetTangents(tangents);
            mesh.boneWeights = boneweights.ToArray();
            mesh.bindposes   = bindPoses;
            mesh.SetTriangles(new int [] { 0, 1, 2 }, 0);

            GameObject obj = new GameObject(Path.GetFileNameWithoutExtension(assetName) + $@"_{index}");
            obj.AddComponent <SkinnedMeshRenderer>();
            obj.GetComponent <SkinnedMeshRenderer>().bones      = bones;
            obj.GetComponent <SkinnedMeshRenderer>().sharedMesh = mesh;
            obj.transform.parent = meshesObj.transform;

            AssetDatabase.CreateAsset(mesh, assetName + $@"/{Path.GetFileNameWithoutExtension(assetName)}_{index}.mesh");
        }

        root.AddComponent <FlverMesh>();
        root.GetComponent <FlverMesh>().Link = assetLink;

        AssetDatabase.CreateAsset(assetLink, assetName + ".asset");
        AssetDatabase.SaveAssets();
        PrefabUtility.SaveAsPrefabAsset(root, assetName + ".prefab");
        Object.DestroyImmediate(root);
    }