Ejemplo n.º 1
0
 public string GetFilepath(string location, MyTextureType type)
 {
     using (List <MyObjectBuilder_AssetModifierDefinition.MyAssetTexture> .Enumerator enumerator = this.Textures.GetEnumerator())
     {
         while (true)
         {
             if (!enumerator.MoveNext())
             {
                 break;
             }
             MyObjectBuilder_AssetModifierDefinition.MyAssetTexture current = enumerator.Current;
             if ((current.Location == location) && (current.Type == type))
             {
                 return(current.Filepath);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
        void FixModTexturePaths(MyAssetModifierDefinition assetDef)
        {
            try
            {
                if (assetDef.Textures == null || assetDef.Textures.Count <= 0)
                {
                    Log.Error($"Skin '{assetDef.Id.SubtypeName}' has no textures!");
                    return;
                }

                if (TextureChanges == null)
                {
                    TextureChanges = new Dictionary <string, DoTextureChange>();
                }
                else
                {
                    TextureChanges.Clear();
                }

                for (int i = 0; i < assetDef.Textures.Count; i++)
                {
                    MyObjectBuilder_AssetModifierDefinition.MyAssetTexture texture = assetDef.Textures[i];

                    if (string.IsNullOrEmpty(texture.Filepath))
                    {
                        continue;
                    }

                    if (texture.Filepath.StartsWith(".."))
                    {
                        continue; // some fix already applied
                    }
                    string fixedPath = Path.Combine(assetDef.Context.ModPath, texture.Filepath);
                    //fixedPath = Path.GetFullPath(fixedPath);

                    if (!MyAPIGateway.Utilities.FileExistsInModLocation(fixedPath, assetDef.Context.ModItem))
                    {
                        continue;
                    }

                    //Log.Info($"Fixed paths for mod '{assetDef.Context.ModName}' --- {texture.Location}: '{texture.Filepath}' to '{fixedPath}'");

                    // has no direct effect on the skin, the render thing after does, but this is for consistency
                    texture.Filepath     = fixedPath;
                    assetDef.Textures[i] = texture;

                    DoTextureChange texChange = TextureChanges.GetValueOrDefault(texture.Location);
                    switch ((TextureType)texture.Type)
                    {
                    case TextureType.ColorMetal: texChange.ColorMetalFileName = fixedPath; break;

                    case TextureType.NormalGloss: texChange.NormalGlossFileName = fixedPath; break;

                    case TextureType.Extensions: texChange.ExtensionsFileName = fixedPath; break;

                    case TextureType.Alphamask: texChange.AlphamaskFileName = fixedPath; break;
                    }
                    TextureChanges[texture.Location] = texChange;
                }

                if (TextureChanges.Count == 0)
                {
                    return;
                }

                MyDefinitionManager.MyAssetModifiers assetModifierForRender = MyDefinitionManager.Static.GetAssetModifierDefinitionForRender(assetDef.Id.SubtypeId);

                foreach (var kv in TextureChanges)
                {
                    // HACK: generating the prohibited MyTextureChange object from XML with similar data
                    string xml = MyAPIGateway.Utilities.SerializeToXML(kv.Value);
                    xml = xml.Replace(nameof(DoTextureChange), "MyTextureChange");
                    assetModifierForRender.SkinTextureChanges[kv.Key] = DeserializeAs(xml, assetModifierForRender.SkinTextureChanges);
                }

                Log.Info($"Fixed mod-relative paths for skin '{assetDef.Id.SubtypeName}' from mod '{assetDef.Context.ModName}'");
            }
            catch (Exception e)
            {
                Log.Error($"Error in IsSkinAsset() for asset={assetDef.Id.ToString()}\n{e}");
            }
        }