/// <summary> /// Converts a value to a <see cref="byte"/>. /// </summary> /// <param name="value">The object to convert.</param> /// <returns>The converted <paramref name="value"/>.</returns> public byte ToByte(object value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } return(SConvert.ToByte(value, CultureInfo.InvariantCulture)); }
private static void RegisterDoubleConversions( ITypeConverterRegistry registry) { registry.Register <double, byte>(from => SysConv.ToByte(from)); registry.Register <double, short>(from => SysConv.ToInt16(from)); registry.Register <double, int>(from => SysConv.ToInt32(from)); registry.Register <double, long>(from => SysConv.ToInt64(from)); registry.Register <double, ushort>(from => SysConv.ToUInt16(from)); registry.Register <double, uint>(from => SysConv.ToUInt32(from)); registry.Register <double, ulong>(from => SysConv.ToUInt64(from)); registry.Register <double, decimal>(from => SysConv.ToDecimal(from)); registry.Register <double, float>(from => SysConv.ToSingle(from)); registry.Register <double, string>(from => from.ToString(CultureInfo.InvariantCulture)); }
private static void RegisterSingleConversions( DefaultTypeConverter registry) { registry.Register <float, byte>(from => SysConv.ToByte(from)); registry.Register <float, short>(from => SysConv.ToInt16(from)); registry.Register <float, int>(from => SysConv.ToInt32(from)); registry.Register <float, long>(from => SysConv.ToInt64(from)); registry.Register <float, ushort>(from => SysConv.ToUInt16(from)); registry.Register <float, uint>(from => SysConv.ToUInt32(from)); registry.Register <float, ulong>(from => SysConv.ToUInt64(from)); registry.Register <float, decimal>(from => SysConv.ToDecimal(from)); registry.Register <float, double>(from => SysConv.ToDouble(from)); registry.Register <float, string>(from => from.ToString(CultureInfo.InvariantCulture)); }
public P2PMessage MakeMsg() { P2PMessage msg = new P2PMessage(); if (isForOtherPlayer) { msg.WriteByte((byte)MessageType.OtherHandGunChange); msg.WriteByte(playerId); } else { msg.WriteByte((byte)MessageType.HandGunChange); } msg.WriteByte(Convert.ToByte(destroy)); msg.WriteByte((byte)type); return(msg); }
/// <summary> /// 16 hex string converted to byte array /// </summary> /// <param name="hexString">16 hex string</param> /// <returns>byte array</returns> private static byte[] HexStringToBytes(string hexString) { if (hexString == null || string.IsNullOrEmpty(hexString)) { return(null); } var length = hexString.Length / 2; if (hexString.Length % 2 != 0) { return(null); } var d = new byte[length]; for (var i = 0; i < length; i++) { d[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16); } return(d); }
private void init() { int i, j; byte [] delim = new byte[3]; byte [] buf = new byte[SEGMENT_RECORD_LENGTH]; databaseType = (byte)DatabaseInfo.COUNTRY_EDITION; recordLength = STANDARD_RECORD_LENGTH; //file.Seek(file.Length() - 3,SeekOrigin.Begin); file.Seek(-3, SeekOrigin.End); for (i = 0; i < STRUCTURE_INFO_MAX_SIZE; i++) { file.Read(delim, 0, 3); if (delim[0] == 255 && delim[1] == 255 && delim[2] == 255) { databaseType = Convert.ToByte(file.ReadByte()); if (databaseType >= 106) { // Backward compatibility with databases from April 2003 and earlier databaseType -= 105; } // Determine the database type. if (databaseType == DatabaseInfo.REGION_EDITION_REV0) { databaseSegments = new int[1]; databaseSegments[0] = STATE_BEGIN_REV0; recordLength = STANDARD_RECORD_LENGTH; } else if (databaseType == DatabaseInfo.REGION_EDITION_REV1) { databaseSegments = new int[1]; databaseSegments[0] = STATE_BEGIN_REV1; recordLength = STANDARD_RECORD_LENGTH; } else if (databaseType == DatabaseInfo.CITY_EDITION_REV0 || databaseType == DatabaseInfo.CITY_EDITION_REV1 || databaseType == DatabaseInfo.ORG_EDITION || databaseType == DatabaseInfo.ISP_EDITION || databaseType == DatabaseInfo.ASNUM_EDITION) { databaseSegments = new int[1]; databaseSegments[0] = 0; if (databaseType == DatabaseInfo.CITY_EDITION_REV0 || databaseType == DatabaseInfo.CITY_EDITION_REV1) { recordLength = STANDARD_RECORD_LENGTH; } else { recordLength = ORG_RECORD_LENGTH; } file.Read(buf, 0, SEGMENT_RECORD_LENGTH); for (j = 0; j < SEGMENT_RECORD_LENGTH; j++) { databaseSegments[0] += (unsignedByteToInt(buf[j]) << (j * 8)); } } break; } else { //file.Seek(file.getFilePointer() - 4); file.Seek(-4, SeekOrigin.Current); //file.Seek(file.position-4,SeekOrigin.Begin); } } if ((databaseType == DatabaseInfo.COUNTRY_EDITION) | (databaseType == DatabaseInfo.PROXY_EDITION) | (databaseType == DatabaseInfo.NETSPEED_EDITION)) { databaseSegments = new int[1]; databaseSegments[0] = COUNTRY_BEGIN; recordLength = STANDARD_RECORD_LENGTH; } if ((dboptions & GEOIP_MEMORY_CACHE) == 1) { int l = (int)file.Length; dbbuffer = new byte[l]; file.Seek(0, SeekOrigin.Begin); file.Read(dbbuffer, 0, l); } }
public MainWindow() { InitializeComponent(); _tempsize = DensityScrollViewer.ContentHorizontalOffset; Closing += (s, e) => ViewModelLocator.Cleanup(); Messenger.Default.Register <DataRoad>(this, "ShowInfo", message => { Info = message; }); Messenger.Default.Register <float>(this, "ShowInfoDistance", message => { Distance = message; }); Messenger.Default.Register <ObservableCollection <Graphics> >(this, "ShowGeneralGraff", message => GeneralGraff.DrawGraphic(message, collor = true)); var timer = new System.Windows.Threading.DispatcherTimer { Interval = new TimeSpan(0, 0, 1), IsEnabled = true }; timer.Tick += (o, t) => { TimeBlock.Text = " " + DateTime.Now.ToLongTimeString() + "\n" + DateTime.Now.ToLongDateString(); }; timer.Start(); Messenger.Default.Register <List <List <object> > >(this, "GreatGraphic", message => { LineSeries LS; AreaSeries AS; ColumnSeries CL; List <byte> CountGener; List <float> Distance; List <float> Layer123; List <double> Plotnost; List <Graphics> dataValues; LinearAxis linerAxx; LinearAxis linerAxy; Setter setter; Style style; Style legendStyle; Setter legendSetterw; Setter legendSetterl; AreaDataPoint areaDataPoint; int max; Control control; LineDataPoint lineDataPoint; Setter setterpoint; switch (_greatGraphicName) { case "CountChart": CountGener = new List <byte>(); Distance = new List <float>(); foreach (var count in message[0]) { CountGener.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); for (var i = 0; i < CountGener.Count - 1; i++) { var graph = new Graphics(); graph.CountLayer = CountGener[i]; graph.Distance = Distance[i]; dataValues.Add(graph); } setter = new Setter(); setter.Property = BackgroundProperty; setter.Value = Brushes.Black; style = new Style(); var columnDataPoint = new ColumnDataPoint(); style.TargetType = columnDataPoint.GetType(); style.Setters.Add(setter); CL = new ColumnSeries { ItemsSource = dataValues, DependentValuePath = "CountLayer", IndependentValuePath = "Distance" }; CL.DataPointStyle = style; linerAxx = new LinearAxis(); linerAxy = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Minimum = 0; linerAxy.Maximum = 4; linerAxx.Title = "Расстояние, [м]"; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Количество слоёв", }; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(CL); LayoutRoot.Children.Add(chart); break; case "ChartLayer3": Layer123 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer123.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer123[0]); for (var i = 0; i < Layer123.Count - 1; i++) { var graph = new Graphics(); graph.Layer3 = Layer123[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer123[i] > max) { max = Convert.ToInt16(Layer123[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоя №1", }; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.DodgerBlue; style = new Style(); areaDataPoint = new AreaDataPoint(); style.TargetType = areaDataPoint.GetType(); style.Setters.Add(setterpoint); style.Setters.Add(setter); AS = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer3", IndependentValuePath = "Distance", }; AS.DataPointStyle = style; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(AS); LayoutRoot.Children.Add(chart); break; case "ChartLayer2": Layer123 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer123.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer123[0]); for (var i = 0; i < Layer123.Count - 1; i++) { var graph = new Graphics(); graph.Layer2 = Layer123[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer123[i] > max) { max = Convert.ToInt16(Layer123[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоя №2", }; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.DarkRed; style = new Style(); areaDataPoint = new AreaDataPoint(); style.TargetType = areaDataPoint.GetType(); style.Setters.Add(setter); style.Setters.Add(setterpoint); AS = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer2", IndependentValuePath = "Distance" }; AS.DataPointStyle = style; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(AS); LayoutRoot.Children.Add(chart); break; case "ChartLayer1": Layer123 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer123.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer123[0]); for (var i = 0; i < Layer123.Count - 1; i++) { var graph = new Graphics(); graph.Layer1 = Layer123[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer123[i] > max) { max = Convert.ToInt16(Layer123[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.OliveDrab; style = new Style(); areaDataPoint = new AreaDataPoint(); style.TargetType = areaDataPoint.GetType(); style.Setters.Add(setter); style.Setters.Add(setterpoint); AS = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer1", IndependentValuePath = "Distance" }; AS.DataPointStyle = style; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоя №3", }; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(AS); LayoutRoot.Children.Add(chart); break; case "ChartAll": var Layer1 = new List <float>(); var Layer2 = new List <float>(); var Layer3 = new List <float>(); Distance = new List <float>(); foreach (var count in message[0]) { Layer1.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } foreach (var count in message[2]) { Layer2.Add(Convert.ToByte(count)); } foreach (var count in message[3]) { Layer3.Add(Convert.ToByte(count)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Layer3[0]); for (var i = 0; i < Layer1.Count - 1; i++) { var graph = new Graphics(); graph.Layer3 = Layer3[i]; graph.Layer2 = Layer2[i]; graph.Layer1 = Layer1[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Layer3[i] > max) { max = Convert.ToInt16(Layer3[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "Толщина, [см]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; //// var setter1 = new Setter(); var setterpoint1 = new Setter(); setterpoint1.Property = OpacityProperty; setterpoint1.Value = (double)0; setter1.Property = BackgroundProperty; setter1.Value = Brushes.OliveDrab; var style1 = new Style(); var areaDataPoint1 = new AreaDataPoint(); style1.TargetType = areaDataPoint1.GetType(); style1.Setters.Add(setter1); style1.Setters.Add(setterpoint1); var ser1 = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer1", IndependentValuePath = "Distance", Title = "Слой №3" }; ser1.DataPointStyle = style1; /// var setter2 = new Setter(); var setterpoint2 = new Setter(); setterpoint2.Property = OpacityProperty; setterpoint2.Value = (double)0; setter2.Property = BackgroundProperty; setter2.Value = Brushes.DarkRed; var style2 = new Style(); var areaDataPoint2 = new AreaDataPoint(); style2.TargetType = areaDataPoint2.GetType(); style2.Setters.Add(setter2); style2.Setters.Add(setterpoint2); var ser2 = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer2", IndependentValuePath = "Distance", Title = "Слой №2" }; ser2.DataPointStyle = style2; /// var setter3 = new Setter(); var setterpoint3 = new Setter(); setterpoint3.Property = OpacityProperty; setterpoint3.Value = (double)0; setter3.Property = BackgroundProperty; setter3.Value = Brushes.DodgerBlue; var style3 = new Style(); var areaDataPoint3 = new AreaDataPoint(); style3.TargetType = areaDataPoint3.GetType(); style3.Setters.Add(setter3); style3.Setters.Add(setterpoint3); var ser3 = new AreaSeries { ItemsSource = dataValues, DependentValuePath = "Layer3", IndependentValuePath = "Distance", Title = "Слой №1" }; ser3.DataPointStyle = style3; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Толщина слоёв", }; var setterlegendcollor = new Setter(); var setterlegendborder = new Setter(); setterlegendcollor.Property = BackgroundProperty; setterlegendcollor.Value = new SolidColorBrush(Color.FromRgb(3, 94, 129)); setterlegendborder.Property = BorderBrushProperty; setterlegendborder.Value = new SolidColorBrush(Color.FromRgb(3, 94, 129)); legendStyle = new Style(); control = new Control(); legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(setterlegendcollor); legendStyle.Setters.Add(setterlegendborder); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(ser3); chart.Series.Add(ser2); chart.Series.Add(ser1); LayoutRoot.Children.Add(chart); break; case "Plotnost": Plotnost = new List <double>(); Distance = new List <float>(); foreach (var count in message[0]) { Plotnost.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } dataValues = new List <Graphics>(); max = Convert.ToInt16(Plotnost[0]); for (var i = 0; i < Plotnost.Count - 1; i++) { var graph = new Graphics(); graph.IntensityN1 = Plotnost[i]; graph.Distance = Distance[i]; dataValues.Add(graph); if (Plotnost[i] > max) { max = Convert.ToInt16(Plotnost[i]); } } linerAxx = new LinearAxis(); linerAxx.Orientation = AxisOrientation.X; linerAxx.ShowGridLines = true; linerAxx.Title = "Расстояние, [м]"; linerAxy = new LinearAxis(); linerAxy.Orientation = AxisOrientation.Y; linerAxy.ShowGridLines = true; linerAxy.Title = "[кг/м^3]"; linerAxy.Minimum = 0; linerAxy.Maximum = max + 2; setter = new Setter(); setterpoint = new Setter(); setterpoint.Property = OpacityProperty; setterpoint.Value = (double)0; setter.Property = BackgroundProperty; setter.Value = Brushes.OliveDrab; style = new Style(); lineDataPoint = new LineDataPoint(); style.TargetType = lineDataPoint.GetType(); style.Setters.Add(setter); style.Setters.Add(setterpoint); LS = new LineSeries() { ItemsSource = dataValues, DependentValuePath = "IntensityN1", IndependentValuePath = "Distance" }; LS.DataPointStyle = style; chart = new Chart() { Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)), Title = "Плотность", }; legendSetterw = new Setter(); legendSetterl = new Setter(); legendStyle = new Style(); control = new Control(); legendSetterw.Property = WidthProperty; legendSetterw.Value = (double)0; legendSetterl.Property = HeightProperty; legendSetterl.Value = (double)0; legendStyle.TargetType = control.GetType(); legendStyle.Setters.Add(legendSetterl); legendStyle.Setters.Add(legendSetterw); chart.LegendStyle = legendStyle; chart.Axes.Add(linerAxx); chart.Axes.Add(linerAxy); chart.MouseLeftButtonDown += MouseLeftButtonDownGrid; chart.Series.Add(LS); LayoutRoot.Children.Add(chart); break; case "GeneralGraff": CountGener = new List <byte>(); Distance = new List <float>(); foreach (var count in message[0]) { CountGener.Add(Convert.ToByte(count)); } foreach (var distance in message[1]) { Distance.Add(Convert.ToSingle(distance)); } var dataValues1 = new ObservableCollection <Graphics>(); for (var i = 0; i < CountGener.Count - 1; i++) { var graph = new Graphics(); graph.GeneralState = CountGener[i]; graph.Distance = Distance[i]; dataValues1.Add(graph); } Gridnorm = new Grid(); Gridd = new Graff(); Gridd.DrawGraphic(dataValues1, collor = false); Gridd.Width = 1111; Gridd.Height = 234; var text1 = new TextBlock(); var text2 = new TextBlock(); var collor1 = new TextBlock(); var collor2 = new TextBlock(); var collortext1 = new TextBlock(); var collortext2 = new TextBlock(); collor1.Background = Brushes.Red; collor2.Background = Brushes.Green; collor1.Width = 50; collor1.Height = 50; collor2.Width = 50; collor2.Height = 50; collor1.HorizontalAlignment = HorizontalAlignment.Left; collor1.VerticalAlignment = VerticalAlignment.Top; collor2.HorizontalAlignment = HorizontalAlignment.Left; collor2.VerticalAlignment = VerticalAlignment.Top; collor1.Margin = new Thickness(370, 650, 0, 0); collor2.Margin = new Thickness(690, 650, 0, 0); collortext1.Text = "- не соответствует"; collortext2.Text = "- соответствует"; collortext1.FontSize = 19; collortext2.FontSize = 19; collortext1.HorizontalAlignment = HorizontalAlignment.Left; collortext1.VerticalAlignment = VerticalAlignment.Top; collortext2.HorizontalAlignment = HorizontalAlignment.Left; collortext2.VerticalAlignment = VerticalAlignment.Top; collortext1.Margin = new Thickness(440, 657, 0, 0); collortext2.Margin = new Thickness(760, 657, 0, 0); text1.Text = "Общее состояние дорожного покрытия"; text2.Text = "Расстояние, [м]"; text2.FontStyle = FontStyles.Italic; text1.FontSize = 22; text2.FontSize = 19; text1.HorizontalAlignment = HorizontalAlignment.Left; text1.VerticalAlignment = VerticalAlignment.Top; text2.HorizontalAlignment = HorizontalAlignment.Left; text2.VerticalAlignment = VerticalAlignment.Top; text1.Margin = new Thickness(440, 350, 0, 0); text2.Margin = new Thickness(570, 530, 0, 0); Gridnorm.Children.Add(collortext1); Gridnorm.Children.Add(collortext2); Gridnorm.Children.Add(collor1); Gridnorm.Children.Add(collor2); Gridnorm.Children.Add(text1); Gridnorm.Children.Add(text2); Gridnorm.Children.Add(Gridd); Gridnorm.Background = new SolidColorBrush(Color.FromRgb(3, 94, 129)); LayoutRoot.Children.Add(Gridnorm); Gridnorm.MouseLeftButtonDown += MouseLeftButtonDownGrid1; Gridd.MouseLeftButtonDown += MouseLeftButtonDownGrid1; break; } }); }
} = new ProfileNetwork(); /* connection types & server/client ports */ /// <summary> /// Saves object state to the inbound file. /// </summary> public void Save() { /** * We first open up a binary writer for storing the configuration in the blam.sav binary. Data is all written in * one go to the binary on the filesystem. */ using (var fs = new FileStream(Path, FileMode.Open, FileAccess.ReadWrite)) using (var ms = new MemoryStream(8192)) using (var bw = new BinaryWriter(ms)) { void WriteBoolean(Offset offset, bool data) { ms.Position = (int)offset - 1; bw.Write(data); } void WriteInteger(Offset offset, int data) { ms.Position = (int)offset - 1; bw.Write(data); } fs.Position = 0; fs.CopyTo(ms); /** * The name is stored in UTF-16; hence, we rely on the Unicode class to encode the string to a byte array for * writing the profile name in the binary. */ ms.Position = (int)Offset.ProfileName; bw.Write(Encoding.Unicode.GetBytes(Details.Name)); /** * First, we'll take care of the enum options. Storing them is rather straightforward: we cast their values to * integers, which can be then written to the binary. */ WriteInteger(Offset.ProfileColour, (int)Details.Colour); WriteInteger(Offset.VideoFrameRate, (int)Video.FrameRate); WriteInteger(Offset.VideoQualityParticles, (int)Video.Particles); WriteInteger(Offset.VideoQualityTextures, (int)Video.Quality); WriteInteger(Offset.AudioQuality, (int)Audio.Quality); WriteInteger(Offset.AudioVariety, (int)Audio.Variety); WriteInteger(Offset.NetworkConnectionType, (int)Network.Connection); /** * The following values are values which can have any integer (within the limits of the data types, of course). */ WriteInteger(Offset.MouseSensitivityHorizontal, Mouse.Sensitivity.Horizontal); WriteInteger(Offset.MouseSensitivityVertical, Mouse.Sensitivity.Vertical); WriteInteger(Offset.VideoResolutionWidth, Video.Resolution.Width); WriteInteger(Offset.VideoResolutionHeight, Video.Resolution.Height); WriteInteger(Offset.VideoRefreshRate, Video.RefreshRate); WriteInteger(Offset.VideoMiscellaneousGamma, Video.Gamma); WriteInteger(Offset.AudioVolumeMaster, Audio.Volume.Master); WriteInteger(Offset.AudioVolumeEffects, Audio.Volume.Effects); WriteInteger(Offset.AudioVolumeMusic, Audio.Volume.Music); WriteInteger(Offset.NetworkPortServer, Network.Port.Server); WriteInteger(Offset.NetworkPortClient, Network.Port.Client); /* * As for the boolean values, we convert them behind the scene to their integer equivalents -- 1 and 0 for true * and false, respectively. */ WriteBoolean(Offset.MouseInvertVerticalAxis, Mouse.InvertVerticalAxis); WriteBoolean(Offset.VideoEffectsSpecular, Video.Effects.Specular); WriteBoolean(Offset.VideoEffectsShadows, Video.Effects.Shadows); WriteBoolean(Offset.VideoEffectsDecals, Video.Effects.Decals); WriteBoolean(Offset.AudioEAX, Audio.EAX); WriteBoolean(Offset.AudioHWA, Audio.HWA); /** * The layout of the blam.sav is, in a nutshell: * * [0x0000 - 0x1005] [0x1FFC - 0x2000] * | | * | + - hash data (4 bytes) * + ------------------- main data (8188 bytes) * * By ... * * 1. truncating the last four bytes (the hash) from the memory stream; then * 2. calculating the hash for the main data (i.e. remaining bytes); then * 3. appending it to the memory stream (i.e. replacing the old hash) ... * * ... we can write the contents to filesystem and expect HCE to accept both the data and the new hash. */ Console.Info("Truncating CRC32 checksum from memory stream"); ms.SetLength(ms.Length - 4); Console.Info("Calculating new CRC32 checksum"); var hash = GetHash(ms.ToArray()); Console.Debug("New CRC32 hash - 0x" + BitConverter.ToString(hash).Replace("-", string.Empty)); Console.Info("Appending new CRC32 checksum to memory stream"); ms.SetLength(ms.Length + 4); ms.Position = (int)Offset.BinaryCrc32Hash; bw.Write(hash); Console.Info("Clearing contents of the profile filesystem binary"); fs.SetLength(0); Console.Info("Copying profile data in memory to the binary file"); ms.Position = 0; ms.CopyTo(fs); Console.Info("Saved profile data to the binary on the filesystem"); /** * This method returns a forged CRC-32 hash which can be written to the end of the blam.sav binary. This allows * the binary to be considered valid by HCE. By forged hash, we refer to the bitwise complement of a CRC-32 hash * of the blam.sav data. */ byte[] GetHash(byte[] data) { /** * This look-up table has been generated from the standard 0xEDB88320 polynomial, which results in hashes that * HCE deems valid. The aforementioned polynomial is the reversed equivalent of 0x04C11DB7, and is used, well, * everywhere! */ var crcTable = new uint[] { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D }; /** * With the available data, we conduct a basic cyclic redundancy check operation on it, using the * aforementioned look-up table. This provides us with the CRC-32 for the main data in the blam.sav binary. * * However, possibly for obfuscation, HCE stores the complement (bitwise NOT) of the hash. This requires us to * flip each bit in the entire hash. Once we've done that, we are left with the desired hash that can be * stored in the blam.sav binary. */ var hashData = BitConverter.GetBytes(~data.Aggregate(0xFFFFFFFF, (checksumRegister, currentByte) => crcTable[(checksumRegister & 0xFF) ^ Convert.ToByte(currentByte)] ^ (checksumRegister >> 8))); for (var i = 0; i < hashData.Length; i++) { hashData[i] = (byte)~hashData[i]; } return(hashData); } } }
protected static internal object ConvertValue(Type type, NSJSValue value) { if (type == null) { throw new ArgumentNullException("type"); } object o = FetchValue(type, value); if (type == typeof(int)) { o = (o == null ? 0 : Converter.ToInt32(o)); } else if (type == typeof(uint)) { o = (o == null ? 0u : Converter.ToUInt32(o)); } else if (type == typeof(short)) { o = (o == null ? (short)0 : Converter.ToInt16(o)); } else if (type == typeof(ushort)) { o = (o == null ? (ushort)0 : Converter.ToUInt16(o)); } else if (type == typeof(sbyte)) { o = (o == null ? (sbyte)0 : Converter.ToSByte(o)); } else if (type == typeof(byte)) { o = (o == null ? (byte)0 : Converter.ToByte(o)); } else if (type == typeof(long)) { o = (o == null ? 0L : Converter.ToInt64(o)); } else if (type == typeof(ulong)) { o = (o == null ? 0ul : Converter.ToUInt64(o)); } else if (type == typeof(float)) { o = (o == null ? 0f : Converter.ToSingle(o)); } else if (type == typeof(double)) { o = (o == null ? 0d : Converter.ToDouble(o)); } else if (type == typeof(decimal)) { o = (o == null ? 0m : Converter.ToDecimal(o)); } else if (type == typeof(char)) { o = (o == null ? '\0' : Converter.ToChar(o)); } else if (type == typeof(DateTime)) { long ticks = 0; if (o is long) { ticks = (long)o; } else if (o != null) { ticks = Converter.ToInt64(o); } o = NSJSDateTime.LocalDateToDateTime(ticks); } else if (type == typeof(string)) { if (o == null) { o = null; } else if (!(o is string)) { o = o.ToString(); } } else if (typeof(NSJSValue).IsAssignableFrom(type)) { return(type.IsInstanceOfType(value) ? value : null); } return(o); }
public byte ToByte(object value) => SystemConvert.ToByte(value);
/// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.IConvertible.ToByte"]/*' /> /// <internalonly/> byte IConvertible.ToByte(IFormatProvider provider) { return Convert.ToByte(m_value); }
byte IConvertible.ToByte (IFormatProvider provider) { return Convert.ToByte (Value, provider); }
byte IConvertible.ToByte(IFormatProvider provider) { return(Convert.ToByte((float)this)); }