Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I guess we're doing UI again #345

Merged
merged 32 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
43fc95c
add levelgen flags
Dregu Oct 8, 2023
6767fa8
Merge branch 'main' into UI
Dregu Oct 11, 2023
b166e9f
Use destroy_grid in ui delete
Dregu Oct 11, 2023
ff63713
hitbox color fixes
Dregu Oct 11, 2023
3be15a4
Merge branch 'main' into UI
Dregu Oct 11, 2023
2dd67d9
add ui warp buttons to special game screens
Dregu Oct 11, 2023
26e3165
Add unload level callbacks
Dregu Oct 11, 2023
eeeeabf
rename unload_level and add pre_spawn_level
Dregu Oct 11, 2023
fdfd1ad
layer init hooks
Dregu Oct 11, 2023
0c3b6c7
add set_death_enabled
Dregu Oct 11, 2023
28337d4
add ui options to disable death and respawn players
Dregu Oct 11, 2023
6560ecb
Merge branch 'main' into UI
Dregu Oct 12, 2023
0e3294e
fix get_procedural_chance logic
Dregu Oct 12, 2023
c19bb9d
add procedural chances to ui
Dregu Oct 12, 2023
646a07b
ui chances fixes
Dregu Oct 12, 2023
e70b5cb
thank you for the useless warning
Dregu Oct 12, 2023
54a993a
run level gen callbacks for transitions
Dregu Oct 12, 2023
a312d78
testing cutscene_behavior
Dregu Oct 13, 2023
f3cdf00
fix spawn_player position
Dregu Oct 13, 2023
a9c1f3e
add layer hack to spawn_player
Dregu Oct 13, 2023
20eeb43
uglier hack that works better
Dregu Oct 14, 2023
07f6968
make it not stupid
Dregu Oct 14, 2023
a449568
remove defaults
Dregu Oct 14, 2023
5425ab7
fix docs
Dregu Oct 14, 2023
3b62a27
add patterns for new patterns
Dregu Oct 14, 2023
55584e9
fix clear_callback in movable virtual hooks
Dregu Oct 14, 2023
0aedff0
change some patterns to vtable offsets
Dregu Oct 14, 2023
27df88c
fix spawn_player uid
Dregu Oct 14, 2023
2fd3f4b
update docs
Dregu Oct 14, 2023
d375795
remove cutscenes, add some input helpers
Dregu Oct 14, 2023
1a100fd
fix crash when destroying layer with players
Dregu Oct 14, 2023
56a7322
rename and document death
Dregu Oct 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/game_api/spawn_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,18 +662,33 @@ void init_spawn_hooks()
}
}

void spawn_player(int8_t player_slot, float x, float y)
int32_t spawn_player(int8_t player_slot, std::optional<float> x, std::optional<float> y)
{
if (player_slot < 1 || player_slot > 4)
return;
return -1;
auto state = State::get().ptr();
auto& slot = state->items->player_select_slots[player_slot - 1];
if (slot.character < to_id("ENT_TYPE_CHAR_ANA_SPELUNKY") || slot.character > to_id("ENT_TYPE_CHAR_CLASSIC_GUY"))
return -1;
if (state->items->player_count < player_slot)
state->items->player_count = player_slot;
slot.activated = true;

push_spawn_type_flags(SPAWN_TYPE_SCRIPT);
OnScopeExit pop{[]
{ pop_spawn_type_flags(SPAWN_TYPE_SCRIPT); }};

using spawn_player_fun = void(Items*, uint8_t ps, float pos_x, float pos_y);
auto old_x = state->level_gen->spawn_x;
auto old_y = state->level_gen->spawn_y;
state->level_gen->spawn_x = x.value_or(old_x);
state->level_gen->spawn_y = y.value_or(old_y);
auto uid = (int32_t)state->next_entity_uid;
Dregu marked this conversation as resolved.
Show resolved Hide resolved
using spawn_player_fun = void(Items*, uint8_t ps);
static auto spawn_player = (spawn_player_fun*)get_address("spawn_player");
spawn_player(get_state_ptr()->items, player_slot - 1, x, y);
spawn_player(get_state_ptr()->items, player_slot - 1);
Dregu marked this conversation as resolved.
Show resolved Hide resolved
state->level_gen->spawn_x = old_x;
state->level_gen->spawn_y = old_y;
return uid;
}

int32_t spawn_companion(ENT_TYPE companion_type, float x, float y, LAYER layer)
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();

void spawn_player(int8_t player_slot, float x, float y);
int32_t spawn_player(int8_t player_slot, std::optional<float> x = std::nullopt, std::optional<float> y = 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
4 changes: 2 additions & 2 deletions src/injected/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ void respawn()
if (!found)
{
g_state->items->player_inventories[i].health = 4;
UI::spawn_player(i, g_state->level_gen->spawn_x, g_state->level_gen->spawn_y);
UI::spawn_player(i);
}
}
}
Expand Down Expand Up @@ -8071,7 +8071,7 @@ void render_game_props()
{
g_state->items->player_inventories[i].health = 4;
auto uid = g_state->next_entity_uid;
UI::spawn_player(i, spawn_x, spawn_y);
UI::spawn_player(i);
auto player = get_entity_ptr(uid)->as<Player>();
player->set_position(spawn_x, spawn_y);
}
Expand Down
2 changes: 1 addition & 1 deletion src/injected/ui_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ 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, float x, float y)
void UI::spawn_player(uint8_t player_slot, std::optional<float> x, std::optional<float> y)
{
::spawn_player(player_slot + 1, x, y);
}
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, float x, float y);
static void spawn_player(uint8_t player_slot, std::optional<float> x = std::nullopt, std::optional<float> y = std::nullopt);
static std::pair<float, float> spawn_position();
static void load_death_screen();
};
Loading