ModPlus.AutoCAD.Module.2016 by modplus.org

<PackageReference Include="ModPlus.AutoCAD.Module.2016" Version="10.0.0" />

 ModPlus

using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.ApplicationServices.Core; using Autodesk.AutoCAD.EditorInput; using Autodesk.Internal.Windows; using Autodesk.Windows; using Microsoft.Win32; using ModPlus.App; using ModPlus.Helpers; using ModPlus.MiniPlugins; using ModPlus.Windows; using ModPlusAPI; using ModPlusAPI.LicenseServer; using ModPlusAPI.RegistryData; using ModPlusAPI.UserInfo; using ModPlusAPI.Windows; using System; using System.Diagnostics; using System.IO; using System.Linq; using System.Net; using System.Reflection; using System.Runtime.CompilerServices; using System.Timers; using System.Windows.Interop; using System.Xml.Linq; namespace ModPlus { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class ModPlus { [System.Runtime.CompilerServices.NullableContext(0)] public enum WndMsg { WM_ACAD_HELP = 77, WM_KEYDOWN = 256 } [System.Runtime.CompilerServices.NullableContext(0)] public enum WndKey { VK_F1 = 112 } [System.Runtime.CompilerServices.NullableContext(0)] internal class WebClientWithTimeout : WebClient { [System.Runtime.CompilerServices.NullableContext(1)] protected override WebRequest GetWebRequest(Uri uri) { WebRequest webRequest = base.GetWebRequest(uri); if (webRequest != null) webRequest.Timeout = 3000; return webRequest; } } private const string LangItem = "AutocadDlls"; private static bool _dropNextHelpCall; private static string _currentTooltip; private static bool _quiteLoad; private static readonly string[] BaseFiles = new string[7] { "mpBaseInt.dll", "mpMetall.dll", "mpConcrete.dll", "mpMaterial.dll", "mpOther.dll", "mpWood.dll", "mpProductInt.dll" }; internal static bool IsCracked { get; set; } public unsafe void Initialize() { try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); RegistryMoveHelper.Move(); if (Language.Initialize()) { _quiteLoad = Variables.get_QuietLoading(); Editor val = Application.get_DocumentManager().get_MdiActiveDocument().get_Editor(); if (!CheckCadVersion()) { val.WriteMessage("\n***************************"); val.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p1")); val.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p2")); val.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p3")); val.WriteMessage("\n***************************"); } else { Statistic.SendModuleLoaded("AutoCAD", "2016"); val.WriteMessage("\n***************************"); val.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p4")); if (!_quiteLoad) val.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p5")); LoadAssemblies(val); if (!_quiteLoad) val.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p6")); LoadBaseAssemblies(val); if (!_quiteLoad) val.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p7")); UserConfigFile.InitConfigFile(); if (!_quiteLoad) val.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p8")); int num = LoadPlugins(val); if (num == 0) MessageBox.Show(Language.GetItem("ModPlusAPI", "m5"), 3); CheckAdaptation(); XElement cuiAsXElement = Adaptation.GetCuiAsXElement("AutoCAD"); if (!cuiAsXElement.Descendants("Function").Any() && num != 0) MessageBox.Show(Language.GetItem("ModPlusAPI", "m6"), 3); ComponentManager.add_ItemInitialized((EventHandler<RibbonItemEventArgs>)ComponentManager_ItemInitialized); if (Variables.get_Palette()) MpPalette.CreatePalette(false); Application.add_SystemVariableChanged(new SystemVariableChangedEventHandler((object)this, (IntPtr)(void*))); FloatMenuCommand.LoadMainMenu(); MpDrawingsFunction.LoadMainMenu(); MiniFunctions.LoadUnloadContextMenu(); PlatformUtils.CheckAndRunUpdater(); if (bool.TryParse(UserConfigFile.GetValue("mpProductInsert", "ShowIcon"), out bool result) & result) ProductIconCommands.ShowIcon(); bool disableConnectionWithLicenseServerInAutoCAD = Variables.get_DisableConnectionWithLicenseServerInAutoCAD(); if (Variables.get_IsLocalLicenseServerEnable() && !disableConnectionWithLicenseServerInAutoCAD) ClientStarter.StartConnection(1); if (Variables.get_IsWebLicenseServerEnable() && !disableConnectionWithLicenseServerInAutoCAD) WebLicenseServerClient.get_Instance().Start(1); UserInfoService.ProductStartupAuthorization(); Application.add_PreTranslateMessage(new PreTranslateMessageEventHandler((object)this, (IntPtr)(void*))); ComponentManager.add_ToolTipOpened((EventHandler)ComponentManager_ToolTipOpened); ComponentManager.add_ToolTipClosed((EventHandler)ComponentManager_ToolTipClosed); stopwatch.Stop(); val.WriteMessage(string.Format("\n{0} {1}", Language.GetItem("AutocadDlls", "p9"), stopwatch.ElapsedMilliseconds)); val.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p10")); val.WriteMessage("\n***************************"); try { string value = RegistryUtils.GetValue<string>("TopDir"); string text = Path.Combine(value, "Extensions", "ModPlusAPI.dll"); if (File.Exists(text) && !AuthenticodeTools.IsTrusted(text)) { Timer timer = new Timer(); timer.Elapsed += delegate { IsCracked = true; }; timer.Interval = 600000; timer.AutoReset = false; timer.Enabled = true; timer.Start(); } } catch { } } } } catch (Exception ex) { ExceptionBox.Show(ex); } } public unsafe void Terminate() { ClientStarter.StopConnection(); Application.remove_PreTranslateMessage(new PreTranslateMessageEventHandler((object)this, (IntPtr)(void*))); ComponentManager.remove_ToolTipOpened((EventHandler)ComponentManager_ToolTipOpened); ComponentManager.remove_ToolTipClosed((EventHandler)ComponentManager_ToolTipClosed); } private static bool CheckCadVersion() { Version version = Application.get_Version(); int num = version.Major; string str = num.ToString(); num = version.Minor; return (str + "." + num.ToString()).Equals("20.1"); } private static void LoadAssemblies(Editor ed) { try { string[] extensionsLibraries = Constants.ExtensionsLibraries; foreach (string text in extensionsLibraries) { string text2 = Path.Combine(Constants.get_ExtensionsDirectory(), text); if (File.Exists(text2)) { if (!_quiteLoad) ed.WriteMessage("\n* " + Language.GetItem("AutocadDlls", "p11") + " " + text); Assembly.LoadFrom(text2); } } } catch (Exception ex) { ExceptionBox.Show(ex); } } private static void LoadBaseAssemblies(Editor ed) { try { string text = Path.Combine(Constants.get_CurrentDirectory(), "Data"); if (Directory.Exists(text)) { string[] baseFiles = BaseFiles; foreach (string text2 in baseFiles) { string text3 = Path.Combine(text, text2); if (File.Exists(text3)) { if (!_quiteLoad) ed.WriteMessage("\n* " + Language.GetItem("AutocadDlls", "p12") + " " + text2); Assembly.LoadFrom(text3); } else if (!_quiteLoad) { ed.WriteMessage("\n* " + Language.GetItem("AutocadDlls", "p13") + " " + text2); } } } else if (!_quiteLoad) { ed.WriteMessage("\n" + Language.GetItem("AutocadDlls", "p14")); } } catch (Exception ex) { ExceptionBox.Show(ex); } } private static int LoadPlugins(Editor ed) { int num = 0; try { RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\ModPlus\\Plugins") ?? Registry.CurrentUser.OpenSubKey("ModPlus\\Functions"); if (registryKey != null) { using (registryKey) { string[] subKeyNames = registryKey.GetSubKeyNames(); foreach (string text in subKeyNames) { RegistryKey registryKey2 = registryKey.OpenSubKey(text); if (registryKey2 != null) { string[] subKeyNames2 = registryKey2.GetSubKeyNames(); foreach (string text2 in subKeyNames2) { if (text2.Equals("2016")) { RegistryKey registryKey3 = registryKey2.OpenSubKey(text2); if (registryKey3 != null) { string pluginFile = GetPluginFile(text, "2016"); if (!string.IsNullOrEmpty(pluginFile) && File.Exists(pluginFile)) { string value = registryKey3.GetValue("OnOff")?.ToString() ?? "True"; if (!bool.TryParse(value, out bool result) | result) { if (!_quiteLoad) ed.WriteMessage("\n* " + Language.GetItem("AutocadDlls", "p15") + " " + text); Assembly loadedFuncAssembly = Assembly.LoadFrom(pluginFile); LoadPluginsHelper.GetDataFromFunctionInterface(loadedFuncAssembly); num++; } } } } } } } } return num; } return num; } catch (Exception ex) { ExceptionBox.Show(ex); return num; } } private static string GetPluginFile(string pluginName, string availProductVersion) { return Path.Combine(Constants.get_CurrentDirectory(), "Functions", "AutoCAD", pluginName, pluginName + "_" + availProductVersion + ".dll"); } private static void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e) { if ((object)ComponentManager.get_Ribbon() != null) { ComponentManager.get_Ribbon().add_BackgroundRenderFinished((EventHandler)RibbonOnBackgroundRenderFinished); if (Variables.get_Ribbon()) RibbonBuilder.BuildRibbon(false); else RibbonBuilder.RemoveRibbon(); ComponentManager.remove_ItemInitialized((EventHandler<RibbonItemEventArgs>)ComponentManager_ItemInitialized); } } private static void RibbonOnBackgroundRenderFinished(object sender, EventArgs e) { if (Variables.get_Ribbon()) RibbonBuilder.BuildRibbon(false); else RibbonBuilder.RemoveRibbon(); } private void AcAppOnSystemVariableChanged(object sender, SystemVariableChangedEventArgs e) { if (e.get_Name().Equals("WSCURRENT") && Variables.get_Palette()) MpPalette.CreatePalette(false); } [AsyncStateMachine(typeof(<CheckAdaptation>d__19))] [DebuggerStepThrough] private static void CheckAdaptation() { <CheckAdaptation>d__19 stateMachine = new <CheckAdaptation>d__19(); stateMachine.<>t__builder = AsyncVoidMethodBuilder.Create(); stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); } private void AutoCadMessageHandler(object sender, PreTranslateMessageEventArgs e) { MSG message = e.get_Message(); if (message.get_message() == 256) { message = e.get_Message(); if ((int)message.get_wParam() == 112 && _currentTooltip != null && _currentTooltip.Length > 8 && _currentTooltip.StartsWith("https://modplus.org/")) { _dropNextHelpCall = true; object systemVariable = Application.GetSystemVariable("NOMUTT"); string text = $"""{_currentTooltip}""{systemVariable}"""; Application.SetSystemVariable("NOMUTT", (object)1); Application.get_DocumentManager().get_MdiActiveDocument().SendStringToExecute(text, true, false, false); e.set_Handled(true); } } else { message = e.get_Message(); if (message.get_message() == 77 && _dropNextHelpCall) { _dropNextHelpCall = false; e.set_Handled(true); } } } private static void ComponentManager_ToolTipOpened(object sender, EventArgs e) { ToolTip val = sender as ToolTip; if (val != null) { RibbonToolTip val2 = val.get_Content() as RibbonToolTip; if (val2 == null) _currentTooltip = val.get_HelpTopic(); else _currentTooltip = val2.get_HelpTopic(); } } private static void ComponentManager_ToolTipClosed(object sender, EventArgs e) { _currentTooltip = null; } } }