-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
297 lines (248 loc) · 10.6 KB
/
index.js
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
const USB = require('usb');
const CRC32 = require("crc-32");
const {Profile, ProfileValueAdjustment} = require("./Profile");
const prompt = require('prompt-sync')({sigint: true});
const SONY_VID = 0x054C;
const DS_EDGE_PID = 0x0DF2;
const controller = USB.findByIds(SONY_VID, DS_EDGE_PID);
if (!controller) {
console.log("No DualSense Edge controller found... exiting.")
process.exit(0);
}
//
// controller.open();
//
// /**
// * By chancing the vValue to between addresses (Replicating bRequestSetConfigPayloads layout [0,1,2]):
// * 0x0370 - 0x0372 - Default profile
// * 0x0373 - 0x0375 - First custom profile
// * 0x0376 - 0x0378 - Second custom profile
// * 0x0379 - 0x037b - Third custom profile
// */
// controller.controlTransfer(0xa1, 1, 0x0378, 0x03, 63, function (error, buffer) {
// console.table(buffer);
// controller.close();
// });
/**
* In order to create a new profile or overriding a profile, there needs to be 3 set config calls to create one.
*
* Example below creates a new profile which has a label of B x 40 (limit of name allocation) and using default configurations
*/
let bRequestSetConfigPayloads = [[ // 12345678
0x61, 0x00, 0x01, 0x00, 0x00, 0x00, 0x41, 0x00, // a.....A. -> first byte = profile | second byte = sequence
0x42, 0x00, 0x42, 0x00, 0x42, 0x00, 0x42, 0x00, // B.B.B.B.
0x42, 0x00, 0x42, 0x00, 0x42, 0x00, 0x42, 0x00, // B.B.B.B.
0x42, 0x00, 0x42, 0x00, 0x42, 0x00, 0x42, 0x00, // B.B.B.B.
0x42, 0x00, 0x42, 0x00, 0x42, 0x00, 0x42, 0x00, // B.B.B.B.
0x42, 0x00, 0x42, 0x00, 0x42, 0x00, 0x42, 0x00, // B.B.B.B.
0x42, 0x00, 0x42, 0x00, 0x42, 0x00, 0x42, 0x00, // B.B.B.B.
0x42, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, // B.B..... -> last 4 bytes are not dependent on crc-32 check
], [0x61, 0x01, 0x42, 0x00, 0x42, 0x00, 0x42, 0x00, // a.B.B.B. -> first byte = profile | second byte = sequence | If name is longer than 27 characters, it will also fill these bytes in next sequence
0x42, 0x00, 0x42, 0x00, 0x42, 0x00, 0x42, 0x00, // B.B.B.B.
0x42, 0x00, 0x42, 0x00, 0x42, 0x00, 0x42, 0x00, // B.B.B.B.
0x42, 0x00, 0x42, 0x00, 0x7e, 0x05, 0x28, 0x42, // B.B.~.(B -> label ends | 5 byte in this row starts checksum?? CRC?? If anyone knows what this is, let me know.
0x8a, 0x5d, 0x42, 0x4e, 0xa6, 0xa8, 0xcd, 0xce, // .]BN....
0x85, 0x54, 0x22, 0x43, 0x00, 0x00, 0x00, 0x00, // .T"C.... -> sixth byte = dead zone left stick? | last byte left stick curve adjustments
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........ -> first to fifth byte -> left stick curve adjustments | seventh byte = dead zone right stick?
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........ -> first to fourth byte -> right stick curve adjustments | last 4 bytes are not dependent on crc-32 check
], [0x61, 0x02, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, // a....... -> first byte = profile | second byte = sequence | third to fifth byte -> right stick curve adjustments | last 4 bytes trigger dead zone min+max L2 and R2
0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, // ........ -> Starting fourth byte = button mapping. Counting order to 0x0f is default
0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // ........ -> Rest of button mapping
0x0e, 0x0f, 0x00, 0x00, 0xc0, 0x00, 0x01, 0x00, // ........ -> Button mapping stops at 0x0f. | Fourth byte = touchpad? | Seventh byte = joystick profile (More info below)
0x01, 0x00, 0x1c, 0x55, 0xbb, 0x05, 0x87, 0x01, // ...U.... -> First byte = joystick profile (More info below) | Date time creation?
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........
// 0xb2, 0xba, 0x59, 0xc1, 0x00, 0x00, 0x00, 0x00, ..Y..... -> first 4 bytes CRC-32 | last 4 bytes are not dependent on crc-32 check
]];
/**
* Joystick profile
* 0x00 = Default
* 0x01 = Quick
* 0x02 = Precise
* 0x03 = Steady
* 0x04 = Digital
* 0x05 = Dynamic
*/
const PROFILE_NAME = {
Default: 0x00,
Quick: 0x01,
Precise: 0x02,
Steady: 0x03,
Digital: 0x04,
Dynamic: 0x05,
}
const profiles = [
new Profile(PROFILE_NAME.Default, [
new ProfileValueAdjustment(128),
new ProfileValueAdjustment(128),
new ProfileValueAdjustment(196),
new ProfileValueAdjustment(196),
new ProfileValueAdjustment(225),
new ProfileValueAdjustment(225)
]),
new Profile(PROFILE_NAME.Quick, [
new ProfileValueAdjustment(38),
new ProfileValueAdjustment(38),
new ProfileValueAdjustment(122, -3),
new ProfileValueAdjustment(139, [6, 5]),
new ProfileValueAdjustment(255),
new ProfileValueAdjustment(255)
]),
new Profile(PROFILE_NAME.Precise, [
new ProfileValueAdjustment(70, 3),
new ProfileValueAdjustment(57, [-3, -4]),
new ProfileValueAdjustment(134, 3),
new ProfileValueAdjustment(115, [-6, -7]),
new ProfileValueAdjustment(196, 2),
new ProfileValueAdjustment(177, [-7, -8])
]),
new Profile(PROFILE_NAME.Steady, [
new ProfileValueAdjustment(62, -1),
new ProfileValueAdjustment(62, -1),
new ProfileValueAdjustment(120, -4),
new ProfileValueAdjustment(129, [0, -1]),
new ProfileValueAdjustment(197, [3, 2]),
new ProfileValueAdjustment(179, [-5, -6])
]),
new Profile(PROFILE_NAME.Digital, [
new ProfileValueAdjustment(38),
new ProfileValueAdjustment(38),
new ProfileValueAdjustment(38),
new ProfileValueAdjustment(75, 18),
new ProfileValueAdjustment(255),
new ProfileValueAdjustment(255)
]),
new Profile(PROFILE_NAME.Dynamic, [
new ProfileValueAdjustment(69, [3, 2]),
new ProfileValueAdjustment(57, [-3, -4]),
new ProfileValueAdjustment(183, [-4, -5]),
new ProfileValueAdjustment(198, 3),
new ProfileValueAdjustment(255),
new ProfileValueAdjustment(255)
]),
];
const EMPTY_BUFFER_64 = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
];
const REPORT_ID_DELETE_SET_CONFIG = 0x68;
const PROFILE_OPTION = [0x60, 0x61, 0x62];
const B_REQUEST_SET_CONFIG = 9;
const arrayCRC32Le = byteArray => {
let copy = JSON.parse(JSON.stringify(byteArray));
let unpackCopy = [];
for (let i = 0; i < copy.length; i++) {
copy[i].splice(0, 2);
i !== copy.length - 1 ? copy[i] = copy[i].slice(0, -4) : false;
}
copy.map(elem => unpackCopy.push(...elem));
return (CRC32.buf(unpackCopy) >>> 0).toString(16).match(/.{1,2}/g).reverse().map(hex => parseInt(hex, 16));
}
const createProfileLabel = () => {
let bytes = new Array(80);
let name = prompt('Profile name (Max 40 characters!): ');
name = name.split('');
for (let i = 0; i < bytes.length; i++) {
if (i % 2 !== 0 || !name.length) {
bytes[i] = 0x00;
} else {
bytes[i] = name.shift().charCodeAt(0);
}
}
return bytes;
}
const deleteProfile = () => {
console.log("Profile number: ");
console.log("0 : FN + circle");
console.log("1 : FN + cross");
console.log("2 : FN + square");
const profileNumber = prompt('Profile number: ');
if (PROFILE_OPTION[profileNumber]) {
controller.open(true);
let payload = EMPTY_BUFFER_64;
payload[0] = REPORT_ID_DELETE_SET_CONFIG;
payload[1] = 4 - profileNumber;
controller.controlTransfer(0x21, B_REQUEST_SET_CONFIG, 0x0368, 0x003, Buffer.from(payload), function (error, buffer) {
console.log(buffer);
console.log("Done!");
controller.close();
readline.close();
});
} else {
console.log("Invalid option");
}
}
const createProfile = () => {
console.log("Profile number: ");
console.log("0 : FN + square");
console.log("1 : FN + cross");
console.log("2 : FN + circle");
const profileNumber = prompt('Profile number: ');
if (PROFILE_OPTION[profileNumber]) {
readline.close();
controller.open(true);
let steps = 0;
let label = [createProfileLabel()];
label.push(label[0].slice(54));
label[0] = label[0].slice(0, 54);
for (let i = 6; i < bRequestSetConfigPayloads[0].length - 4; i++) {
if (label[0].length) {
bRequestSetConfigPayloads[0][i] = label[0].shift();
continue;
}
break;
}
for (let i = 2; i < 27; i++) {
if (label[1].length) {
bRequestSetConfigPayloads[1][i] = label[1].shift();
continue;
}
break;
}
// TODO user can alter curve for every joy-con
let joyConL = profiles[2].getHexValuesByIndex(0);
let joyConR = profiles[2].getHexValuesByIndex(0);
for (let i = 47; i < 53; i++) {
bRequestSetConfigPayloads[1][i] = joyConL.shift();
}
for (let i = 56; i < 60; i++) {
bRequestSetConfigPayloads[1][i] = joyConR.shift();
}
bRequestSetConfigPayloads[2][2] = joyConR.shift();
bRequestSetConfigPayloads[2][3] = joyConR.shift();
bRequestSetConfigPayloads[2][30] = profiles[2].getId();
bRequestSetConfigPayloads[2][32] = profiles[2].getId();
bRequestSetConfigPayloads[2].push(...[...arrayCRC32Le(bRequestSetConfigPayloads), ...[0x00, 0x00, 0x00, 0x00]]);
for (let payload of bRequestSetConfigPayloads) {
payload[0] = PROFILE_OPTION[profileNumber];
controller.controlTransfer(0x21, B_REQUEST_SET_CONFIG, 0x0361, 0x003, Buffer.from(payload), function (error, buffer) {
steps++;
if (steps === 3) {
console.log("Done!");
controller.close();
readline.close();
}
});
}
} else {
console.log("Invalid option");
}
}
const readline = require('readline').createInterface({
input: process.stdin, output: process.stdout,
});
console.log("Commands: \n- create\n- delete");
switch (prompt('Profile command: ')) {
case 'create':
createProfile();
break;
case 'delete':
deleteProfile();
break;
default:
console.log('Unknown command');
readline.close();
break;
}