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

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

PSX modding (scripts decompiled, PSX compiler, STY tiles 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 41 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 43 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 42 times
Last edited by valps on 18 Nov 2024, 15:56, edited 3 times in total.
User avatar
valps
Car Jacker
Car Jacker
Posts: 42
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.
ste_gmp.zip
(161.19 KiB) Downloaded 42 times
There is the subroutine of editor.exe which look at chunk headers in IDA:
sub_411029:

loc_4111C9 - "UMAP" (uncompressed map)
loc_411299 - "CMAP" (16-bits compressed map)
loc_4113FB - "DMAP" (32-bits compressed map)
loc_411458 - "ZONE" (zones chunk)
loc_411522 - "MOBJ" (map objects chunk)
loc_41160F - "PSXM" (PSX mapping table)
loc_41165D - "ANIM" (animations chunk)
loc_4116C2 - "LGHT" (lights chunk)

PSX versions have only CMAP, ZONE, ANIM and RGEN (junctions chunk). My patched ste.gmp manages to get the first chunk header "CMAP" read but fails to reach the ZONE chunk.
User avatar
valps
Car Jacker
Car Jacker
Posts: 42
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 33 times
Video:

Testing electrobaton in PSX and making fun with script:
User avatar
valps
Car Jacker
Car Jacker
Posts: 42
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 34 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 32 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: 581
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
Car Jacker
Car Jacker
Posts: 42
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 30 times
User avatar
B-$hep
Immortal
Posts: 581
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.
Post Reply