Ejemplo n.º 1
0
        public SkinInfo(MyAssetModifierDefinition definition, string name, string icon)
        {
            // definition is null for no-skin one.
            Definition = definition;
            SubtypeId  = (definition == null ? MyStringHash.NullOrEmpty : definition.Id.SubtypeId);

            Name = name;
            Icon = MyStringId.GetOrCompute(icon);

            // mod DLC-less skins are always owned
            // TODO: check if it's a vanilla definition that originally has DLC requirement and ignore those, but no way to get original vanilla definitions...
            AlwaysOwned = Definition == null || (!Definition.Context.IsBaseGame && (Definition.DLCs == null || Definition.DLCs.Length == 0));

            // cannot check DLC ownership here, must check it a bit later
            LocallyOwned = AlwaysOwned;
        }
Ejemplo n.º 2
0
        void UpdatePaintCanMaterial()
        {
            PaintMaterial material = PaintPreviewMaterial ?? OwnerInfo.GetPaintMaterial();

            MyDefinitionManager.MyAssetModifiers skinRender = default(MyDefinitionManager.MyAssetModifiers);
            Vector3?skinColorOverride = null;

            if (material.Skin.HasValue)
            {
                skinRender = MyDefinitionManager.Static.GetAssetModifierDefinitionForRender(material.Skin.Value);

                MyAssetModifierDefinition skinDef = MyDefinitionManager.Static.GetAssetModifierDefinition(new MyDefinitionId(typeof(MyObjectBuilder_AssetModifierDefinition), material.Skin.Value));
                if (skinDef != null && skinDef.DefaultColor.HasValue)
                {
                    skinColorOverride = skinDef.DefaultColor.Value.ColorToHSVDX11();
                }
            }

            Vector3 colorMask = skinColorOverride ?? material.ColorMask ?? Main.Palette.DefaultColorMask;

            IMyEntity paintEntity = (MagazineSubpart as IMyEntity) ?? Rifle;

            paintEntity.Render.MetalnessColorable = skinRender.MetalnessColorable;
            paintEntity.Render.TextureChanges     = skinRender.SkinTextureChanges;

            // required to properly update skin (like glamour not being recolorable
            paintEntity.Render.RemoveRenderObjects();
            paintEntity.Render.AddRenderObjects();

            if (!paintEntity.Render.EnableColorMaskHsv)
            {
                paintEntity.Render.EnableColorMaskHsv = true;
            }

            paintEntity.Render.ColorMaskHsv = colorMask;

            ParticleColor = Utils.ColorMaskToRGB(colorMask);
        }
Ejemplo n.º 3
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}");
            }
        }
Ejemplo n.º 4
0
        static bool IsSkinAsset(MyAssetModifierDefinition assetDef)
        {
            if (assetDef == null)
            {
                return(false);
            }

            try
            {
                if (assetDef.Id.SubtypeName == TEST_ARMOR_SUBTYPE)
                {
                    return(false); // skip unusable vanilla test armor
                }
                if (assetDef.Id.SubtypeName.EndsWith(ARMOR_SUFFIX))
                {
                    return(true);
                }

                if (assetDef.Icons != null)
                {
                    foreach (string icon in assetDef.Icons)
                    {
                        if (icon == null)
                        {
                            continue;
                        }

                        if (icon.IndexOf("armor", StringComparison.OrdinalIgnoreCase) != -1)
                        {
                            return(true);
                        }
                    }
                }

                if (assetDef.Textures != null)
                {
                    foreach (MyObjectBuilder_AssetModifierDefinition.MyAssetTexture texture in assetDef.Textures)
                    {
                        if (texture.Location == null)
                        {
                            continue;
                        }

                        if (texture.Location.Equals("SquarePlate", StringComparison.OrdinalIgnoreCase))
                        {
                            return(true);
                        }

                        if (texture.Location.Equals("PaintedMetal_Colorable", StringComparison.OrdinalIgnoreCase))
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error($"Error in IsSkinAsset() for asset={assetDef.Id.ToString()}\n{e}");
            }

            return(false);
        }