Example #1
0
        public static PalFile createpalfile(List <Palette> Lpalin, List <Palette> Rpalin)
        {
            PalFile outpal = new PalFile();

            outpal.Lpals  = Lpalin;
            outpal.Rpals  = Rpalin;
            outpal.palcnt = Lpalin.Count + Rpalin.Count;

            return(outpal);
        }
Example #2
0
        public static PalFile fixpalsides2(string character, Palette lside, Palette rside)
        {
            PalFile fixcol = new PalFile();

            int[] sethcolormapfrom = new int[] { 11, 12, 13, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153 };
            int[] sethcolormapto   = new int[] { 27, 28, 29, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169 };

            int[] hildacolormapfrom = new int[] { 26, 27, 28, 64, 65, 66, 67, 68, 80, 81, 82, 83 };
            int[] hildacolormapto   = new int[] { 42, 43, 44, 70, 71, 72, 73, 74, 85, 86, 87, 88 };

            int[] stmcolormapfrom = new int[] { 11, 12, 13 };
            int[] stmcolormapto   = new int[] { 27, 28, 29 };

            int[] arrayfrom = new int[4];
            int[] arrayto   = new int[4];

            switch (character)
            {
            case "seth":
                arrayfrom = sethcolormapfrom;
                arrayto   = sethcolormapto;
                break;

            case "hilda":
                arrayfrom = hildacolormapfrom;
                arrayto   = hildacolormapto;
                break;

            case "rentaro":
                arrayfrom = stmcolormapfrom;
                arrayto   = stmcolormapto;
                break;

            default:

                break;
            }

            Console.WriteLine("fixing sides for: " + character);

            for (int i = 0; i < arrayfrom.Length; i++)
            {
                Console.WriteLine("fixing sides for loop: " + character);

                rside.colors[arrayfrom[i]] = lside.colors[arrayto[i]];
                rside.colors[arrayto[i]]   = lside.colors[arrayfrom[i]];
            }

            fixcol.Rpals.Add(rside);
            fixcol.Lpals.Add(lside);

            return(fixcol);
        }
Example #3
0
        public static PalFile setpalalpha(Palette lside, Palette rside, Palette alphamap)
        {
            PalFile fixcol = new PalFile();

            for (int i = 0; i < 255; i++)
            {
                lside.colors[i][3] = alphamap.colors[i][0];
                rside.colors[i][3] = alphamap.colors[i][0];
            }

            fixcol.Rpals.Add(rside);
            fixcol.Lpals.Add(lside);

            return(fixcol);
        }
Example #4
0
        public static PalFile setpal_basealpha(Palette lside, Palette rside, byte val)
        {
            PalFile fixcol = new PalFile();

            for (int i = 0; i < 255; i++)
            {
                lside.colors[i][3] = val;
                rside.colors[i][3] = val;
            }

            fixcol.Rpals.Add(rside);
            fixcol.Lpals.Add(lside);

            return(fixcol);
        }
Example #5
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);
        }
Example #6
0
        public static PalFile flipindex(PalFile inpal)
        {
            foreach (Palette pal in inpal.Lpals)
            {
                for (int i = 0; i < inpal.Lpals.Count; i++)
                {
                    inpal.Lpals[i].colors.Reverse();
                }
            }

            foreach (Palette pal in inpal.Rpals)
            {
                for (int i = 0; i < inpal.Rpals.Count; i++)
                {
                    inpal.Rpals[i].colors.Reverse();
                }
            }

            return(inpal);
        }
Example #7
0
        public static PalFile reverse_byte_order(Palette lside, Palette rside)
        {
            PalFile fixcol = new PalFile();

            for (int i = 0; i < lside.colors.Length; i++)
            {
                byte[] workingpal = new byte[] { 255, 0, 0, 0 };
                Array.Copy(lside.colors[i], 0, workingpal, 1, 3);

                lside.colors[i] = workingpal.Reverse().ToArray();

                byte[] workingpal2 = new byte[] { 255, 0, 0, 0 };
                Array.Copy(rside.colors[i], 0, workingpal2, 1, 3);

                rside.colors[i] = workingpal.Reverse().ToArray();
            }

            fixcol.Rpals.Add(rside);
            fixcol.Lpals.Add(lside);

            return(fixcol);
        }
Example #8
0
        public static void replacepalette(Palette left, Palette right, PalFile file, int index)
        {
            Console.WriteLine("replace index " + index + " cnt " + file.Lpals.Count);
            if (file.Lpals.Count > index && file.Lpals.Count > 0)
            {
                file.Lpals.RemoveAt(index);
                file.Lpals.Insert(index, left);
            }
            else
            {
                while (file.Lpals.Count < index)
                {
                    file.Lpals.Add(file.Lpals[0]);
                }

                file.Lpals.Insert(index, left);

                //Console.WriteLine(file.Lpals.Count);
            }

            if (file.Rpals.Count > index && file.Rpals.Count > 0)
            {
                file.Rpals.RemoveAt(index);
                file.Rpals.Insert(index, right);
            }
            else
            {
                while (file.Rpals.Count < index)
                {
                    file.Rpals.Add(file.Rpals[0]);
                }

                file.Rpals.Insert(index, right);

                //Console.WriteLine(file.Rpals.Count);
            }
        }
Example #9
0
        public static void Main(string[] args)
        {
            string workingdir = Directory.GetCurrentDirectory();
            string mode       = "unist";
            bool   editsave   = false;

            /*
             * string PSPALdir = Path.Combine(workingdir, none);
             * string UNIPALdir = Path.Combine(workingdir, none);
             * string outputdir = Path.Combine(workingdir, none);
             * string txtlistdir = Path.Combine(workingdir, none);
             */

            string PSPALdir  = "none";
            string UNIPALdir = "none";
            string outputdir = "none";

            string palnumstring     = "0";
            string alphacolorstring = "255";

            List <string> outputdirs = new List <string>();

            byte alphacolor = Convert.ToByte(alphacolorstring);

            int palnum = Convert.ToInt32(palnumstring);

            int output_type = 0;
            int manual_type = -1;


            List <string> pspaldirtextlist = new List <string>();

            if (args.Length > 0)
            {
                int count = 0;
                foreach (string arg in args)
                {
                    //Console.WriteLine(args.Length+" "+arg);
                    switch (arg)
                    {
                    case "-input":
                        PSPALdir = @args[count + 1];
                        break;

                    case "-basepal":
                        UNIPALdir = @args[count + 1];
                        break;

                    case "-color":
                        palnumstring = args[count + 1];
                        break;

                    case "-output":
                        outputdir = @args[count + 1];

                        outputdirs.Add(outputdir);

                        break;

                    case "-mode":
                        mode = args[count + 1];
                        break;

                    case "-sides":
                        break;

                    case "-editsave":
                        editsave = true;

                        Console.WriteLine("save edit");
                        break;

                    case "-basealpha":
                        alphacolor = Convert.ToByte(args[count + 1]);
                        break;

                    case "-manual_type":
                        manual_type = Convert.ToByte(args[count + 1]);
                        break;

                    case "-output_type":
                        output_type = Convert.ToByte(args[count + 1]);
                        break;
                    }
                    count++;
                    //Console.WriteLine(count);
                }
                //System.Environment.Exit(0);
            }
            else
            {
                Console.WriteLine("Syntax: -input MS.Pal|Pal List.txt|Pal.png|, -basepal UNI.Pal, -color Pal to replace, -output output file");
                return;
            }

            if (editsave)
            {
                if (File.Exists(PSPALdir))
                {
                    Console.WriteLine("writing save");
                    PalMethods.createfile(outputdir, PalMethods.editsave(File.ReadAllBytes(PSPALdir)));
                    return;
                }
                else
                {
                    Console.WriteLine("save file not found");
                    return;
                }
            }

            byte[] basepalbytes = new byte[86032];

            int type = 0;

            string PSPALfn = Path.GetFileName(PSPALdir);

            PalFile basepal = new PalFile();
            Palette inpal   = new Palette();

            if (File.Exists(UNIPALdir))
            {
                basepalbytes = File.ReadAllBytes(UNIPALdir);
                type         = (manual_type != -1)? manual_type : PalMethods.determineinput(basepalbytes);
                switch (type)
                {
                case 0:     //st mode
                    break;

                case 1:     //el mode
                    break;

                case 2:     //png (useless here)
                    break;

                case 3:     //text list
                    break;

                case 4:     //nitro+
                    break;

                case 10:
                    break;
                }
                basepal = PalMethods.loadpals(basepalbytes, type);
            }
            byte[] PSPAL = new byte[1024];

            if (File.Exists(PSPALdir))
            {
                //inpal = PalMethods.loadpalette(PSPAL, 100);


                if (PSPALfn.EndsWith(".txt"))
                {
                    pspaldirtextlist = File.ReadAllLines(PSPALdir).ToList();
                    Console.WriteLine("a text file " + pspaldirtextlist.Count);
                    for (int i = 0; i < pspaldirtextlist.Count; i++)
                    {
                        if (pspaldirtextlist[i] != "")
                        {
                            List <string> config_list = new List <string>();

                            Regex match_params = new Regex(@"\[(.*?)\]");

                            MatchCollection line_parameters = match_params.Matches(pspaldirtextlist[i]);

                            foreach (Match match in line_parameters)
                            {
                                config_list.Add(pspaldirtextlist[i].Substring(match.Index + 1, match.Length - 2));
                            }

                            //Console.WriteLine("early config match count "+line_parameters.Count+" ind "+ line_parameters[0].Index+" len "+ line_parameters[0].Length);

                            string use_str = (line_parameters.Count > 0)? pspaldirtextlist[i].Substring(0, line_parameters[0].Index) : pspaldirtextlist[i];
                            if (File.Exists(use_str) == false)
                            {
                                string mess = "file not found";

                                Console.WriteLine("skipped " + use_str + " num " + i + " " + " because " + mess);

                                if (i > basepal.Lpals.Count)
                                {
                                    Palette newpal = new Palette();

                                    basepal.Lpals.Add(newpal);
                                }

                                if (i > basepal.Rpals.Count)
                                {
                                    Palette newpal = new Palette();

                                    basepal.Rpals.Add(newpal);
                                }
                            }
                            else
                            {
                                Console.WriteLine("cycling lines " + i + " " + use_str);

                                PalMethods.replacepalettes(Path.GetFullPath(use_str), basepal, i, config_list);
                                //Console.WriteLine("palrep "+i);
                                //Console.WriteLine(basepal.palcnt + " " + basepal.Lpals.Count + " " + basepal.Rpals.Count);
                            }
                        }
                        else
                        {
                            Console.WriteLine("propogating empty line " + i + " " + pspaldirtextlist[i]);
                            if (i > basepal.Lpals.Count)
                            {
                                Palette newpal = new Palette();

                                basepal.Lpals.Add(newpal);
                            }

                            if (i > basepal.Rpals.Count)
                            {
                                Palette newpal = new Palette();

                                basepal.Rpals.Add(newpal);
                            }
                        }
                    }
                }
                else
                {
                    PalMethods.replacepalettes(PSPALdir, basepal);

                    //PalMethods.replacepalette(txtinpal, txtinpal, basepal, i);
                }

                foreach (string path in outputdirs)
                {
                    PalMethods.createfile(Path.Combine(workingdir, path), basepal.getdata(type, (pal_game)output_type));
                }
            }
        }
Example #10
0
        public static PalFile loadpals(byte[] sourcearray, int type = 0)
        {
            bool two_sides = true;
            int  col_len   = 1024; //length of a 256 color table
            int  offset    = 0;

            switch (type)
            {
            case 0:
                offset = 16;     //st mode
                break;

            case 1:
                offset = 4;     //el mode
                break;

            case 2:
                col_len = 768;
                break;

            case 100:     //melty mode
                offset    = 4;
                two_sides = false;
                break;

            case 3:     //text list
                break;

            case 4:     //nitro+
                offset = 16;
                break;

            case 10:
                //headeroff = 0;
                break;
            }

            int numpal = (sourcearray.Length - offset) / 1024;

            Console.WriteLine("num total " + numpal);

            PalFile retpal = new PalFile();

            retpal.palcnt = numpal;

            List <Palette> LEFTpalettelist  = new List <Palette>();
            List <Palette> RIGHTpalettelist = new List <Palette>();

            for (int i = offset, p = 0; p < numpal; i += 1024, p++)
            {
                Console.WriteLine("num total " + numpal + " at " + i + " num " + p);
                Palette workingcol = loadpalette(sourcearray, 0, i);
                if (two_sides)
                {
                    if (p >= numpal / 2)
                    {
                        RIGHTpalettelist.Add(workingcol);

                        Console.WriteLine("side 2");
                    }
                    else
                    {
                        LEFTpalettelist.Add(workingcol);

                        Console.WriteLine("side 1");
                    }
                }
                else
                {
                    LEFTpalettelist.Add(workingcol);
                }

                //Console.WriteLine(i);
                //Console.WriteLine(workingcol.Length);
                //Console.WriteLine("loaded " + palettelist.Count + " palettes");

                byte[] paldat = workingcol.getdata();

                string workingdir = Directory.GetCurrentDirectory();

                //Console.WriteLine(paldat[0]+" and "+workingcol.getdata()[0]);

                bool debugoutput = false;

                if (debugoutput)
                {
                    System.IO.File.WriteAllBytes(Path.Combine(workingdir, "debug/debug_" + p + ".pal"), paldat);
                }
            }

            retpal.Lpals = LEFTpalettelist;
            retpal.Rpals = RIGHTpalettelist;

            return(retpal);
        }
Example #11
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);
        }