-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
121 lines (110 loc) · 3.87 KB
/
Form1.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
using System;
using System.Diagnostics;
using System.Windows.Forms;
using static MemoryHelper;
namespace EventLogger
{
public partial class Form1 : Form
{
public Timer timer = new Timer() { Interval = 100 };
public Logger logger;
public int lobbyStatePtr = 0;
public int lobbyState = 0;
public Form1()
{
InitializeComponent();
logger = new Logger(null, cacheEventPlayers: false, logHexTimes: true);
timer.Tick += LogManager;
timer.Start();
FormMessage("Logging started! (custom games only)");
FormMessage("Log folder: " + AppDomain.CurrentDomain.BaseDirectory);
FormMessage("Close this window to stop logging.");
}
public void LogManager(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("ASN_App_PcDx9_Final");
if (processes.Length == 0)
{
if (processId != 0)
{
FormMessage("S&ASRT was closed");
MemoryHelper.Reset();
}
return;
}
else if (processes[0].Id != processId)
{
FormMessage("S&ASRT is running");
MemoryHelper.Initialise(processes[0].Id);
LobbyStateInit();
}
int newLobbyState = GetLobbyState();
if (logger.currentSession == null && lobbyState > 0 && (ReadByte(ReadInt(0xEC1A88) + 0x101D6C) & 0x1F) == 16) // must be an active custom lobby
{
logger.NewSession();
FormMessage("Session started");
}
if (lobbyState == 3 && newLobbyState == 4)
{
logger.NewEvent();
FormMessage("Event started: " + logger.currentSession.lastEvent.map.GetDescription() + " " + logger.currentSession.lastEvent.type.GetDescription());
}
if (lobbyState == 18 && newLobbyState != 18)
{
logger.LogEventResults();
logger.WriteLogFiles();
FormMessage("Results logged!");
}
lobbyState = newLobbyState;
}
public void LobbyStateInit()
{
if (ReadByte(0x70665C) == 0xEB)
{
// already loaded
lobbyStatePtr = ReadInt(0x70668A);
}
else
{
Write(0x70665C, new byte[] { 0xEB, 0x28 });
Write(0x706686, new byte[] { 0x8B, 0xF1, 0x88, 0x15 });
lobbyStatePtr = Allocate(0, 1);
Write(0x70668A, lobbyStatePtr);
Write(0x70668E, new byte[] { 0xEB, 0xCE });
}
}
public int GetLobbyState()
{
int lobbyState = 0;
if (ReadByte(ReadInt(0xEC1A88) + 0x525) > 0)
{
if (ReadInt(ReadInt(0xBCE920)) != 0)
{
lobbyState = ReadByte(0xFF0FFC);
}
else
{
lobbyState = Math.Max((byte)1, ReadByte(ReadInt(0xEC1A88) + 0x101D72));
}
}
return lobbyState;
}
public void FormMessage(string message)
{
message = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "] " + message;
if (!string.IsNullOrEmpty(richTextBox1.Text))
{
message = "\n" + message;
}
richTextBox1.AppendText(message);
}
private void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
logger.cacheEventPlayers = checkBox1.Checked;
}
private void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
logger.logHexTimes = checkBox2.Checked;
}
}
}