Skip to content

Commit

Permalink
Merge branch 'main' into PauseAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Dec 5, 2023
2 parents 4cb7819 + c6bb761 commit 4cc758d
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 155 deletions.
5 changes: 3 additions & 2 deletions docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16451,7 +16451,7 @@ <h3 id='PlayerSlot'>PlayerSlot</h3>
</tr>
<tr>
<td>int</td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=player_id">player_id</a></td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=player_slot">player_slot</a></td>
<td></td>
</tr>
<tr>
Expand Down Expand Up @@ -16681,7 +16681,7 @@ <h3 id='StateMemory'>StateMemory</h3>
</tr>
<tr>
<td>nil</td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=force_current_theme">force_current_theme(int t)</a></td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=force_current_theme">force_current_theme(THEME t)</a></td>
<td>This function should only be used in a very specific circumstance (forcing the exiting theme when manually transitioning). Will crash the game if used inappropriately!</td>
</tr>
<tr>
Expand Down Expand Up @@ -23531,6 +23531,11 @@ <h3 id='Player'>Player</h3>
<td>Used in base camp to talk with the <a href="#NPC">NPC</a>&#39;s</td>
</tr>
<tr>
<td><a href="#SoundMeta">SoundMeta</a></td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=special_sound">special_sound</a></td>
<td>For Lise System walking and looking up sounds</td>
</tr>
<tr>
<td>int</td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=jump_lock_timer">jump_lock_timer</a></td>
<td>Increases when holding jump button in the air, set to max while jumping. If this isn&#39;t 0, a jump will only be<br/>registered if the jump button was not held on the previous frame.</td>
Expand Down
9 changes: 7 additions & 2 deletions docs/light.html
Original file line number Diff line number Diff line change
Expand Up @@ -16451,7 +16451,7 @@ <h3 id='PlayerSlot'>PlayerSlot</h3>
</tr>
<tr>
<td>int</td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=player_id">player_id</a></td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=player_slot">player_slot</a></td>
<td></td>
</tr>
<tr>
Expand Down Expand Up @@ -16681,7 +16681,7 @@ <h3 id='StateMemory'>StateMemory</h3>
</tr>
<tr>
<td>nil</td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=force_current_theme">force_current_theme(int t)</a></td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=force_current_theme">force_current_theme(THEME t)</a></td>
<td>This function should only be used in a very specific circumstance (forcing the exiting theme when manually transitioning). Will crash the game if used inappropriately!</td>
</tr>
<tr>
Expand Down Expand Up @@ -23531,6 +23531,11 @@ <h3 id='Player'>Player</h3>
<td>Used in base camp to talk with the <a href="#NPC">NPC</a>&#39;s</td>
</tr>
<tr>
<td><a href="#SoundMeta">SoundMeta</a></td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=special_sound">special_sound</a></td>
<td>For Lise System walking and looking up sounds</td>
</tr>
<tr>
<td>int</td>
<td><a href="https://github.com/spelunky-fyi/overlunky/search?l=Lua&amp;q=jump_lock_timer">jump_lock_timer</a></td>
<td>Increases when holding jump button in the air, set to max while jumping. If this isn&#39;t 0, a jump will only be<br/>registered if the jump button was not held on the previous frame.</td>
Expand Down
5 changes: 3 additions & 2 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2892,7 +2892,7 @@ Type | Name | Description
[INPUTS](#INPUTS) | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) |
[InputMapping](#InputMapping) | [input_mapping_keyboard](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=input_mapping_keyboard) |
[InputMapping](#InputMapping) | [input_mapping_controller](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=input_mapping_controller) |
int | [player_id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_id) |
int | [player_slot](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=player_slot) |
bool | [is_participating](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=is_participating) |

### PlayerSlotSettings
Expand Down Expand Up @@ -2954,7 +2954,7 @@ int | [level_start](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=lev
[THEME](#THEME) | [theme_next](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=theme_next) | Next [THEME](#THEME) number, used when loading a new level or transition
[THEME](#THEME) | [theme_start](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=theme_start) | [THEME](#THEME) to start new runs in
[ThemeInfo](#ThemeInfo) | [current_theme](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=current_theme) | Points to the current [ThemeInfo](#ThemeInfo)
nil | [force_current_theme(int t)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=force_current_theme) | This function should only be used in a very specific circumstance (forcing the exiting theme when manually transitioning). Will crash the game if used inappropriately!
nil | [force_current_theme(THEME t)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=force_current_theme) | This function should only be used in a very specific circumstance (forcing the exiting theme when manually transitioning). Will crash the game if used inappropriately!
int | [shoppie_aggro](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=shoppie_aggro) | Current shoppie aggro
int | [shoppie_aggro_next](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=shoppie_aggro_next) | Shoppie aggro to use in the next level
int | [outposts_spawned](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=outposts_spawned) |
Expand Down Expand Up @@ -5344,6 +5344,7 @@ int | [linked_companion_child](https://github.com/spelunky-fyi/overlunky/search?
[Ai](#Ai) | [ai](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ai) |
[PlayerSlot](#PlayerSlot) | [input](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=input) |
[Entity](#Entity) | [basecamp_button_entity](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=basecamp_button_entity) | Used in base camp to talk with the [NPC](#NPC)'s
[SoundMeta](#SoundMeta) | [special_sound](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=special_sound) | For Lise System walking and looking up sounds
int | [jump_lock_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=jump_lock_timer) | Increases when holding jump button in the air, set to max while jumping. If this isn't 0, a jump will only be<br/>registered if the jump button was not held on the previous frame.
int | [coyote_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=coyote_timer) | can jump while airborne if greater than 0
int | [swim_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=swim_timer) | Timer between strokes when holding jump button in water.
Expand Down
5 changes: 5 additions & 0 deletions src/game_api/bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,9 @@ class Bucket
std::unordered_map<std::string, EditedMemory> original_memory;
/// PauseAPI is used by Overlunky and can be used to control the Overlunky pause options from scripts. Can be accessed from the global `pause` more easily.
PauseAPI* pause_api;

private:
Bucket() = default;
Bucket(const Bucket&) = delete;
Bucket& operator=(const Bucket&) = delete;
};
59 changes: 59 additions & 0 deletions src/game_api/custom_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ const std::vector<std::pair<CUSTOM_TYPE, std::string_view>> custom_type_names =
{CUSTOM_TYPE::YELLOWCAPE, "YELLOWCAPE"},
{CUSTOM_TYPE::YETIKING, "YETIKING"},
{CUSTOM_TYPE::YETIQUEEN, "YETIQUEEN"},
{CUSTOM_TYPE::PURCHASABLE, "PURCHASABLE"},
};

template <CUSTOM_TYPE CustomEntityType, class... StrArgs>
Expand Down Expand Up @@ -1564,6 +1565,64 @@ std::span<const ENT_TYPE> get_custom_entity_types(CUSTOM_TYPE type)
return make_custom_entity_type_list<CUSTOM_TYPE::YETIKING>("ENT_TYPE_MONS_YETIKING");
case CUSTOM_TYPE::YETIQUEEN:
return make_custom_entity_type_list<CUSTOM_TYPE::YETIQUEEN>("ENT_TYPE_MONS_YETIQUEEN");
case CUSTOM_TYPE::PURCHASABLE:
return make_custom_entity_type_list<CUSTOM_TYPE::TORCH>(
"ENT_TYPE_ITEM_WOODEN_ARROW",
"ENT_TYPE_ITEM_ROCK",
"ENT_TYPE_ITEM_METAL_ARROW",
"ENT_TYPE_ITEM_LIGHT_ARROW",
"ENT_TYPE_ITEM_PRESENT",
"ENT_TYPE_ITEM_GHIST_PRESENT",
"ENT_TYPE_ITEM_POT",
"ENT_TYPE_ITEM_SKULL",
"ENT_TYPE_ITEM_PICKUP_TORNJOURNALPAGE",
"ENT_TYPE_ITEM_PICKUP_JOURNAL",
"ENT_TYPE_ITEM_PICKUP_ROPE",
"ENT_TYPE_ITEM_PICKUP_ROPEPILE",
"ENT_TYPE_ITEM_PICKUP_BOMBBAG",
"ENT_TYPE_ITEM_PICKUP_BOMBBOX",
"ENT_TYPE_ITEM_PICKUP_ROYALJELLY",
"ENT_TYPE_ITEM_PICKUP_COOKEDTURKEY",
"ENT_TYPE_ITEM_PICKUP_GIANTFOOD",
"ENT_TYPE_ITEM_PICKUP_ELIXIR",
"ENT_TYPE_ITEM_PICKUP_CLOVER",
"ENT_TYPE_ITEM_PICKUP_SEEDEDRUNSUNLOCKER",
"ENT_TYPE_ITEM_PICKUP_SPECTACLES",
"ENT_TYPE_ITEM_PICKUP_CLIMBINGGLOVES",
"ENT_TYPE_ITEM_PICKUP_PITCHERSMITT",
"ENT_TYPE_ITEM_PICKUP_SPRINGSHOES",
"ENT_TYPE_ITEM_PICKUP_SPIKESHOES",
"ENT_TYPE_ITEM_PICKUP_PASTE",
"ENT_TYPE_ITEM_PICKUP_COMPASS",
"ENT_TYPE_ITEM_PICKUP_SPECIALCOMPASS",
"ENT_TYPE_ITEM_PICKUP_PARACHUTE",
"ENT_TYPE_ITEM_PICKUP_UDJATEYE",
"ENT_TYPE_ITEM_PICKUP_KAPALA",
"ENT_TYPE_ITEM_PICKUP_HEDJET",
"ENT_TYPE_ITEM_PICKUP_CROWN",
"ENT_TYPE_ITEM_PICKUP_EGGPLANTCROWN",
"ENT_TYPE_ITEM_PICKUP_TRUECROWN",
"ENT_TYPE_ITEM_PICKUP_ANKH",
"ENT_TYPE_ITEM_PICKUP_TABLETOFDESTINY",
"ENT_TYPE_ITEM_PICKUP_SKELETON_KEY",
"ENT_TYPE_ITEM_PURCHASABLE_CAPE",
"ENT_TYPE_ITEM_PURCHASABLE_JETPACK",
"ENT_TYPE_ITEM_PURCHASABLE_TELEPORTER_BACKPACK",
"ENT_TYPE_ITEM_PURCHASABLE_HOVERPACK",
"ENT_TYPE_ITEM_PURCHASABLE_POWERPACK",
"ENT_TYPE_ITEM_WEBGUN",
"ENT_TYPE_ITEM_SHOTGUN",
"ENT_TYPE_ITEM_FREEZERAY",
"ENT_TYPE_ITEM_CAMERA",
"ENT_TYPE_ITEM_TELEPORTER",
"ENT_TYPE_ITEM_MATTOCK",
"ENT_TYPE_ITEM_BOOMERANG",
"ENT_TYPE_ITEM_MACHETE",
"ENT_TYPE_ITEM_PLASMACANNON",
"ENT_TYPE_ITEM_SCEPTER",
"ENT_TYPE_ITEM_CLONEGUN",
"ENT_TYPE_ITEM_WOODEN_SHIELD",
"ENT_TYPE_ITEM_METAL_SHIELD");
default:
{
auto it = user_custom_types.find(type);
Expand Down
2 changes: 2 additions & 0 deletions src/game_api/custom_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "aliases.hpp" // for ENT_TYPE

// New types need to be added to the enum, plus the custom_type_names vector and then finally in the get_custom_entity_types function
enum class CUSTOM_TYPE : uint32_t
{
ACIDBUBBLE = 1000, // to be sure that's it's bigger than ENT_TYPE_LIQUID_COARSE_LAVA
Expand Down Expand Up @@ -343,6 +344,7 @@ enum class CUSTOM_TYPE : uint32_t
YELLOWCAPE,
YETIKING,
YETIQUEEN,
PURCHASABLE,
};

constexpr CUSTOM_TYPE custom_type_max = CUSTOM_TYPE::YETIQUEEN;
Expand Down
4 changes: 2 additions & 2 deletions src/game_api/entities_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class Player : public PowerupCapable
PlayerSlot* input_ptr;
/// Used in base camp to talk with the NPC's
Entity* basecamp_button_entity;
int32_t i168;
int32_t i16c;
/// For Lise System walking and looking up sounds
SoundMeta* special_sound;
float y_pos; // not sure why, seams to be the same as abs_y
/// Increases when holding jump button in the air, set to max while jumping. If this isn't 0, a jump will only be
/// registered if the jump button was not held on the previous frame.
Expand Down
6 changes: 3 additions & 3 deletions src/game_api/entities_floors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void Floor::fix_decorations(bool fix_also_neighbors, bool fix_styled_floor)
Floor* neighbours[4]{};
bool neighbours_same[4]{};

auto state = State::get();
auto& state = State::get();
auto layer_ptr = state.layer(layer);

for (size_t i = 0; i < 4; i++)
Expand Down Expand Up @@ -188,7 +188,7 @@ void Floor::add_decoration(FLOOR_SIDE side)
return;
}

auto state = State::get();
auto& state = State::get();
auto layer_ptr = state.layer(layer);
add_decoration_opt(side, decoration_entity_type, layer_ptr);
}
Expand Down Expand Up @@ -741,7 +741,7 @@ void Door::unlock(bool unlock)
static const ENT_TYPE eggchild_room_door = to_id("ENT_TYPE_FLOOR_DOOR_MOAI_STATUE");
static const ENT_TYPE EW_door = to_id("ENT_TYPE_FLOOR_DOOR_EGGPLANT_WORLD");
const auto ent_type = this->type->id;
auto state = State::get();
auto& state = State::get();

if (ent_type == locked_door || ent_type == locked_door + 1) // plus one for DOOR_LOCKED_PEN
{
Expand Down
22 changes: 6 additions & 16 deletions src/game_api/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Entity::teleport(float dx, float dy, bool s, float vx, float vy, bool snap)
{
// screen coordinates -1..1
// log::debug!("Teleporting to screen {}, {}", x, y);
auto state = State::get();
auto& state = State::get();
auto [x_pos, y_pos] = state.click_position(dx, dy);
if (snap && abs(vx) + abs(vy) <= 0.04f)
{
Expand Down Expand Up @@ -96,7 +96,7 @@ void Entity::set_layer(LAYER layer_to)
if (layer == dest_layer)
return;

auto state = State::get();
auto& state = State::get();
if (this != this->topmost_mount())
this->topmost_mount()->set_layer(layer_to);

Expand Down Expand Up @@ -139,7 +139,7 @@ void Entity::remove()
{
if (layer != 2)
{
auto state = State::get();
auto& state = State::get();
auto ptr_from = state.ptr()->layers[layer];
if ((this->type->search_flags & 1) == 0 || ((Player*)this)->ai != 0)
{
Expand Down Expand Up @@ -387,19 +387,9 @@ std::span<uint32_t> Entity::get_items()

Entity* get_entity_ptr(uint32_t uid)
{
auto state = State::get();
auto p = state.find(uid);
if (IsBadWritePtr(p, 0x178))
return nullptr;
return p;
}

Entity* get_entity_ptr_local(uint32_t uid)
{
auto state = State::get();
auto p = state.find_local(uid);
if (IsBadWritePtr(p, 0x178))
return nullptr;
auto p = State::find(State::get().ptr(), uid);
// if (IsBadWritePtr(p, 0x178))
// return nullptr;
return p;
}

Expand Down
1 change: 0 additions & 1 deletion src/game_api/entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,3 @@ AABB get_hitbox(uint32_t uid, bool use_render_pos);

struct EntityFactory* entity_factory();
Entity* get_entity_ptr(uint32_t uid);
Entity* get_entity_ptr_local(uint32_t uid);
10 changes: 5 additions & 5 deletions src/game_api/entity_lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::vector<ENT_TYPE> get_proper_types(std::vector<ENT_TYPE> ent_types)

int32_t get_grid_entity_at(float x, float y, LAYER layer)
{
auto state = State::get();
auto& state = State::get();
uint8_t actual_layer = enum_to_layer(layer);

if (Entity* ent = state.layer(actual_layer)->get_grid_entity_at(x, y))
Expand Down Expand Up @@ -169,8 +169,8 @@ std::vector<uint32_t> get_entities_by(ENT_TYPE entity_type, uint32_t mask, LAYER

std::vector<uint32_t> get_entities_at(std::vector<ENT_TYPE> entity_types, uint32_t mask, float x, float y, LAYER layer, float radius)
{
// TODO: use entitie regions?
auto state = State::get();
// TODO: use entity regions?
auto& state = State::get();
std::vector<uint32_t> found;
const std::vector<ENT_TYPE> proper_types = get_proper_types(std::move(entity_types));
auto push_entities_at = [&x, &y, &radius, &proper_types, &found](const EntityList& entities)
Expand Down Expand Up @@ -204,8 +204,8 @@ std::vector<uint32_t> get_entities_at(ENT_TYPE entity_type, uint32_t mask, float

std::vector<uint32_t> get_entities_overlapping_hitbox(std::vector<ENT_TYPE> entity_types, uint32_t mask, AABB hitbox, LAYER layer)
{
// TODO: use entitie regions?
auto state = State::get();
// TODO: use entity regions?
auto& state = State::get();
std::vector<uint32_t> result;
const std::vector<ENT_TYPE> proper_types = get_proper_types(std::move(entity_types));
if (layer == LAYER::BOTH)
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Entity* Layer::spawn_entity(ENT_TYPE id, float x, float y, bool screen, float vx
}
else if (screen)
{
auto state = State::get();
auto& state = State::get();
std::tie(x, y) = state.click_position(x, y);
min_speed_check = 0.04f;
if (snap && abs(vx) + abs(vy) <= min_speed_check)
Expand Down
6 changes: 2 additions & 4 deletions src/game_api/level_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1891,8 +1891,7 @@ std::pair<float, float> LevelGenSystem::get_room_pos(uint32_t x, uint32_t y)
}
std::optional<uint16_t> LevelGenSystem::get_room_template(uint32_t x, uint32_t y, uint8_t l)
{
auto state = State::get();
auto* state_ptr = state.ptr_local();
auto* state_ptr = State::get().ptr_local();

if (x < 0 || y < 0 || x >= state_ptr->w || y >= state_ptr->h)
return std::nullopt;
Expand All @@ -1908,8 +1907,7 @@ std::optional<uint16_t> LevelGenSystem::get_room_template(uint32_t x, uint32_t y
}
bool LevelGenSystem::set_room_template(uint32_t x, uint32_t y, int l, uint16_t room_template)
{
auto state = State::get();
auto* state_ptr = state.ptr_local();
auto* state_ptr = State::get().ptr_local();

if (x < 0 || y < 0 || x >= state_ptr->w || y >= state_ptr->h)
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/game_api/level_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct LevelGenData
uint32_t machine_rewardroom_chance;
uint32_t max_liquid_particles;
uint32_t flagged_liquid_rooms;
uint32_t unknown_config;
uint32_t unknown_config; //
};
};

Expand All @@ -151,7 +151,8 @@ struct LevelGenData
game_unordered_map<game_string, RoomTemplateDef> room_templates;

game_unordered_map<std::uint16_t, RoomTemplateData> room_template_datas;
std::byte padding1[0x6b8];
std::array<uint32_t, 429> unknown; // index is tile code id from TileCodeDef
// uint32_t padding;
std::array<RoomTemplateData, 8 * 15> set_room_datas;

game_unordered_map<game_string, ChanceDef> monster_chances;
Expand Down
Loading

0 comments on commit 4cc758d

Please sign in to comment.