public void OpenComponentScope(CodeRenderingContext context, string name, string type, string parameterName) { var scope = new ScopeEntry(name, ScopeKind.Component); _stack.Push(scope); var blazorNodeWriter = (BlazorNodeWriter)context.NodeWriter; blazorNodeWriter.BeginWriteAttribute(context.CodeWriter, name); OffsetBuilderVarNumber(1); // Writes code that looks like: // // builder.AddAttribute(0, "{name}", ({type})((__builder) => { ... })); // OR // builder.AddAttribute(0, "{name}", ({type})((context) => (__builder) => { ... })); context.CodeWriter.Write($"({type})("); if (parameterName != null) { context.CodeWriter.Write($"({parameterName}) => "); } scope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName); }
public void OpenTemplateScope(CodeRenderingContext context) { var currentScope = new ScopeEntry("__template", ScopeKind.Template); _stack.Push(currentScope); // Templates always get a lambda scope, because they are defined as a lambda. OffsetBuilderVarNumber(1); currentScope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName); }
public void SetScope(int strength) { foreach (ScopeEntry s in scopeEntries) { if (s.strength == strength) { currentScope = s; break; } } }
public void OpenComponentScope(CodeRenderingContext context, string name, string parameterName) { var scope = new ScopeEntry(name, ScopeKind.Component); _stack.Push(scope); OffsetBuilderVarNumber(1); // Writes code that looks like: // // ((__builder) => { ... }) // OR // ((context) => (__builder) => { ... }) if (parameterName != null) { context.CodeWriter.Write($"({parameterName}) => "); } scope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName); }
private void RecordScopeMapping(ReachableContext reachableContext) { foreach (var scope in reachableContext.ReachableTypes.GroupBy(g => g.Scope, g => g.Module.Assembly)) { var assm = scope.Distinct().ToList(); if (assm.Count > 1) { DLog.Warning(DContext.CompilerCodeGenerator, "More than one assembly for scope {0}", scope.Key.Name); // let's not risk a wrong mapping. continue; } var filename = assemblyToFilename(assm.First()); if (filename != null) { var scopeEntry = new ScopeEntry(scope.Key.Name, filename, File.GetLastWriteTimeUtc(filename), Hash.HashFileMD5(filename)); mapFile.Add(scopeEntry); } } }
private void DisplayCurrentWeapon(WeaponProfile p, ScopeEntry s) { settings.isLoading = true; setStatus("Updating current weapon display"); if (p == null) { labActiveWeapon.Text = "None"; setStatus("No weapon found"); } else { labActiveWeapon.Text = "" + p.name; setStatus("Weapon is now: " + p.name); } if (s == null) { labActiveScope.Text = "None"; nudCompensationAmount.Value = 0; nudCompensationDelay.Value = 0; nudFireRateDelay.Value = 0; nudActivationDelay.Value = 0; } else { labActiveScope.Text = "" + s.strength + "x"; nudCompensationAmount.Value = s.compensationAmount; nudCompensationDelay.Value = s.compensationDelay; nudFireRateDelay.Value = s.fireDelay; nudActivationDelay.Value = s.activationDelay; } settings.isLoading = false; }
private void bgwMain_DoWork(object sender, DoWorkEventArgs e) { int startTime; int nextFireTime; PlayerWeapon[] playerWeapons = new PlayerWeapon[2] { new PlayerWeapon(), new PlayerWeapon() }; startTime = 0; nextFireTime = 0; runMode = RunMode.RUN; bool doingNade = false; bool slept = false; int nextWindowTime = Environment.TickCount; IntPtr lastForegroundWindow = IntPtr.Zero; bool isGameActive = false; float brightnessMinimum; Point scopeStart1 = new Point(1586, 115); Point scopeStart2 = new Point(1586, 345); Point start = new Point(890, 920); Size area = new Size(140, 45); Size scopeArea = new Size(48, 43); List <ScopeMask> scopeMasks; int currentWeaponGameIndex = 1; SpeechSynthesizer speaker = new SpeechSynthesizer(); speaker.Volume = 100; brightnessMinimum = 0.80f; float scopeBrightnessMaximum = 0.15f; bool firedGun = false; int lastWeaponSlot = 1, currentWeaponSlot = 1; List <string> singleFireWeapons = new List <string>(new string[] { "awm", "crossbow", "kar98k", "m24" }); weaponMasks = new List <WeaponMask>(); scopeMasks = new List <ScopeMask>(); // Load the scope masks into objects foreach (string s in Directory.GetFiles("input images\\raw\\menu scopes")) { ScopeMask mask; Bitmap bmp; bmp = new Bitmap(s); mask = new ScopeMask(); mask.filename = s.Split("\\").Last().Split(".").First(); mask.points = new List <MaskPoint>(); for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x += 10) { Color pixel = bmp.GetPixel(x, y); if ((pixel.R == Color.Magenta.R && pixel.G == Color.Magenta.G && pixel.B == Color.Magenta.B) == false) { mask.points.Add(new MaskPoint(x, y, ((pixel.R + pixel.G + pixel.B) / 3.0f))); } } } mask.strength = int.Parse(mask.filename.Split(".").First().Split("-").First().Replace("x", "")); setStatus("Point count: " + mask.points.Count); bmp.Dispose(); scopeMasks.Add(mask); } scopeMasks = scopeMasks.OrderBy(x => x.points.Count).ToList(); scopeMasks.Reverse(); // Load the gun masks into objects foreach (string s in Directory.GetFiles("input images\\raw\\menu guns")) { WeaponMask mask; Bitmap bmp; bmp = new Bitmap(s); mask = new WeaponMask(); mask.filename = s.Split("\\").Last().Split(".").First().ToLower(); mask.points = new List <MaskPoint>(); for (int y = 0; y < bmp.Height; y += 1) { for (int x = 0; x < bmp.Width; x++) { Color pixel = bmp.GetPixel(x, y); if ((pixel.R == Color.Magenta.R && pixel.G == Color.Magenta.G && pixel.B == Color.Magenta.B) == false) { mask.points.Add(new MaskPoint(x, y, ((pixel.R + pixel.G + pixel.B) / 3.0f))); } } } mask.points.Sort((x, y) => { if (x.averagePixel == y.averagePixel) { return(0); } else if (x.averagePixel < y.averagePixel) { return(-1); } else { return(1); } }); mask.points.Reverse(); List <MaskPoint> final = new List <MaskPoint>(); for (int i = 0; i < mask.points.Count; i += mask.points.Count / 20) { final.Add(mask.points[i]); } mask.points = final; setStatus("Weapon Point count: " + mask.points.Count); bmp.Dispose(); weaponMasks.Add(mask); } weaponMasks = weaponMasks.OrderBy(x => x.points.Count).ToList(); weaponMasks.Reverse(); // Create the weapon profiles foreach (WeaponMask a in weaponMasks) { // If the profile doesn't exist yet if (weaponProfiles.Where(x => x.name == a.filename).FirstOrDefault() == null) { WeaponProfile p = new WeaponProfile(); p.name = a.filename; weaponProfiles.Add(p); } } // Add the scope profiles to each weapon foreach (WeaponProfile p in weaponProfiles) { foreach (ScopeMask s in scopeMasks) { // If it doesn't have an entry for that scope strength, then create one if (p.scopeEntries.Where(x => x.strength == s.strength).FirstOrDefault() == null) { ScopeEntry se = new ScopeEntry(); se.strength = s.strength; p.scopeEntries.Add(se); } } } Point ptGunMaskStart1 = new Point(1445, 158); Point ptGunMaskStart2 = new Point(1445, 388); Point ptScopeMaskStart1 = new Point(1585, 114); Point ptScopeMaskStart2 = new Point(1585, 344); List <string> screenshots; int lastScreenshotTime = 0; int nextCompensationTime = 0; bool requestingScreenshot = false; while (true) { try { if ((GetAsyncKeyState(Keys.Up) & 1) == 1) { nudIndex--; if (nudIndex < 0) { nudIndex = 0; } this.ActiveControl = null; foreach (NumericUpDown a in nudOptions) { a.BackColor = SystemColors.Control; } nudOptions[nudIndex].BackColor = Color.LightGray; } else if ((GetAsyncKeyState(Keys.Down) & 1) == 1) { nudIndex++; if (nudIndex > 3) { nudIndex = 3; } this.ActiveControl = null; foreach (NumericUpDown a in nudOptions) { a.BackColor = SystemColors.Control; } nudOptions[nudIndex].BackColor = Color.LightGray; } else if ((GetAsyncKeyState(Keys.Left) & 1) == 1) { if (nudOptions[nudIndex].Value > nudOptions[nudIndex].Minimum) { if (GetAsyncKeyState(Keys.LShiftKey) != 0) { nudOptions[nudIndex].Value = Math.Max(0, nudOptions[nudIndex].Value - 100); } else { nudOptions[nudIndex].Value -= 1; } } } else if ((GetAsyncKeyState(Keys.Right) & 1) == 1) { if (nudOptions[nudIndex].Value < nudOptions[nudIndex].Maximum) { if (GetAsyncKeyState(Keys.LShiftKey) != 0) { nudOptions[nudIndex].Value = Math.Min(nudOptions[nudIndex].Maximum, nudOptions[nudIndex].Value + 100); } else { nudOptions[nudIndex].Value += 1; } } } else if ((GetAsyncKeyState(Keys.D1) & 1) == 1) { currentWeaponSlot = 0; WeaponProfile p = weaponProfiles.Where(x => x.name == playerWeapons[currentWeaponSlot].name).FirstOrDefault(); ScopeEntry s = null; if (p != null) { s = p.scopeEntries.Where(x => x.strength == playerWeapons[currentWeaponSlot].scopeStrength).FirstOrDefault(); } DisplayCurrentWeapon(p, s); } else if ((GetAsyncKeyState(Keys.D2) & 1) == 1) { currentWeaponSlot = 1; WeaponProfile p = weaponProfiles.Where(x => x.name == playerWeapons[currentWeaponSlot].name).FirstOrDefault(); ScopeEntry s = null; if (p != null) { s = p.scopeEntries.Where(x => x.strength == playerWeapons[currentWeaponSlot].scopeStrength).FirstOrDefault(); } DisplayCurrentWeapon(p, s); } else if ((GetAsyncKeyState(Keys.D5) & 1) == 1 || (GetAsyncKeyState(Keys.G) & 1) == 1) { currentWeaponSlot = 4; DisplayCurrentWeapon(null, null); } else if ((GetAsyncKeyState(Keys.Tab) & 1) == 1) { AccurateSleep(0.3f); requestingScreenshot = true; } if (Environment.TickCount > nextWindowTime) { isGameActive = IsGameActive(); nextWindowTime = Environment.TickCount + 2000; } if (isGameActive == true || skipWindowCheck == true) { if (requestingScreenshot == true) { if (Environment.TickCount - lastScreenshotTime > 1000) { setStatus("Taking screenshot"); keybd_event((int)Keys.F12, 0x9e, 0, UIntPtr.Zero); Thread.Sleep(10); keybd_event((int)Keys.F12, 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero); Thread.Sleep(10); requestingScreenshot = false; } } // Process any screenshots in the folder screenshots = Directory.GetFiles("input images\\screenshots").ToList(); if (screenshots.Count > 0) { DirectBitmap rawTest = null; Thread.Sleep(25); screenshots[0] = screenshots[screenshots.Count - 1]; setStatus("Screenshot found"); for (int i = 0; i < 100; i++) { try { rawTest = new DirectBitmap(screenshots[0]); break; } catch (Exception x) { x.ToString(); Thread.Sleep(10); } } if (rawTest != null) { if (IsScreenshotInTabMenu(rawTest) == true) { // While the tab is open, keep screenshotting requestingScreenshot = true; WeaponProfile p; for (int i = 0; i < 2; i++) { p = null; setStatus("Checking slot: " + i); Point ptCurrentGunMaskStart, ptCurrentScopeMaskStart; if (i == 0) { ptCurrentGunMaskStart = ptGunMaskStart1; ptCurrentScopeMaskStart = ptScopeMaskStart1; } else { ptCurrentGunMaskStart = ptGunMaskStart2; ptCurrentScopeMaskStart = ptScopeMaskStart2; } //Image compare for a weapon match foreach (WeaponMask m in weaponMasks) { if (DoesMaskMatch(rawTest, ptCurrentGunMaskStart, m.points) == true) { p = WeaponMaskToProfile(m); int index = weaponMasks.IndexOf(m); weaponMasks.Insert(0, m); weaponMasks.RemoveAt(index + 1); break; } Thread.Sleep(1); } // if a weapon was matched if (p != null) { int scopeStrength = 1; bool updateDisplay = false; setStatus("Matched: " + p.name); if (playerWeapons[i].name != p.name) { //Process.Start(screenshots[0]); playerWeapons[i].name = p.name; string name = playerWeapons[i].name; if (name == "pp-19 bizon") { name = "P. P. Bizon"; } else if (name == "sks") { name = "S. K. S."; } else if (name == "aug") { name = "A. U. G."; } else if (name == "awm") { name = "A. W. M."; } else if (name == "slr") { name = "S. L. R."; } else if (name == "ak47") { name = "A. K. 47"; } speaker.SpeakAsync(name + " " + (i == 0 ? "first" : "second") + " slot"); updateDisplay = true; } foreach (ScopeMask s in scopeMasks) { if (DoesMaskMatch(rawTest, ptCurrentScopeMaskStart, s.points) == true) { setStatus("Matched scope: " + s.strength); scopeStrength = s.strength; int index = scopeMasks.IndexOf(s); scopeMasks.Insert(0, s); scopeMasks.RemoveAt(index + 1); if (cbBabyMode.Checked == true) { if (scopeStrength > 2) { scopeStrength = 2; } } break; } Thread.Sleep(1); } if (playerWeapons[i].scopeStrength != scopeStrength) { playerWeapons[i].scopeStrength = scopeStrength; speaker.SpeakAsync(playerWeapons[i].scopeStrength + " X. " + (i == 0 ? "first" : "second") + " slot"); updateDisplay = true; } if (updateDisplay == true) { WeaponProfile p2 = weaponProfiles.Where(x => x.name == playerWeapons[currentWeaponSlot].name).FirstOrDefault(); ScopeEntry s2 = null; if (p2 != null) { s2 = p2.scopeEntries.Where(x => x.strength == playerWeapons[currentWeaponSlot].scopeStrength).FirstOrDefault(); } DisplayCurrentWeapon(p2, s2); } } } } } if (rawTest != null) { rawTest.Dispose(); } setStatus("Deleting screenshots"); foreach (string s in screenshots) { try { File.Delete(s); } catch (Exception x) { x.ToString(); } } setStatus("Finished deleting"); } if ((GetAsyncKeyState(Keys.LButton) != 0) && GetAsyncKeyState(Keys.RButton) == 0 && doingNade == false) { keybd_event((int)'L', 0x9e, 0, UIntPtr.Zero); doingNade = true; } // if its attempt to do a nade if (doingNade == true) { if ((GetAsyncKeyState(Keys.LButton) == 0) && GetAsyncKeyState(Keys.RButton) == 0) { keybd_event((int)'L', 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero); doingNade = false; } } // If its attempting to spray or is simulating a spray if (GetAsyncKeyState(Keys.LButton) != 0 && GetAsyncKeyState(Keys.RButton) != 0 && currentWeaponSlot < 2) { if (startTime == 0) { startTime = Environment.TickCount; } //If the fire button has been held long enough to activate compensation if (Environment.TickCount - startTime > nudActivationDelay.Value) { WeaponProfile currentWeaponProfile; currentWeaponProfile = weaponProfiles.Where(x => x.name == playerWeapons[currentWeaponSlot].name).FirstOrDefault(); // If there is a weapon selected if (currentWeaponProfile != null) { ScopeEntry currentScopeEntry; currentScopeEntry = currentWeaponProfile.scopeEntries.Where(x => x.strength == playerWeapons[currentWeaponSlot].scopeStrength).FirstOrDefault(); // If there is a scope available if (currentScopeEntry != null) { if (Environment.TickCount >= nextCompensationTime) { mouse_event(MOUSEEVENTF_MOVE, 0, currentScopeEntry.compensationAmount, 0, UIntPtr.Zero); nextCompensationTime = Environment.TickCount + currentScopeEntry.compensationDelay; } if (Environment.TickCount >= nextFireTime) { keybd_event((int)'L', 0x9e, 0, UIntPtr.Zero); nextFireTime = Environment.TickCount + (int)currentScopeEntry.fireDelay; Thread.Sleep(25); } else { // Do not try to auto fire on a gun that cannot be autofired if (singleFireWeapons.IndexOf(currentWeaponProfile.name) == -1) { keybd_event((int)'L', 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero); } } } } } } else { // if it didn't shoot if (startTime != 0 && nextFireTime == 0) { keybd_event((int)'L', 0x9e, 0, UIntPtr.Zero); Thread.Sleep(25); keybd_event((int)'L', 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero); } // If it did shoot, reset the fire key just in case else if (nextFireTime != 0) { keybd_event((int)'L', 0x9e, KEYEVENTF_KEYUP, UIntPtr.Zero); } startTime = 0; nextFireTime = 0; } } } catch (Exception x) { MessageBox.Show(x.ToString()); } Thread.Sleep(1); } }