/
enchmouseover.cs
1047 lines (865 loc) · 42.3 KB
/
enchmouseover.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
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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using ScrollsModLoader.Interfaces;
using UnityEngine;
using Mono.Cecil;
//using Mono.Cecil;
//using ScrollsModLoader.Interfaces;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Reflection;
using JsonFx.Json;
using System.Text.RegularExpressions;
namespace enchmouseover.mod
{
struct enchantments
{
public string name;
public int posx;
public int posy;
}
public class moveunit
{
public int move = 0;
public TileColor tp = TileColor.unknown;
public int movesdone = 0;
public moveunit(int m, TilePosition p)
{
this.move = m;
this.tp = p.color;
}
}
public class enchmouseover : BaseMod, ICommListener
{
private BattleMode bm = null;
private Boolean showpicture = false;
private Boolean showall = false;
private Boolean allwayson = false;
List<enchantments> enchlist = new List<enchantments>();
List<enchantments> Allenchlist = new List<enchantments>();
Dictionary<string, Texture2D> enchantslib= new Dictionary<string, Texture2D>();
int picx=53;
int picy=40;
private int[] cardids;
private string[] cardnames;
private int[] cardImageid;
private int showpattern=2;
private FieldInfo reftile;
private FieldInfo tileover;
private FieldInfo mrktpe;
private FieldInfo sbfrm;
private FieldInfo chargeAnim = typeof(Tile).GetField("chargeAnim", BindingFlags.Instance | BindingFlags.NonPublic);
private FieldInfo targetAnimBack = typeof(Tile).GetField("targetAnimBack", BindingFlags.Instance | BindingFlags.NonPublic);
private FieldInfo targetAnimFront = typeof(Tile).GetField("targetAnimFront", BindingFlags.Instance | BindingFlags.NonPublic);
private int cardnametoimageid(string name) { return cardImageid[Array.FindIndex(cardnames, element => element.Equals(name))]; }
private FieldInfo buffMaterialInfo = typeof(Unit).GetField("buffMaterial", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo updatechat = typeof(BattleMode).GetMethod("updateChat", BindingFlags.NonPublic | BindingFlags.Instance);
MethodInfo mi=typeof(BattleMode).GetMethod("getAllUnitsCopy", BindingFlags.NonPublic | BindingFlags.Instance);
MethodInfo hm = typeof(BattleMode).GetMethod("handleGameChatMessage", BindingFlags.NonPublic | BindingFlags.Instance);
MethodInfo selectTargetMethod = typeof(BattleMode).GetMethod("selectTargetArea", BindingFlags.NonPublic | BindingFlags.Instance);
TileColor showLobbers = TileColor.unknown;
List<TilePosition> enemyLobbers = new List<TilePosition>();
TilePosition currentHover = new TilePosition(TileColor.white, 1, 1);
Dictionary<long, moveunit> moveCounter = new Dictionary<long, moveunit>();
private FieldInfo attackcounterinfo = typeof(Unit).GetField("attackCounter", BindingFlags.Instance | BindingFlags.NonPublic);
private FieldInfo attackCounterObjArrinfo = typeof(Unit).GetField("attackCounterObjArr", BindingFlags.Instance | BindingFlags.NonPublic);
private FieldInfo countdownStatinfo = typeof(Unit).GetField("countdownStat", BindingFlags.Instance | BindingFlags.NonPublic);
private MethodInfo createSymbolsMethodInfo = typeof(Unit).GetMethod("createSymbols", BindingFlags.NonPublic | BindingFlags.Instance);
bool mark = false;
public void onConnect(OnConnectData ocd)
{
//lol
}
public void handleMessage(Message msg)
{ // collect data for enchantments (or units who buff)
if (msg is CardTypesMessage)
{
JsonReader jsonReader = new JsonReader();
Dictionary<string, object> dictionary = (Dictionary<string, object>)jsonReader.Read(msg.getRawText());
Dictionary<string, object>[] d = (Dictionary<string, object>[])dictionary["cardTypes"];
this.cardids = new int[d.GetLength(0)];
this.cardnames = new string[d.GetLength(0)];
this.cardImageid = new int[d.GetLength(0)];
for (int i = 0; i < d.GetLength(0); i++)
{
cardids[i] = Convert.ToInt32(d[i]["id"]);
cardnames[i] = d[i]["name"].ToString();
cardImageid[i] = Convert.ToInt32(d[i]["cardImage"]);
}
//App.Communicator.removeListener(this);//dont need the listener anymore
}
if(msg is AbilityInfoMessage)
{
AbilityInfoMessage aim = (AbilityInfoMessage)msg;
if (aim.abilityId == "Move")//aim.isPlayable &&
{
this.showLobbers = TileColor.white;
if (aim.unitPosition.color == TileColor.white) this.showLobbers = TileColor.black;
this.calculateEnemyLobbers(this.showLobbers);
}
this.showLobbers = TileColor.unknown;
}
if (msg is CardInfoMessage)
{
CardInfoMessage aim = (CardInfoMessage)msg;
//Console.WriteLine("cardinfo");
if (aim.card.getPieceKind() == CardType.Kind.CREATURE || aim.card.getPieceKind() == CardType.Kind.STRUCTURE)//aim.isPlayable &&
{
this.mark =true;
if (aim.data.selectableTiles.Count >= 1)
{
//Console.WriteLine("cardinfo " + aim.data.selectableTiles.tileSets[0][0].color);
this.showLobbers = aim.data.selectableTiles.tileSets[0][0].color.otherColor();
this.calculateEnemyLobbers(this.showLobbers);
}
}
this.showLobbers = TileColor.unknown;
}
return;
}
private void calculateEnemyLobbers(TileColor tc)
{
this.enemyLobbers.Clear();
//this.bm.getTileList(tc);
//Console.WriteLine("##");
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
Unit unitFromTile = this.bm.getUnit(tc, i, j);
if (unitFromTile == null) continue;
/*int movecount = 0;
foreach (ActiveAbility aa in unitFromTile.getActiveAbilities())
{
Console.WriteLine(aa.name);
if (aa.isMoveLike()) movecount++;
}
Console.WriteLine("-");*/
TilePosition tp2 = new TilePosition(tc.otherColor(), i, 2 - j);
if (unitFromTile.getTargetArea() == TargetArea.RADIUS_4)
{
selectTargetMethod.Invoke(this.bm, new object[]{TargetArea.RADIUS_4, tp2});
selectTargetArea(TargetArea.RADIUS_4, tp2);
}
if (unitFromTile.getTargetArea() == TargetArea.RADIUS_3)
{
selectTargetMethod.Invoke(this.bm, new object[] { TargetArea.RADIUS_3, tp2 });
selectTargetArea(TargetArea.RADIUS_3, tp2);
}
/*if (unitFromTile.getTargetArea() == TargetArea.RADIUS_7)
{
TilePosition tp2 = new TilePosition(tc.otherColor(), i, 2 - j);
selectTargetMethod.Invoke(this.bm, new object[] { TargetArea.RADIUS_7, tp2 });
}*/
}
}
}
private void selectTargetArea(TargetArea targetArea, TilePosition tp)
{
Tile.SelectionType markedID = targetArea.selectionType();
List<TilePosition> list = targetArea.getTargets(tp);
List<Tile> tiles = new List<Tile>();
foreach (TilePosition current2 in list)
{
this.enemyLobbers.Add(current2);
}
}
public void writetxtinchat(string msgs)
{
Console.WriteLine(msgs);
try
{
String chatMsg = msgs;
if (hm != null) // send chat message
{
GameChatMessageMessage gcmm = new GameChatMessageMessage(chatMsg);
gcmm.from = "Enchmouseover";
hm.Invoke(this.bm, new GameChatMessageMessage[] { gcmm });
}
else // can't invoke updateChat
{
}
/*if (updatechat != null) // send chat message
{
updatechat.Invoke(this.bm, new String[] { chatMsg });
}
else // can't invoke updateChat
{
}*/
}
catch // could not get information
{
}
}
//initialize everything here, Game is loaded at this point4
public enchmouseover()
{
mi = typeof(BattleMode).GetMethod("getAllUnitsCopy", BindingFlags.NonPublic | BindingFlags.Instance);
reftile = typeof(Tile).GetField("referenceTile", BindingFlags.Instance | BindingFlags.NonPublic);
tileover = typeof(Tile).GetField("tileOverlay", BindingFlags.Instance | BindingFlags.NonPublic);
mrktpe = typeof(Tile).GetField("markerType", BindingFlags.Instance | BindingFlags.NonPublic);
sbfrm = typeof(Tile).GetField("subFrame", BindingFlags.Instance | BindingFlags.NonPublic);
try
{
App.Communicator.addListener(this);
}
catch { }
Console.WriteLine("lodet enchmouseover ####################################");
}
public static string GetName ()
{
return "Enchantmouseover";
}
public static int GetVersion ()
{
return 10;
}
private void Allenchantcreator(List<EnchantmentInfo> enchants, Tile component, Boolean all) // creates global/local enchantlist
{
if (enchants.Count > 0)
{
enchantments tmpench = new enchantments();
//circle with screen coordinates
/* Vector3 screenPoint = Camera.main.WorldToScreenPoint(component.transform.position);
double mx=screenPoint.x;
double my=Camera.main.pixelHeight-screenPoint.y;
int anz= enchants.Count ;
Double winkel = 3.1415926536*2/(double)anz ;
Double radius =80;
Console.WriteLine(component.transform.position.ToString() + " #####");
for (int i=0; i < anz; i++)
{
tmpench.name=enchants.ElementAt(i).name;
tmpench.posx = (int)(mx + Math.Cos(i*winkel)*radius)- picx/2;
tmpench.posy = (int)(my + Math.Sin(i*winkel)*radius)-picy/2;
enchlist.Add(tmpench);
if (!enchantslib.ContainsKey(tmpench.name))
{
Texture2D newtexture = new Texture2D(2, 2, TextureFormat.RGB24, false);
byte[] data = File.ReadAllBytes("C:\\Users\\Thele\\AppData\\Local\\Mojang\\Scrolls\\game\\Bear Paw_prev.png");
newtexture.LoadImage(data);
enchantslib.Add(tmpench.name, newtexture);
}
}*/
// circle with real world coordinates
Vector3 screenPoint = component.transform.position;//
double mx = screenPoint.x;
double my = screenPoint.z;
float tmpx, tmpz;
double tempx, tempy;
int anz = enchants.Count;
int leftx = 0, rightx = 0, y = 0, belowposx = 0, belowposy = 0;
Double winkel = 3.1415926536 * 2 / (double)anz;
Double radius = 1.0;
if (this.showpattern == 2)
{
winkel = 3.1415926536 * 2;
tmpx = (float)((mx - 0.08 + Math.Cos(winkel) * radius));
tmpz = (float)((my + Math.Sin(winkel) * radius));
tempx = Camera.main.WorldToScreenPoint(new Vector3(tmpx, 0f, tmpz)).x;
tempy = Camera.main.WorldToScreenPoint(new Vector3(tmpx, 0f, tmpz)).y;
belowposx = (int)(tempx - picx / 2);
belowposy = (int)(Camera.main.pixelHeight - tempy - picy / 2);
leftx = belowposx;
rightx = belowposx + 2 + picx;
y = belowposy;
}
for (int i = 0; i < anz; i++)
{
tmpench.name = enchants.ElementAt(i).name;
if (this.showpattern == 1)// circle with real world coordinates
{
tmpx = (float)((mx - 0.08 + Math.Cos(i * winkel) * radius));
tmpz = (float)((my + Math.Sin(i * winkel) * radius));
tempx = Camera.main.WorldToScreenPoint(new Vector3(tmpx, screenPoint.y, tmpz)).x;
tempy = Camera.main.WorldToScreenPoint(new Vector3(tmpx, screenPoint.y, tmpz)).y;
tmpench.posx = (int)(tempx - picx / 2);
tmpench.posy = (int)(Camera.main.pixelHeight - tempy - picy / 2);
}
if (this.showpattern == 2)// right side with real world coordinates
{
tmpench.posy = y;
if ((i % 5) % 2 == 0)
{
tmpench.posx = leftx;
leftx = leftx - 2 - picx;
}
else
{
tmpench.posx = rightx;
rightx = rightx + 2 + picx;
}
if ((i + 1) % 5 == 0)// after 5 enchantments, go one line deeper
{
y = y + 2 + picy;
leftx = belowposx;
rightx = belowposx + 2 + picx;
};
}
if (all == true)
{
this.Allenchlist.Add(tmpench);
}
else
{
this.enchlist.Add(tmpench);
}
if (!enchantslib.ContainsKey(tmpench.name))
{
string enchname = tmpench.name;
if (enchname == ("Poison Immunity")) { enchname = "Sand Pact Memorial"; };
if (enchname.StartsWith("Resistance")) { enchname = "Stone Pact Memorial"; };
if (enchname.StartsWith("Poison")) { enchname = "Ranger's Bane"; };
if (enchname.StartsWith("Curse")) { enchname = "Cluster Hex"; };
if (enchname == "Decomposing") { enchname = "Return To Nature"; };
if (enchname == "Piercing") { enchname = "Piercing Projectile"; };
if (enchname.StartsWith("Armor")) { enchname = "Wings Shield"; };
if (enchname.StartsWith("Magic Armor")) { enchname = "Metempsychosis"; };
if (enchname == "Slayer") { enchname = "Ilmire Hunter"; };
if (enchname.StartsWith("Move")) { enchname = "New Orders"; };
if (enchname.StartsWith("Haste")) { enchname = "Speed"; };
if (enchname.StartsWith("Spiky")) { enchname = "Illthorn"; };
if (enchname == ("Inspired")) { enchname = "Jarl Urhald"; };
Texture2D newtexture = new Texture2D(2, 2, TextureFormat.RGB24, false);
try
{
newtexture = App.AssetLoader.LoadTexture2D(cardnametoimageid(enchname).ToString());
}
catch
{
this.writetxtinchat("Enchmod doesnt know " + enchname);
}
this.enchantslib.Add(tmpench.name, newtexture);
}
}
}
}
/*public void handleMessage(Message msg)
{
if (msg is RoomInfoMessage)
{
JsonReader jsonReader = new JsonReader();
Dictionary<string, object> dictionary = (Dictionary<string, object>)jsonReader.Read(msg.getRawText());
Dictionary<string, object>[] d = (Dictionary<string, object>[])dictionary["profiles"];
string tmpid = "";
string tmpname = "";
for (int i = 0; i < d.GetLength(0); i++)
{
tmpid=d[i]["id"].ToString();
tmpname = d[i]["name"].ToString();
playerinfo tmpplayer = new playerinfo();
tmpplayer.name = tmpname;
tmpplayer.ID = tmpid;
if (!liplayerinfo.Contains(tmpplayer)) { liplayerinfo.Add(tmpplayer); }
}
}
return;
}
public void onReconnect()
{
return; // don't care
}*/
//only return MethodDefinitions you obtained through the scrollsTypes object
//safety first! surround with try/catch and return an empty array in case it fails
public static MethodDefinition[] GetHooks (TypeDefinitionCollection scrollsTypes, int version)
{
try
{
return new MethodDefinition[] {
scrollsTypes["BattleMode"].Methods.GetMethod("sendBattleRequest", new Type[]{typeof(Message)}),
scrollsTypes["BattleMode"].Methods.GetMethod("OnGUI")[0],
scrollsTypes["BattleMode"].Methods.GetMethod("Update")[0],
scrollsTypes["BattleMode"].Methods.GetMethod("tileOver", new Type[]{typeof(TilePosition)} ),
scrollsTypes["BattleMode"].Methods.GetMethod("tileOut", new Type[]{typeof(GameObject),typeof(int),typeof(int)} ),
scrollsTypes["BattleMode"].Methods.GetMethod("toggleUnitStats")[0],
scrollsTypes["Unit"].Methods.GetMethod("renderUnit")[0],
scrollsTypes["BattleMode"].Methods.GetMethod("markMoveTile", new Type[]{typeof(TilePosition),typeof(TilePosition)} ),
scrollsTypes["Tile"].Methods.GetMethod("markInternal", new Type[]{typeof(Tile.SelectionType),typeof(float)} ),
scrollsTypes["BattleMode"].Methods.GetMethod("forceRunEffect", new Type[]{typeof(EffectMessage)}),
// scrollsTypes["BattlemodeUI"].Methods.GetMethod("Update")[0],
//scrollsTypes["Tile"].Methods.GetMethod("updateMoveAnim")[0],
//scrollsTypes["ChatUI"].Methods.GetMethod("OnGUI")[0],
};
}
catch
{
return new MethodDefinition[] { };
}
}
public long getId(Unit u)
{
return u.GetInstanceID();// better than cardid because token have the same ;_;
}
public void resetMoveAllUnits()
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
Unit unitFromTile = this.bm.getUnit(TileColor.white, i, j);
if (unitFromTile != null)
{
updateMoveUnit(unitFromTile, unitFromTile.getBuffs(), unitFromTile.getActiveAbilities(), unitFromTile.getName(), unitFromTile.getTilePosition());
}
unitFromTile = this.bm.getUnit(TileColor.black, i, j);
if (unitFromTile != null)
{
updateMoveUnit(unitFromTile, unitFromTile.getBuffs(), unitFromTile.getActiveAbilities(), unitFromTile.getName(), unitFromTile.getTilePosition());
}
}
}
}
public void updateMoveUnit(Unit un, List<EnchantmentInfo> enchants, ActiveAbility[] actives, string name, TilePosition tp)
{
long id = this.getId(un);
int hasmove = 0;
foreach (ActiveAbility aa in actives)
{
if (aa.isMoveLike()) hasmove = 1;
}
if (name == "Infected Gravelock") hasmove = 0;//maybe at last?
if (name == "Stormknight") hasmove = 2;//maybe at last?
if (this.moveCounter.ContainsKey(id))
{
this.moveCounter[id].move = hasmove;
}
else
{
this.moveCounter.Add(id, new moveunit(hasmove, tp));
}
foreach (EnchantmentInfo ei in enchants)
{
if (ei.name == "Move") this.moveCounter[id].move++; // is maybe wrong (see trials-buffs)
if (ei.name == "Binding Root") this.moveCounter[id].move -= 2;
if (ei.name == "Dryadic Power") this.moveCounter[id].move -= 1;
if (ei.name == "Horn of Ages") this.moveCounter[id].move -= 1;
if (ei.name == "Malevolent Gaze") this.moveCounter[id].move -= 2;
if (ei.name == "New Orders") this.moveCounter[id].move += 1;
if (ei.name == "Nuru's Needle") this.moveCounter[id].move -= 1;
//if (ei.name == "Oum Lasa High Guard") this.moveCounter[id] -= 100;
if (ei.name == "Roasted Bean Potion") this.moveCounter[id].move += 1;
if (ei.name == "Wings Captain") this.moveCounter[id].move += 1;
}
//oum Lasa high guard effect:
//Console.WriteLine("" + tp.ToString());
for (int i = 0; i < tp.column; i++)
{
Unit u = this.bm.getUnit(tp.color, tp.row, i);
if (u != null)
{
//Console.WriteLine("own " + u.name);
return;
}
}
for (int i = 0; i < 3; i++)
{
Unit u = this.bm.getUnit(tp.color.otherColor(), tp.row, i);
if (u != null)
{
//Console.WriteLine("enemy " + u.name);
if (u.getName() == "Oum Lasa High Guard")
{
this.moveCounter[id].move = 0;
}
return;
}
}
}
public void printMove(TileColor tc)
{
foreach (KeyValuePair<long, moveunit> kvp in this.moveCounter)
{
if (kvp.Value.tp != tc) continue;
Console.WriteLine(kvp.Key + " move: " + kvp.Value.movesdone + " " +kvp.Value.move + " " + kvp.Value.tp.ToString());
}
}
public override bool WantsToReplace(InvocationInfo info)
{
if (info.targetMethod.Equals("sendBattleRequest"))
{
Console.WriteLine("sendrequest");
if (info.arguments[0] is GameChatMessageMessage)
{
GameChatMessageMessage msg = (GameChatMessageMessage)info.arguments[0];
string[] splitt = msg.text.Split(' ');
if ((splitt[0] == "/showench" || splitt[0] == "\\showench"))
{
return true;
}
}
}
return false;
}
public override void ReplaceMethod(InvocationInfo info, out object returnValue)
{
returnValue = null;
if (info.targetMethod.Equals("sendBattleRequest"))
{
Console.WriteLine("sendrequest");
if (info.arguments[0] is GameChatMessageMessage)
{
GameChatMessageMessage msg = (GameChatMessageMessage)info.arguments[0];
string[] splitt = msg.text.Split(' ');
if ((splitt[0] == "/showench" || splitt[0] == "\\showench"))
{
Boolean donesomething =false;
if (splitt.Length == 2)
{
if (splitt[1] == "circle")
{
this.showpattern = 1;
string text = "enchantments are shown on a circle around unit";
writetxtinchat(text);
donesomething = true;
}
if (splitt[1] == "below")
{
this.showpattern = 2;
string text = "enchantments are shown below unit";
writetxtinchat(text);
donesomething = true;
}
if (splitt[1] == "ctrlon")
{
this.allwayson = true;
string text = "if unit stats are shown permanently, enchantments are shown permanently, ";
writetxtinchat(text);
donesomething = true;
}
if (splitt[1] == "ctrloff")
{
this.allwayson = false;
string text = "if unit stats are shown permanently, enchantments aren't shown permanently, ";
writetxtinchat(text);
donesomething = true;
}
}
if (donesomething==false)
{
string text = "commands: circle, below";
writetxtinchat(text);
}
}
}
}
}
TilePosition tpStatsupdate = null;
public override void BeforeInvoke(InvocationInfo info)
{
if (info.target is BattleMode && info.targetMethod.Equals("forceRunEffect"))
{
EffectMessage currentEffect = (EffectMessage)info.arguments[0];
string type = currentEffect.type;
try
{
if (type == "TurnBegin")
{
resetMoveAllUnits();
foreach (KeyValuePair<long, moveunit> mu in this.moveCounter)
{
mu.Value.movesdone = 0;
}
}
if (type == "UnitActivateAbility")
{
EMUnitActivateAbility cef = (EMUnitActivateAbility)currentEffect;
string name = cef.name;
if (name == "Move" || name == "Flying")
{
long id = this.getId(this.bm.getUnit(cef.unit));
if (this.moveCounter.ContainsKey(id)) this.moveCounter[id].movesdone += 1;
}
}
if (type == "StatsUpdate")
{
EMStatsUpdate cef = (EMStatsUpdate)currentEffect;
this.tpStatsupdate = new TilePosition( cef.target.color, cef.target.row, cef.target.column);
}
}
catch
{
}
}
return;
}
private void showMoveOfUnit(Unit u)
{
List<GameObject> attackCounterObjArr = (List<GameObject>)attackCounterObjArrinfo.GetValue(u);
Stat countdownStat = (Stat)countdownStatinfo.GetValue(u);
int value = 0;
long id= this.getId(u);
if (this.moveCounter.ContainsKey(id))
{
moveunit mu = this.moveCounter[id];
value = Math.Max(0, mu.move - mu.movesdone);
}
attackCounterObjArr.ForEach(delegate(GameObject g)
{
UnityEngine.Object.Destroy(g);
});
attackCounterObjArr.Clear();
attackCounterObjArr.AddRange((List<GameObject>)this.createSymbolsMethodInfo.Invoke(u, new object[] { value, countdownStat.digits.transform }));
attackCounterObjArr.ForEach(delegate(GameObject g)
{
g.tag = "blinkable_countdown";
});
attackCounterObjArr.ForEach(delegate(GameObject g)
{
g.renderer.material.color = Color.green;
if (value == 0) g.renderer.material.color = Color.red;
});
}
public override void AfterInvoke (InvocationInfo info, ref object returnValue)
{
if (info.target is BattleMode && info.targetMethod.Equals("forceRunEffect"))
{
if (tpStatsupdate != null)
{
Unit statsupdate = this.bm.getUnit(tpStatsupdate);
if (statsupdate != null)
{
updateMoveUnit(statsupdate, statsupdate.getBuffs(), statsupdate.getActiveAbilities(), statsupdate.getName(), statsupdate.getTilePosition());
}
tpStatsupdate = null;
}
EffectMessage currentEffect = (EffectMessage)info.arguments[0];
string type = currentEffect.type;
if (type == "MoveUnit")
{
this.resetMoveAllUnits();
}
if (type == "SummonUnit")
{
EMSummonUnit cef = (EMSummonUnit)currentEffect;
Unit un = this.bm.getUnit(cef.target);
this.updateMoveUnit(un, new List<EnchantmentInfo>(), cef.card.getActiveAbilities(), cef.card.getName(), cef.target);
}
if (type == "TeleportUnits")
{
this.resetMoveAllUnits();
}
}
if (info.target is BattleMode && info.targetMethod.Equals("toggleUnitStats"))
{
Boolean showUnitStats= (Boolean)typeof(BattleMode).GetField ("showUnitStats", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(info.target);
Allenchlist.Clear();
this.showall = showUnitStats;
if (showUnitStats == true)
{
MethodInfo mi = typeof(BattleMode).GetMethod("getAllUnitsCopy", BindingFlags.NonPublic | BindingFlags.Instance);
foreach (Unit current in (List<Unit>)mi.Invoke(this.bm,null))
{
List<EnchantmentInfo> enchants = current.getBuffs();
//Tile component = ((BattleMode)info.target).getTileFromUnit(current);
Tile component = ((BattleMode)info.target).getTile(current.getTilePosition());
this.Allenchantcreator(enchants, component, true);
}
}
}
if (info.target is Unit && info.targetMethod.Equals("renderUnit"))
{
if (bm == null) return;
Unit current = (Unit)info.target;
List<EnchantmentInfo> enchants = current.getBuffs();
if (enchants.Count > 0)
{
//Tile component = ((BattleMode)bm).getTileFromUnit(current);
Tile component = ((BattleMode)bm).getTile(current.getTilePosition());
Tile.SelectionType marker = (Tile.SelectionType)mrktpe.GetValue(component);
if (marker != Tile.SelectionType.Hover)
{
Material buffmat = (Material)this.buffMaterialInfo.GetValue(info.target);
buffmat.SetColor("_Color", ColorUtil.FromInts(255, 0, 0, 220));
buffmat.color = new Color(1.0f, 0.0f, 0.0f, 0.7f);
//current.renderer.material.color = new Color(1.0f, 0.5f, 0.5f, 0.7f);
//GameObject refer = (GameObject)reftile.GetValue(component);
//refer.renderer.material.color = new Color(1.0f, 0f, 0f, 0.4f);
//GameObject to = (GameObject)tileover.GetValue(component);
//to.renderer.material.color = new Color(1.0f, 0f, 0f, 0.4f);
//component.getReference().renderer.material.color = new Color(1f, 0f, 0f, 0.4f);
}
}
}
if (info.target is BattleMode && info.targetMethod.Equals("Update"))
{
if (Input.GetKeyDown(KeyCode.M))
{
foreach (Unit u in this.bm.getUnitsFor(TileColor.white))
{
showMoveOfUnit(u);
}
foreach (Unit u in this.bm.getUnitsFor(TileColor.black))
{
showMoveOfUnit(u);
}
}
if (Input.GetKeyUp(KeyCode.M))
{
foreach (Unit u in this.bm.getUnitsFor(TileColor.white))
{
int v = (int)attackcounterinfo.GetValue(u);
u.setAttackCounter(v - 1);
u.setAttackCounter(v);
}
foreach (Unit u in this.bm.getUnitsFor(TileColor.black))
{
int v = (int)attackcounterinfo.GetValue(u);
u.setAttackCounter(v - 1);
u.setAttackCounter(v);
}
}
}
if (info.target is BattleMode && info.targetMethod.Equals("OnGUI"))
{
if (bm == null)
{
bm = (BattleMode)info.target;
}
if (Input.GetMouseButtonDown(0) && this.currentHover.color != TileColor.unknown)
{
//mouse pressed!
this.calculateEnemyLobbers(this.currentHover.color.otherColor());
//Console.WriteLine("moves:###############################");
//printMove(TileColor.white);
//printMove(TileColor.black);
}
if (showall == true && this.allwayson==true)
{
Allenchlist.Clear();
foreach (Unit current in (List<Unit>)mi.Invoke(this.bm, null))
{
List<EnchantmentInfo> enchants = current.getBuffs();
//Tile component = ((BattleMode)info.target).getTileFromUnit(current);
Tile component = ((BattleMode)info.target).getTile(current.getTilePosition());
this.Allenchantcreator(enchants, component, true);
}
foreach (var item in Allenchlist)
{
Rect position = new Rect(item.posx, item.posy, picx, picy);
GUI.DrawTexture(position, enchantslib[item.name]);
}
}
else
{
if (showpicture == true)
{
foreach (var item in enchlist)
{
Rect position = new Rect(item.posx, item.posy, picx, picy);
GUI.DrawTexture(position, enchantslib[item.name]);
}
}
}
/*
foreach (Unit current in (List<Unit>)mi.Invoke(this.bm, null))
{
//current.renderer.material.color = new Color(1f, 1f, 1f, 1f);
Material buffmat = (Material)this.buffMaterialInfo.GetValue(current);
Console.WriteLine("#clolor12" + buffmat.GetColor("_Color"));
buffmat.SetColor("_Color", ColorUtil.FromHex24(16777173u));
List<EnchantmentInfo> enchants = current.getBuffs();
Tile component = ((BattleMode)info.target).getTileFromUnit(current);
if (enchants.Count > 0)
{
Tile.SelectionType marker = (Tile.SelectionType)mrktpe.GetValue(component);
if (marker != Tile.SelectionType.Hover)
{
//current.renderer.material.color = new Color(1.0f, 0.5f, 0.5f, 0.7f);
buffmat.SetColor("_Color", ColorUtil.FromInts(255,0,0,220));
buffmat.color = new Color(1.0f, 0.0f, 0.0f, 0.7f);
current.renderer.material.color = new Color(1.0f, 0.0f, 0.0f, 0.7f);
Console.WriteLine("#clolorrrrr" + buffmat.GetColor("_Color"));
//GameObject refer = (GameObject)reftile.GetValue(component);
//refer.renderer.material.color = new Color(1.0f, 0f, 0f, 0.4f);
//GameObject to = (GameObject)tileover.GetValue(component);
//to.renderer.material.color = new Color(1.0f, 0f, 0f, 0.4f);
//component.getReference().renderer.material.color = new Color(1f, 0f, 0f, 0.4f);
}
}
}*/
}
if (info.target is BattleMode && info.targetMethod.Equals("tileOver"))
{
showpicture = true;
TilePosition tilepos = (TilePosition)info.arguments[0];
this.currentHover.color = tilepos.color;
this.currentHover.row = tilepos.row;
this.currentHover.column = tilepos.column;
//Unit unitFromTile = ((BattleMode)info.target).getUnitFromTile(component);
Unit unitFromTile = ((BattleMode)info.target).getUnit(tilepos);
Tile component = ((BattleMode)info.target).getTile(tilepos);
enchlist.Clear();
if (unitFromTile != null)
{
List<EnchantmentInfo> enchants= unitFromTile.getBuffs();
this.Allenchantcreator(enchants,component, false);
}
}
if (info.target is BattleMode && info.targetMethod.Equals("tileOut"))
{
showpicture = false;
this.currentHover.color = TileColor.unknown;
}
if (info.target is BattleMode && info.targetMethod.Equals("markMoveTile"))
{
TilePosition tilepos =(TilePosition)info.arguments[1];
Tile tile = this.bm.getTile(tilepos);
int bad = 0;
foreach (TilePosition tp in this.enemyLobbers)
{
if (tilepos.Equals(tp))
{
bad++;
}
}
if (bad>=1)
{
//Console.WriteLine("bad spottet " + tilepos);
GameObject to = (GameObject)tileover.GetValue(tile);
GameObject refer = (GameObject)reftile.GetValue(tile);
GameObject taf = (GameObject)targetAnimFront.GetValue(tile);
GameObject tab = (GameObject)targetAnimBack.GetValue(tile);
GameObject car = (GameObject)chargeAnim.GetValue(tile);
refer.renderer.material.color = new Color(1.0f, 0f, 0f, 0.2f * bad);
to.renderer.material.color = new Color(1.0f, 0f, 0f, 0.2f * bad);
if (taf != null) taf.renderer.material.color = new Color(1.0f, 0f, 0f, 0.2f * bad);
if (tab != null) tab.renderer.material.color = new Color(1.0f, 0f, 0f, 0.2f * bad);
if (car != null) car.renderer.material.color = new Color(1.0f, 0f, 0f, 0.2f * bad);