This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
134 lines (103 loc) · 4.9 KB
/
Main.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace NostalgiaAnticheat {
public partial class Main : Form {
public Main() {
InitializeComponent();
GTASA.StartWatchDog();
GTASA.OnGameStateChanged += (state) => Invoke(new Action(() => DisplayGameState()));
lblGTAState.Text = "Estado do GTA:SA: Nenhum";
new Thread(() => {
while (true) {
Thread.Sleep(1000);
foreach (Process process in Process.GetProcesses()) {
long memory = process.WorkingSet64 / 1024 / 1024; // Convert to MB
// GTA:SA process uses between 310 and 320 MB of memory
if (memory > 310 && memory < 320) Debug.WriteLine("{0} - {1} MB", process.ProcessName, memory);
}
}
}).Start();
}
private void Main_Load(object sender, EventArgs e) {
}
// Event for when the application closes
private void Main_FormClosing(object sender, FormClosingEventArgs e) {
// Close the GTA:SA process if it's running
if (GTASA.CurrentState != GTASA.GameState.None) GTASA.Close();
}
private void DisplayGameState() {
string prefix = "Estado do GTA:SA: ";
switch (GTASA.CurrentState) {
case GTASA.GameState.None:
lblGTAState.Text = prefix + "Nenhum";
break;
case GTASA.GameState.GTASA:
lblGTAState.Text = prefix + "Rodando";
break;
case GTASA.GameState.SAMP:
lblGTAState.Text = prefix + "Rodando (SAMP)";
break;
}
}
private void button1_Click(object sender, EventArgs e) {
//listBox1.Items.Add(SAMP.IsRunning ? "SAMP is running" : "SAMP is not running");
string settingsStr = String.Empty;
Dictionary<GTASA.GameSettings, string> settings = GTASA.GetGameSettings();
foreach (KeyValuePair<GTASA.GameSettings, string> setting in settings) settingsStr += setting.Key.ToString() + ": " + setting.Value.ToString() + Environment.NewLine;
MessageBox.Show(settingsStr, "GTA:SA Settings");
}
private void button2_Click(object sender, EventArgs e) {
ProcessModuleCollection modules = GTASA.GetModules();
List<string> moduleNames = new List<string>();
/*listBox2.Items.Clear();
foreach (ProcessModule module in modules)
{
listBox2.Items.Add(module.ModuleName);
moduleNames.Add(module.ModuleName);
}*/
// Send an HTTP UPLOAD to http://localhost/nostalgia/ac.php with the module names
// Setup the POST data
Dictionary<string, string> postData = new Dictionary<string, string> {
{ "modules", String.Join(",", moduleNames.ToArray()) },
{ "player", SAMP.PlayerName },
{ "version", SAMP.Version.ToString() }
};
// Send the POST web request
var request = WebRequest.Create("https://webhook.site/8bca59e4-5496-465c-b532-cb3875766c3f");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
// Encode the POST data
string encodedData = String.Empty;
foreach (KeyValuePair<string, string> pair in postData) encodedData += WebUtility.UrlEncode(pair.Key) + "=" + WebUtility.UrlEncode(pair.Value) + "&";
// Remove the last ampersand
encodedData = encodedData.Substring(0, encodedData.Length - 1);
// Write the POST data to the request stream
byte[] data = Encoding.ASCII.GetBytes(encodedData);
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream()) stream.Write(data, 0, data.Length);
// Get the response
var response = (HttpWebResponse)request.GetResponse();
// Read the response
string responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
// Show the response
MessageBox.Show(responseString, "Response");
// Close the response
response.Close();
}
private void button4_Click(object sender, EventArgs e) {
// Load the GTA:SA IMG file
string path = SAMP.GamePath + "models\\gta3.img";
var files = IMG.Load(path);
/*listBox3.Items.Clear();
foreach (var file in files)
{
listBox3.Items.Add(String.Format("{0} - {1}", file.Key, file.Value));
}*/
}
}
}