Skip to content

Commit

Permalink
Merge pull request #395 from Mr-Auto/render
Browse files Browse the repository at this point in the history
Some render stuff
  • Loading branch information
Mr-Auto authored Dec 21, 2024
2 parents 6c0b359 + 1d6a2ac commit c6b8917
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 101 deletions.
11 changes: 9 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.

1 change: 1 addition & 0 deletions docs/src/includes/_enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ Name | Data | Description
Name | Data | Description
---- | ---- | -----------
[DTOR](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RENDER_INFO_OVERRIDE.DTOR) | 0 |
[DRAW](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RENDER_INFO_OVERRIDE.DRAW) | 1 |
[RENDER](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=RENDER_INFO_OVERRIDE.RENDER) | 3 |

## REPEAT_TYPE
Expand Down
11 changes: 9 additions & 2 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -953,13 +953,18 @@ Type | Name | Description
---- | ---- | -----------
float | [x](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=x) |
float | [y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=y) |
float | [offset_x](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=offset_x) |
float | [offset_y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=offset_y) |
[WORLD_SHADER](#WORLD_SHADER) | [shader](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=shader) |
[Quad](#Quad) | [source](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=source) |
[Quad](#Quad) | [destination](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=destination) |
float | [tilew](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=tilew) |
float | [tileh](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=tileh) |
bool | [facing_left](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=facing_left) |
float | [angle](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=angle) |
int | [animation_frame](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=animation_frame) |
bool | [render_inactive](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=render_inactive) |
float | [brightness](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=brightness) |
int | [texture_num](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=texture_num) |
[Entity](#Entity) | [get_entity()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_entity) |
bool | [set_normal_map_texture(TEXTURE texture_id)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_normal_map_texture) | Sets second_texture to the texture specified, then sets third_texture to SHINE_0 and texture_num to 3. You still have to change shader to 30 to render with normal map (same as COG normal maps)
Expand All @@ -973,8 +978,10 @@ bool | [set_texture_num(int num)](https://github.com/spelunky-fyi/overlunky/sear
nil | [clear_virtual(CallbackId callback_id)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=clear_virtual) | Clears the hook given by `callback_id`, alternatively use `clear_callback()` inside the hook.
[CallbackId](#Aliases) | [set_pre_dtor(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_dtor) | Hooks before the virtual function.<br/>The callback signature is `nil dtor(RenderInfo self)`
[CallbackId](#Aliases) | [set_post_dtor(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_dtor) | Hooks after the virtual function.<br/>The callback signature is `nil dtor(RenderInfo self)`
[CallbackId](#Aliases) | [set_pre_render(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_render) | Hooks before the virtual function.<br/>The callback signature is `bool render(RenderInfo self, float float, VanillaRenderContext vanilla_render_context)`
[CallbackId](#Aliases) | [set_post_render(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_render) | Hooks after the virtual function.<br/>The callback signature is `nil render(RenderInfo self, float float, VanillaRenderContext vanilla_render_context)`
[CallbackId](#Aliases) | [set_pre_draw(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_draw) | Hooks before the virtual function.<br/>The callback signature is `bool draw(RenderInfo self)`<br/>Virtual function docs:<br/>Called when the entity enters the camera view, using its hitbox with an extra threshold. Handles low-level graphics tasks related to the GPU
[CallbackId](#Aliases) | [set_post_draw(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_draw) | Hooks after the virtual function.<br/>The callback signature is `nil draw(RenderInfo self)`<br/>Virtual function docs:<br/>Called when the entity enters the camera view, using its hitbox with an extra threshold. Handles low-level graphics tasks related to the GPU
[CallbackId](#Aliases) | [set_pre_render(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_render) | Hooks before the virtual function.<br/>The callback signature is `bool render(RenderInfo self, Vec2 offset, VanillaRenderContext vanilla_render_context)`<br/>Virtual function docs:<br/>Offset used in CO to draw the fake image of the entity on the other side of a level
[CallbackId](#Aliases) | [set_post_render(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_render) | Hooks after the virtual function.<br/>The callback signature is `nil render(RenderInfo self, Vec2 offset, VanillaRenderContext vanilla_render_context)`<br/>Virtual function docs:<br/>Offset used in CO to draw the fake image of the entity on the other side of a level

### RoomOwnerDetails

Expand Down
21 changes: 11 additions & 10 deletions src/game_api/game_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

struct Renderer
{
// check x64dbg plugin for up to date structure

uint32_t render_width; // same as window size unless resolution scale is set
uint32_t render_height;

uint32_t fps; // changing it doesn't seam to do anything
uint32_t fps_denominator;

uint32_t render_width2; // repeat?
uint32_t render_width2; // used by the liquids to know what part(?) of screen to draw on top of the liquid (for all the transformation effects)
uint32_t render_height2;

uint8_t flags1;
Expand All @@ -27,14 +29,13 @@ struct Renderer

size_t unknown38; // bool?
float unknown39; // not sure if actually float
float unknown40;
float unknown41;
float unknown40; // some float counter
float brightness; // whole game brightness, can be set above 1
uint8_t unknown42[4];
const char** unknown43a; // font/floor it's changing
const char** unknown43b; // noise0.dds
const char** unknown43c; // noise1.dds
size_t unknown44[4]; // null?
size_t unknown45; // bool?
const char** textures_to_load[7]; // textures to load for entity
uint32_t texture_num; // number of textures in use

uint32_t unknown45; // padding?

// feels like two standard containers or something
size_t* unknown46;
Expand Down Expand Up @@ -88,8 +89,8 @@ struct Renderer

uint8_t skip3[0xAD8]; // probably some static arrays of ... stuff

size_t swap_chain;
// 3 more pointers, some bit fields, then 5 more pointers
size_t swap_chain; // unsure?
// a lot of stuff more, total size is 0x81138 bytes

// somewhere there should be shaders stored

Expand Down
11 changes: 5 additions & 6 deletions src/game_api/render_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "state.hpp" // for State, StateMemory
#include "strings.hpp" //
#include "texture.hpp" // for Texture, get_textures, get_texture
#include "thread_utils.hpp" // for OnHeapPointer

class JournalPage;
struct Camera;
Expand Down Expand Up @@ -660,7 +659,7 @@ void init_render_api_hooks()

Entity* RenderInfo::get_entity() const
{
return OnHeapPointer<Entity>{entity_offset}.decode_local();
return entity_offset.decode_local();
}

uint32_t RenderInfo::get_aux_id() const
Expand All @@ -672,7 +671,7 @@ bool RenderInfo::set_second_texture(TEXTURE texture_id)
{
if (auto* new_texture = ::get_texture(texture_id))
{
second_texture_name = new_texture->name;
texture_names[1] = new_texture->name;
return true;
}
return false;
Expand All @@ -682,7 +681,7 @@ bool RenderInfo::set_third_texture(TEXTURE texture_id)
{
if (auto* new_texture = ::get_texture(texture_id))
{
third_texture_name = new_texture->name;
texture_names[2] = new_texture->name;
return true;
}
return false;
Expand All @@ -691,7 +690,7 @@ bool RenderInfo::set_third_texture(TEXTURE texture_id)
bool RenderInfo::set_texture_num(uint32_t num)
{
// Prevent some crashes
if ((num >= 2 && !second_texture_name) || (num >= 3 && !third_texture_name) || num >= 4)
if ((num >= 2 && !texture_names[1]) || (num >= 3 && !texture_names[2]) || num >= 4)
{
return false;
}
Expand All @@ -704,7 +703,7 @@ bool RenderInfo::set_normal_map_texture(TEXTURE texture_id)
if (set_second_texture(texture_id))
{
constexpr uint32_t SHINE_TEXTURE = 400;
third_texture_name = ::get_texture(SHINE_TEXTURE)->name;
texture_names[2] = ::get_texture(SHINE_TEXTURE)->name;
texture_num = 3;
return true;
}
Expand Down
56 changes: 24 additions & 32 deletions src/game_api/render_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "containers/game_vector.hpp" // for game_vector
#include "math.hpp" // for Quad, AABB (ptr only)
#include "texture.hpp" // for Texture
#include "thread_utils.hpp" // for OnHeapPointer

struct JournalUI;
struct Layer;
Expand Down Expand Up @@ -261,20 +262,21 @@ struct RenderInfo
float x;
float y;
uint32_t unknown3;
float unknown4;
uint32_t unknown5;
float offset_x;
float offset_y;
uint32_t unknown6;
uint32_t unknown7;
uint32_t unknown8;
uint32_t unknown9;
float unknown8; // used for parallax?
float unknown9; // automatically goes to 0, while it's non 0 game does (unknown9/unknown8) or something like that and influences position

float x_dupe1; // position last refresh
float y_dupe1; // position last refresh
uint32_t unknown10;
float x_dupe2;
float y_dupe2;
uint32_t unknown11;
uint8_t unknown_timer1; // can someone test this at higher refresh rate if it's tided to the fps or Hz?
uint8_t unknown_timer2; // for some entities this stops when the entity is not on screen but the above one don't
uint8_t unknown_timer2; // for some entities this stops when the entity is not on screen but the above one doesn't
bool unknown12c;
bool unknown12d;
bool render_inactive; // stops all the rendering stuff, the value is forced thou
Expand All @@ -287,7 +289,7 @@ struct RenderInfo
bool unknown17;
bool unknown18;
uint32_t unknown19;
WORLD_SHADER shader; // 0 - 36, game crash at around 55
WORLD_SHADER shader;
uint8_t unknown20a;
uint8_t unknown20b;
uint8_t unknown20c;
Expand Down Expand Up @@ -319,37 +321,27 @@ struct RenderInfo
float angle2;
float angle_related;
uint32_t animation_frame;
uint32_t unknown38;
Texture* texture;
const char** texture_name;

const char** second_texture_name; // Normal map texture on COG entities (shader 30), shine texture on ice entities. May not have a correct value on entities that don't use it
const char** third_texture_name; // Shine texture on COG entities (shader 30). May not have a correct value on entities that don't use it
size_t unknown41; // fourth texture?? seems to be somehow used if changing the texture_num to 4
size_t unknown42;
size_t unknown43;
size_t unknown44;
uint32_t unknown38; // padding
Texture* texture; // probably just used for definition
const char** texture_names[7];
// second_texture_name Normal map texture on COG entities (shader 30), shine texture on ice entities. May not have a correct value on entities that don't use it
// third_texture_name Shine texture on COG entities (shader 30). May not have a correct value on entities that don't use it

uint32_t texture_num; // liquids use 0, most sprite entities use 1, ice uses 2, COG entities use 3
uint32_t unknown50;
size_t entity_offset; // the offset of the associated entity in memory, starting from the memory segment that State resides in
uint32_t padding1;
OnHeapPointer<Entity> entity_offset;
bool flip_horizontal; // facing left
uint8_t unknown52;
uint8_t unknown53;
uint8_t unknown54;
uint8_t padding2[3];
uint32_t unknown55;
float darkness; // 0.0 = completely black ; 1.0 = normal (dark effect like when on fire)
uint32_t unknown56;
uint32_t unknown57;
uint32_t unknown58;
float* unknown59;
uint32_t unknown60;
uint32_t unknown61; // end, next RenderInfo below
float brightness; // 0.0 = completely black ; 1.0 = normal (used for dark effect like when on fire)

virtual ~RenderInfo() = 0;
virtual void unknown_v2() = 0;
virtual void update() = 0;
virtual void render(float*) = 0;
virtual bool unknown_3() = 0; // init? sets darkness to 1.0 at the start, then does some other stuff
/// Called when the entity enters the camera view, using its hitbox with an extra threshold. Handles low-level graphics tasks related to the GPU
virtual void draw() = 0; // initializes positions
virtual void update() = 0; // math, basically always runs before render
/// Offset used in CO to draw the fake image of the entity on the other side of a level
virtual void render(Vec2* offset) = 0;
virtual bool set_entity(Texture* texture, Entity* entity) = 0;

// gets the entity owning this RenderInfo
Entity* get_entity() const;
Expand Down
Loading

0 comments on commit c6b8917

Please sign in to comment.