-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
174 lines (144 loc) · 5.2 KB
/
Program.cs
File metadata and controls
174 lines (144 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
class Program
{
static void Main()
{
Console.Title = "Neverlose Tools";
Console.OutputEncoding = Encoding.UTF8;
DrawHeader();
Console.WriteLine("请选择游戏:");
Console.WriteLine(" [1] CS2");
Console.WriteLine(" [2] CSGO Legacy");
Console.Write("\n> ");
string choice = Console.ReadLine();
bool isCsgo = choice == "2";
Console.Write("\n请输入启动项(留空不使用启动项): ");
string launchOptions = Console.ReadLine() ?? "";
string temp = Path.GetTempPath();
string nlLog = Path.Combine(temp, "nl.log");
清空日志(nlLog);
Console.WriteLine("\n正在监听,请打开注入器注入。");
等待日志关键字(nlLog, "PreinitSuspended");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nNL注入器初始化成功,准备启动游戏");
Console.ResetColor();
结束Steam();
启动游戏(isCsgo, launchOptions);
if (isCsgo)
{
string csgoLog = Path.Combine(temp, "nl_csgo.log");
Console.WriteLine("\n等待NL注入...");
清空日志(csgoLog);
等待并提示(csgoLog, "server 0", "NL服务器连接成功!");
等待并提示(csgoLog, "user...", "NL用户信息获取成功!");
等待并提示(csgoLog, "...1", "开始注入流程!");
等待并提示(csgoLog, "Initializing", "✔ 注入成功,模块正在初始化...");
等待日志关键字(csgoLog, "Finished.");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("\n✔ 所有注入流程已完成");
Console.ResetColor();
}
Console.WriteLine("\n程序结束,按任意键退出...");
Console.ReadKey();
}
static void 清空日志(string path)
{
try
{
File.WriteAllText(path, string.Empty);
//Console.WriteLine($"已清空日志:{Path.GetFileName(path)}");
}
catch
{
Console.WriteLine($"无法清空日志:{Path.GetFileName(path)}");
}
}
static void 等待日志关键字(string path, string keyword)
{
long lastLen = 0;
while (true)
{
if (File.Exists(path))
{
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
if (fs.Length > lastLen)
{
fs.Seek(lastLen, SeekOrigin.Begin);
using var sr = new StreamReader(fs);
string content = sr.ReadToEnd();
lastLen = fs.Length;
if (content.Contains(keyword))
return;
}
}
Thread.Sleep(500);
}
}
static void 等待并提示(string path, string keyword, string message)
{
long lastLen = 0;
bool 已提示 = false;
while (true)
{
if (File.Exists(path))
{
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
if (fs.Length > lastLen)
{
fs.Seek(lastLen, SeekOrigin.Begin);
using var sr = new StreamReader(fs);
string content = sr.ReadToEnd();
lastLen = fs.Length;
if (!已提示 && content.Contains(keyword))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(message);
Console.ResetColor();
已提示 = true;
return;
}
}
}
Thread.Sleep(500);
}
}
static void 结束Steam()
{
foreach (var p in Process.GetProcessesByName("steam"))
{
try
{
Console.WriteLine("正在结束 Steam.exe...");
p.Kill();
p.WaitForExit();
}
catch { }
}
}
static void 启动游戏(bool isCsgo, string launchOptions)
{
string url = "steam://run/730";
if (isCsgo)
url += "//-beta csgo_legacy";
if (!string.IsNullOrWhiteSpace(launchOptions))
url += " " + launchOptions;
Console.WriteLine($"启动游戏:{url}");
Process.Start(new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
static void DrawHeader()
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("====================================");
Console.WriteLine(" Neverlose Tools");
Console.WriteLine("====================================\n");
Console.ResetColor();
}
}