/OpenAdhoc

Open-source re-implementation of Gran Turismo Scripts

Primary LanguageCGNU General Public License v3.0GPL-3.0

OpenAdhoc

OpenAdhoc is an open-source re-implementation of the proprietary "Adhoc" scripting language used in Gran Turismo games. OpenAdhoc allows logic-based modding as seen on the GT6 Spec II Mod and GT4 Randomizer/Spec II, among other fan projects currently in development.

This repository contains compilable game scripts re-created from originally compiled ones. This allows source-code level editing for scripts that have been successfully reverse-engineered in Adhoc-based GT games.
GT4 Prologue, GT4, Tourist Trophy, GT HD, GT5 Prologue, GTPSP, GT5, GT6, GT Sport, and all games in between them are in the scope of OpenAdhoc.

Scripts operate nearly as the whole of game logic, while the executable mostly serves as the engine and exposes libraries to the script interface. The games use a system of "projects" to divide the major menu types. Each game mode is made out of a project folder containing the Adhoc logic script(s) (.adc), the UI definition script (.mproject), and assets: localization files, textures, models, and animations packaged into container files (.gpb).

Note

This code is licensed under GPL-v3. You are required to disclose source/changes including for mods.

Modified versions of OpenAdhoc for fan projects such as GT6 Spec II & GT5 Master Mod are required to be uploaded to a separate fork.

๐ŸŽฎ Games & Progress

Tip

Percentage/Progression is relative to the overall amount of lines that have been reversed.

[โŒ๏ธ] Demos & Misc. builds
GT4 Prologue Era
GT4 Prologue Subaru Version

No progress.

GT4 Prologue E3 2003

No progress.

GT4 Prius Trial Version

No progress.

GT Special Edition 2004 Geneva Edition

No progress.

GT Special Edition 2004 Toyota Demo

No progress.

GT4 Era
GT4 E3 2004

No progress.

GT4 BMW 1 Series Virtual Drive

No progress.

GT4 Tokyo Game Show 2004

No progress.

GT4 First Preview

No progress.

GT4 - Mazda MX-5 Edition Demo

No progress.

Tourist Trophy Era
Tourist Trophy Store Demo

No progress.

GT HD Era
GT HD E3 2006

No progress.

GT HD Tokyo Game Show 2006

No progress.

GT HD Premium Subaru Impreza Rally Car '99

No progress.

GT HD Le Mans 2007

No progress.

GT HD Nissan Xanavi Nismo Z

No progress.

GT HD "Wedding Version"

No progress.

GT5 Prologue Era
GT5P Games Convention 2007

No progress.

GT5P Tokyo Games Show 2007

No progress.

GT5P Tokyo Motor Show 2007

No progress.

GT5P Free Trial Version

No progress.

GT5P Spec-I (December '07 JP release)

No progress.

GT5P Spec II Nรผrburgring Special Edition 2008

No progress.

GT5P Games Convention 2008

No progress.

GT5P Special Event Version GT by Citroรซn

No progress.

GT5P DOME S102 '08

No progress.

GT5P Le Mans Special Edition '09

No progress.

GT PSP Era
GT PSP E3 2009

No progress.

GT PSP E3 2009

No progress.

GT PSP Gamescom 2009

No progress.

GT PSP Tokyo Games Show 2009

No progress.

GT5 Era
GT5 Gamescom 2009

No progress.

GT5 Tokyo Games Show 2009

No progress.

GT5 Tokyo Motor Show 2009

No progress.

GT5 Time Trial Challenge

No progress.

GT5 CES Demo

No progress.

GT5 SLS Demo

No progress.

GT5 Nรผr 2010 Demo

No progress.

GT5 24 Heures du Mans Demo

No progress.

GT5 E3 2010 Demo

No progress.

GT5 Kiosk Demo

No progress.

GT5 Gamescom 2010

No progress.

GT5 Tokyo Games Show 2010

No progress.

GT5 QA Build

No progress.

GT Academy 2012

No progress.

GT6 Era
GT Academy 2013

No progress.

GT E3 2013

No progress.

GT6 Gamescom 2013

No progress.

GT6 Tokyo Games Show 2013

No progress.

GT6 Toyota S-FR Build

No progress.

GT Sport Era
GT Sport E3 2016

No progress.

GT Sport Gamescom 2016

No progress.

GT Sport Essen Motorshow Demo

No progress.

GT Sport Closed Beta Test Version

No progress.

GT Sport Open Beta

No progress.

GT Sport MEGAWEB GR ZONE

No progress.

GT Sport TGS2017 VR Support

No progress.

[๐Ÿšง] GT4 Prologue (40%)

GT4 Prologue

Adhoc Version: 5
5 of 11 projects are completed and can be compiled.
No progress has been made currently.

Name Completed Purpose
language โœ”๏ธ Language selection menu
memcard โœ”๏ธ Save file Load/Save, Load/Save replay, etc.
option โŒ๏ธ A hidden menu that contains advanced settings, primarily networking
option2 โœ”๏ธ Options menu
prize โŒ๏ธ Prize screen when unlocking a new car
prologue โŒ๏ธ School mode and its sub-menus
prologue_arcade โŒ๏ธ Arcade mode and its sub-menus
prologue_opening โŒ๏ธ Opening movie handler
quick โœ”๏ธ Pre-race menu for School mode
quick-arcade โŒ๏ธ Pre-race menu for Arcade mode
GT4Application โœ”๏ธ Initializer and Config Script loader / re-loader
[โœ…] GT4 (100%)

GT4

Adhoc Version: 7 (v5-7 compatible)
All 29 projects are completed and can be compiled.
There are 2 collections of shared scripts (share and quick-share) that multiple projects use.
There are 10 leftover projects from GT4P and retail GT4 that are not relevant.

Name Purpose
arcade Arcade mode and all of its sub-menus
boot Bootup, Language select, new game setup, initial intro movie
cursor Sets up cursor and dialog boxes
demo_movie Intro when idle at main menu, and any movie that plays after completing event
eyetoy Handles unlocking Nike Car when scanning GT Shirt with the Eyetoy accessory
gtmode Gran Turismo Mode and all of its sub-menus
labomode Photo lab, Replay Theater, Load & Save Replay, Delete Replay/Film/Photo
logger Replay Analyzer menu, accessed from various Pre-Race menus
message Online mode message menu
network (GT4 Online) Network Connection and Online mode login
network (GT4 Retail) Network Connection for LAN Battle mode. Returns to arcade project once established. Also contains some unused menu pages
online (GT4 Online) Online mode
option Game Options
photo_save Photo preview and save for Photo Drive
photo_shoot Photo mode camera menu, photo preview and save for Photo Travel
print Print menu, accessed from Photo Lab
quick-arcade Arcade mode Single Race Pre-Race menu
quick-championship GT Mode Championship Pre-Race menu
quick-event GT Mode Single Race, Practice, and Family Cup Pre-Race menu
quick-freerun GT Mode Photo Drive Pre-Race menu
quick-license GT Mode License test Pre-Race menu
quick-mission GT Mode Mission Pre-Race menu
quick-mt GT Mode Power & Speed Pre-Race menu
quick-online Online Mode Pre-Race menu
quick-practice GT Mode Track Meet Pre-Race menu
quick-tt Arcade Mode Time Trial Pre-Race menu
setting Car Setting menu and all of its sub-menus (Change parts and tuning sliders)
slide Slideshow mode
GT4Application Initializer and Config Script loader / re-loader
-------- ---- Stub projects: ----
event Unused project that appears to be a mode used on demo setups for public events. Seems non-functional.
ranking Online leaderboards, accessed from Event project
message (GT4 Retail) Message handler for the stub Online mode. (Compilable if GT4O_US_BETA define is absent in the YAML)
online (GT4 Retail) An earlier and unused implementation of online mode, works similarly to GT4 Online's version
language Leftover from GT4P's language select. Contains more language options, appears to be a dev version
list_box Leftover from GT4P's Save/Delete Replay menu. Possibly contains framework for an unused save icon customizer
memcard GT4P leftover
option2 GT4P leftover
option3 GT4P leftover
quick GT4P leftover
[โŒ๏ธ] Tourist Trophy

Tourist Trophy

Adhoc Version: 7
There are 22 projects.
There are 2 collections of shared scripts (share and quick-share) that multiple projects use.
No progress has been made currently.

Name Completed Purpose
arcade โŒ๏ธ Arcade mode and all of its sub-menus
bestshot โŒ๏ธ
boot โŒ๏ธ Bootup, new game setup, initial intro movie
cursor โŒ๏ธ Sets up cursor and dialog boxes
demo_movie โŒ๏ธ Intro when idle at main menu, and any movie that plays after completing event
labomode โŒ๏ธ Photo lab, Replay Theater, Load & Save Replay, Delete Replay/Film/Photo
option โŒ๏ธ Game Options
photo_save โŒ๏ธ Photo mode
print โŒ๏ธ
quick-arcade โŒ๏ธ
quick-challenge โŒ๏ธ
quick-championship โŒ๏ธ
quick-event โŒ๏ธ
quick-freerun โŒ๏ธ
quick-license โŒ๏ธ
quick-photo โŒ๏ธ
quick-practice โŒ๏ธ
quick-tt โŒ๏ธ
setting โŒ๏ธ Bike Setting menu and all of its sub-menus (Change parts and tuning sliders)
slide โŒ๏ธ Slideshow mode
ttmode โŒ๏ธ Tourist Trophy mode and all of its sub-menus
GT4Application โŒ๏ธ Initializer and Config Script loader / re-loader
[โŒ๏ธ] GT HD

GT HD

Adhoc Version: 10 (v8-10 compatible)
There are 7 projects.
There are 2 collections of shared scripts (share and quick-share) that multiple projects use.
No progress has been made currently.

Name Completed Purpose
boot โŒ๏ธ
cursor โŒ๏ธ
demo_movie โŒ๏ธ
option โŒ๏ธ
quick-arcade โŒ๏ธ
trial โŒ๏ธ
GT4Application โŒ๏ธ Initializer and Config Script loader / re-loader
[โŒ๏ธ] GT5 Prologue

GT5 Prologue

Adhoc Version: 10
No progress has been made currently.

[โœ…] GT PSP (gt5m) (100%)

GT PSP (gt5m)

Adhoc Version: 12
All projects and scripts fully reversed by pez2k โœ”๏ธ
Adhoc code is identical for all regions and revisions.

[๐Ÿšง] GT5 (2.11) (>=25%)

GT5

Adhoc Version: 12
GT5 2.11 is prefered over 2.17 due to 2.12<->2.17 having no extra content, and mainly patches exploits/server use and other minor things.

Name Completed Purpose
main โœ”๏ธ Initial Bootstrap & Utils before boot
arcade โœ”๏ธ Arcade Mode
academy โŒ N/A
boot โœ”๏ธ Boot Project (logic is in bootstrap scripts)
concept โŒ N/A
config โŒ N/A
cursor โŒ N/A
demo_movie โŒ N/A
dialog โŒ N/A
gps_replay โŒ N/A
gtauto โŒ N/A
gtmode โŒ N/A
gttop โœ”๏ธ Main Menu
gttv โŒ N/A
gttv2 โŒ N/A
leavedemo โŒ N/A
manual โŒ N/A
multimonitor โŒ N/A
museum โŒ N/A
news โŒ N/A
online โŒ N/A
online_bspec โŒ N/A
option โŒ N/A
photo โŒ N/A
play_movie โŒ N/A
race โŒ N/A
race_* โŒ N/A
ranking โŒ N/A
rcvtst โŒ N/A
setting โŒ N/A
ui_kit โŒ N/A
user_profile โŒ N/A
user_profile_driver โŒ N/A

[๐Ÿ”ง] GT6 (1.22) (>=70%)

GT6

Adhoc Version: 12
26 of 49 projects are completed and can be compiled

Name Completed Purpose
main โœ”๏ธ Initial Bootstrap & Utils before boot
arcade โœ”๏ธ Arcade Mode
boot โœ”๏ธ Boot Process handling (Game Start to main project i.e gtmode or dev_runviewer
config โœ”๏ธ Game Save Nodes Creation
community โœ”๏ธ Community/Online Features Menu (Clubs, TimeLine, Bbs, etc)
cursor โœ”๏ธ Cursor handling & Top Menu
datalogger โŒ Car Data Logger Menu
dev_design_work โœ”๏ธ UI Showcasing (1.00)
dev_runviewer โœ”๏ธ Developer Tools
dev_sound โœ”๏ธ Sound Engineering Develop Tools
dev_test_sequence โŒ Unknown Dev Tools
develop โœ”๏ธ Cheat/QA Menu for gtmode
dialog โŒ UI Components for Dialogs
event_setting โŒ Settings Menu for Editing Lobby Options
garage โœ”๏ธ Garage Manager
gps_replay โŒ GPS Replay
gtmode โœ”๏ธ GT Mode. Everything before loading into an event/race.
gtauto โœ”๏ธ GT Auto
gttv โŒ Stub Leftover from GT5
leavedemo โœ”๏ธ Idle demonstration project
manual โœ”๏ธ Manual Menu & Credits
multimonitor โœ”๏ธ Multimonitor Handler Project
option โœ”๏ธ Game Settings Menu
photo โœ”๏ธ Photo Mode Handler
play_movie โœ”๏ธ Intro Movie Player Project
race โœ”๏ธ Main Race Project & Base
race_arcade_style โŒ Sierra Time Rally game mode plugin
race_course_edit โŒ Custom Track Test & Uploader game mode plugin
race_drag โŒ Left-over Drag game mode plugin
race_drift โŒ Drift game mode plugin
race_freerun โœ”๏ธ Free-Run game mode plugin
race_license โœ”๏ธ License game mode plugin
race_mission โœ”๏ธ Mission game mode plugin
race_online_drift โŒ Seasonal Drift Event game mode plugin
race_online_event โŒ Online Quickmatch Event game mode plugin
race_online_room โœ”๏ธ Online Lobby game mode plugin
race_online_single โŒ Seasonal Event game mode plugin
race_online_timeattack โŒ Seasonal Time Trial game mode plugin
race_single โŒ Event game mode plugin
race_split โŒ Split-Screen game mode plugin
race_tutorial โŒ Tutorial game mode plugin
race_timeattack โœ”๏ธ Time Trial game mode plugin
ranking โŒ Rankings/Leaderboard Handler Project
setting โŒ Car Parameters/Tuning Menu
ui_kit โœ”๏ธ Generic UI Components Project
ui_kit_sub โŒ Unknown
vision_gt โŒ Vision GT Menu
[โŒ] GT Sport (gt7sp)

GT Sport (gt7sp)

Adhoc Version: 12
Only the boot project (1.00) reversed.

[๐Ÿ›‘] GT7

GT7

Out of scope. GT7 no longer uses Adhoc language and instead uses Swift (custom parser & compiler) which is then compiled to adhoc bytecode.

Note

Original bugs are left as is. You can find any that have been identified with the // BUG comments.

Matching notes are usually found starting with // NOTE or // COMPILER NOTE.

โš™๏ธ Compilation

Adhoc Toolchain version 1.3.3 is required to compile game scripts. The tool itself is command line-based without a native GUI, however it does have a VS Code Extension, and a Python GUI wrapper for streamlined usage / workflow.

Tip

Adhoc Toolchain (i.e adhoc.exe) can be added to your PATH (Optional)

๐Ÿ”ง Compilation process:

  • adhoc build -i path:\to\.yaml\project\file -o path:\to\output\.adc\file
    or
  • adhoc build -i path:\to\.ad\source\file -o path:\to\output\.adc\file -v Adhoc Version (5,7,10,12, etc.)
    or
  • "Run Build Task (CTRL+SHIFT+B)" with the VS Code Adhoc Extension on any source file or project file.
    or
  • Use the Python wrapper script for a straightforward GUI to send commands to the program.

For more details refer to the Adhoc Page on the Modding Hub.

๐Ÿ“‹Contributing & Notes

1. Disassembly

  • To contribute to OpenAdhoc, the 1st step is to disassemble an original adhoc script (.adc), arriving at an intermediate translation of the bytecode that is understandable enough to convert into full source code.
  • The Adhoc toolchain allows disassembling scripts into an assembly-like text form. Most scripts contain symbols which are mandatory and thus allows reconstructing code back into source. Very rarely did syntax have to be made up to support specific adhoc features due to no original source reference, so the documentation is the code.
  • To disassemble a script, run the following command: adhoc path:\to\.adc\file

2. Decompilation

Translation

  • Understanding how to read the disassembly can be challenging at first. Compare reversed scripts against their corresponding disassembly code to learn.
  • Translating by hand is very time-consuming. If you have the patience, you can train an AI model to translate the disassembly for you by having it help you edit code that's already translated, and attempt to have it decompile disassembly every so often.
  • The key to training it is providing a lot of adhoc source code, and over many separate chats over time. It needs to learn the format of adhoc much moreso than the disassembly.
  • This can take a very long time before it gets any good, but if it does it can make short work of even the largest scripts.
๐Ÿ“ Translation example (Expand to view)

Disassembly:

1A4E| 118| 30| FUNCTION_DEFINE - onActivate(context)
// FUNCTION_DEFINE means we are beginning a new function. we write function onActivate(context) {
> Instruction Count: 43 (1A7F)
> Stack Size: 6 - Variable Heap Size: 7 - Variable Heap Size Static: =Variable Heap Size
1A87| 109| 0| VARIABLE_PUSH: Slide,slide,Slide::slide, Static:2
// The 1st piece of relevant code is Slide::slide
// making this the start of the 1st line of code inside this function.
1AB0| 109| 1| EVAL
1AB5| 109| 2| ATTRIBUTE_PUSH: isPlaying
// attributes are represented by period . so now we have Slide::slide.isPlaying
1AC5| 109| 3| EVAL
1ACA| 109| 4| CALL: ArgCount=0
// we now know there's arguments with CALL: ArgCount. In this case it's 0 so we will now have Slide::slide.isPlaying()
1AD3| 109| 5| EVAL
1AD8| 109| 6| UNARY_OPERATOR: ! (!)
// We don't know how this is used quite yet, for now we hold onto that
1AE0| 109| 7| JUMP_IF_FALSE: Jump To Func Ins 39
// Now we know. Jump if false is a standard if() statement. So now our 1st line of code is complete: if (!Slide::slide.isPlaying()) {
1AE9| 110| 8| NOP
1AEE| 111| 9| VARIABLE_PUSH: main,sound,main::sound, Static:3
// Now inside the if statement, our 2nd line of code begins. So far we have main::sound
1B15| 111| 10| EVAL
1B1A| 111| 11| ATTRIBUTE_PUSH: play
// attribute for main::sound, now we have main::sound.play
1B25| 111| 12| EVAL
1B2A| 111| 13| STRING_CONST: ok
// A string! these are represented by quotes "". For now we don't know how this is used. Save for later.
1B33| 111| 14| CALL: ArgCount=1
// With the argument here we now know: main::sound.play("ok")
1B3C| 111| 15| EVAL
1B41| 111| 16| POP_OLD
// *POP_OLDs incidcate the end for a line of code, so the 2nd line is done
// and since it isn't an if or a switch case, we finish it off with semicolon: main::sound.play("ok");
1B46| 112| 17| VARIABLE_PUSH: Slide,slide,Slide::slide, Static:2
// Now on the 3rd line starting with Slide::slide
1B6F| 112| 18| EVAL
1B74| 112| 19| ATTRIBUTE_PUSH: doPlay
// Now we have Slide::slide.doPlay
1B81| 112| 20| EVAL
1B86| 112| 21| CALL: ArgCount=0
// *Now we have Slide::slide.doPlay()
1B8F| 112| 22| EVAL
1B94| 112| 23| POP_OLD
// Cap it off with semicolon: Slide::slide.doPlay();
1B99| 113| 24| VARIABLE_PUSH: sensitive,sensitive, Static:4
// 4th line: sensitive
1BBC| 113| 25| EVAL
1BC1| 113| 26| CALL: ArgCount=0
// Now we have sensitive()
1BCA| 113| 27| EVAL
1BCF| 113| 28| POP_OLD
// *Confirms the end of line 4, cap it off with semicolon
1BD4| 114| 29| VARIABLE_PUSH: SlideRoot,SlideRoot, Static:5
// 5th line: SlideRoot
1BF7| 114| 30| EVAL
1BFC| 114| 31| ATTRIBUTE_PUSH: setFocus
// Now we have SlideRoot.setFocus
1C0B| 114| 32| EVAL
1C10| 114| 33| VARIABLE_PUSH: Stop,Stop, Static:6
// Don't know what to do with Stop just yet
1C29| 114| 34| EVAL
1C2E| 114| 35| CALL: ArgCount=1
// *Now we do: SlideRoot.setFocus(Stop)
1C37| 114| 36| EVAL
1C3C| 114| 37| POP_OLD
// Cap it off with semicolon
1C41| 115| 38| NOP
// As per the jump instruction from earlier, we have now exited the if statement and need to cap it off with the other end of the curly bracket }.
1C46| 117| 39| INT_CONST: 2 (0x02)
1C4F| 117| 40| POP_OLD
1C54| 117| 41| SET_STATE_OLD: State=RETURN (1)
// This particular bundle of code means we are returning something specific. In this case
// we are returning 2 (return 2;) however the correct interpretation is EVENTRESULT type 2,
// which is EVENTRESULT_FILTER. so the correct translation is return EVENTRESULT_FILTER;.
// This is commonly seen on functions that involve canceling things and going backward.
1C5A| 118| 42| SET_STATE_OLD: State=RETURN (1)
// The compiler automatically handles the final return on any function, so these are not written.

Translated:

function onActivate(context)
{
    if (!Slide::slide.isPlaying())
    {
        main::sound.play("ok");
        Slide::slide.doPlay();
        sensitive();
        SlideRoot.setFocus(Stop);
    }

    return EVENTRESULT_FILTER;
}

--- End Translation Example ---

Things that are okay to discard

  • Following line numbers - attempting to follow line numbers for code that may be stripped from undefined original preprocessor directives or missing comment blocks can leave holes in the source, therefore prefered not to follow line numbers for better readability.
  • Logic order - It is common that scripts were written using such pattern: nil != myObject or "Dog" == myString. For readability, literals should always be on the right-hand side such as myObject != nil.

Things that should be preserved, or recommended to have

  • All code of any kind should be present in the scripts; bugs should NOT be fixed but should always be marked with a // BUG: <comment> block. An example of this is usage of undeclared variables, typos.
  • Comments to help understand code in general are not needed but appreciated.
  • Usage of PROJECT and ROOT defines should be used everywhere besides the main module declarations.
  • Usage of other defines such as EVENTRESULT and PAD defines (list here)

3. Compilation, comparison, commit

  • The 1st roadblock is squashing any mistakes in translating the disassembly if your translated code doesn't at least compile. You'll be on your own until you can get it to compile.
  • Once you successfully compile it, the next step is to revise the translated code to get it to completely match the original compiled code. To do so, disassemble both the original .adc and your new .adc. Use the included python compare script in the Toolchain's scripts folder to diff them. This will output an html file letting you view both disassemblies side-by-side. Red highlights indicate missing logic, and green highlights indicate added logic. Revise your translated code until all relevant red and green highlights from the comparison are eliminated.
  • Once your translated code is fully matching (or at least as close as possible), fork the repo, add your files to your fork, then make a pull request. In the Pull request conversation, add any relevant information about your new files. If you have any mistakes that you are unable to correct, point them out for review and suggestions.

๐Ÿ“œ History

  • August 2020 - Initial breakthrough in Adhoc, dissasembler built based on reverse-engineering
  • September 2020 - Master Mod release for GT5 with hex-edited script code edits
  • July 2021 - GT6 Spec II Mod release for GT6
  • December 2021 - Breakthrough. GT Sport Closed Beta build dump, contained a few scripts in source and compiled formats which allowed to figure most of the syntax to be similar to Javascript and Python. Stack understanding later came thanks to a random thought by ddm999 and the first custom "hello world" script compilation within the GT6 Web Server successfully ran to completion.
  • January 2022 - First fully recompiled project (boot).
  • February 2022 <-> December 2022 - Dozens of projects successfully recreated.
  • December 2022 - Source release.
  • September 2025 - GT4 and GT PSP reach 100% matching Adhoc decompilation.

Licensing

This project uses the GNU GENERAL PUBLIC LICENSE.

This project is not affiliated with "Polyphony Digital Inc." , "Gran Turismo", "GT", or any other projects by the aforementioned entities.