Exemple #1
0
            public InternalVariableDesc(ref FsuipcVariable variable)
            {
                var vc = new VariableConverter();

                Variable = variable;
                Buffer   = new byte[vc.ConvertSize(variable.GetVariableSize())];
            }
Exemple #2
0
        public bool AddVariableToRead(FsuipcVariable variable)
        {
            var varConverter          = new VariableConverter();
            var convertedVariableSize = varConverter.ConvertSize(variable.GetVariableSize());

            _fsuipcVariablesForRead[variable.Id] = new InternalVariableDesc(ref variable);

            return(_fsuipc.FSUIPC_Read(variable.Offset, convertedVariableSize, ref _fsuipcVariablesForRead[variable.Id].Token, ref _dwResult));
            // что делать с dwResult. Куда-то возвращать?
        }
        /// <summary>
        /// Получить значение переменной в памяти
        /// </summary>
        /// <param name="moduleName">Имя модуля, где находится переменная</param>
        /// <param name="moduleOffset">Относительное смещение от начала модуля</param>
        /// <param name="variableSize">Размер переменной</param>
        /// <returns>Результат получения значения переменной</returns>
        public ManageMemoryVariableResult GetVariableValue(string moduleName, uint moduleOffset, MemoryVariableSize variableSize)
        {
            lock (_modules)
            {
                if (!_modules.ContainsKey(moduleName))
                {
                    return(new ManageMemoryVariableResult
                    {
                        Code = MemoryPatchVariableErrorCode.ModuleNotFound,
                        ErrorMessage = moduleName
                    });
                }

                if ((int)_modules[moduleName].BaseAddress + _modules[moduleName].Size < moduleOffset)
                {
                    return(new ManageMemoryVariableResult
                    {
                        Code = MemoryPatchVariableErrorCode.OffsetIsOutOfModule
                    });
                }

                try
                {
                    var  baseOffset   = (IntPtr)((int)_modules[moduleName].BaseAddress + moduleOffset);
                    var  varConverter = new VariableConverter();
                    var  buffer       = new byte[varConverter.ConvertSize(variableSize)];
                    uint bytesRead    = 0;
                    var  readResult   = ReadProcessMemory(_processHandle, baseOffset, buffer, (uint)buffer.Length, ref bytesRead);
                    if (!readResult)
                    {
                        return(new ManageMemoryVariableResult
                        {
                            Code = MemoryPatchVariableErrorCode.ReadError,
                            Value = 0
                        });
                    }
                    var result = varConverter.ArrayToValue(buffer, variableSize);
                    return(new ManageMemoryVariableResult
                    {
                        Code = MemoryPatchVariableErrorCode.Ok,
                        Value = result
                    });
                }
                catch (Exception ex)
                {
                    return(new ManageMemoryVariableResult
                    {
                        Code = MemoryPatchVariableErrorCode.Unknown,
                        ErrorMessage = ex.Message
                    });
                }
            }
        }
Exemple #4
0
        public void Process()
        {
            var res = _fsuipc.FSUIPC_Process(ref _dwResult);

            foreach (var variable in _fsuipcVariablesForRead)
            {
                var varConverter          = new VariableConverter();
                var convertedVariableSize = varConverter.ConvertSize(variable.Value.Variable.GetVariableSize());
                _fsuipc.FSUIPC_Get(ref variable.Value.Token, convertedVariableSize, ref variable.Value.Buffer);
                variable.Value.Variable.SetValueInMemory(varConverter.ArrayToValue(variable.Value.Buffer, variable.Value.Variable.GetVariableSize()));
            }
        }
Exemple #5
0
        public bool AddVariableToWrite(FsuipcVariable variable)
        {
            var varConverter          = new VariableConverter();
            var convertedVariableSize = varConverter.ConvertSize(variable.GetVariableSize());

            _fsuipcVariablesForWrite[variable.Id]        = new InternalVariableDesc(ref variable);
            _fsuipcVariablesForWrite[variable.Id].Buffer = varConverter.ValueToArray((double)variable.GetValueToSet(), variable.GetVariableSize());
            var result = _fsuipc.FSUIPC_Write(variable.Offset, convertedVariableSize, ref _fsuipcVariablesForWrite[variable.Id].Buffer, ref _fsuipcVariablesForWrite[variable.Id].Token, ref _dwResult);

            return(result);
            // что делать с dwResult. Куда-то возвращать?
        }