-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBVMPrivilegeGateTest.bb
More file actions
705 lines (620 loc) · 24.6 KB
/
BVMPrivilegeGateTest.bb
File metadata and controls
705 lines (620 loc) · 24.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
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
Strict
EnableGC
; Regression tests pinning the BVM privilege-gate contract for the
; "equivalent-effect bypass" cluster in ScriptingCommands.bb.
;
; Nineteen BVM functions had effects identical to already-gated
; peers but lacked the gate themselves, defeating the privilege model:
;
; Newly-gated function Bypass of Gate chosen
; -------------------------------------------------------------------
; BVM_CHANGEGOLD BVM_SETGOLD RequirePrivileged
; BVM_CHANGEMONEY BVM_SETMONEY RequirePrivileged
; BVM_GIVEXP BVM_SETACTORLEVEL RequirePrivileged
; BVM_GIVEKILLXP BVM_SETACTORLEVEL RequirePrivileged
; BVM_SETATTRIBUTE BVM_KILLACTOR RequirePrivileged
; BVM_CHANGEATTRIBUTE BVM_KILLACTOR RequirePrivileged
; BVM_SETMAXATTRIBUTE BVM_SETATTRIBUTE RequirePrivileged
; BVM_CHANGEMAXATTRIBUTE BVM_SETATTRIBUTE RequirePrivileged
; BVM_SETREPUTATION BVM_SETHOMEFACTION RequirePrivileged
; BVM_SETLEADER (pet recruitment) RequirePrivileged
; BVM_SETABILITYLEVEL BVM_SETATTRIBUTE RequirePrivileged
; BVM_SETITEMHEALTH (item brick) RequirePrivileged
; BVM_SETRESISTANCE BVM_SETFACTIONRATING RequirePrivileged
; BVM_SETACTORGENDER (cosmetic griefing) RequirePrivileged
; BVM_SETACTORBEARD (cosmetic griefing) RequirePrivileged
; BVM_SETACTORHAIR (cosmetic griefing) RequirePrivileged
; BVM_SETACTORFACE (cosmetic griefing) RequirePrivileged
; BVM_SETACTORCLOTHES (cosmetic griefing) RequirePrivileged
; BVM_REMOVEZONEINSTANCE (admin-only) RequirePrivileged
;
; Four sibling functions (SETACTORAISTATE / SETACTORTARGET / SETNAME /
; SETTAG) intentionally stay UNGATED -- shipped content scripts in
; data/Server Data/Scripts (AOE Damage Spell Template, /Assist chat
; command, marriage, Spawn_Test) call them from non-priv spawns and a
; full-priv gate would silently break them. Audit comments at each
; function record this and point at the follow-up.
;
; ScriptingCommands.bb can't be Included directly into a test build --
; it pulls in the entire actor / item / wire / scripting graph. Following
; the established ClampFloatTest.bb / ItemsTest.bb pattern, we replicate
; the gate semantics and the gate-relevant prologue of each function,
; then assert the gate behaviour.
;
; Replication shape: production has the helpers read SI fields via
; SI = Object.ScriptInstance(hSI); If SI = Null Then Return False
; If SI\Privileged <> 0 Then Return True
; We split SI's fields into individual globals (ScriptActive flag plus
; Privileged / AI / AIContext) so the test can configure script state
; without depending on the Object/Handle table or fighting GC over a
; transient ScriptInstance object. Gate decision logic is verbatim.
; A refactor that changes the gate decision must update both copies.
; --- Replicated gate state --------------------------------------------
; Production: Object.ScriptInstance(hSI). A truthy ScriptActive means
; "the lookup succeeded" -- i.e., there IS an executing script context.
; Setting ScriptActive=False reproduces "hSI is stale / freed".
Global ScriptActive = False
Global ScriptPrivileged = 0
Global ScriptAI = 0
Global ScriptAIContext = 0
Global ScriptName$ = "TestScript"
; Capture the last refusal so tests can assert the gate refusal path
; actually fired (not a silent no-op).
Global LastScriptLog$ = ""
Function BVM_ScriptLog(Message$)
LastScriptLog$ = Message$
End Function
; Production: Function BVM_RequirePrivileged%() at ScriptingCommands.bb:132
Function BVM_RequirePrivileged%()
If ScriptActive = False Then Return False
If ScriptPrivileged <> 0 Then Return True
BVM_ScriptLog("Privileged BVM call refused from non-privileged script: " + ScriptName)
Return False
End Function
; Production: Function BVM_RequireSelfOrPrivileged%(Param1%) at ScriptingCommands.bb:148
Function BVM_RequireSelfOrPrivileged%(Param1%)
If ScriptActive = False Then Return False
If ScriptPrivileged <> 0 Then Return True
If Param1% <> 0 And (Param1% = ScriptAI Or Param1% = ScriptAIContext) Then Return True
BVM_ScriptLog("BVM call refused: target is neither script's actor nor context (" + ScriptName + ")")
Return False
End Function
; --- Mock-mutation surface ---------------------------------------------
; Each newly-gated function in production performs a state mutation
; (gold transfer, attribute change, zone teardown, ...). Replicate just
; the gate prologue + a single observable side-effect for each, so the
; test asserts the gate actually short-circuits the function body.
Global MutationGold = 0
Global MutationMoney = 0
Global MutationXP = 0
Global MutationKillXP = 0
Global MutationSetAttr = 0
Global MutationChangeAttr = 0
Global MutationSetMaxAttr = 0
Global MutationChangeMaxAttr = 0
Global MutationSetReputation = 0
Global MutationSetLeader = 0
Global MutationSetAbilityLevel = 0
Global MutationSetItemHealth = 0
Global MutationSetResistance = 0
Global MutationSetActorAppearance = 0 ; shared counter for the 5 appearance setters
Global MutationSetActorGroup = 0
Global MutationRemoveZone = 0
Function MockBVM_CHANGEGOLD(Param1%, Param2%)
If Not BVM_RequirePrivileged() Then Return
MutationGold = MutationGold + Param2%
End Function
Function MockBVM_CHANGEMONEY(Param1%, Param2%)
If Not BVM_RequirePrivileged() Then Return
MutationMoney = MutationMoney + Param2%
End Function
Function MockBVM_GIVEXP(Param1%, Param2%, Param3%=0)
If Not BVM_RequirePrivileged() Then Return
MutationXP = MutationXP + Param2%
End Function
Function MockBVM_GIVEKILLXP(Param1%, Param2%)
If Not BVM_RequirePrivileged() Then Return
MutationKillXP = MutationKillXP + 1
End Function
Function MockBVM_SETATTRIBUTE(Param1%, Param2$, Param3%)
If Not BVM_RequirePrivileged() Then Return
MutationSetAttr = MutationSetAttr + Param3%
End Function
Function MockBVM_CHANGEATTRIBUTE(Param1%, Param2$, Param3%)
If Not BVM_RequirePrivileged() Then Return
MutationChangeAttr = MutationChangeAttr + Param3%
End Function
Function MockBVM_SETMAXATTRIBUTE(Param1%, Param2$, Param3%)
If Not BVM_RequirePrivileged() Then Return
MutationSetMaxAttr = MutationSetMaxAttr + Param3%
End Function
Function MockBVM_CHANGEMAXATTRIBUTE(Param1%, Param2$, Param3%)
If Not BVM_RequirePrivileged() Then Return
MutationChangeMaxAttr = MutationChangeMaxAttr + Param3%
End Function
Function MockBVM_SETREPUTATION(Param1%, Param2%)
If Not BVM_RequirePrivileged() Then Return
MutationSetReputation = MutationSetReputation + Param2%
End Function
Function MockBVM_SETLEADER(Param1%, Param2%)
If Not BVM_RequirePrivileged() Then Return
MutationSetLeader = MutationSetLeader + 1
End Function
Function MockBVM_SETABILITYLEVEL(Param1%, Param2$, Param3%)
If Not BVM_RequirePrivileged() Then Return
MutationSetAbilityLevel = MutationSetAbilityLevel + Param3%
End Function
Function MockBVM_SETITEMHEALTH(Param1%, Param2%)
If Not BVM_RequirePrivileged() Then Return
MutationSetItemHealth = MutationSetItemHealth + Param2%
End Function
Function MockBVM_SETRESISTANCE(Param1%, Param2$, Param3%)
If Not BVM_RequirePrivileged() Then Return
MutationSetResistance = MutationSetResistance + Param3%
End Function
; Shared appearance-setter mock -- threat model + gate shape are
; identical across GENDER / BEARD / HAIR / FACE / CLOTHES, so a single
; mock covers the contract. The production functions are 5 separate
; bodies (each writing a distinct field + broadcasting a distinct
; sub-code) and each gets its own gate; the test just proves the
; gate is wired.
Function MockBVM_SETACTORAPPEARANCE(Param1%, Param2%)
If Not BVM_RequirePrivileged() Then Return
MutationSetActorAppearance = MutationSetActorAppearance + 1
End Function
Function MockBVM_REMOVEZONEINSTANCE(Param1$, Instance%)
If Not BVM_RequirePrivileged() Then Return
MutationRemoveZone = MutationRemoveZone + 1
End Function
; SetActorGroup gate (PR #325). TeamID is the team / party / faction
; identifier consumed by chat routing and combat friendly-fire gating;
; flipping it via a clicker script lets a non-priv NPC reassign the
; clicker's team. Zero shipped content-script callers (verified via
; `grep -rni SetActorGroup data/`), so RequirePrivileged was clean to
; land without content rewrites. Same threat model + gate shape as the
; appearance cluster.
Function MockBVM_SETACTORGROUP(Param1%, Param2%)
If Not BVM_RequirePrivileged() Then Return
MutationSetActorGroup = MutationSetActorGroup + 1
End Function
; --- Test fixture helpers ----------------------------------------------
Function ResetMutationCounters()
MutationGold = 0
MutationMoney = 0
MutationXP = 0
MutationKillXP = 0
MutationSetAttr = 0
MutationChangeAttr = 0
MutationSetMaxAttr = 0
MutationChangeMaxAttr = 0
MutationSetReputation = 0
MutationSetLeader = 0
MutationSetAbilityLevel = 0
MutationSetItemHealth = 0
MutationSetResistance = 0
MutationSetActorAppearance = 0
MutationSetActorGroup = 0
MutationRemoveZone = 0
LastScriptLog$ = ""
End Function
Function InstallScript(Privileged%, AI%, AIContext%)
ScriptActive = True
ScriptPrivileged = Privileged
ScriptAI = AI
ScriptAIContext = AIContext
End Function
Function ClearScript()
ScriptActive = False
ScriptPrivileged = 0
ScriptAI = 0
ScriptAIContext = 0
End Function
; ======================================================================
; Gate helper contract -- a non-priv script returns False; the refusal
; goes through BVM_ScriptLog so server operators have an audit trail.
; ======================================================================
Test testRequirePrivilegedAllowsPrivilegedScript()
InstallScript(1, 0, 0)
Assert(BVM_RequirePrivileged() = True)
End Test
Test testRequirePrivilegedRefusesNonPrivilegedScript()
InstallScript(0, 0, 0)
LastScriptLog$ = ""
Assert(BVM_RequirePrivileged() = False)
; Refusal must be audit-logged, not silently dropped.
Assert(Len(LastScriptLog$) > 0)
End Test
Test testRequirePrivilegedFailsClosedOnMissingScript()
; A stale/invalid script context must not be treated as privileged.
; Closed-by-default is the entire point of the gate.
ClearScript()
Assert(BVM_RequirePrivileged() = False)
End Test
Test testRequireSelfOrPrivilegedAllowsPrivilegedScript()
InstallScript(1, 0, 0)
Assert(BVM_RequireSelfOrPrivileged(12345) = True)
End Test
Test testRequireSelfOrPrivilegedAllowsOwnAI()
InstallScript(0, 777, 0)
Assert(BVM_RequireSelfOrPrivileged(777) = True)
End Test
Test testRequireSelfOrPrivilegedAllowsOwnContext()
InstallScript(0, 0, 888)
Assert(BVM_RequireSelfOrPrivileged(888) = True)
End Test
Test testRequireSelfOrPrivilegedRefusesArbitraryTarget()
InstallScript(0, 100, 200)
LastScriptLog$ = ""
Assert(BVM_RequireSelfOrPrivileged(999) = False)
Assert(Len(LastScriptLog$) > 0)
End Test
Test testRequireSelfOrPrivilegedRejectsZeroTarget()
; Param1 = 0 must not match SI\AI = 0 or SI\AIContext = 0 -- otherwise
; a freshly-created script (both fields default 0) would be allowed
; to target "actor 0" from any non-priv context.
InstallScript(0, 0, 0)
Assert(BVM_RequireSelfOrPrivileged(0) = False)
End Test
Test testRequireSelfOrPrivilegedFailsClosedOnMissingScript()
ClearScript()
Assert(BVM_RequireSelfOrPrivileged(0) = False)
Assert(BVM_RequireSelfOrPrivileged(123) = False)
End Test
; ======================================================================
; Per-function gate enforcement -- the seven newly-gated functions must
; short-circuit when the calling script is non-privileged.
; ======================================================================
Test testChangeGoldGateBlocksNonPrivileged()
InstallScript(0, 0, 0)
ResetMutationCounters()
MockBVM_CHANGEGOLD(0, 1000000)
; State unchanged: the gate ran *before* the gold mutation.
Assert(MutationGold = 0)
End Test
Test testChangeGoldGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_CHANGEGOLD(0, 1000000)
Assert(MutationGold = 1000000)
End Test
Test testChangeMoneyGateBlocksNonPrivileged()
InstallScript(0, 0, 0)
ResetMutationCounters()
MockBVM_CHANGEMONEY(0, -500000)
Assert(MutationMoney = 0)
End Test
Test testChangeMoneyGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_CHANGEMONEY(0, -500000)
Assert(MutationMoney = -500000)
End Test
Test testGiveXPGateBlocksNonPrivileged()
InstallScript(0, 0, 0)
ResetMutationCounters()
MockBVM_GIVEXP(0, 999999999)
Assert(MutationXP = 0)
End Test
Test testGiveXPGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_GIVEXP(0, 100)
Assert(MutationXP = 100)
End Test
Test testGiveKillXPGateBlocksNonPrivileged()
InstallScript(0, 0, 0)
ResetMutationCounters()
MockBVM_GIVEKILLXP(0, 0)
Assert(MutationKillXP = 0)
End Test
Test testGiveKillXPGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_GIVEKILLXP(0, 0)
Assert(MutationKillXP = 1)
End Test
Test testSetAttributeGateBlocksArbitraryTarget()
InstallScript(0, 100, 0)
ResetMutationCounters()
MockBVM_SETATTRIBUTE(999, "Health", 0)
Assert(MutationSetAttr = 0)
End Test
; THE EXPLOIT this gate exists to block. For Examine/Trade/RightClick/
; ItemScript spawns, ThreadScript("...", "Examine", Handle(clicker),
; Handle(NPC)) makes `SI\AI = Handle(clicker)`. A self-or-priv gate on
; Param1=clicker_handle would match SI\AI and let SetAttribute(clicker,
; "Health", 0) reach KillActor(...) on the clicker. The full-priv gate
; refuses regardless of how the target handle relates to SI\AI.
Test testSetAttributeGateBlocksKillingOwnAITarget()
; Non-priv clicker-driven script: SI\AI = clicker handle (777 here).
; The exploit call passes Param1 = 777 == SI\AI, which would defeat
; a self-or-priv gate. The full-priv gate must still refuse.
InstallScript(0, 777, 200)
ResetMutationCounters()
MockBVM_SETATTRIBUTE(777, "Health", 0)
Assert(MutationSetAttr = 0)
End Test
Test testSetAttributeGateBlocksKillingOwnContextTarget()
; Same exploit, but a script spawn shape where the lethal target
; happens to be SI\AIContext. The gate must still refuse.
InstallScript(0, 100, 500)
ResetMutationCounters()
MockBVM_SETATTRIBUTE(500, "Health", 0)
Assert(MutationSetAttr = 0)
End Test
Test testSetAttributeGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_SETATTRIBUTE(999, "Health", 42)
Assert(MutationSetAttr = 42)
End Test
Test testChangeAttributeGateBlocksArbitraryTarget()
; Same exploit shape via ChangeAttribute(target, "Health", -big%).
InstallScript(0, 100, 0)
ResetMutationCounters()
MockBVM_CHANGEATTRIBUTE(999, "Health", -1000000)
Assert(MutationChangeAttr = 0)
End Test
Test testChangeAttributeGateBlocksKillingOwnAITarget()
; Mirror of the SetAttribute clicker-bypass test on the Change path.
InstallScript(0, 777, 200)
ResetMutationCounters()
MockBVM_CHANGEATTRIBUTE(777, "Health", -1000000)
Assert(MutationChangeAttr = 0)
End Test
Test testChangeAttributeGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_CHANGEATTRIBUTE(999, "Health", -7)
Assert(MutationChangeAttr = -7)
End Test
; ======================================================================
; SetMaxAttribute / ChangeMaxAttribute sibling-asymmetry gates.
;
; The SET/CHANGE pair above is gated because their HealthStat branch
; falls through to KillActor(...) -- a clicker one-shot kill exploit.
; The SET/CHANGE-MAX pair sits next door and was left ungated, but it's
; still a brick vector:
;
; SetMaxAttribute(player, "Health", 1) -> max HP = 1 forever, next
; damage tick kills them
; SetMaxAttribute(player, "Speed", 0) -> player can't move
; SetMaxAttribute(player, "Energy", 0) -> player can't cast spells
;
; Same clicker-bypass mechanics as SET/CHANGE: ThreadScript spawn for
; Examine/Trade/RightClick/ItemScript makes SI\AI = Handle(clicker), so
; the gate has to be RequirePrivileged (not SelfOrPrivileged).
; ======================================================================
Test testSetMaxAttributeGateBlocksArbitraryTarget()
InstallScript(0, 100, 0)
ResetMutationCounters()
MockBVM_SETMAXATTRIBUTE(999, "Health", 1)
Assert(MutationSetMaxAttr = 0)
End Test
Test testSetMaxAttributeGateBlocksBrickingOwnAITarget()
; The SI\AI = clicker shape -- a self-or-priv gate would incorrectly
; match Param1 = 777 against SI\AI = 777 and let the brick through.
; Full-priv must refuse.
InstallScript(0, 777, 200)
ResetMutationCounters()
MockBVM_SETMAXATTRIBUTE(777, "Health", 1)
Assert(MutationSetMaxAttr = 0)
End Test
Test testSetMaxAttributeGateBlocksBrickingOwnContextTarget()
InstallScript(0, 100, 500)
ResetMutationCounters()
MockBVM_SETMAXATTRIBUTE(500, "Speed", 0)
Assert(MutationSetMaxAttr = 0)
End Test
Test testSetMaxAttributeGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_SETMAXATTRIBUTE(999, "Health", 200)
Assert(MutationSetMaxAttr = 200)
End Test
Test testChangeMaxAttributeGateBlocksArbitraryTarget()
; ChangeMaxAttribute(target, "Health", -big%) drives Maximum[Health]
; toward zero -- same brick vector via the relative-mutation path.
InstallScript(0, 100, 0)
ResetMutationCounters()
MockBVM_CHANGEMAXATTRIBUTE(999, "Health", -1000000)
Assert(MutationChangeMaxAttr = 0)
End Test
Test testChangeMaxAttributeGateBlocksBrickingOwnAITarget()
InstallScript(0, 777, 200)
ResetMutationCounters()
MockBVM_CHANGEMAXATTRIBUTE(777, "Health", -1000000)
Assert(MutationChangeMaxAttr = 0)
End Test
Test testChangeMaxAttributeGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_CHANGEMAXATTRIBUTE(999, "Health", 50)
Assert(MutationChangeMaxAttr = 50)
End Test
; ======================================================================
; Faction / leader / ability / item-health -- the next slice of the
; brick-vector sweep flagged by PR #300's reviewer. Each one is a
; non-priv-script-reachable mutation that bricks gameplay state.
; ======================================================================
; SetReputation -- faction-interaction key. Brick: SetReputation(clicker,
; -10000) locks the player out of every reputation-gated vendor / quest
; / zone.
Test testSetReputationGateBlocksArbitraryTarget()
InstallScript(0, 100, 0)
ResetMutationCounters()
MockBVM_SETREPUTATION(999, -10000)
Assert(MutationSetReputation = 0)
End Test
Test testSetReputationGateBlocksBrickingOwnAITarget()
; The exact clicker shape: SI\AI = clicker, Param1 = clicker.
; Full-priv must refuse where self-or-priv would not.
InstallScript(0, 777, 200)
ResetMutationCounters()
MockBVM_SETREPUTATION(777, -10000)
Assert(MutationSetReputation = 0)
End Test
Test testSetReputationGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_SETREPUTATION(999, 50)
Assert(MutationSetReputation = 50)
End Test
; SetLeader -- pet recruitment. Brick: SetLeader(SomeWorldGuard,
; clicker) recruits world NPCs as private pets. Production function
; restricts Param1 to NPCs (Actor\RNID = -1), so the player-as-pet
; shape is impossible, but the world-NPC-as-pet shape is the gap.
Test testSetLeaderGateBlocksNonPrivileged()
InstallScript(0, 100, 0)
ResetMutationCounters()
MockBVM_SETLEADER(999, 777)
Assert(MutationSetLeader = 0)
End Test
Test testSetLeaderGateBlocksOwnAILeader()
; Clicker-shape: SI\AI = clicker handle (777), Param2 = clicker
; (the would-be new leader). Full-priv refuses.
InstallScript(0, 777, 200)
ResetMutationCounters()
MockBVM_SETLEADER(999, 777)
Assert(MutationSetLeader = 0)
End Test
Test testSetLeaderGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_SETLEADER(999, 777)
Assert(MutationSetLeader = 1)
End Test
; SetAbilityLevel -- combat ability scaling. Brick: SetAbilityLevel(
; clicker, "<spell>", 0) zeros out the chosen ability; iteration over
; the spell list bricks the player's entire combat toolkit.
Test testSetAbilityLevelGateBlocksArbitraryTarget()
InstallScript(0, 100, 0)
ResetMutationCounters()
MockBVM_SETABILITYLEVEL(999, "Fireball", 0)
Assert(MutationSetAbilityLevel = 0)
End Test
Test testSetAbilityLevelGateBlocksBrickingOwnAITarget()
InstallScript(0, 777, 200)
ResetMutationCounters()
MockBVM_SETABILITYLEVEL(777, "Fireball", 0)
Assert(MutationSetAbilityLevel = 0)
End Test
Test testSetAbilityLevelGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_SETABILITYLEVEL(999, "Fireball", 5)
Assert(MutationSetAbilityLevel = 5)
End Test
; SetItemHealth -- durability. Brick: iterate clicker's
; Inventory\Items[] and zero each ItemHealth, gutting all gear in one
; click. Param1 is an ItemInstance handle (not an ActorInstance), so
; the self-or-priv shortcut doesn't apply -- there is no SI\AI for an
; item. RequirePrivileged is the only sensible gate; tests just cover
; the priv vs. non-priv contract.
Test testSetItemHealthGateBlocksNonPrivileged()
InstallScript(0, 0, 0)
ResetMutationCounters()
MockBVM_SETITEMHEALTH(12345, 0)
Assert(MutationSetItemHealth = 0)
End Test
Test testSetItemHealthGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_SETITEMHEALTH(12345, 100)
Assert(MutationSetItemHealth = 100)
End Test
; SetResistance -- damage-type resistance; consumed by the combat
; damage formula the same way FactionRatings[] is. Brick path is
; symmetric to SETFACTIONRATING (already gated): negative value =
; catastrophic damage taken; >100 value = invulnerable in PvE.
Test testSetResistanceGateBlocksArbitraryTarget()
InstallScript(0, 100, 0)
ResetMutationCounters()
MockBVM_SETRESISTANCE(999, "Fire", -100)
Assert(MutationSetResistance = 0)
End Test
Test testSetResistanceGateBlocksBrickingOwnAITarget()
; Clicker-shape: SI\AI = clicker (777), Param1 = clicker.
InstallScript(0, 777, 200)
ResetMutationCounters()
MockBVM_SETRESISTANCE(777, "Fire", -100)
Assert(MutationSetResistance = 0)
End Test
Test testSetResistanceGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_SETRESISTANCE(999, "Fire", 50)
Assert(MutationSetResistance = 50)
End Test
; ======================================================================
; Appearance-cluster cosmetic-griefing gates. The 5 production
; functions (SETACTORGENDER / BEARD / HAIR / FACE / CLOTHES) all use
; the same gate shape (full-priv). The SETACTORAISTATE / SETACTORTARGET
; / SETNAME / SETTAG functions are intentionally UNGATED -- see test
; file header for the content-script-callers explanation.
;
; Shared mock covers the contract; each production gate is verified by
; inspection (audit-comment template is identical).
; ======================================================================
Test testSetActorAppearanceGateBlocksArbitrary()
InstallScript(0, 100, 0)
ResetMutationCounters()
MockBVM_SETACTORAPPEARANCE(999, 2)
Assert(MutationSetActorAppearance = 0)
End Test
Test testSetActorAppearanceGateBlocksOwnAITarget()
; Clicker self-grief shape: SI\AI = clicker, Param1 = clicker.
InstallScript(0, 777, 200)
ResetMutationCounters()
MockBVM_SETACTORAPPEARANCE(777, 2)
Assert(MutationSetActorAppearance = 0)
End Test
Test testSetActorAppearanceGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_SETACTORAPPEARANCE(999, 3)
Assert(MutationSetActorAppearance = 1)
End Test
Test testRemoveZoneInstanceGateBlocksNonPrivileged()
InstallScript(0, 0, 0)
ResetMutationCounters()
MockBVM_REMOVEZONEINSTANCE("MainZone", 5)
Assert(MutationRemoveZone = 0)
End Test
Test testRemoveZoneInstanceGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_REMOVEZONEINSTANCE("MainZone", 5)
Assert(MutationRemoveZone = 1)
End Test
; ======================================================================
; SetActorGroup gate (PR #325). TeamID drives chat-routing (/g guild
; chat keys on `A2\TeamID = AI\TeamID`) and friendly-fire / aggression
; gating. Flipping TeamID via a non-priv clicker script lets an NPC
; reassign the clicker's team -- griefing + chat-exfiltration vector.
; Zero shipped content-script callers (verified at recon time), so
; RequirePrivileged was clean to land. Sibling-asymmetry with the 12
; already-gated mutators in this file.
; ======================================================================
Test testSetActorGroupGateBlocksNonPrivileged()
InstallScript(0, 0, 0)
ResetMutationCounters()
MockBVM_SETACTORGROUP(999, 5)
Assert(MutationSetActorGroup = 0)
End Test
Test testSetActorGroupGateBlocksOwnAITarget()
; The clicker shape: Examine/Trade/RightClick/ItemScript spawn
; sets SI\AI = Handle(clicker). A self-or-priv gate would
; incorrectly let Param1 = clicker_handle through; this test
; confirms full RequirePrivileged blocks even that case.
InstallScript(0, 777, 0)
ResetMutationCounters()
MockBVM_SETACTORGROUP(777, 5)
Assert(MutationSetActorGroup = 0)
End Test
Test testSetActorGroupGatePassesForPrivileged()
InstallScript(1, 0, 0)
ResetMutationCounters()
MockBVM_SETACTORGROUP(999, 5)
Assert(MutationSetActorGroup = 1)
End Test