PSX modding (scripts decompiled, PSX compiler, STY tiles, GMP files etc.)

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
Post Reply
User avatar
valps
Psycho
Psycho
Posts: 60
Joined: 31 Dec 2020, 15:03
GH nick: Valps
Location: Brazil
Contact:

PSX modding (scripts decompiled, PSX compiler, STY tiles, GMP files etc.)

Post by valps »

In PC version of GTA2, hex data of commands of scripts in .scr starts at offset 0x2EE0. You can see that in T.M. decompiler code:

Code: Select all

const int max_base_pointers = 6000;
const int max_base_pointers_size = max_base_pointers*sizeof(uint16_t);
Since sizeof(uint16_t) = 2, then max_base_pointers_size = 12000 = 0x2EE0

The demo version "wildemo.scr" starts at a different offset, so I patched it (removing a lot of zero bytes) in order to make it start at 0x2EE0, which is the offset the decompiler works with. I managed to decompile it partially, but some variables were missing and it generated some garbage code at the end, since the decompiler seems don't knowing the actual final pointer. I didn't managed to decompile demo missions since their pointers aren't matching with base script wildemo.scr.
wildemo_patched.zip
(17.49 KiB) Downloaded 116 times
Doing a first look, I guess that the 6 minutes timer in demo version is much likely performed by gta2.exe, since I cannot see any timer being set in wildemo.scr (besides the kill frenzy ones).

The PSX offset is 0x1770, which is exactly the half of 0x2EE0, so I managed to decompile PSX scripts as well (without garbage code):
PSX_decompiled.zip
(157.75 KiB) Downloaded 129 times
Their strings (.mis names, zone names, gang names etc.) also are on different offset, so I changed on decompiler too. Due this, the .scr are completely decompiled. I managed to recompile PSX Downtown for example, although the recompiled one cannot be used on PSX because the official compiler we have is for PC (PSX will expect different offsets, so it will probably crash). With luck, maybe it's possible to change something in miss2.exe to make it compile scripts in PSX mode instead of PC, so we will unlock [jailfree] PSX modding (besides patching .scr). (EDIT: I did it. See my third post on this thread)

EDIT: I've fixed an error in PSX version of bil_zh2.mis, where a undefined gang (islagang) was used although this gang don't exist in PSX version.

Also, I've decompiled the Dreamcast scripts:
Dreamcast_decompiled.zip
(173.89 KiB) Downloaded 114 times
EDIT: I got it! All PSX tiles!

All PSX tiles embedded in .sty files, ready to use in map editor:
PSX_sty.zip
(5.91 MiB) Downloaded 30 times
All PSX tiles in individual 64x64 .bmp files:
PSX_Tiles_64x64_fixed.zip
(1.48 MiB) Downloaded 33 times
All PSX gmp maps converted:
PSX_maps.zip
(551.74 KiB) Downloaded 26 times
Last edited by valps on 17 Feb 2025, 19:49, edited 8 times in total.
User avatar
valps
Psycho
Psycho
Posts: 60
Joined: 31 Dec 2020, 15:03
GH nick: Valps
Location: Brazil
Contact:

Re: PSX scripts decompiled (and partially Demo)

Post by valps »

I've tried to hack miss2.exe in order to make it decompile in PSX mode but I wasn't successful. There is another way, which is creating a new program in C++ that can remove some zero bytes from the PC recompiled scripts so they will have the same size of PSX scripts.

I also have tried to make PSX gmp openable in map editor by patching the files and make them as similar as possible with PC versions, but I wasn't successful (again). There is the file patched if anyone wants to try to do it. It does have a GBMP header and all PSX terminators (AA AA) removed.

EDIT: I got all PSX maps.
Last edited by valps on 17 Feb 2025, 19:48, edited 2 times in total.
User avatar
valps
Psycho
Psycho
Posts: 60
Joined: 31 Dec 2020, 15:03
GH nick: Valps
Location: Brazil
Contact:

Re: PSX scripts decompiled (and partially Demo)

Post by valps »

Okay, I've patched miss2.exe to compile as if it's in PSX mode:

1 - The strings "#ifdef PC" and "#ifdef PSX" were swapped, so #ifdef PC is ignored in compilation instead of #ifdef PSX
2 - The script and string offset were reduced by half

I've tested it and it worked!

Download:
miss2_PSX_exe.zip
(237.11 KiB) Downloaded 100 times
Video:

Testing electrobaton in PSX and making fun with script:
User avatar
valps
Psycho
Psycho
Posts: 60
Joined: 31 Dec 2020, 15:03
GH nick: Valps
Location: Brazil
Contact:

Re: PSX modding (scripts decompiled, PSX compiler etc.)

Post by valps »

Open these .sty files using DMA map editor and you will be able unlock the "Playstation" tab
BIL_STE_WIL_with_PSXT.zip
(7.29 MiB) Downloaded 110 times
It's just the PC versions of wil/ste/bil.sty but includes a PSXT chunk from the PSX versions of wil/ste/bil.sty

I want to export all PSX tiles into BMP files. There is all PSX tiles in binary data
PSX_tiles_binary.zip
(785.17 KiB) Downloaded 107 times
Contains the tiles themselves and their respective palettes binaries.

EDIT: Some useful info:

- Palette offset starts after 0x8000 bytes of each 256x256 page of 64 tiles.
- The palette has the size 0x800 bytes. After it another 256x256 page of 64 tiles starts.

I've found that the palettes have these settings (using MummGGTool):

- Panel size: Width: 256, Height: 64
- Colour order: BGR
- 15 bits colours
- Pixel format: Linear Indexed (with Pal), 4 bpp, little endian

Each PSX tile has its own 16-colours palette, so extracting them manually will take much time.

Image:
ste_psx_tiles.jpg
User avatar
B-$hep
Immortal
Posts: 583
Joined: 24 Apr 2009, 21:43
GH nick: B-Shep
Location: EU

Re: PSX modding (scripts decompiled, PSX compiler, STY tiles etc.)

Post by B-$hep »

Where did you run the map editor?

I mean the map editor has tile picker rendering problem on XP and newer Windows.
You seem to have all rendered.

How?
Always wear safety glasses while programming.
User avatar
valps
Psycho
Psycho
Posts: 60
Joined: 31 Dec 2020, 15:03
GH nick: Valps
Location: Brazil
Contact:

Re: PSX modding (scripts decompiled, PSX compiler, STY tiles etc.)

Post by valps »

B-$hep wrote: 19 Nov 2024, 17:34 Where did you run the map editor?

I mean the map editor has tile picker rendering problem on XP and newer Windows.
You seem to have all rendered.

How?
Nah, I just selected these tiles in reverse order just to show PSX tiles. If I go to any other column, white tiles will appear again.
valps wrote: 16 Nov 2024, 21:44 Open these .sty files using DMA map editor and you will be able unlock the "Playstation" tab

...
All PSX tiles but on 16-colour greyscale palette. Also it has all original 16-colour RGB palettes, so theorically one can restore the original colours since there is a biunivocal equivalence between them.
PSX_tiles_gry_palettes.zip
(514.82 KiB) Downloaded 100 times
User avatar
B-$hep
Immortal
Posts: 583
Joined: 24 Apr 2009, 21:43
GH nick: B-Shep
Location: EU

Re: PSX modding (scripts decompiled, PSX compiler, STY tiles etc.)

Post by B-$hep »

I did a fix years ago for tile picker.
It would allow DMA editor to work on modern systems.
But I dont remember atm why I stopped.
I think I encountered some issues and didnt know how to resolve it.

Now we have ChatGPT, which should resolve them
Always wear safety glasses while programming.
Francis09
Ped
Ped
Posts: 3
Joined: 01 Jan 2025, 16:38
GH nick: Francis Bianco

Re: PSX modding (scripts decompiled, PSX compiler, STY tiles etc.)

Post by Francis09 »

Hi everyone, im playing GTA 2 to 100% but the trailer kill frenzy's make crash the game when i reload the save game...but i make another versión of GTA 2 with the same save game but the archive "BIL.SCR" not have the "3C01" bits of "PUT_THE_CAR_ON_TRAILER" or something like that. :idea:

It works but the problem is the music, the music doesn't' work and the Playstation logo doesn't appear. :?

The rest is fine, how i can fix the music at least? :?:

greetings from argentina (im new and sorry for my Bad English :v)
Last edited by Francis09 on 01 Jan 2025, 16:47, edited 1 time in total.
[russia] :v
User avatar
valps
Psycho
Psycho
Posts: 60
Joined: 31 Dec 2020, 15:03
GH nick: Valps
Location: Brazil
Contact:

Re: PSX modding (scripts decompiled, PSX compiler, STY tiles etc.)

Post by valps »

I managed to restore the original palettes from the binaries using python. Here are the pages:

I will slice them into individual bmp tiles soon.

EDIT: I've finally extracted all PSX tiles individually.

EDIT2: I've embedded all PSX tiles into STY files. They are ready to use in map editor. Download is on the first post.

Python code: https://github.com/Valps/gta2-psx-tile-converter
User avatar
valps
Psycho
Psycho
Posts: 60
Joined: 31 Dec 2020, 15:03
GH nick: Valps
Location: Brazil
Contact:

Re: PSX modding (scripts decompiled, PSX compiler, STY tiles etc.)

Post by valps »

All PSX maps:
PSX_maps.zip
(551.74 KiB) Downloaded 25 times
Includes all PSX zones and animations.

Source code of the PSX map converter: https://github.com/Valps/gta2-psx-gmp-converter
User avatar
JernejL
Hitman
Hitman
Posts: 174
Joined: 21 Feb 2010, 22:03
GH nick: RedShirt

Re: PSX modding (scripts decompiled, PSX compiler, STY tiles, GMP files etc.)

Post by JernejL »

is there any difference in sty file format for ps2? do those style files not just open in my gta2 style editor?
User avatar
valps
Psycho
Psycho
Posts: 60
Joined: 31 Dec 2020, 15:03
GH nick: Valps
Location: Brazil
Contact:

Re: PSX modding (scripts decompiled, PSX compiler, STY tiles, GMP files etc.)

Post by valps »

JernejL wrote: 18 Feb 2025, 11:43 is there any difference in sty file format for ps2? do those style files not just open in my gta2 style editor?
All chunk headers (their positions in the file and their size) are missing in PSX sty file, but they can be found at another separated file called GAME.OVL. Their size do not include the padding bytes, which makes it a bit more difficult to locate the data in the hex editor.

It's a bit strange because the PSX gmp files have their headers in them.

Some PSX chunks don't exists in the PC version (such as OVLY and REPL) and vice-versa (the TILE chunk is replaced by PSXT for example).

All PSX headers:

Code: Select all

SPRB
FONB
CARU
SPEC
RECY
REPL
PALX
OBJI
SPRX
PALB
CARI
OVLY
SPRG
PPAL
PSXT
The PSXT chunk was used to be in the PC versions of .sty during game development but was removed later before release. The DMA map editor can read this chunk (if you inject the PSXT chunk into PC .sty files) which enables the "Playstation" tab and its features, such as viewing the map using the PSX tiles and do remapping between PC tiles and PSX tiles.
User avatar
valps
Psycho
Psycho
Posts: 60
Joined: 31 Dec 2020, 15:03
GH nick: Valps
Location: Brazil
Contact:

Re: PSX modding (scripts decompiled, PSX compiler, STY tiles, GMP files etc.)

Post by valps »

The CMAP chunk of PSX gmp files written in C, if anyone is interested:

Code: Select all

struct block_info
{
 UInt16 left, right, top, bottom, lid;
 UInt8 arrows;
 UInt8 slope_type;
};

struct partial_block_info
{
 UInt16 lid;
 UInt8 arrows;
 UInt8 slope_type;
};

struct psx_compressed_map
{
 UInt16 base [256][256];
 UInt16 column_words;
 UInt16 column[size: column_words];
 UInt16 padding_1[512];
 UInt16 num_complete_blocks;	//  blocks with at least 1 non-null side
 block_info blocks_1[size: num_complete_blocks];
 UInt16 padding_2[768];	  //  768 = 0x600 bytes / 2
 UInt16 num_partial_blocks;		//  blocks without sides
 partial_block_info blocks_2[size: num_partial_blocks];   
};

struct column_info
{
 UInt8 height;
 UInt8 offset;
 UInt16 blockd[size: height - offset];
};

//  if blockd[...] < 32768, then it stores the index of "blocks_1".
//  if blockd[...] >= 32768, then (it - 32768) stores the index of "blocks_2".

Post Reply