-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trainer.cs
286 lines (258 loc) · 8.54 KB
/
Trainer.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LBAMemoryModule;
namespace LBATrainer
{
/**
* Shared stuff goes in here
*/
public partial class frmTrainer : Form
{
const byte LBA_ONE = 1;
const byte LBA_TWO = 2;
private Items items;
private Mem memRoutines;
oTimerSetItems tsi;
oTimerGetItems tgi;
public frmTrainer()
{
InitializeComponent();
//tcLBA2Inner.TabPages.Remove(tpLBA2Debug);
memRoutines = new Mem();
scan(memRoutines.DetectLBAVersion());
SetDoubleBuffered(tcLBAVersion);
tsi = new oTimerSetItems(oTimerSetItems.LBAVersion.One);
tgi = new oTimerGetItems();
}
#region General
#region setDoubleBuffered
/**
* Used to stop flickering on interface update
* caused by constantly updating with times
*/
public static void SetDoubleBuffered(Control control)
{
// set instance non-public property with name "DoubleBuffered" to true
typeof(Control).InvokeMember("DoubleBuffered",
BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, control, new object[] { true });
}
#endregion
private void TcLBAVersion_SelectedIndexChanged(object sender, EventArgs e)
{
scan((uint)tcLBAVersion.SelectedIndex + 1);
}
#endregion
private void FrmTrainer_Load(object sender, EventArgs e)
{
Reload(sender, e);
}
private void FrmTrainer_FormClosed(object sender, FormClosedEventArgs e)
{
LBA1SG_FormClosed(sender, e);
}
private int getInt(string value)
{
int val;
if (!int.TryParse(value, out val)) return -1;
return val;
}
//To be triggered from TextChanged event
private void filterCBO(ComboBox cb, Item[] itms)
{
//If not entering data i.e. empty field
if (-1 != cb.SelectedIndex) return;
cb.Items.Clear();
for (int i = 0; i < itms.Length; i++)
if (itms[i].name.ToLower().Contains(cb.Text.ToLower()))
cb.Items.Add(itms[i]);
cb.SelectionStart = cb.Text.Length;
cb.SelectionLength = 0;
}
#region hotkey
private HotKey registerHotKey(Keys k)
{
try
{
HotKey hk = new HotKey(this.Handle);
hk.RegisterHotKeys((uint)k);
return hk;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return null;
}
private void unregisterHotKey(HotKey hk)
{
try
{
if (null != hk)
{
hk.UnRegisterHotKeys();
hk = null;
}
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
}
protected override void WndProc(ref Message keyPressed)
{
if (keyPressed.Msg == 0x0312)
{
LBA1SG_processHotkey((Keys)keyPressed.WParam);
//LBA1Menu_processHotkey((Keys)keyPressed.WParam);
LBA2HyperCar_ProcessHotKey((Keys)keyPressed.WParam);
LBA1Behaviour_processHotkey((Keys)keyPressed.WParam);
LBA1DWD_processHotkey((Keys)keyPressed.WParam);
}
base.WndProc(ref keyPressed);
}
#endregion
//This should be integrated into oTimerSetItems
private oTimerSetItems itemToggle(oTimerSetItems tsi, uint offset, ushort val, byte size, oTimerSetItems.LBAVersion LBAVer)
{
if (null == tsi) tsi = new oTimerSetItems(LBAVer);
if (!tsi.RemoveIfExists(offset))
tsi.AddItem(offset, val, size);
if (tsi.IsEmpty()) tsi = null;
return tsi;
}
private string getLBAFilesPath(ushort LBAVer)
{
return AppDomain.CurrentDomain.BaseDirectory + "files\\languages\\ENG\\lba" + LBAVer.ToString() + "\\";
}
#region MenuItems
private void RefreshToolStripMenuItem_Click(object sender, EventArgs e)
{
Reload(sender, e);
}
private void Reload(object sender, EventArgs e)
{
Options opt = new Options();
memRoutines = new Mem();
byte ver = memRoutines.DetectLBAVersion();
//Load even if game not running
if (0 == ver)
{
;
}
//Load only if LBA1 running
if (1 == ver)
{
memRoutines.WriteVal(1, (int)LBA1_AUTOZOOM, (ushort)(LBA1AutoZoomToolStripMenuItem1.Checked ? 1 : 0), 1);
LBA1SG_Load(sender, e, opt);
LBA1MenuFunctions_Load(sender, e, opt);
LBA1_Flags.Scan();
FlyingLBA1.RefreshConnection();
ucTeleportLBA1.RefreshConnection();
LBA1Othr_Start();
return;
}
//Load only if LBA2 running
if (2 == ver)
{
LBA2Slate_Load();
LBA2_Flags.Scan();
FlyingLBA2.RefreshConnection();
ucTeleportLBA2.RefreshConnection();
LBA2Othr_Load();
return;
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
new AboutBox1().ShowDialog();
}
#endregion
private void LBA2Misc_btnBlowtron_Click(object sender, EventArgs e)
{
byte val = (byte) memRoutines.readVal(LBA2_BLOWTRON_LOCATION, 1);
LBA2Misc_rbBlowtron0.Checked = (0 == val || 3 == val);
LBA2Misc_rbBlowtron1.Checked = (1 == val);
LBA2Misc_rbBlowtron2.Checked = (2 == val);
}
private void btnRickKeyShow_Click(object sender, EventArgs e)
{
byte val = (byte)memRoutines.readVal(0x58107, 1);
LBA2Misc_rbRickKeyDoor.Checked = (1 == val);
LBA2Misc_rbRickKeyMiddle.Checked = (0 == val);
LBA2Misc_rbRickKeyOffice.Checked = (2 == val);
}
private void button2_Click(object sender, EventArgs e)
{
Movies m = new Movies(getLBAFilesPath(2));
byte val = byte.Parse(textBox1.Text);
m.Load();
if (m.movies[val].IsEnabled())
m.movies[val].Disable();
else
m.movies[val].Enable();
}
private void manuelAggressionToolStripMenuItem_Click(object sender, EventArgs e)
{
/*Auto: 0x1278 = 4. 0xE1E = 1
* Manual: 0x1278 = 2. 0xE1E = 0
*
*/
bool manual = 0 == memRoutines.readVal(0x1278, 1);
if (manual)
{
memRoutines.WriteVal(0x1278, 4, 1);
memRoutines.WriteVal(0xE1E, 1, 1);
}
else
{
memRoutines.WriteVal(0x1278, 2, 1);
memRoutines.WriteVal(0xE1E, 0, 1);
}
}
/*private void LBA1Fly_chkWalkingInAir_CheckedChanged(object sender, EventArgs e)
{
if (LBA1Fly_chkWalkingInAir.Checked)
tsi.AddItem(0xD54D, 0, 1);
else
{
tsi.RemoveIfExists(0xD54D);
memRoutines.WriteVal(0xD54D, 8, 1);
}
}
private void LBA2Flying_chkDisableGravity_CheckedChanged(object sender, EventArgs e)
{
if (LBA2Flying_chkDisableGravity.Checked)
tsi.AddItem(0x580FA, 0, 2);
else
{
tsi.RemoveIfExists(0x580FA);
memRoutines.WriteVal(0x580FA, 8, 1);
}
}*/
}
public class NameValue
{
public byte val;
public string name;
public NameValue() { }
public NameValue(byte val, string name)
{
this.val = val;
this.name = name;
}
public override string ToString()
{
return name;
}
}
}