-
Notifications
You must be signed in to change notification settings - Fork 0
Variables
The scripts can define, set and read variables within the game. They can be used to branch the story depending on the user's choices or to unlock features in the menu.
Variables are used together with the two opcodes set and if. They both accept simple logical and mathematical operations, where set expects an assignment (e.g. s_hanabi = s_hanabi + 1) while if needs a boolean expression (e.g. s_rikka >= 4 && rikka_flag == 1) and only executes the next statement if this evaluates to true.
The expressions are not stored as plain text in the compiled binaries but in a tokenized form. Each token (variable names, operators, constants) starts with the token type (4 byte integer) followed by a 16 bytes wide, 0-terminated string containing only the token itself (without spaces). This means that the total size of such an argument (containing multiple tokens) must be a multiple of 20.
Tropical Kiss seems to contain the following tokens:
| Token ID (Hex) | Description | Examples |
|---|---|---|
| 00 | Identifier |
tn_shirt, g_izumi_clear
|
| 01 | Number |
1, 2, 3
|
| 02 | + | |
| 0A | >= | |
| 0C | == | |
| 12 | = | |
| 14 | && |
Furthermore, the following tokens can be found within the compiler inside the TSSystem.exe binary:
| Token ID (Hex) | Description | Examples |
|---|---|---|
| && | ||
| || | ||
| += | ||
| -= | ||
| /= | ||
| *= | ||
| %= | ||
| <= | ||
| >= | ||
| != | ||
| == | ||
| - | ||
(Whitespace) |
||
| < | ||
| > |
This are only the used ones, reversing the script compiler should reveal the remaining tokens.
Fun fact: in the original Scenario.dat files, the filler bytes of the tokens (after the null-terminator) didn't get nulled, so you can probably see some memory of the compiler leaked here.
Every variable prefixed with g_ (e.g. the ending flags like g_hanabi_clear) is treated as a global (savegame independent) variable. These variables can be accessed from every save file and are stored under %APPDATA%\Twinkle\TropicalKiss\global.sav. The format of this file is trivial:
int32 var_count
for i = 0 to var_count:
int32 name_length
char name[name_length]
int32 value