-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScriptMod.bas
More file actions
2365 lines (2306 loc) · 80.3 KB
/
ScriptMod.bas
File metadata and controls
2365 lines (2306 loc) · 80.3 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
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
Attribute VB_Name = "ScriptMod"
'ScriptEvent Numbers
'-----------------------------------------------------------
'Num Event Source Target Arg
'1/2 NewMessage N/A N/A [Message]
'1=Before message displayed, 2=After.
'
'3/4 PlayerSignOn [PNum] N/A N/A
'3=Before Sign On message is sent, 4=After.
'
'5/6 PlayerSignOff [PNum] N/A N/A
'5=Before Sign Off message is sent, 6=After.
'
'7/8 BattleOver [Winner] [Loser] {"WIN"|"TIE"}
'7=Before Battle results are sent, 8=After
'
'9/10 BattleBegin [Challenger] [Challengee] N/A
'9=Before battle starts, 10=after.
'
'11/12 ChatMessage [Sender] N/A [Message]
'11=Before message is sent, 12=After.
'
'13/14 PlayerAway [PNum] N/A N/A
'13=Before player goes Away, 14=After.
'
'15/16 PlayerKick [Kicker] [KickedPNum] N/A
'15=Before Kick occurs, 16=After.
'
'17/18 PlayerBan [Banner] [BannedPNum] N/A
'17=Before Ban occurs, 18=After.
'
'19/20 TeamChange [PNum] N/A N/A
'19=Before Team change is sent to other users, 20=After
'
'21/22 ChallengeIssued [Challenger] [Challengee] N/A
'21=Before challenge is sent, 22=After
'
'23 ServerStartup N/A N/A N/A
'24+ Timer N/A N/A N/A
'
'Variable Symbols
'------------------------------------------------------------
'$ - Text
'# - Number
'@ - Keyword
'! - Varient
'
'Special Commands
'------------------------------------------------------------
'Marker #Num
'^^^Marks the spot for a GoTo statement. #Num must be an
' actual value, not a variable.
'
'GoTo #MarkerNum
'^^^Starts execution directly after the specified Marker.
' #MarkerNum may be a variable.
'
'If [Condition]
' [Statements1]
'Else
' [Statements2]
'End If
'^^^Checks the [Condition] for validity. If it is determined
' true, [Statements1] executes. If false, then [Statements2]
' executs. If Else and [Statements2] are omitted and
' [Condition] is false, excution jumps to the line after the
' EndIf statement.
'
'Conditional Symbols
'-------------------------------------------------------------
' = Equal to.
' == Equal to. (Case Sensitive when dealing with Text)
' <> Not equal to.
' > Greater than.
' < Less than.
' >= Greater than or equal to.
' <= Less than or equal to.
'
'Condition Operators
'------------------------------------------------------------
' AND Returns True if both conditions are True
' OR Returns True if either of the conditions are True
' XOR Returns True if only one of the conditions is True
' EQV Returns True if both conditions are True or False
'
'Regular Functions
'------------------------------------------------------------
'#HasPoke(#PNum, #PokeNum)
'^^^Returns 1 if Player PNum has the Pokemon with
' the No. PokeNum in his/her team. Returns 0
' otherwise.
'
'#HasPokeMove(#PNum, #PokeNum, #MoveNum)
'^^^Returns 1 if Player PNum has the Pokemon with
' the No. PokeNum and having the move MoveNum in
' his/her team. Returns 0 otherwise.
'
'#GetPlayerInfo(#PNum, @Info)
'^^^Returns the specified Player's information
' depending on the value of @Info. (Number
' only) See below for valid values.
'
'$GetPlayerInfo(#PNum, @Info)
'^^^Returns the specified Player's information
' depending on the value of @Info. (Text
' only) See below for valid values.
'
'#LineNum
'^^^Returns the number of lines of text in the
' main message box.
'
'#TrainersNum
'^^^Returns the number of connected Players
'
'#SysTimer
'^^^Returns the number of seconds past midnight.
'
'$Time
'^^^Returns the current time in the form: HH:MM:SS AM/PM
'
'$Date
'^^^Returns the current date in the form: MM/DD/YY
'
'$WeekDay
'^^^Returns a string containing the current day of the week.
'
'$Month
'^^^Returns a string containing the current month.
'
'#PNumber($PName)
'^^^Returns the number of the player matching then
' name $PName
'
'#Math($MathString)
'^^^Returns the answer to the mathmatical string
' contained in $MathString
'
'#Rand(#UpperLimit, #LowerLimit)
'^^^Returns a random long between #LowerLimit
' and #UpperLimit, inclusive. If #LowerLimit
' is omitted, 0 is assumed.
'
'#RandPlayer
'^^^Returns a random player number. Returns 0 if
' no players are connected.
'
'#GetValue($Key)
'^^^Retrieves a number from the Windows Registry.
' An error occurs if the value is not a number.
'
'$GetValue($Key)
'^^^Retrieves a number from the Windows Registry.
' If the value is a number, it is coverted to
' text.
'
'$Msg(#Index)
'^^^Returns a Predefined Message, set in the Script
' Window on the Messages tab.
'
'Settable Functions
'-------------------------------------------------
'#MaxUsers
'^^^Returns/Sets the maximum number of players.
'
'#FloodTol
'^^^Returns/Sets the server's flood tolerance.
'
'$WelcomeMsg
'^^^Returns/Sets the server's welcome message.
'
'String Manipulation Functions:
'-------------------------------------------------
'$Left($Text, #Number)
'^^^Returns the specified number of characters from
' the left of the text.
'
'$Right($Text, #Number)
'^^^Returns the specified number of characters from
' the right of the text.
'
'$Mid($Text, #Start, #Length)
'^^^Returns a portion of the text $Text starting
' at the character specified in #Start as long
' as #Length characters.
'
'
'#IsIn($Text, $Check, #Case)
'^^^Checks if $Check is located anywhere in $Text.
' If so, returns the number of characters into
' $Text that $Check is found. If not, returns 0.
' #Case specifies whether or not the check is
' case sensitive. 0=Not CS, 1=CS. If omitted,
' Not CS is assumed.
'
'#Len($Text)
'^^^Returns the number of characters in the text.
'
'$Replace $SourceText, $Find, $Replace
'^^^Searchs for the text $Find in $SourceText and
' replaces it with $Replace. Returns the result.
'
'$LCase($Text)
'^^^Puts all the letters in $Text in lower case.
'
'$UCase($Text)
'^^^Puts all the letters in $Text in upper case.
'
'$Chr(#Code)
'^^^Returns the character specified by the ASCII
' code #Code. Valid value for #Code are 0 to
' 255. NOTE: $Chr(1) is reserved for system
' use. If you try to use it, it will be
' replaced with $Chr(2). Both are meaningless
' characters.
'
'#Asc($Character)
'^^^Returns the ASCII code for the character. If
' the length of $Character is more than 1, the
' first character is used.
'
'$Str(#Number)
'^^^Returns the specified number in text format.
'
'#Val($Text)
'^^^Returns the numbers in a text statement in
' number format.
'
'Subroutines:
'-------------------------------------------------
'/? !val
'^^^Show the value of !val in the messages box.
'
'/Set !var, !val
'^^^Set the value of variable !var to !val. If the
' variable does not exist, it is created. If !val
' is omitted, 0 or "" is assumed, depending on the
' variable type.
'
'/Unset !var
'^^^Destroys the variable !var.
'
'/Inc #var, #num
'^^^Increments the value of #var by #num. If #num
' is omitted, 1 is assumed. To decrease a number,
' use a negitive value for #num.
'
'/Clear
'^^^Clears the main messages box
'
'/SendPM #PNum, $Message
'^^^Sends a message to only the player #PNum.
'
'/SendAll $Message
'^^^Sends a message to all connected players.
'
'/Kick #PNum
'^^^Disconnects player #PNum.
'
'/Ban #PNum
'^^^Disconnects player #PNum and adds his/her IP to
' the banned IP list.
'
'/SIDBan #PNum
'^^^Disconnects player #PNum and adds his/her SID to
' the banned SID list.
'
'/StopEvent
'^^^Stops the current event from taking place. Only
' valid in certain BE event scripts.
'
'/Run $Path
'^^^Runs a the program located at $Path
'
'/SaveVal $Key, !Val
'^^^Saves a value to the Windows Registry. Advanced
' users can use this to extend the script's power.
' Keys are saved to the Visual Basic SaveSetting
' directory under /NetBattle/Script Values/[$Key]
'
'/SetPlayerInfo #PNum, @Info, !NewVal
'^^^Sets the specified player's infomation as !NewVal.
' Only certain values can be set. See below for
' valid @Info values.
'
'Values for Get/SetPlayerValue's @Info
'------------------------------------------------------
'Value Type Notes
'NAME $ Name.
'IPAD $ IP Address. Cannot be Set.
'PSID $ SID. Cannot be Set.
'DNSA $ DNS Address. Cannot be Set.
'EXTR $ Extra information.
'VERS $ NetBattle Version number. Cannot be Set.
'AUTH # Authority. 0=Player, 1=Mod, 2=Admin
'BWTH # Battling With (Player Number) Cannot be Set.
'SPED # Connection speed. Cannot be Set.
'HIDE # 0=Team Hidden, 1=Team Shown
'WINS # Wins. Cannot be Set.
'LOSE # Loses. Cannot be Set.
'TIES # Ties. Cannot be Set.
'DISC # Disconnects. Cannot be Set.
'
'
'Scripting Module v1.0
'by MasamuneXGP
'
'The scripting module consists of five major functions:
'1. Script Translator (ReRead), 2. Statement Execution (Exec),
'3. Function Evaluation (Eval), 4. Condition Evaluation (IfEval),
'and 5. Block Execution (BlockExec).
'As well as one minor function, Event Initializing (ScriptEvent).
Option Explicit
Option Compare Text
Public Type CallType
EventNum As Long
Source As Long
Target As Long
Arg As String
End Type
Private Type LineType
Text As String
LineNum As Long
End Type
Public Type MarkerType
mName As String
mLine As Long
End Type
Public Type EventType
sLine() As LineType
Marker() As MarkerType
Counter As Long
Trigger As Long
End Type
Public Type VarType1
vName As String
Value As Single
End Type
Public Type VarType2
vName As String
Value As String
End Type
Public Type VarType3
vName As String
Value() As Single
End Type
Public Type VarType4
vName As String
Value() As String
End Type
Global Const TimerLimit As Long = 24
Global MainScript As String
Global ProcessScript As Boolean
Global sSource As Long
Global sTarget As Long
Global sArg As String
Global PDM() As String
Global AppPath As String
Global VarChange As Boolean
Global NumVar() As VarType1
Global TxtVar() As VarType2
Global PANum() As VarType3
Global PATxt() As VarType4
Global sEvent() As EventType
Global BlankSource As CallType
Private Type DLLArgType
Type As Long
Value As Long
End Type
Private Type DLLType
Name As String
hLib As Long
Addr As Long
End Type
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private LoadedDLLs() As DLLType
Private PtrCaller As INBScript
Private Delegator As FunctionDelegator
Public DLLReturnVal As String
'Private Declare Sub event_function Lib "Script.dll" ( _
ByVal EventNum As Long, _
ByRef CancelByte As Byte, _
ByVal Source As Long, _
ByVal Target As Long, _
ByVal Arg As String)
'Private Declare Function set_callback Lib "Script.dll" ( _
ByVal Address As Long) As Long
'void event_function (int EVENTNUM, char * Cancel, int Source, int Target, char * Arg)
'***************************************************************'
'-------------BEGIN MAJOR #1: SCRIPT TRANSLATION----------------'
'***************************************************************'
'This function reads the script and puts the lines into
'variables ready for processing. It returns an error
'description, if there is one.
Public Function Reread(Script As String) As String
Const FATAL As String = "FATAL SCRIPT ERROR IN LINE #"
Dim Xs As Single
Dim W As Long
Dim X As Long
Dim Y As Long
Dim Z As Long
Dim E As String
Dim EventNum As Long
Dim iLine() As String
Dim cLine As String
Dim Temp As String
Dim IfNest() As Long
ProcessScript = False
On Error GoTo ErrorTrap
ReDim sEvent(TimerLimit - 1)
For X = 1 To TimerLimit - 1
ReDim sEvent(X).sLine(0)
ReDim sEvent(X).Marker(0)
Next X
ReDim IfNest(0)
ReDim sTimer(0)
iLine() = Split(Script, vbNewLine)
If UBound(iLine) = -1 Then Exit Function
For X = 1 To UBound(iLine) + 1
iLine(X - 1) = LineCheck(Trim(iLine(X - 1)), E)
If E <> "" Then GoTo NotMyFault
cLine = iLine(X - 1)
If Left(cLine, 6) = "Event " Then
If EventNum <> 0 Then GoTo MissingEndEvent
Temp = Trim(Right(cLine, Len(cLine) - 6))
Y = 0
Z = 0
If Left(Temp, 1) = "-" Then
Y = 1
Z = 1
ElseIf Left(Temp, 1) = "+" Then
Z = 1
End If
EventNum = GetEventNum(Right(Temp, Len(Temp) - Z))
If EventNum = TimerLimit Then
Xs = CSng(Right(Temp, Len(Temp) - 6))
If Xs <> Int(Xs) Then GoTo BadTimerVal
Z = CInt(Xs)
If Z < 1 Or Z > 86400 Then GoTo BadTimerVal2
For Y = TimerLimit To UBound(sEvent)
If sEvent(Y).Trigger = Z Then GoTo RedundantEvent
Next Y
ReDim Preserve sEvent(Y)
ReDim sEvent(Y).sLine(0)
ReDim sEvent(Y).Marker(0)
sEvent(Y).Trigger = Z
sEvent(Y).Counter = 0
EventNum = Y
Else
EventNum = EventNum - Y
If EventNum < 1 Then GoTo UnknownEvent
If UBound(sEvent(EventNum).sLine) <> 0 Then GoTo RedundantEvent
End If
ElseIf cLine = "EndEvent" Then
If EventNum = 0 Then GoTo MisplacedEE
If UBound(IfNest) <> 0 Then GoTo IfWithout
EventNum = 0
ElseIf Left(cLine, 1) = ":" Then
If EventNum = 0 Then GoTo ComOutside
Temp = Right(cLine, Len(cLine) - 1)
If Not IsAlpha(Temp) Then GoTo BadMarkerVal
If GetMarkerNum(EventNum, Temp) <> 0 Then GoTo RedundantMarker
Z = UBound(sEvent(EventNum).Marker) + 1
ReDim Preserve sEvent(EventNum).Marker(Z)
sEvent(EventNum).Marker(Z).mName = Temp
sEvent(EventNum).Marker(Z).mLine = UBound(sEvent(EventNum).sLine)
ElseIf Left(cLine, 3) = "If " Then
If EventNum = 0 Then GoTo ComOutside
Y = UBound(sEvent(EventNum).sLine) + 1
ReDim Preserve sEvent(EventNum).sLine(Y)
sEvent(EventNum).sLine(Y).Text = cLine
sEvent(EventNum).sLine(Y).LineNum = X
Z = UBound(IfNest) + 1
ReDim Preserve IfNest(Z)
IfNest(Z) = Y
ElseIf cLine = "Else" Then
If EventNum = 0 Then GoTo ComOutside
If UBound(IfNest) = 0 Then GoTo ElseWithout
Y = UBound(IfNest)
Z = UBound(sEvent(EventNum).sLine) + 1
sEvent(EventNum).sLine(IfNest(Y)).Text = sEvent(EventNum).sLine(IfNest(Y)).Text & "|" & CStr(Z)
IfNest(Y) = Z
ReDim Preserve sEvent(EventNum).sLine(Z)
sEvent(EventNum).sLine(Z).Text = "Else"
sEvent(EventNum).sLine(Z).LineNum = X
ElseIf cLine = "EndIf" Then
If EventNum = 0 Then GoTo ComOutside
If UBound(IfNest) = 0 Then GoTo EndIfWithout
Y = UBound(IfNest)
Z = UBound(sEvent(EventNum).sLine)
sEvent(EventNum).sLine(IfNest(Y)).Text = sEvent(EventNum).sLine(IfNest(Y)).Text & "|" & CStr(Z)
ReDim Preserve IfNest(Y - 1)
ElseIf Left(cLine, 2) = "//" Or cLine = "" Then 'do nothing
Else
If EventNum = 0 Then GoTo ComOutside
Y = UBound(sEvent(EventNum).sLine) + 1
ReDim Preserve sEvent(EventNum).sLine(Y)
sEvent(EventNum).sLine(Y).Text = cLine
sEvent(EventNum).sLine(Y).LineNum = X
End If
Next X
If EventNum <> 0 Then GoTo MissingEndEvent
ProcessScript = True
Reread = "Script Check: OK!"
Exit Function
'--------------Errors---------------
ErrorTrap:
Reread = FATAL & X & ": RTE " & Err.Number & ": " & Err.Description & "."
Exit Function
NotMyFault:
Reread = FATAL & X & ": " & E
Exit Function
MissingEndEvent:
Reread = FATAL & X & ": Missing EndEvent."
Exit Function
UnknownEvent:
Reread = FATAL & X & ": Unknown Event."
Exit Function
RedundantEvent:
Reread = FATAL & X & ": Redundant Event."
Exit Function
BadTimerVal:
Reread = FATAL & X & ": Timer Interval Must Be long."
Exit Function
BadTimerVal2:
Reread = FATAL & X & ": Timer Interval Out of Bounds."
Exit Function
MisplacedEE:
Reread = FATAL & X & ": Misplaced EndEvent."
Exit Function
ComOutside:
Reread = FATAL & X & ": Statement Outside Event."
Exit Function
BadMarkerVal:
Reread = FATAL & X & ": Marker Name Must Consist of Letters Only."
Exit Function
RedundantMarker:
Reread = FATAL & X & ": Redundant Marker."
Exit Function
MissingEndIf:
Reread = FATAL & X & ": Missing EndIf."
Exit Function
IfWithout:
Reread = FATAL & X & ": If Without EndIf."
Exit Function
ElseWithout:
Reread = FATAL & X & ": Else Without If."
Exit Function
EndIfWithout:
Reread = FATAL & X & ": EndIf Without If."
Exit Function
End Function
'***************************************************************'
'-------------BEGIN MAJOR #2: STATEMENT EXECUTION---------------'
'***************************************************************'
'This function executes the statement given to it. If there are
'no errors, this returns "". If there is an error, this returns
'the error description.
Public Function Exec(Statement As String, CallInfo As CallType, CancelEvent As Boolean) As String
Dim TextVal() As String
Dim EvalArg() As String
Dim Arg() As String
Dim Build As String
Dim Build2 As String
Dim Temp As String
Dim Temp2 As String
Dim Char As String
Dim Pre As String
Dim E As String
Dim W As Long
Dim X As Long
Dim Y As Long
Dim Z As Long
Dim Xs As Single
Dim Ys As Single
On Error GoTo ErrorTrap
If Left(Statement, 1) <> "/" Then GoTo InvalidCommand
Build = Right(Statement, Len(Statement) - 1)
E = ""
'Temporarily cut out the text values so they don't interfere.
TextVal = RemoveText(Build, E)
If E <> "" Then GoTo MissingQuote
'Parse the arguments
ReDim EvalArg(0)
W = 0
Y = InStr(1, Build, " ")
If Y = 0 Then Y = Len(Build)
Pre = Trim(Left(Build, Y))
Temp = Right(Build, Len(Build) - Y)
Build2 = Temp
Z = InStr(1, Temp, "(")
If Z = 0 Then Z = Len(Temp) + 1
For X = Z To Len(Temp)
Char = Mid(Temp, X, 1)
If Char = "(" Then
W = W + 1
If W = 1 Then Y = X
End If
If Char = ")" Then
W = W - 1
If W = 0 Then
Temp2 = Mid(Temp, Y, X - Y + 1)
Z = UBound(EvalArg) + 1
ReDim Preserve EvalArg(Z)
EvalArg(Z) = Temp2
Build2 = Replace(Build2, Temp2, "{" & CStr(Z) & "}", 1, 1)
End If
End If
Next X
If W <> 0 Then GoTo MissingPar
Arg = ParseArgs(Build2)
'Put the text values back in and evaluate
For X = 0 To UBound(Arg)
For Y = 1 To UBound(EvalArg)
Arg(X) = Replace(Arg(X), "{" & CStr(Y) & "}", EvalArg(Y), 1, 1)
Next Y
For Y = 1 To UBound(TextVal)
Z = InStrRev(Arg(X), Chr(34))
Arg(X) = Left(Arg(X), Z) & Replace(Arg(X), "[" & CStr(Y) & "]", TextVal(Y), Z + 1, 1)
Next Y
If X = 1 And Pre = "SetPlayerInfo" Then
'Do Nothing, it's a constant.
ElseIf X <> 0 Or (Pre <> "Set" And Pre <> "Inc" And Pre <> "Unset" And Pre <> "SetPA") Then
Arg(X) = Eval(Arg(X), CallInfo, E)
If E <> "" Then
Exec = E
Exit Function
End If
Arg(X) = Replace(Dequote(Arg(X)), Chr(1), Chr(34))
ElseIf Pre <> "Unset" And Pre <> "SetPA" Then
Y = InStr(1, Arg(0), "(")
Z = InStrRev(Arg(0), ")")
If Y <> 0 Then
If Z = 0 Then GoTo MissingPar
Temp = Eval(Mid(Arg(0), Y + 1, Z - Y - 1), CallInfo, E)
If E <> "" Then
Exec = E
Exit Function
End If
Arg(0) = Replace(Arg(0), Mid(Arg(0), Y + 1, Z - Y - 1), Temp)
Else
If Z <> 0 Then GoTo MissingPar
End If
End If
Next X
'Now that all the functions are evaluated,
'it's time to execute!
Select Case Pre
Case "?"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
ServerWindow.AddMessage Arg(0)
Case "Set"
If UBound(Arg) = 0 Then
ReDim Preserve Arg(1)
If Left(Arg(0), 1) = "#" Then
Arg(1) = "0"
Else
Arg(1) = Chr(34) & Chr(34)
End If
End If
If UBound(Arg) <> 1 Then GoTo WrongArgNum
If Len(Arg(0)) < 2 Then GoTo InvalidArg
Select Case Left(Arg(0), 1)
Case "$"
Temp = Enquote(Replace(Arg(1), Chr(34), Chr(1)))
Y = GetTxtVarNum(Arg(0))
If Y > UBound(TxtVar) Then
Z = GetPATxt(Arg(0))
If Z = 0 Then
If Not IsAlpha(Right(Arg(0), Len(Arg(0)) - 1)) Then GoTo BadVar
ReDim Preserve TxtVar(Y)
TxtVar(Y).vName = Arg(0)
TxtVar(Y).Value = Temp
Else
Y = InStr(1, Arg(0), "(")
W = InStrRev(Arg(0), ")")
If W = 0 Or Y = 0 Then GoTo InvalidArg
Temp2 = Eval(Mid(Arg(0), Y + 1, W - Y - 1), CallInfo, E)
If E <> "" Then
Exec = E
Exit Function
End If
Y = CInt(Temp2)
PATxt(Z).Value(Y) = Temp
End If
Else
TxtVar(Y).Value = Temp
End If
VarChange = True
Case "#"
Xs = CSng(Arg(1))
Y = GetNumVarNum(Arg(0))
If Y > UBound(NumVar) Then
Z = GetPANum(Arg(0))
If Z = 0 Then
If Not IsAlpha(Right(Arg(0), Len(Arg(0)) - 1)) Then GoTo BadVar
ReDim Preserve NumVar(Y)
NumVar(Y).vName = Arg(0)
NumVar(Y).Value = Xs
Else
Y = InStr(1, Arg(0), "(")
W = InStrRev(Arg(0), ")")
If W = 0 Or Y = 0 Then GoTo InvalidArg
Temp2 = Eval(Mid(Arg(0), Y + 1, W - Y - 1), CallInfo, E)
If E <> "" Then
Exec = E
Exit Function
End If
Y = CInt(Temp2)
PANum(Z).Value(Y) = Xs
End If
Else
NumVar(Y).Value = Xs
End If
VarChange = True
Case Else: GoTo InvalidArg
End Select
Case "SetPA"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
If Not IsAlpha(Right(Arg(0), Len(Arg(0)) - 1)) Then GoTo BadVar
Select Case Mid(Arg(0), 1, 1)
Case "#"
X = UBound(PANum) + 1
ReDim Preserve PANum(X)
ReDim PANum(X).Value(MaxUsers)
PANum(X).vName = Arg(0)
Case "$"
X = UBound(PATxt) + 1
ReDim Preserve PATxt(X)
ReDim PATxt(X).Value(MaxUsers)
For Y = 1 To MaxUsers
PATxt(X).Value(Y) = Chr(34) & Chr(34)
Next Y
PATxt(X).vName = Arg(0)
Case Else
GoTo InvalidArg
End Select
Case "Unset"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
Select Case Left(Arg(0), 1)
Case "#"
Y = GetNumVarNum(Arg(0))
W = UBound(NumVar)
If Y <> W + 1 Then
For Z = Y To W - 1
NumVar(Z) = NumVar(Z + 1)
Next Z
ReDim Preserve NumVar(W - 1)
Else
Y = GetPANum(Arg(0))
If Y <> 0 Then
Z = UBound(PANum)
For X = Y To Z - 1
PANum(X) = PANum(X + 1)
Next X
ReDim Preserve PANum(Z - 1)
End If
End If
VarChange = True
Case "$"
Y = GetTxtVarNum(Arg(0))
W = UBound(TxtVar)
If Y <> W + 1 Then
For Z = Y To W - 1
TxtVar(Z) = TxtVar(Z + 1)
Next Z
ReDim Preserve TxtVar(W - 1)
Else
Y = GetPATxt(Arg(0))
If Y <> 0 Then
Z = UBound(PATxt)
For X = Y To Z - 1
PATxt(X) = PATxt(X + 1)
Next X
ReDim Preserve PATxt(Z - 1)
End If
End If
VarChange = True
Case Else
GoTo InvalidArg
End Select
Case "Inc"
If UBound(Arg) = 0 Then ReDim Preserve Arg(1): Arg(1) = "1"
If UBound(Arg) <> 1 Then GoTo WrongArgNum
Xs = CSng(Arg(1))
If Left(Arg(0), 1) <> "#" Then Y = CInt("a")
Y = GetNumVarNum(Arg(0))
If Y = UBound(NumVar) + 1 Then
Y = GetPANum(Arg(0))
If Y = 0 Then GoTo NoSuchVar
Z = InStrRev(Arg(0), ")")
W = InStr(1, Arg(0), "(")
If Z = 0 Or W = 0 Then GoTo InvalidArg
Z = CInt(Mid(Arg(0), W + 1, Z - W - 1))
If E <> "" Then
Exec = E
Exit Function
End If
PANum(Y).Value(Z) = PANum(Y).Value(Z) + Xs
Else
NumVar(Y).Value = NumVar(Y).Value + Xs
End If
VarChange = True
Case "Clear"
ServerWindow.Messages.Text = ""
Case "SendPM"
If UBound(Arg) <> 1 Then GoTo WrongArgNum
Y = CInt(Arg(0))
If Not IsLoaded(Y) Then GoTo PlayerNotConnected
ServerWindow.AddToQueue Y, "CMSG:" & Arg(1)
Case "SendAll"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
ServerWindow.SendAll "CMSG:" & Arg(0)
ServerWindow.AddMessage Arg(0)
Case "Kick"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
Y = CInt(Arg(0))
If Not IsLoaded(Y) Then GoTo PlayerNotConnected
Player(Y).DCReason = "Scripted kick."
ServerWindow.AddToQueue Y, "BOOT:"
If CallInfo.Source = Y Then CancelEvent = True
Case "Ban"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
Y = CInt(Arg(0))
If Not IsLoaded(Y) Then GoTo PlayerNotConnected
ServerDB.BanUser Y
If CallInfo.Source = Y Then CancelEvent = True
Case "SIDBan"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
Y = CInt(Arg(0))
If Not IsLoaded(Y) Then GoTo PlayerNotConnected
ServerDB.SIDBanUser Y
If CallInfo.Source = Y Then CancelEvent = True
Case "TempBan"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
Y = CInt(Arg(0))
If Not IsLoaded(Y) Then GoTo PlayerNotConnected
ServerWindow.Tempban Y
If CallInfo.Source = Y Then CancelEvent = True
Case "Run"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
Shell Arg(0), vbNormalFocus
Case "SaveValue"
If UBound(Arg) <> 1 Then GoTo WrongArgNum
SaveSetting "NetBattle", "Script Values", Arg(0), Arg(1)
Case "SetPlayerInfo"
If UBound(Arg) <> 2 Then GoTo WrongArgNum
X = CInt(Arg(0))
If Not IsLoaded(X) Then GoTo PlayerNotConnected
Select Case Arg(1)
Case "EXTR"
Player(X).Extra = CorrectText(Arg(2))
Case "AUTH"
If CInt(Arg(2)) > 2 Or CInt(Arg(2)) < 0 Then GoTo InvalidArg
Player(X).Authority = CInt(Arg(2)) + 1
ServerWindow.SendAll "AUTH:" & FixedHex(X, 3) & Player(X).Authority
ServerDB.ChgAuth Player(X).Name, Player(X).Authority
Case "HIDE"
Player(X).ShowTeam = Not (CInt(Arg(2)) = 0)
Case Else
GoTo InvalidArg
End Select
ServerWindow.RefreshListing
If CallInfo.EventNum <> 19 Then ServerWindow.SendAll ServerWindow.PreparePlayerData(X, True)
Case "Load"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
X = LoadLibrary(Arg(0))
If X = 0 Then Exec = "Error loading DLL.": Exit Function
Y = GetProcAddress(X, "event_function")
If Y = 0 Then
FreeLibrary X
Exec = "The DLL was loaded, but the event_function proc was not found."
Exit Function
End If
ReDim Preserve LoadedDLLs(UBound(LoadedDLLs) + 1)
With LoadedDLLs(UBound(LoadedDLLs))
.Name = LCase$(Arg(0))
.hLib = X
.Addr = Y
End With
Call ServerWindow.AddMessage(Arg(0) & " loaded successfully.")
Case "Unload"
If UBound(Arg) <> 0 Then GoTo WrongArgNum
Arg(0) = LCase$(Arg(0))
For X = 1 To UBound(LoadedDLLs)
If LoadedDLLs(X).Name = Arg(0) Then Exit For
Next X
If X = UBound(LoadedDLLs) + 1 Then
Exec = "DLL is not loaded."
Exit Function
End If
Y = FreeLibrary(LoadedDLLs(X).hLib)
If Y = 0 Then
Exec = "FreeLibrary error."
Else
For X = X + 1 To UBound(LoadedDLLs)
LoadedDLLs(X - 1) = LoadedDLLs(X)
Next X
ReDim Preserve LoadedDLLs(X - 2)
End If
Call ServerWindow.AddMessage(Arg(0) & " unloaded successfully.")
Case Else
GoTo InvalidCommand
End Select
Exit Function
'--------------Errors---------------
ErrorTrap:
Exec = "RTE " & Err.Number & ": " & Err.Description & "."
Exit Function
NoSuchVar:
Exec = "No Such Variable."
Exit Function
BadVar:
Exec = "Variable Name Must Include Only Letters."
Exit Function
MissingPar:
Exec = "Missing Parenthesis."
Exit Function
MissingQuote:
Exec = "Missing: " & Chr(34)
Exit Function
WrongArgNum:
Exec = "Wrong Number of Arguments."
Exit Function
PlayerNotConnected:
Exec = "No Such Player Number."
Exit Function
InvalidArg:
Exec = "Invalid Argument."
Exit Function
TextOutside:
Exec = "Text Outside Quotes."
Exit Function
InvalidCommand:
Exec = "Invalid Command."
Exit Function
End Function
'***************************************************************'
'-------------BEGIN MAJOR #3: FUNCTION EVALUATION---------------'
'***************************************************************'
'This function evaluates all the script functions and math, as
'well as all nested functions, and returns the final value. If
'there is an error while processing, it is stored in ErrorBuffer.
Public Function Eval(Source As String, CallInfo As CallType, ErrorBuffer As String, Optional DoVars As Boolean = True) As String
Dim B As Boolean
Dim V As Long
Dim W As Long
Dim X As Long
Dim Y As Long
Dim Z As Long
Dim Xl As Long
Dim Yl As Long
Dim Xs As Single
Dim Ys As Single
Dim Zs As Single
Dim E As String
Dim a() As Long
Dim F() As String
Dim Arg() As String
Dim Pre As String
Dim Temp As String
Dim Build As String
Dim NewVal As String
Dim TextVal() As String
Dim FinalVal As String
'This is the main processing function. It evaluates all script functions.
On Error GoTo ErrorTrap
If Source = Enquote("") Then
Eval = Source
Exit Function
End If
If IsStrictNumeric(Source) Then
Eval = Source
Exit Function
End If
If Left(Source, 1) = Chr(34) And InStr(2, Source, Chr(34)) = Len(Source) Then
Eval = Source
Exit Function
End If
Build = Source