Exemplo n.º 1
0
        // Sample Input for Saturn:
        // 160949FC 0090
        // Address: 0949FC
        // Value:  90
        // Note, 3XXXXXXX are Big Endian
        // Remove first two octets
        public static IDecodeResult Decode(string code)
        {
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (code.IndexOf(" ") != 8)
            {
                return(new InvalidCheatCode("All Saturn GameShark Codes need to contain a space after the eighth character."));
            }

            if (code.Length != 13)
            {
                return(new InvalidCheatCode("All Saturn GameShark Cheats need to be 13 characters in length."));
            }

            var result = new DecodeResult {
                Size = WatchSize.Word
            };

            //  Only the first character really matters?  16 or 36?
            var test = code.Remove(2, 11).Remove(1, 1);

            if (test == "3")
            {
                result.Size = WatchSize.Byte;
            }

            var s = code.Remove(0, 2);

            result.Address = int.Parse(s.Remove(6, 5), NumberStyles.HexNumber);
            result.Value   = int.Parse(s.Remove(0, 7));
            return(result);
        }
Exemplo n.º 2
0
        // 30XXXXXX 00YY
        public static IDecodeResult Decode(string code)
        {
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (code.IndexOf(" ") != 8)
            {
                return(new InvalidCheatCode("All PSX GameShark Codes need to contain a space after the eighth character."));
            }

            if (code.Length != 13)
            {
                return(new InvalidCheatCode("All PSX GameShark Cheats need to be 13 characters in length."));
            }

            var result = new DecodeResult();

            var type = code.Substring(0, 2);

            result.Size = type switch
            {
                "10" => WatchSize.Word,
                "11" => WatchSize.Word,
                "20" => WatchSize.Byte,
                "21" => WatchSize.Byte,
                "30" => WatchSize.Byte,
                "80" => WatchSize.Word,
                "D0" => WatchSize.Word,
                "D1" => WatchSize.Word,
                "D2" => WatchSize.Word,
                "D3" => WatchSize.Word,
                "D4" => WatchSize.Word,
                "D5" => WatchSize.Word,
                "D6" => WatchSize.Word,
                "E0" => WatchSize.Byte,
                "E1" => WatchSize.Byte,
                "E2" => WatchSize.Byte,
                "E3" => WatchSize.Byte,
                _ => WatchSize.Byte
            };

            var s = code.Remove(0, 2);

            result.Address = int.Parse(s.Remove(6, 5), NumberStyles.HexNumber);
            result.Value   = int.Parse(s.Remove(0, 7), NumberStyles.HexNumber);

            return(result);
        }
    }
Exemplo n.º 3
0
        public static Cheat ToCheat(this DecodeResult result, MemoryDomain domain, string description)
        {
            var watch = Watch.GenerateWatch(
                domain,
                result.Address,
                result.Size,
                DisplayType.Hex,
                domain.EndianType == MemoryDomain.Endian.Big,
                description);

            return(result.Compare.HasValue
                                ? new Cheat(watch, result.Value, result.Compare.Value, true, Cheat.CompareType.Equal)
                                : new Cheat(watch, result.Value));
        }
        // Sample Input for GB/GBC:
        // 010FF6C1
        // Becomes:
        // Address C1F6
        // Value 0F
        public static IDecodeResult Decode(string code)
        {
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (code.Length != 8 || code.Contains("-"))
            {
                return(new InvalidCheatCode("GameShark codes must be 8 characters with no dashes."));
            }

            var test = code.Substring(0, 2);

            if (test != "00" && test != "01")
            {
                return(new InvalidCheatCode("All GameShark Codes for GameBoy need to start with 00 or 01"));
            }

            var result = new DecodeResult {
                Size = WatchSize.Byte
            };

            code = code.Remove(0, 2);

            var valueStr = code.Remove(2, 4);

            code = code.Remove(0, 2);

            var addrStr = code.Remove(0, 2);

            addrStr += code.Remove(2, 2);

            result.Value   = int.Parse(valueStr, NumberStyles.HexNumber);
            result.Address = int.Parse(addrStr, NumberStyles.HexNumber);
            return(result);
        }
        public static IDecodeResult Decode(string code)
        {
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (code.IndexOf("-") != 3 && code.Length != 9)
            {
                return(new InvalidCheatCode("Action Replay Codes must be 9 characters with a dash after the third character"));
            }

            var result = new DecodeResult {
                Size = WatchSize.Byte
            };

            var s          = code.Remove(0, 2);
            var ramAddress = s.Remove(4, 2).Replace("-", "");
            var ramValue   = s.Remove(0, 5);

            result.Address = int.Parse(ramAddress, NumberStyles.HexNumber);
            result.Value   = int.Parse(ramValue, NumberStyles.HexNumber);
            return(result);
        }
		public static IDecodeResult Decode(string code)
		{
			if (code == null)
			{
				throw new ArgumentNullException(nameof(code));
			}

			if (!code.Contains("-") && code.Length != 9)
			{
				return new InvalidCheatCode("Game genie codes must be 9 characters with a format of xxyy-yyyy");
			}

			// Code: D F 4 7 0 9 1 5 6 B C 8 A 2 3 E
			// Hex:  0 1 2 3 4 5 6 7 8 9 A B C D E F
			// XXYY-YYYY, where XX is the value, and YY-YYYY is the address.
			// Char # |   0   |   1   |   2   |   3   |   4   |   5   |   6   |   7   |
			// Bit  # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|
			// maps to|     Value     |i|j|k|l|q|r|s|t|o|p|a|b|c|d|u|v|w|x|e|f|g|h|m|n|
			// order  |     Value     |a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|
			var result = new DecodeResult { Size = WatchSize.Byte };

			int x;

			// Value
			if (code.Length > 0)
			{
				SNESGameGenieTable.TryGetValue(code[0], out x);
				result.Value = x << 4;
			}

			if (code.Length > 1)
			{
				SNESGameGenieTable.TryGetValue(code[1], out x);
				result.Value |= x;
			}

			// Address
			if (code.Length > 2)
			{
				SNESGameGenieTable.TryGetValue(code[2], out x);
				result.Address = x << 12;
			}

			if (code.Length > 3)
			{
				SNESGameGenieTable.TryGetValue(code[3], out x);
				result.Address |= x << 4;
			}

			if (code.Length > 4)
			{
				SNESGameGenieTable.TryGetValue(code[4], out x);
				result.Address |= (x & 0xC) << 6;
				result.Address |= (x & 0x3) << 22;
			}

			if (code.Length > 5)
			{
				SNESGameGenieTable.TryGetValue(code[5], out x);
				result.Address |= (x & 0xC) << 18;
				result.Address |= (x & 0x3) << 2;
			}

			if (code.Length > 6)
			{
				SNESGameGenieTable.TryGetValue(code[6], out x);
				result.Address |= (x & 0xC) >> 2;
				result.Address |= (x & 0x3) << 18;
			}

			if (code.Length > 7)
			{
				SNESGameGenieTable.TryGetValue(code[7], out x);
				result.Address |= (x & 0xC) << 14;
				result.Address |= (x & 0x3) << 10;
			}

			return result;
		}
Exemplo n.º 7
0
 public static bool IsValid(this IDecodeResult result, out DecodeResult valid)
 {
     valid = result as DecodeResult;
     return(result is DecodeResult);
 }
        public static IDecodeResult Decode(string code)
        {
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (code.Length != 6 && code.Length != 8)
            {
                return(new InvalidCheatCode("Game Genie codes need to be six or eight characters in length."));
            }

            var result = new DecodeResult {
                Size = WatchSize.Byte
            };

            // char 3 bit 3 denotes the code length.
            if (code.Length == 6)
            {
                // Char # |   1   |   2   |   3   |   4   |   5   |   6   |
                // Bit  # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|
                // maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|5|E|F|G|
                result.Value   = 0;
                result.Address = 0x8000;

                GameGenieTable.TryGetValue(code[0], out var x);
                result.Value |= x & 0x07;
                result.Value |= (x & 0x08) << 4;

                GameGenieTable.TryGetValue(code[1], out x);
                result.Value   |= (x & 0x07) << 4;
                result.Address |= (x & 0x08) << 4;

                GameGenieTable.TryGetValue(code[2], out x);
                result.Address |= (x & 0x07) << 4;

                GameGenieTable.TryGetValue(code[3], out x);
                result.Address |= (x & 0x07) << 12;
                result.Address |= x & 0x08;

                GameGenieTable.TryGetValue(code[4], out x);
                result.Address |= x & 0x07;
                result.Address |= (x & 0x08) << 8;

                GameGenieTable.TryGetValue(code[5], out x);
                result.Address |= (x & 0x07) << 8;
                result.Value   |= x & 0x08;
            }
            else
            {
                // Char # |   1   |   2   |   3   |   4   |   5   |   6   |   7   |   8   |
                // Bit  # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|
                // maps to|1|6|7|8|H|2|3|4|-|I|J|K|L|A|B|C|D|M|N|O|%|E|F|G|!|^|&|*|5|@|#|$|
                result.Value   = 0;
                result.Address = 0x8000;
                result.Compare = 0;

                GameGenieTable.TryGetValue(code[0], out var x);
                result.Value |= x & 0x07;
                result.Value |= (x & 0x08) << 4;

                GameGenieTable.TryGetValue(code[1], out x);
                result.Value   |= (x & 0x07) << 4;
                result.Address |= (x & 0x08) << 4;

                GameGenieTable.TryGetValue(code[2], out x);
                result.Address |= (x & 0x07) << 4;

                GameGenieTable.TryGetValue(code[3], out x);
                result.Address |= (x & 0x07) << 12;
                result.Address |= x & 0x08;

                GameGenieTable.TryGetValue(code[4], out x);
                result.Address |= x & 0x07;
                result.Address |= (x & 0x08) << 8;

                GameGenieTable.TryGetValue(code[5], out x);
                result.Address |= (x & 0x07) << 8;
                result.Compare |= x & 0x08;

                GameGenieTable.TryGetValue(code[6], out x);
                result.Compare |= x & 0x07;
                result.Compare |= (x & 0x08) << 4;

                GameGenieTable.TryGetValue(code[7], out x);
                result.Compare |= (x & 0x07) << 4;
                result.Value   |= x & 0x08;
            }

            return(result);
        }
        public static IDecodeResult Decode(string _code)
        {
            if (_code == null)
            {
                throw new ArgumentNullException(nameof(_code));
            }

            if (_code.LastIndexOf("-") != 7 || _code.IndexOf("-") != 3)
            {
                return(new InvalidCheatCode("All Master System Game Genie Codes need to have a dash after the third character and seventh character."));
            }

            // No cypher on value
            // Char # |   0   |   1   |   2   |   3   |   4   |   5   |   6   |   7   |   8   |
            // Bit  # |3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|3|2|1|0|
            // maps to|      Value    |A|B|C|D|E|F|G|H|I|J|K|L|XOR 0xF|a|b|c|c|NotUsed|e|f|g|h|
            // proper |      Value    |XOR 0xF|A|B|C|D|E|F|G|H|I|J|K|L|g|h|a|b|Nothing|c|d|e|f|
            var result = new DecodeResult {
                Size = WatchSize.Byte
            };

            int x;

            // Getting Value
            if (_code.Length > 0)
            {
                _gbGgGameGenieTable.TryGetValue(_code[0], out x);
                result.Value = x << 4;
            }

            if (_code.Length > 1)
            {
                _gbGgGameGenieTable.TryGetValue(_code[1], out x);
                result.Value |= x;
            }

            // Address
            if (_code.Length > 2)
            {
                _gbGgGameGenieTable.TryGetValue(_code[2], out x);
                result.Value = x << 8;
            }
            else
            {
                result.Value = -1;
            }

            if (_code.Length > 3)
            {
                _gbGgGameGenieTable.TryGetValue(_code[3], out x);
                result.Address |= x << 4;
            }

            if (_code.Length > 4)
            {
                _gbGgGameGenieTable.TryGetValue(_code[4], out x);
                result.Address |= x;
            }

            if (_code.Length > 5)
            {
                _gbGgGameGenieTable.TryGetValue(_code[5], out x);
                result.Address |= (x ^ 0xF) << 12;
            }

            // compare need to be full
            if (_code.Length > 8)
            {
                _gbGgGameGenieTable.TryGetValue(_code[6], out x);
                var comp = x << 2;

                // 8th character ignored
                _gbGgGameGenieTable.TryGetValue(_code[8], out x);
                comp          |= (x & 0xC) >> 2;
                comp          |= (x & 0x3) << 6;
                result.Compare = comp ^ 0xBA;
            }

            return(result);
        }