-
Notifications
You must be signed in to change notification settings - Fork 2
/
ControllerSettings.cs
executable file
·331 lines (300 loc) · 18.4 KB
/
ControllerSettings.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
using System;
using System.Configuration;
using System.Drawing;
using System.Windows;
using SharpDX.XInput;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
namespace d3gamepad
{
public class ControllerSettings
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);
public struct Rect
{
public int Left { get; set; }
public int Top { get; set; }
public int Right { get; set; }
public int Bottom { get; set; }
}
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
public enum DeviceCap
{
VERTRES = 10,
DESKTOPVERTRES = 117,
}
public int character_ratio { get; }
public int deadzone { get; }
public double force_ratio { get; }
public int max { get; }
public int max_stick { get; }
public int stick_speed { get; }
public int stick2_ratio { get; }
public int vb_stick_value { get; }
public bool rumble { get; }
public int rumble_delay { get; }
public int rumble_min_dmg { get; }
public bool dpi_check { get; }
public bool moveattack { get; set; }
public float ScreenScalingFactor { get; set; }
// VKC
public string VKC_ForceStop { get; set; }
public string VKC_ForceMove { get; set; }
public string VKC_Skill3 { get; set; }
public string VKC_Skill4 { get; set; }
public string VKC_Skill5 { get; set; }
public string VKC_Skill6 { get; set; }
public string VKC_Potion { get; set; }
public string VKC_Character { get; set; }
public string VKC_TownPortal { get; set; }
public string VKC_Skill { get; set; }
public string VKC_Start { get; set; }
public string VKC_Inventory { get; set; }
public string VKC_MAP { get; set; }
public string VKC_HINTS { get; set; }
public string VKC_SKIP { get; set; }
// SCREEN VARIABLES
public int d3Width { get; set; }
public int d3Height { get; set; }
public int UIWidth { get; set; }
public int UIHeight { get; set; }
public int c_d3Width { get; set; }
public int c_d3Height { get; set; }
public int screenWidth { get; set; }
public int screenHeight { get; set; }
public Rect d3_Rect = new Rect();
public bool hasChanged = false;
private string D3Prefs;
public int refresh_rate { get; set; }
public int stick_speed2 { get; set; }
public GamepadButtonFlags GamepadButtonFlagsA { get; }
public GamepadButtonFlags GamepadButtonFlagsB { get; }
public GamepadButtonFlags GamepadButtonFlagsBack { get; }
public GamepadButtonFlags GamepadButtonFlagsDPadDown { get; }
public GamepadButtonFlags GamepadButtonFlagsDPadLeft { get; }
public GamepadButtonFlags GamepadButtonFlagsDPadRight { get; }
public GamepadButtonFlags GamepadButtonFlagsDPadUp { get; }
public GamepadButtonFlags GamepadButtonFlagsLeftShoulder { get; }
public GamepadButtonFlags GamepadButtonFlagsLeftThumb { get; }
public GamepadButtonFlags GamepadButtonFlagsRightShoulder { get; }
public GamepadButtonFlags GamepadButtonFlagsRightThumb { get; }
public GamepadButtonFlags GamepadButtonFlagsStart { get; }
public GamepadButtonFlags GamepadButtonFlagsX { get; }
public GamepadButtonFlags GamepadButtonFlagsY { get; }
public ControllerSettings()
{
// VKC
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_ForceMove"]))
VKC_ForceMove = Convert.ToString(ConfigurationManager.AppSettings["VKC_ForceMove"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_ForceStop"]))
VKC_ForceStop = Convert.ToString(ConfigurationManager.AppSettings["VKC_ForceStop"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_Skill3"]))
VKC_Skill3 = Convert.ToString(ConfigurationManager.AppSettings["VKC_Skill3"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_Skill4"]))
VKC_Skill4 = Convert.ToString(ConfigurationManager.AppSettings["VKC_Skill4"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_Skill5"]))
VKC_Skill5 = Convert.ToString(ConfigurationManager.AppSettings["VKC_Skill5"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_Skill6"]))
VKC_Skill6 = Convert.ToString(ConfigurationManager.AppSettings["VKC_Skill6"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_Potion"]))
VKC_Potion = Convert.ToString(ConfigurationManager.AppSettings["VKC_Potion"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_Character"]))
VKC_Character = Convert.ToString(ConfigurationManager.AppSettings["VKC_Character"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_TownPortal"]))
VKC_TownPortal = Convert.ToString(ConfigurationManager.AppSettings["VKC_TownPortal"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_Skill"]))
VKC_Skill = Convert.ToString(ConfigurationManager.AppSettings["VKC_Skill"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_Start"]))
VKC_Start = Convert.ToString(ConfigurationManager.AppSettings["VKC_Start"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_Inventory"]))
VKC_Inventory = Convert.ToString(ConfigurationManager.AppSettings["VKC_Inventory"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_MAP"]))
VKC_MAP = Convert.ToString(ConfigurationManager.AppSettings["VKC_MAP"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_HINTS"]))
VKC_HINTS = Convert.ToString(ConfigurationManager.AppSettings["VKC_HINTS"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["VKC_SKIP"]))
VKC_SKIP = Convert.ToString(ConfigurationManager.AppSettings["VKC_SKIP"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["force_ratio"]))
force_ratio = Convert.ToDouble(ConfigurationManager.AppSettings["force_ratio"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["stick2_ratio"]))
stick2_ratio = Convert.ToInt16(ConfigurationManager.AppSettings["stick2_ratio"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["character_ratio"]))
character_ratio = Convert.ToInt16(ConfigurationManager.AppSettings["character_ratio"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["max"]))
max = Convert.ToInt32(ConfigurationManager.AppSettings["max"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["max_stick"]))
max_stick = Convert.ToInt16(ConfigurationManager.AppSettings["max_stick"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["deadzone"]))
deadzone = Convert.ToInt16(ConfigurationManager.AppSettings["deadzone"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["stick_speed"]))
stick_speed = Convert.ToInt32(ConfigurationManager.AppSettings["stick_speed"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["moveattack"]))
moveattack = Convert.ToBoolean(ConfigurationManager.AppSettings["moveattack"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["rumble"]))
rumble = Convert.ToBoolean(ConfigurationManager.AppSettings["rumble"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["rumble_delay"]))
rumble_delay = Convert.ToInt16(ConfigurationManager.AppSettings["rumble_delay"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["rumble_min_dmg"]))
rumble_min_dmg = Convert.ToInt16(ConfigurationManager.AppSettings["rumble_min_dmg"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["vb_stick"]))
vb_stick_value = Convert.ToInt16(ConfigurationManager.AppSettings["vb_stick"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["dpi_check"]))
dpi_check = Convert.ToBoolean(ConfigurationManager.AppSettings["dpi_check"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["refresh_rate"]))
refresh_rate = Convert.ToInt16(ConfigurationManager.AppSettings["refresh_rate"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsX"]))
GamepadButtonFlagsX = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsX"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsA"]))
GamepadButtonFlagsA = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsA"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsB"]))
GamepadButtonFlagsB = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsB"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsY"]))
GamepadButtonFlagsY = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsY"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsRightShoulder"]))
GamepadButtonFlagsRightShoulder = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsRightShoulder"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsLeftShoulder"]))
GamepadButtonFlagsLeftShoulder = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsLeftShoulder"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsStart"]))
GamepadButtonFlagsStart = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsStart"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsBack"]))
GamepadButtonFlagsBack = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsBack"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsDPadUp"]))
GamepadButtonFlagsDPadUp = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsDPadUp"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsDPadRight"]))
GamepadButtonFlagsDPadRight = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsDPadRight"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsDPadLeft"]))
GamepadButtonFlagsDPadLeft = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsDPadLeft"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsDPadDown"]))
GamepadButtonFlagsDPadDown = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsDPadDown"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsLeftThumb"]))
GamepadButtonFlagsLeftThumb = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsLeftThumb"]);
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["GamepadButtonFlagsRightThumb"]))
GamepadButtonFlagsRightThumb = ReadKeyString(ConfigurationManager.AppSettings["GamepadButtonFlagsRightThumb"]);
}
public GamepadButtonFlags ReadKeyString(string key)
{
switch (key)
{
case "A":
return GamepadButtonFlags.A;
case "B":
return GamepadButtonFlags.B;
case "Back":
return GamepadButtonFlags.Back;
case "DPadDown":
return GamepadButtonFlags.DPadDown;
case "DPadLeft":
return GamepadButtonFlags.DPadLeft;
case "DPadRight":
return GamepadButtonFlags.DPadRight;
case "DPadUp":
return GamepadButtonFlags.DPadUp;
case "LeftShoulder":
return GamepadButtonFlags.LeftShoulder;
case "LeftThumb":
return GamepadButtonFlags.LeftThumb;
case "RightShoulder":
return GamepadButtonFlags.RightShoulder;
case "RightThumb":
return GamepadButtonFlags.RightThumb;
case "Start":
return GamepadButtonFlags.Start;
case "X":
return GamepadButtonFlags.X;
case "Y":
return GamepadButtonFlags.Y;
default:
return GamepadButtonFlags.None;
}
}
private string Between(ref string src, string start, string ended, bool del)
{
string ret = "";
int idxStart = src.IndexOf(start);
if (idxStart != -1)
{
idxStart = idxStart + start.Length;
int idxEnd = src.IndexOf(ended, idxStart);
if (idxEnd != -1)
{
ret = src.Substring(idxStart, idxEnd - idxStart);
if (del == true)
src = src.Replace(start + ret + ended, "");
}
}
return ret;
}
public int DisplayModeWindowMode;
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Documents", "Diablo III", "D3Prefs.txt");
public bool UpdateScreenValues()
{
// GET WINDOW
hasChanged = false;
if (File.Exists(path))
{
try
{
using (FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader reader = new StreamReader(stream))
{
string readText = reader.ReadToEnd();
if (readText != D3Prefs)
{
DisplayModeWindowMode = Int32.Parse(Between(ref readText, "DisplayModeWindowMode \"", "\"", false));
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
IntPtr desktop = g.GetHdc();
int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);
ScreenScalingFactor = dpi_check ? (float)PhysicalScreenHeight / (float)LogicalScreenHeight : 1;
screenWidth = Convert.ToInt16(SystemParameters.PrimaryScreenWidth * ScreenScalingFactor);
screenHeight = Convert.ToInt16(SystemParameters.PrimaryScreenHeight * ScreenScalingFactor);
if (DisplayModeWindowMode == 1)
{
// Windowed
d3Width = Int32.Parse(Between(ref readText, "DisplayModeWinWidth \"", "\"", false));
d3Height = Int32.Parse(Between(ref readText, "DisplayModeWinHeight \"", "\"", false));
UIWidth = Int32.Parse(Between(ref readText, "DisplayModeWidth \"", "\"", false));
UIHeight = Int32.Parse(Between(ref readText, "DisplayModeHeight \"", "\"", false));
d3_Rect.Left = Int32.Parse(Between(ref readText, "DisplayModeWinLeft \"", "\"", false));
d3_Rect.Top = Int32.Parse(Between(ref readText, "DisplayModeWinTop \"", "\"", false));
d3_Rect.Right = d3_Rect.Left + d3Width;
// Windows bar
d3_Rect.Top += 30;
d3Height -= 38; // why 8 ?!
d3_Rect.Bottom = d3_Rect.Top + d3Height;
}
else
{
// Fullscreen
UIWidth = d3Width = screenWidth;
UIHeight = d3Height = screenHeight;
d3_Rect.Left = 0;
d3_Rect.Top = 0;
d3_Rect.Right = UIWidth;
d3_Rect.Bottom = UIHeight;
}
Trace.WriteLine("DisplayModeWindowMode:" + DisplayModeWindowMode + "\nPrimaryScreenWidth:" + UIWidth + "\nPrimaryScreenHeight:" + UIHeight);
c_d3Width = d3Width / 2;
c_d3Height = (d3Height - d3Height / character_ratio) / 2;
stick_speed2 = c_d3Width / stick2_ratio;
D3Prefs = readText;
hasChanged = true;
}
}
}
}catch(Exception)
{
// File is being read/write by D3
Trace.WriteLine("File is being read/write by D3");
}
}
return hasChanged;
}
}
}