Skip to content

Commit 1378b67

Browse files
committed
count secrets automatically
1 parent e7736e7 commit 1378b67

File tree

9 files changed

+121
-3
lines changed

9 files changed

+121
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Currently the following configuration options are supported:
5050
Action key held.
5151
- `fix_tihocan_secret_sound`: disable the secret sound incorrectly playing
5252
during using the golden key in Tomb of Tihocan.
53+
- `fix_hardcoded_secret_counts`: calculate the number of secrets based on a
54+
trigger count within a file rather than using hardcoded values.
5355

5456
## Decompilation progress
5557

Tomb1Main.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"enable_numeric_keys": true,
1313
"healthbar_showing_mode": "flashing",
1414
"fix_end_of_level_freeze": true,
15-
"fix_tihocan_secret_sound": true
15+
"fix_tihocan_secret_sound": true,
16+
"fix_hardcoded_secret_counts": true
1617
}

src/game/const.h

+4
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,9 @@
100100
#define VAULT_ANGLE (30 * ONE_DEGREE)
101101
#define HANG_ANGLE (35 * ONE_DEGREE)
102102
#define FRAME_ROT 10
103+
#define END_BIT 0x8000
104+
#define DATA_TYPE 0x00FF
105+
#define VALUE_BITS 0x03FF
106+
#define TRIG_BITS(T) ((T & 0x3FFF) >> 10)
103107

104108
#endif

src/game/types.h

+35
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,41 @@ typedef enum {
611611
RF_UNDERWATER = 1,
612612
} ROOM_FLAGS;
613613

614+
typedef enum {
615+
FT_FLOOR = 0,
616+
FT_DOOR = 1,
617+
FT_TILT = 2,
618+
FT_ROOF = 3,
619+
FT_TRIGGER = 4,
620+
FT_LAVA = 5,
621+
} FLOOR_TYPES;
622+
623+
typedef enum {
624+
TT_TRIGGER = 0,
625+
TT_PAD = 1,
626+
TT_SWITCH = 2,
627+
TT_KEY = 3,
628+
TT_PICKUP = 4,
629+
TT_HEAVY = 5,
630+
TT_ANTIPAD = 6,
631+
TT_COMBAT = 7,
632+
TT_DUMMY = 8,
633+
} TRIGGER_TYPES;
634+
635+
typedef enum {
636+
TO_OBJECT,
637+
TO_CAMERA,
638+
TO_SINK,
639+
TO_FLIPMAP,
640+
TO_FLIPON,
641+
TO_FLIPOFF,
642+
TO_TARGET,
643+
TO_FINISH,
644+
TO_CD,
645+
TO_FLIPEFFECT,
646+
TO_SECRET
647+
} TRIGGER_OBJECTS;
648+
614649
#pragma pack(push, 1)
615650

616651
typedef struct {

src/main.c

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ static int Tomb1MReadConfig()
107107
tr1m_json_get_boolean_value(json, "fix_end_of_level_freeze");
108108
Tomb1MConfig.fix_tihocan_secret_sound =
109109
tr1m_json_get_boolean_value(json, "fix_tihocan_secret_sound");
110+
Tomb1MConfig.fix_hardcoded_secret_counts =
111+
tr1m_json_get_boolean_value(json, "fix_hardcoded_secret_counts");
110112

111113
json_value_free(json);
112114
free(cfg_data);

src/mod.c

+69
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,72 @@ void Tomb1MRenderBar(int value, int value_max, int bar_type)
152152
}
153153
}
154154
}
155+
156+
int Tomb1MGetSecretCount()
157+
{
158+
int count = 0;
159+
uint32_t secrets = 0;
160+
161+
for (int i = 0; i < RoomCount; i++) {
162+
ROOM_INFO* r = &RoomInfo[i];
163+
for (int j = 0; j < r->y_size * r->x_size; j++) {
164+
FLOOR_INFO* floor = &r->floor[j];
165+
166+
int k = floor->index;
167+
if (!k) {
168+
continue;
169+
}
170+
171+
while (k < FloorDataSize) {
172+
uint16_t floor = FloorData[k++];
173+
174+
switch (floor & DATA_TYPE) {
175+
case FT_DOOR:
176+
case FT_ROOF:
177+
case FT_TILT:
178+
k++;
179+
break;
180+
181+
case FT_LAVA:
182+
break;
183+
184+
case FT_TRIGGER: {
185+
uint16_t trig_type = (floor & 0x3F00) >> 8;
186+
k++; // skip basic trigger stuff
187+
188+
if (trig_type == TT_SWITCH || trig_type == TT_KEY
189+
|| trig_type == TT_PICKUP) {
190+
k++;
191+
}
192+
193+
while (1) {
194+
int16_t command = FloorData[k++];
195+
if (TRIG_BITS(command) == TO_CAMERA) {
196+
k++;
197+
}
198+
199+
if (TRIG_BITS(command) == TO_SECRET) {
200+
int16_t number = command & VALUE_BITS;
201+
if (!(secrets & (1 << number))) {
202+
secrets |= (1 << number);
203+
count++;
204+
}
205+
}
206+
207+
if (command & END_BIT) {
208+
break;
209+
}
210+
}
211+
break;
212+
}
213+
}
214+
215+
if (floor & END_BIT) {
216+
break;
217+
}
218+
}
219+
}
220+
}
221+
222+
return count;
223+
}

src/mod.h

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct {
3131
int8_t healthbar_showing_mode;
3232
int8_t fix_end_of_level_freeze;
3333
int8_t fix_tihocan_secret_sound;
34+
int8_t fix_hardcoded_secret_counts;
3435
} Tomb1MConfig;
3536

3637
struct {
@@ -48,5 +49,6 @@ int Tomb1MGetRenderHeightDownscaled();
4849
int Tomb1MGetRenderWidthDownscaled();
4950
int Tomb1MGetRenderHeight();
5051
int Tomb1MGetRenderWidth();
52+
int Tomb1MGetSecretCount();
5153

5254
#endif

src/specific/file.c

+4
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ int32_t __cdecl S_LoadLevel(int level_id)
290290
}
291291
}
292292

293+
if (Tomb1MConfig.fix_hardcoded_secret_counts) {
294+
SecretTotals[level_id] = Tomb1MGetSecretCount();
295+
}
296+
293297
return ret;
294298
}
295299

src/specific/game.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ void __cdecl LevelStats(int level_id)
9999
"SECRETS", // TODO: translation
100100
secrets_taken,
101101
"OF", // TODO: translation
102-
SecretTotals[level_id] // TODO: calculate this automatically
103-
);
102+
SecretTotals[level_id]);
104103
txt = T_Print(0, 40, 0, string);
105104
T_CentreH(txt, 1);
106105
T_CentreV(txt, 1);

0 commit comments

Comments
 (0)