Skip to content

Commit

Permalink
add layer hack to spawn_player
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Oct 13, 2023
1 parent f3cdf00 commit a9c1f3e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/game_api/spawn_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ void init_spawn_hooks()
}
}

int32_t spawn_player(int8_t player_slot, std::optional<float> x, std::optional<float> y)
int32_t spawn_player(int8_t player_slot, std::optional<float> x, std::optional<float> y, std::optional<LAYER> layer)
{
if (player_slot < 1 || player_slot > 4)
return -1;
Expand All @@ -685,7 +685,12 @@ int32_t spawn_player(int8_t player_slot, std::optional<float> x, std::optional<f
auto uid = (int32_t)state->next_entity_uid;
using spawn_player_fun = void(Items*, uint8_t ps);
static auto spawn_player = (spawn_player_fun*)get_address("spawn_player");
// lazy? maybe. it's where it gets the state+0x1300 layer0 pointer
auto layer_off = get_address("spawn_player") + 0x3ea;
if (layer.has_value() && layer.value() == LAYER::BACK)
write_mem_recoverable("spawn_player_layer", layer_off, 0x1308, true);
spawn_player(get_state_ptr()->items, player_slot - 1);
recover_mem("spawn_player_layer");
state->level_gen->spawn_x = old_x;
state->level_gen->spawn_y = old_y;
return uid;
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/spawn_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void pop_spawn_type_flags(SPAWN_TYPE flags);

void init_spawn_hooks();

int32_t spawn_player(int8_t player_slot, std::optional<float> x = std::nullopt, std::optional<float> y = std::nullopt);
int32_t spawn_player(int8_t player_slot, std::optional<float> x = std::nullopt, std::optional<float> y = std::nullopt, std::optional<LAYER> layer = std::nullopt);
int32_t spawn_companion(ENT_TYPE companion_type, float x, float y, LAYER layer);
int32_t spawn_shopkeeper(float x, float y, LAYER layer, ROOM_TEMPLATE room_template = 65);
int32_t spawn_roomowner(ENT_TYPE owner_type, float x, float y, LAYER layer, int16_t room_template = -1);
Expand Down
2 changes: 1 addition & 1 deletion src/injected/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,7 @@ void respawn()
}
return;
}
for (int8_t i = 0; i < 4; ++i)
for (int8_t i = 0; i < g_state->items->player_count; ++i)
{
auto found = false;
for (auto p : UI::get_players())
Expand Down
4 changes: 2 additions & 2 deletions src/injected/ui_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,9 @@ int32_t UI::spawn_playerghost(ENT_TYPE char_type, float x, float y, LAYER layer,
return uid;
}

void UI::spawn_player(uint8_t player_slot, std::optional<float> x, std::optional<float> y)
void UI::spawn_player(uint8_t player_slot, std::optional<float> x, std::optional<float> y, std::optional<LAYER> layer)
{
::spawn_player(player_slot + 1, x, y);
::spawn_player(player_slot + 1, x, y, layer);
}

std::pair<float, float> UI::spawn_position()
Expand Down
2 changes: 1 addition & 1 deletion src/injected/ui_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class UI
static float get_spark_distance(SparkTrap* ent);
static void save_progress();
static int32_t spawn_playerghost(ENT_TYPE char_type, float x, float y, LAYER layer, float vx, float vy);
static void spawn_player(uint8_t player_slot, std::optional<float> x = std::nullopt, std::optional<float> y = std::nullopt);
static void spawn_player(uint8_t player_slot, std::optional<float> x = std::nullopt, std::optional<float> y = std::nullopt, std::optional<LAYER> layer = std::nullopt);
static std::pair<float, float> spawn_position();
static void load_death_screen();
};

0 comments on commit a9c1f3e

Please sign in to comment.