예제 #1
0
파일: Codes.cs 프로젝트: Glain/FFTPatcher
        /// <summary>
        /// Generates codes based on context.
        /// </summary>
        public static IList<string> GenerateCodes( Context context, IList<byte> oldBytes, IList<byte> newBytes, UInt32 offset, CodeEnabledOnlyWhen when )
        {
            switch( context )
            {
                case Context.US_PSP:
                    return GeneratePSPCodes( oldBytes, newBytes, offset );
                case Context.US_PSX:
                    return GeneratePSXCodes( oldBytes, newBytes, offset, when );
            }

            return new List<string>();
        }
예제 #2
0
        /// <summary>
        /// Generates codes based on context.
        /// </summary>
        public static IList <string> GenerateCodes(Context context, IList <byte> oldBytes, IList <byte> newBytes, UInt32 offset, CodeEnabledOnlyWhen when)
        {
            switch (context)
            {
            case Context.US_PSP:
                return(GeneratePSPCodes(oldBytes, newBytes, offset));

            case Context.US_PSX:
                return(GeneratePSXCodes(oldBytes, newBytes, offset, when));
            }

            return(new List <string>());
        }
예제 #3
0
파일: Codes.cs 프로젝트: Glain/FFTPatcher
        private static IList<string> GeneratePSXCodes(IList<byte> oldBytes, IList<byte> newBytes, UInt32 offset, CodeEnabledOnlyWhen when)
        {
            List<string> codes = new List<string>();
            bool[] patched = new bool[newBytes.Count];

            // Generate 80h codes
            for (int i = (int)(offset % 2); i < newBytes.Count; i += 2)
            {
                if (((i + 1) < newBytes.Count) &&
                    ((newBytes[i] != oldBytes[i]) &&
                    (newBytes[i + 1] != oldBytes[i + 1])) &&
                    (!patched[i]) && (!patched[i + 1]))
                {
                    UInt32 addy = (UInt32)(offset + i);
                    string code = string.Format("80{0:X6} {2:X2}{1:X2}",
                        addy, newBytes[i], newBytes[i + 1]);
                    codes.Add(code);
                    patched[i] = true;
                    patched[i + 1] = true;
                }
            }

            // Generate 40h codes
            for (int i = 0; i < newBytes.Count; i++)
            {
                if ((newBytes[i] != oldBytes[i]) && (!patched[i]))
                {
                    UInt32 addy = (UInt32)(offset + i);
                    string code = string.Format("30{0:X6} 00{1:X2}",
                        addy, newBytes[i]);
                    codes.Add(code);
                    patched[i] = true;
                }
            }

            // Sort them
            codes.Sort((s, t) => s.Substring(2).CompareTo(t.Substring(2)));

            // Insert conditionals if necessary
            const string worldConditional = "7013B900 F400";
            const string battleConditional = "7014E61C F400";

            if (when != CodeEnabledOnlyWhen.Any)
            {
                string conditional =
                    when == CodeEnabledOnlyWhen.Battle ? battleConditional : worldConditional;
                List<string> realCodes = new List<string>(codes.Count * 2);
                foreach (string code in codes)
                {
                    realCodes.Add(conditional);
                    realCodes.Add(code);
                }
                codes = realCodes;
            }
            return codes.AsReadOnly();
        }
예제 #4
0
        private static IList <string> GeneratePSXCodes(IList <byte> oldBytes, IList <byte> newBytes, UInt32 offset, CodeEnabledOnlyWhen when)
        {
            List <string> codes = new List <string>();

            bool[] patched = new bool[newBytes.Count];

            // Generate 80h codes
            for (int i = (int)(offset % 2); i < newBytes.Count; i += 2)
            {
                if (((i + 1) < newBytes.Count) &&
                    ((newBytes[i] != oldBytes[i]) &&
                     (newBytes[i + 1] != oldBytes[i + 1])) &&
                    (!patched[i]) && (!patched[i + 1]))
                {
                    UInt32 addy = (UInt32)(offset + i);
                    string code = string.Format("80{0:X6} {2:X2}{1:X2}",
                                                addy, newBytes[i], newBytes[i + 1]);
                    codes.Add(code);
                    patched[i]     = true;
                    patched[i + 1] = true;
                }
            }

            // Generate 40h codes
            for (int i = 0; i < newBytes.Count; i++)
            {
                if ((newBytes[i] != oldBytes[i]) && (!patched[i]))
                {
                    UInt32 addy = (UInt32)(offset + i);
                    string code = string.Format("30{0:X6} 00{1:X2}",
                                                addy, newBytes[i]);
                    codes.Add(code);
                    patched[i] = true;
                }
            }

            // Sort them
            codes.Sort((s, t) => s.Substring(2).CompareTo(t.Substring(2)));

            // Insert conditionals if necessary
            //const string worldConditional = "7013B900 F400";
            //const string battleConditional = "7014E61C F400";

            if (when != CodeEnabledOnlyWhen.Any)
            {
                //string conditional = (when == CodeEnabledOnlyWhen.Battle) ? battleConditional : worldConditional;
                string conditional = ConditionalCodeMap[when];

                List <string> realCodes = new List <string>(codes.Count * 2);
                foreach (string code in codes)
                {
                    realCodes.Add(conditional);
                    realCodes.Add(code);
                }
                codes = realCodes;
            }
            return(codes.AsReadOnly());
        }