Re: Decompiled Sysop Scripts
Vid Kid wrote:
Ok , looked through the 0_login script .. for those whom have my .cts
Same version that you can have as .ts here ...
Please try the .ts one out and let me know if it works the same.
I have found (in the first few hundred lines)
a couple waiton commands made into settexttriggers
and a bunch of killtriggers with " around them (may cause errors)
as well as if statements changed IF ($var = "1") to IF ($Var = 1)
which WILL be problematic at the end results.
I will continue on reading/comparing original to this decompile.
I cant wait to get to the includes to see that also.
I did notice that any comments were removed and most word placements were
removed.. making reading a bit harder for me , but aesthetically ok in script running.
So far good job .. hope the .ts runs right.
I'll be back to post more in a bit .. for those following.
Vid
Hi Vid,
A couple of points here.
None of this is documented, so everything I did was based on reading the released twx source code and reverse engineering it. There were many bugs in my earlier iterations of this based on unexpected behavior by the compiler. I have fixed most of them.
When you compile a .CTS to .TS, it is actually compiling it into bytecode - meaning that it breaks down the statements (setvar, send, etc) and turns them into individual bytes that refer to what each statement does. It then has a structure where the bytes following reference each of the parameters (variables, constants, etc) used by the command, and it separately adds all the text strings, encrypted, to the end of the file, along with the labels (unencrypted).
The compiler throws away all comments, so the .CTS doesn't contain any of the comments in the original code. Those are impossible to reproduce.
When you actually load a .TS into TWX, it compiles it exactly as it would if you ran TWXC on it, and then executes the compiled code. So the only difference in performance between loading a .CTS or a .TS is that the startup time to load the script is slightly slower with a .TS (because it has to compile it to run it).
Anyway, back to what's changed/missing. The compiler converts all if/then/else and while statements to "BRANCH" statements. These are in the twx documentation describing what they do as a compiler internal statement (but can actually be used in scripts directly). So, an if statement like:
if ($1 = foo)
setvar $1 bar
end
Turns into:
BRANCH :22 $1 = foo
setvar $1 bar
:22
If/then/else are more complicated:
if ($1 = foo)
setvar $1 bar
else if ($1 = bar)
setvar $1 foo
else if ($1 = bob)
setvar $1 foo
end
Becomes:
BRANCH :23 $1 = foo
setvar $1 bar
goto :22
:23
BRANCH :24 $1 = bar
setvar $1 foo
goto :22
:24
BRANCH :22 $1 = bob
setvar $1 foo
:22
While statements are similarly changed into BRANCH and GOTO. This is reflected in the output of my decompiler. I may go back and clean it up, but it's difficult work, and the code generated runs just fine.
re waiton - the compiler converts this directly:
waiton "foo"
to:
settexttrigger WAITON1 :28 "foo"
:WAITON1
Meaning, if you put a "waiton" in your code, it is automatically converted to a trigger by the compiler. So it's no difference from using a trigger.
Waitfor is different - it is a separate function and ignores all other triggers. Waiton can be interrupted by other triggers because it's a trigger itself.
I suspect waitfor is faster, based on how the compiler handles it.
More on this later - I plan to document all of this for anyone who wants to work on this in the future.
I am happy to discuss with you sometime if you'd like.
I would love for you to look at the other scripts and provide any feedback you have so I can make the decompiler better. It's over 2000 lines of c# code already. I do plan to release it once I am sure I have dealt with all the edge cases.