diff --git a/.vscode/launch.json b/.vscode/launch.json index f980ab9..51f9cfb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,7 +1,16 @@ { - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", - "configurations": [] + "configurations": [ + { + "name": ".NET Core Launch", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/net8.0/Debug.dll", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + "console": "externalTerminal" + } + ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7f159e7..d05a36d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,16 +1,15 @@ { - "version": "2.0.0", - "tasks": [ - { - "type": "dotnet", - "task": "build D:\\Debug\\Debug.csproj", - "file": "D:\\Debug\\Debug.csproj", - "group": { - "kind": "test", - "isDefault": true - }, - "problemMatcher": [], - "label": "dotnet: build D:\\Debug\\Debug.csproj" - } - ] + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}" + ], + "problemMatcher": "$msCompile" + } + ] } \ No newline at end of file diff --git a/App.config b/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Chouka.cs b/Chouka.cs index 4758483..d8fa646 100644 --- a/Chouka.cs +++ b/Chouka.cs @@ -1,7 +1,13 @@  +using Debug.MODS; + namespace Debug; -public class ChouKa +#pragma warning disable 0414 // 关闭未使用变量的警告 +#pragma warning disable CS0414 +public class ChouKa : Activity { + public const string Title = "抽卡"; + public const int Priority = 0; // 10 20 30 50 60 70 80 90 int currentsize = 0; int baodinum = 70; //第一次保底80 往后就用随机数80 ~ 90 @@ -10,7 +16,6 @@ public class ChouKa string[] waile = ["薄荷", "铁锈会员10天"];// 设置歪的物品 string baozan = "name";//设置本次UP池 精品 只能有一个 - //普通物品抽中数量 int putongsize = 0; //精品物品抽中数量 @@ -19,10 +24,8 @@ public class ChouKa int waisize_A = 0, waisize_B = 0; //创建随机数生成器 private readonly Random random = new(); - string message = $"普通抽卡概率:{70}%\n精品抽卡概率:{30}%\n歪概率:{10}%\n" + - - "保底 80~90"; - + readonly string message = string.Empty; + // = $"普通抽卡概率:{70}%\n精品抽卡概率:{30}%\n歪概率:{10}%\n" +"保底 80~90"; public ChouKa() { // 清除控制台屏幕 @@ -30,7 +33,7 @@ public class ChouKa Console.Clear(); while (Program.IsWhile) { - ModeSwitch.New("抽卡系统", ["返回首页", "普通抽卡*1", "普通抽卡*10"], (a) => + _ = new ModeSwitch("抽卡系统", ["返回首页", "普通抽卡*1", "普通抽卡*10"], (a) => { switch (a) { @@ -47,11 +50,17 @@ public class ChouKa } break; } - }, message + "\n" + "当前保底:" + baodinum + "\n当前歪概率:" + waisize + "\n当前普通概率:" + (100 - baodinum) + - $"\n普通物品:{putongsize} 精品物品:{baozansize} 歪物品:薄荷{waisize_A} 铁锈会员10天{waisize_B}\n"); + }, GetDegree("保底概率", baodinum) + + "\n" + GetDegree("歪概率", waisize) + + "\n" + GetDegree("UP概率", 100 - baodinum) + + $"\n垃圾:{putongsize} && Up:{baozansize} && 歪物品:薄荷糖:{waisize_A} 橘子{waisize_B}\n"); } _ = new Program(); } + string GetDegree(string message, int num) + { + return message + ":" + num + "%"; + } public void Start() { diff --git a/Debug.csproj b/Debug.csproj index 7f65e79..7a9d213 100644 --- a/Debug.csproj +++ b/Debug.csproj @@ -1,5 +1,4 @@  - Exe net8.0 @@ -9,5 +8,7 @@ + \ No newline at end of file diff --git a/Debug.dtd b/Debug.dtd new file mode 100644 index 0000000..29cb1db --- /dev/null +++ b/Debug.dtd @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/MODS/Activity.cs b/MODS/Activity.cs new file mode 100644 index 0000000..30df31c --- /dev/null +++ b/MODS/Activity.cs @@ -0,0 +1,29 @@ + + +using System.Reflection; + +#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。 +public class Activity +{ + public Activity() + { + // 获取当前类的类型 + Type activityType = this.GetType(); + // Console.WriteLine($"当前对象的类型是:{activityType.Name}"); + string Title; + // 获取静态字段 Title + FieldInfo titleSField = activityType.GetField("Title", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy + | BindingFlags.NonPublic); + if (titleSField != null) + { + // 获取静态字段的值 + Title = (string)titleSField.GetValue(null); // 静态字段传 null + } + else + { + Title = activityType.Name; + } + // Console.WriteLine($"当前对象的标题是:{Title}"); + Console.Title = Title ?? "null"; + } +} \ No newline at end of file diff --git a/ModeSwitch.cs b/MODS/ModeSwitch.cs similarity index 99% rename from ModeSwitch.cs rename to MODS/ModeSwitch.cs index 9c16ab8..b2b366e 100644 --- a/ModeSwitch.cs +++ b/MODS/ModeSwitch.cs @@ -1,9 +1,9 @@ using System.Text; -namespace Debug; +namespace Debug.MODS; public class ModeSwitch { - private object? class_; + private readonly object? class_; public event Action? Enter; private readonly string[] str = ["退出"]; private int mode = 0; diff --git a/MODS/Title.cs b/MODS/Title.cs new file mode 100644 index 0000000..b57a56d --- /dev/null +++ b/MODS/Title.cs @@ -0,0 +1,15 @@ + + +using System.Reflection; + +namespace Debug.MODS; +public class Title +{ + public string title; + public int Priority; + public Title(string title, int priority) + { + this.title = title; + this.Priority = priority; + } +} \ No newline at end of file diff --git a/MODS/Tutke b/MODS/Tutke new file mode 100644 index 0000000..e69de29 diff --git a/MODS/TypeHelper.cs b/MODS/TypeHelper.cs new file mode 100644 index 0000000..c6a37e0 --- /dev/null +++ b/MODS/TypeHelper.cs @@ -0,0 +1,106 @@ + +using System.Reflection; + +namespace Debug.MODS; +public class TypeHelper +{ + public readonly List result = []; + readonly string Title = "Title"; + readonly string Priority = "Priority"; + public TypeHelper() + { + Run(); + } + public TypeHelper(string title, string Priority) + { + this.Title = title; + this.Priority = Priority; + Run(); + } + + private void Run() + { + GetTypesInheritingFrom(); + } + + public void showUI() + { + + } + + /// + /// 获取所有继承自指定基类的类型 + /// + /// 基类 + /// 继承自基类的类型列表 + public List GetTypesInheritingFrom() + { + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + try + { + foreach (var type in assembly.GetTypes()) + { + if (typeof(TBase).IsAssignableFrom(type) && type != typeof(TBase)) + { + result.Add(type); + } + } + } + catch (ReflectionTypeLoadException ex) + { + foreach (var type in ex.Types.Where(t => t != null)) + { + if (typeof(TBase).IsAssignableFrom(type) && type != typeof(TBase)) + { + result.Add(type); + } + } + } + } + // GetTitles(); + // 按 `Priority` 常量值排序 + result.Sort((a, b) => GetPriority(a).CompareTo(GetPriority(b))); + return result; + } + + private int GetPriority(Type type) + { + // 获取 `Priority` 常量字段 + var field = type.GetField(Priority, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy + | BindingFlags.NonPublic); + + // 确保字段存在且是 `int` + if (field != null && field.FieldType == typeof(int)) + { + // Console.WriteLine((int)field.GetValue(null)!); + return (int)field.GetValue(null)!; // 获取静态字段的值 + } + return int.MaxValue; // 如果没有 `Priority`,默认放到最后 + } + +#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。 + public string[] GetTitles() + { + List list = []; + foreach (var type in result) + { + string Title; + // 获取静态字段 Title + FieldInfo titleSField = type.GetField("Title", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy + | BindingFlags.NonPublic); + if (titleSField != null) + { + // 获取静态字段的值 + Title = (string)titleSField.GetValue(null); // 静态字段传 null + } + else + { + Title = type.Name; + } + // Console.WriteLine("正在搜索:" + Title); + list.Add(Title ?? "null"); + } + return [.. list]; + } +} \ No newline at end of file diff --git a/MinLong/Main.cs b/MinLong/Main.cs index 74c62c8..f854031 100644 --- a/MinLong/Main.cs +++ b/MinLong/Main.cs @@ -5,8 +5,9 @@ namespace Debug.MinLong; #pragma warning disable CA1822 // 将成员标记为 static #pragma warning disable IDE0051 // 删除未使用的私有成员 #pragma warning disable IDE1006 // 命名样式 -public class Main +public class Main : Activity { + const string Title = "小龙快跑"; public Main() { diff --git a/ModelingMusic/Music.cs b/ModelingMusic/Music.cs index e21d50c..58d70b6 100644 --- a/ModelingMusic/Music.cs +++ b/ModelingMusic/Music.cs @@ -1,18 +1,20 @@ using System.Diagnostics; using System.Text; +using Debug.MODS; namespace Debug.ModelingMusic; -public class Music +public class Music : Activity { - public static string title = "模拟音游 1.5 by"; + public const string Title = "模拟音游 1.5 by"; //选择的模式 + private const int Priority = 0; private static int mode = 0; public Music() { Console.Clear(); string[] str = ["返回首页", "启动", "手动测试", "自动测试", "字符串测试", "字符串随机测试"]; - ModeSwitch.New(title, str, (a) => + _ = new ModeSwitch(Title, str, (a) => { mode = a; Console.CursorVisible = false; // 隐藏光标 diff --git a/Program.cs b/Program.cs index d9eabd4..4790a16 100644 --- a/Program.cs +++ b/Program.cs @@ -1,63 +1,57 @@ -using System.Text; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Text; using Debug.ModelingMusic; +using Debug.MODS; namespace Debug; /// /// 主程序入口 参考 https://blog.csdn.net/oscar999/article/details/141370223 /// 在VS Code的终端中,使用dotnet build命令来编译项目。这将在项目目录中生成一个bin文件夹,其中包含编译后的程序集。 /// 使用dotnet run命令来运行项目。这将编译项目(如果尚未编译)并运行编译后的程序。 /// + +#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。 public class Program { + [DllImport("user32.dll")] + static extern IntPtr LoadKeyboardLayout(string pwszKLID, uint Flags); + + [DllImport("user32.dll")] + static extern IntPtr ActivateKeyboardLayout(IntPtr hkl, uint Flags); + const string ENGLISH_KEYBOARD_LAYOUT = "00000409"; // 美国英语布局 + // 获取所有继承自 Activity 的类 public static void Main(string[] args) { + // Console.WriteLine("Hello World!"); + _ = new Program(); + } + //Y,X + public static readonly Point[,] chars = new Point[10, 50]; + public static bool IsWhile = true; + public const char ShowChar = ' '; + public static Random random = new(); + public Program() + { + Console.Clear(); Console.Title = "Tools";//设置窗口标题 // 设置控制台输出编码,以支持复杂字符 Console.OutputEncoding = Encoding.UTF8; Console.CursorVisible = false; - // new MusicFrom(); - _ = new Program(); - } - - //Y,X - public static readonly Point[,] chars = new Point[10, 50]; - public static bool IsWhile = true; - - public const char ShowChar = ' '; - public static Random random = new(); - - public Program() - { - Console.Clear(); + var ActivityType = new TypeHelper(); // ResetChars(); - string[] str = ["抽卡", "搜索引擎", Music.title, "小龙快跑", "贪吃蛇", "铁锈助手(联机模块)[未开发]", "服务器代理"]; - var modeSwitch = new ModeSwitch("请选择你要执行的操作", str, (a) => + var modeSwitch = new ModeSwitch("请选择你要执行的操作", ActivityType.GetTitles(), (a) => { - switch (a) + object[] objects = [this]; + Type[] paramTypes = Array.ConvertAll(objects, p => p.GetType()); + ConstructorInfo constructor = ActivityType.result[a].GetConstructor(paramTypes); + if (constructor != null) { - case 0: - _ = new ChouKa();//抽卡 - break; - case 1: - _ = new Mod(); - break; - case 2: - _ = new Music(); - // _ = new MusicFrom(); - break; - case 3: - _ = new MinLong.Main(); - break; - case 4: - _ = new Tanchishe.Main(); - break; - case 5: - // _ = new Tanchishe.Main(); - _ = new Program(); - break; - case 6: - _ = new ProxySettingsHelper(this); - break; + Activator.CreateInstance(ActivityType.result[a], objects); + } + else + { + Activator.CreateInstance(ActivityType.result[a]); } }, "作者:MuQing\n使用语言:C#\n使用IDE:VS Code\n使用框架:.NET 8.0 \n测试运行平台:Windows11\n项目地址:https://git.coldmint.top/muqing/ModelingMusicForm.git"); } diff --git a/ProxySettingsHelper.cs b/ProxySettingsHelper.cs index c009d86..69a197a 100644 --- a/ProxySettingsHelper.cs +++ b/ProxySettingsHelper.cs @@ -1,10 +1,12 @@ +using Debug.MODS; using Microsoft.Win32; using System.Runtime.InteropServices; namespace Debug; #pragma warning disable CA1416 // 验证平台兼容性 #pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。 -public class ProxySettingsHelper +public class ProxySettingsHelper : Activity { + public const string Title = "服务器代理"; // 引入WinINet API函数 [DllImport("wininet.dll", SetLastError = true)] private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength); @@ -28,7 +30,7 @@ public class ProxySettingsHelper SetProxy(true, proxy); break; } - _ = new ProxySettingsHelper(this); + _ = new ProxySettingsHelper(class_); }, $"代理已{(enableProxy ? "开启" : "关闭")},地址: {proxy}"); } diff --git a/README.md b/README.md index 99dc725..2344951 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,41 @@ # ModelingDebug ### C#-Net控制台程序 -## 功能 -1. 抽卡模拟器 -2. 文件/文件夹搜索 -3. 下落字符调试 -4. 小龙快跑 简易游戏 - -## 集成和使用 +## 模块继承 +如果一个类继承了Activity那么使用GetTypesInheritingFrom把他们全部获取 +如果继承了请在里面加入一些可被识别的变量类型 +```csharp +public static Title = "模块选择器"; +public const Title = "模块选择器"; +``` +string Title 是模块的标题 +int Priority 是优先级,数字越小越靠前展示 +## 规范使用 +继承了Activity的类的方法并且同时使用了模块选择器的 类 里面要有 +Title Priority +## 选择器 +``` +string[] str = ["模块", "模块", "模块", "模块"]; +var modeSwitch = new ModeSwitch("请选择你要执行的操作:", str, (a) => +{ + switch (a) + { + case 0: + //需要执行的方法模块 + break; + case 1: + break; + default: + printfLine("还没有这个功能"); + break; + } +}); +``` +## 模块选择器 +正确的说是加载所有Activity的一个选择器 +显示到页面中(如图) +![alt text](image.png) +## 选择器的使用 内置选择模式 可自由添加模块 PgUp/W 上选择 @@ -15,41 +43,29 @@ 1···9快捷数字选择 Enter(回车) 确定执行 Esc 选择退出 Enter(回车) 返回选择器 -### 使用 + 如果选择器被传入了一个类型,则选择器会返回这一个类 + public ModeSwitch(object class_, string title, string[] a, Action Enter, string message) +### 打包和运行 Visual Studio Code Visual Studio 2022 其他能运行C# Net8.0的程序 ### 方法 - var 变量 = new ModeSwitch("string", string[], (a) => - { - //在这里处理选择逻辑 - },"message"); +1. 模块选择器
+public ModeSwitch(object class_, string title, string[] a, Action Enter, string message) +可选的是class_,message +class_是标记我可以用Esc返回这个类 +message是底部的提示信息你可以在这里标注每个功能的使用方法 +2. Activity
+自动获取被他继承子类的Title方法 +3. TypeHelper
+获取所有被这个父类继承的子类 +var ActivityType = new TypeHelper<类>(); -### 例子 - string[] str = ["模块", "模块", "模块", "模块"]; - var modeSwitch = new ModeSwitch("请选择你要执行的操作:", str, (a) => - { - switch (a) - { - case 0: - //需要执行的方法模块 - break; - case 1: - //需要执行的方法模块 - break; - case 2: - //需要执行的方法模块 - break; - case 3: - //需要执行的方法模块 - break; - case 4: - //需要执行的方法模块 - break; - default: - printfLine("还没有这个功能"); - break; - } - }); -### 新增底部注意提醒词 -public ModeSwitch(string title, string[] a, Action Enter, string message) \ No newline at end of file +自定义 获取子类的静态标题和优先级的变量定义 +public TypeHelper(string title, string Priority) + +GetTitles()获取所有子类的标题 + +GetTypesInheritingFrom() 获取所有子类 这个默认在创建的时候就执行了 + +如果你要获取被获取的类的列表可以使用ActivityType.result这个就是列表 diff --git a/SearchFile.cs b/SearchFile.cs index 2995efc..3468458 100644 --- a/SearchFile.cs +++ b/SearchFile.cs @@ -1,11 +1,13 @@ using Debug; +using Debug.MODS; /// /// 文件夹文件搜索引擎操作 /// namespace Debug; -public class Mod +public class Mod : Activity { + const string Title = "文件搜索"; private static DateTime time; /// /// 结束时间 @@ -40,7 +42,7 @@ public class Mod public Mod() { Console.Clear(); - ModeSwitch.New("搜索模式", ["返回主页", "文件", "文件夹"], MODE); + _ = new ModeSwitch("搜索模式", ["返回主页", "文件", "文件夹"], MODE); } public void MODE(int a) { diff --git a/Tanchishe/Main.cs b/Tanchishe/Main.cs index b95eeb4..1366d92 100644 --- a/Tanchishe/Main.cs +++ b/Tanchishe/Main.cs @@ -3,8 +3,9 @@ /// /// 贪吃蛇主入口 /// -public class Main +public class Main : Activity { + const string Title = "贪吃蛇"; readonly int MaxY; readonly int MaxX; public Main() diff --git a/image.png b/image.png new file mode 100644 index 0000000..699c348 Binary files /dev/null and b/image.png differ diff --git a/zidonghua.cs b/zidonghua.cs new file mode 100644 index 0000000..6ddc68c --- /dev/null +++ b/zidonghua.cs @@ -0,0 +1,90 @@ +using System; +using System.Runtime.InteropServices; +using System.Threading; + +namespace Debug; +public class zidonghua +{ + [StructLayout(LayoutKind.Sequential)] + struct INPUT + { + public int type; + public InputUnion u; + } + + [StructLayout(LayoutKind.Explicit)] + struct InputUnion + { + [FieldOffset(0)] public MOUSEINPUT mi; + [FieldOffset(0)] public KEYBDINPUT ki; + } + + [StructLayout(LayoutKind.Sequential)] + struct MOUSEINPUT + { + public int dx; + public int dy; + public int mouseData; + public int dwFlags; + public int time; + public IntPtr dwExtraInfo; + } + + [StructLayout(LayoutKind.Sequential)] + struct KEYBDINPUT + { + public short wVk; + public short wScan; + public int dwFlags; + public int time; + public IntPtr dwExtraInfo; + } + + [DllImport("user32.dll", SetLastError = true)] + static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize); + + const int INPUT_MOUSE = 0; + const int INPUT_KEYBOARD = 1; + const int KEYEVENTF_KEYUP = 0x0002; + const int MOUSEEVENTF_LEFTDOWN = 0x0002; + const int MOUSEEVENTF_LEFTUP = 0x0004; + + static void SimulateKeyPress(short keyCode) + { + INPUT[] inputs = new INPUT[2]; + inputs[0].type = INPUT_KEYBOARD; + inputs[0].u.ki.wVk = keyCode; + inputs[0].u.ki.dwFlags = 0; + + inputs[1].type = INPUT_KEYBOARD; + inputs[1].u.ki.wVk = keyCode; + inputs[1].u.ki.dwFlags = KEYEVENTF_KEYUP; + + SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT))); + } + + static void SimulateMouseClick(int x, int y) + { + INPUT[] inputs = new INPUT[2]; + inputs[0].type = INPUT_MOUSE; + inputs[0].u.mi.dx = x; + inputs[0].u.mi.dy = y; + inputs[0].u.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; + + inputs[1].type = INPUT_MOUSE; + inputs[1].u.mi.dx = x; + inputs[1].u.mi.dy = y; + inputs[1].u.mi.dwFlags = MOUSEEVENTF_LEFTUP; + + SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT))); + } + [DllImport("user32.dll")] + static extern short VkKeyScan(char ch); + public zidonghua() + { + Thread.Sleep(3000); + SimulateKeyPress(VkKeyScan('A')); + Thread.Sleep(1000); + SimulateMouseClick(500, 500); + } +}