forked from TorannD/ValheimLegends
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValheimLegends.cs
3538 lines (3334 loc) · 215 KB
/
ValheimLegends.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 System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using System.Reflection;
using System.IO;
using UnityEngine.UI;
using System.Threading;
namespace ValheimLegends
{
[BepInPlugin("ValheimLegends", "ValheimLegends", "0.4.9")]
public class ValheimLegends : BaseUnityPlugin
{
public static Harmony _Harmony;
public const string Version = "0.4.9";
public const float VersionF = 0.49f;
public const string ModName = "Valheim Legends";
public static bool playerEnabled = true;
//loaded info
public static List<VL_Player> vl_playerList;
public static VL_Player vl_player;
public static Sprite RiposteIcon;
public static Sprite RogueIcon;
public static Sprite MonkIcon;
public static Sprite RangerIcon;
public static Sprite ValkyrieIcon;
public static Sprite WeakenIcon;
public static Sprite BiomeMeadowsIcon;
public static Sprite BiomeBlackForestIcon;
public static Sprite BiomeSwampIcon;
public static Sprite BiomeMountainIcon;
public static Sprite BiomePlainsIcon;
public static Sprite BiomeOceanIcon;
public static Sprite BiomeMistIcon;
public static Sprite BiomeAshIcon;
//configs
//public static ConfigVariable<bool> modEnabled;
//public static ConfigVariable<string> chosenClass;
//public static ConfigVariable<bool> vl_mce_enforceConfigurationClass;
//public static ConfigVariable<string> Ability1_Hotkey;
//public static ConfigVariable<string> Ability1_Hotkey_Combo;
//public static ConfigVariable<string> Ability2_Hotkey;
//public static ConfigVariable<string> Ability2_Hotkey_Combo;
//public static ConfigVariable<string> Ability3_Hotkey;
//public static ConfigVariable<string> Ability3_Hotkey_Combo;
//public static ConfigVariable<float> vl_mce_energyCostMultiplier;
//public static ConfigVariable<float> vl_mce_cooldownMultiplier;
//public static ConfigVariable<float> vl_mce_abilityDamageMultiplier;
//public static ConfigVariable<float> vl_mce_skillGainMultiplier;
//public static ConfigVariable<float> icon_X_Offset;
//public static ConfigVariable<float> icon_Y_Offset;
//public static ConfigVariable<string> iconAlignment;
//public static ConfigVariable<bool> showAbilityIcons;
public static ConfigEntry<bool> modEnabled;
public static ConfigEntry<string> Ability1_Hotkey;
public static ConfigEntry<string> Ability1_Hotkey_Combo;
public static ConfigEntry<string> Ability2_Hotkey;
public static ConfigEntry<string> Ability2_Hotkey_Combo;
public static ConfigEntry<string> Ability3_Hotkey;
public static ConfigEntry<string> Ability3_Hotkey_Combo;
public static ConfigEntry<float> vl_svr_energyCostMultiplier;
public static ConfigEntry<float> vl_svr_cooldownMultiplier;
public static ConfigEntry<float> vl_svr_abilityDamageMultiplier;
public static ConfigEntry<float> vl_svr_skillGainMultiplier;
public static ConfigEntry<float> vl_svr_unarmedDamageMultiplier;
public static ConfigEntry<float> icon_X_Offset;
public static ConfigEntry<float> icon_Y_Offset;
public static ConfigEntry<bool> showAbilityIcons;
public static ConfigEntry<string> iconAlignment;
public static ConfigEntry<string> chosenClass;
public static ConfigEntry<bool> vl_svr_allowAltarClassChange;
public static ConfigEntry<bool> vl_svr_enforceConfigClass;
public static ConfigEntry<bool> vl_svr_aoeRequiresLoS;
public static readonly Color abilityCooldownColor = new Color(1f, .3f, .3f, .5f);
//Class configs
public static ConfigEntry<float> vl_svr_berserkerDash;
public static ConfigEntry<float> vl_svr_berserkerBerserk;
public static ConfigEntry<float> vl_svr_berserkerExecute;
public static ConfigEntry<float> vl_svr_berserkerBonusDamage;
public static ConfigEntry<float> vl_svr_berserkerBonus2h;
public static ConfigEntry<string> vl_svr_berserkerItem;
public static ConfigEntry<float> vl_svr_druidVines;
public static ConfigEntry<float> vl_svr_druidRegen;
public static ConfigEntry<float> vl_svr_druidDefenders;
public static ConfigEntry<float> vl_svr_druidBonusSeeds;
public static ConfigEntry<string> vl_svr_druidItem;
public static ConfigEntry<float> vl_svr_duelistSeismicSlash;
public static ConfigEntry<float> vl_svr_duelistRiposte;
public static ConfigEntry<float> vl_svr_duelistHipShot;
public static ConfigEntry<float> vl_svr_duelistBonusParry;
public static ConfigEntry<string> vl_svr_duelistItem;
public static ConfigEntry<float> vl_svr_enchanterWeaken;
public static ConfigEntry<float> vl_svr_enchanterCharm;
public static ConfigEntry<float> vl_svr_enchanterBiome;
public static ConfigEntry<float> vl_svr_enchanterBiomeShock;
public static ConfigEntry<float> vl_svr_enchanterBonusElementalBlock;
public static ConfigEntry<float> vl_svr_enchanterBonusElementalTouch;
public static ConfigEntry<string> vl_svr_enchanterItem;
public static ConfigEntry<float> vl_svr_mageFireball;
public static ConfigEntry<float> vl_svr_mageFrostDagger;
public static ConfigEntry<float> vl_svr_mageFrostNova;
public static ConfigEntry<float> vl_svr_mageInferno;
public static ConfigEntry<float> vl_svr_mageMeteor;
public static ConfigEntry<string> vl_svr_mageItem;
public static ConfigEntry<float> vl_svr_metavokerLight;
public static ConfigEntry<float> vl_svr_metavokerReplica;
public static ConfigEntry<float> vl_svr_metavokerWarpDamage;
public static ConfigEntry<float> vl_svr_metavokerWarpDistance;
public static ConfigEntry<float> vl_svr_metavokerBonusSafeFallCost;
public static ConfigEntry<float> vl_svr_metavokerBonusForceWave;
public static ConfigEntry<string> vl_svr_metavokerItem;
public static ConfigEntry<float> vl_svr_monkChiPunch;
public static ConfigEntry<float> vl_svr_monkChiSlam;
public static ConfigEntry<float> vl_svr_monkChiBlast;
public static ConfigEntry<float> vl_svr_monkFlyingKick;
public static ConfigEntry<float> vl_svr_monkBonusBlock;
public static ConfigEntry<float> vl_svr_monkSurge;
public static ConfigEntry<float> vl_svr_monkChiDuration;
public static ConfigEntry<string> vl_svr_monkItem;
public static ConfigEntry<float> vl_svr_priestHeal;
public static ConfigEntry<float> vl_svr_priestPurgeHeal;
public static ConfigEntry<float> vl_svr_priestPurgeDamage;
public static ConfigEntry<float> vl_svr_priestSanctify;
public static ConfigEntry<float> vl_svr_priestBonusDyingLightCooldown;
public static ConfigEntry<string> vl_svr_priestItem;
public static ConfigEntry<float> vl_svr_rangerPowerShot;
public static ConfigEntry<float> vl_svr_rangerShadowWolf;
public static ConfigEntry<float> vl_svr_rangerShadowStalk;
public static ConfigEntry<float> vl_svr_rangerBonusPoisonResistance;
public static ConfigEntry<float> vl_svr_rangerBonusRunCost;
public static ConfigEntry<string> vl_svr_rangerItem;
public static ConfigEntry<float> vl_svr_rogueBackstab;
public static ConfigEntry<float> vl_svr_rogueFadeCooldown;
public static ConfigEntry<float> vl_svr_roguePoisonBomb;
public static ConfigEntry<float> vl_svr_rogueBonusThrowingDagger;
public static ConfigEntry<float> vl_svr_rogueTrickCharge;
public static ConfigEntry<string> vl_svr_rogueItem;
public static ConfigEntry<float> vl_svr_shamanSpiritShock;
public static ConfigEntry<float> vl_svr_shamanEnrage;
public static ConfigEntry<float> vl_svr_shamanShell;
public static ConfigEntry<float> vl_svr_shamanBonusSpiritGuide;
public static ConfigEntry<float> vl_svr_shamanBonusWaterGlideCost;
public static ConfigEntry<string> vl_svr_shamanItem;
public static ConfigEntry<float> vl_svr_valkyrieLeap;
public static ConfigEntry<float> vl_svr_valkyrieStaggerCooldown;
public static ConfigEntry<float> vl_svr_valkyrieBulwark;
public static ConfigEntry<float> vl_svr_valkyrieBonusChillWave;
public static ConfigEntry<float> vl_svr_valkyrieBonusIceLance;
public static ConfigEntry<float> vl_svr_valkyrieChargeDuration;
public static ConfigEntry<string> vl_svr_valkyrieItem;
//Save and load data
public class VL_Player
{
public string vl_name;
public PlayerClass vl_class;
}
public enum PlayerClass
{
None = 0,
Berserker = 1,
Druid = 2,
Metavoker = 3,
Mage = 4,
Priest = 5,
//Necromancer = 6,
Monk = 7,
Ranger = 8,
Duelist = 9,
Enchanter = 10,
Rogue = 11,
Shaman = 16,
Valkyrie = 32
}
public static int GetPlayerClassNum
{
get
{
if(vl_player.vl_class == PlayerClass.Berserker)
{
return (int)PlayerClass.Berserker;
}
else if(vl_player.vl_class == PlayerClass.Druid)
{
return (int)PlayerClass.Druid;
}
else if (vl_player.vl_class == PlayerClass.Metavoker)
{
return (int)PlayerClass.Metavoker;
}
else if (vl_player.vl_class == PlayerClass.Mage)
{
return (int)PlayerClass.Mage;
}
else if (vl_player.vl_class == PlayerClass.Priest)
{
return (int)PlayerClass.Priest;
}
//else if (vl_player.vl_class == PlayerClass.Necromancer)
//{
// return (int)PlayerClass.Necromancer;
//}
else if (vl_player.vl_class == PlayerClass.Monk)
{
return (int)PlayerClass.Monk;
}
else if (vl_player.vl_class == PlayerClass.Ranger)
{
return (int)PlayerClass.Ranger;
}
else if (vl_player.vl_class == PlayerClass.Duelist)
{
return (int)PlayerClass.Duelist;
}
else if (vl_player.vl_class == PlayerClass.Enchanter)
{
return (int)PlayerClass.Enchanter;
}
else if (vl_player.vl_class == PlayerClass.Rogue)
{
return (int)PlayerClass.Rogue;
}
else if (vl_player.vl_class == PlayerClass.Shaman)
{
return (int)PlayerClass.Shaman;
}
else if (vl_player.vl_class == PlayerClass.Valkyrie)
{
return (int)PlayerClass.Valkyrie;
}
else
{
return (int)PlayerClass.None;
}
}
}
//[HarmonyPatch(typeof(Odinflight.PlayerPatches.PlayerVisuals), "SetupPlayerVisuals")]
//public static class Odinflight_patch
//{
// public static void Postfix(Odinflight.PlayerPatches.PlayerVisuals __instance)
// {
// ZLog.Log("" + __instance.PlayerRAC);
// foreach(AnimationClip ac in __instance.PlayerRAC.animationClips)
// {
// ZLog.Log("animation clip name: " + ac.name);
// }
// }
//}
[HarmonyPatch(typeof(ZNet), "Awake")]
[HarmonyPriority(int.MaxValue)]
public static class ZNet_VL_Register
{
public static void Postfix(ZNet __instance, ZRoutedRpc ___m_routedRpc)
{
___m_routedRpc.Register<ZPackage>("VL_ConfigSync", VL_ConfigSync.RPC_VL_ConfigSync);
}
}
public static long ServerID;
[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
public static class ConfigServerSync
{
private static void Postfix(ref ZNet __instance, ZRpc rpc)
{
MethodBase GetServerPeerID = AccessTools.Method(typeof(ZRoutedRpc), "GetServerPeerID", null, null);
ServerID = (long)GetServerPeerID.Invoke(ZRoutedRpc.instance, new object[0]);
if (!__instance.IsServer())
{
ZRoutedRpc.instance.InvokeRoutedRPC(ServerID, "VL_ConfigSync", new object[] { new ZPackage() });
}
}
}
//[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
//public static class ConfigServerSync
//{
// private static void Postfix(ref ZNet __instance)
// {
// if (!__instance.IsServer())
// {
// ZLog.Log("-------------------- SENDING VL_CONFIGSYNC REQUEST");
// ZRoutedRpc.instance.InvokeRoutedRPC("VL_ConfigSync", new object[] { new ZPackage() });
// }
// }
//}
[HarmonyPatch(typeof(PlayerProfile), "SavePlayerToDisk", null)]
public static class SaveVLPlayer_Patch
{
public static void Postfix(PlayerProfile __instance, string ___m_filename, string ___m_playerName)
{
try
{
//ZLog.Log("filename: " + ___m_filename);
Directory.CreateDirectory(Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/characters/VL");
string text = Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/characters/VL/" + ___m_filename + "_vl.fch";
string text3 = Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/characters/VL/" + ___m_filename + "_vl.fch.new";
ZPackage zPackage = new ZPackage();
zPackage.Write(GetPlayerClassNum);
byte[] array = zPackage.GenerateHash();
byte[] array2 = zPackage.GetArray();
FileStream fileStream = File.Create(text3);
BinaryWriter binaryWriter = new BinaryWriter(fileStream);
binaryWriter.Write(array2.Length);
binaryWriter.Write(array2);
binaryWriter.Write(array.Length);
binaryWriter.Write(array);
binaryWriter.Flush();
fileStream.Flush(flushToDisk: true);
fileStream.Close();
fileStream.Dispose();
if (File.Exists(text))
{
File.Delete(text);
}
File.Move(text3, text);
}
catch(NullReferenceException ex)
{
//failed to save, return to normal process
}
}
}
[HarmonyPatch(typeof(PlayerProfile), "LoadPlayerFromDisk", null)]
public class LoadVLPlayer_Patch
{
public static void Postfix(PlayerProfile __instance, string ___m_filename, string ___m_playerName)
{
//ZLog.Log("Loading player: (" + ___m_playerName + ")");
try
{
if(vl_playerList == null)
{
vl_playerList = new List<VL_Player>();
}
vl_playerList.Clear();
ZPackage zPackage = LoadPlayerDataFromDisk(___m_filename);
if (zPackage == null)
{
//ZLog.LogWarning("No player data for valheim legends");
goto LoadExit;
}
int num = zPackage.ReadInt();
VL_Player newLegend = new VL_Player();
newLegend.vl_name = ___m_playerName;
newLegend.vl_class = (PlayerClass)num;
vl_playerList.Add(newLegend);
//ZLog.Log("VL adding " + ___m_playerName + " as class num " + num);
}
catch (Exception ex)
{
ZLog.LogWarning("Exception while loading player VL profile: " + ex.ToString());
}
LoadExit:;
}
private static ZPackage LoadPlayerDataFromDisk(string m_filename)
{
string text = Utils.GetSaveDataPath(FileHelpers.FileSource.Local) + "/characters/VL/" + m_filename + "_vl.fch";
//ZLog.Log("Player load file is : (" + text + ")");
FileStream fileStream;
try
{
fileStream = File.OpenRead(text);
}
catch
{
//ZLog.Log(" failed to load " + text);
return null;
}
byte[] data;
try
{
BinaryReader binaryReader = new BinaryReader(fileStream);
int count = binaryReader.ReadInt32();
data = binaryReader.ReadBytes(count);
int count2 = binaryReader.ReadInt32();
binaryReader.ReadBytes(count2);
}
catch
{
ZLog.LogError(" error loading VL player data");
fileStream.Dispose();
return null;
}
fileStream.Dispose();
return new ZPackage(data);
}
}
public static bool ClassIsValid
{
get
{
if(vl_player != null)
{
return vl_player.vl_class != PlayerClass.None;
}
return false;
}
}
private static readonly Type patchType = typeof(ValheimLegends);
//objects
public static Sprite Ability1_Sprite;
public static Sprite Ability2_Sprite;
public static Sprite Ability3_Sprite;
public static Sprite DyingLight_Sprite;
public static string Ability1_Name;
public static string Ability2_Name;
public static string Ability3_Name;
public static string Ability1_Description;
public static string Ability2_Description;
public static string Ability3_Description;
public static List<RectTransform> abilitiesStatus = new List<RectTransform>();
//global variables
public static bool shouldUseGuardianPower = true;
public static bool shouldValkyrieImpact = false;
public static bool isChanneling = false;
public static int channelingCancelDelay = 0;
public static bool isChargingDash = false;
public static int dashCounter = 0;
public static int logCheck = 0;
public static int animationCountdown = 0;
//Skills
public static readonly int DisciplineSkillID = 781;
public static readonly int AbjurationSkillID = 791;
public static readonly int AlterationSkillID = 792;
public static readonly int ConjurationSkillID = 793;
public static readonly int EvocationSkillID = 794;
public static readonly int IllusionSkillID = 795;
public enum SkillName
{
Discipline = 781,
Abjuration = 791,
Alteration = 792,
Conjuration = 793,
Evocation = 794,
Illusion = 795
}
public static Skills.SkillType DisciplineSkill = (Skills.SkillType)DisciplineSkillID;
public static Skills.SkillType AbjurationSkill = (Skills.SkillType)AbjurationSkillID;
public static Skills.SkillType AlterationSkill = (Skills.SkillType)AlterationSkillID;
public static Skills.SkillType ConjurationSkill = (Skills.SkillType)ConjurationSkillID;
public static Skills.SkillType EvocationSkill = (Skills.SkillType)EvocationSkillID;
public static Skills.SkillType IllusionSkill = (Skills.SkillType)IllusionSkillID;
public static Skills.SkillDef DisciplineSkillDef;
public static Skills.SkillDef AbjurationSkillDef;
public static Skills.SkillDef AlterationSkillDef;
public static Skills.SkillDef ConjurationSkillDef;
public static Skills.SkillDef EvocationSkillDef;
public static Skills.SkillDef IllusionSkillDef;
public static List<Skills.SkillDef> legendsSkills = new List<Skills.SkillDef>();
//informational patches
//[HarmonyPatch(typeof(StatusEffect), "Setup", null)]
//public class MonitorStatusEffects_Patch
//{
// public static void Postfix(StatusEffect __instance, string ___m_name, string ___m_category)
// {
// ZLog.Log("Setup status: (" + ___m_name + ") category: (" + ___m_category + ")");
// }
//}
//[HarmonyPatch(typeof(ZSyncAnimation), "SetTrigger", null)]
//public class AnimationTrigger_Prevention_Patch
//{
// public static bool Prefix(ZSyncAnimation __instance, string name, ref Animator ___m_animator)
// {
// if(name == "gpower")
// {
// ___m_animator.speed = 5f;
// }
// return true;
// }
//}
//[HarmonyPatch(typeof(ZSyncAnimation), "RPC_SetTrigger", null)]
//public class AnimationTrigger_Monitor_Patch
//{
// public static void Postfix(ZSyncAnimation __instance, long sender, string name)
// {
// ZLog.Log("animation: " + name);
// }
//}
//[HarmonyPatch(typeof(ZNetScene), "RemoveObjects", null)]
//public class AnimationTrigger_Monitor_Patch
//{
// public static bool Prefix(ZNetScene __instance, List<ZDO> currentNearObjects, List<ZDO> currentDistantObjects, Dictionary<ZDO, ZNetView> ___m_instances, List<ZNetView> ___m_tempRemoved)
// {
// int frameCount = Time.frameCount;
// foreach (ZDO currentNearObject in currentNearObjects)
// {
// //ZLog.Log("rmv: near object - " + currentNearObject.m_type.ToString());
// currentNearObject.m_tempRemoveEarmark = frameCount;
// }
// foreach (ZDO currentDistantObject in currentDistantObjects)
// {
// //ZLog.Log("rmv: far object - " + currentDistantObject.m_type.ToString());
// currentDistantObject.m_tempRemoveEarmark = frameCount;
// }
// ___m_tempRemoved.Clear();
// foreach (ZNetView value in ___m_instances.Values)
// {
// //ZLog.Log("val name " +value.name);
// if (value.GetZDO().m_tempRemoveEarmark != frameCount)
// {
// if (value != null)
// {
// ___m_tempRemoved.Add(value);
// }
// else
// {
// ZLog.Log("not adding " + value);
// }
// }
// }
// for (int i = 0; i < ___m_tempRemoved.Count; i++)
// {
// ZNetView zNetView = ___m_tempRemoved[i];
// if (zNetView != null)
// {
// ZDO zDO = zNetView.GetZDO();
// if (zDO != null)
// {
// zNetView.ResetZDO();
// UnityEngine.Object.Destroy(zNetView.gameObject);
// if (!zDO.m_persistent && zDO.IsOwner())
// {
// ZDOMan.instance.DestroyZDO(zDO);
// }
// }
// else
// {
// ZLog.Log("null zdo");
// }
// ___m_instances.Remove(zDO);
// }
// else
// {
// ZLog.Log("znet view " + ___m_tempRemoved[i]);
// ___m_tempRemoved.Remove(zNetView);
// i--;
// }
// }
// return false;
// }
//}
//[HarmonyPatch(typeof(CharacterTimedDestruction), "Trigger", new Type[]
//{
// typeof(float)
//})]
//public class TimedDestruction_testpatch
//{
// public static bool Prefix(CharacterTimedDestruction __instance, Character ___m_character)
// {
// ZLog.Log("destroying " + ___m_character.name + " from timed event of " + __instance.m_timeoutMin + "min " + __instance.m_timeoutMax + "max");
// return true;
// }
//}
//
//console commands
//
[HarmonyPatch(typeof(Skills), "CheatRaiseSkill", null)]
public class CheatRaiseSkill_VL_Patch
{
public static bool Prefix(Skills __instance, string name, float value, Player ___m_player)
{
if(VL_Console.CheatRaiseSkill(__instance, name, value, ___m_player))
{
Console.instance.Print("Skill " + name + " raised " + value);
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Terminal), "InputText", null)]
public class Cheats_VL_Patch
{
public static void Postfix(Console __instance, InputField ___m_input)
{
if ((bool)ZNet.instance && ZNet.instance.IsServer() && (bool)Player.m_localPlayer && __instance.IsCheatsEnabled() && playerEnabled)
{
string text = ___m_input.text;
string[] array = text.Split(' ');
if (array.Length > 1)
{
if (array[0] == "vl_changeclass")
{
string className = array[1];
VL_Console.CheatChangeClass(className);
}
}
}
}
}
//
//mod patches
//
[HarmonyPatch(typeof(Aoe), "OnHit")]
public static class Aoe_LOSCheck_Prefix
{
private static bool Prefix(Aoe __instance, Collider collider, Vector3 hitPoint, List<GameObject> ___m_hitList, ref bool __result)
{
GameObject gameObject = Projectile.FindHitObject(collider);
if (___m_hitList.Contains(gameObject))
{
__result = false;
return false;
}
IDestructible component = gameObject.GetComponent<IDestructible>();
if (component != null)
{
Character character = component as Character;
if ((bool)character)
{
if (!VL_Utility.LOS_IsValid(character, __instance.transform.position))
{
__result = false;
return false;
}
}
}
return true;
}
}
//[HarmonyPatch(typeof(Projectile), "IsValidTarget")]
//public static class Projectile_AoE_LOSCheck_Prefix
//{
// private static bool Prefix(Projectile __instance, IDestructible destr, ref bool __result)
// {
// Character character = destr as Character;
// if ((bool)character)
// {
// if (!VL_Utility.LOS_IsValid(character, __instance.transform.position, __instance.transform.position + __instance.GetVelocity() * -1.5f))
// {
// __result = false;
// return false;
// }
// }
// return true;
// }
//}
[HarmonyPatch(typeof(Humanoid), "GetCurrentWeapon")]
public static class UnarmedDamage
{
private static ItemDrop.ItemData Postfix(ItemDrop.ItemData __weapon, ref Character __instance)
{
if (__weapon != null && __weapon.m_shared.m_name == "Unarmed")
{
Player player = (Player)__instance;
//ZLog.Log("weapon damage " + __weapon.m_shared.m_damages.m_blunt + " skill factor " + player.GetSkillFactor(Skills.SkillType.Unarmed) + " modifier " + VL_GlobalConfigs.g_UnarmedDamage);
__weapon.m_shared.m_damages.m_blunt = player.GetSkillFactor(Skills.SkillType.Unarmed) * VL_GlobalConfigs.g_UnarmedDamage * 100f;
}
return __weapon;
}
}
[HarmonyPatch(typeof(Player), "ActivateGuardianPower", null)]
public class ActivatePowerPrevention_Patch
{
public static bool Prefix(Player __instance, ref bool __result)
{
if (!shouldUseGuardianPower)
{
__result = false;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Player), "OnDodgeMortal", null)]
public class DodgeBreaksChanneling_Patch
{
public static void Postfix(Player __instance)
{
if (isChanneling)
{
ValheimLegends.isChanneling = false;
}
}
}
[HarmonyPatch(typeof(Player), "StartGuardianPower", null)]
public class StartPowerPrevention_Patch
{
public static bool Prefix(Player __instance, ref bool __result)
{
if (!shouldUseGuardianPower)
{
__result = false;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Player), "CanMove", null)]
public class CanMove_Casting_Patch
{
public static void Postfix(Player __instance, ref bool __result)
{
if(isChanneling)
{
__result = false;
}
}
}
[HarmonyPatch(typeof(Menu), "OnQuit", null)]
public class QuitYes_Patch
{
public static bool Prefix()
{
RemoveSummonedWolf();
return true;
}
}
[HarmonyPatch(typeof(Menu), "OnLogout", null)]
public class RemoveWolfOnLogout_Patch
{
public static bool Prefix()
{
RemoveSummonedWolf();
return true;
}
}
private static int Script_WolfAttackMask = LayerMask.GetMask("Default", "static_solid", "Default_small", "piece_nonsolid", "terrain", "vehicle", "piece", "viewblock", "character", "character_noenv", "character_trigger");
[HarmonyPatch(typeof(Attack), "Start", null)]
public class ShadowWolfAttack_Patch
{
public static bool Prefix(Attack __instance, Humanoid character, Rigidbody body, ZSyncAnimation zanim, CharacterAnimEvent animEvent, VisEquipment visEquipment, ItemDrop.ItemData weapon, Attack previousAttack, float timeSinceLastAttack, float attackDrawPercentage, string ___m_attackAnimation)
{
if (character != null && (character.m_name == "Shadow Wolf" || character.m_name.Contains("Demon Wolf")))
{
//Vector3 hitVec = character.transform.position + character.transform.forward * .2f + character.transform.up * .2f;
//GameObject prefab = ZNetScene.instance.GetPrefab("VL_ShadowWolfAttack");
//GameObject GO_ShadowWolfAttack = UnityEngine.Object.Instantiate(prefab, hitVec, Quaternion.identity);
//Projectile P_ShadowWolfAttack = GO_ShadowWolfAttack.GetComponent<Projectile>();
////P_ShadowWolfAttack.name = "ShadowWolfAttack";
//P_ShadowWolfAttack.m_respawnItemOnHit = false;
//P_ShadowWolfAttack.m_blockable = true;
//P_ShadowWolfAttack.m_dodgeable = true;
//P_ShadowWolfAttack.m_spawnOnHit = null;
//P_ShadowWolfAttack.m_ttl = .5f;
//P_ShadowWolfAttack.m_gravity = 0f;
//P_ShadowWolfAttack.m_rayRadius = .1f;
//GO_ShadowWolfAttack.transform.localScale = Vector3.zero;
//RaycastHit hitInfo = default(RaycastHit);
//Vector3 position = character.transform.position;
//Vector3 target = (!Physics.Raycast(hitVec, character.transform.forward, out hitInfo, float.PositiveInfinity, Script_WolfAttackMask) || !(bool)hitInfo.collider) ? (position + character.transform.forward * 1000f) : hitInfo.point;
//float dmgMod = UnityEngine.Random.Range(.6f, 1.2f);
//if (character.GetSEMan().HaveStatusEffect("SE_VL_Companion"))
//{
// SE_Companion se_comp = (SE_Companion)character.GetSEMan().GetStatusEffect("SE_VL_Companion");
// dmgMod *= se_comp.damageModifier;
//}
//HitData hitData = new HitData();
//hitData.m_damage = P_ShadowWolfAttack.m_damage;
//hitData.ApplyModifier(dmgMod);
//Vector3 a = Vector3.MoveTowards(GO_ShadowWolfAttack.transform.position, target, 1f);
//P_ShadowWolfAttack.Setup(character, (a - GO_ShadowWolfAttack.transform.position) * 10f, -1f, hitData, null);
//GO_ShadowWolfAttack = null;
Vector3 hitVec = character.transform.position + character.transform.up * .3f;
RaycastHit hitInfo = default(RaycastHit);
//ZLog.Log("hitVec position " + hitVec);
//Vector3 target = (!Physics.Raycast(hitVec, character.transform.forward, out hitInfo, 5f, Script_WolfAttackMask) || !(bool)hitInfo.collider) ? (character.transform.position + character.transform.forward * 5f) : hitInfo.point;
Physics.SphereCast(hitVec, 0.2f, character.transform.forward, out hitInfo, 3f, Script_WolfAttackMask);
if (hitInfo.collider != null && hitInfo.collider.gameObject != null)
{
//ZLog.Log("collider " + hitInfo.collider);
//ZLog.Log("collider distance " + hitInfo.distance);
Character ch;
hitInfo.collider.gameObject.TryGetComponent<Character>(out ch);
bool flag = ch != null;
if (ch == null)
{
ch = (Character)hitInfo.collider.GetComponentInParent(typeof(Character));
flag = ch != null;
if (ch == null)
{
ch = (Character)hitInfo.collider.GetComponentInChildren<Character>();
flag = ch != null;
}
}
if (flag && BaseAI.IsEnemy(ch, character) && !ch.IsDodgeInvincible())
{
//ZLog.Log("collider game object is character");
//ZLog.Log("" + ch.m_name + " position " + ch.transform.position + " distance of " + (ch.transform.position - hitVec).magnitude + " away and center is " + (ch.GetCenterPoint() - hitVec).magnitude);
//ZLog.Log("hitting " + ch.m_name + " at range " + (ch.transform.position - hitVec).magnitude);
Vector3 direction = (hitVec - ch.GetEyePoint());
float dmgMod = UnityEngine.Random.Range(.6f, 1.2f);
if (character.GetSEMan().HaveStatusEffect("SE_VL_Companion"))
{
SE_Companion se_comp = (SE_Companion)character.GetSEMan().GetStatusEffect("SE_VL_Companion".GetStableHashCode());
dmgMod *= se_comp.damageModifier;
}
HitData hitData = new HitData();
hitData.m_damage = weapon.GetDamage();
hitData.m_damage.m_slash = weapon.GetDamage().m_slash * dmgMod;
hitData.m_point = hitInfo.point;
hitData.m_dir = (ch.transform.position - character.transform.position);
hitData.m_skill = Skills.SkillType.Unarmed;
if(ch.IsBlocking())
{
Player p = ch as Player;
if (p != null)
{
MethodBase BlockAttack = AccessTools.Method(typeof(Humanoid), "BlockAttack", null, null);
BlockAttack.Invoke(p, new object[2] {
hitData,
character
});
}
}
else
{
ch.Damage(hitData);
}
}
}
}
return true;
}
}
private static void RemoveSummonedWolf()
{
foreach (Character ch in Character.GetAllCharacters())
{
if (ch != null && ch.GetSEMan() != null)
{
if (ch.GetSEMan().HaveStatusEffect("SE_VL_Companion"))
{
SE_Companion se_c = ch.GetSEMan().GetStatusEffect("SE_VL_Companion".GetStableHashCode()) as SE_Companion;
if (se_c.summoner == Player.m_localPlayer)
{
MonsterAI ai = ch.GetComponent<MonsterAI>();
if(ai != null)
{
ai.SetFollowTarget(null);
}
ch.m_faction = Character.Faction.MountainMonsters;
HitData hit = new HitData();
hit.m_damage.m_slash = 9999f;
ch.Damage(hit);
//UnityEngine.GameObject.Destroy(ch.gameObject);
}
}
else if(ch.GetSEMan().HaveStatusEffect("SE_VL_Charm"))
{
SE_Charm se_charm = (SE_Charm)ch.GetSEMan().GetStatusEffect("SE_VL_Charm".GetStableHashCode());
ch.m_faction = se_charm.originalFaction;
}
}
}
}
[HarmonyPatch(typeof(BaseAI), "CanSenseTarget", new Type[]
{
typeof(Character)
})]
public class CanSee_Shadow_Patch
{
public static bool Prefix(BaseAI __instance, Character target, ref bool __result)
{
if (target != null)
{
Player player = target as Player;
if (player != null && player.GetSEMan().HaveStatusEffect("SE_VL_ShadowStalk".GetStableHashCode()))
{
if (player.IsCrouching())
{
__result = false;
return false;
}
}
}
return true;
}
}
[HarmonyPatch(typeof(Character), "UpdateGroundContact", null)]
public class Valkyrie_ValidateHeight_Patch
{
public static bool Prefix(Character __instance, ref float ___m_maxAirAltitude, bool ___m_groundContact)
{
if (vl_player != null && vl_player.vl_class == PlayerClass.Monk && ___m_groundContact && Mathf.Max(0f, ___m_maxAirAltitude - __instance.transform.position.y) > 4f)
{
___m_maxAirAltitude -= 6;
}
return true;
}
public static void Postfix(Character __instance, float ___m_maxAirAltitude, bool ___m_groundContact)
{
if (__instance == Player.m_localPlayer)
{
if (Class_Valkyrie.inFlight)
{
if (Mathf.Max(0f, ___m_maxAirAltitude - __instance.transform.position.y) > 1f)
{
ValheimLegends.shouldValkyrieImpact = true;
}
}
}
}
}
[HarmonyPatch(typeof(Character), "ResetGroundContact", null)]
public class Valkyrie_GroundContact_Patch
{
public static void Postfix(Character __instance, float ___m_maxAirAltitude, bool ___m_groundContact)
{
if (__instance == Player.m_localPlayer && shouldValkyrieImpact)
{
float maxAltitude = Mathf.Max(0f, ___m_maxAirAltitude - __instance.transform.position.y);
ValheimLegends.shouldValkyrieImpact = false;
if (vl_player.vl_class == PlayerClass.Valkyrie)
{
Class_Valkyrie.Impact_Effect(Player.m_localPlayer, maxAltitude);
Class_Valkyrie.inFlight = false;
}
if(vl_player.vl_class == PlayerClass.Monk)
{
Class_Monk.Impact_Effect(Player.m_localPlayer, maxAltitude);
}
}
}
}
[HarmonyPatch(typeof(Humanoid), "UseItem")]