예제 #1
0
        //private List<RecipeOverride> defaultRecipeOverrides

        public bool TryOverrideRecipe(TechType fragment, out RecipeData outRecipe)
        {
            string sFragment = fragment.ToString();

            foreach (RecipeOverride r in RecipeOverrides)
            {
                if (sFragment == r.overridden)
                {
                    outRecipe = new RecipeData();
                    foreach (StringIngredient s in r.replacements)
                    {
                        if (TechTypeUtils.TryGetModTechType(s.techType, out TechType t))
                        {
                            outRecipe.Ingredients.Add(new Ingredient(t, s.amount));
                        }
                        else
                        {
#if !RELEASE
                            Logger.Log(Logger.Level.Error, $"Could not parse {s.techType} as TechType; check the spelling and/or case");
#endif
                            outRecipe = null;
                            return(false);
                        }
                    }
                    return(true);
                }
            }
            outRecipe = null;
            return(false);
        }
예제 #2
0
        public static void PostEquipmentChanged(ref Player __instance, string slot, InventoryItem item)
        {
            List <string> mySlots = new List <string>()
            {
                "Body", "Gloves"
            };

            bool bLog = Main.playerSlots.Contains(slot);
            //Logger.Log(Logger.Level.Debug, "1");
            bool bUseCustomTex = (Main.suitTexture != null && Main.glovesTexture != null);

            if (bLog)
            {
                Logger.Log(Logger.Level.Debug, $"Player_EquipmentChanged_Patch.Postfix: slot = {slot}. Custom textures enabled: {bUseCustomTex}");
            }
            //if (bLog) Logger.Log(Logger.Level.Debug, "2");
            Equipment equipment = Inventory.main.equipment;

            if (equipment == null)
            {
                if (bLog)
                {
                    Logger.Log(Logger.Level.Error, $"Failed to get Equipment instance");
                }
                return;
            }
            if (__instance == null)
            {
                if (bLog)
                {
                    Logger.Log(Logger.Level.Error, $"Failed to get Player instance");
                }
                return;
            }

            //if (bLog) Logger.Log(Logger.Level.Debug, "3");
            if (__instance.equipmentModels == null)
            {
                if (bLog)
                {
                    Logger.Log(Logger.Level.Error, $"Failed to get equipmentModels member of Player instance");
                }
                return;
            }

            GameObject playerModel      = Player.main.gameObject;
            Shader     shader           = Shader.Find("MarmosetUBER");
            Renderer   reinforcedGloves = playerModel.transform.Find("body/player_view/male_geo/reinforcedSuit/reinforced_suit_01_glove_geo").gameObject.GetComponent <Renderer>();

            if (defaultGloveMaterial == null)
            {
                if (reinforcedGloves != null)
                {
                    // Save a copy of the original material, for use later
                    if (bLog)
                    {
                        Logger.Log(Logger.Level.Debug, "Found Reinforced Gloves shader and copying default material");
                    }
                    defaultGloveMaterial = new Material(reinforcedGloves.material);
                }
                else
                if (bLog)
                {
                    Logger.Log(Logger.Level.Error, "ReinforcedGloves renderer not found while attempting to copy default material");
                }
            }
            Renderer reinforcedSuit = playerModel.transform.Find("body/player_view/male_geo/reinforcedSuit/reinforced_suit_01_body_geo").gameObject.GetComponent <Renderer>();

            if (reinforcedSuit != null)
            {
                if (defaultSuitMaterial == null)
                {
                    // Save a copy of the original material, for use later
                    if (bLog)
                    {
                        Logger.Log(Logger.Level.Debug, "Found Reinforced Suit shader and copying default material");
                    }
                    defaultSuitMaterial = new Material(reinforcedSuit.material);
                }
                if (defaultArmsMaterial == null)
                {
                    // Save a copy of the original material, for use later
                    if (bLog)
                    {
                        Logger.Log(Logger.Level.Debug, "Found Reinforced Suit shader and copying default arm material");
                    }
                    defaultArmsMaterial = new Material(reinforcedSuit.materials[1]);
                }
            }
            else
            if (bLog)
            {
                Logger.Log(Logger.Level.Error, "ReinforcedSuit renderer not found while attempting to copy default materials");
            }

            foreach (Player.EquipmentType equipmentType in __instance.equipmentModels)
            {
                bool bChangeTex = false;
                bUseCustomTex = (Main.suitTexture != null && Main.glovesTexture != null);
                string   activeSlot     = equipmentType.slot;
                TechType techTypeInSlot = equipment.GetTechTypeInSlot(equipmentType.slot);

                if (activeSlot == "Body")
                {
                    bHasSurvivalSuit = SurvivalSuits.Contains(techTypeInSlot);
                    Log.LogDebug($"PlayerPatches.EquipmentChanged(): TechType in slot Body = '{techTypeInSlot}', bHasSurvivalSuit = {bHasSurvivalSuit}");
                    bChangeTex       = (techTypeInSlot != lastBodyTechType);
                    techTypeInSlot   = CheckSubstitute(techTypeInSlot);
                    lastBodyTechType = techTypeInSlot;
                    if (techTypeInSlot == ttSuit ||
                        (TechTypeUtils.TryGetModTechType("NitrogenBrineSuit2", out TechType tt2) && techTypeInSlot == tt2) ||
                        (TechTypeUtils.TryGetModTechType("NitrogenBrineSuit3", out TechType tt3) && techTypeInSlot == tt3))
                    {
                        techTypeInSlot = TechType.ReinforcedDiveSuit;
                    }
                    else
                    {
                        bUseCustomTex = false;
                    }
                }
                else if (activeSlot == "Gloves")
                {
                    bChangeTex         = (techTypeInSlot != lastGlovesTechType);
                    lastGlovesTechType = techTypeInSlot;
                    if (techTypeInSlot == ttGloves)
                    {
                        techTypeInSlot = TechType.ReinforcedGloves;
                    }
                    else
                    {
                        bUseCustomTex = false;
                    }
                }
                //else
                //    continue;

                bool flag = false;
                if (bLog)
                {
                    Logger.Log(Logger.Level.Debug, $"checking equipmentModels for TechType {techTypeInSlot.AsString(false)}");
                }
                foreach (Player.EquipmentModel equipmentModel in equipmentType.equipment)
                {
                    //Player.EquipmentModel equipmentModel = equipmentType.equipment[j];
                    bool equipmentVisibility = (equipmentModel.techType == techTypeInSlot);
                    if (bChangeTex)
                    {
                        if (bLog)
                        {
                            Logger.Log(Logger.Level.Debug, "Equipment changed, changing textures");
                        }
                        if (bUseCustomTex)
                        {
                            if (shader == null)
                            {
                                if (bLog)
                                {
                                    Logger.Log(Logger.Level.Debug, $"Shader is null, custom texture disabled");
                                }
                                bUseCustomTex = false;
                            }
                            else if (activeSlot == "Gloves" && reinforcedGloves == null)
                            {
                                if (bLog)
                                {
                                    Logger.Log(Logger.Level.Debug, $"reinforcedGloves is null, custom texture disabled");
                                }
                                bUseCustomTex = false;
                            }
                            else if (activeSlot == "Body" && reinforcedSuit == null)
                            {
                                if (bLog)
                                {
                                    Logger.Log(Logger.Level.Debug, $"reinforcedSuit is null, custom texture disabled");
                                }
                                bUseCustomTex = false;
                            }
                        }
                    }

                    flag = (flag || equipmentVisibility);
                    if (equipmentModel.model != null)
                    {
                        if (bChangeTex)
                        {
                            if (bUseCustomTex)
                            {
                                // Apply the Brine Suit texture
                                if (activeSlot == "Gloves")
                                {
                                    // if the gloves shader isn't null, add the shader
                                    if (reinforcedGloves != null && // This shouldn't be necessary but I'm taking no chances
                                        reinforcedGloves.material != null)
                                    {
                                        if (brineGloveMaterial == null)
                                        {
                                            brineGloveMaterial = GetGloveMaterial(shader, defaultGloveMaterial);
                                        }

                                        if (brineGloveMaterial != null)
                                        {
                                            reinforcedGloves.material = brineGloveMaterial;
                                        }
                                        else
                                        {
                                            if (bLog)
                                            {
                                                Logger.Log(Logger.Level.Error, "Creation of new Brine glove material failed");
                                            }
                                        }
                                    }
                                }
                                else if (activeSlot == "Body")
                                {
                                    if (reinforcedSuit != null &&
                                        reinforcedSuit.material != null &&
                                        reinforcedSuit.material.shader != null)
                                    {
                                        if (brineArmsMaterial == null)
                                        {
                                            if (bLog)
                                            {
                                                Logger.Log(Logger.Level.Debug, "Creating new brineArmsMaterial");
                                            }
                                            if (defaultArmsMaterial != null)
                                            {
                                                brineArmsMaterial = GetGloveMaterial(null, defaultArmsMaterial);

                                                /*brineArmsMaterial = new Material(defaultArmsMaterial);
                                                 * // add the suit's arms main Texture when equipped
                                                 * //if (bLog) Logger.Log(Logger.Level.Debug, $"add the suit's arms main Texture when equipped");
                                                 * brineArmsMaterial.mainTexture = Main.glovesTexture;
                                                 * // add the suit's arms spec Texture when equipped
                                                 * //if (bLog) Logger.Log(Logger.Level.Debug, $"add the suit's arms spec Texture when equipped");
                                                 * brineArmsMaterial.SetTexture(ShaderPropertyID._SpecTex, Main.glovesTexture);
                                                 * // add the suit's arms illum texture when equipped
                                                 * //if (bLog) Logger.Log(Logger.Level.Debug, $"add the suit's arms illum texture when equipped");
                                                 * brineArmsMaterial.SetTexture(ShaderPropertyID._Illum, Main.glovesIllumTexture);*/
                                            }
                                            else
                                            if (bLog)
                                            {
                                                Logger.Log(Logger.Level.Error, "defaultArmsMaterial not set while trying to create new brineArmsMaterial");
                                            }
                                        }

                                        if (brineArmsMaterial != null)
                                        {
                                            if (bLog)
                                            {
                                                Logger.Log(Logger.Level.Debug, "Applying brineArmsMaterial");
                                            }
                                            reinforcedSuit.materials[1] = brineArmsMaterial;
                                        }
                                        else
                                        if (bLog)
                                        {
                                            Logger.Log(Logger.Level.Error, "Error generating brineArmsMaterial");
                                        }


                                        if (brineSuitMaterial == null)
                                        {
                                            if (bLog)
                                            {
                                                Logger.Log(Logger.Level.Debug, "Creating new brineSuitMaterial");
                                            }
                                            if (defaultSuitMaterial != null)
                                            {
                                                brineSuitMaterial = new Material(defaultSuitMaterial);

                                                brineSuitMaterial.shader      = shader;
                                                brineSuitMaterial.mainTexture = Main.suitTexture;
                                                // add the suit spec texture when equipped
                                                //if (bLog) Logger.Log(Logger.Level.Debug, $"add the suit spec texture when equipped");
                                                brineSuitMaterial.SetTexture(ShaderPropertyID._SpecTex, Main.suitTexture);
                                                // add  the suit illum Texture when equipped
                                                //if (bLog) Logger.Log(Logger.Level.Debug, $"add  the suit illum Texture when equipped");
                                                brineSuitMaterial.SetTexture(ShaderPropertyID._Illum, Main.suitIllumTexture);

                                                /*
                                                 * // add the suit's arms main Texture when equipped
                                                 * //if (bLog) Logger.Log(Logger.Level.Debug, $"add the suit's arms main Texture when equipped");
                                                 * reinforcedSuit.materials[1].mainTexture = Main.glovesTexture;
                                                 * // add the suit's arms spec Texture when equipped
                                                 * //if (bLog) Logger.Log(Logger.Level.Debug, $"add the suit's arms spec Texture when equipped");
                                                 * reinforcedSuit.materials[1].SetTexture(ShaderPropertyID._SpecTex, Main.glovesTexture);
                                                 * // add the suit's arms illum texture when equipped
                                                 * //if (bLog) Logger.Log(Logger.Level.Debug, $"add the suit's arms illum texture when equipped");
                                                 * reinforcedSuit.materials[1].SetTexture(ShaderPropertyID._Illum, Main.glovesIllumTexture);
                                                 */
                                            }
                                            else
                                            if (bLog)
                                            {
                                                Logger.Log(Logger.Level.Error, "defaultSuitMaterial not set while trying to create new brineSuitMaterial");
                                            }
                                        }

                                        if (brineSuitMaterial != null)
                                        {
                                            if (bLog)
                                            {
                                                Logger.Log(Logger.Level.Debug, "Applying brineSuitMaterial");
                                            }
                                            reinforcedSuit.material     = brineSuitMaterial;
                                            reinforcedSuit.materials[0] = brineSuitMaterial;
                                        }
                                        else
                                        if (bLog)
                                        {
                                            Logger.Log(Logger.Level.Error, "Creation of new Brine Suit material failed");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (activeSlot == "Body")
                                {
                                    if (reinforcedSuit != null)
                                    {
                                        if (defaultSuitMaterial != null)
                                        {
                                            reinforcedSuit.material     = defaultSuitMaterial;
                                            reinforcedSuit.materials[0] = defaultSuitMaterial;
                                        }
                                        else
                                        if (bLog)
                                        {
                                            Logger.Log(Logger.Level.Error, "Could not restore default suit material; Default suit material not found");
                                        }

                                        if (defaultArmsMaterial != null)
                                        {
                                            reinforcedSuit.materials[1] = defaultArmsMaterial;
                                        }
                                        else
                                        if (bLog)
                                        {
                                            Logger.Log(Logger.Level.Error, "Could not restore default arms material; Default arms material not found");
                                        }
                                    }
                                }
                                else if (activeSlot == "Gloves")
                                {
                                    if (reinforcedGloves != null)
                                    {
                                        if (defaultGloveMaterial != null)
                                        {
                                            reinforcedGloves.material = defaultGloveMaterial;
                                        }
                                        else
                                        if (bLog)
                                        {
                                            Logger.Log(Logger.Level.Error, "Could not restore default glove material; Default glove material not found");
                                        }
                                    }
                                }
                            }
                        }

                        equipmentModel.model.SetActive(equipmentVisibility);
                    }
                }
                if (equipmentType.defaultModel != null)
                {
                    equipmentType.defaultModel.SetActive(!flag);
                }
            }

            // Actually we don't need this, since we're not doing anything that would change the outcome of UpdateReinforcedSuit.
            // Might be useful in the future though, so it's getting commented-out instead of deleted.

            /*MethodInfo dynMethod = __instance.GetType().GetMethod("UpdateReinforcedSuit", BindingFlags.NonPublic | BindingFlags.Instance);
             * dynMethod.Invoke(__instance, null);*/
        }