コード例 #1
0
ファイル: Program.cs プロジェクト: Settlers4Modding/S4GFX
        static public SndFileReader LoadSnd(string fileId)
        {
            bool sil = File.Exists(fileId + ".sil");

            if (sil == false)
            {
                return(null);
            }

            bool snd = File.Exists(fileId + ".snd");

            if (!snd)
            {
                return(null);
            }

            var silBinaryReader = new BinaryReader(File.Open(fileId + ".sil", FileMode.Open), Encoding.Default, true);
            var sndBinaryReader = new BinaryReader(File.Open(fileId + ".snd", FileMode.Open), Encoding.Default, true);

            var silReader = new SilFileReader(silBinaryReader);

            sndFile = new SndFileReader(sndBinaryReader, silReader);

            silBinaryReader?.Close();
            sndBinaryReader?.Close();

            return(sndFile);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Settlers4Modding/S4GFX
        private static void SaveAllSounds(string path, SndFileReader file = null)
        {
            Console.WriteLine($"Start saving: " + path);
            file = file ?? sndFile;

            for (int i = 1; i < file.GetSoundCount(); i++)
            {
                try {
                    Directory.CreateDirectory("export/" + path);
                    File.WriteAllBytes($"export/{path}/{i}.wav", file.GetSound(i));
                }catch (Exception e) {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                }
            }

            Console.WriteLine($"Saved: " + path);
        }
コード例 #3
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();
        }