-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterrupt.cpp
More file actions
485 lines (419 loc) · 20 KB
/
Copy pathInterrupt.cpp
File metadata and controls
485 lines (419 loc) · 20 KB
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#include "../plugin_sdk/plugin_sdk.hpp"
#include "Interrupt.h"
namespace InterruptDB {
std::map<std::string, TreeEntry*> menuMap;
std::map<uint32_t, interruptableSpell> spellMap;
bool useSmallMenu = false;
int boolMenuMinImportance = -1;
bool useAllies = false;
auto rbuffhashes = { buff_hash("LucianR"), buff_hash("SamiraR"), buff_hash("RyzeRChannel"), buff_hash("Gate") }; // I hate this, also buff times are wrong, maybe need to use onProcessSpellCast
std::map<uint32_t, float> animationStarttimes;
std::map<std::string, internalSpellData> channelTime = { // I cant get every Spell via spelldata->channeltime
{"AurelionSolQ", internalSpellData(0,3.25,3.25,0)},
{"AurelionSolW", internalSpellData(0,0,0,0.4)},
{"AkshanR", internalSpellData(0.5,2.5,2.5,0)}, // I will not do the calculations to find out how many he needs
// Belveth E and Briar E are not interruptable
{"CaitlynR", internalSpellData(1,1,1,0.375)},
{"FiddleSticksW", internalSpellData(0,2,2,0.25)},
{"FiddleSticksR", internalSpellData(1.5,1.5,1.5,0)},
{"GalioW", internalSpellData(0,2,1.25,0)},
{"GalioR", internalSpellData(1.25,1.25,1.25,0)},
{"GragasW", internalSpellData(0.75,0.75,0.75,0)},
// Irelia W not interruptable
{"JannaR", internalSpellData(0,3,3,0)}, // Could in theory do calculations if/when team is full hp
{"JhinR", internalSpellData(0,10,4,1)}, // Could try to figure out how many shots he has left?
{"KarthusR", internalSpellData(3,3,3,0.25)},
{"KatarinaR", internalSpellData(0,2.5,2.5,0)}, // Could check targets in range
// KSante W not interruptable
{"LucianR", internalSpellData(0.75,3,3,0)}, //Could check targets, Also since buff time is wrong, this is not accurate
{"MalzaharR", internalSpellData(0,2.5,2.5,0)},
{"MasterYiW", internalSpellData(0,4,4,0)}, // Again, a full hp yi will probably not W for 4 seconds
{"MissFortuneR", internalSpellData(0,3,3,0)},
{"NaafiriW", internalSpellData(0.75,0.75,0.75,0)},
{"NunuW", internalSpellData(0.5,10,5,0)},
{"NunuR", internalSpellData(0,3,3,0)},
{"PantheonQ", internalSpellData(0,3.25,0.35,0)},
{"PantheonR", internalSpellData(2,2,2,0.1)},
{"PoppyR", internalSpellData(0,4,1,0)},
{"PykeQ", internalSpellData(0,3,1,0)},
{"QuinnR", internalSpellData(2,2,2,0)},
// I dont think having rammus q here makes sense, nunu w should be okay with prediction, but rammus q is impossible
{"RyzeR", internalSpellData(2,2,2,0)},
{"SamiraR", internalSpellData(2.25,2.25,2.25,0)},
{"ShenR", internalSpellData(3,3,3,0)},
{"SionQ", internalSpellData(0,2,1,0)},
{"TahmKenchW", internalSpellData(1.35,1.35,1.35,0)},
{"TaliyahR", internalSpellData(1,1,1,0)},
{"TwistedFateR", internalSpellData(1.5,1.5,1.5,0)},
{"VarusQ", internalSpellData(0,4.5,1.25,0)},
{"VelkozR", internalSpellData(0.8,2.6,2.6,0.2)},
{"ViQ", internalSpellData(0,4.5,1.25,0)},
{"ViegoW", internalSpellData(0,3,1,0)},
{"VladimirE", internalSpellData(0,1.5,1,0)},
{"WarwickQ", internalSpellData(0,0.5,0,0)}, // Not sure if this makes sense
{"WarwickR", internalSpellData(1.5,1.5,1.5,0)},
{"XerathQ", internalSpellData(0,3,1.75,0)},
{"XerathR", internalSpellData(0,10,2,0)},
{"ZacE", internalSpellData(0,4.5,0.9,0)},
};
std::string getDisplayName(game_object_script target) {
switch (target->get_champion())
{
case champion_id::AurelionSol: return "Aurelion Sol";
case champion_id::Belveth: return "Bel'Veth";
case champion_id::Chogath: return "Cho'Gath";
case champion_id::DrMundo: return "Dr. Mundo";
case champion_id::FiddleSticks: return "Fiddlesticks";
case champion_id::JarvanIV: return "Jarvan IV";
case champion_id::Kaisa: return "Kai'Sa";
case champion_id::Khazix: return "Kha'Zix";
case champion_id::KogMaw: return "Kog'Maw";
case champion_id::KSante: return "K'Sante";
case champion_id::Leblanc: return "LeBlanc";
case champion_id::LeeSin: return "Lee Sin";
case champion_id::MasterYi: return "Master Yi";
case champion_id::MissFortune: return "Miss Fortune";
case champion_id::MonkeyKing: return "Wukong";
case champion_id::Nunu: return "Nunu and Willump";
case champion_id::RekSai: return "Rek'Sai";
case champion_id::Renata: return "Renata Glasc";
case champion_id::TahmKench: return "Tahm Kench";
case champion_id::Velkoz: return "Vel'Koz";
default: return target->get_model();
}
}
void InitiateSlot(TreeTab* tab, game_object_script entity, spellslot slot, std::string name, std::string spellName, int defaultValue)
{
std::string key;
void* texture;
switch (slot)
{
case spellslot::q:
key = "Q";
texture = entity->get_spell(slot)->get_icon_texture();
break;
case spellslot::w:
key = "W";
texture = entity->get_spell(slot)->get_icon_texture();
break;
case spellslot::e:
key = "E";
texture = entity->get_spell(slot)->get_icon_texture();
break;
case spellslot::r:
key = "R";
texture = entity->get_spell(slot)->get_icon_texture();
break;
default:
key = "?";
texture = entity->get_passive_icon_texture();
break;
}
auto model = entity->get_model();
auto displayName = getDisplayName(entity);
auto id = std::to_string((int)entity->get_champion());
if (useSmallMenu) {
if (boolMenuMinImportance < 0) {
menuMap[model + key] = tab->add_slider(model + key, displayName + " | " + key, defaultValue, 0, 3, true);
}
else {
menuMap[model + key] = tab->add_checkbox(model + key, displayName + " | " + key, defaultValue>=boolMenuMinImportance, true);
menuMap[model + key]->set_texture(texture);
}
}
else {
auto t = tab->add_tab(model, "[" + displayName + "]");
t->set_texture(entity->get_square_icon_portrait());
if (boolMenuMinImportance < 0) {
menuMap[model + key] = t->add_slider(model + key, "[" + key + "] - " + spellName, defaultValue, 0, 3, true);
}
else {
menuMap[model + key] = t->add_checkbox(model + key, "[" + key + "] - " + spellName, defaultValue >= boolMenuMinImportance, true);
menuMap[model + key]->set_texture(texture);
}
}
}
void on_update() {
auto l = useAllies ? entitylist->get_ally_heroes() : entitylist->get_enemy_heroes();
for (const auto& target: l){
interruptableSpell output = interruptableSpell();
if (!target || !target->is_valid() || !target->is_ai_hero()) { // to fix rare crash that i cant reproduce
spellMap[target->get_handle()] = output;
continue;
}
auto active = target->get_active_spell();
/*if (!active && !target->has_buff(rbuffhashes)) {
spellMap[target->get_handle()] = output;
continue;
}*/
std::string key = "?";
float realStartTime = -1;
// This split is needed since SamiraR, LucianR etc are not in activeSpell, they are only a buff
if (active) {
auto slot = active->get_spellslot();
switch (slot)
{
case spellslot::q:
key = "Q";
break;
case spellslot::w:
key = "W";
break;
case spellslot::e:
key = "E";
break;
case spellslot::r:
// I exclude Warwick here, dont want to "interrupt" his jump, only the channel
// So i ignore him if he uses r here
if (target->get_champion() != champion_id::Warwick)
key = "R";
break;
case (spellslot)48:
if (target->get_champion() == champion_id::Warwick)
key = "R";
break;
default:
//console->print("Spellslot %i", (int) slot);
break;
}
realStartTime = active->get_time();
}
if (target->has_buff(rbuffhashes)) {
// yeah i could just check buff endtime, but i will keep it like this
key = "R";
for (const auto buffhash : rbuffhashes) {
auto b = target->get_buff(buffhash);
if (b) realStartTime = b->get_start();
}
}
/*if (target->get_spell(spellslot::w)->get_name_hash() == spell_hash("AurelionSolWToggle") && target->is_playing_animation(buff_hash("Spell2"))) {
key = "W";
// i am not sure how i should get this?
realStartTime = gametime->get_time();
}*/
if (target->get_spell(spellslot::w)->get_name_hash() == spell_hash("AurelionSolWToggle")) {
key = "W";
auto b = target->get_buff(buff_hash("AurelionSolW"));
if (b) {
realStartTime = b->get_start() - 0.5; // 0.5 instead of 0.4 since buffs are delayed
}
}
auto entity = menuMap.find(target->get_model() + key);
if (entity == menuMap.end()) {
spellMap[target->get_handle()] = output;
continue;
}
if (boolMenuMinImportance == -1) {
output.dangerLevel = entity->second->get_int();
}
else {
output.dangerLevel = entity->second->get_bool();
}
auto spellListIter = channelTime.find(target->get_model() + key);
if (spellListIter == channelTime.end()) {
spellMap[target->get_handle()] = output;
continue;
}
float timeSinceStart = gametime->get_time() - realStartTime - spellListIter->second.castTime;
float expTimeLeft = spellListIter->second.expectedTime - timeSinceStart;
float minTimeLeft = spellListIter->second.minTime - timeSinceStart;
float maxTimeLeft = spellListIter->second.maxTime - timeSinceStart;
if (target->get_champion() == champion_id::AurelionSol && key == "Q") {
if (target->get_spell(spellslot::q)->level() == 5) maxTimeLeft = 100 - timeSinceStart;
}
if (target->get_champion() == champion_id::AurelionSol && key == "W") {
auto path = target->get_real_path();
if (path.size() > 1) {
float travelDistanceLeft = path[1].distance(target);
float normalFlightTimeLeft = travelDistanceLeft / (335 + target->get_move_speed());
float qFlightTime = 2 * normalFlightTimeLeft;
expTimeLeft = normalFlightTimeLeft;
maxTimeLeft = qFlightTime;
}
else {
auto passive = target->get_buff(buff_hash("AurelionSolPassive"));
if (passive) {
float travelDistance = 1200 + 7.5 * passive->get_count();
float normalTime = travelDistance / (335 + target->get_move_speed());
float qFlightTime = 2 * normalTime;
expTimeLeft = normalTime - timeSinceStart;
maxTimeLeft = qFlightTime - timeSinceStart;
}
}
}
const auto& tempBuff2 = target->get_buff(buff_hash("xerathrshots")); // works okay
if (tempBuff2)
expTimeLeft = (tempBuff2->get_count() - 1) * 0.5;
if (target->get_champion() == champion_id::Zac)
expTimeLeft = 0.8 + 0.1 * target->get_spell(spellslot::e)->level() - timeSinceStart;
output.expectedRemainingTime = fmax(expTimeLeft, 0);
output.minRemainingTime = fmax(minTimeLeft, 0);
output.maxRemainingTime = fmax(maxTimeLeft, 0);
spellMap[target->get_handle()] = output;
}
}
void InitializeCancelMenu(TreeTab* tab,bool smallMode, int boolMode, bool debugUseAllies)
{
// dev.bgx.gg clearly says its not needed to remove callbacks, only recommended
event_handler<events::on_update>::add_callback(on_update);
useSmallMenu = smallMode;
boolMenuMinImportance = boolMode;
useAllies = debugUseAllies;
std::vector<game_object_script> enemyList;
if (debugUseAllies) {
enemyList = entitylist->get_ally_heroes();
}else{
enemyList = entitylist->get_enemy_heroes();
}
for (auto& e : enemyList)
{
if (e == nullptr)
return;
auto id = e->get_champion();
switch (id) {
case champion_id::AurelionSol:
InitiateSlot(tab, e, spellslot::q, "Aurelion Sol", "Breath of Light", 1);
InitiateSlot(tab, e, spellslot::w, "Aurelion Sol", "Astral Flight", 0);
break;
case champion_id::Akshan:
InitiateSlot(tab, e, spellslot::r, "Akshan", "Comeuppance", 2);
break;
case champion_id::Caitlyn:
InitiateSlot(tab, e, spellslot::r, "Caitlyn", "Ace in the Hole", 3);
break;
case champion_id::FiddleSticks:
InitiateSlot(tab, e, spellslot::w, "Fiddlesticks", "Bountiful Harvest", 1);
InitiateSlot(tab, e, spellslot::r, "Fiddlesticks", "Crowstorm", 3);
break;
case champion_id::Galio:
InitiateSlot(tab, e, spellslot::w, "Galio", "Shield of Durand", 0);
InitiateSlot(tab, e, spellslot::r, "Galio", "Hero's Entrance", 3);
break;
case champion_id::Gragas:
InitiateSlot(tab, e, spellslot::w, "Gragas", "Drunken Rage", 0);
break;
case champion_id::Janna:
InitiateSlot(tab, e, spellslot::r, "Janna", "Monsoon", 3);
break;
case champion_id::Jhin:
InitiateSlot(tab, e, spellslot::r, "Jhin", "Curtain's Call", 3);
break;
case champion_id::Karthus:
InitiateSlot(tab, e, spellslot::r, "Karthus", "Requiem", 3);
break;
case champion_id::Katarina:
InitiateSlot(tab, e, spellslot::r, "Katarina", "Death Lotus", 3);
break;
case champion_id::Kayn:
InitiateSlot(tab, e, spellslot::r, "Kayn", "Umbral Trespass", 0);
break;
case champion_id::Lucian:
InitiateSlot(tab, e, spellslot::r, "Lucian", "The Culling", 3);
break;
case champion_id::Malzahar:
InitiateSlot(tab, e, spellslot::r, "Malzahar", "Death Grasp", 3);
break;
case champion_id::MasterYi:
InitiateSlot(tab, e, spellslot::w, "Master Yi", "Meditate", 1);
break;
case champion_id::MissFortune:
InitiateSlot(tab, e, spellslot::r, "Miss Fortune", "Bullet Time", 3);
break;
case champion_id::Naafiri:
InitiateSlot(tab, e, spellslot::w, "Naafiri", "Hounds' Pursuit", 0);
break;
case champion_id::Nunu:
InitiateSlot(tab, e, spellslot::w, "Nunu and Willump", "Biggest Snowball Ever!", 2);
InitiateSlot(tab, e, spellslot::r, "Nunu and Willump", "Absolute Zero", 3);
break;
case champion_id::Pantheon:
InitiateSlot(tab, e, spellslot::q, "Pantheon", "Comet Spear", 0);
InitiateSlot(tab, e, spellslot::r, "Pantheon", "Grand Starfall", 3);
break;
case champion_id::Poppy:
InitiateSlot(tab, e, spellslot::r, "Poppy", "Keeper's Verdict", 3);
break;
case champion_id::Pyke:
InitiateSlot(tab, e, spellslot::q, "Pyke", "Bone Skewer", 0);
break;
case champion_id::Quinn:
InitiateSlot(tab, e, spellslot::r, "Quinn", "Behind Enemy Lines", 1);
break;
case champion_id::Rammus:
InitiateSlot(tab, e, spellslot::q, "Rammus", "Powerball", 0);
break;
case champion_id::Ryze:
InitiateSlot(tab, e, spellslot::r, "Ryze", "Realm Warp", 3);
break;
case champion_id::Samira:
InitiateSlot(tab, e, spellslot::r, "Samira", "Inferno Trigger", 3);
break;
case champion_id::Shen:
InitiateSlot(tab, e, spellslot::r, "Shen", "Stand United", 3);
break;
case champion_id::Sion:
InitiateSlot(tab, e, spellslot::q, "Sion", "Decimating Smash", 2);
break;
case champion_id::TahmKench:
InitiateSlot(tab, e, spellslot::w, "Tahm Kench", "Abyssal Dive", 2);
break;
case champion_id::Taliyah:
InitiateSlot(tab, e, spellslot::r, "Taliyah", "Weaver's Wall", 0);
break;
case champion_id::TwistedFate:
InitiateSlot(tab, e, spellslot::r, "Twisted Fate", "Gate", 3);
break;
case champion_id::Varus:
// Maybe add WQ as separate? Cause its more worth to cancel
InitiateSlot(tab, e, spellslot::q, "Varus", "Piercing Arrow", 0);
break;
case champion_id::Velkoz:
InitiateSlot(tab, e, spellslot::r, "Vel'Koz", "Life Form Disintegration Ray", 3);
break;
case champion_id::Vi:
InitiateSlot(tab, e, spellslot::q, "Vi", "Vault Breaker", 0);
break;
case champion_id::Viego:
InitiateSlot(tab, e, spellslot::w, "Viego", "Spectral Maw", 0);
break;
case champion_id::Vladimir:
InitiateSlot(tab, e, spellslot::e, "Vladimir", "Tides of Blood", 0);
break;
case champion_id::Warwick:
InitiateSlot(tab, e, spellslot::q, "Warwick", "Jaws of the Beast", 0);
InitiateSlot(tab, e, spellslot::r, "Warwick", "Infinite Duress", 3);
break;
case champion_id::Xerath:
InitiateSlot(tab, e, spellslot::q, "Xerath", "Arcanopulse", 0);
InitiateSlot(tab, e, spellslot::r, "Xerath", "Rite of the Arcane", 3);
break;
case champion_id::Yuumi:
InitiateSlot(tab, e, spellslot::q, "Yuumi", "Prowling Projectile", 0);
InitiateSlot(tab, e, spellslot::r, "Yuumi", "Final Chapter", 0);
break;
case champion_id::Zac:
InitiateSlot(tab, e, spellslot::e, "Zac", "Elastic Slingshot", 2);
break;
default:
break;
}
}
if(boolMode < 0)
tab->add_separator("sep1", "Change Spell Importance here");
tab->add_separator("sep2", "Made by Flofian");
// Credits are appreciated, but i dont care if you remove this line
}
int getCastingImportance(game_object_script target)
{
if (spellMap.find(target->get_handle()) != spellMap.end()) {
return spellMap[target->get_handle()].dangerLevel;
}
return -1;
}
interruptableSpell getInterruptable(game_object_script target) {
if (spellMap.find(target->get_handle()) != spellMap.end()) {
return spellMap[target->get_handle()];
}
return interruptableSpell();
}
}