Example #1
0
        public override void Inject(bool encrypt, string outputPath, string shortName, string longName,
                                    Bitmap menuIconImg, Bitmap bootTvImg, Bitmap bootDrcImg)
        {
            string outPath = GetValidOutputPath(outputPath, shortName);

            if (Directory.Exists(outPath) &&
                (Directory.GetDirectories(outPath).Length != 0 || Directory.GetFiles(outPath).Length != 0))
            {
                throw new Exception("The output path \"" + outPath + "\"exists and is not empty.");
            }

            Base = GetLoadedBase();
            if (!BaseIsLoaded)
            {
                throw new Exception("The base is not ready.");
            }

            InjectImages(menuIconImg, bootTvImg, bootDrcImg);
            if (RomIsValid)
            {
                InjectMeta(shortName, longName);
            }
            InjectRom();

            if (encrypt)
            {
                NusContent.Encrypt(BasePath, outPath);
            }
            else if (!Useful.DirectoryCopy(BasePath, outPath, true))
            {
                throw new Exception("\"" + BasePath + "\" copy failed.");
            }
        }
        public void LoadBase(string path)
        {
            NusContent.Format format = NusContent.GetFormat(path);

            if (format == NusContent.Format.Decrypted)
            {
                ValidateBase(path);

                if (Directory.Exists(BasePath))
                {
                    Directory.Delete(BasePath, true);
                    Base = null;
                }

                if (Useful.DirectoryCopy(path, BasePath, true))
                {
                    Base = GetLoadedBase();
                }
                else
                {
                    throw new Exception("Could not load base \"" + path + "\".");
                }
            }
            else if (format == NusContent.Format.Encrypted)
            {
                ValidateEncryptedBase(path);

                if (Directory.Exists(BasePath))
                {
                    Directory.Delete(BasePath, true);
                    Base = null;
                }

                Directory.CreateDirectory(BasePath);
                NusContent.Decrypt(path, BasePath);
                Base = GetLoadedBase();
            }
            else
            {
                StringBuilder strBuilder = new StringBuilder();
                strBuilder.AppendLine("The folder not contains a valid NUS content.");
                strBuilder.AppendLine("If it is an unpackaged (decrypted) NUS content, then:");
                strBuilder.AppendLine("The \"" + path + "\\code\" folder not exist.");
                strBuilder.AppendLine("Or \"" + path + "\\content\" folder not exist.");
                strBuilder.AppendLine("Or \"" + path + "\\meta\" folder not exist.");
                strBuilder.AppendLine("If it is an packaged (encrypted) NUS content, then:");
                strBuilder.AppendLine("The \"" + path + "\\title.tmd\" file not exist.");
                strBuilder.AppendLine("Or \"" + path + "\\title.tik\" file not exist.");
                strBuilder.AppendLine("Or \"" + path + "\\title.cert\" file not exist.");
                throw new Exception(strBuilder.ToString());
            }
        }
        protected string GetValidOutputPath(string outputPath, string shortName)
        {
            if (!Directory.Exists(outputPath))
            {
                throw new Exception("The output path \"" + outputPath + "\" not exist.");
            }

            if (shortName.Length == 0)
            {
                throw new Exception("The short name is empty.");
            }

            char[] array   = Useful.Windows1252ToASCII(shortName, '_').ToCharArray();
            char[] invalid = Path.GetInvalidFileNameChars();
            for (int i = 0; i < array.Length; i++)
            {
                foreach (char c in invalid)
                {
                    if (array[i] == c)
                    {
                        array[i] = '_';
                    }
                }
            }
            string folderName = new string(array);

            StringBuilder strBuilder = new StringBuilder(outputPath.Length + folderName.Length + 20);

            strBuilder.Append(outputPath);
            strBuilder.Append("\\");
            strBuilder.Append(folderName);
            strBuilder.Append(" [");
            if (RomIsValid)
            {
                strBuilder.Append(TitleId);
                strBuilder.Append("]");
            }
            else
            {
                strBuilder.Append(NusContent.GetTitleID(BasePath));
                strBuilder.Append("] (Edited)");
            }

            return(strBuilder.ToString());
        }
        protected void InjectImages(Bitmap menuIconImg, Bitmap bootTvImg, Bitmap bootDrcImg)
        {
            Graphics g;

            if (menuIconImg != null)
            {
                Bitmap tmpMenuIconImg;
                tmpMenuIconImg = new Bitmap(128, 128, PixelFormat.Format32bppArgb);
                g = Graphics.FromImage(tmpMenuIconImg);
                g.DrawImage(menuIconImg, new Rectangle(0, 0, 128, 128));
                g.Dispose();
                if (!NusContent.SaveTGA(tmpMenuIconImg, BasePath + "\\meta\\iconTex.tga"))
                {
                    throw new Exception("Error creating \"iconTex.tga\" file.");
                }
            }

            if (bootTvImg != null)
            {
                Bitmap tmpBootTvImg;
                tmpBootTvImg = new Bitmap(1280, 720, PixelFormat.Format24bppRgb);
                g            = Graphics.FromImage(tmpBootTvImg);
                g.DrawImage(bootTvImg, new Rectangle(0, 0, 1280, 720));
                g.Dispose();
                if (!NusContent.SaveTGA(tmpBootTvImg, BasePath + "\\meta\\bootTvTex.tga"))
                {
                    throw new Exception("Error creating \"bootTvTex.tga\" file.");
                }
            }

            if (bootDrcImg != null)
            {
                Bitmap tmpBootDrcImg;
                tmpBootDrcImg = new Bitmap(854, 480, PixelFormat.Format24bppRgb);
                g             = Graphics.FromImage(tmpBootDrcImg);
                g.DrawImage(bootDrcImg, new Rectangle(0, 0, 854, 480));
                g.Dispose();
                if (!NusContent.SaveTGA(tmpBootDrcImg, BasePath + "\\meta\\bootDrcTex.tga"))
                {
                    throw new Exception("Error creating \"bootDrcTex.tga\" file.");
                }
            }
        }
        protected string GetAppFileName(string path)
        {
            if (File.Exists(Environment.CurrentDirectory + "\\resources\\unpack\\cos.xml"))
            {
                File.Delete(Environment.CurrentDirectory + "\\resources\\unpack\\cos.xml");
            }

            NusContent.Decrypt(path, "code\\cos.xml", Environment.CurrentDirectory + "\\resources\\unpack\\cos.xml");

            if (!File.Exists(Environment.CurrentDirectory + "\\resources\\unpack\\cos.xml"))
            {
                throw new Exception("The NUS content does not contains \"code\\cos.xml\" file.");
            }

            XmlDocument xmlCos = new XmlDocument();

            xmlCos.Load(Environment.CurrentDirectory + "\\resources\\unpack\\cos.xml");
            XmlNode cos_argstr = xmlCos.SelectSingleNode("app/argstr");

            return(cos_argstr.InnerText);
        }
Example #6
0
        private void DeterminateBase(string path)
        {
            NusContent.Format format = NusContent.GetFormat(path);

            if (format == NusContent.Format.Decrypted)
            {
                NESInjector  nesI  = new NESInjector();
                SNESInjector snesI = new SNESInjector();
                N64Injector  n64I  = new N64Injector();
                GBAInjector  gbaI  = new GBAInjector();
                NDSInjector  ndsI  = new NDSInjector();

                VCNES vcnes = nesI.GetBase(path);
                if (vcnes != null)
                {
                    Cll.Log.WriteLine("Base format: NES");
                }

                VCSNES vcsnes = snesI.GetBase(path);
                if (vcsnes != null)
                {
                    Cll.Log.WriteLine("Base format: SNES");
                }

                VCN64 vcn64 = n64I.GetBase(path);
                if (vcn64 != null)
                {
                    Cll.Log.WriteLine("Base format: N64");
                }

                VCGBA vcgba = gbaI.GetBase(path);
                if (vcgba != null)
                {
                    Cll.Log.WriteLine("Base format: GBA");
                }

                VCNDS vcnds = ndsI.GetBase(path);
                if (vcnds != null)
                {
                    Cll.Log.WriteLine("Base format: NDS");
                }

                /*ValidateBase(path);
                 *
                 * if (Directory.Exists(BasePath))
                 * {
                 *  Directory.Delete(BasePath, true);
                 *  Base = null;
                 * }
                 *
                 * if (Useful.DirectoryCopy(path, BasePath, true))
                 *  Base = GetLoadedBase();
                 * else
                 *  throw new Exception("Could not load base \"" + path + "\".");*/
            }
            else if (format == NusContent.Format.Encrypted)
            {
                /*ValidateEncryptedBase(path);
                 *
                 * if (Directory.Exists(BasePath))
                 * {
                 *  Directory.Delete(BasePath, true);
                 *  Base = null;
                 * }
                 *
                 * Directory.CreateDirectory(BasePath);
                 * NusContent.Decrypt(path, BasePath);
                 * Base = GetLoadedBase();*/
            }
            else
            {
                StringBuilder strBuilder = new StringBuilder();
                strBuilder.AppendLine("The folder not contains a valid NUS content.");
                strBuilder.AppendLine("If it is an unpackaged (decrypted) NUS content, then:");
                strBuilder.AppendLine("The \"" + path + "\\code\" folder not exist.");
                strBuilder.AppendLine("Or \"" + path + "\\content\" folder not exist.");
                strBuilder.AppendLine("Or \"" + path + "\\meta\" folder not exist.");
                strBuilder.AppendLine("If it is an packaged (encrypted) NUS content, then:");
                strBuilder.AppendLine("The \"" + path + "\\title.tmd\" file not exist.");
                strBuilder.AppendLine("Or \"" + path + "\\title.tik\" file not exist.");
                strBuilder.AppendLine("Or \"" + path + "\\title.cert\" file not exist.");
                throw new Exception(strBuilder.ToString());
            }
        }