Skip to content

Commit

Permalink
add numeric keys feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Feb 13, 2021
1 parent 52b2a9b commit 58ee62e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ Currently the following configuration options are supported:
- `enable_enemy_healthbar`: enables showing healthbar for the active enemy.
- `enable_look_while_running`: allows the player to look while running, jumping
etc. (similar to TR2 style).
- `enable_numeric_keys`: enables quick weapon draws and medpack usage.
- <kbd>1</kbd>: draw pistols
- <kbd>2</kbd>: draw shotgun
- <kbd>3</kbd>: draw magnums
- <kbd>4</kbd>: draw UZI
- <kbd>8</kbd>: use small medpack
- <kbd>9</kbd>: use large medpack
- `fix_end_of_level_freeze`: fix game freeze when ending the level with the
Action key held.
- `fix_tihocan_secret_sound`: disable the secret sound incorrectly playing
Expand Down
1 change: 1 addition & 0 deletions TR1Main.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"enable_red_healthbar": true,
"enable_enemy_healthbar": true,
"enable_look_while_running": true,
"enable_numeric_keys": true,
"fix_end_of_level_freeze": true,
"fix_tihocan_secret_sound": true
}
1 change: 1 addition & 0 deletions src/game/inv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// clang-format off
#define Inv_RemoveItem ((void __cdecl(*)(int16_t item_num))0x004212A0)
#define Inv_RequestItem ((int32_t __cdecl(*)(int16_t item_num))0x00421200)
#define Display_Inventory ((int32_t __cdecl(*)(int32_t inventory_mode))0x0041E760)
// clang-format on

Expand Down
27 changes: 27 additions & 0 deletions src/game/shell.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "game/data.h"
#include "game/inv.h"
#include "game/items.h"
#include "game/lara.h"
#include "game/shell.h"
#include "mod.h"
#include <stdarg.h>
Expand Down Expand Up @@ -336,6 +338,31 @@ void __cdecl S_UpdateInput()
linput |= IN_ROLL;
}

if (TR1MConfig.enable_numeric_keys) {
if (KeyData->keymap[DIK_1] && Inv_RequestItem(O_GUN_ITEM)) {
Lara.request_gun_type = LG_PISTOLS;
} else if (KeyData->keymap[DIK_2] && Inv_RequestItem(O_SHOTGUN_ITEM)) {
Lara.request_gun_type = LG_SHOTGUN;
} else if (KeyData->keymap[DIK_3] && Inv_RequestItem(O_MAGNUM_ITEM)) {
Lara.request_gun_type = LG_MAGNUMS;
} else if (KeyData->keymap[DIK_4] && Inv_RequestItem(O_UZI_ITEM)) {
Lara.request_gun_type = LG_UZIS;
}

if (TR1MData.medipack_cooldown > 0) {
--TR1MData.medipack_cooldown;
} else {
if (KeyData->keymap[DIK_8] && Inv_RequestItem(O_MEDI_OPTION)) {
UseItem(O_MEDI_OPTION);
TR1MData.medipack_cooldown = 15; // half a second
} else if (
KeyData->keymap[DIK_9] && Inv_RequestItem(O_BIGMEDI_OPTION)) {
UseItem(O_BIGMEDI_OPTION);
TR1MData.medipack_cooldown = 15;
}
}
}

if (KeyData->keymap[DIK_RETURN] || (linput & IN_ACTION)) {
linput |= IN_SELECT;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ static int TR1MReadConfig()

json_value* json = json_parse((const json_char*)cfg_data, cfg_size);

TR1MData.medipack_cooldown = 0;

TR1MConfig.disable_healing_between_levels =
tr1m_json_get_boolean_value(json, "disable_healing_between_levels");
TR1MConfig.disable_medpacks =
Expand All @@ -69,6 +71,8 @@ static int TR1MReadConfig()
tr1m_json_get_boolean_value(json, "enable_enemy_healthbar");
TR1MConfig.enable_look_while_running =
tr1m_json_get_boolean_value(json, "enable_look_while_running");
TR1MConfig.enable_numeric_keys =
tr1m_json_get_boolean_value(json, "enable_numeric_keys");
TR1MConfig.fix_end_of_level_freeze =
tr1m_json_get_boolean_value(json, "fix_end_of_level_freeze");
TR1MConfig.fix_tihocan_secret_sound =
Expand Down
2 changes: 2 additions & 0 deletions src/mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ struct {
int enable_red_healthbar;
int enable_enemy_healthbar;
int enable_look_while_running;
int enable_numeric_keys;
int fix_end_of_level_freeze;
int fix_tihocan_secret_sound;
} TR1MConfig;

struct {
int stored_lara_health;
int medipack_cooldown;
} TR1MData;

int TR1MGetOverlayScale(int base);
Expand Down

0 comments on commit 58ee62e

Please sign in to comment.