コード例 #1
0
ファイル: Program.cs プロジェクト: Settlers4Modding/S4GFX
        private static ImageData[] LoadFromBitmap(string path, int i, GfxFileReader file)
        {
            GfxImage image = file.GetImage(i);

            bool   saveByIndex = file.HasDIL;
            string basePath    = $"export/{path}/{(saveByIndex ? $"{image.jobIndex}/" : "")}";

            List <ImageData> imgs = new List <ImageData>();

            foreach (string filePath in Directory.GetFiles(basePath))
            {
                Bitmap map = new Bitmap(filePath);

                ImageData data = new ImageData(map.Height, map.Width);
                image.Width  = map.Width;
                image.Height = map.Height;

                data.data = new Byte[map.Height * map.Width * 4];

                int index = 0;
                for (int y = 0; y < map.Height; y++)
                {
                    for (int x = 0; x < map.Width; x++)
                    {
                        Color c = map.GetPixel(x, y);

                        data.data[index + 0] = c.R;
                        data.data[index + 1] = c.G;
                        data.data[index + 2] = c.B;
                        data.data[index + 3] = 255;

                        index += 4;
                    }
                }

                imgs.Add(data);
            }
            return(imgs.ToArray());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Settlers4Modding/S4GFX
        static void Main(string[] args)
        {
            Console.WriteLine("=Settler IV image exporter/importer=========================");
            Console.WriteLine("Place this exe in the Settler IV folder!");
            Console.WriteLine("Exported images will be saved to the \"export/gfx/%GROUP%/\" folder.");
            Console.WriteLine("Exported sounds will be saved to the \"export/snd/\" folder. Run with --snd to extract sound files.");
            Console.WriteLine("============================================================");

            if (args.Contains("--snd"))
            {             // --snd argument has been passed to the exe
                sndFile = LoadSnd("Snd/0");
                if (sndFile == null)
                {
                    Console.WriteLine("Error: Cannot export sounds because 0.sil or 0.snd is not available.");
                }
                else
                {
                    SaveAllSounds("Snd/0");
                }
            }

            Console.WriteLine("");
            Console.WriteLine("Export all: (1), Export one group: (2), Export one single image: (3), Import one image collection (4)");
            Console.WriteLine("");

            string choice = Console.ReadLine();

            switch (choice)
            {
            case "1":
                AskRemoveShadowsAndAlpha();

                //Parallel.For(0, 45, (i) => {
                //	var gfx = Load("GFX/" + i);
                //	if (gfx == null)
                //		return;

                //	SaveAllBitmaps("GFX/" + i, gfx);
                //});
                for (int i = 0; i < 45; i++)
                {
                    Load("GFX/" + i);
                    SaveAllBitmaps("GFX/" + i);
                }
                break;

            default:
            case "2": {
REPEAT:
                Console.WriteLine("What group would you like to export the images from?");
                string choiceGroup = Console.ReadLine();

                string path = "GFX/" + choiceGroup;
                if (!File.Exists(path + ".gfx"))
                {
                    Console.WriteLine($"Group {path} does not exist!");
                    goto REPEAT;
                }

                AskRemoveShadowsAndAlpha();
                Load(path);
                SaveAllBitmaps(path);
            }
            break;

            case "3": {
REPEAT_SINGLE_GROUP:
                Console.WriteLine("What group would you like to export an image from?");
                string choiceGroup = Console.ReadLine();

                string path = "GFX/" + choiceGroup;
                if (!File.Exists(path + ".gfx"))
                {
                    Console.WriteLine($"Group {path} does not exist!");
                    goto REPEAT_SINGLE_GROUP;
                }
                Load(path);

REPEAT_SINGLE_IMAGE:
                Console.WriteLine($"What number has the image you want to export? This group contains: {gfxFile.GetImageCount()} images");
                string choiceImage = Console.ReadLine();

                int image = int.Parse(choiceImage);
                if (image > gfxFile.GetImageCount())
                {
                    Console.WriteLine($"There is no image nr. {image}!");
                    goto REPEAT_SINGLE_IMAGE;
                }

                AskRemoveShadowsAndAlpha();
                SaveToBitmap(path, image, gfxFile);
            }
            break;

            case "4": {                     //IMPORT
                Console.WriteLine("=IMPORT=====================================================");
                Console.WriteLine("To import files, save them to the export/gfx/%GROUP%/%id%/ folder.");
                Console.WriteLine("The image collection has to be complete for the import to work");
                Console.WriteLine("To see what image has what index, export the group with (1-3) in the main menu.");
                Console.WriteLine("Example would be: export/gfx/14/1 -> replaces the woodcutter images of the trojan");
                Console.WriteLine("");
                Console.WriteLine("The finished gfx (and, but not neccesary, gil) file will be saved next to this programm.");
                Console.WriteLine("Replace the original files in the gfx folder with the newly generated ones");
                Console.WriteLine("============================================================");
                Console.WriteLine("");

REPEAT_SINGLE_GROUP:
                Console.WriteLine("What group would you like to import a file into?");
                string choiceGroup = Console.ReadLine();

                string path = "GFX/" + choiceGroup;
                if (!File.Exists(path + ".gfx"))
                {
                    Console.WriteLine($"Group {path} does not exist!");
                    goto REPEAT_SINGLE_GROUP;
                }
                Load(path);

REPEAT_SINGLE_IMAGE:
                Console.WriteLine($"What number has the first image in the collection you want to import into the game files? This group contains: {gfxFile.GetImageCount()} images");
                string choiceImage = Console.ReadLine();

                int image = int.Parse(choiceImage);
                if (image > gfxFile.GetImageCount())
                {
                    Console.WriteLine($"There is no image nr. {image}!");
                    goto REPEAT_SINGLE_IMAGE;
                }

                //AskRemoveShadowsAndAlpha();
                //SaveToBitmap(path, image, gfxFile);

                ImageData[] data = LoadFromBitmap(path, image, gfxFile);
                gfxFile.ChangeImageData(choiceGroup, image, data);
            }
            break;

            case "5": {                     //Secret test key
REPEAT_SINGLE_GROUP:
                Console.WriteLine("What group would you like to export an image from?");
                string choiceGroup = Console.ReadLine();

                string path = "GFX/" + choiceGroup;
                if (!File.Exists(path + ".gfx"))
                {
                    Console.WriteLine($"Group {path} does not exist!");
                    goto REPEAT_SINGLE_GROUP;
                }
                Load(path);

                gfxFile.RemoveDILDependence();

REPEAT_SINGLE_IMAGE:
                Console.WriteLine($"What number has the image you want to export? This group contains: {gfxFile.GetImageCount()} images");
                string choiceImage = Console.ReadLine();

                int image = int.Parse(choiceImage);
                if (image > gfxFile.GetImageCount())
                {
                    Console.WriteLine($"There is no image nr. {image}!");
                    goto REPEAT_SINGLE_IMAGE;
                }

                AskRemoveShadowsAndAlpha();
                SaveToBitmap(path, image, gfxFile);
            }
            break;
            }

            Console.WriteLine("");
            Console.WriteLine("======");
            Console.WriteLine("FINISHED LOADING");
            Console.WriteLine("You may close this app now...");
            Console.WriteLine("======");

            gfxFile = null;
            GC.Collect();
            Console.ReadKey();
        }