Пример #1
0
    /// <inheritdoc/>
    public void Dispose()
    {
        GC.SuppressFinalize(this);

        Name         = null;
        TextureEntry = null;
    }
Пример #2
0
        public Bitmap GetTextureFor(UndertaleTexturePageItem texPageItem, string imageName, bool includePadding = false)
        {
            int    exportWidth   = texPageItem.BoundingWidth;  // sprite.Width
            int    exportHeight  = texPageItem.BoundingHeight; // sprite.Height
            Bitmap embeddedImage = GetEmbeddedTexture(texPageItem.TexturePage);

            // Sanity checks.
            if (includePadding && ((texPageItem.TargetWidth > exportWidth) || (texPageItem.TargetHeight > exportHeight)))
            {
                throw new InvalidDataException(imageName + "'s texture is larger than its bounding box!");
            }

            // Create a bitmap representing that part of the texture page.
            Bitmap resultImage = null;

            lock (embeddedImage)
            {
                try
                {
                    resultImage = embeddedImage.Clone(new Rectangle(texPageItem.SourceX, texPageItem.SourceY, texPageItem.SourceWidth, texPageItem.SourceHeight), PixelFormat.DontCare);
                }
                catch (OutOfMemoryException)
                {
                    throw new OutOfMemoryException(imageName + "'s texture is abnormal. 'Source Position/Size' boxes 3 & 4 on texture page may be bigger than the sprite itself or it's set to '0'.");
                }
            }

            // Resize the image, if necessary.
            if ((texPageItem.SourceWidth != texPageItem.TargetWidth) || (texPageItem.SourceHeight != texPageItem.TargetHeight))
            {
                resultImage = ResizeImage(resultImage, texPageItem.TargetWidth, texPageItem.TargetHeight);
            }

            // Put it in the final holder image.
            Bitmap returnImage = resultImage;

            if (includePadding)
            {
                returnImage = new Bitmap(exportWidth, exportHeight);
                Graphics g = Graphics.FromImage(returnImage);
                g.DrawImage(resultImage, new Rectangle(texPageItem.TargetX, texPageItem.TargetY, resultImage.Width, resultImage.Height), new Rectangle(0, 0, resultImage.Width, resultImage.Height), GraphicsUnit.Pixel);
                g.Dispose();
            }

            return(returnImage);
        }
Пример #3
0
        public Bitmap GetTextureFor(UndertaleTexturePageItem texPageItem, string imageName)
        {
            int exportWidth  = texPageItem.BoundingWidth;  // sprite.Width
            int exportHeight = texPageItem.BoundingHeight; // sprite.Height

            Bitmap embeddedImage = null;

            lock (embeddedDictionary)
            {
                if (!embeddedDictionary.ContainsKey(texPageItem.TexturePage))
                {
                    embeddedDictionary[texPageItem.TexturePage] = GetImageFromByteArray(texPageItem.TexturePage.TextureData.TextureBlob);
                }
                embeddedImage = embeddedDictionary[texPageItem.TexturePage];
            }

            // Sanity checks.
            if ((texPageItem.TargetWidth > exportWidth) || (texPageItem.TargetHeight > exportHeight))
            {
                throw new InvalidDataException(imageName + "'s texture is larger than its bounding box!");
            }

            // Create a bitmap representing that part of the texture page.
            Bitmap resultImage = null;

            lock (embeddedImage)
                resultImage = embeddedImage.Clone(new Rectangle(texPageItem.SourceX, texPageItem.SourceY, texPageItem.SourceWidth, texPageItem.SourceHeight), PixelFormat.DontCare);

            // Resize the image, if necessary.
            if ((texPageItem.SourceWidth != texPageItem.TargetWidth) || (texPageItem.SourceHeight != texPageItem.TargetHeight))
            {
                resultImage = ResizeImage(resultImage, texPageItem.TargetWidth, texPageItem.TargetHeight);
            }

            // Put it in the final holder image.
            Bitmap   finalImage = new Bitmap(exportWidth, exportHeight);
            Graphics g          = Graphics.FromImage(finalImage);

            g.DrawImage(resultImage, new Rectangle(texPageItem.TargetX, texPageItem.TargetY, resultImage.Width, resultImage.Height), new Rectangle(0, 0, resultImage.Width, resultImage.Height), GraphicsUnit.Pixel);
            g.Dispose();

            return(finalImage);
        }
Пример #4
0
 public void ExportAsPNG(UndertaleTexturePageItem texPageItem, string FullPath, string imageName = null, bool includePadding = false)
 {
     SaveImageToFile(FullPath, GetTextureFor(texPageItem, imageName != null ? imageName : Path.GetFileNameWithoutExtension(FullPath), includePadding));
 }
Пример #5
0
 /// <inheritdoc />
 public void Unserialize(UndertaleReader reader)
 {
     Name         = reader.ReadUndertaleString();
     TextureEntry = reader.ReadUndertaleObjectPointer <UndertaleTexturePageItem>();
 }
Пример #6
0
        public static void SpeedrunPatches(UndertaleData data)
        {
            UndertaleScript setboi = new UndertaleScript();

            setboi.Name      = data.Strings.MakeString("set_speedrun_category");
            setboi.Code      = new UndertaleCode();
            setboi.Code.Name = data.Strings.MakeString("gml_Script_set_speedrun_category");
            setboi.Code.ReplaceGML(RabbitRunCode.set_speedrun_category, data);
            data.Code.Add(setboi.Code);
            data.Scripts.Add(setboi);

            UndertaleScript sprun = new UndertaleScript();

            sprun.Name = new UndertaleString("menu_speedrun_script");
            data.Strings.Add(sprun.Name);
            sprun.Code = new UndertaleCode();
            data.Code.Add(sprun.Code);
            sprun.Code.Name = new UndertaleString("gml_Script_menu_speedrun_script");
            data.Strings.Add(sprun.Code.Name);
            sprun.Code.ReplaceGML(RabbitRunCode.menu_speedrun_script, data);
            sprun.Code.UpdateAddresses();
            data.Scripts.Add(sprun);

            UndertaleCode ae = data.Code.ByName("gml_Script_setfile");

            ae.AppendGML(RabbitRunCode.gml_Script_setfile, data);
            ae.UpdateAddresses();

            UndertaleCode ee = data.Code.ByName("gml_Object_obj_mainmenus_Create_0");

            ReplaceInGML("GAME\", 1, 8],", "GAME\", 1, 8], [\"SPEEDBUN\", 1, 19], ", ee, data);
            ee.UpdateAddresses();
            ReplaceInGML("i = 0", RabbitRunCode.speedrunMenuInit, ee, data);

            UndertaleCode ie = data.Code.ByName("gml_Script_cKeys_beginstep");

            ie.AppendGML(RabbitRunCode.tasBeginStepInput, data);

            UndertaleCode oe = data.Code.ByName("gml_Object_obj_init_Create_0");

            oe.AppendGML(@"global.playRun = false;
global.watchRun = false;
global.speedrunning = true;
global.inrun = false;
global.onehun = false;//one hundred percent
global.allbun = false;//all cuties
global.anyper = false;//any percent", data);

            UndertaleCode ue = data.Code.ByName("gml_Script_SaveStringToFile");

            ue.ReplaceGML(RabbitRunCode.saveStringFile, data);

            UndertaleSprite mico = data.Sprites.ByName("spr_menuicons");

            UndertaleSprite.TextureEntry te = new UndertaleSprite.TextureEntry();
            UndertaleTexturePageItem     ti = mico.Textures[1].Texture;
            UndertaleTexturePageItem     to = data.Sprites.ByName("spr_antibunidle").Textures[0].Texture;

            te.Texture                = new UndertaleTexturePageItem();
            te.Texture.TargetX        = ti.TargetX;
            te.Texture.TargetY        = ti.TargetY;
            te.Texture.SourceX        = to.SourceX;
            te.Texture.SourceY        = to.SourceY;
            te.Texture.BoundingHeight = ti.BoundingHeight;
            te.Texture.BoundingWidth  = ti.BoundingWidth;
            te.Texture.SourceWidth    = 16;
            te.Texture.TargetWidth    = 16;
            te.Texture.SourceHeight   = 15;
            te.Texture.TargetHeight   = 15;
            te.Texture.TexturePage    = to.TexturePage;
            data.TexturePageItems.Add(te.Texture);
            mico.Textures.Insert(2, te);
        }