-
Notifications
You must be signed in to change notification settings - Fork 1
/
apocalypse.asm
1100 lines (1006 loc) · 35.4 KB
/
apocalypse.asm
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
//----------------------------------------------------------------------
// The Apocalypse System
// Written By: Matt Weber (https://badecho.com) (https://twitch.tv/omni)
// Copyright 2024 Bad Echo LLC
//
// Bad Echo Technologies are licensed under the
// GNU Affero General Public License v3.0.
//
// See accompanying file LICENSE.md or a copy at:
// https://www.gnu.org/licenses/agpl-3.0.html
//----------------------------------------------------------------------
// Global Apocalypse memory.
alloc(playerDamageX,8)
alloc(playerGodMode,8)
registersymbol(playerDamageX)
registersymbol(playerGodMode)
playerDamageX:
dd (float)1.0
playerGodMode:
dd 0
// Player Apocalypse System Function
// [rsp+48]: Player's coordinates (aligned at x-coordinate)
// [rsp+50]: Max player health amount
// [rsp+58]: Player's health amount
// [rsp+60]: Damage amount
// Updated damage is in EAX.
// Updated health before damage is in EBX.
alloc(executePlayerApocalypse,$1000)
alloc(logPlayerApocalypse,8)
alloc(apocalypseDieRoll,8)
alloc(apocalypseDieRollUpper,8)
alloc(apocalypseDieRollLower,8)
alloc(extraDamageSafetyThreshold,8)
alloc(extraDamageResidualHealth,8)
alloc(teleported,8)
alloc(teleportedX,8)
alloc(teleportedY,8)
alloc(teleportedZ,8)
alloc(teleportitisResult,8)
alloc(teleportitisResultUpper,8)
alloc(teleportitisResultLower,8)
alloc(teleportitisDivisor,8)
alloc(teleportitisShifter,8)
alloc(lastXDisplacement,8)
alloc(lastYDisplacement,8)
alloc(lastZDisplacement,8)
alloc(lastVerticalDisplacement,8)
alloc(negativeVerticalDisplacementEnabled,8)
alloc(teleportitisDisplacementX,8)
alloc(verticalTeleportitisDisplacementX,8)
alloc(coordinatesAreDoubles,8)
alloc(murderRoll,8)
alloc(murderRollUpper,8)
alloc(murderRollLower,8)
alloc(fatalisResult,8)
alloc(fatalisResultUpper,8)
alloc(fatalisResultLower,8)
alloc(fatalisState,8)
alloc(fatalisBloodlustDamageX,8)
alloc(fatalisHealthLost,8)
alloc(fatalisDeaths,8)
alloc(fatalisMinutesAfflicted,8)
alloc(basePlayerDamageX,8)
alloc(extraDamageX,8)
alloc(murderDamageX,8)
alloc(orgasmHealthHealed,8)
alloc(maxDamageToPlayer,8)
alloc(lastDamageToPlayer,8)
alloc(totalDamageToPlayer,8)
alloc(disableTeleportitis,8)
alloc(disableMurder,8)
alloc(murderIsAfoot,8)
alloc(teleportitisCooldownMinutes,8)
alloc(apocalypseInCooldown,8)
alloc(apocalypseCooldownMilliseconds,8)
registersymbol(apocalypseCooldownMilliseconds)
registersymbol(apocalypseInCooldown)
registersymbol(executePlayerApocalypse)
registersymbol(logPlayerApocalypse)
registersymbol(extraDamageSafetyThreshold)
registersymbol(teleported)
registersymbol(teleportedX)
registersymbol(teleportedY)
registersymbol(teleportedZ)
registersymbol(apocalypseDieRoll)
registersymbol(negativeVerticalDisplacementEnabled)
registersymbol(teleportitisDisplacementX)
registersymbol(verticalTeleportitisDisplacementX)
registersymbol(murderRoll)
registersymbol(fatalisResult)
registersymbol(fatalisResultUpper)
registersymbol(fatalisState)
registersymbol(fatalisBloodlustDamageX)
registersymbol(fatalisHealthLost)
registersymbol(fatalisDeaths)
registersymbol(fatalisMinutesAfflicted)
registersymbol(basePlayerDamageX)
registersymbol(extraDamageX)
registersymbol(orgasmHealthHealed)
registersymbol(murderDamageX)
registersymbol(maxDamageToPlayer)
registersymbol(lastDamageToPlayer)
registersymbol(totalDamageToPlayer)
registersymbol(lastZDisplacement)
registersymbol(lastYDisplacement)
registersymbol(lastXDisplacement)
registersymbol(lastVerticalDisplacement)
registersymbol(coordinatesAreDoubles)
registersymbol(disableTeleportitis)
registersymbol(disableMurder)
registersymbol(murderIsAfoot)
registersymbol(teleportitisCooldownMinutes)
executePlayerApocalypse:
// Backing up a few SSE registers we'll be using to
// hold the parameters provided to this function.
sub rsp,10
movdqu [rsp],xmm0
sub rsp,10
movdqu [rsp],xmm1
sub rsp,10
movdqu [rsp],xmm2
sub rsp,10
movdqu [rsp],xmm3
// Load the player's health parameter.
movss xmm3,[rsp+58]
// Load the damage amount parameter.
movss xmm0,[rsp+60]
// Check if the damage being done is enough to warrant Apocalypse execution.
mov rax,damageThreshold
ucomiss xmm0,[rax]
jbe exitPlayerApocalypse
// If God Mode is disabled, then we apply the Apocalypse.
cmp [playerGodMode],1
jne applyApocalypse
// Otherwise, we zero out our final damage amount register and exit.
xorps xmm0,xmm0
jmp exitPlayerApocalypse
applyApocalypse:
// If "Murder Is Afoot!!" mode is enabled, force a murder effect.
cmp [murderIsAfoot],1
jne checkFatalis
mov [apocalypseDieRoll],8
mov [murderRoll],4
jmp murder
checkFatalis:
// Fatalis
//
// If the player has the Fatalis debuff, all damage is fatal. Exposure to Fatalis is indicated by the 'fatalisState'
// being 1, while full-on affliction is indicated by a state of 2. Having a state of exposure allows the messaging
// system the ability to detect newly acquired Fatalis statuses, and to be able to report on these events appropriately.
//
// The messaging system is then responsible for setting 'fatalisState' to 2, indicating that it is now active.
// Now, that being said: if the player is being hit at a very, very high frequency, it is possible that another
// hit can occur after Fatalis exposure, but before the messaging system can set it as active.
//
// This is very much an edge case, and it is handled by simply allowing the damage to be processed normally
// (as in, vanilla game mechanics) and without reporting it via the Apocalypse system. This will allow us to avoid
// any strange "experience gaps" that would occur, such as messages to the player that they have Fatalis followed
// by non-Fatalis Player Apocalypse effect messsages. It also prevents any chance that the "exposure event" isn't
// reported, or that only an exposure event is reported, without the expected follow-up Fatalis death event message
// (which would be expected since...we'd be dead).
//
// The normal damage from this rare edge case will not be reported -- we'll need to implement a queue in assembly in order
// for that and other normally missed events to be caught.
cmp [fatalisState],1
je exitPlayerApocalypse
cmp [fatalisState],2
jne checkForCooldown
// To make good on the Fatalis debuff, we set the damage equal to the health.
movss xmm0,xmm3
movss [fatalisHealthLost],xmm3
inc [fatalisDeaths]
jmp updatePlayerDamageStats
checkForCooldown:
// If the Apocalypse system is in cooldown, something which will only happen if a target game has enabled the feature,
// we abort execution of the Apocalypse unless the base damage is enough to kill the player.
// The reason for this is because we want the death of the player to be reported in messaging, which will only happen if
// death happens from the result of an Apocalypse roll.
cmp [apocalypseInCooldown],1
jne applyApocalypseRoll
vsubss xmm1,xmm3,xmm0
xorps xmm2,xmm2
ucomiss xmm1,xmm2
ja exitPlayerApocalypse
applyApocalypseRoll:
// Load the parameters for generating the dice roll random number.
push [apocalypseDieRollLower]
push [apocalypseDieRollUpper]
call generateRandomNumber
// Our random roll value is in eax -- we back it up to the "apocalypseDieRoll"
// symbol so that the value can be displayed by the event logging display code.
mov [apocalypseDieRoll],eax
cmp eax,4
jle extraDamage
cmp eax,6
jle teleportitis
cmp eax,9
jle riskOfMurder
jmp suddenGasm
extraDamage:
// Load the player's maximum health, check if current health is below that multiplied by
// the safety threshold.
movss xmm1,[rsp+50]
mulss xmm1,[extraDamageSafetyThreshold]
ucomiss xmm3,xmm1
jb applyExtraDamage
// Check if the damage would normally kill us, even without the extra damage effect.
movss xmm1,xmm3
subss xmm1,xmm0
mov rax,epsilon
movss xmm2,[rax]
ucomiss xmm1,xmm2
jb applyExtraDamage
// Normal damage wouldn't kill us, check if extra damage would, and then prevent it from doing so.
movss xmm1,xmm3
movss xmm2,xmm0
mulss xmm2,[extraDamageX]
subss xmm1,xmm2
movss xmm2,[rax]
ucomiss xmm1,xmm2
ja applyExtraDamage
// Set damage to be same as current health minus our "left over" health so that we end up with
// this health amount following application of damage to our health.
movss xmm0,xmm3
subss xmm0,[extraDamageResidualHealth]
jmp updatePlayerDamageStats
applyExtraDamage:
mulss xmm0,[extraDamageX]
jmp updatePlayerDamageStats
teleportitis:
// Check if teleportitis is disabled. If so, we instead apply extra damage.
cmp [disableTeleportitis],1
jne commitTeleportitis
mov [apocalypseDieRoll],1
jmp extraDamage
commitTeleportitis:
// Some games will disable modifications being made to the player's coordinates
// during certain animations such as weapon attacks or getting knocked back.
// This code needs to be hooked into and temporarily disabled in order for
// teleportitis to work. This can be done by checking the "teleported" symbol
// and preventing those coordinates from being reset. That code will then
// need to set this symbol to 0. In most games I've hacked, this is not
// required. In fact, only one: Dark Souls I.
mov [teleported],1
// Load the player coordinates address parameter.
mov rbx,[rsp+48]
// Load the parameters for generating the random displacement value to be
// applied to the x-coordinate.
push [teleportitisResultLower]
push [teleportitisResultUpper]
call generateRandomNumber
// The random number is an integer and will need to be converted to a float.
mov [teleportitisResult],eax
cvtsi2ss xmm1,[teleportitisResult]
// The random number is divided by the following divisor to bring it into the
// expected range (0-10) along with some decimal precision (3 decimal places).
divss xmm1,[teleportitisDivisor]
// We cannot generate random negative integers, we instead shift what we have
// here by a negative amount. The range 0 to 10 becomes -5 to 5.
subss xmm1,[teleportitisShifter]
// We finally take what we have and then multiply it by the displacement
// multiplier to get the final displacement value to apply to the player's
// x-coordinate.
mulss xmm1,[teleportitisDisplacementX]
// We then take the player's current x-coordinate from memory and add the
// displacement value to it.
cmp [coordinatesAreDoubles],1
je loadXAsDouble
movss xmm2,[rbx]
jmp addChangeToX
loadXAsDouble:
cvtsd2ss xmm2,[rbx]
addChangeToX:
movss [lastXDisplacement],xmm1
addss xmm2,xmm1
// The updated x-coordinate is committed back into the memory, which will
// move the player.
movss [teleportedX],xmm2
cmp [coordinatesAreDoubles],1
je commitXAsDouble
movss [rbx],xmm2
jmp teleportitisY
commitXAsDouble:
cvtss2sd xmm1,xmm2
movsd [rbx],xmm1
teleportitisY:
// Load the parameters for generating the random displacement value to be
// applied to the y-coordinate.
push [teleportitisResultLower]
push [teleportitisResultUpper]
call generateRandomNumber
mov [teleportitisResult],eax
cvtsi2ss xmm1,[teleportitisResult]
divss xmm1,[teleportitisDivisor]
// If the Y-axis is not the vertical axis, then we we don't need to check
// whether vertical displacement is enabled.
mov rax,yIsVertical
cmp [rax],1
jne skipYSkipCheck
// If negative vertical displacement is not enabled we do not want to shift it,
// this causes the random value to remain in the range of 0 to 10.
cmp [negativeVerticalDisplacementEnabled],1
jne skipNegativeVerticalYDisplacement
skipYSkipCheck:
subss xmm1,[teleportitisShifter]
skipNegativeVerticalYDisplacement:
mulss xmm1,[teleportitisDisplacementX]
// The vertical displacement value is logged separately and has its own multiplier as changes to it are
// often the most consequential. We make sure the Y-axis is the vertical one before logging and multiplying it.
mov rax,yIsVertical
cmp [rax],1
jne skipLastYVerticalDisplacement
mulss xmm1,[verticalTeleportitisDisplacementX]
movss [lastVerticalDisplacement],xmm1
skipLastYVerticalDisplacement:
// We then take the player's current y-coordinate from memory and add the
// displacement value to it.
cmp [coordinatesAreDoubles],1
je loadYAsDouble
movss xmm2,[rbx+4]
jmp addChangeToY
loadYAsDouble:
cvtsd2ss xmm2,[rbx+8]
addChangeToY:
movss [lastYDisplacement],xmm1
addss xmm2,xmm1
// The updated y-coordinate is commited back into the memory, which will
// move the player.
movss [teleportedY],xmm2
cmp [coordinatesAreDoubles],1
je commitYAsDouble
movss [rbx+4],xmm2
jmp teleportitisZ
commitYAsDouble:
cvtss2sd xmm1,xmm2
movsd [rbx+8],xmm1
teleportitisZ:
// Load the parameters for generating the random displacement value to be
// applied to the z-coordinate.
push [teleportitisResultLower]
push [teleportitisResultUpper]
call generateRandomNumber
mov [teleportitisResult],eax
cvtsi2ss xmm1,[teleportitisResult]
divss xmm1,[teleportitisDivisor]
// Like the y-axis, the z-axis can sometimes be the vertical axis. So checks
// similar to the ones made in the y-coordinate displacement code are made.
mov rax,yIsVertical
cmp [rax],0
jne skipZSkipCheck
cmp [negativeVerticalDisplacementEnabled],1
jne skipNegativeVerticalZDisplacement
skipZSkipCheck:
subss xmm1,[teleportitisShifter]
skipNegativeVerticalZDisplacement:
mulss xmm1,[teleportitisDisplacementX]
mov rax,yIsVertical
cmp [rax],0
jne skipLastZVerticalDisplacement
mulss xmm1,[verticalTeleportitisDisplacementX]
movss [lastVerticalDisplacement],xmm1
skipLastZVerticalDisplacement:
// We then take the player's current z-coordinate from memory and add the
// displacement value to it.
cmp [coordinatesAreDoubles],1
je loadZAsDouble
movss xmm2,[rbx+8]
jmp addChangeToZ
loadZAsDouble:
cvtsd2ss xmm2,[rbx+10]
addChangeToZ:
movss [lastZDisplacement],xmm1
addss xmm2,xmm1
// The updated z-coordinate is commited back into the memory, which will
// move the player.
movss [teleportedZ],xmm2
cmp [coordinatesAreDoubles],1
je commitZAsDouble
movss [rbx+8],xmm2
jmp updatePlayerDamageStats
commitZAsDouble:
cvtss2sd xmm1,xmm2
movsd [rbx+10],xmm1
jmp updatePlayerDamageStats
riskOfMurder:
// Load the parameters for generating the Risk of Murder dice roll random
// number.
push [murderRollLower]
push [murderRollUpper]
call generateRandomNumber
// Our Risk of Murder roll is in eax -- we back it up to the "murderRoll"
// symbol so that the value can be displayed by the event logging display code.
mov [murderRoll],eax
cmp eax,3
// If the resulting roll is 4 or 5, then the player is getting murdered.
jg murder
// Otherwise, normal damage applies, however there is also now a very slight chance
// of Fatalis being applied...
push [fatalisResultLower]
push [fatalisResultUpper]
call generateRandomNumber
// The Fatalis roll is in eax -- we throw it into the "fatalisResult" symbol
// so we can report on it.
mov [fatalisResult],eax
// Fatalis will only be applied if the roll landed on the maximum possible value.
cmp eax,[fatalisResultUpper]
jne updatePlayerDamageStats
// The player has been exposed to Fatalis.
mov [fatalisState],1
// The player, although made fragile by the scourge of Fatalis, enters a rage that increases their damage.
// Store current player damage for later restoration, and then increase it by 1.25x.
movss xmm1,[playerDamageX]
movss [basePlayerDamageX],xmm1
mulss xmm1,[fatalisBloodlustDamageX]
movss [playerDamageX],xmm1
jmp updatePlayerDamageStats
murder:
// Check if murder is disabled, if so, just apply normal damage.
cmp [disableMurder],1
jne commitMurder
mov [murderRoll],1
jmp updatePlayerDamageStats
commitMurder:
mulss xmm0,[murderDamageX]
jmp updatePlayerDamageStats
suddenGasm:
// The player will be fully healed and damage negated. First, we record how much we're healing by
// finding the difference between the value of the player maximum health parameter and the current
// working health value.
movss xmm0,[rsp+50]
subss xmm0,xmm3
movss [orgasmHealthHealed],xmm0
// We then load the player maximum health parameter again and store its value in the final player health
// (prior to damage applied) register.
movss xmm3,[rsp+50]
// We zero out our final damage amount register.
xorps xmm0,xmm0
jmp applyPlayerApocalypseExit
updatePlayerDamageStats:
// If the final damage amount is less than or equal to the current max damage
// to the player, it doesn't need to be updated obviously!
ucomiss xmm0,[maxDamageToPlayer]
jna skipMaxPlayerDamageUpdate
movss [maxDamageToPlayer],xmm0
skipMaxPlayerDamageUpdate:
// We save the final damage amount as the last damage to be done to the player,
// and add it to the running total.
movss [lastDamageToPlayer],xmm0
movss xmm1,xmm0
addss xmm1,[totalDamageToPlayer]
movss [totalDamageToPlayer],xmm1
applyPlayerApocalypseExit:
// Because Apocalypse execution is complete, we trigger an event log entry for
// it by setting "logPlayerApocalypse" to 1.
mov [logPlayerApocalypse],1
jmp exitPlayerApocalypse
exitPlayerApocalypse:
// We commit our final damage amount to eax.
movd eax,xmm0
// We commit our final working player health to ebx.
movd ebx,xmm3
// Restore backed up values.
movdqu xmm3,[rsp]
add rsp,10
movdqu xmm2,[rsp]
add rsp,10
movdqu xmm1,[rsp]
add rsp,10
movdqu xmm0,[rsp]
add rsp,10
// This function has 4 parameters, each require 8 bytes. 4x8 == 20 (hex).
ret 20
logPlayerApocalypse:
dd 0
apocalypseDieRoll:
dd 0
apocalypseDieRollUpper:
dd #10
apocalypseDieRollLower:
dd 1
extraDamageResidualHealth:
dd (float)69.0
extraDamageSafetyThreshold:
dd (float)0.9
teleportitisResult:
dd 0
teleportitisResultUpper:
dd #10000
teleportitisResultLower:
dd 0
teleportitisDivisor:
dd (float)1000.0
teleportitisShifter:
dd (float)5.0
teleported:
dd 0
teleportedX:
dd (float)0.0
teleportedY:
dd (float)0.0
teleportedZ:
dd (float)0.0
lastXDisplacement:
dd (float)0.0
lastYDisplacement:
dd (float)0.0
lastZDisplacement:
dd (float)0.0
negativeVerticalDisplacementEnabled:
dd 1
coordinatesAreDoubles:
dd 0
teleportitisDisplacementX:
dd (float)1.0
verticalTeleportitisDisplacementX:
dd (float)1.0
murderRoll:
dd 0
murderRollUpper:
dd #5
murderRollLower:
dd 1
fatalisResult:
dd 0
fatalisResultUpper:
dd #12
fatalisResultLower:
dd 1
fatalisState:
dd 0
fatalisBloodlustDamageX:
dd (float)1.25
fatalisHealthLost:
dd (float)0.0
fatalisDeaths:
dd 0
fatalisMinutesAfflicted:
dd 0
extraDamageX:
dd (float)2.0
murderDamageX:
dd (float)69.0
orgasmHealthHealed:
dd (float)0.0
maxDamageToPlayer:
dd 0
lastDamageToPlayer:
dd 0
totalDamageToPlayer:
dd 0
disableTeleportitis:
dd 0
disableMurder:
dd 0
murderIsAfoot:
dd 0
teleportitisCooldownMinutes:
dd 2
apocalypseInCooldown:
dd 0
apocalypseCooldownMilliseconds:
dd 0
// Enemy Apocalypse System Function
// [rsp+58]: Target health value
// [rsp+60]: Damage amount
alloc(executeEnemyApocalypse,$1000)
alloc(lastEnemyDamageEvent,8)
alloc(lastEnemyDamageEventBonusX,8)
alloc(lastEnemyDamageEventBonusAmount,8)
alloc(newEnemyDamagePulse,8)
alloc(newEnemyDamagePulseBonusAmount,8)
alloc(enemyDamagePulses,8)
alloc(newEnemyDamageEvent,8)
alloc(newEnemyDamageEventHasBonus,8)
alloc(newEnemyDamageEventBonusX,8)
alloc(newEnemyDamageEventBonusAmount,8)
alloc(newEnemyDamageEventNotProcessed,8)
alloc(maxEnemyDamageEvent,8)
alloc(maxEnemyDamageEventBonusAmount,8)
alloc(totalEnemyDamage,8)
alloc(totalEnemyDamageBonusAmount,8)
alloc(logEnemyApocalypseGoku,8)
alloc(gokuResult,8)
alloc(gokuResultUpper,8)
alloc(gokuResultLower,8)
alloc(gokuDamageX,8)
alloc(lastEnemyHealthValue,8)
alloc(logEnemyApocalypseCrit,8)
alloc(playerCritChanceResultUpper,8)
alloc(playerCritChanceResultLower,8)
alloc(playerCritChanceResult,8)
alloc(playerCritDamageResultUpper,8)
alloc(playerCritDamageResultLower,8)
alloc(playerCritDamageResult,8)
alloc(playerCritDamageDivisor,8)
registersymbol(executeEnemyApocalypse)
registersymbol(lastEnemyDamageEvent)
registersymbol(lastEnemyDamageEventBonusX)
registersymbol(lastEnemyDamageEventBonusAmount)
registersymbol(newEnemyDamagePulse)
registersymbol(newEnemyDamagePulseBonusAmount)
registersymbol(enemyDamagePulses)
registersymbol(newEnemyDamageEvent)
registersymbol(newEnemyDamageEventHasBonus)
registersymbol(newEnemyDamageEventBonusX)
registersymbol(newEnemyDamageEventBonusAmount)
registersymbol(newEnemyDamageEventNotProcessed)
registersymbol(maxEnemyDamageEvent)
registersymbol(maxEnemyDamageEventBonusAmount)
registersymbol(totalEnemyDamage)
registersymbol(totalEnemyDamageBonusAmount)
registersymbol(logEnemyApocalypseGoku)
registersymbol(gokuDamageX)
registersymbol(gokuResultUpper)
registersymbol(lastEnemyHealthValue)
registersymbol(logEnemyApocalypseCrit)
registersymbol(playerCritDamageResultUpper)
registersymbol(playerCritDamageResultLower)
registersymbol(playerCritDamageResult)
executeEnemyApocalypse:
// Backing up a few SSE registers we'll be using to
// hold the parameters provided to this function.
sub rsp,10
movdqu [rsp],xmm0
sub rsp,10
movdqu [rsp],xmm1
sub rsp,10
movdqu [rsp],xmm2
sub rsp,10
movdqu [rsp],xmm3
sub rsp,10
movdqu [rsp],xmm4
// Load the enemy's health parameter.
movss xmm1,[rsp+58]
// Load the damage amount parameter.
movss xmm0,[rsp+60]
// Check if the damage being done is enough to warrant Apocalypse execution.
mov rax,damageThreshold
ucomiss xmm0,[rax]
jbe exitEnemyApocalypse
cmp [playerGodMode],1
jne checkForNewEvent
// If God Mode is enabled, enemies die immediately. The damage, being fake, is not recorded to our
// normal statistics.
movss xmm0,[rsp+58]
movd eax,xmm0
movd ebx,xmm0
jmp enemyApocalypseCleanup
checkForNewEvent:
cmp [newEnemyDamageEventNotProcessed],0
jne applyDamageByPlayer
mov [newEnemyDamageEvent],0
mov [newEnemyDamageEventBonusAmount],0
mov [newEnemyDamageEventBonusX],0
mov [newEnemyDamageEventHasBonus],0
mov [newEnemyDamageEventNotProcessed],1
applyDamageByPlayer:
// Clear out the register that will eventually hold any bonus damage amount.
xorps xmm3,xmm3
// Apply our base player damage multiplier to the damage amount.
mulss xmm0,[playerDamageX]
// If the current damage pulse is part of an event which already has a bonus multiplier, then there is no need
// to roll for bonuses again.
cmp [newEnemyDamageEventHasBonus],1
je applyExistingBonus
// Load the parameters for generating the critical hit check.
push [playerCritChanceResultLower]
push [playerCritChanceResultUpper]
call generateRandomNumber
// Our random roll value is in eax -- we back it up to the
// "playerCritChanceResult" symbol so that the value can be displayed by the
// event logging display code.
mov [playerCritChanceResult],eax
// We can't generate random floats, only random integers. So, to have
// a 1.5% crit chance, we generate a number in the range of 0 to 200, and
// then check if the value is less than or equal to 3 (3/200 = 0.015).
cmp eax,#3
jg checkKamehameha
// Load the parameters for generating the critical hit damage.
push [playerCritDamageResultLower]
push [playerCritDamageResultUpper]
call generateRandomNumber
// Our random roll value is in eax -- we back it up to the
// "playerCritDamageResult" symbol so that the value can be displayed by
// the event logging display code.
mov [playerCritDamageResult],eax
// We can't generate floating point random numbers, so we convert it to float
// and divide it by our divisor to put it in range with one level of decimal
// precision.
cvtsi2ss xmm2,[playerCritDamageResult]
divss xmm2,[playerCritDamageDivisor]
movss [newEnemyDamageEventBonusX],xmm2
mov [newEnemyDamageEventHasBonus],1
// We signal to the event logging system that a crit occurred by setting
// the "logEnemyApocalypseCrit" symbol to 1.
mov [logEnemyApocalypseCrit],1
jmp applyNewBonus
checkKamehameha:
// Load the parameters for generating the Kamehameha check.
push [gokuResultLower]
push [gokuResultUpper]
call generateRandomNumber
// Our random roll value is in eax -- we back it up to the "gokuResult"
// symbol so that the value can be displayed by the event logging display code.
mov [gokuResult],eax
// If the roll is exactly 69, a Kamehameha has occurred! Big damage time baby.
cmp eax,#69
jne updateEnemyDamageStats
movss xmm2,[gokuDamageX]
movss [newEnemyDamageEventBonusX],xmm2
mov [newEnemyDamageEventHasBonus],1
// We signal to the event logging system that a Kamehameha occurred by setting
// the "logEnemyApocalypseGoku" symbol to 1.
mov [logEnemyApocalypseGoku],1
applyNewBonus:
// If there were any previous damage pulses, we'll want to apply the bonus to these amounts retroactively too.
// So, we take all damage previously done and subtract that from all previous damage multiplied by the bonus.
movss xmm4,[newEnemyDamageEvent]
movss xmm3,xmm4
mulss xmm3,xmm2
subss xmm3,xmm4
// We add the current pulse's pre-bonus damage to the previous pulses' pre-bonus damage, so we
// can figure out the amount of additional bonus damage being applied during this pulse.
addss xmm4,xmm0
// We then apply the bonus to the current pulse's damage, and add the additional bonus damage from previous pulses to it.
mulss xmm0,xmm2
addss xmm0,xmm3
// Now, to figure out this pulse's additional bonus damage, we subtract the pre-bonus damage (which includes pre-bonus amounts
// from previous pulses, as well the pre-bonus damage from this pulse) from the just calculated amount for this pulse.
movss xmm3,xmm0
subss xmm3,xmm4
jmp updateEnemyDamageStats
applyExistingBonus:
movss xmm4,xmm0
// Apply the bonus to the current pulse's damage.
movss xmm2,[newEnemyDamageEventBonusX]
mulss xmm0,xmm2
// We then figure out this pulse's additional bonus damage by subtracting the post-bonus damage from the pre-bonus damage.
movss xmm3,xmm0
subss xmm3,xmm4
updateEnemyDamageStats:
// At this point, the following registers hold the following values:
// xmm0: The current pulse's final damage amount (including any bonus damage amount).
// xmm1: The current pulse's target health value.
// xmm3: The current pulse's bonus damage amount.
// Sometimes the enemy health is hidden from the player by the game. Well I like
// flexing my muscle and displaying it anyway on stream with the
// "lastEnemyHealthValue" symbol. We perform a mock damage application here and
// store it there.
subss xmm1,xmm0
movss [lastEnemyHealthValue],xmm1
// We publish the current pulse's final and bonus damage amounts to their respective symbols.
movss [newEnemyDamagePulse],xmm0
movss [newEnemyDamagePulseBonusAmount],xmm3
// Add the final damage amount from this pulse to the running total damage associated with the event.
movss xmm2,[newEnemyDamageEvent]
addss xmm2,xmm0
movss [newEnemyDamageEvent],xmm2
// Add the bonus damage amount from this pulse to the running total bonus damage associated with this event.
movss xmm4,[newEnemyDamageEventBonusAmount]
addss xmm4,xmm3
movss [newEnemyDamageEventBonusAmount],xmm4
// If the total damage amount associated with the event is less than or equal to the current max damage event
// amount, then we don't need to update the max damage event obviously!
ucomiss xmm2,[maxEnemyDamageEvent]
jna skipMaxEnemyDamageUpdate
movss [maxEnemyDamageEvent],xmm2
movss [maxEnemyDamageEventBonusAmount],xmm4
skipMaxEnemyDamageUpdate:
// Add the final damage amount from this pulse to the total damage done to enemies.
movss xmm1,xmm0
addss xmm1,[totalEnemyDamage]
movss [totalEnemyDamage],xmm1
// Add the bonus damage amount from this pulse to the total bonus damage done to enemies.
movss xmm1,xmm3
addss xmm1,[totalEnemyDamageBonusAmount]
movss [totalEnemyDamageBonusAmount],xmm1
exitEnemyApocalypse:
// We commit our final damage amount to eax.
movd eax,xmm0
// We commit our final target health value to ebx, which actually never changes.
// It is simply used to calculate what the health will be to display with the
// "lastEnemyHealthValue" stat, and also for purposes of polymorphism, in a
// manner of speaking.
movss xmm1,[rsp+58]
// Increment the number of enemy damage pulses that have occurred.
inc [enemyDamagePulses]
enemyApocalypseCleanup:
movd ebx,xmm1
movdqu xmm4,[rsp]
add rsp,10
movdqu xmm3,[rsp]
add rsp,10
movdqu xmm2,[rsp]
add rsp,10
movdqu xmm1,[rsp]
add rsp,10
movdqu xmm0,[rsp]
add rsp,10
// This function has 2 parameters, each require 8 bytes. 2x8 == 10 (hex).
ret 10
lastEnemyDamageEvent:
dd (float)0.0
lastEnemyDamageEventBonusX:
dd (float)0.0
lastEnemyDamageEventBonusAmount:
dd (float)0.0
newEnemyDamagePulse:
dd (float)0.0
newEnemyDamagePulseBonusAmount:
dd (float)0.0
enemyDamagePulses:
dd 0
newEnemyDamageEvent:
dd (float)0.0
newEnemyDamageEventHasBonus:
dd 0
newEnemyDamageEventBonusX:
dd (float)0.0
newEnemyDamageEventBonusAmount:
dd (float)0.0
newEnemyDamageEventNotProcessed:
dd 0
maxEnemyDamageEvent:
dd (float)0.0
maxEnemyDamageEventBonusAmount:
dd (float)0.0
totalEnemyDamage:
dd (float)0.0
totalEnemyDamageBonusAmount:
dd (float)0.0
logEnemyApocalypseGoku:
dd 0
gokuResult:
dd 0
gokuResultUpper:
dd #10000
gokuResultLower:
dd 0
gokuDamageX:
dd (float)10000.0
lastEnemyHealthValue:
dd 0
playerCritChanceResult:
dd 0
playerCritChanceResultUpper:
dd #200
playerCritChanceResultLower:
dd 0
playerCritDamageResult:
dd 0
playerCritDamageResultUpper:
dd #50
playerCritDamageResultLower:
dd #20
playerCritDamageDivisor:
dd (float)10.0
logEnemyApocalypseCrit:
dd 0
[DISABLE]
// Cleanup of global Apocalypse memory
dealloc(playerDamageX)
dealloc(playerGodMode)
unregistersymbol(playerDamageX)
unregistersymbol(playerGodMode)
// Cleanup of Player Apocalypse System Function
unregistersymbol(logPlayerApocalypse)
unregistersymbol(extraDamageSafetyThreshold)
unregistersymbol(teleported)
unregistersymbol(teleportedX)
unregistersymbol(teleportedY)
unregistersymbol(teleportedZ)
unregistersymbol(apocalypseDieRoll)
unregistersymbol(murderRoll)
unregistersymbol(fatalisResult)
unregistersymbol(fatalisResultUpper)
unregistersymbol(fatalisState)
unregistersymbol(fatalisBloodlustDamageX)
unregistersymbol(fatalisHealthLost)
unregistersymbol(fatalisDeaths)
unregistersymbol(fatalisMinutesAfflicted)
unregistersymbol(basePlayerDamageX)
unregistersymbol(lastXDisplacement)
unregistersymbol(lastYDisplacement)
unregistersymbol(lastZDisplacement)
unregistersymbol(lastVerticalDisplacement)
unregistersymbol(coordinatesAreDoubles)
unregistersymbol(negativeVerticalDisplacementEnabled)
unregistersymbol(teleportitisDisplacementX)
unregistersymbol(verticalTeleportitisDisplacementX)
unregistersymbol(orgasmHealthHealed)
unregistersymbol(extraDamageX)
unregistersymbol(murderDamageX)
unregistersymbol(maxDamageToPlayer)
unregistersymbol(lastDamageToPlayer)
unregistersymbol(totalDamageToPlayer)
unregistersymbol(executePlayerApocalypse)
unregistersymbol(disableTeleportitis)
unregistersymbol(disableMurder)
unregistersymbol(murderIsAfoot)
unregistersymbol(teleportitisCooldownMinutes)
unregistersymbol(apocalypseInCooldown)
unregistersymbol(apocalypseCooldownMilliseconds)
dealloc(apocalypseCooldownMilliseconds)
dealloc(apocalypseInCooldown)
dealloc(teleportitisCooldownMinutes)
dealloc(logPlayerApocalypse)
dealloc(teleported)