Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding SadScript Support
#1
First of many, before archive tutorials to be converted.

Diffculty 2/5 (mostly copy and paste ebcause I seriously cant explain half of what GSD told me xD)

First off make sure you have SadScript3:
http://www.pscode.com/vb/scripts/ShowZi ... S367166177

Off the bat, ill tell you SadScript does not allow sending stungs to subs like so:
Code:
MyScript.ExecuteStatement "ScriptFile.txt", "SubNameHere " & "Hello"

not possible Tongue

Ok in the zip folder you should see DLL and Sample.
From the DLL folder copy the clsRC4 and clsSadScript put that into your game's server folder.
Now go into the Sample folder.
Copy clsCommands and put that into your game's server folder.
Good now open up your game's server project.
Now add all 3 of those Class Modules to your project.
Go to Project>Reference and make reference to: Mircrosoft Script Control 1.0

in modGlobals add this at the top:

Code:
Global MyScript As clsSadScript
Public clsScriptCommands As clsCommands

Now open clsSadScript and change:


Code:
Public Type define
    sVari As String
    sValue As String
End Type

to

Code:
Private Type define
    sVari As String
    sValue As String
End Type

Now find:
Code:
Sub InitServer()
Add this near the top:

Code:
Call SetStatus("Loading scripts...")
        Set MyScript = New clsSadScript
        Set clsScriptCommands = New clsCommands
        MyScript.ReadInCode App.Path & "\ScriptFile.txt", "\ScriptFile.txt", MyScript.SControl, False
        MyScript.SControl.AddObject "ScriptHardCode", clsScriptCommands, True

Note: You can change \ScriptFile.txt to whatever you want, just make sure you know this name for later.

Now add this anywhere you want the script to load:
Code:
MyScript.ExecuteStatement "ScriptFile.txt", "SubNameHere"

Now change SubNameHere to whatever sub you want it to load.
Ok now if you want variables like player index do this:
Code:
MyScript.ExecuteStatement "ScriptFile.txt", "SubNameHere " & index

Note the space after the SubNameHere, you will always need that.
Now if you want more variables do:
Code:
MyScript.ExecuteStatement "ScriptFile.txt", "SubNameHere " & index & "," & index

And so on!

Finnally replace all of clsRC4 with the following

[code]Option Explicit
Private Const BLOCKSIZE = 256
Dim mnsBox(0 To 255) As Integer 'S-Box
Dim mnKeep(0 To 255) As Integer
Private mstrError As String
Private mstrPassword As String
Private mnErrorNumber As Long

Public Property Get ErrorNumber() As Long
ErrorNumber = mnErrorNumber
End Property

Public Property Let Password(ByVal vData As String)
mstrPassword = vData
Initialize mstrPassword
End Property

Public Property Get Password() As String
Password = mstrPassword
End Property

Public Property Get ErrorMessage() As String
ErrorMessage = mstrError
End Property

Public Function EncryptFile(ByVal strSource As String, ByVal strTarget As String, Optional strPassword As String) As Boolean
Dim strNameRoutine As String ' Name of routine For logging and Error routine
Dim nResult As Long
Dim inbyte As Byte
Dim nIndex As Long
Dim nSourceFile As Integer
Dim nTargetFile As Integer
Dim nSourceSize As Long
Dim nChunkSize As Integer
Dim strInput As String
Dim strOutput As String
Dim blnContinue As Boolean
On Local Error GoTo EncryptFile_Error
' InitialinIndexe variables
strNameRoutine = "EncryptFile"
nResult = 0 ' 0 = Failure - Must change To indicate success

If mstrPassword = "" And strPassword = "" Then
mstrError = "You need To enter a password For encrypten or decrypten"
GoTo EncryptFile_Exit
Else


If Len(strPassword) And strPassword mstrPassword Then
mstrPassword = strPassword
End If
End If


If Len(strSource) = 0 Or Len(strTarget) = 0 Then
mstrError = "Error - Source/Target name missing"
GoTo EncryptFile_Exit
End If


If Len(Dir$(strSource)) = 0 Then
mstrError = "Error missing source"
GoTo EncryptFile_Exit
End If


If Len(Dir$(strTarget)) Then
Kill strTarget
End If
' get the file handles
nSourceFile = FreeFile
nSourceSize = FileLen(strSource)
Open strSource For Binary As nSourceFile
nTargetFile = FreeFile
Open strTarget For Binary As nTargetFile
blnContinue = False ' Set this so we reset the indexes in the first call...


Do Until nIndex >= nSourceSize


If nIndex + BLOCKSIZE > nSourceSize Then
nChunkSize = nSourceSize - nIndex
Else
nChunkSize = BLOCKSIZE
End If
nIndex = nIndex + nChunkSize
strInput = Space$(nChunkSize) ' init For getting data
Get #nSourceFile, , strInput
strOutput = EnDeCrypt(strInput, blnContinue)
Put #nTargetFile, , strOutput
blnContinue = True ' mark it so that we Do Not reset the indexes on subsuquent calls
Loop
' clean up
Close nSourceFile
Close nTargetFile
nResult = True
EncryptFile_Exit:
On Local Error GoTo 0 ' turn off error trapping
EncryptFile = nResult
Exit Function
' Error Recovery & Logging
EncryptFile_Error:
' Log the error and exit routine
mnErrorNumber = Err.Number
mstrError = Err.Description & " In " & strNameRoutine
nResult = 0 ' verify that we are Set To failure
Resume EncryptFile_Exit
End Function

Public Function EncryptString(ByVal strSource As String, Optional strPassword As String) As String
Dim strNameRoutine As String ' Name of routine For logging and Error routine
Dim strResult As String
On Local Error GoTo EnCryptString_Error
' Initialize variables
strNameRoutine = "EnCryptString"
strResult = "" ' 0 = Failure - Must change To indicate success
' make sure we have the files, names and
' basic requirements


If mstrPassword = "" And strPassword = "" Then
mstrError = "You need To enter a password For encrypten or decrypten"
GoTo EnCryptString_Exit
Else


If Len(strPassword) And strPassword mstrPassword Then
mstrPassword = strPassword
End If
End If

If Len(strSource) = 0 Then
mstrError = "Error - Source/Target name missing"
GoTo EnCryptString_Exit
End If
strResult = EnDeCrypt(strSource, False)
EnCryptString_Exit:
On Local Error GoTo 0 ' turn off error trapping
EncryptString = strResult
Exit Function
' Error Recovery & Logging
EnCryptString_Error:
' Log the error and exit routine
mnErrorNumber = Err.Number
mstrError = Err.Description & " In " & strNameRoutine
strResult = "" ' verify that we are Set To failure
Resume EnCryptString_Exit
End Function

Private Sub Initialize(ByVal strPassword As String)
Dim temp As Integer
Dim nBufferIndex As Integer
Dim nPwdIndex As Integer
'Save Password in Byte-Array
nPwdIndex = 0


For nBufferIndex = 0 To 255
nPwdIndex = nPwdIndex + 1


If nPwdIndex > Len(strPassword) Then
nPwdIndex = 1
End If
mnKeep(nBufferIndex) = Asc(Mid$(strPassword, nPwdIndex, 1))
Next nBufferIndex
'INI S-Box


For nBufferIndex = 0 To 255
mnsBox(nBufferIndex) = nBufferIndex
Next nBufferIndex
nPwdIndex = 0


For nBufferIndex = 0 To 255
nPwdIndex = (nPwdIndex + mnsBox(nBufferIndex) + mnKeep(nBufferIndex)) Mod 256
' Swap( mnsBox(i),mnsBox(j) )
temp = mnsBox(nBufferIndex)
mnsBox(nBufferIndex) = mnsBox(nPwdIndex)
mnsBox(nPwdIndex) = temp
Next nBufferIndex
End Sub

Private Function EnDeCrypt(strSourceText As String, Optional blnContinue As Boolean) As String 'Only use this routine For short texts
Static nIndex As Integer
Static nIndex2 As Integer ' ok it's a poor name, but it is simply the second index...
Dim nKeyByte As Integer
Dim byteCypher As Byte
Dim strCipher As String
Dim nSwap As Integer
Dim nTextIndex As Long


If blnContinue = False Then
Initialize mstrPassword ' we have To re-initialize everytime because of the array shuffle
nIndex = 0
nIndex2 = 0
End If


For nTextIndex = 1 To Len(strSourceText)
nIndex = (nIndex + 1) Mod 256
nIndex2 = (nIndex2 + mnsBox(nIndex)) Mod 256
' Swap( mnsBox(nIndex),mnsBox(nIndex2) )
'
nSwap = mnsBox(nIndex)
mnsBox(nIndex) = mnsBox(nIndex2)
mnsBox(nIndex2) = nSwap
'Generate Keybyte nKeyByte
nKeyByte = mnsBox((mnsBox(nIndex) + mnsBox(nIndex2)) Mod 256)
'Plaintextbyte xor Keybyte
byteCypher = Asc(Mid$(strSourceText, nTextIndex, 1)) Xor nKeyByte
strCipher = strCipher & Chr$(byteCypher)
Next nTextIndex
EnDeCrypt = strCipher
End Function

Private Function EnDeCryptSingle(bytePlain As Byte, Optional blnContinue As Boolean) As Byte 'Use this routine For really huge files
Static nIndex As Integer
Static nIndex2 As Integer
Dim nSwap As Integer
Dim nKeyByte As Integer
Dim byteCipher As Byte


If blnContinue = False Then
Initialize mstrPassword ' we have To re-initialize everytime because of the array shuffle
nIndex = 0
nIndex2 = 0
End If
' get calculation values
nIndex = (nIndex + 1) Mod 256
nIndex2 = (nIndex2 + mnsBox(nIndex)) Mod 256
' Swap( mnsBox(nIndex),mnsBox(nIndex2) )
'
nSwap = mnsBox(nIndex)
mnsBox(nIndex) = mnsBox(nIndex2)
mnsBox(nIndex2) = nSwap
'Generate nKeyByteeybyte nKeyByte
nKeyByte = mnsBox((mnsBox(nIndex) + mnsBox(nIndex2)) Mod 256)
'Plaintextbyte xor nKeyByteeybyte
byteCipher = bytePlain Xor nKeyByte
EnDeCryptSingle = byteCipher
End Function



Now replace clsSadScript with:
Code:
Option Explicit
Private Type define
sVari As String
sValue As String
End Type

Public WithEvents SControl As ScriptControl
Private sAllCode() As String
Private sSubs() As String
Private sFunctions() As String
Public p_colSubs As Collection
Public p_colFuncs As Collection
Public Path As String
Private m_oCrypt As clsRC4

Public Property Let FilePass(sPass As String)
m_oCrypt.Password = sPass
End Property

'/////////////////////////////\/\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Public Function ReadInCode(sfile As String, sModTitle As String, msc As ScriptControl, Optional bEncrypted As Boolean = False)
'/////////////////////////////\/\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim sTemp As String 'Holds each line as it comes in from the file
Dim iTemp As Integer
Dim sTotalTemp As String 'Holds all lines
Dim sTempCode() As String 'Temporary Array to hold Include files
Dim iFileNum As Integer 'File Number we're working with
Dim sDefines() As define 'Defines to go through and change later
'Set encryption object
Set m_oCrypt = New clsRC4

'Unencrypt file
If bEncrypted = True Then
If m_oCrypt.EncryptFile(sfile, sfile & "1") = True Then
Kill sfile
Name sfile & "1" As sfile
Else
MsgBox "Unencrypt FAILED!"
Exit Function
End If
End If

'Start Blank
Erase sAllCode
ReDim sDefines(0)
iFileNum = FreeFile 'Get new file number (thats not in use)

Open sfile For Input As iFileNum 'Open file

Do Until EOF(iFileNum) = True 'Loop until file is at the end
Line Input #iFileNum, sTemp 'Get 1 line and put in sTemp
sTemp = Trim(Replace(sTemp, vbTab, "")) 'Trim string, get rid of all tabs
If Left(sTemp, 1) "#" And Trim(sTemp) "" Then 'If line is a comment, ignore
sTotalTemp = sTotalTemp & sTemp & vbNewLine 'Add line to the string
Else
'Yeah we got include statement
If LCase(Left(sTemp, 8)) = "#include" Then
sTemp = Mid(sTemp, InStr(sTemp, "
Reply
#2
I'm having prblems with this one. Some help please?

Runtime Error '429': Cannot Create ActiveX Component

Highlites the following:


In clsSadScript.CLS
Quote:'/////////////////////////////\/\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Private Sub Class_Initialize()
'/////////////////////////////\/\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Set SControl = New ScriptControl
SControl.Language = "vbScript"
End Sub
Reply
#3
Is adding sadscript good?
Reply
#4
Krloz Wrote:Is adding sadscript good?

little point unless you're releasing a game engine... that you want semi-customiseable... otherwise... why clutter the server folder?
Reply
#5
I was going to use it so that I dont have to hard code 100 quests into the server modules lol.
Reply
#6
msscript.dll ... helps to find and register that :wink:

Now, to figure out how it works :?
Reply
#7
To figure out how to code anything, head over to Elysium Source forum and read up on the code for SadScript included in the engine Smile I believe there is even a tutorial about SadScript in the forum somewhere.
Reply
#8
Thanks, I'll go have a look over there. Went and downloaded the Diamond source and had a look at it to se ehow everything worked. Best way for me to learn is to see it lol Smile.


Had a few Type Mismatch errors but I got it to work. This should make quest creation a LOT easier Big Grin
Reply
#9
God-Sent-Death Wrote:To figure out how to code anything, head over to Elysium Source forum and read up on the code for SadScript included in the engine Smile I believe there is even a tutorial about SadScript in the forum somewhere.

Hahahah. I find your avatar hilarious xD
Reply
#10
Kite Wrote:
God-Sent-Death Wrote:To figure out how to code anything, head over to Elysium Source forum and read up on the code for SadScript included in the engine Smile I believe there is even a tutorial about SadScript in the forum somewhere.

Hahahah. I find your avatar hilarious xD

me too xD where did u got it from? Tongue
Reply
#11
I think it's the dance that race does on the game WoW. Not sure, never played that race, I don't like going horde. They all look gay.
Reply
#12
A bit off-topic no?
Anyhow, *cough* http://www.worldofwarcraft.com/info/races/dancing.html
Reply
#13
http://splamm.com/elysium/forums/viewtopic.php?t=1309

TheYellowMole's Ultimate Guide to Sadscript. Never seen a better guide to sadscript. I suggest that people that add this, read the tut.
Reply
#14
Joost Wrote:http://splamm.com/elysium/forums/viewtopic.php?t=1309

TheYellowMole's Ultimate Guide to Sadscript. Never seen a better guide to sadscript. I suggest that people that add this, read the tut.

Confusedhock: very nice Confusedhock:
Reply
#15
I know this is an old topic. But after following the tutorial, I add this to my script file...

Code:
Sub JoinGame(index)

    ' Send them welcome
    PlayerMsg index, "Test", white)
End Sub

Then add this in Sub JoinGame under the SendWelcome call

Code:
MyScript.ExecuteStatement "eScript.txt", "JoinGame " & Index

It doesn't print a message.
Reply
#16
your syntax is incorrect, eh?

Sub JoinGame(index)

' Send them welcome
PlayerMsg(index, "Test", white)
End Sub
Reply
#17
still get the same error, no message
Reply
#18
missing call?

Call PlayerMsg(index, "test" color)
Reply
#19
Usually in VB6 you don't really need to put Call. But i'll give it a try. I doubt it's that though. I'll have to try and rip the system from somebody elses engine.
Reply
#20
if you use ( and ) you need to use call.
Reply
#21
GameBoy Wrote:Usually in VB6 you don't really need to put Call. But i'll give it a try. I doubt it's that though. I'll have to try and rip the system from somebody elses engine.

Im pretty sure only functions dont require the call.. function.. :wink:
Reply
#22
works for subs too. There's absolutely no "call " in my code, what so ever.

I was just looking around. Is there something I need to add to clsCommands in order for SadScript to send data from the main.txt to the client?
Reply
#23
Sub SendData
Reply
#24
that'll be why then Big Grin
Reply
#25
Um, can someone please help me here? I have no idea what I am doing.

I try to put the execut script statement in my join game sub and try to add a little player message, but it doesn't work at all. Sad Any help?

~Braydok
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)