UScripting in Linux

  • Hey - turns out IRC is out and something a little more modern has taken it's place... A little thing called Discord!

    Join our community @ https://discord.gg/JuaSzXBZrk for a pick-up game, or just to rekindle with fellow community members.

Quasi^

Me.
Oct 26, 2002
3,410
48
Behind a crate
Someone asked me on unrealadmin.org to make a tutorial for compiling/decompiling uscript under linux, so I thought I'd bore you all here with it too :p

Also have it on my w/site too.

Exporting and Compiling UScript in Linux




1. Tools You Need


First off you cannot compile or export UScript with the native Linux UCC.
You need an emulator and the DLLs and EXEs from the Windows version of the
game. WIne is by far the best for this purpose.

Head over to http://www.winehq.com and look for a package for your distro or
else get the source and compile and install manually.

When Wine is installed open up winecfg ( type 'winecfg' in a terminal )
and have a look at your drive letters.
The reason for this is we will need to tell Wine whereabouts your UT is
installed later on. You may likely need a path like Z:\\path\\to\\ut...
or if like me your UT is installed on a mounted partition you might need
to add it in winecfg in the drives tab. E.g. mine is H:\\ut.

Next you will need UCC.EXE and the DLLs from UT Windows, so copy them from
the CD into your UT/System folder. I forget exactly which DLLs you need so
get them all.

A Little Test

cd into your ut/system folder and type 'wine ucc'. You should see a message:
Code:
=======================================
ucc.exe: UnrealOS execution environment
Copyright 1999 Epic Games Inc
=======================================

Use "ucc help" for help
You may also get some errors about midi and GetProcessWorkingSetSize but don't
worry about these. So long as you get the welcome message above, all is well.








2. Exporting Code


The command line is:
Code:
wine ucc batchexport PACKAGE class .uc UTDir\\PACKAGE\\Classes
You need double \\ or wine will not find the dirs.

So for example to export all scripts in BotPack do:
Code:
wine ucc batchexport BotPack.u class .uc h:\\ut\\BotPack\\Classes
Replace h:\\ut with the path to ut you noted from winecfg earlier.

The command line explained:

batchexport tells ucc we want to export something
BotPack.u is the name of the package we want to export
class tells ucc that we want classes
.uc is the file extension we want
h:\\ut\\BotPack\\Classes tells ucc where to save files to

After issuing this command you should see a list of classes wizz past
and finally at the end:
Code:
Success - 0 error(s), 0 warnings
Now you can go up a dir ( cd .. ) and check that there is in fact a BotPack dir
with a subdir Classes, containing all the .uc files from BotPack.

So far so good.







3 Compiling Code


Ok so you have some code that you want to compile. First off it must be in a subdir
Classes of a subdir of your package name which is a subdir of the main ut dir.

I.E. ut/PackageName/Classes/SomeScript.uc

Exactly the same as in Windows.

Also you must rename/delete any older compiled package from the System dir before
compiling or your new code will not compile. Same as in Windows.

Next add your package to bottom of EditPackages= list in UnrealTournament.ini e.g.
Code:
EditPackages=MyNewWeapon
Now we are good to go. The command line is:
Code:
wine ucc make
It's as simple as that. Now you should either have a success message, or a load
of errors. If you get errors ucc is kind enough to point you to where they are
in the code usually. If everything went ok you can boot up UT and play with
your new toy.







4 Automating


Wouldn't it be nice not to have to type a whole lot of commands to do this? Yes
it would. So I have a few scripts that make decompiling and compiling a lot easier
to type.



My uccmake script:
Code:
####################################################
#!/bir/bash
rm /path/to/ut/System/PackageName.u 2>/dev/null
wine /path/to/ut/System/ucc make 2>/dev/null
####################################################
Now when I'm working on a package I edit the script with the package name, and then
I can just run 'uccmake' in a terminal and it works fine. Notice the 2>/dev/null
at the end of both lines? That stops any errors from showing. You will still get
output from ucc but it will block the wine midi warning we saw earlier. Much neater.



I also have a uccexport script:
Code:
####################################################
#!/bin/bash
wine h:\\ut\\System\\ucc batchexport $1.u class .uc h:\\ut\\$1\\Classes 2>/dev/null
####################################################
Note that the package name is replaced with a variable $1. This takes the package
name from the command line. E.G. if I type
Code:
uccexport BotPack
It will replace $1 with BotPack.

If you have kde installed you can make a nice gui decompiler using kdialog. You can
also use xdialog for this but the syntax will be different.

My gui exporter script:
Code:
####################################################
#!/bin/bash

error()
{
kdialog --error "Error in export"
exit 0
}

cd /str1/ut/System
rm list 2>/dev/null

for f in `ls *.u`; do echo $f $f >> list; done

list=`cat list`
file=`kdialog --geometry 400x800 --menu Browser $list`
[[ ! -f $file ]] && exit 0
let len=${#file}
package=${file:0:$len-2}
uccexport $package || error
kdialog --msgbox "Export Successful"
####################################################
Notice that exporter uses the uccexport script, so you need both to get this to work.

All these scripts are very basic and could be improved upon no doubt. Also I would
advise having a scripts subdir in your home dir to keep bash scripts in and adding
it to your PATH variable in .bash_profile or .bashrc:
Code:
export PATH=$PATH:~/scripts/
This makes things a lot easier.








5. Editing


In Windows I used Wotgreal a lot but there is no similar software for linux. My advice
is to install a multi tabbed terminal (mrxvt is excellent for this) and have one tab
for browsing code and another for compiling etc. With creative use of the 'grep'
command you can do almost anything.

For an editor I use vim which has nice syntax highlighting and other functions which
I've customised somewhat. But vim is harder to learn than some gui editors and it's
really a matter of what suits you.

If you do go with vim, here are some helpful shortcuts for putting in your .vimrc:
Code:
####################################################
set softtabstop=4
set shiftwidth=4
set tabstop=4
set autoindent
map <F2> :set number!<CR>
map <F9> :call ShowFunctions()<CR>

function! ShowFunctions()
exec "!ctags --uc-kinds=f" expand("%")
!~/scripts/uctags
30vsplit tags
set nowrap
setlocal ts=99
map <CR> 0ye<C-W>w:tag <C-R>"<CR>
endfunction
####################################################
To clean up the ShowFunctions command you will also need a uctags file:
Code:
####################################################
#!/bin/bash
sed -i '/TAG/d' tags
sed -i 's/bool /bool_/' tags
sed -i 's/int /int_/' tags
sed -i 's/string /string_/' tags
####################################################
What these do is set a tab stop of 4 characters which I find best for code. The F2 key
will toggle line numbering which is handy for finding errors. F9 uses the ctags
program to open a side window with the list of functions. Pressing enter on a function
will make the right pane go to that function, although it can have problems with
complex code.