示例#1
0
        private static void SearchAndShow(GameFile file)
        {
            // It is better not to try to modify it.
            if (file.Name == "ARM7.bin")
            {
                return;
            }

            // 1.A Check if it's encoded
            bool isEncoded;

            // Take ARM as compressed always, if the file finally
            // it's not compressed the tool will do nothing
            ArmFile arm9   = file as ArmFile;
            bool    isArm9 = arm9 != null;

            isEncoded = isArm9;

            // If it's an overlay is easy to know when it's compressed
            OverlayFile overlay = file as OverlayFile;

            if (overlay != null)
            {
                isEncoded = overlay.IsEncoded;
            }

            // 1.B Decode if so
            if (isEncoded)
            {
                SetEncodingFormat(file, true);
                file.Format.Read();                 // Get data from file
                file.Format.Import(new string[0]);  // Call to the decoding program
                file.Format.Write();                // Overwrite data file
                file.Format.Dispose();
            }

            // 2 Search.
            //  If we have found something, let's examine its data
            long pos = SearchText(file.Stream, 0);

            if (pos != -1)
            {
                // Get RAM address
                if (isArm9)
                {
                    pos += arm9.RamAddress;
                }
                else
                {
                    pos += overlay.RamAddress;
                }

                Console.WriteLine("Found in {0} at 0x{1:X8}", file.Name, pos);
                Console.Write("Press Enter to continue.");
                Console.ReadKey(true);
            }
        }
示例#2
0
        private static bool SearchAndModify(GameFile file)
        {
            // It is better not to try to modify it.
            if (file.Name == "ARM7.bin")
            {
                return(false);
            }

            Console.WriteLine("Searching in {0}", file.Name);
            bool found = false;

            string[] noParams = new string[0];

            // 1.A Check if it's encoded
            bool isEncoded;

            // Take ARM as compressed always, if the file finally
            // it's not compressed the tool will do nothing
            bool isArm9 = file is ArmFile;

            isEncoded = isArm9;

            // If it's an overlay is easy to know when it's compressed
            OverlayFile overlay = file as OverlayFile;

            if (overlay != null)
            {
                isEncoded = overlay.IsEncoded;
            }

            // 1.B Decode if so
            if (isEncoded)
            {
                // Get the original size
                long encodedSize = file.Length;

                SetEncodingFormat(file, true);
                file.Format.Read();             // Get data from file
                file.Format.Import(noParams);   // Call to the decoding program
                file.Format.Write();            // Overwrite data file
                file.Format.Dispose();

                // Check if the file was decoded
                // else, it is not encoded and must not be
                // encoded again
                // This can happen only with ARM9 file
                isEncoded = encodedSize != file.Length;
                if (!isEncoded)
                {
                    Console.WriteLine("\tFile {0} is not encoded.", file.Name);
                }
            }
            else
            {
                // Get a stream to work with and set to the file
                // This allow read & write operations
                // In the case of decoding this is already done
                DataStream stream = new DataStream(new MemoryStream(), 0, 0);
                file.Stream.WriteTo(stream);
                file.ChangeStream(stream);
            }

            // 2 While get the end of the file
            //	2.A Search next value & Edit the value
            int pos = 0;

            while (pos != -1)
            {
                pos = Search(file.Stream, pos);
                if (pos != -1)
                {
                    found = true;
                    pos   = Replace(file.Stream, pos);
                }
            }

            // Write if it was decoded return to original state
            if (isEncoded)
            {
                SetEncodingFormat(file, false);
                file.Format.Read();             // Get data from file
                file.Format.Import(noParams);   // Call to encoding program
                file.Format.Write();            // Overwrite data file
                file.Format.Dispose();
            }

            return(found);
        }