示例#1
0
        public static bool EnableCheat(ECheat cheat, bool state)
        {
            if (IsCheatUnlocked(cheat))
            {
                Manager.SetEnabled(cheat, state);

                return(IsCheatEnabled(cheat) == state);
            }

            return(false);
        }
        /// <summary>
        /// Called whenever any of the CheckBoxes used to activate/deactivate cheats from the trainer gets checked or unchecked.
        /// </summary>
        /// <param name="sender">Object which sent the event.</param>
        /// <param name="e">Arguments from the event.</param>
        private void CheckBoxCheatToggled(object sender, RoutedEventArgs e)
        {
            // Only proceed if the trainer is attached...
            if (GameMemoryIO.Attached == false)
            {
                return;
            }

            // Retrieve information which will be used to enable or disable the cheat
            CheckBox chkBox       = (CheckBox)e.Source;
            ECheat   cheatID      = (ECheat)chkBox.Tag;
            bool     bEnableCheat = (chkBox.IsChecked == true);

            SetCheatEnabled(cheatID, bEnableCheat);
        }
        /// <summary>
        /// Called whenever any of the CheckBoxes used to activate/deactivate cheats from the trainer gets checked or unchecked.
        /// </summary>
        /// <param name="sender">Object which sent the event.</param>
        /// <param name="e">Arguments from the event.</param>
        private void CheckBoxCheatToggled(object sender, RoutedEventArgs e)
        {
            // Retrieve information which will be used to enable or disable the cheat
            CheckBox chkBox       = (CheckBox)e.Source;
            ECheat   cheatID      = (ECheat)chkBox.Tag;
            bool     bEnableCheat = (chkBox.IsChecked == true);

            // Update the list of cheats to be enabled
            if (bEnableCheat)
            {
                m_enabledCheats.Add(cheatID);
            }
            else
            {
                m_enabledCheats.Remove(cheatID);
            }

            // Enable or disable the cheat in the game's memory space
            if (GameMemoryIO.IsAttached())
            {
                GameMemoryInjector.SetMemoryAlterationsActive(cheatID, bEnableCheat);
            }
        }
        /// <summary>This method is called to enable or disable cheats, altering the game's process' memory space accordingly.</summary>
        /// <param name="cheatID">The identifier of the cheat that needs to be enabled/disabled on the game.</param>
        /// <param name="bEnable">A flag specifying if the cheat is to be enabled or disabled.</param>
        private void SetCheatEnabled(ECheat cheatID, bool bEnable)
        {
            FieldInfo     fieldInfo     = typeof(ECheat).GetField(cheatID.ToString());
            CheatTypeInfo cheatTypeInfo = fieldInfo.GetCustomAttribute <CheatTypeInfo>();

            IntPtr targetInstructionAddress = LowLevelConstants.GetCheatTargetInstructionAddress(cheatID, GameMemoryIO.TargetProcess.MainModule.BaseAddress);

            // Verify if we're enabling or disabling the cheat...
            if (bEnable == false)
            {
                // Disabling the cheat is just a matter of writing the original bytes of the instruction into the right place
                GameMemoryIO.WriteToTarget(targetInstructionAddress, cheatTypeInfo.OriginalInstructionBytes);
            }
            else
            {
                // Enable the cheat based on its type...
                switch (cheatTypeInfo.CheatType)
                {
                case ECheatType.evCheatTypeNOP:
                {
                    // Enabling a NOP cheat is just a matter of replacing the instruction's original bytes by NOP instructions
                    byte [] arrayOfNOPs = Enumerable.Repeat <byte>(LowLevelConstants.INSTRUCTION_NOP, cheatTypeInfo.OriginalInstructionBytes.Length).ToArray();
                    GameMemoryIO.WriteToTarget(targetInstructionAddress, arrayOfNOPs);
                    break;
                }

                case ECheatType.evCheatTypeCodeCave:
                    GameMemoryInjector.WriteCodeCaveDetour(targetInstructionAddress, cheatTypeInfo.CodeCave, cheatTypeInfo.OriginalInstructionBytes.Length);
                    break;

                default:
                    throw new NotImplementedException(string.Format("[{0}] Activation of cheats of type \"{1}\" are not yet implemented!",
                                                                    this.GetType().Name, cheatTypeInfo.CheatType.ToString()));
                }
            }
        }
示例#5
0
 /// <summary>
 /// Retrieves the address of the instruction which the trainer needs to modify in order to enable or disable a given cheat.
 /// </summary>
 /// <param name="cheatID">The cheat whose target instruction is to be retrieved.</param>
 /// <param name="mainModuleBaseAddress">The base address of the game process's main module.</param>
 /// <returns>Returns the address of the instruction associated with the given cheat.</returns>
 public static IntPtr GetCheatTargetInstructionAddress(ECheat cheatID, IntPtr mainModuleBaseAddress)
 {
     return(mainModuleBaseAddress + sm_cheatTargetInstructionAddress[cheatID]);
 }
示例#6
0
 public static bool IsCheatUnlocked(ECheat cheat) => Manager.IsUnlocked(cheat);
示例#7
0
 public static bool IsCheatEnabled(ECheat cheat) => Manager.IsEnabled(cheat);