sannybuilder / dev

Sanny Builder Bug Tracker and Roadmap development
https://sannybuilder.com
48 stars 0 forks source link

Support long strings for LCS #183

Open XMDS opened 2 years ago

XMDS commented 2 years ago

Since the parameter type (1 byte) of LCS is fully occupied:

enum eLCSScriptParameterType
{
    ARGUMENT_END = 0,
    ARGUMENT_INT_ZERO,
    ARGUMENT_FLOAT_ZERO,
    ARGUMENT_FLOAT_1BYTE,
    ARGUMENT_FLOAT_2BYTES,
    ARGUMENT_FLOAT_3BYTES,
    ARGUMENT_INT32,
    ARGUMENT_INT8,
    ARGUMENT_INT16,
    ARGUMENT_FLOAT,
    ARGUMENT_TIMERA,
    ARGUMENT_TIMERB,
    ARGUMENT_LOCAL = 12,//12 = 0@ --- 107 = 95@
    ARGUMENT_LOCAL_ARRAY = 108, //108 = 0@[0] --- 0@[95] = 203
    ARGUMENT_GLOBAL = 204, //26 NUM_GLOBAL_SLOTS
    ARGUMENT_GLOBAL_ARRAY = 230, //26 NUM_GLOBAL_SLOTS_ARRAY
}
XMDS commented 2 years ago
Application has crashed, here's a log:
Current process ID: 10384
Current thread ID: 10465
Exception address: 0x00004E8E (module not found)
Exception signal: 7 (SIGBUS)
Exception code: 0x1 (BUS_ADRALN)

General registers:
R0 : 0x00000000 (0)
R1 : 0x00000000 (0)
R2 : 0x00004E4E (20046)
R3 : 0xEA32D1C0 (-365768256)
R4 : 0xD7FDC780 (-671234176)
R5 : 0xD7D4F810 (-673908720)
R6 : 0xBE8F9F40 (-1097883840)
R7 : 0xD7FC7578 (-671320712)
R8 : 0xD7FDC798 (-671234152)
R9 : 0xC2070294 (-1039727980)
R10: 0xC2070294 (-1039727980)
R11: 0xBE8F9FA4 (-1097883740)
R12: 0x00413000 (4272128)
SP : 0xBE8F9F30 (-1097883856)
LR : 0xD78EB8A0 (-678512480)
PC : 0xD78F4384 (-678476924) ["libGTALcs.so"+0x2F4384]
PSR : 0x20800010 (545259536)

It is best not to use string pointers. It is inevitable to make LCS support long strings, because the use of pointers will cause "memory byte misalignment" errors

for: https://github.com/sannybuilder/dev/issues/36

Since the game loads the script to a different address every time, this problem occurs when the hex static memory space is used as a function parameter. This is very unfriendly to script writers, because most script writers don’t understand why the game crashes

XMDS commented 2 years ago

About lcs long strings. Since the parameter type value 1 byte (0-255) is completely occupied, it is not reliable to detect the parameter type by the parameter type value. It is recommended that long strings do not need two bytes of parameter type value and string length, and the first byte of the string parameter should be the first character by default.

Maybe the compiler should provide a standard. When the string is larger than 8 bytes, the default is to process the string as a long string and add a terminator to the last byte

'gtalcs' short string(max 7 byte + 00)
hex
67 74 61 6C 63 73 00 00
end

"gtalcsx…" long string
hex
67 74 61 6C 63 73 78 00 …
end
XMDS commented 2 years ago

GTA3/VC:

.short string: ascii + 00

GTA3 VC SA big long string: type + length + ascii

SA: long string: type + ascii + 00 //max 15

short string: type + ascii +00 // max 7

XMDS commented 2 years ago

The NewCommands project adds new opcode commands for LCS to read strings using pointers:

0DD0: 0@ = get_label_addr @str
0ACA: show_text_box 0@

:str
hex
"GTALCS" 00
end

For long string arguments it will additionally have 1 new opcode command to get the string pointer:

0AFA: 0@ = get_string_pointer "GTALCS"
0ACA: show_text_box 0@

They only use the address to save to the variable. There will be no extra string literal commands