public static bool GetBoolValue(this WatchVariable watchVar, uint offset) { // Get dataBytes var dataBytes = watchVar.GetByteData(offset); // Make sure offset is a valid pointer if (dataBytes == null) { return(false); } // Get Uint64 value var intBytes = new byte[8]; dataBytes.CopyTo(intBytes, 0); UInt64 dataValue = BitConverter.ToUInt64(intBytes, 0); // Apply mask if (watchVar.Mask.HasValue) { dataValue &= watchVar.Mask.Value; } // Boolean parsing bool value = (dataValue != 0x00); value = watchVar.InvertBool ? !value : value; return(value); }
public static CheckState ContainsLocksCheckState( WatchVariable variable, List <uint> addresses = null) { if (!ContainsAnyLocks()) { return(CheckState.Unchecked); } List <WatchVariableLock> newLocks = variable.GetLocks(addresses); if (newLocks.Count == 0) { return(CheckState.Unchecked); } CheckState firstCheckState = _lockList.Contains(newLocks[0]) ? CheckState.Checked : CheckState.Unchecked; for (int i = 1; i < newLocks.Count; i++) { CheckState checkState = _lockList.Contains(newLocks[i]) ? CheckState.Checked : CheckState.Unchecked; if (checkState != firstCheckState) { return(CheckState.Indeterminate); } } return(firstCheckState); }
// Wrapper to make defining variables easier protected static WatchVariableControlPrecursor gfxProperty(string name, string type, uint offset, Structs.WatchVariableSubclass subclass = Structs.WatchVariableSubclass.Number, uint?mask = null) { Color color = (offset <= 0x13) ? ColorUtilities.GetColorFromString("Yellow") : ColorUtilities.GetColorFromString("LightBlue"); WatchVariable watchVar = new WatchVariable( type, null /* specialType */, Structs.BaseAddressTypeEnum.GfxNode, null /* offsetUS */, null /* offsetJP */, null /* offsetPAL */, offset, mask, null); WatchVariableControlPrecursor precursor = new WatchVariableControlPrecursor( name, watchVar, subclass, color, null /* displayType */, null /* roundingLimit */, (type == "uint" || type == "ushort") ? true : (bool?)null, null /* invertBool */, null /* coordinate */, null /* isYaw */, new List <Structs.VariableGroup>()); return(precursor); }
public override void AddVariable(WatchVariableControl control) { WatchVariableWrapper watchVarWrapper = control.WatchVarWrapper; WatchVariable watchVar = watchVarWrapper.WatchVar; if (watchVar.BaseAddressType == BaseAddressTypeEnum.Triangle) { if (Config.TriangleManager.TrianglePointerAddress.HasValue) { Config.VarHackManager.AddVariable( control.VarName + " " + VarHackConfig.EscapeChar, Config.TriangleManager.TrianglePointerAddress.Value, watchVar.MemoryType, watchVarWrapper.GetUseHex(), watchVar.Offset); } } else { List <uint> addressList = watchVar.GetAddressList(control.FixedAddressList); for (int i = 0; i < addressList.Count; i++) { string indexSuffix = addressList.Count > 1 ? (i + 1).ToString() : ""; Config.VarHackManager.AddVariable( control.VarName + indexSuffix + " " + VarHackConfig.EscapeChar, addressList[i], watchVar.MemoryType, watchVarWrapper.GetUseHex(), null); } } }
void IVariableAdder.AddVariable(WatchVariableControl control) { WatchVariableWrapper watchVarWrapper = control.WatchVarWrapper; WatchVariable watchVar = watchVarWrapper.WatchVar; if (watchVar.BaseAddressType == BaseAddressTypeEnum.Triangle) { var trianglePointerAddress = AccessScope <StroopMainForm> .content.trianglesTab.TrianglePointerAddress; if (trianglePointerAddress.HasValue) { AddVariable( control.VarName + " " + VarHackConfig.EscapeChar, trianglePointerAddress.Value, watchVar.MemoryType, watchVarWrapper.GetUseHex(), watchVar.Offset); } } else { List <uint> addressList = watchVar.GetAddressList(control.FixedAddressListGetter()); for (int i = 0; i < addressList.Count; i++) { string indexSuffix = addressList.Count > 1 ? (i + 1).ToString() : ""; AddVariable( control.VarName + indexSuffix + " " + VarHackConfig.EscapeChar, addressList[i], watchVar.MemoryType, watchVarWrapper.GetUseHex(), null); } } }
public static uint GetProcessAddress(this WatchVariable watchVar, ProcessStream stream, uint offset = 0) { uint address = GetRamAddress(watchVar, stream, offset, false); return((uint)LittleEndianessAddressing.AddressFix( (int)(address + stream.ProcessMemoryOffset), watchVar.GetByteCount())); }
// Wrapper to make defining variables easier protected static WatchVariableControlPrecursor gfxProperty(string name, string type, uint offset, Structs.WatchVariableSubclass subclass = Structs.WatchVariableSubclass.Number, uint?mask = null) { Color color = (offset <= 0x13) ? ColorUtilities.GetColorFromString("Yellow") : ColorUtilities.GetColorFromString("LightBlue"); WatchVariable watchVar = new WatchVariable( memoryTypeName: type, specialType: null, baseAddressType: BaseAddressTypeEnum.GfxNode, offsetUS: null, offsetJP: null, offsetSH: null, offsetEU: null, offsetDefault: offset, mask: mask, shift: null, handleMapping: true); WatchVariableControlPrecursor precursor = new WatchVariableControlPrecursor( name: name, watchVar: watchVar, subclass: subclass, backgroundColor: color, displayType: null, roundingLimit: null, useHex: (type == "uint" || type == "ushort") ? true : (bool?)null, invertBool: null, coordinate: null, isYaw: null, groupList: new List <VariableGroup>()); return(precursor); }
private bool ResultValid() { uint address; if (comboBoxType.SelectedIndex < 0) { MessageBox.Show("Select a value type!"); return(false); } else if (ParsingUtilities.TryParseHex(maskedTextBoxAddress.Text, out address)) { MessageBox.Show("Enter a valid address!"); return(false); } WatchVariable watchVar = new WatchVariable(); watchVar.Name = textBoxName.Text; watchVar.Type = WatchVariableExtensions.GetStringType((string)comboBoxType.SelectedItem); watchVar.Address = address; watchVar.AbsoluteAddressing = checkBoxAbsolute.Checked; _value = watchVar; return(true); }
public static bool GetBoolValue(this WatchVariable watchVar, ProcessStream stream, uint offset) { // Get dataBytes var byteCount = WatchVariable.TypeSize[watchVar.Type]; var dataBytes = stream.ReadRam(watchVar.OtherOffset ? offset + watchVar.Address : watchVar.Address, byteCount, watchVar.AbsoluteAddressing); // Get Uint64 value var intBytes = new byte[8]; dataBytes.CopyTo(intBytes, 0); UInt64 dataValue = BitConverter.ToUInt64(intBytes, 0); // Apply mask if (watchVar.Mask.HasValue) { dataValue &= watchVar.Mask.Value; } // Boolean parsing bool value = (dataValue != 0x00); value = watchVar.InvertBool ? !value : value; return(value); }
/// <summary> /// Clean up the resources used by the user control. /// </summary> /// <param name="disposing">True, to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Cleanup(bool disposing) { try { if (disposing) { // Cleanup managed objects by calling their Dispose() methods. if (components != null) { components.Dispose(); } } // Whether called by consumer code or the garbage collector free all unmanaged resources and set the value of managed data members to null. m_WatchVariable = null; m_ClientAsFormPTU = null; #region - [Detach the event handler methods.] - #endregion - [Detach the event handler methods.] - #region - [Component Designer Variables] - #endregion - [Component Designer Variables] - } catch (Exception) { // Don't do anything, just ensure that an exception isn't thrown. } finally { base.Cleanup(disposing); } }
/// <summary> /// Clean up the resources used by the form. /// </summary> /// <param name="disposing">True to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Cleanup(bool disposing) { try { if (disposing) { // Cleanup managed objects by calling their Dispose() methods. if (components != null) { components.Dispose(); } } // Whether called by consumer code or the garbage collector free all unmanaged resources and set the value of managed data members to null. m_WatchVariable = null; m_IChartScale = null; m_CalledFromAsFormConfigureChartRecorder = null; #region --- Windows Form Designer Variables --- // Detach the event handler delegates. // Set the Windows Form Designer Variables to null. #endregion --- Windows Form Designer Variables --- } catch (Exception) { // Don't do anything, just ensure that an exception isn't thrown. } finally { base.Cleanup(disposing); } }
public static void UpdateLockValues( WatchVariable variable, List <object> newValues, List <uint> addresses = null) { if (LockConfig.LockingDisabled) { return; } if (!ContainsAnyLocks()) { return; } List <WatchVariableLock> newLocks = variable.GetLocks(addresses); int minCount = Math.Min(newValues.Count, newLocks.Count); for (int i = 0; i < minCount; i++) { if (newValues[i] == null) { continue; } foreach (WatchVariableLock currentLock in _lockList) { if (currentLock.Equals(newLocks[i])) { currentLock.UpdateLockValue(newValues[i]); } } } }
public static UIntPtr GetProcessAddress(this WatchVariable watchVar, uint offset = 0) { uint address = GetRamAddress(watchVar, offset, false); return(Config.Stream.ConvertAddressEndianess( new UIntPtr(address + (ulong)Config.Stream.ProcessMemoryOffset.ToInt64()), watchVar.ByteCount)); }
public ModifyAddWatchVariableForm(WatchVariable watchVar) { InitializeComponent(); textBoxName.Text = watchVar.Name; comboBoxType.SelectedItem = watchVar.Type; maskedTextBoxAddress.Text = watchVar.Address.ToString(); checkBoxAbsolute.Checked = watchVar.AbsoluteAddressing; }
public static byte[] GetBytesFromAngleString(this WatchVariable watchVar, ProcessStream stream, uint offset, string value, WatchVariableControl.AngleViewModeType viewMode) { if (watchVar.Type != typeof(UInt32) && watchVar.Type != typeof(UInt16) && watchVar.Type != typeof(Int32) && watchVar.Type != typeof(Int16)) { return(null); } UInt32 writeValue = 0; // Print hex if (ParsingUtilities.IsHex(value)) { ParsingUtilities.TryParseHex(value, out writeValue); } else { switch (viewMode) { case WatchVariableControl.AngleViewModeType.Signed: case WatchVariableControl.AngleViewModeType.Unsigned: case WatchVariableControl.AngleViewModeType.Recommended: int tempValue; if (int.TryParse(value, out tempValue)) { writeValue = (uint)tempValue; } else if (!uint.TryParse(value, out writeValue)) { return(null); } break; case WatchVariableControl.AngleViewModeType.Degrees: double degValue; if (!double.TryParse(value, out degValue)) { return(null); } writeValue = (UInt16)(degValue / (360d / 65536)); break; case WatchVariableControl.AngleViewModeType.Radians: double radValue; if (!double.TryParse(value, out radValue)) { return(null); } writeValue = (UInt16)(radValue / (2 * Math.PI / 65536)); break; } } var byteCount = WatchVariable.TypeSize[watchVar.Type]; return(BitConverter.GetBytes(writeValue).Take(byteCount).ToArray()); }
public static void RemoveLocks(WatchVariable variable, List <uint> addresses = null) { List <WatchVariableLock> newLocks = variable.GetLocks(addresses); foreach (WatchVariableLock newLock in newLocks) { _lockList.Remove(newLock); } }
public static bool SetBytes(this WatchVariable watchVar, uint offset, byte[] dataBytes) { if (dataBytes == null) { return(false); } return(Config.Stream.WriteRamLittleEndian(dataBytes, watchVar.HasAdditiveOffset ? offset + watchVar.Address : watchVar.Address, watchVar.UseAbsoluteAddressing)); }
public static bool SetBytes(this WatchVariable watchVar, ProcessStream stream, uint offset, byte[] dataBytes) { if (dataBytes == null) { return(false); } return(stream.WriteRam(dataBytes, watchVar.OtherOffset ? offset + watchVar.Address : watchVar.Address, watchVar.AbsoluteAddressing)); }
public WatchVariableControl(WatchVariable watchVar) { _specialName = watchVar.Name; _watchVar = watchVar; CreateControls(); if (watchVar.BackroundColor.HasValue) { Color = watchVar.BackroundColor.Value; } }
public static void AddLocks(WatchVariable variable, List <uint> addresses = null) { List <WatchVariableLock> newLocks = variable.GetLocks(addresses); foreach (WatchVariableLock newLock in newLocks) { if (!_lockList.Contains(newLock)) { _lockList.Add(newLock); } } }
private List <WatchVariableControl> GetSnowParticleControls(int index) { uint structOffset = (uint)index * SnowConfig.ParticleStructSize; List <uint> offsets = new List <uint>() { structOffset + SnowConfig.XOffset, structOffset + SnowConfig.YOffset, structOffset + SnowConfig.ZOffset, }; List <string> names = new List <string>() { String.Format("Particle {0} X", index), String.Format("Particle {0} Y", index), String.Format("Particle {0} Z", index), }; List <WatchVariableControl> controls = new List <WatchVariableControl>(); for (int i = 0; i < 3; i++) { WatchVariable watchVar = new WatchVariable( name: names[i], memoryTypeName: "int", specialType: null, baseAddressType: BaseAddressTypeEnum.Snow, offsetUS: null, offsetJP: null, offsetSH: null, offsetEU: null, offsetDefault: offsets[i], mask: null, shift: null, handleMapping: true); WatchVariableControlPrecursor precursor = new WatchVariableControlPrecursor( name: names[i], watchVar: watchVar, subclass: WatchVariableSubclass.Number, backgroundColor: null, displayType: null, roundingLimit: null, useHex: null, invertBool: null, isYaw: null, coordinate: i == 0 ? Coordinate.X : i == 1 ? Coordinate.Y : Coordinate.Z, groupList: new List <VariableGroup>() { VariableGroup.Snow }); controls.Add(precursor.CreateWatchVariableControl()); } return(controls); }
/** * Gets user added variables from the mapping, * assuming they're suffixed with "_f32", "_s16", etc. */ public static List <WatchVariableControl> GetVariables() { if (mappingCurrent == null) { return(new List <WatchVariableControl>()); } List <WatchVariableControl> controls = new List <WatchVariableControl>(); foreach (uint address in mappingCurrent.Keys) { string stringValue = mappingCurrent[address]; (Type type, string name) = GetInfoIfUserAddedWord(stringValue); if (type == null) { continue; } string typeString = TypeUtilities.TypeToString[type]; WatchVariable watchVar = new WatchVariable( name: name, memoryTypeName: typeString, specialType: null, baseAddressType: BaseAddressTypeEnum.Relative, offsetUS: address, offsetJP: address, offsetSH: address, offsetEU: address, offsetDefault: null, mask: null, shift: null, handleMapping: false); WatchVariableControlPrecursor precursor = new WatchVariableControlPrecursor( name: name, watchVar: watchVar, subclass: WatchVariableSubclass.Number, backgroundColor: null, displayType: null, roundingLimit: null, useHex: null, invertBool: null, isYaw: null, coordinate: null, groupList: new List <VariableGroup>() { VariableGroup.Custom }); WatchVariableControl control = precursor.CreateWatchVariableControl(); controls.Add(control); } return(controls); }
public WatchVariableControl(ProcessStream stream, WatchVariable watchVar, uint otherOffset = 0) { _specialName = watchVar.Name; _watchVar = watchVar; _stream = stream; OtherOffset = otherOffset; CreateControls(); if (watchVar.BackroundColor.HasValue) { Color = watchVar.BackroundColor.Value; } }
public static byte[] GetByteData(this WatchVariable watchVar, uint offset) { // Get dataBytes var dataBytes = Config.Stream.ReadRamLittleEndian(watchVar.HasAdditiveOffset ? new UIntPtr(offset + watchVar.Address) : new UIntPtr(watchVar.Address), watchVar.ByteCount, watchVar.UseAbsoluteAddressing); // Make sure offset is a valid pointer if (watchVar.HasAdditiveOffset && offset == 0) { return(null); } return(dataBytes); }
public static byte[] GetByteData(this WatchVariable watchVar, ProcessStream stream, uint offset) { // Get dataBytes var byteCount = WatchVariable.TypeSize[watchVar.Type]; var dataBytes = stream.ReadRam(watchVar.OtherOffset ? offset + watchVar.Address : watchVar.Address, byteCount, watchVar.AbsoluteAddressing); // Make sure offset is a valid pointer if (watchVar.OtherOffset && offset == 0) { return(null); } return(dataBytes); }
/// <summary> /// Initializes a new instance of the form. (1) Positions the form; (2) displays the watch variable and current value; (3) displays the flag state /// corresponding to the current value of the watch variable. /// </summary> /// <param name="bitmaskControl">Reference to the bit mask control that called this form.</param> public FormShowFlags(VariableControl bitmaskControl) { InitializeComponent(); m_VariableControl = bitmaskControl; // Add this form to the list of opened dialog forms associated with the client form. m_ClientAsFormPTU = m_VariableControl.ClientForm as FormPTU; if (m_ClientAsFormPTU != null) { m_ClientAsFormPTU.OpenedDialogBoxList.Add(this); } // Register the event handler for the data update event. m_ClientAsIDataUpdate = m_VariableControl.ClientForm as IDataUpdate; if (m_ClientAsIDataUpdate != null) { m_ClientAsIDataUpdate.DataUpdate += new EventHandler(DataUpdate); } m_OldIdentifier = (short)m_VariableControl.Identifier; try { m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier]; if (m_WatchVariable == null) { throw new ArgumentException(Resources.MBTWatchVariableNotDefined); } } catch (Exception) { throw new ArgumentException(Resources.MBTWatchVariableNotDefined); } m_WatchVariableName = m_VariableControl.VariableNameFieldText; // Get a list of the current state of each flag and keep a record to determine if there is a change in state. List <FlagState_t> flagStateList = Lookup.WatchVariableTableByOldIdentifier.GetFlagStateList(m_OldIdentifier, m_PreviousValue = GetValue()); m_TableLayoutPanel = ConstructLayoutPanel(); m_PanelFlagList.Controls.Add(m_TableLayoutPanel); ConfigureTableLayoutPanel(m_TableLayoutPanel, flagStateList); UpdateTitle(m_WatchVariableName, GetValue()); UpdateFlagStates(m_TableLayoutPanel.Controls, flagStateList); CheckHeight(); PositionTheForm(m_VariableControl); }
/// <summary> /// Initializes a new instance of the class. /// </summary>. /// <param name="listBox">The ListBox control containing the chart recorder channel scaling information.</param> public FormChangeChartScale(ListBox listBox) { InitializeComponent(); Debug.Assert(listBox != null, "FormChangeChartScale.Ctor() - "); int oldIdentifier = ((WatchItem_t)listBox.SelectedItem).OldIdentifier; m_SelectedIndex = listBox.SelectedIndex; try { m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.RecordList[oldIdentifier]; if (m_WatchVariable == null) { throw new ArgumentException(); } Text = m_WatchVariable.Name; } catch (Exception) { throw new ArgumentException(Resources.MBTWatchVariableNotFound); } // Display the engineering units of the watch variable associated with the current channel. m_LabelUnitsMin.Text = m_WatchVariable.Units; m_LabelUnitsMax.Text = m_WatchVariable.Units; // Set the display format. if (m_WatchVariable.FormatString.ToLower().Equals(CommonConstants.DDFormatStringHex)) { m_HexFormat = true; } // Display the default upper and lower chart scale limits of the watch variable associated with the current channel. if (m_HexFormat == true) { m_LabelDefaultChartScaleMin.Text = CommonConstants.HexValueIdentifier + ((uint)m_WatchVariable.MinChartScale).ToString(CommonConstants.FormatStringHex); m_LabelDefaultChartScaleMax.Text = CommonConstants.HexValueIdentifier + ((uint)m_WatchVariable.MaxChartScale).ToString(CommonConstants.FormatStringHex); } else { m_LabelDefaultChartScaleMin.Text = m_WatchVariable.MinChartScale.ToString(CommonConstants.FormatStringNumeric); m_LabelDefaultChartScaleMax.Text = m_WatchVariable.MaxChartScale.ToString(CommonConstants.FormatStringNumeric); } m_LabelDefaultUnits.Text = m_WatchVariable.Units; }
/// <summary> /// Initialize a new instance of the class. /// </summary> /// <param name="watchControl">The watch control derived user control that called this form.</param> /// <exception cref="Exception">Thrown if the old Identifier associated with the control that called this form is not defined in the current data dictionary.</exception> public FormChangeWatch(WatchControl watchControl) { InitializeComponent(); m_WatchControl = watchControl; // Use the communication interface associated with the client form. m_ICommunicationInterface = m_WatchControl.ClientForm as ICommunicationInterface <ICommunicationWatch>; Debug.Assert(m_ICommunicationInterface != null); // Register the event handler for the data update event. m_IDataUpdate = m_WatchControl.ClientForm as IDataUpdate; if (m_IDataUpdate != null) { m_IDataUpdate.DataUpdate += new EventHandler(DataUpdate); } m_IPollTarget = m_WatchControl.ClientForm as IPollTarget; Debug.Assert(m_IPollTarget != null); m_OldIdentifier = (short)m_WatchControl.Identifier; try { m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier]; if (m_WatchVariable == null) { throw new ArgumentException(Resources.MBTWatchVariableNotDefined); } } catch (Exception) { throw new ArgumentException(Resources.MBTWatchVariableNotDefined); } m_WatchVariableName = m_WatchControl.VariableNameFieldText; Text = m_WatchVariableName; #region - [Units] - string units = m_WatchVariable.Units; m_LabelCurrentValueUnits.Text = units; m_LabelAllowableRangeUnits.Text = units; m_LabelNewValueUnits.Text = units; #endregion - [Units] - // Update the display by calling the DataUpdate event handler. DataUpdate(this, new EventArgs()); }
public static void SetBoolValue(this WatchVariable watchVar, uint offset, bool value) { // Get dataBytes var address = watchVar.HasAdditiveOffset ? offset + watchVar.Address : watchVar.Address; var dataBytes = watchVar.GetByteData(offset); // Make sure offset is a valid pointer if (dataBytes == null) { return; } if (watchVar.InvertBool) { value = !value; } // Get Uint64 value var intBytes = new byte[8]; dataBytes.CopyTo(intBytes, 0); UInt64 dataValue = BitConverter.ToUInt64(intBytes, 0); // Apply mask if (watchVar.Mask.HasValue) { if (value) { dataValue |= watchVar.Mask.Value; } else { dataValue &= ~watchVar.Mask.Value; } } else { dataValue = value ? 1U : 0U; } var writeBytes = new byte[watchVar.ByteCount]; var valueBytes = BitConverter.GetBytes(dataValue); Array.Copy(valueBytes, 0, writeBytes, 0, watchVar.ByteCount); Config.Stream.WriteRamLittleEndian(writeBytes, address, watchVar.UseAbsoluteAddressing); }
public VariableBitForm(string varName, WatchVariable watchVar, List <uint> fixedAddressList) { _varName = varName; _watchVar = watchVar; _fixedAddressList = fixedAddressList; _timer = new Timer { Interval = 30 }; InitializeComponent(); _textBoxVarName.Text = _varName; _bytes = new BindingList <ByteModel>(); for (int i = 0; i < watchVar.ByteCount.Value; i++) { _bytes.Add(new ByteModel(watchVar.ByteCount.Value - 1 - i, 0, _dataGridViewBits, this)); } _dataGridViewBits.DataSource = _bytes; _dataGridViewBits.CellContentClick += (sender, e) => _dataGridViewBits.CommitEdit(new DataGridViewDataErrorContexts()); ControlUtilities.SetTableDoubleBuffered(_dataGridViewBits, true); _reversedBytes = _bytes.ToList(); _reversedBytes.Reverse(); int effectiveTableHeight = ControlUtilities.GetTableEffectiveHeight(_dataGridViewBits); int totalTableHeight = _dataGridViewBits.Height; int emptyHeight = totalTableHeight - effectiveTableHeight + 3; Height -= emptyHeight; ControlUtilities.AddCheckableContextMenuStripItems( this, new List <string>() { "Show Value", "Show Float Components" }, new List <bool>() { false, true }, boolValue => _showFloatComponents = boolValue, false); _timer.Tick += (s, e) => UpdateForm(); _timer.Start(); }