/// <summary> /// Used only by the Save class. /// </summary> bool _SaveStateNow() { if (DB == null) { return(true); } try { using (var trans = DB.Transaction()) { DB.Execute("REPLACE INTO _misc VALUES ('expanded',?)", string.Join(" ", Root.Descendants().Where(n => n.IsExpanded).Select(n => n.IdString))); using (new StringBuilder_(out var b)) { var a = OpenFiles; b.Append(a.IndexOf(_currentFile)); foreach (var v in a) { b.Append(' ').Append(v.IdString); //FUTURE: also save current position and scroll position, eg "id.pos.scroll" } DB.Execute("REPLACE INTO _misc VALUES ('open',?)", b.ToString()); } trans.Commit(); } return(true); } catch (SLException ex) { Debug_.Print(ex); return(false); } }
/// <summary> /// Writes a string result for the task that called <see cref="runWait(out string, string, string[])"/> or <see cref="runWait(Action{string}, string, string[])"/> to run this task, or for the program that started this task using command line like "Au.Editor.exe *Script5.cs". /// Returns false if this task was not started in such a way. Returns false if failed to write, except when <i>s</i> is null/"". /// </summary> /// <param name="s">A string. This function does not append newline characters.</param> /// <remarks> /// <see cref="runWait(Action{string}, string, string[])"/> can read the string in real time. /// <see cref="runWait(out string, string, string[])"/> gets all strings joined when the task ends. /// The program that started this task using command line like "Au.Editor.exe *Script5.cs" can read the string from the redirected standard output in real time, or the string is displayed to its console in real time. The string encoding is UTF8; if you use a .bat file or cmd.exe and want to get correct Unicode text, execute this before, to change console code page to UTF-8: <c>chcp 65001</c>. /// </remarks> #if true public static unsafe bool writeResult(string s) { s_wrPipeName ??= Environment.GetEnvironmentVariable("script.writeResult.pipe"); if (s_wrPipeName == null) { return(false); } if (s.NE()) { return(true); } if (Api.WaitNamedPipe(s_wrPipeName, 3000)) //15 mcs { using var pipe = Api.CreateFile(s_wrPipeName, Api.GENERIC_WRITE, 0, default, Api.OPEN_EXISTING, 0); //7 mcs if (!pipe.Is0) { fixed(char *p = s) if (Api.WriteFile(pipe, p, s.Length * 2, out _)) { return(true); //17 mcs } } } Debug_.PrintNativeError_(); return(false); //SHOULDDO: optimize. Eg the app may override TextWriter.Write(char) and call this on each char in a string etc. // Now 40 mcs. Console.Write(char) 20 mcs. }
private static int Balance(SortedInt32KeyNode <TValue> tree) { Requires.NotNull(tree, "tree"); Debug_.Assert(!tree.IsEmpty); return(tree._right._height - tree._left._height); }
/// <summary> /// If possible, gets whether the window is DPI-scaled/virtualized, and gets physical and logical rects if scaled. /// Returns false if !osVersion.minWin10_1607 or if cannot get that info. /// Gets that info in a fast and reliable way. /// </summary> internal static bool GetScalingInfo_(wnd w, out bool scaled, out RECT rPhysical, out RECT rLogical) { scaled = false; rPhysical = default; rLogical = default; if (!osVersion.minWin10_1607) { return(false); } var awareness = WindowDpiAwareness(w); //fast on Win10 if (awareness is Awareness.System or Awareness.Unaware) //tested: unaware-gdi-scaled same as unaware { if (awareness == Awareness.System && Api.GetDpiForWindow(w) != System) /*fast*/ //Cannot get rLogical. It's rare and temporary, ie when the user recently changed DPI of the primary screen. //Even if this func isn't used to get rects, without this fast code could be unreliable. { Debug_.Print("w System DPI != our System DPI"); return(false); } for (; ;) { RECT r1 = w.Rect, r2, r3; //note: with ClientRect 4 times faster, but unreliable if small rect. Now fast enough. bool rectWorkaround = false; using (var u = new AwarenessContext(awareness == Awareness.System ? -2 : -1)) { if (Api.GetAwarenessFromDpiAwarenessContext(u.Previous_) != Awareness.PerMonitor) /*fast*/ //cannot get rPhysical. But let's set PM awareness and get it. Works even if this process is Unaware. { rectWorkaround = _GetRect(w, out r1); Debug_.Print("bad DPI awareness of this thread; workaround " + (rectWorkaround ? "OK" : "failed")); if (!rectWorkaround) { return(false); //unlikely. Then the caller probably will call the legacy func, it works with any DPI awareness. } } r2 = w.Rect; if (r2 == r1) { break; } } if (!rectWorkaround) { r3 = w.Rect; } else { _GetRect(w, out r3); } if (r3 != r1) { continue; //moved, resized or closed between Rect and Rect } scaled = true; rPhysical = r1; rLogical = r2; break; }
void _TextChanged() { string name = tName.Text; var a = new List <(string name, string code)>(); int nWild = 0; for (int i = 0; i < name.Length; i++) { switch (name[i]) { case '*': case '?': nWild++; break; } } if (name.Length > 0 && (nWild == 0 || name.Length - nWild >= 2)) { string sql; if (name.Contains(' ')) { sql = $"in ('{string.Join("', '", name.RxFindAll(@"\b[A-Za-z_]\w\w+", (RXFlags)0))}')"; } else if (name.FindAny("*?") >= 0) { sql = $"GLOB '{name}'"; } else { sql = $"= '{name}'"; } try { using var stat = _db.Statement("SELECT name, code FROM api WHERE name " + sql); //perf.first(); while (stat.Step()) { a.Add((stat.GetText(0), stat.GetText(1))); } //perf.nw(); //30 ms cold, 10 ms warm. Without index. } catch (SLException ex) { Debug_.Print(ex.Message); } } string s = ""; if (a.Count != 0) { s = a[0].code; if (a.Count > 1) { s = string.Join(s.Starts("internal const") ? "\r\n" : "\r\n\r\n", a.Select(o => o.code)); } s += "\r\n"; } code.ZSetText(s); }
public _NetDocumentationProvider() { try { _db = EdDatabases.OpenDoc(); //never mind: we don't dispose it on process exit if (_db.Get(out string s, "SELECT xml FROM doc WHERE name='.'")) { _refs = new HashSet <string>(s.Split('\n')); } } catch (SLException ex) { Debug_.Print(ex.Message); } }
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { if (Variables.Proc != null) { DllImport.SetParent(Variables.Proc.MainWindowHandle, IntPtr.Zero); DllImport.MoveWindow(Variables.Proc.MainWindowHandle, PrivateVariable.Instance.EmuDefaultLocation.X, PrivateVariable.Instance.EmuDefaultLocation.Y, 0, 0, true); } Debug_.WriteLine(e.ExceptionObject.ToString()); File.WriteAllText("error.log", e.ExceptionObject.ToString()); MessageBox.Show(e.ExceptionObject.ToString()); Environment.Exit(0); }
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { if (Variables.Proc != null) { DllImport.SetParent(Variables.Proc.MainWindowHandle, IntPtr.Zero); DllImport.MoveWindow(Variables.Proc.MainWindowHandle, PrivateVariable.Instance.EmuDefaultLocation.X, PrivateVariable.Instance.EmuDefaultLocation.Y, 0, 0, true); } Debug_.WriteLine(e.Exception + " At: " + e.Exception.Source + " At: " + e.Exception.TargetSite); File.WriteAllText("error.log", e.Exception.ToString()); MessageBox.Show(e.Exception.Message.ToString()); Environment.Exit(0); }
/// <summary> /// AVL rotate double-right operation. /// </summary> /// <param name="tree">The tree.</param> /// <returns>The rotated tree.</returns> private static SortedInt32KeyNode <TValue> DoubleRight(SortedInt32KeyNode <TValue> tree) { Requires.NotNull(tree, "tree"); Debug_.Assert(!tree.IsEmpty); if (tree._left.IsEmpty) { return(tree); } SortedInt32KeyNode <TValue> rotatedLeftChild = tree.Mutate(left: RotateLeft(tree._left)); return(RotateRight(rotatedLeftChild)); }
/// <summary> /// Initializes a new instance of the <see cref="SortedInt32KeyNode{TValue}"/> class that is not yet frozen. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="left">The left.</param> /// <param name="right">The right.</param> /// <param name="frozen">Whether this node is prefrozen.</param> private SortedInt32KeyNode(int key, TValue value, SortedInt32KeyNode <TValue> left, SortedInt32KeyNode <TValue> right, bool frozen = false) { Requires.NotNull(left, "left"); Requires.NotNull(right, "right"); Debug_.Assert(!frozen || (left._frozen && right._frozen)); _key = key; _value = value; _left = left; _right = right; _frozen = frozen; _height = checked ((byte)(1 + Math.Max(left._height, right._height))); }
// Returns size of hashtable to grow to. public static int ExpandPrime(int oldSize) { int newSize = 2 * oldSize; // Allow the hashtables to grow to maximum possible size (~2G elements) before encoutering capacity overflow. // Note that this check works even when _items.Length overflowed thanks to the (uint) cast if ((uint)newSize > MaxPrimeArrayLength && MaxPrimeArrayLength > oldSize) { Debug_.Assert(MaxPrimeArrayLength == GetPrime(MaxPrimeArrayLength), "Invalid MaxPrimeArrayLength"); return(MaxPrimeArrayLength); } return(GetPrime(newSize)); }
/// <summary> /// AVL rotate right operation. /// </summary> /// <param name="tree">The tree.</param> /// <returns>The rotated tree.</returns> private static SortedInt32KeyNode <TValue> RotateRight(SortedInt32KeyNode <TValue> tree) { Requires.NotNull(tree, "tree"); Debug_.Assert(!tree.IsEmpty); if (tree._left.IsEmpty) { return(tree); } var left = tree._left; return(left.Mutate(right: tree.Mutate(left: left._right))); }
public void ConnectEmulator() { string[] MEmu = { "MEmu", "逍遥模拟器" }; foreach (var p in Process.GetProcessesByName("MEmu")) { Debug_.WriteLine(p.MainWindowTitle); if (MEmu.Contains(p.MainWindowTitle)) { IntPtr handle = DllImport.FindWindowEx(p.MainWindowHandle, IntPtr.Zero, string.Empty, string.Empty); Variables.Proc = p; Variables.ScriptLog("Emulator ID: " + p.Id, Color.DarkGreen); break; } } }
/// <summary> /// Initializes a new instance of the <see cref="ImmutableArray{T}"/> struct. /// </summary> /// <param name="items">The array from which to copy.</param> internal static ImmutableArray <T> CreateDefensiveCopy <T>(T[] items) { Debug_.Assert(items != null); if (items.Length == 0) { return(ImmutableArray <T> .Empty); // use just a shared empty array, allowing the input array to be potentially GC'd } // defensive copy var tmp = new T[items.Length]; Array.Copy(items, 0, tmp, 0, items.Length); return(new ImmutableArray <T>(tmp)); }
private static SortedInt32KeyNode <TValue> MakeBalanced(SortedInt32KeyNode <TValue> tree) { Requires.NotNull(tree, "tree"); Debug_.Assert(!tree.IsEmpty); if (IsRightHeavy(tree)) { return(Balance(tree._right) < 0 ? DoubleLeft(tree) : RotateLeft(tree)); } if (IsLeftHeavy(tree)) { return(Balance(tree._left) > 0 ? DoubleRight(tree) : RotateRight(tree)); } return(tree); }
void _ThreadProc() { WindowsHook hk = null, hm = null; WinEventHook hwe = null; try { try { if (_block.Has(BIEvents.Keys)) { hk = WindowsHook.Keyboard(_keyHookProc ??= _KeyHookProc); } if (_block.HasAny(BIEvents.MouseClicks | BIEvents.MouseMoving)) { hm = WindowsHook.Mouse(_mouseHookProc ??= _MouseHookProc); } } catch (AuException e1) { Debug_.Print(e1); _block = 0; return; } //failed to hook //This prevents occassional inserting a foreign key after the first our-script-pressed key. //To reproduce, let our script send small series of chars in loop, and simultaneously a foreign script send other chars. wait.doEvents(); //print.it("started"); Api.SetEvent(_syncEvent); //the hook detects Ctrl+Alt+Del, Win+L, UAC consent, etc. SystemEvents.SessionSwitch only Win+L. try { hwe = new WinEventHook(EEvent.SYSTEM_DESKTOPSWITCH, 0, _winEventProc ??= _WinEventProc); } catch (AuException e1) { Debug_.Print(e1); } //failed to hook wait.Wait_(-1, WHFlags.DoEvents, _stopEvent, _threadHandle); if (_blockedKeys != null) { bool onlyUp = _discardBlockedKeys || Environment.TickCount64 - _startTime > c_maxResendTime; _blockedKeys.SendBlocked_(onlyUp); } //print.it("ended"); } finally { _blockedKeys = null; hk?.Dispose(); hm?.Dispose(); hwe?.Dispose(); Api.SetEvent(_syncEvent); } GC.KeepAlive(this); }
/// <summary> /// Performs the set operation on a given data structure. /// </summary> private static MutationResult Add(T item, MutationInput origin) { Requires.NotNullAllowStructs(item, "item"); OperationResult result; int hashCode = origin.EqualityComparer.GetHashCode(item); HashBucket bucket = origin.Root.GetValueOrDefault(hashCode); var newBucket = bucket.Add(item, origin.EqualityComparer, out result); if (result == OperationResult.NoChangeRequired) { return(new MutationResult(origin.Root, 0)); } var newRoot = UpdateRoot(origin.Root, hashCode, newBucket); Debug_.Assert(result == OperationResult.SizeChanged); return(new MutationResult(newRoot, 1 /*result == OperationResult.SizeChanged ? 1 : 0*/)); }
nint _WndProc(wnd w, int message, nint wParam, nint lParam) { try { switch (message) { case Api.WM_USER + 1: //_ht.Return((int)wParam, false); //test speed without _KeyMouseEvent _KeyMouseEvent((int)wParam, (HooksThread.UsedEvents)lParam); return(0); case Api.WM_USER + 20: _windowTriggers.SimulateNew_(wParam, lParam); return(0); case Api.WM_USER + 30: _ShowToolbarsDialog(); return(0); } } catch (Exception ex) { Debug_.Print(ex.Message); return(default); }
/// <summary> /// Gets check state of this check box or radio button. /// Returns 0 if unchecked, 1 if checked, 2 if indeterminate. Also returns 0 if this is not a button or if failed to get state. /// </summary> /// <param name="useElm">Use <see cref="elm.State"/>. If false (default) and this button has a standard checkbox style, uses API <msdn>BM_GETCHECK</msdn>.</param> public int GetCheckState(bool useElm = false) { if (useElm || !_IsCheckbox()) { //info: Windows Forms controls are user-drawn and don't have one of the styles, therefore BM_GETCHECK does not work. try { //avoid exception in property-get functions using var e = elm.fromWindow(W, EObjid.CLIENT, flags: EWFlags.NoThrow); if (e == null) { return(0); } return(_GetElmCheckState(e)); } catch (Exception ex) { Debug_.Print(ex); } //CONSIDER: if fails, show warning. In all wnd property-get functions. return(0); } else { return((int)W.Send(BM_GETCHECK)); } }
/// <summary> /// Gets indices of owned windows of the specified window, including all descendants. /// Can be called multiple times for different owner windows; uses arrays created in ctor (the slowest part). /// </summary> /// <param name="owner">Owner window.</param> /// <param name="skip">A callback function that receives descendant indice and can return true to skip that window and its descendants.</param> /// <param name="andOwner">Add <i>owner</i> to the list too, at the position matching the Z order.</param> /// <returns>List of <see cref="all"/> indices of owned windows. Sorted like in the Z order. Not null.</returns> public List <int> GetIndices(wnd owner, Func <int, bool> skip = null, bool andOwner = false) { var ai = new List <int>(); _Owned(owner); void _Owned(wnd owner) { int oint = (int)owner; for (int i = 0; i < owners.Length; i++) { if (owners[i] == oint) { if (skip != null && skip(i)) { continue; } ai.Add(i); _Owned(all[i]); } } } if (andOwner) { int j = Array.IndexOf(all, owner); if (j >= 0) { ai.Add(j); } else { Debug_.Print("owner not in all"); } } ai.Sort(); return(ai); }
public static void LoadAndCreateToolbars() { var pm = PanelManager = new KPanels(); //FUTURE: later remove this code. Now may need to delete old custom Layout.xml. var customLayoutPath = AppSettings.DirBS + "Layout.xml"; if (filesystem.exists(customLayoutPath).File) { try { var s2 = filesystem.loadText(customLayoutPath); //print.it(s2); if (!s2.Contains("<panel name=\"Outline\"")) //v0.4 added several new panels etc, and users would not know the best place for them, or even how to move { filesystem.delete(customLayoutPath, FDFlags.RecycleBin); bool silent = s2.RxIsMatch(@"<document name=""documents"" ?/>\s*</tab>"); //very old and incompatible if (!silent) { print.it("Info: The window layout has been reset, because several new panels have been added in this app version.\r\n\tIf you want to undo it: 1. Exit the program. 2. Restore file Layout.xml from the Recycle Bin (replace the existing file). 3. Run the program. 4. Move panels from the bottom of the window to a better place."); } //rejected: show Yes/No dialog. Let users at first see the new default layout, then they can undo. } } catch (Exception e1) { Debug_.Print(e1.ToStringWithoutStack()); } } pm.BorderBrush = SystemColors.ActiveBorderBrush; //pm.Load(folders.ThisAppBS + @"Default\Layout.xml", null); pm.Load(folders.ThisAppBS + @"Default\Layout.xml", customLayoutPath); pm["Menu"].Content = Menu = new Menu(); TFile = _TB("File"); TEdit = _TB("Edit"); TRun = _TB("Run"); TTools = _TB("Tools"); THelp = _TB("Help", true); TCustom1 = _TB("Custom1"); TCustom2 = _TB("Custom2"); ToolBar _TB(string name, bool isHelp = false) { var c = new ToolBar { Name = name }; c.UiaSetName(name); c.HideGripAndOverflow(false); var tt = new ToolBarTray { IsLocked = true }; //because ToolBar looks bad if parent is not ToolBarTray tt.ToolBars.Add(c); #if true if (isHelp) { var p = new DockPanel { Background = tt.Background }; DockPanel.SetDock(tt, Dock.Right); p.Children.Add(tt); //FUTURE //var box = new TextBox { Height = 20, Margin = new Thickness(3, 1, 3, 2), Padding = new Thickness(1, 1, 1, 0) }; //p.Children.Add(box); pm[name].Content = p; } else { pm[name].Content = tt; } #else if (name == "Help") { c.Items.Add(new TextBox { Width = 150, Padding = new Thickness(1, 0, 1, 0) }); } pm[name].Content = tt; #endif return(c); } // ToolBar _TB(string name, bool isHelp = false) { // var c = new ToolBar { Name = name }; // var tt = new ToolBarTray { IsLocked = true }; //because ToolBar looks bad if parent is not ToolBarTray // c.UiaSetName(name); // tt.ToolBars.Add(c); //#if true // if (isHelp) { // var p = new DockPanel { Background = tt.Background }; // DockPanel.SetDock(tt, Dock.Right); // p.Children.Add(tt); // //FUTURE // //var box = new TextBox { Height = 20, Margin = new Thickness(3, 1, 3, 2), Padding = new Thickness(1, 1, 1, 0) }; // //p.Children.Add(box); // pm[name].Content = p; // } else { // pm[name].Content = tt; // } //#else // if (name == "Help") c.Items.Add(new TextBox { Width = 150, Padding = new Thickness(1, 0, 1, 0) }); // pm[name].Content = tt; //#endif // return c; // } }
public static void Demon_Realm() { Debug_.WriteLine(); Point?point = null; int error = 0; while (true) { var image = BotCore.ImageCapture(); point = BotCore.FindImage(image, Img.Close2, false); if (point != null) { BotCore.SendTap(new Point(point.Value.X, point.Value.Y)); BotCore.Delay(1000, false); continue; } point = BotCore.FindImage(image, Img.GreenButton, false); if (point != null) { BotCore.SendTap(new Point(point.Value.X, point.Value.Y)); BotCore.Delay(1000, false); continue; } if (!BotCore.GameIsForeground("com.nubee.valkyriecrusade")) { return; } if (BotCore.RGBComparer(image, new Point(415, 678), Color.FromArgb(223, 192, 63), 10)) { PrivateVariable.VCevent = PrivateVariable.EventType.DemonRealm; PrivateVariable.InEventScreen = true; DemonStage_Enter(); return; } image = BotCore.ImageCapture(); Variables.ScriptLog("Locating Demon Realm Event UI!", Color.White); if (BotCore.RGBComparer(image, new Point(600, 405), Color.FromArgb(59, 30, 37), 15)) { VCBotScript.Tower_Floor = OCR.OcrImage(BotCore.CropImage(image, new Point(300, 115), new Point(484, 142)), "eng"); VCBotScript.Tower_Rank = OCR.OcrImage(BotCore.CropImage(image, new Point(300, 150), new Point(458, 170)), "eng"); Variables.ScriptLog("Demon Realm Event Found!", Color.Lime); PrivateVariable.InEventScreen = true; VCBotScript.energy = VCBotScript.GetEnergy(); VCBotScript.runes = VCBotScript.GetRune(); break; } else { BotCore.Delay(1000, false); error++; if (error > 20) { ScriptErrorHandler.Reset("Unable to locate event. Going back to main screen"); return; } } } if (VCBotScript.energy == 0) { Variables.ScriptLog("Waiting for energy", Color.Yellow); Variables.ScriptLog("Close game and wait for energy because of no energy left", Color.Yellow); VCBotScript.NoEnergy(); PrivateVariable.InEventScreen = false; PrivateVariable.InMainScreen = false; PrivateVariable.Battling = false; return; } Variables.ScriptLog("Enterting Stage", Color.White); BotCore.SendSwipe(new Point(307, 249), new Point(305, 403), 300); BotCore.Delay(1500); switch (MainScreen.Level) { case 0: BotCore.SendTap(250, 284); break; case 1: if (BotCore.RGBComparer(VCBotScript.image, new Point(143, 355), Color.FromArgb(51, 16, 5), 20)) { Variables.ScriptLog("中级还没被解锁!自动往下挑战中!", Color.Red); BotCore.SendTap(250, 284); break; } BotCore.SendTap(362, 283); break; case 2: if (BotCore.RGBComparer(VCBotScript.image, new Point(143, 355), Color.FromArgb(51, 16, 5), 20)) { Variables.ScriptLog("上级还没被解锁!自动往下挑战中!", Color.Red); if (BotCore.RGBComparer(VCBotScript.image, new Point(324, 270), Color.FromArgb(51, 16, 5), 20)) { Variables.ScriptLog("中级还没被解锁!自动往下挑战中!", Color.Red); BotCore.SendTap(250, 284); break; } BotCore.SendTap(362, 283); break; } BotCore.SendTap(214, 370); break; case 3: if (BotCore.RGBComparer(VCBotScript.image, new Point(324, 355), Color.FromArgb(51, 16, 5), 20)) { Variables.ScriptLog("超上级还没被解锁!自动往下挑战中!", Color.Red); if (BotCore.RGBComparer(VCBotScript.image, new Point(143, 355), Color.FromArgb(51, 16, 5), 20)) { Variables.ScriptLog("上级还没被解锁!自动往下挑战中!", Color.Red); if (BotCore.RGBComparer(VCBotScript.image, new Point(324, 270), Color.FromArgb(51, 16, 5), 20)) { Variables.ScriptLog("中级还没被解锁!自动往下挑战中!", Color.Red); BotCore.SendTap(250, 284); break; } BotCore.SendTap(362, 283); break; } } BotCore.SendTap(353, 371); break; case 4: if (BotCore.RGBComparer(VCBotScript.image, new Point(324, 355), Color.FromArgb(51, 16, 5), 20)) { Variables.ScriptLog("超上级还没被解锁!自动往下挑战中!", Color.Red); if (BotCore.RGBComparer(VCBotScript.image, new Point(143, 355), Color.FromArgb(51, 16, 5), 20)) { Variables.ScriptLog("上级还没被解锁!自动往下挑战中!", Color.Red); if (BotCore.RGBComparer(VCBotScript.image, new Point(324, 270), Color.FromArgb(51, 16, 5), 20)) { Variables.ScriptLog("中级还没被解锁!自动往下挑战中!", Color.Red); BotCore.SendTap(250, 284); break; } BotCore.SendTap(362, 283); break; } } BotCore.SendTap(353, 371); break; } bool EnteredStage = false; error = 0; do { VCBotScript.image = BotCore.ImageCapture(); if (BotCore.RGBComparer(VCBotScript.image, new Point(959, 656), 31, 102, 26, 4)) { Variables.ScriptLog("Start battle", Color.Lime); BotCore.SendTap(new Point(959, 656)); BotCore.Delay(2000, false); if (VCBotScript.runes == 4 && VCBotScript.energy == 5) { BotCore.SendSwipe(new Point(640, 473), new Point(640, 280), 1000); BotCore.Delay(500, false); } BotCore.SendTap(new Point(758, 566)); BotCore.Delay(6000, 8000); BotCore.SendTap(640, 400); //Tap away Round Battle Text BotCore.Delay(2000, false); VCBotScript.stop.Start(); VCBotScript.energy--; //Calculate Energy used if ((VCBotScript.nextOnline - DateTime.Now) < new TimeSpan(3, 15, 0)) { VCBotScript.nextOnline = VCBotScript.nextOnline.AddMinutes(45); } EnteredStage = true; BotCore.Delay(5000, false); break; } else { BotCore.Delay(1000, 1500); error++; if (error > 10) { return; } } if (!BotCore.GameIsForeground("com.nubee.valkyriecrusade")) { ScriptErrorHandler.Reset("Game is closed! Restarting all!"); return; } }while (!EnteredStage); DemonStage_Enter(); }
public void Init() { //_StartProfileOptimization(); Title = App.AppNameLong; //don't append document name etc if (App.Settings.wndpos.main == null) { Width = 1000; Height = 700; WindowStartupLocation = WindowStartupLocation.CenterScreen; //and will EnsureInScreen } WndSavedRect.Restore(this, App.Settings.wndpos.main, o => App.Settings.wndpos.main = o); Panels.LoadAndCreateToolbars(); App.Commands = new KMenuCommands(typeof(Menus), Panels.Menu); App.Commands[nameof(Menus.File.New)].SubmenuOpened = (o, _) => FilesModel.FillMenuNew(o as MenuItem); App.Commands[nameof(Menus.File.Workspace)].SubmenuOpened = (o, _) => FilesModel.FillMenuRecentWorkspaces(o as MenuItem); var atb = new ToolBar[7] { Panels.THelp, Panels.TTools, Panels.TFile, Panels.TRun, Panels.TEdit, Panels.TCustom1, Panels.TCustom2 }; App.Commands.InitToolbarsAndCustomize(folders.ThisAppBS + @"Default\Commands.xml", AppSettings.DirBS + "Commands.xml", atb); var bRun = App.Commands[nameof(Menus.Run.Run_script)].FindButtonInToolbar(Panels.TRun); if (bRun != null) { bRun.Width = 50; bRun.Margin = new(10, 0, 10, 0); } //make Run button bigger //SHOULDDO: bad if vertical toolbar var bNew = App.Commands[nameof(Menus.File.New)].FindMenuButtonInToolbar(Panels.TFile); if (bNew != null) { bNew.MouseDoubleClick += (_, e) => { e.Handled = true; Menus.File.New.New_script(); } } ; Panels.CreatePanels(); App.Commands.BindKeysTarget(this, ""); Panels.PanelManager.Container = g => { this.Content = g; }; //timer.after(100, _ => DOptions.ZShow()); //timer.after(100, _ => App.Model.Properties()); //timer.after(100, _ => Menus.File.Workspace.New_workspace()); //timer.after(100, _ => DIcons.ZShow()); //timer.after(600, _ => Au.Tools.Dwnd.Dialog(wnd.find(null, "Shell_TrayWnd"))); //timer.after(600, _ => Au.Tools.Dwnd.Dialog(wnd.findOrRun(null, "Notepad", run: () => run.it(folders.System + "notepad.exe")))); //timer.after(500, _ => Au.Tools.Delm.Dialog(new POINT(806, 1580))); //timer.after(500, _ => Au.Tools.Delm.Dialog()); //timer.after(400, _ => Au.Tools.Duiimage.Dialog()); //timer2.every(200, _ => { GC.Collect(); }); #if DEBUG App.Timer1s += () => { var e = Keyboard.FocusedElement as FrameworkElement; Debug_.PrintIf(e != null && !e.IsVisible, "focused invisible"); //print.it(e, FocusManager.GetFocusedElement(App.Wmain)); }; #endif }
/// <summary> /// Called at the end of opening this workspace. /// </summary> public void LoadState(bool expandFolders = false, bool openFiles = false) { if (DB == null) { return; } try { Save.LoadingState = true; if (expandFolders) { if (DB.Get(out string s, "SELECT data FROM _misc WHERE key='expanded'") && !s.NE()) { foreach (var v in s.Segments(" ")) { var f = FindById(s[v.Range]); //if (f != null) TreeControl.Expand(f, true); if (f != null) { f.SetIsExpanded(true); } } } } if (openFiles) { if (DB.Get(out string s, "SELECT data FROM _misc WHERE key='open'") && !s.NE()) { //format: indexOfActiveDocOrMinusOne id1 id2 ... int i = -2, iActive = s.ToInt(); FileNode fnActive = null; //perf.first(); foreach (var v in s.Segments(" ")) { i++; if (i < 0) { continue; } var fn = FindById(s[v.Range]); if (fn == null) { continue; } OpenFiles.Add(fn); if (i == iActive) { fnActive = fn; } } //perf.next(); if (fnActive == null || !SetCurrentFile(fnActive)) { _UpdateOpenFiles(null); //disable Previous command } //perf.nw(); } } } catch (Exception ex) { Debug_.Print(ex); } finally { Save.LoadingState = false; } }
/// <summary> /// Makes triggers alive. /// </summary> /// <remarks> /// This function monitors hotkeys, activated windows and other events. When an event matches an added trigger, launches the thrigger's action, which runs in other thread by default. /// Does not return immediately. Runs until this process is terminated or <see cref="Stop"/> called. /// </remarks> /// <example>See <see cref="ActionTriggers"/>.</example> /// <exception cref="InvalidOperationException">Already running.</exception> /// <exception cref="AuException">Something failed.</exception> public unsafe void Run() { //Debug_.PrintLoadedAssemblies(true, true, true); ThrowIfRunning_(); //bool haveTriggers = false; HooksThread.UsedEvents hookEvents = 0; _windowTriggers = null; for (int i = 0; i < _t.Length; i++) { var t = _t[i]; if (t == null || !t.HasTriggers) { continue; } //haveTriggers = true; switch ((TriggerType)i) { case TriggerType.Hotkey: hookEvents |= HooksThread.UsedEvents.Keyboard; break; case TriggerType.Autotext: hookEvents |= HooksThread.UsedEvents.Keyboard | HooksThread.UsedEvents.Mouse; break; case TriggerType.Mouse: hookEvents |= (t as MouseTriggers).UsedHookEvents_; break; case TriggerType.Window: _windowTriggers = t as WindowTriggers; break; } } //print.it(haveTriggers, (uint)llHooks); //if(!haveTriggers) return; //no. The message loop may be used for toolbars etc. if (!s_wasRun) { s_wasRun = true; WndUtil.RegisterWindowClass(c_cn); } _wMsg = WndUtil.CreateMessageOnlyWindow(_WndProc, c_cn); _mainThreadId = Api.GetCurrentThreadId(); _winTimerPeriod = 0; _winTimerLastTime = 0; if (hookEvents != 0) { //prevent big delay later on first LL hook event while hook proc waits if (!s_wasKM) { s_wasKM = true; ThreadPool.QueueUserWorkItem(_ => { try { //using var p1 = perf.local(); new wndFinder("*a").IsMatch(wnd.getwnd.root); //if used window scopes etc _ = WindowsHook.LowLevelHooksTimeout; //slow JIT of registry functions Jit_.Compile(typeof(ActionTriggers), nameof(_WndProc), nameof(_KeyMouseEvent)); Jit_.Compile(typeof(TriggerHookContext), nameof(TriggerHookContext.InitContext), nameof(TriggerHookContext.PerfEnd), nameof(TriggerHookContext.PerfWarn)); Jit_.Compile(typeof(ActionTrigger), nameof(ActionTrigger.MatchScopeWindowAndFunc)); Jit_.Compile(typeof(HotkeyTriggers), nameof(HotkeyTriggers.HookProc)); AutotextTriggers.JitCompile(); MouseTriggers.JitCompile(); } catch (Exception ex) { Debug_.Print(ex); } }); } _thc = new TriggerHookContext(this); _ht = new HooksThread(hookEvents, _wMsg); } try { _evStop = Api.CreateEvent(false); _StartStopAll(true); IntPtr h = _evStop; _Wait(&h, 1); } finally { if (hookEvents != 0) { _ht.Dispose(); _ht = null; } Api.DestroyWindow(_wMsg); _wMsg = default; Stopping?.Invoke(this, EventArgs.Empty); _evStop.Dispose(); _StartStopAll(false); _mainThreadId = 0; _threads?.Dispose(); _threads = null; } void _StartStopAll(bool start) { foreach (var t in _t) { if (t?.HasTriggers ?? false) { t.StartStop(start); } } } }
public static void Tower() { Debug_.WriteLine(); BotCore.Delay(1000, false); var image = Screenshot.ImageCapture(); Point?point = BotCore.FindImage(image, Img.Close2, false, 0.8); if (point != null) { BotCore.SendTap(new Point(point.Value.X, point.Value.Y)); BotCore.Delay(1000, false); } image = Screenshot.ImageCapture(); Variables.ScriptLog("Locating Tower Event UI!", Color.White); if (BotCore.FindImage(image, Img.Locate_Tower, true, 0.8) != null) { image = Screenshot.ImageCapture(); VCBotScript.Tower_Floor = OCR.OcrImage(Screenshot.CropImage(image, new Point(280, 110), new Point(440, 145)), "eng"); VCBotScript.Tower_Rank = OCR.OcrImage(Screenshot.CropImage(image, new Point(280, 145), new Point(410, 170)), "eng"); Variables.ScriptLog("Tower Event Found!", Color.Lime); PrivateVariable.Instance.InEventScreen = true; } else { PrivateVariable.Instance.InMainScreen = false; PrivateVariable.Instance.InEventScreen = false; return; } image = Screenshot.ImageCapture(); while (!BotCore.RGBComparer(new Point(135, 526), 13, 46, 74, 10)) { BotCore.Delay(1000, true); image = Screenshot.ImageCapture(); } VCBotScript.energy = VCBotScript.GetEnergy(); VCBotScript.runes = VCBotScript.GetRune(); Variables.ScriptLog("Current have " + VCBotScript.energy + " energy and " + VCBotScript.runes + " runes", Color.LightSkyBlue); if (VCBotScript.energy == 0) { Variables.ScriptLog("Waiting for energy", Color.Yellow); if (PrivateVariable.Instance.TakePartInNormalStage) { BotCore.SendTap(1218, 662); BotCore.Delay(400, 600); BotCore.SendTap(744, 622); } else { if (PrivateVariable.Instance.Use_Item) { if (VCBotScript.runes == 5) { Variables.ScriptLog("Use item as it is now rune!", Color.White); } else { Variables.ScriptLog("Close game and wait for energy because of no energy left", Color.White); VCBotScript.NoEnergy(); PrivateVariable.Instance.InEventScreen = false; PrivateVariable.Instance.InMainScreen = false; PrivateVariable.Instance.Battling = false; return; } } else { Variables.ScriptLog("Close game and wait for energy because of no energy left", Color.White); VCBotScript.NoEnergy(); PrivateVariable.Instance.InEventScreen = false; PrivateVariable.Instance.InMainScreen = false; PrivateVariable.Instance.Battling = false; return; } } } Variables.ScriptLog("Entering Stage!", Color.Lime); image = Screenshot.ImageCapture(); if (BotCore.FindImage(image, Img.GreenButton, false, 0.9) == null) { Variables.ScriptLog("Rune Boss found!", Color.Lime); } else { var templevel = MainScreen.Level; Loop: switch (templevel) { case 0: for (int x = 0; x < 5; x++) { VCBotScript.image = Screenshot.ImageCapture(); if (BotCore.FindImage(VCBotScript.image, Img.LV0, true, 0.85) == null) { BotCore.SendTap(rnd.Next(410, 420), rnd.Next(650, 660)); BotCore.Delay(500); } } BotCore.SendTap(785, 618); break; case 1: for (int x = 0; x < 5; x++) { VCBotScript.image = Screenshot.ImageCapture(); if (BotCore.FindImage(VCBotScript.image, Img.LV1, true, 0.85) == null) { BotCore.SendTap(rnd.Next(410, 420), rnd.Next(650, 660)); BotCore.Delay(500); } } if (BotCore.FindImage(VCBotScript.image, Img.LV1, true, 0.85) == null) { Variables.ScriptLog("Unable to switch to stage. Stage not unlocked?", Color.Red); templevel--; goto Loop; } BotCore.SendTap(785, 618); break; case 2: for (int x = 0; x < 5; x++) { VCBotScript.image = Screenshot.ImageCapture(); if (BotCore.FindImage(VCBotScript.image, Img.LV2, true, 0.85) == null) { BotCore.SendTap(rnd.Next(410, 420), rnd.Next(650, 660)); BotCore.Delay(500); } else if (BotCore.FindImage(VCBotScript.image, Img.LV3, true, 0.85) != null) { //This is not 上级,this is f*****g 超上级 BotCore.SendTap(rnd.Next(410, 420), rnd.Next(650, 660)); BotCore.Delay(500); } } if (BotCore.FindImage(VCBotScript.image, Img.LV2, true, 0.85) == null) { Variables.ScriptLog("Unable to switch to stage. Stage not unlocked?", Color.Red); templevel--; goto Loop; } BotCore.SendTap(785, 618); break; case 3: for (int x = 0; x < 5; x++) { VCBotScript.image = Screenshot.ImageCapture(); if (BotCore.FindImage(VCBotScript.image, Img.LV3, true, 0.85) == null) { BotCore.SendTap(rnd.Next(410, 420), rnd.Next(650, 660)); BotCore.Delay(500); } } if (BotCore.FindImage(VCBotScript.image, Img.LV3, true, 0.85) == null) { Variables.ScriptLog("Unable to switch to stage. Stage not unlocked?", Color.Red); templevel--; goto Loop; } BotCore.SendTap(785, 618); break; case 4: for (int x = 0; x < 5; x++) { VCBotScript.image = Screenshot.ImageCapture(); if (BotCore.FindImage(VCBotScript.image, Img.LV4, true, 0.85) == null) { BotCore.SendTap(rnd.Next(410, 420), rnd.Next(650, 660)); BotCore.Delay(500); } } if (BotCore.FindImage(VCBotScript.image, Img.LV4, true, 0.85) == null) { Variables.ScriptLog("Unable to switch to stage. Stage not unlocked?", Color.Red); templevel--; goto Loop; } BotCore.SendTap(785, 618); break; } } BotCore.Delay(2000); BotCore.SendTap(800, 660); /* * image = Screenshot.ImageCapture(); * switch (MainScreen.Level) * { * case 0: * BotCore.SendTap(196, 648); * break; * case 1: * if (BotCore.RGBComparer( new Point(328, 621), Color.FromArgb(13, 12, 12), 35)) * { * Variables.ScriptLog("中级还没被解锁!自动往下挑战中!", Color.Red); * BotCore.SendTap(196, 648); * break; * } * BotCore.SendTap(391, 648); * break; * case 2: * if (BotCore.RGBComparer( new Point(515, 625), Color.FromArgb(12, 11, 12), 35)) * { * Variables.ScriptLog("上级还没被解锁!自动往下挑战中!", Color.Red); * if (BotCore.RGBComparer( new Point(328, 621), Color.FromArgb(13, 12, 12), 5)) * { * Variables.ScriptLog("中级还没被解锁!自动往下挑战中!", Color.Red); * BotCore.SendTap(196, 648); * break; * } * BotCore.SendTap(391, 648); * break; * } * BotCore.SendTap(581, 646); * break; * case 3: * if (BotCore.RGBComparer( new Point(703, 622), Color.FromArgb(32, 30, 30), 35)) * { * Variables.ScriptLog("超上级还没被解锁!自动往下挑战中!", Color.Red); * if (BotCore.RGBComparer( new Point(515, 625), Color.FromArgb(12, 11, 12), 35)) * { * Variables.ScriptLog("上级还没被解锁!自动往下挑战中!", Color.Red); * if (BotCore.RGBComparer( new Point(328, 621), Color.FromArgb(13, 12, 12), 35)) * { * Variables.ScriptLog("中级还没被解锁!自动往下挑战中!", Color.Red); * BotCore.SendTap(196, 648); * break; * } * BotCore.SendTap(391, 648); * break; * } * BotCore.SendTap(581, 646); * break; * } * BotCore.SendTap(741, 623); * break; * case 4: * if (BotCore.RGBComparer( new Point(885, 621), Color.FromArgb(107, 100, 100), 90)) * { * Variables.ScriptLog("霸级还没被解锁!自动往下挑战中!", Color.Red); * if (BotCore.RGBComparer( new Point(703, 621), Color.FromArgb(107, 100, 100), 90)) * { * Variables.ScriptLog("超上级还没被解锁!自动往下挑战中!", Color.Red); * if (BotCore.RGBComparer( new Point(515, 621), Color.FromArgb(107, 100, 100), 90)) * { * Variables.ScriptLog("上级还没被解锁!自动往下挑战中!", Color.Red); * if (BotCore.RGBComparer( new Point(328, 621), Color.FromArgb(117, 100, 100), 90)) * { * Variables.ScriptLog("中级还没被解锁!自动往下挑战中!", Color.Red); * BotCore.SendTap(196, 648); * break; * } * BotCore.SendTap(391, 648); * break; * } * BotCore.SendTap(581, 646); * break; * } * BotCore.SendTap(741, 623); * break; * } * BotCore.SendTap(921, 620); * break; * }*/ BotCore.Delay(3000, false); do { if (!BotCore.GameIsForeground("com.nubee.valkyriecrusade")) { return; } /*if (PrivateVariable.Use_Item && VCBotScript.energy == 0 && VCBotScript.runes == 5) * { * image = Screenshot.ImageCapture(); * if (BotCore.GetPixel(new Point(798, 313), image) != Color.FromArgb(27, 95, 22)) * { * BotCore.Delay(1000, false); * continue; * } * BotCore.SendTap(798, 313); * image = Screenshot.ImageCapture(); * Point? p = BotCore.FindImage(image, Img.GreenButton, false); * while (p == null) * { * if (!BotCore.GameIsForeground("com.nubee.valkyriecrusade")) * { * return; * } * BotCore.Delay(400, 600); * image = Screenshot.ImageCapture(); * p = BotCore.FindImage(image, Img.GreenButton, false); * } * BotCore.SendTap(p.Value); * VCBotScript.energy = 5; * BotCore.Delay(5000, false); * }*/ image = Screenshot.ImageCapture(); if (BotCore.RGBComparer(new Point(959, 656), 31, 102, 26, 4)) { Variables.ScriptLog("Start battle", Color.Lime); BotCore.SendTap(new Point(959, 656)); BotCore.Delay(7000, false); BotCore.SendTap(640, 400); //Tap away Round Battle Text BotCore.Delay(2000, false); VCBotScript.stop.Start(); PrivateVariable.Instance.Battling = true; VCBotScript.energy--; //Calculate Energy used if (VCBotScript.nextOnline < DateTime.Now) { VCBotScript.nextOnline = DateTime.Now; } VCBotScript.nextOnline = VCBotScript.nextOnline.AddMinutes(45); BotCore.Delay(1000, false); break; } else { image = Screenshot.ImageCapture(); var crop = Screenshot.CropImage(image, new Point(125, 600), new Point(1270, 10)); point = BotCore.FindImage(crop, Img.Red_Button, false, 0.9); if (point != null) { Variables.ScriptLog("Rune boss found!", Color.Yellow); BotCore.SendTap(new Point(point.Value.X + 125, point.Value.Y)); VCBotScript.RuneBoss = true; BotCore.Delay(9000, 12000); } else { ScriptErrorHandler.ErrorHandle(); } } image = Screenshot.ImageCapture(); ScriptErrorHandler.ErrorHandle(); }while (!PrivateVariable.Instance.Battling); }
/// <summary> /// Creates documentation provider for assembly <i>asmPath</i>. /// Returns null if its xml file does not exist. /// Returns _DocumentationProvider if xml file is big and found or successfully created and successfully loaded database for it. /// Else returns _XmlFileDocumentationProvider. /// </summary> public static DocumentationProvider Create(string asmPath) { if (s_d.TryGetValue(asmPath, out var dp)) { return(dp); } var xmlPath = Path.ChangeExtension(asmPath, "xml"); if (!filesystem.getProperties(xmlPath, out var px)) { return(null); } if (px.Size >= 10_000) { var md5 = new Hash.MD5Context(); md5.Add(xmlPath.Lower()); var dbPath = folders.ThisAppTemp + md5.Hash.ToString() + ".db"; try { if (!filesystem.getProperties(dbPath, out var pd) || pd.LastWriteTimeUtc != px.LastWriteTimeUtc) { //Debug_.Print($"creating db: {asmPath} -> {dbPath}"); filesystem.delete(dbPath); using (var d = new sqlite(dbPath)) { using var trans = d.Transaction(); d.Execute("CREATE TABLE doc (name TEXT PRIMARY KEY, xml TEXT)"); using var statInsert = d.Statement("INSERT INTO doc VALUES (?, ?)"); var xr = XmlUtil.LoadElem(xmlPath); foreach (var e in xr.Descendants("member")) { var name = e.Attr("name"); //remove <remarks> and <example>. foreach (var v in e.Descendants("remarks").ToArray()) { v.Remove(); } foreach (var v in e.Descendants("example").ToArray()) { v.Remove(); } using var reader = e.CreateReader(); reader.MoveToContent(); var xml = reader.ReadInnerXml(); //print.it(name, xml); statInsert.BindAll(name, xml).Step(); statInsert.Reset(); } trans.Commit(); d.Execute("VACUUM"); } File.SetLastWriteTimeUtc(dbPath, px.LastWriteTimeUtc); } var db = new sqlite(dbPath, SLFlags.SQLITE_OPEN_READONLY); //never mind: we don't dispose it on process exit s_d[asmPath] = dp = new _DocumentationProvider { _db = db }; return(dp); } catch (Exception ex) { Debug_.Print(ex.ToStringWithoutStack()); } } //return XmlDocumentationProvider.CreateFromFile(xmlPath); //no, need XML with root element. return(new _XmlFileDocumentationProvider(xmlPath)); }
VarInt IAccessible.get_accRole(VarInt varChild) { Debug_.PrintIf(Api.GetCurrentThreadId() != _w.ThreadId, "thread"); var r = !_B(varChild, out var b) ? ERole.TOOLBAR : b.ItemType switch { TBItemType.Separator => ERole.SEPARATOR, TBItemType.Group => ERole.GROUPING, TBItemType.Menu => ERole.BUTTONMENU, _ => ERole.BUTTON }; return((int)r - 1); } VarInt IAccessible.get_accState(VarInt varChild) { EState r = 0; if (!_w.IsEnabled()) { r |= EState.DISABLED; } if (!_B(varChild, out var b)) { if (!_w.IsVisible) { r |= EState.INVISIBLE; } } else { if (b.IsSeparatorOrGroup_) { r |= EState.DISABLED; } if (b.IsMenu_) { r |= EState.HASPOPUP; } //SHOULDDO: if offscreen, r |= EState.INVISIBLE | EState.OFFSCREEN; //no: EState.HOTTRACKED; } return((int)r - 1); } string IAccessible.get_accHelp(VarInt varChild) => _B(varChild, out var b) ? _GetFullTooltip(b) : null; int IAccessible.get_accHelpTopic(out string pszHelpFile, VarInt varChild) => throw new NotImplementedException(); string IAccessible.get_accKeyboardShortcut(VarInt varChild) => null; object IAccessible.get_accFocus() => null; object IAccessible.get_accSelection() => null; string IAccessible.get_accDefaultAction(VarInt varChild) => !_B(varChild, out var b) || b.IsSeparatorOrGroup_ ? null : b.IsMenu_ ? "Open" : "Execute"; void IAccessible.accSelect(ESelect flagsSelect, VarInt varChild) => throw new NotImplementedException(); void IAccessible.accLocation(out int pxLeft, out int pyTop, out int pcxWidth, out int pcyHeight, VarInt varChild) { if (!_B(varChild, out var b)) { _StdAO.accLocation(out pxLeft, out pyTop, out pcxWidth, out pcyHeight, varChild); } else { var r = b.rect; _w.MapClientToScreen(ref r); pxLeft = r.left; pyTop = r.top; pcxWidth = r.Width; pcyHeight = r.Height; } } object IAccessible.accNavigate(NAVDIR navDir, VarInt varStart) { int i = varStart; var a = _a; if (navDir == NAVDIR.FIRSTCHILD || navDir == NAVDIR.LASTCHILD) { if (i == -1) { return(navDir == NAVDIR.FIRSTCHILD ? 1 : a.Count); } } else { if (i == -1) { return(_StdAO.accNavigate(navDir, varStart)); } switch (navDir) { case NAVDIR.PREVIOUS: if (i > 0) { return(i); } break; case NAVDIR.NEXT: if (++i < a.Count) { return(i + 1); } break; } } return(null); } VarInt IAccessible.accHitTest(int xLeft, int yTop) { POINT p = new(xLeft, yTop); _w.MapScreenToClient(ref p); if (!_w.ClientRect.Contains(p)) { return(_StdAO.accHitTest(xLeft, yTop)); } return(_HitTest(p)); } void IAccessible.accDoDefaultAction(VarInt varChild) { if (!_B(varChild, out var b) || b.IsSeparatorOrGroup_) { return; } _w.Post(Api.WM_USER + 50, (int)varChild); } void IAccessible.put_accName(VarInt varChild, string szName) { } void IAccessible.put_accValue(VarInt varChild, string szValue) { } bool _B(VarInt varChild, out ToolbarItem b) { int i = varChild; if (i == -1) { b = null; return(false); } b = _a[i]; return(true); } }
private static bool IsLeftHeavy(SortedInt32KeyNode <TValue> tree) { Requires.NotNull(tree, "tree"); Debug_.Assert(!tree.IsEmpty); return(Balance(tree) <= -2); }
bool _FillProperties(bool newWindow) { bool isCon = !_con.Is0; _WinInfo f = default; if (!_GetClassName(_wnd, out f.wClass)) { return(false); //note: get even if !newWindow, to detect closed window } if (isCon && !_GetClassName(_con, out f.cClass)) { return(false); } bool _GetClassName(wnd w, out string cn) { cn = w.ClassName; if (cn != null) { return(true); } _winInfo.zText = "Failed to get " + (w == _wnd ? "window" : "control") + " properties: \r\n" + lastError.message; _scroller.Visibility = Visibility.Hidden; return(false); } _noeventValueChanged = true; var wndName = _wnd.NameTL_; if (newWindow) { nameW.Set(true, TUtil.EscapeWindowName(wndName, true)); classW.Set(true, TUtil.StripWndClassName(f.wClass, true)); f.wProg = _wnd.ProgramName; var ap = new List <string> { f.wProg, "WOwner.Process(processId)", "WOwner.Thread(threadId)" }; if (!_wnd.Get.Owner.Is0) { ap.Add("WOwner.Window(ow)"); } programW.Set(wndName.NE(), f.wProg, ap); containsW.Set(false, null, _ContainsCombo_DropDown); } else if (wndName != _wndName) { if (TUtil.ShouldChangeTextBoxWildex(nameW.t.Text, wndName)) { nameW.Set(true, TUtil.EscapeWindowName(wndName, true)); } } f.wName = _wndName = wndName; if (isCon) { //name combo f.cName = _con.Name; int iSel = f.cName.NE() ? -1 : 0; var an = new List <string> { TUtil.EscapeWildex(f.cName) }; _ConNameAdd("***wfName ", f.cWF = _con.NameWinforms); /*bool isElm =*/ _ConNameAdd("***elmName ", f.cElm = _con.NameElm); //bool isLabel = _ConNameAdd("***label ", f.cLabel = _con.NameLabel); //if(isElm && isLabel && iSel == an.Count - 2 && f.cElm == f.cLabel) iSel++; //if label == elmName, prefer label if (iSel < 0) { iSel = 0; //never select text, even if all others unavailable } _ConNameAdd("***text ", f.cText = _con.ControlText); bool _ConNameAdd(string prefix, string value) { if (value.NE()) { return(false); } if (iSel < 0) { iSel = an.Count; } an.Add(prefix + TUtil.EscapeWildex(value)); return(true); } bool idUseful = TUtil.GetUsefulControlId(_con, _wnd, out f.cId); //idC.Visible = idUseful; idC.Set(idUseful, f.cId.ToS() + (idUseful ? null : " /*probably not useful*/")); string sName = an[iSel], sClass = TUtil.StripWndClassName(f.cClass, true); nameC.Set(!idUseful, sName, an); classC.Set(!idUseful, sClass); bool hiddenToo = !_con.IsVisible; cHiddenTooC.IsChecked = hiddenToo; var skip = idUseful ? null : TUtil.GetControlSkip(_wnd, _con, sName, sClass, hiddenToo); skipC.Set(skip != null, skip); } bool checkControl = isCon && _checkControl; _cControl.IsChecked = checkControl; _ShowControlProperties(showGrid: checkControl, showAll: isCon); _noeventValueChanged = false; _scroller.Visibility = Visibility.Visible; _FillWindowInfo(f); return(true); List <string> _ContainsCombo_DropDown() { try { var a1 = new List <string>(); //child foreach (var c in _wnd.Get.Children(onlyVisible: true)) { var cn = c.Name; if (cn.NE()) { continue; } cn = "c '" + TUtil.StripWndClassName(c.ClassName, true) + "' " + TUtil.EscapeWildex(cn); if (!a1.Contains(cn)) { a1.Add(cn); } } //elm var a2 = new List <string>(); var a3 = _wnd.Elm[name : "?*", prop : "notin=SCROLLBAR\0maxcc=100", flags : EFFlags.ClientArea].FindAll(); //all that have a name string prevName = null; for (int i = a3.Length; --i >= 0;) { if (!a3[i].GetProperties("Rn", out var prop)) { continue; } if (prop.Name == prevName && prop.Role == "WINDOW") { continue; } prevName = prop.Name; //skip parent WINDOW string rn = "e '" + prop.Role + "' " + TUtil.EscapeWildex(prop.Name); if (!a2.Contains(rn)) { a2.Add(rn); } } a2.Reverse(); a1.AddRange(a2); return(a1); //rejected: sort } catch (Exception ex) { Debug_.Print(ex); return(null); } } }