Ejemplo n.º 1
0
        public Form1()
        {
            MaterialSkin.MaterialSkinManager.Instance.Theme = MaterialSkin.MaterialSkinManager.Themes.DARK;
            InitializeComponent();

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            HomeMenuPartBox.Items.AddRange(HomeMenuParts.Keys.ToArray());
            HomeMenuPartBox.SelectedIndex = 0;
            HomeMenuPartBox_SelectedIndexChanged(null, null);

            LoadFileText    = SwitchThemesCommon.GeneratePatchListString(Templates);
            tbPatches.Text += LoadFileText;
        }
Ejemplo n.º 2
0
 public static void UploadSZS(Uint8Array arr)         //called from js
 {
     DoActionWithloading(() =>
     {
         byte[] sarc = ManagedYaz0.Decompress(arr.ToArray());
         CommonSzs   = SARCExt.SARC.UnpackRamN(sarc);
         sarc        = null;
         while (LayoutsComboBox.LastChild.TextContent != "Don't patch")
         {
             LayoutsComboBox.RemoveChild(LayoutsComboBox.LastChild);
         }
         targetPatch = SwitchThemesCommon.DetectSarc(CommonSzs, DefaultTemplates.templates);
         if (targetPatch == null)
         {
             Window.Alert("This is not a valid theme file, if it's from a newer firmware it's not compatible with this tool yet");
             CommonSzs               = null;
             targetPatch             = null;
             lblDetected.TextContent = "";
             return;
         }
         lblDetected.TextContent = "Detected " + targetPatch.TemplateName + " " + targetPatch.FirmName;
         for (int i = 0; i < layoutPatches.Length; i++)
         {
             if (layoutPatches[i] != null && layoutPatches[i].IsCompatible(CommonSzs))
             {
                 LayoutsComboBox.Add(new HTMLOptionElement()
                 {
                     TextContent = layoutPatches[i].ToString(), Value = i.ToString()
                 });
             }
         }
     });
 }
Ejemplo n.º 3
0
        internal void Apply(Harmony harmony)
        {
            harmony.Patch(AccessTools.Method(_object, nameof(Object.draw), new[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
            harmony.Patch(AccessTools.Method(_object, nameof(Object.drawPlacementBounds), new[] { typeof(SpriteBatch), typeof(GameLocation) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPlacementBoundsPrefix)));
            harmony.Patch(AccessTools.Method(_object, nameof(Object.DayUpdate), new[] { typeof(GameLocation) }), postfix: new HarmonyMethod(GetType(), nameof(DayUpdatePostfix)));
            harmony.Patch(AccessTools.Method(_object, nameof(Object.rot), null), postfix: new HarmonyMethod(GetType(), nameof(RotPostfix)));
            harmony.Patch(AccessTools.Method(_object, nameof(Object.placementAction), new[] { typeof(GameLocation), typeof(int), typeof(int), typeof(Farmer) }), postfix: new HarmonyMethod(GetType(), nameof(PlacementActionPostfix)));

            harmony.Patch(AccessTools.Constructor(_object, new[] { typeof(Vector2), typeof(int), typeof(int) }), postfix: new HarmonyMethod(GetType(), nameof(ObjectPostfix)));

            if (PatchTemplate.IsDGAUsed())
            {
                try
                {
                    if (Type.GetType("DynamicGameAssets.Game.CustomObject, DynamicGameAssets") is Type dgaObjectType && dgaObjectType != null)
                    {
                        harmony.Patch(AccessTools.Method(dgaObjectType, nameof(Object.draw), new[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
                        harmony.Patch(AccessTools.Method(dgaObjectType, nameof(Object.placementAction), new[] { typeof(GameLocation), typeof(int), typeof(int), typeof(Farmer) }), postfix: new HarmonyMethod(GetType(), nameof(PlacementActionPostfix)));
                    }

                    if (Type.GetType("DynamicGameAssets.Game.CustomBigCraftable, DynamicGameAssets") is Type dgaCraftableType && dgaCraftableType != null)
                    {
                        harmony.Patch(AccessTools.Method(dgaCraftableType, nameof(Object.draw), new[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
                    }
                }
                catch (Exception ex)
                {
                    _monitor.Log($"Failed to patch Dynamic Game Assets in {this.GetType().Name}: AT may not be able to override certain DGA object types!", LogLevel.Warn);
                    _monitor.Log($"Patch for DGA failed in {this.GetType().Name}: {ex}", LogLevel.Trace);
                }
            }
        }
Ejemplo n.º 4
0
        public Form1()
        {
            InitializeComponent();

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            HomeMenuPartBox.Items.AddRange(HomeMenuParts.Keys.ToArray());
            HomeMenuPartBox.SelectedIndex = 0;
            HomeMenuPartBox_SelectedIndexChanged(null, null);

            LoadFileText   = SwitchThemesCommon.GeneratePatchListString(Templates);
            tbPatches.Text = "(To dump the following files check the guide at https://git.io/fxdyF )\r\n" + LoadFileText;
        }
Ejemplo n.º 5
0
        public Form1()
        {
            InitializeComponent();
            PatchLabelText = materialLabel3.Text;

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            LoadFileText   = SwitchThemesCommon.GeneratePatchListString(Templates);
            tbPatches.Text = "(To dump the following files check the guide at https://git.io/fxdyF )\r\n" + LoadFileText;

            if (!File.Exists("hactool\\hactool.exe") || !File.Exists("hactool\\keys.dat"))
            {
                materialTabControl1.TabPages.Remove(NCADumpPage);
            }
        }
 public static bool PatchBgLayout(this BflytFile f, PatchTemplate patch)
 {
     #region DetectPatch
     if (f[patch.PatchIdentifier] != null)
     {
         return(true);
     }
     {
         var p = f["3x3lxBG"];
         if (p != null)
         {
             f.RemovePane(p);
             f.GetTex.Textures[0] = "White1x1^r";
             f.GetMat.Materials.RemoveAt(1);
         }
     }
     #endregion
     #region FindAndRemoveTargetBgPanels
     BasePane target = null;
     foreach (var t in patch.targetPanels)
     {
         var p = f[t];
         if (p == null)
         {
             continue;
         }
         if (target == null)
         {
             target = p;
         }
         if (patch.DirectPatchPane)
         {
             ushort m  = f.AddBgMat(patch.MaintextureName);
             var    pe = p as Pic1Pane;
             pe.MaterialIndex = m;
         }
         else if (!patch.NoRemovePanel)
         {
             var pe = p as Pan1Pane;
             pe.Position = new Vector3(5000, 60000, 0);
         }
     }
     if (target == null)
     {
         return(false);
     }
     #endregion
     if (!patch.DirectPatchPane)
     {
         return(f.AddBgPanel(target, patch.MaintextureName, patch.PatchIdentifier));
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 7
0
        private void OpenSzsButton(object sender, EventArgs e)
        {
            OpenFileDialog opn = new OpenFileDialog()
            {
                Title  = "open szs",
                Filter = "szs file|*.szs|all files|*.*",
            };

            if (opn.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            if (!File.Exists(opn.FileName))
            {
                MessageBox.Show("Could not open file");
                return;
            }

            targetPatch = null;
            LayoutPatchList.Items.Clear();
            LayoutPatchList.Items.Add("Don't patch");

            CommonSzs   = SARCExt.SARC.UnpackRamN(ManagedYaz0.Decompress(File.ReadAllBytes(opn.FileName)));
            targetPatch = SwitchThemesCommon.DetectSarc(CommonSzs, Templates);

            if (targetPatch == null)
            {
                if (Advanced)
                {
                    AdvancedUpdate();
                    lblDetected.Text = "Unknown szs file";
                    return;
                }

                MessageBox.Show("This is not a valid theme file, if it's from a newer firmware it's not compatible with this tool yet");
                CommonSzs        = null;
                targetPatch      = null;
                lblDetected.Text = "";
                return;
            }

            AdvancedUpdate();
            lblDetected.Text = "Detected " + targetPatch.TemplateName + " " + targetPatch.FirmName;

            foreach (var l in Layouts.Values)
            {
                if (l.IsCompatible(CommonSzs))
                {
                    LayoutPatchList.Items.Add(l);
                }
            }
            LayoutPatchList.Items.Add("Open from file...");
            LayoutPatchList.SelectedIndex = 0;
        }
Ejemplo n.º 8
0
        private static bool DrawInMenuPrefix(Flooring __instance, SpriteBatch spriteBatch, Vector2 positionOnScreen, Vector2 tileLocation, float scale, float layerDepth)
        {
            if (__instance.modData.ContainsKey("AlternativeTextureName") && !PatchTemplate.IsDGAObject(__instance))
            {
                var textureModel = AlternativeTextures.textureManager.GetSpecificTextureModel(__instance.modData["AlternativeTextureName"]);
                if (textureModel is null)
                {
                    return(true);
                }

                var textureVariation = Int32.Parse(__instance.modData["AlternativeTextureVariation"]);
                if (textureVariation == -1 || AlternativeTextures.modConfig.IsTextureVariationDisabled(textureModel.GetId(), textureVariation))
                {
                    return(true);
                }
                var textureOffset = textureModel.GetTextureOffset(textureVariation);

                int     sourceRectPosition   = 1;
                byte    drawSum              = 0;
                Vector2 surroundingLocations = tileLocation;
                surroundingLocations.X += 1f;
                GameLocation farm = Game1.getLocationFromName("Farm");
                if (farm.terrainFeatures.ContainsKey(surroundingLocations) && farm.terrainFeatures[surroundingLocations] is Flooring)
                {
                    drawSum = (byte)(drawSum + 2);
                }
                surroundingLocations.X -= 2f;
                if (farm.terrainFeatures.ContainsKey(surroundingLocations) && Game1.currentLocation.terrainFeatures[surroundingLocations] is Flooring)
                {
                    drawSum = (byte)(drawSum + 8);
                }
                surroundingLocations.X += 1f;
                surroundingLocations.Y += 1f;
                if (Game1.currentLocation.terrainFeatures.ContainsKey(surroundingLocations) && farm.terrainFeatures[surroundingLocations] is Flooring)
                {
                    drawSum = (byte)(drawSum + 4);
                }
                surroundingLocations.Y -= 2f;
                if (farm.terrainFeatures.ContainsKey(surroundingLocations) && farm.terrainFeatures[surroundingLocations] is Flooring)
                {
                    drawSum = (byte)(drawSum + 1);
                }
                sourceRectPosition = Flooring.drawGuide[drawSum];
                spriteBatch.Draw(textureModel.GetTexture(textureVariation), positionOnScreen, new Rectangle(sourceRectPosition % 16 * 16, sourceRectPosition / 16 * 16 + textureOffset, 16, 16), Color.White, 0f, Vector2.Zero, scale * 4f, SpriteEffects.None, layerDepth + positionOnScreen.Y / 20000f);

                return(false);
            }
            return(true);
        }
        internal void Apply(Harmony harmony)
        {
            harmony.Patch(AccessTools.Method(_object, nameof(FishTankFurniture.draw), new[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));

            if (PatchTemplate.IsDGAUsed())
            {
                try
                {
                    if (Type.GetType("DynamicGameAssets.Game.CustomFishTankFurniture, DynamicGameAssets") is Type dgaFishTankFurnitureType && dgaFishTankFurnitureType != null)
                    {
                        harmony.Patch(AccessTools.Method(dgaFishTankFurnitureType, nameof(FishTankFurniture.draw), new[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
                    }
                }
                catch (Exception ex)
                {
                    _monitor.Log($"Failed to patch Dynamic Game Assets in {this.GetType().Name}: AT may not be able to override certain DGA object types!", LogLevel.Warn);
                    _monitor.Log($"Patch for DGA failed in {this.GetType().Name}: {ex}", LogLevel.Trace);
                }
            }
        }
Ejemplo n.º 10
0
        public static byte[] Make(SarcData input, DDSLoadResult dds, PatchTemplate targetPatch, LayoutPatch layout)
        {
            if (layout != null)
            {
                var layoutres = SwitchThemesCommon.PatchLayouts(input, layout.Files);
                if (layoutres == BflytFile.PatchResult.Fail)
                {
                    Window.Alert("One of the target files for the selected layout patch is missing in the SZS, you are probably using an already patched SZS or the wrong layout");
                    return(null);
                }
                else if (layoutres == BflytFile.PatchResult.CorruptedFile)
                {
                    Window.Alert("A layout in this SZS is missing a pane required for the selected layout patch, you are probably using an already patched SZS or the wrong layout");
                    return(null);
                }
            }

            if (SwitchThemesCommon.PatchBntx(input, dds, targetPatch) == BflytFile.PatchResult.Fail)
            {
                Window.Alert(
                    "Can't build this theme: the szs you opened doesn't contain some information needed to patch the bntx," +
                    "without this information it is not possible to rebuild the bntx." +
                    "You should use an original or at least working szs");
                return(null);
            }
            var res = SwitchThemesCommon.PatchBgLayouts(input, targetPatch);

            if (res == BflytFile.PatchResult.Fail)
            {
                Window.Alert("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
                return(null);
            }
            else if (res == BflytFile.PatchResult.CorruptedFile)
            {
                Window.Alert("This file has been already patched with another tool and is not compatible, you should get an unmodified layout.");
                return(null);
            }
            var sarc = SARC.PackN(input);

            return(ManagedYaz0.Compress(sarc.Item2, 1, (int)sarc.Item1));
        }
Ejemplo n.º 11
0
        private static bool DrawInMenuPrefix(Furniture __instance, NetInt ___sourceIndexOffset, SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, StackDrawType drawStackNumber, Color color, bool drawShadow)
        {
            if (Game1.activeClickableMenu is PaintBucketMenu && !PatchTemplate.IsDGAObject(__instance))
            {
                var texture    = Furniture.furnitureTexture;
                var sourceRect = __instance.rotations > 1 ? __instance.sourceRect.Value : __instance.defaultSourceRect.Value;

                if (__instance.modData.ContainsKey("AlternativeTextureName") && AlternativeTextures.textureManager.GetSpecificTextureModel(__instance.modData["AlternativeTextureName"]) is AlternativeTextureModel textureModel && Int32.TryParse(__instance.modData["AlternativeTextureVariation"], out int textureVariation) && textureVariation != -1)
                {
                    texture      = textureModel.GetTexture(textureVariation);
                    sourceRect.X = Math.Max(0, __instance.sourceRect.X - __instance.defaultSourceRect.X);
                    sourceRect.Y = textureModel.GetTextureOffset(textureVariation);
                }

                sourceRect.X += sourceRect.Width * ___sourceIndexOffset.Value;
                spriteBatch.Draw(texture, location + new Vector2(32f, 32f), sourceRect, color * transparency, 0f, new Vector2(sourceRect.Width / 2, sourceRect.Height / 2), 1f * GetScaleSize(sourceRect) * scaleSize, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth);

                return(false);
            }
            return(true);
        }
Ejemplo n.º 12
0
        internal void Apply(Harmony harmony)
        {
            harmony.Patch(AccessTools.Method(_object, nameof(Fence.draw), new[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
            harmony.Patch(AccessTools.Method(_object, nameof(Fence.performObjectDropInAction), new[] { typeof(Item), typeof(bool), typeof(Farmer) }), postfix: new HarmonyMethod(GetType(), nameof(PerformObjectDropInActionPostfix)));

            if (PatchTemplate.IsDGAUsed())
            {
                try
                {
                    if (Type.GetType("DynamicGameAssets.Game.CustomFence, DynamicGameAssets") is Type dgaFenceType && dgaFenceType != null)
                    {
                        // DGA doesn't use either of these methods for CustomFence
                        //harmony.Patch(AccessTools.Method(dgaFenceType, nameof(Fence.draw), new[] { typeof(SpriteBatch), typeof(int), typeof(int), typeof(float) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
                        //harmony.Patch(AccessTools.Method(dgaFenceType, nameof(Fence.performObjectDropInAction), new[] { typeof(Item), typeof(bool), typeof(Farmer) }), postfix: new HarmonyMethod(GetType(), nameof(PerformObjectDropInActionPostfix)));
                    }
                }
                catch (Exception ex)
                {
                    _monitor.Log($"Failed to patch Dynamic Game Assets in {this.GetType().Name}: AT may not be able to override certain DGA object types!", LogLevel.Warn);
                    _monitor.Log($"Patch for DGA failed in {this.GetType().Name}: {ex}", LogLevel.Trace);
                }
            }
        }
Ejemplo n.º 13
0
        internal void Apply(Harmony harmony)
        {
            harmony.Patch(AccessTools.Method(_object, nameof(Crop.draw), new[] { typeof(SpriteBatch), typeof(Vector2), typeof(Color), typeof(float) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
            harmony.Patch(AccessTools.Method(_object, nameof(Crop.drawWithOffset), new[] { typeof(SpriteBatch), typeof(Vector2), typeof(Color), typeof(float), typeof(Vector2) }), prefix: new HarmonyMethod(GetType(), nameof(DrawWithOffsetPrefix)));

            if (PatchTemplate.IsDGAUsed())
            {
                try
                {
                    if (Type.GetType("DynamicGameAssets.Game.CustomCrop, DynamicGameAssets") is Type dgaCropType && dgaCropType != null)
                    {
                        // DGA doesn't use either of these methods for CustomCrop, as Crop.draw and Crop.drawWithOffset aren't virtual (i.e. not overridable)
                        //harmony.Patch(AccessTools.Method(dgaCropType, nameof(Crop.draw), new[] { typeof(SpriteBatch), typeof(Vector2), typeof(Color), typeof(float) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
                        //harmony.Patch(AccessTools.Method(dgaCropType, nameof(Crop.drawWithOffset), new[] { typeof(SpriteBatch), typeof(Vector2), typeof(Color), typeof(float), typeof(Vector2) }), prefix: new HarmonyMethod(GetType(), nameof(DrawWithOffsetPrefix)));
                    }
                }
                catch (Exception ex)
                {
                    _monitor.Log($"Failed to patch Dynamic Game Assets in {this.GetType().Name}: AT may not be able to override certain DGA object types!", LogLevel.Warn);
                    _monitor.Log($"Patch for DGA failed in {this.GetType().Name}: {ex}", LogLevel.Trace);
                }
            }
        }
Ejemplo n.º 14
0
        internal void Apply(Harmony harmony)
        {
            harmony.Patch(AccessTools.Method(_object, nameof(FruitTree.draw), new[] { typeof(SpriteBatch), typeof(Vector2) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
            harmony.Patch(AccessTools.Method(_object, nameof(FruitTree.seasonUpdate), new[] { typeof(bool) }), postfix: new HarmonyMethod(GetType(), nameof(SeasonUpdatePostfix)));
            harmony.Patch(AccessTools.Constructor(typeof(FruitTree), new[] { typeof(int) }), postfix: new HarmonyMethod(GetType(), nameof(FruitTreePostfix)));
            harmony.Patch(AccessTools.Constructor(typeof(FruitTree), new[] { typeof(int), typeof(int) }), postfix: new HarmonyMethod(GetType(), nameof(FruitTreePostfix)));

            if (PatchTemplate.IsDGAUsed())
            {
                try
                {
                    if (Type.GetType("DynamicGameAssets.Game.CustomFruitTree, DynamicGameAssets") is Type dgaCropType && dgaCropType != null)
                    {
                        harmony.Patch(AccessTools.Method(dgaCropType, nameof(FruitTree.draw), new[] { typeof(SpriteBatch), typeof(Vector2) }), prefix: new HarmonyMethod(GetType(), nameof(DrawPrefix)));
                        harmony.Patch(AccessTools.Method(dgaCropType, nameof(FruitTree.seasonUpdate), new[] { typeof(bool) }), postfix: new HarmonyMethod(GetType(), nameof(SeasonUpdatePostfix)));
                    }
                }
                catch (Exception ex)
                {
                    _monitor.Log($"Failed to patch Dynamic Game Assets in {this.GetType().Name}: AT may not be able to override certain DGA object types!", LogLevel.Warn);
                    _monitor.Log($"Patch for DGA failed in {this.GetType().Name}: {ex}", LogLevel.Trace);
                }
            }
        }
Ejemplo n.º 15
0
        public Form1()
        {
            MaterialSkin.MaterialSkinManager.Instance.Theme = MaterialSkin.MaterialSkinManager.Themes.DARK;
            InitializeComponent();

            Advanced = Properties.Settings.Default.Adv;
            if (Advanced)
            {
                EnableAdvanced();
            }
            else
            {
                DisableAdvanced();
            }

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            HomeMenuPartBox.Items.AddRange(HomeMenuParts.Keys.ToArray());
            HomeMenuPartBox.SelectedIndex = 0;
            HomeMenuPartBox_SelectedIndexChanged(null, null);

            HomeAppletIcoButtonsInit();
        }
Ejemplo n.º 16
0
        internal static void PlacementActionPostfix(Object __instance, bool __result, GameLocation location, int x, int y, Farmer who = null)
        {
            if (!__result)
            {
                return;
            }

            // Used for most objects, except for those whom are converted upon placement (such as Fences)
            var placedObject = PatchTemplate.GetObjectAt(location, x, y);

            if (placedObject is null)
            {
                var terrainFeature = GetTerrainFeatureAt(location, x, y);
                if (terrainFeature is Flooring flooring)
                {
                    flooring.modData["AlternativeTextureSheetId"] = __instance.ParentSheetIndex.ToString();

                    var flooringName       = $"{AlternativeTextureModel.TextureType.Flooring}_{GetFlooringName(flooring)}";
                    var flooringSeasonName = $"{flooringName}_{Game1.currentSeason}";
                    if (AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(flooringName) && AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(flooringSeasonName))
                    {
                        var result = Game1.random.Next(2) > 0 ? AssignModData(flooring, flooringSeasonName, true) : AssignModData(flooring, flooringName, false);
                        return;
                    }
                    else
                    {
                        if (AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(flooringName))
                        {
                            AssignModData(flooring, flooringName, false);
                            return;
                        }

                        if (AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(flooringSeasonName))
                        {
                            AssignModData(flooring, flooringSeasonName, true);
                            return;
                        }
                    }

                    AssignDefaultModData(flooring, flooringSeasonName, true);
                }
                return;
            }

            var modelType          = placedObject is Furniture ? AlternativeTextureModel.TextureType.Furniture : AlternativeTextureModel.TextureType.Craftable;
            var instanceName       = $"{modelType}_{GetObjectName(placedObject)}";
            var instanceSeasonName = $"{instanceName}_{Game1.currentSeason}";

            if (AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(instanceName) && AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(instanceSeasonName))
            {
                var result = Game1.random.Next(2) > 0 ? AssignModData(placedObject, instanceSeasonName, true, placedObject.bigCraftable) : AssignModData(placedObject, instanceName, false, placedObject.bigCraftable);
                return;
            }
            else
            {
                if (AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(instanceName))
                {
                    AssignModData(placedObject, instanceName, false, placedObject.bigCraftable);
                    return;
                }

                if (AlternativeTextures.textureManager.DoesObjectHaveAlternativeTexture(instanceSeasonName))
                {
                    AssignModData(placedObject, instanceSeasonName, true, placedObject.bigCraftable);
                    return;
                }
            }

            AssignDefaultModData(placedObject, instanceSeasonName, true, placedObject.bigCraftable);
        }