コード例 #1
0
        /// <summary>Called when the trainer needs to be detached from the game's process.</summary>
        private void DetachFromGame()
        {
            // Detach from the target process
            if (GameMemoryIO.IsAttached())
            {
                // If the game's process is still running, all cheats must be disabled
                if (GameMemoryIO.TargetProcess.HasExited == false)
                {
                    foreach (ECheat curCheat in Enum.GetValues(typeof(ECheat)))
                    {
                        SetCheatEnabled(curCheat, false);
                    }
                }

                // Release injected memory, cleanup and detach
                GameMemoryInjector.ResetAllocatedMemoryData();
                GameMemoryIO.DetachFromProcess();
            }

            // Reset all of the values of the DependencyProperty objects which represent injected variables
            foreach (KeyValuePair <DependencyProperty, EVariable> curPair in sm_dependencyPropertyToInjectedVariable)
            {
                // Retrieve the initial value of the injected variable
                DependencyProperty varDepProp = curPair.Key;
                EVariable          varID      = curPair.Value;

                FieldInfo enumeratorInfo           = typeof(EVariable).GetField(varID.ToString());
                VariableDefinitionAttribute varDef = enumeratorInfo.GetCustomAttribute <VariableDefinitionAttribute>();

                // Reset the variable back to its initial value
                this.SetValue(varDepProp, varDef.InitialValue);
            }
        }
コード例 #2
0
        /// <summary>
        /// Registers a DependencyProperty which is associated to a given injected variable of the trainer.
        /// The default value and type for the property is retrieved from the associated injected variable.
        /// </summary>
        /// <param name="propertyName">The name of the DependencyProperty to be registered.</param>
        /// <param name="varID">The injected variable to be associated with the DependencyProperty.</param>
        /// <returns>Returns a DependencyProperty representing the injected variable.</returns>
        private static DependencyProperty RegisterInjectedVariableDependencyProperty(string propertyName, EVariable varID)
        {
            // Retrieve information about the variable
            MemberInfo enumeratorInfo          = typeof(EVariable).GetField(varID.ToString());
            VariableDefinitionAttribute varDef = enumeratorInfo.GetCustomAttribute <VariableDefinitionAttribute>();
            Object defaultVarValue             = varDef.InitialValue;
            Type   varType = varDef.InitialValue.GetType();

            // Register the DependencyProperty
            DependencyProperty newDepProperty = DependencyProperty.Register(propertyName, varType, typeof(MainWindow),
                                                                            new PropertyMetadata(defaultVarValue, InjectedVariableValueChanged));

            sm_dependencyPropertyToInjectedVariable.Add(newDepProperty, varID);
            return(newDepProperty);
        }
コード例 #3
0
 /// <summary>
 /// Return true if the given aFormatString matches the regex for the given variable
 /// </summary>
 /// <param name="aFormatString">The format string to check for a match</param>
 /// <param name="aVariable">The variable to check</param>
 /// <returns></returns>
 public static bool IsMatch(string aFormatString, EVariable aVariable)
 {
     var regex = new Regex(RegexPattern.Replace("[VariableName]", aVariable.ToString()), RegexOptions.IgnoreCase);
     return regex.IsMatch(aFormatString);
 }