public static void VbeEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { if (Suspend || hwnd == IntPtr.Zero || _vbe.IsWrappingNullReference) { return; } var windowType = hwnd.ToWindowType(); #if (DEBUG && (THIRSTY_DUCK || THIRSTY_DUCK_EVT)) //This is an output window firehose, viewer discretion is advised. if (idObject != (int)ObjId.Cursor) { var windowClassName = hwnd.ToClassName(); if (!WinEventMap.Lookup.TryGetValue((int)eventType, out var eventName)) { eventName = "Unknown"; } Debug.WriteLine($"EVT: 0x{eventType:X4} ({eventName}) Hwnd 0x{(int)hwnd:X4} ({windowClassName}), idObject {idObject}, idChild {idChild}"); } #endif if (windowType == WindowType.IntelliSense) { if (eventType == (uint)WinEvent.ObjectShow) { OnIntelliSenseChanged(true); } else if (eventType == (uint)WinEvent.ObjectHide) { OnIntelliSenseChanged(false); } } else if (windowType == WindowType.CodePane && idObject == (int)ObjId.Caret && (eventType == (uint)WinEvent.ObjectLocationChange || eventType == (uint)WinEvent.ObjectCreate)) { OnSelectionChanged(hwnd); } else if (SubclassManager.IsSubclassable(windowType) && (idObject == (int)ObjId.Window && eventType == (uint)WinEvent.ObjectCreate) || !Subclasses.IsSubclassed(hwnd)) { Attach(hwnd); } else if (eventType == (uint)WinEvent.ObjectFocus && idObject == (int)ObjId.Client) { //Test to see if it was a selection change in the project window. var parent = User32.GetParent(hwnd); if (parent != IntPtr.Zero && parent.ToWindowType() == WindowType.Project && hwnd == User32.GetFocus()) { FocusDispatcher(_vbe, new WindowChangedEventArgs(parent, FocusType.ChildFocus)); } } }
public static void HookEvents(IVBE vbe) { _vbe = vbe; if (_eventHandle == IntPtr.Zero) { _eventProc = VbeEventCallback; IntPtr mainWindowHwnd; using (var mainWindow = _vbe.MainWindow) { mainWindowHwnd = new IntPtr(mainWindow.HWnd); } _threadId = User32.GetWindowThreadProcessId(mainWindowHwnd, IntPtr.Zero); _eventHandle = User32.SetWinEventHook((uint)WinEvent.Min, (uint)WinEvent.Max, IntPtr.Zero, _eventProc, 0, _threadId, WinEventFlags.OutOfContext); Subclasses.Subclass(mainWindowHwnd.ChildWindows() .Where(hwnd => SubclassManager.IsSubclassable(hwnd.ToWindowType()))); } }
public static void VbeEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { if (Suspend || hwnd == IntPtr.Zero || _vbe.IsWrappingNullReference) { return; } var windowType = hwnd.ToWindowType(); PeekMessagePump(eventType, hwnd, idObject, idChild); if (windowType == WindowType.IntelliSense) { if (eventType == (uint)WinEvent.ObjectShow) { OnIntelliSenseChanged(true); } else if (eventType == (uint)WinEvent.ObjectHide) { OnIntelliSenseChanged(false); } } else if (windowType == WindowType.CodePane && idObject == (int)ObjId.Caret && (eventType == (uint)WinEvent.ObjectLocationChange || eventType == (uint)WinEvent.ObjectCreate)) { OnSelectionChanged(hwnd); } else if (SubclassManager.IsSubclassable(windowType) && (idObject == (int)ObjId.Window && eventType == (uint)WinEvent.ObjectCreate) || !Subclasses.IsSubclassed(hwnd)) { Attach(hwnd); } else if (eventType == (uint)WinEvent.ObjectFocus && idObject == (int)ObjId.Client) { //Test to see if it was a selection change in the project window. var parent = User32.GetParent(hwnd); if (parent != IntPtr.Zero && parent.ToWindowType() == WindowType.Project && hwnd == User32.GetFocus()) { FocusDispatcher(_vbe, new WindowChangedEventArgs(parent, FocusType.ChildFocus)); } } }
public Dictionary <string, SubClass> GetClasses() { Dictionary <string, SubClass> classes = SubclassManager.LoadClasses(); Config config = Instance.Config; if (config.AdditiveChance) { ClassesAdditive = new Dictionary <RoleType, Dictionary <SubClass, float> >(); foreach (var item in classes) { foreach (RoleType role in item.Value.AffectsRoles) { if (!ClassesAdditive.ContainsKey(role)) { ClassesAdditive.Add(role, new Dictionary <SubClass, float>() { { item.Value, item.Value.FloatOptions["ChanceToGet"] } }); } else { ClassesAdditive[role].Add(item.Value, item.Value.FloatOptions["ChanceToGet"]); } } } //var additiveClasses = ClassesAdditive.ToList(); Dictionary <RoleType, Dictionary <SubClass, float> > classesAdditiveCopy = new Dictionary <RoleType, Dictionary <SubClass, float> >(); foreach (RoleType role in ClassesAdditive.Keys) { var additiveClasses = ClassesAdditive[role].ToList(); additiveClasses.Sort((x, y) => y.Value.CompareTo(x.Value)); if (!classesAdditiveCopy.ContainsKey(role)) { classesAdditiveCopy.Add(role, new Dictionary <SubClass, float>()); } classesAdditiveCopy[role] = additiveClasses.ToDictionary(x => x.Key, x => x.Value); } ClassesAdditive.Clear(); Dictionary <RoleType, float> sums = new Dictionary <RoleType, float>(); foreach (var roles in classesAdditiveCopy) { foreach (SubClass sclass in classesAdditiveCopy[roles.Key].Keys) { if (!sums.ContainsKey(roles.Key)) { sums.Add(roles.Key, 0); } sums[roles.Key] += sclass.FloatOptions["ChanceToGet"]; if (!ClassesAdditive.ContainsKey(roles.Key)) { ClassesAdditive.Add(roles.Key, new Dictionary <SubClass, float>() { { sclass, sclass.FloatOptions["ChanceToGet"] } }); } else { ClassesAdditive[roles.Key].Add(sclass, sums[roles.Key]); } } } } else if (config.WeightedChance) { ClassesWeighted = new Dictionary <RoleType, Dictionary <SubClass, float> >(); foreach (var item in classes) { foreach (RoleType role in item.Value.AffectsRoles) { if (!ClassesWeighted.ContainsKey(role)) { ClassesWeighted.Add(role, new Dictionary <SubClass, float> { { item.Value, item.Value.FloatOptions["ChanceToGet"] } }); } else { ClassesWeighted[role].Add(item.Value, item.Value.FloatOptions["ChanceToGet"]); } } } Dictionary <RoleType, Dictionary <SubClass, float> > classesWeightedCopy = new Dictionary <RoleType, Dictionary <SubClass, float> >(); foreach (RoleType role in ClassesWeighted.Keys) { var weightedClasses = ClassesWeighted[role].ToList(); weightedClasses.Sort((x, y) => y.Value.CompareTo(x.Value)); if (!classesWeightedCopy.ContainsKey(role)) { classesWeightedCopy.Add(role, new Dictionary <SubClass, float>()); } classesWeightedCopy[role] = weightedClasses.ToDictionary(x => x.Key, x => x.Value); } ClassesWeighted.Clear(); Dictionary <RoleType, float> totals = new Dictionary <RoleType, float>(); foreach (var weight in config.BaseWeights) { if (!totals.ContainsKey(weight.Key)) { totals.Add(weight.Key, 0f); } totals[weight.Key] += weight.Value; } foreach (var item in classesWeightedCopy) { foreach (SubClass subClass in classesWeightedCopy[item.Key].Keys) { if (!totals.ContainsKey(item.Key)) { totals.Add(item.Key, 0f); } totals[item.Key] += subClass.FloatOptions["ChanceToGet"]; } } Dictionary <RoleType, float> sums = new Dictionary <RoleType, float>(); foreach (var item in classesWeightedCopy) { foreach (SubClass sclass in classesWeightedCopy[item.Key].Keys) { if (!sums.ContainsKey(item.Key)) { sums.Add(item.Key, 0f); } sums[item.Key] += sclass.FloatOptions["ChanceToGet"]; if (!ClassesWeighted.ContainsKey(item.Key)) { ClassesWeighted.Add(item.Key, new Dictionary <SubClass, float> { { sclass, 100 * (sclass.FloatOptions["ChanceToGet"] / totals[item.Key]) } }); } else { ClassesWeighted[item.Key].Add(sclass, 100 * (sums[item.Key] / totals[item.Key])); } } } } else { ClassesAdditive = null; ClassesWeighted = null; } return(classes); }