示例#1
0
        public static void replacepalettes(string inputdir, PalFile basepal, int index = 0, List <string> early_config = null)
        {
            bool fromuni = false;

            byte[] PSPAL = File.ReadAllBytes(inputdir);

            string configdir = inputdir + "_cfg.txt";

            PalFile newpal = new PalFile();

            if (determineinput(PSPAL) == 0 || determineinput(PSPAL) == 1)
            {
                newpal = loadpals(PSPAL, determineinput(PSPAL));
            }
            else
            {
                Palette PSPALp = PalMethods.loadpalette(PSPAL);

                Palette ltest = new Palette();
                PSPALp.colors.CopyTo(ltest.colors, 0);

                newpal.Lpals.Add(ltest);
                newpal.Rpals.Add(PSPALp);
            }

            if (early_config.Count > 0)
            {
                Console.WriteLine("list config located for " + inputdir);
                newpal = PalMethods.processpalcfg(newpal, early_config);
            }

            if (File.Exists(configdir))
            {
                Console.WriteLine("config located for " + inputdir);

                List <string> configtextlist = File.ReadAllLines(configdir).ToList();

                //Console.WriteLine(configtextlist.Count);

                newpal = PalMethods.processpalcfg(newpal, configtextlist);
            }

            PalMethods.replacepalette(newpal.Lpals[0], newpal.Rpals[0], basepal, index);
        }
示例#2
0
        public static PalFile processpalcfg(PalFile inpal, List <string> instrlist)
        {
            if (instrlist.Count > 0)
            {
                foreach (string line in instrlist)
                {
                    string processedline = line;
                    string paramstr      = "";
                    string varstr        = "";

                    Match comments = Regex.Match(line, @"\/\/(.*)");

                    processedline = line.Remove(comments.Index, comments.Length);

                    //Console.WriteLine(processedline);

                    Match input = Regex.Match(processedline, @"(^[^=]*)(\=)(.*)");
                    if (input.Success)
                    {
                        paramstr = processedline.Substring(input.Groups[1].Index, input.Groups[1].Length);
                        varstr   = processedline.Substring(input.Groups[3].Index, input.Groups[3].Length);
                    }

                    int.TryParse(varstr, out int varint);
                    byte.TryParse(varstr, out byte varbyte);

                    //Console.WriteLine("parameter "+paramstr);
                    //Console.WriteLine("variable " + varstr);

                    switch (paramstr)
                    {
                    case "flipindex":
                        inpal = flipindex(inpal);
                        break;

                    case "autofixsides":
                        Console.WriteLine("fix sides");
                        inpal = fixpalsides2(varstr, inpal.Lpals[0], inpal.Rpals[0]);
                        break;

                    case "basealpha":
                        inpal = setpal_basealpha(inpal.Lpals[0], inpal.Rpals[0], varbyte);
                        break;

                    case "manualalpha":
                        Console.WriteLine("replacing alpha color");
                        byte[] file = File.ReadAllBytes(varstr);

                        inpal = setpalalpha(inpal.Lpals[0], inpal.Rpals[0], loadpalette(file));

                        break;

                    case "frompalcolor":
                        if (inpal.Lpals.Count >= varint)
                        {
                            //Console.WriteLine("this is good "+inpal.Lpals.Count);
                            PalMethods.replacepalette(inpal.Lpals[varint], inpal.Rpals[varint], inpal, 0);
                        }
                        else
                        {
                            Console.WriteLine("frompalcolor out of bounds (probably not a uni pal input)");
                        }
                        break;

                    case "rbo":
                        Console.WriteLine("reverse byte order config");

                        inpal = reverse_byte_order(inpal.Lpals[0], inpal.Rpals[0]);

                        break;

                    case "test":
                        Console.WriteLine("test success");
                        Console.WriteLine("parameter " + paramstr + " help");
                        Console.WriteLine("variable " + varstr + " help");
                        //System.Environment.Exit(0);
                        //PSPALdir = Path.Combine(workingdir, @args[count + 1]);
                        break;

                    case "merge":
                        Match           merge_var    = Regex.Match(varstr, @"(.+?)(?:,|$)"); //several capture groups for several split vars
                        Regex           match_params = new Regex(@"(.+?)(?:,|$)");
                        MatchCollection strmatches   = match_params.Matches(varstr);

                        Console.WriteLine("matches count " + strmatches.Count + " varstr " + varstr);

                        string color_path = @varstr.Substring(strmatches[0].Groups[1].Index, strmatches[0].Groups[1].Length);
                        //Console.WriteLine("match 1 " + color_path);

                        int.TryParse(varstr.Substring(strmatches[1].Groups[1].Index, strmatches[1].Groups[1].Length), out int copy_from_sindex);
                        //Console.WriteLine("match 2 "+ copy_from_sindex);

                        int.TryParse(varstr.Substring(strmatches[2].Groups[1].Index, strmatches[2].Groups[1].Length), out int length);
                        int.TryParse(varstr.Substring(strmatches[3].Groups[1].Index, strmatches[3].Groups[1].Length), out int copy_to_index);

                        Palette use_palette = loadpalette(File.ReadAllBytes(color_path));

                        inpal.Lpals[0] = merge_pal(inpal.Lpals[0], use_palette, copy_from_sindex, length, copy_to_index);
                        inpal.Rpals[0] = merge_pal(inpal.Rpals[0], use_palette, copy_from_sindex, length, copy_to_index);

                        break;

                    default:
                        Console.WriteLine("unrecognized config variable: " + "'" + paramstr + "'");
                        break;
                    }
                }
            }
            return(inpal);
        }