Skip to content

Commit

Permalink
Merge pull request #353 from Mr-Auto/inputs
Browse files Browse the repository at this point in the history
Some Screens and GameAPI stuff
  • Loading branch information
Dregu authored Nov 5, 2023
2 parents c90fd51 + 7015f45 commit 8ff4b4d
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 22 deletions.
14 changes: 12 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.

28 changes: 26 additions & 2 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2248,13 +2248,17 @@ set_callback(function()

```

Derived from [Screen](#Screen)


Type | Name | Description
---- | ---- | -----------
int | [sequence_state](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=sequence_state) |
int | [animation_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=animation_timer) |
float | [constellation_text_opacity](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=constellation_text_opacity) |
float | [constellation_text](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=constellation_text) |
[SoundMeta](#SoundMeta) | [explosion_and_loop](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=explosion_and_loop) |
[SoundMeta](#SoundMeta) | [music](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=music) |

### ScreenCredits

Expand Down Expand Up @@ -2301,7 +2305,6 @@ Derived from [Screen](#Screen)
Type | Name | Description
---- | ---- | -----------
int | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) |
int | [time_till_death_screen](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=time_till_death_screen) | Delay after player death to open the death screen

### ScreenLogo

Expand Down Expand Up @@ -2532,6 +2535,25 @@ float | [topleft_woodpanel_esc_slidein_timer](https://github.com/spelunky-fyi/ov
[TextureRenderingInfo](#TextureRenderingInfo) | [start_sidepanel](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=start_sidepanel) |
float | [start_sidepanel_slidein_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=start_sidepanel_slidein_timer) |

### ScreenStateCamp

Derived from [Screen](#Screen)


Type | Name | Description
---- | ---- | -----------
int | [time_till_reset](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=time_till_reset) | Delay after player death to reset camp

### ScreenStateLevel

Derived from [Screen](#Screen)


Type | Name | Description
---- | ---- | -----------
int | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) |
int | [time_till_death_screen](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=time_till_death_screen) | Delay after player death to open the death screen

### ScreenTeamSelect

Derived from [Screen](#Screen)
Expand Down Expand Up @@ -2929,8 +2951,10 @@ int | [correct_ushabti](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q
int | [camera_layer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=camera_layer) |
int | [layer_transition_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=layer_transition_timer) |
int | [transition_to_layer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=transition_to_layer) |
[ScreenTeamSelect](#ScreenTeamSelect) | [screen_team_select](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_team_select) |
[ScreenCharacterSelect](#ScreenCharacterSelect) | [screen_character_select](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_character_select) |
[ScreenTeamSelect](#ScreenTeamSelect) | [screen_team_select](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_team_select) |
[ScreenStateCamp](#ScreenStateCamp) | [screen_camp](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_camp) |
[ScreenStateLevel](#ScreenStateLevel) | [screen_level](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_level) |
[ScreenTransition](#ScreenTransition) | [screen_transition](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_transition) |
[ScreenDeath](#ScreenDeath) | [screen_death](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_death) |
[ScreenWin](#ScreenWin) | [screen_win](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_win) |
Expand Down
14 changes: 13 additions & 1 deletion src/game_api/game_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ struct Renderer
virtual void some_dx_stuff() = 0; // it actually has a ton of parameters
};

struct UnknownAPIStuff
{
uint32_t unknown1;
int32_t unknown2; // -1

uint8_t unknown3; // controller input flags related maybe?
uint8_t unknown4;
uint8_t unknown5;
uint8_t unknown6;
uint32_t unknown7; // padding?
};

struct GameAPI // size 0x60
{
static GameAPI* get();
Expand All @@ -108,7 +120,7 @@ struct GameAPI // size 0x60
void set_zoom(std::optional<float> current, std::optional<float> target);

bool unknown1;
size_t unknown2; // pointer
UnknownAPIStuff* unknown2;
Renderer* renderer;
uint32_t window_width;
uint32_t window_height;
Expand Down
25 changes: 22 additions & 3 deletions src/game_api/game_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ struct GameProps
bool unknown9;
bool unknown10;
// there's more stuff here
std::array<size_t*, 12> unknown11; // pointers to something

int8_t input_index[5]; // not sure, just came up with this name, if not used it's -1
// for example if you just run the game and use OL to warp somewhere immediately there will be no controller setup, so all of those will be -1

// uint8_t padding_probably1[3];

int32_t unknown12; // -1
int8_t unknown13; // -1

// uint8_t padding_probably2[3];

size_t unknown14; // probably not one thig
uint32_t unknown15;

// uint32_t padding_probably3;
size_t* unknown16;
size_t unknwon17;
double unknown18; // counts time or something? only active when the game window is active
};

struct GameManager
Expand Down Expand Up @@ -118,7 +137,7 @@ struct GameManager
size_t unknown_screen_team_select; // available in State
ScreenCamp* screen_camp;
ScreenLevel* screen_level;
size_t screen_transition; // available in State, but it's a different object! this one only has a render_timer
size_t* screen_transition; // available in State, but it's a different object! this one only has a render_timer
size_t unknown_screen_death; // available in State
size_t unknown_screen_spaceship; // (also not) available in State
size_t unknown_screen_win; // available in State
Expand All @@ -131,8 +150,8 @@ struct GameManager
size_t unknown_screen_arena_items; // available in State
size_t unknown_screen_arena_select; // available in State
size_t unknown_screen_arena_intro; // available in State
size_t screen_arena_level; // also available in State, but it's a different object! this one only has a render_timer, no UI parts
size_t unknown_screen_arena_score; // available in State
size_t* screen_arena_level; // also available in State, but it's a different object! this one only has a render_timer, no UI parts
size_t* unknown_screen_arena_score; // available in State
ScreenOnlineLoading* screen_online_loading;
ScreenOnlineLobby* screen_online_lobby;
PauseUI* pause_ui;
Expand Down
24 changes: 19 additions & 5 deletions src/game_api/screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Screen
uint32_t unknown_zero;

virtual void init() = 0;
virtual void handle_player() = 0; // for normal level: death, camera zoom (level/shop), camera bounds, some save data stuff
virtual void update() = 0; // runs each frame, for level screens: death, camera zoom (level/shop), camera bounds, some save data stuff
virtual ~Screen() = 0;
virtual void render() = 0; // mostly used by the non gameplay screens to draw textures and text
virtual void render() = 0; // mostly used by the non gameplay screens to draw textures, text, UI

std::uint32_t reserve_callback_id();
void unhook(std::uint32_t id);
Expand Down Expand Up @@ -474,18 +474,32 @@ class ScreenTeamSelect : public Screen // ID: 10
uint32_t unknown7;
};

class ScreenCamp : public Screen // ID: 11
class ScreenCamp : public Screen // ID: 11 GameManager
{
public:
uint8_t buttons;
};

class ScreenLevel : public Screen // ID: 12
class ScreenStateCamp : public Screen // ID: 11 StateMemory
{
public:
/// Delay after player death to reset camp
uint8_t time_till_reset;
};

class ScreenStateLevel : public Screen // ID: 12 StateMemory
{
public:
uint8_t buttons;
/// Delay after player death to open the death screen
int8_t time_till_death_screen;
uint8_t time_till_death_screen;
};

class ScreenLevel : public Screen // ID: 12 GameManager
{
public:
uint8_t buttons;
// garbage here ?
};

class ScreenTransition : public Screen // ID: 13
Expand Down
22 changes: 19 additions & 3 deletions src/game_api/script/usertypes/screen_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void register_usertypes(sol::state& lua)
lua["Screen"]["as_screen_character_select"] = &Screen::as<ScreenCharacterSelect>;
lua["Screen"]["as_screen_team_select"] = &Screen::as<ScreenTeamSelect>;
lua["Screen"]["as_screen_camp"] = &Screen::as<ScreenCamp>;
lua["Screen"]["as_screen_state_camp"] = &Screen::as<ScreenStateCamp>; // probably not needed
lua["Screen"]["as_screen_level"] = &Screen::as<ScreenLevel>;
lua["Screen"]["as_screen_state_level"] = &Screen::as<ScreenStateLevel>; // probably not needed
lua["Screen"]["as_screen_transition"] = &Screen::as<ScreenTransition>;
lua["Screen"]["as_screen_death"] = &Screen::as<ScreenDeath>;
lua["Screen"]["as_screen_win"] = &Screen::as<ScreenWin>;
Expand Down Expand Up @@ -343,12 +345,26 @@ void register_usertypes(sol::state& lua)
sol::base_classes,
sol::bases<Screen>());

lua.new_usertype<ScreenStateCamp>(
"ScreenStateCamp",
"time_till_reset",
&ScreenStateCamp::time_till_reset,
sol::base_classes,
sol::bases<Screen>());

lua.new_usertype<ScreenLevel>(
"ScreenLevel",
"buttons",
&ScreenLevel::buttons,
sol::base_classes,
sol::bases<Screen>());

lua.new_usertype<ScreenStateLevel>(
"ScreenStateLevel",
"buttons",
&ScreenStateLevel::buttons,
"time_till_death_screen",
&ScreenLevel::time_till_death_screen,
&ScreenStateLevel::time_till_death_screen,
sol::base_classes,
sol::bases<Screen>());

Expand Down Expand Up @@ -459,11 +475,11 @@ void register_usertypes(sol::state& lua)
"constellation_text",
sol::property([](ScreenConstellation& s) -> std::u16string_view
{
std::u16string_view str(s.constellation_text);
std::u16string_view str(s.constellation_text) /**/;
return str; },
[](ScreenConstellation& s, std::u16string new_str)
{
const char16_t* src = new_str.c_str();
const char16_t* src = new_str.c_str() /**/;
char16_t* temp = s.constellation_text;
unsigned int n = 0;
while ((*temp++ = *src++) != 0)
Expand Down
4 changes: 3 additions & 1 deletion src/game_api/script/usertypes/state_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,10 @@ void register_usertypes(sol::state& lua)
statememory_type["camera_layer"] = &StateMemory::camera_layer;
statememory_type["layer_transition_timer"] = &StateMemory::layer_transition_timer;
statememory_type["transition_to_layer"] = &StateMemory::transition_to_layer;
statememory_type["screen_team_select"] = &StateMemory::screen_team_select;
statememory_type["screen_character_select"] = &StateMemory::screen_character_select;
statememory_type["screen_team_select"] = &StateMemory::screen_team_select;
statememory_type["screen_camp"] = &StateMemory::screen_camp;
statememory_type["screen_level"] = &StateMemory::screen_level;
statememory_type["screen_transition"] = &StateMemory::screen_transition;
statememory_type["screen_death"] = &StateMemory::screen_death;
statememory_type["screen_win"] = &StateMemory::screen_win;
Expand Down
10 changes: 5 additions & 5 deletions src/game_api/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class ScreenArenaLevel;
class ScreenArenaMenu;
class ScreenArenaScore;
class ScreenArenaStagesSelect;
class ScreenCamp;
class ScreenStateCamp;
class ScreenCharacterSelect;
class ScreenConstellation;
class ScreenCredits;
class ScreenDeath;
class ScreenLevel;
class ScreenStateLevel;
class ScreenRecap;
class ScreenScores;
class ScreenTeamSelect;
Expand Down Expand Up @@ -216,8 +216,8 @@ struct StateMemory
// screens that are available in GameManager
ScreenCharacterSelect* screen_character_select;
ScreenTeamSelect* screen_team_select;
ScreenCamp* screen_camp;
ScreenLevel* screen_level;
ScreenStateCamp* screen_camp;
ScreenStateLevel* screen_level;
ScreenTransition* screen_transition;
ScreenDeath* screen_death;
size_t unknown_screen_spaceship; // potentially ScreenSpaceship, but is nullptr (there is no UI rendering on spaceship anyway)
Expand All @@ -229,7 +229,7 @@ struct StateMemory
ScreenArenaMenu* screen_arena_menu;
ScreenArenaStagesSelect* screen_arena_stages_select1;
ScreenArenaItems* screen_arena_items;
ScreenArenaStagesSelect* screen_arena_stages_select2;
ScreenArenaStagesSelect* screen_arena_stages_select2; // same pointer as screen_arena_stages_select1
ScreenArenaIntro* screen_arena_intro;
ScreenArenaLevel* screen_arena_level;
ScreenArenaScore* screen_arena_score;
Expand Down

0 comments on commit 8ff4b4d

Please sign in to comment.