public void PatchMemory(CheatBlock cheatBlock)
 {
     for (var i = 0; i < cheatBlock.Cheats.Count;)
     {
         i = i + ApplyCheat(cheatBlock, cheatBlock.Cheats[i]);
     }
 }
        public int ApplyCheat(CheatBlock cheatBlock, Cheat cheat)
        {
            switch (cheat.CheatType)
            {
            case CheatType._8BitWrite:
                return(_8BitWrite(cheat));

            case CheatType._16BitWrite:
                return(_16BitWrite(cheat));

            case CheatType._32BitWrite:
                return(_32BitWrite(cheat));

            case CheatType._copyBytes:
                return(CopyBytes(cheatBlock, cheat));

            case CheatType._pointerWrite:
                return(PointerWrite(cheatBlock, cheat));

            case CheatType._timer:
                return(Timer(cheatBlock, cheat));

            case CheatType._32BitCondition:
                return(_32BitCondition(cheatBlock, cheat));

            case CheatType._16BitCondition:
                return(_16BitCondition(cheatBlock, cheat));
            }
            return(0);
        }
        public int Timer(CheatBlock cheatBlock, Cheat cheat)
        {
            var cheatTimer = _cheatTimers.SingleOrDefault(c => c.Cheat == cheat);

            if (cheatTimer == null)
            {
                var bytes = cheat.Data
                            .Take(2)
                            .ToArray();

                var timerIntervalType = (CheatTimerIntervalType)BitConverter.ToInt32(bytes, 0);

                var timerInterval = BitConverter.ToInt32(cheat.Data
                                                         .Skip(1)
                                                         .Take(3)
                                                         .ToArray(), 0);

                _cheatTimers.Add(new CheatTimer(cheat, timerIntervalType, timerInterval));
            }

            if (cheatTimer.IsIntervalCriteriaMet())
            {
                return(1);
            }

            var currentPosition = cheatBlock.Cheats.IndexOf(cheat);

            return(cheatBlock.Cheats.Count);
        }
        public int CopyBytes(CheatBlock cheatBlock, Cheat cheat)
        {
            var copyLength  = BitConverter.ToInt32(cheat.Data, 0);
            var bytesToCopy = _byteEditor.Read(cheat.Address + _memoryOffset, copyLength);

            _byteEditor.Write(cheatBlock.Cheats[cheat.Position + 1].Address + _memoryOffset, bytesToCopy);
            return(2);
        }
        public int _32BitCondition(CheatBlock cheatBlock, Cheat cheat)
        {
            var data = _byteEditor
                       .Read(cheat.Address + _memoryOffset, 0x04);

            var IsCriteriaMet = cheat.Data
                                .SequenceEqual(data);

            return(IsCriteriaMet ? 1 : cheatBlock.Cheats.Count);
        }
Exemple #6
0
        public List <CheatBlock> Parse(string cheatList = null)
        {
            _cheatListText = _cheatListText ?? cheatList;

            var blocks = _cheatListText.Split("\r\n\r\n");

            foreach (var block in blocks)
            {
                _cheatList.Add(CheatBlock.Parse(block));
            }
            return(_cheatList);
        }
        public static CheatBlock Parse(string block)
        {
            var label = Regex.Match(block, "(#.{1,})\r\n", RegexOptions.IgnoreCase).Groups[1]?.Value;

            var cheatBlock = new CheatBlock()
            {
                Label = label
            };

            var cheatMatches = Regex.Matches(block, "([a-f0-9]{8}) ([a-f0-9]{8})", RegexOptions.IgnoreCase);

            var i = 0;

            foreach (Match match in cheatMatches)
            {
                var address = match.Groups[1].Value;

                var data = Enumerable.Range(0, match.Groups[2].Value.Length)
                           .Where(x => x % 2 == 0)
                           .Select(x => Convert.ToByte(match.Groups[2].Value.Substring(x, 2), 16))
                           .ToArray();

                Array.Reverse(data);

                cheatBlock.Cheats.Add(new Cheat()
                {
                    Position  = i,
                    Address   = Convert.ToInt32(address.Substring(2, 6), 16),
                    CheatType = (CheatType)Convert.ToInt32(address.Substring(0, 2), 16),
                    Data      = data
                });

                i++;
            }
            return(cheatBlock);
        }
        public int PointerWrite(CheatBlock cheatBlock, Cheat cheat)
        {
            var pointer = Convert.ToInt32(_byteEditor.Read(cheat.Address + _memoryOffset, 0x08));

            return(0);
        }