Giter VIP home page Giter VIP logo

gta3sc's Introduction

gta3sc

Build Status

This is a native script compiler/decompiler for the so called GTA3script language, used to design the mission scripts of the 3D Universe of the series.

Due to its design, it can also be used as a framework for working with SCM data. See the README.md in the src directory for a technical overview. There's also a experimental Dynamic Recompiler in the dynarec-x86 branch.

Building

Windows (MSVC) and Linux (GCC/Clang) are currently supported, but you need the latest compiler toolchain of your platform due to the use of C++17.

Just follow the standard CMake procedure for generating projects or makefiles.

mkdir build
cd build
cmake ..

Then make or use the generated project files.

Using

The compiler/decompiler is invoked by the file extension of the input file, or from the action compile or decompile.

Compilation example:

gta3sc main.sc --config=gta3
gta3sc compile main.sc --config=gta3  # does the same thing as above

Decompilation example:

gta3sc main.scm --config=gta3
gta3sc decompile main.scm --config=gta3  # does the same thing as above

The decompiler is still very early and produces very low-levelish code, so low that it cannot be recompiled back. High-level decompilation is supposed to be implemented later.

Help:

To get further instructions, try getting help from the utility.

gta3sc --help

Testing

Ensuring a compiler is working correctly is a must. To help us on this task we use llvm-lit. While on the root of this tree, use the following command to run all the tests.

lit test --verbose

For further details, please refer to the README.md on the test directory.

gta3sc's People

Contributors

cookieplmonster avatar jayfoxrox avatar likeawindrammer avatar thelink2012 avatar thirteenag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gta3sc's Issues

Desc field for Opcode 0x129 is confusing

Hey, danhedron of OpenRW noticed that one of the commands had confusing descriptions.

Affected GTA III version
Affected GTA VC version

The XML portion in question is

        <Arg Type="INT" Desc="Ped type" Entity="CAR"/>
        <Arg Type="INT" Desc="Model ID" Enum="PEDTYPE"/>
        <Arg Type="INT" Desc="Car/vehicle" Enum="CARPEDMODEL"/>

where a mismatch between Desc and Entity / Enum occurs.


        <Arg Type="INT" Desc="Car/vehicle type" Entity="CAR"/>
        <Arg Type="INT" Desc="Ped" Enum="PEDTYPE"/>
        <Arg Type="INT" Desc="Model ID" Enum="CARPEDMODEL"/>

is probably better.

Note that the GTA SA version of the command is less complete so the problem doesn't exist there yet.

Implement alternators properly

We currently implement alternators by some kind of overloading.

This gives us some issues:

  • Producing a error message is a bit harder.
  • You can't use the non-alternator command (e.g. SET_VAR_INT_TO_VAR_INT) directly, unlike in miss2.

Implement this by using a <Alternators> XML section.

Intermediate Code Output

We should have a compiler option to output the generated intermediate code, in text form. Much like what miss2 does with main_test.txt. The output must be very explicit about datatypes and such.

This will be quite useful for codegen tests, since taking the checksum of the binary every time you modify the test is annoying.

Add -farrays switch

Add a switch to enable the use of arrays instead of always allowing it.

Where should the check be placed? Codegen? Or maybe once a array is declared?

Arrays indices are 0-based

Oh well #46, look at those debug prints

{1885665} 065D: NOP $7424 "OTANK_TARGET[0]" 
{1885687} 065D: NOP $7425 "OTANK_TARGET[1]" 
{1885709} 065D: NOP $7426 "OTANK_TARGET[2]" 

VAR1 = THING - VAR1 is allowed in gta3sc but not in miss2

miss2 throws an error when trying to do something like VAR1 = THING - VAR1 because it would require an implicit temporary variable which miss2 nor gta3sc cannot do. However, gta3sc compiles this and produces invalid code in the process looking like:

VAR = THING
VAR -= VAR

Missing documentation

There is no documentation:

  • How to compile this
  • How to run this
  • What can this even do?

Background: I'm currently looking for a tool to disassemble a PC GTA3 main.scm on Linux.
It's important that I get a disassembled version which still includes all opcode numbers as I want to generate statistics about opcode usage etc.

No local variables range check

You can declare more than 16/32 local variables in one scope, therefore first reusing TIMERA and TIMERB implicitly and then referencing inexistant local variables.

IFNOT / WHILENOT

Allow IFNOT and WHILENOT. Pedantically only in III, but would be nice to support also in VC/SA.

See here for details.

Support for GTA San Andreas

  • Arrays
  • SWITCH (#32)
  • TEXT_LABEL / TEXT_LABEL16 (#33)
  • Streamed scripts (#34)
  • CONST_INT / CONST_FLOAT / CONSTANT_INT (too risky, see #35)
  • Change the amount of allowed local variables, including mission locals (#36)
  • SKIP_CUTSCENE* directives (#37)

Its commands.xml also probably needs more static information? (#38)

Read IDE files

Read IDE files so that the result of ProgramContext::is_model_from_ide is actually accurate. Also remove all the constants from constants.xml that are similar to the name of the models on IDEs.

Making this a optional switch would be a good idea.

No IF statement checks

The compiler doesn't emit any errors nor warnings when you try to use more than 8 conditions in a single IF statement.

Suggestion: Refuse to compile such file? I guess this could be exposed to a configuration file in the future, but for now hardcoding 8 conditions limit should be OK.

Hand-written parser/lexer

Because

  1. ANTLR3 error messages are crypt and doesn't match the formatting of the messages in the rest of the compiler.
  2. ANTLR3 is a performance bottleneck.

Keep the grammar on the header of functions in the lex/parser.

Standardize error messages

Define whether

  • They should be fully lower-case
  • They should end with a dot
  • More?

Additionally

  • Make the message clear (currently it has a quick draft)
  • Possibly suggest a compiler option to get rid of the error

Use a XML for config flags

Use a XML on the directory of each configuration specifying some code generation flags, such as half float. Maybe also specifying the id of special opcodes.

This way, the configurations can have arbitrary values, not only gta3, gtavc and gtasa.

VAR = CONST

Since Vice City the following kind of command is allowed

VAR_INT v
v = CHEETAH // 105

which compiles to a specific opcode (different from the one used in v = 105).

Preprocessor

Implement a very basic preprocessor which only allows the #ifdef / #ifndef directive. Any definition should be given to the compiler by the means of a -D switch.

String Constant Conflicts

String constants may have collisions. For instance, the CAMMODE enumeration contains a SNIPER constant, same name of a CARPEDMODEL constant.

The implication of this is that the following may generate different output depending on how we evaluate the search for a constant:

VAR_INT x
x = SNIPER

In fact, this ends up using CARPEDMODEL in miss2, while it uses the CAMMODE enum here.

Specify the evaluation order of enumerations!

Streamed Scripts

Add -fstreamed-scripts and only allow it with guesser mode.

Implement based on message exchanging with Wesser.

SWITCH

See SCM Language, SWITCH.

Add a -fswitch option, and when SWITCH_START / SWITCH_CONTINUED isn't available, use a IF chain.

We should probably add this to guesser mode?

Configure config/gtasa/ properly

Lots of commands (specially the ones that don't exist in III/VC) need tweaking of static information.

Some of the issues:

  • Out parameters aren't marked as var-only
  • Entity information is missing
  • Enum information is missing

Keep track of entity types stored in variables

miss2 doesn't allow a different entity type to be assigned to a variable, for example:

VAR_INT var
CREATE_CAR 400 0.0 0.0 0.0 var
CREATE_CHAR 4 1 0.0 0.0 0.0 var   // error: Variable has already been used to create a entity of a different type
TERMINATE_THIS_SCRIPT

Define Constants

Implement a mechanism (a pseudo-command) to define constants.

San Andreas probably implemented it with CONST_INT, CONST_FLOAT and/or CONSTANT_INT, but it's too risky to assume anything about those commands. Better create a new one.

REQUIRE

Add a pseudo-command (REQUIRE) which adds a extension script to the compilation process, much like GOSUB_FILE, except without generating a command or calling anything.

SKIP_CUTSCENE

Add a compiler switch, and implement SKIP_CUTSCENE_START and SKIP_CUTSCENE_END directives. Only allow it's use in guesser mode.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.