{"id":18886853,"url":"https://github.com/shadowevil/pak-editor","last_synced_at":"2025-06-10T08:32:49.053Z","repository":{"id":156628432,"uuid":"331850783","full_name":"shadowevil/PAK-Editor","owner":"shadowevil","description":"A program to see a collection of images with rectangles designed to work with games to easily grab images in a bigger sprite.","archived":false,"fork":false,"pushed_at":"2021-01-24T20:01:39.000Z","size":556,"stargazers_count":2,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-24T01:42:08.012Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shadowevil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-22T05:56:01.000Z","updated_at":"2025-03-20T23:37:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"eb053494-471a-4239-a42b-1fe407237989","html_url":"https://github.com/shadowevil/PAK-Editor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadowevil%2FPAK-Editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadowevil%2FPAK-Editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadowevil%2FPAK-Editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadowevil%2FPAK-Editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shadowevil","download_url":"https://codeload.github.com/shadowevil/PAK-Editor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadowevil%2FPAK-Editor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259037941,"owners_count":22796523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T07:31:17.733Z","updated_at":"2025-06-10T08:32:49.009Z","avatar_url":"https://github.com/shadowevil.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PAK-Editor\n\nHow to read the data into a XNA program\n\n        private static byte[] DecryptPAKFile(byte[] buffer)\n        {\n            string str = Encoding.ASCII.GetString(buffer);\n            return Convert.FromBase64String(str);\n        }\n\n        public static MapTiles.Tiles LoadMapTiles(string FileLocation, GraphicsDevice graphics)\n        {\n            MapTiles.Tiles _mapTiles = new MapTiles.Tiles();\n            _mapTiles.TileTexture = new Texture2D[2000];\n            _mapTiles.TileBmp = new Bitmap[2000];\n            _mapTiles.tileBounds = new Microsoft.Xna.Framework.Rectangle[2000];\n\n            using (MemoryStream mS = new MemoryStream(DecryptPAKFile(File.ReadAllBytes(FileLocation))))\n            {\n                int RectDataLength = 0;\n                int ImageSize = 0;\n                int currentRead = 0;\n\n                int CurrentSprite = 0;\n                while (mS.Position \u003c mS.Length)\n                {\n                    byte[] _nMS = new byte[(mS.ToArray().Length - currentRead)];\n                    Array.Copy(mS.ToArray(), currentRead, _nMS, 0, _nMS.Length);\n\n                    string _byteString = Encoding.ASCII.GetString(_nMS);\n\n                    bool isPAK = _byteString.Substring(0, 5) == \"\u003cPAK\u003e\" ? true : false;\n                    if (isPAK)\n                    {\n                        _byteString = _byteString.Substring(5, _byteString.Length - 5);\n                    }\n\n                    RectDataLength = Encoding.ASCII.GetByteCount(_byteString.Substring(0, _byteString.IndexOf('?')));\n                    string rectBuffer = _byteString.Substring(0, _byteString.IndexOf('?'));\n                    ImageSize = Convert.ToInt32(rectBuffer.Split('~').ElementAt(rectBuffer.Split('~').Count() - 2));\n\n                    byte[] ImageBuff = new byte[ImageSize];\n                    Array.Copy(_nMS, RectDataLength + 5, ImageBuff, 0, ImageSize);\n\n                    currentRead += RectDataLength + ImageSize + 5;\n                    mS.Position = currentRead;\n                    if (CurrentSprite == 0)\n                    {\n                        int iter = 0;\n                        foreach (string s in rectBuffer.Split('~'))\n                        {\n                            string[] rectData = s.Split('|');\n                            if (rectData.Count() == 1) break;\n\n                            _mapTiles.tileBounds[iter] = new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(rectData[0]), Convert.ToInt32(rectData[1]),\n                                Convert.ToInt32(rectData[2]), Convert.ToInt32(rectData[3]));\n                            _mapTiles.TileBmp[iter] = CropBitmapSource(new Bitmap(new MemoryStream(ImageBuff)), _mapTiles.tileBounds[iter]);\n                            using (MemoryStream m = new MemoryStream(GetBitmapMemoryStream(_mapTiles.TileBmp[iter])))\n                            {\n                                _mapTiles.TileTexture[iter] = new Texture2D(graphics, _mapTiles.tileBounds[iter].Width, _mapTiles.tileBounds[iter].Height);\n                                _mapTiles.TileTexture[iter] = Texture2D.FromStream(graphics, m);\n                            }\n                            iter++;\n                        }\n                        break;\n                    }\n                    CurrentSprite++;\n                }\n            }\n            return _mapTiles;\n        }\n\n        public static Sprite.SprEntity LoadEntitySprite(Sprite.SprEntity curSpr, string FileLocation, int Sprite, int Image, GraphicsDevice graphics)\n        {\n            Sprite.SprEntity _sprite = curSpr;\n\n            using (MemoryStream mS = new MemoryStream(DecryptPAKFile(File.ReadAllBytes(FileLocation))))\n            {\n                int RectDataLength = 0;\n                int ImageSize = 0;\n                int currentRead = 0;\n\n                int CurrentSprite = 0;\n                while (mS.Position \u003c mS.Length)\n                {\n                    byte[] _nMS = new byte[(mS.ToArray().Length - currentRead)];\n                    Array.Copy(mS.ToArray(), currentRead, _nMS, 0, _nMS.Length);\n\n                    string _byteString = Encoding.ASCII.GetString(_nMS);\n\n                    bool isPAK = _byteString.Substring(0, 5) == \"\u003cPAK\u003e\" ? true : false;\n                    if (isPAK)\n                    {\n                        _byteString = _byteString.Substring(5, _byteString.Length - 5);\n                    }\n\n                    RectDataLength = Encoding.ASCII.GetByteCount(_byteString.Substring(0, _byteString.IndexOf('?')));\n                    string rectBuffer = _byteString.Substring(0, _byteString.IndexOf('?'));\n                    ImageSize = Convert.ToInt32(rectBuffer.Split('~').ElementAt(rectBuffer.Split('~').Count() - 2));\n\n                    byte[] ImageBuff = new byte[ImageSize];\n                    Array.Copy(_nMS, RectDataLength + 5, ImageBuff, 0, ImageSize);\n\n                    currentRead += RectDataLength + ImageSize + 5;\n                    mS.Position = currentRead;\n                    if (CurrentSprite == Sprite)\n                    {\n                        string[] rectData = rectBuffer.Split('~')[Image].Split('|');\n\n                        _sprite.spriteBounds[Image] = new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(rectData[0]), Convert.ToInt32(rectData[1]),\n                            Convert.ToInt32(rectData[2]), Convert.ToInt32(rectData[3]));\n                        if (rectData.Length \u003c= 4) _sprite.xOffset[Image] = 0;\n                         else _sprite.xOffset[Image] = Convert.ToInt32(rectData[4]);\n                        _sprite.spriteBmp[Image] = CropBitmapSource(new Bitmap(new MemoryStream(ImageBuff)), _sprite.spriteBounds[Image]);\n                        using (MemoryStream m = new MemoryStream(GetBitmapMemoryStream(_sprite.spriteBmp[Image])))\n                        {\n                            _sprite.Sprite[Image] = new Texture2D(graphics, _sprite.spriteBounds[Image].Width, _sprite.spriteBounds[Image].Height);\n                            _sprite.Sprite[Image] = Texture2D.FromStream(graphics, m);\n                        }\n                        break;\n                    }\n                    CurrentSprite++;\n                }\n            }\n\n            return _sprite;\n        }\n\n        public static Sprite.Spr LoadSprite(string FileLocation, int Sprite, int Image, GraphicsDevice graphics)\n        {\n            Sprite.Spr _sprite = new Sprite.Spr();\n\n            using (MemoryStream mS = new MemoryStream(DecryptPAKFile(File.ReadAllBytes(FileLocation))))\n            {\n                int RectDataLength = 0;\n                int ImageSize = 0;\n                int currentRead = 0;\n\n                int CurrentSprite = 0;\n                while (mS.Position \u003c mS.Length)\n                {\n                    byte[] _nMS = new byte[(mS.ToArray().Length - currentRead)];\n                    Array.Copy(mS.ToArray(), currentRead, _nMS, 0, _nMS.Length);\n\n                    string _byteString = Encoding.ASCII.GetString(_nMS);\n\n                    bool isPAK = _byteString.Substring(0, 5) == \"\u003cPAK\u003e\" ? true : false;\n                    if (isPAK)\n                    {\n                        _byteString = _byteString.Substring(5, _byteString.Length - 5);\n                    }\n\n                    RectDataLength = Encoding.ASCII.GetByteCount(_byteString.Substring(0, _byteString.IndexOf('?')));\n                    string rectBuffer = _byteString.Substring(0, _byteString.IndexOf('?'));\n                    ImageSize = Convert.ToInt32(rectBuffer.Split('~').ElementAt(rectBuffer.Split('~').Count() - 2));\n\n                    byte[] ImageBuff = new byte[ImageSize];\n                    Array.Copy(_nMS, RectDataLength + 5, ImageBuff, 0, ImageSize);\n\n                    currentRead += RectDataLength + ImageSize + 5;\n                    mS.Position = currentRead;\n                    if (CurrentSprite == Sprite)\n                    {\n                        string[] rectData = rectBuffer.Split('~')[Image].Split('|');\n\n                        _sprite.spriteBounds = new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(rectData[0]), Convert.ToInt32(rectData[1]),\n                            Convert.ToInt32(rectData[2]), Convert.ToInt32(rectData[3]));\n                        _sprite.spriteBmp = CropBitmapSource(new Bitmap(new MemoryStream(ImageBuff)), _sprite.spriteBounds);\n                        using (MemoryStream m = new MemoryStream(GetBitmapMemoryStream(_sprite.spriteBmp)))\n                        {\n                            _sprite.Sprite = new Texture2D(graphics, _sprite.spriteBounds.Width, _sprite.spriteBounds.Height);\n                            _sprite.Sprite = Texture2D.FromStream(graphics, m);\n                        }\n                        break;\n                    }\n                    CurrentSprite++;\n                }\n            }\n\n            return _sprite;\n        }\n\n        public static byte[] GetBitmapMemoryStream(Bitmap bmp)\n        {\n            using (MemoryStream mS = new MemoryStream())\n            {\n                bmp.Save(mS, System.Drawing.Imaging.ImageFormat.Png);\n                return mS.ToArray();\n            }\n        }\n\n        private static Bitmap CropBitmapSource(Bitmap bmp, Microsoft.Xna.Framework.Rectangle srcRectangle)\n        {\n            Rectangle r = new Rectangle(srcRectangle.X, srcRectangle.Y, srcRectangle.Width, srcRectangle.Height);\n            FastImageCroper fic = new FastImageCroper(bmp);\n            Bitmap _bmp = fic.Crop(r);\n            fic.Dispose();\n            return _bmp;\n        }\n    }\n\n    internal unsafe sealed class FastImageCroper : IDisposable\n    {\n        private readonly Bitmap _srcImg;\n        private readonly BitmapData _srcImgBitmapData;\n        private readonly int _bpp;\n        private readonly byte* _srtPrt;\n\n        public FastImageCroper(Bitmap srcImg)\n        {\n            _srcImg = srcImg;\n            _srcImgBitmapData = srcImg.LockBits(new Rectangle(0, 0, srcImg.Width, srcImg.Height), ImageLockMode.ReadOnly, srcImg.PixelFormat);\n            _bpp = _srcImgBitmapData.Stride / _srcImgBitmapData.Width; // == 4\n            _srtPrt = (byte*)_srcImgBitmapData.Scan0.ToPointer();\n        }\n\n        public Bitmap Crop(Rectangle rectangle)\n        {\n            Bitmap dstImg = new Bitmap(rectangle.Width, rectangle.Height, _srcImg.PixelFormat);\n            BitmapData dstImgBitmapData = dstImg.LockBits(new Rectangle(0, 0, dstImg.Width, dstImg.Height), ImageLockMode.WriteOnly, dstImg.PixelFormat);\n            byte* dstPrt = (byte*)dstImgBitmapData.Scan0.ToPointer();\n            byte* srcPrt = _srtPrt + rectangle.Y * _srcImgBitmapData.Stride + rectangle.X * _bpp;\n\n            for (int y = 0; y \u003c rectangle.Height; y++)\n            {\n                int srcIndex = y * _srcImgBitmapData.Stride;\n                int croppedIndex = y * dstImgBitmapData.Stride;\n                memcpy(dstPrt + croppedIndex, srcPrt + srcIndex, dstImgBitmapData.Stride);\n            }\n\n            dstImg.UnlockBits(dstImgBitmapData);\n            return dstImg;\n        }\n\n\n        public void Dispose()\n        {\n            _srcImg.UnlockBits(_srcImgBitmapData);\n        }\n\n\n        [DllImport(\"msvcrt.dll\", CallingConvention = CallingConvention.Cdecl)]\n        private static extern int memcpy(byte* dest, byte* src, long count);\n    }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadowevil%2Fpak-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshadowevil%2Fpak-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadowevil%2Fpak-editor/lists"}