diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua
index f53843818..55546995d 100644
--- a/docs/game_data/spel2.lua
+++ b/docs/game_data/spel2.lua
@@ -2500,13 +2500,18 @@ function PRNG:random(min, max) end
---@class RenderInfo
---@field x number
---@field y number
+ ---@field offset_x number
+ ---@field offset_y number
---@field shader WORLD_SHADER
---@field source Quad
---@field destination Quad
---@field tilew number
---@field tileh number
---@field facing_left boolean
+ ---@field angle number
+ ---@field animation_frame integer
---@field render_inactive boolean
+ ---@field brightness number
---@field texture_num integer
---@field get_entity fun(self): Entity
---@field set_normal_map_texture fun(self, texture_id: TEXTURE): boolean @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)
@@ -2520,8 +2525,10 @@ function PRNG:random(min, max) end
---@field clear_virtual fun(self, callback_id: CallbackId): nil @Clears the hook given by `callback_id`, alternatively use `clear_callback()` inside the hook.
---@field set_pre_dtor fun(self, fun: fun(self: RenderInfo): nil): CallbackId @Hooks before the virtual function.
The callback signature is `nil dtor(RenderInfo self)`
---@field set_post_dtor fun(self, fun: fun(self: RenderInfo): nil): CallbackId @Hooks after the virtual function.
The callback signature is `nil dtor(RenderInfo self)`
- ---@field set_pre_render fun(self, fun: fun(self: RenderInfo, number: number, vanilla_render_context: VanillaRenderContext): boolean): CallbackId @Hooks before the virtual function.
The callback signature is `bool render(RenderInfo self, number number, VanillaRenderContext vanilla_render_context)`
- ---@field set_post_render fun(self, fun: fun(self: RenderInfo, number: number, vanilla_render_context: VanillaRenderContext): boolean): CallbackId @Hooks after the virtual function.
The callback signature is `nil render(RenderInfo self, number number, VanillaRenderContext vanilla_render_context)`
+ ---@field set_pre_draw fun(self, fun: fun(self: RenderInfo): boolean): CallbackId @Hooks before the virtual function.
The callback signature is `bool draw(RenderInfo self)`
Virtual function docs:
Called when the entity enters the camera view, using its hitbox with an extra threshold. Handles low-level graphics tasks related to the GPU
+ ---@field set_post_draw fun(self, fun: fun(self: RenderInfo): boolean): CallbackId @Hooks after the virtual function.
The callback signature is `nil draw(RenderInfo self)`
Virtual function docs:
Called when the entity enters the camera view, using its hitbox with an extra threshold. Handles low-level graphics tasks related to the GPU
+ ---@field set_pre_render fun(self, fun: fun(self: RenderInfo, offset: Vec2, vanilla_render_context: VanillaRenderContext): boolean): CallbackId @Hooks before the virtual function.
The callback signature is `bool render(RenderInfo self, Vec2 offset, VanillaRenderContext vanilla_render_context)`
Virtual function docs:
Offset used in CO to draw the fake image of the entity on the other side of a level
+ ---@field set_post_render fun(self, fun: fun(self: RenderInfo, offset: Vec2, vanilla_render_context: VanillaRenderContext): boolean): CallbackId @Hooks after the virtual function.
The callback signature is `nil render(RenderInfo self, Vec2 offset, VanillaRenderContext vanilla_render_context)`
Virtual function docs:
Offset used in CO to draw the fake image of the entity on the other side of a level
---@class Entity
---@field type EntityDB @Type of the entity, contains special properties etc. If you want to edit them just for this entity look at the EntityDB
diff --git a/docs/src/includes/_enums.md b/docs/src/includes/_enums.md
index 78b5eab4e..052054fec 100644
--- a/docs/src/includes/_enums.md
+++ b/docs/src/includes/_enums.md
@@ -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
diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md
index 1f56dd347..78007ad73 100644
--- a/docs/src/includes/_types.md
+++ b/docs/src/includes/_types.md
@@ -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)
@@ -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.
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.
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.
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.
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.
The callback signature is `bool draw(RenderInfo self)`
Virtual function docs:
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.
The callback signature is `nil draw(RenderInfo self)`
Virtual function docs:
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.
The callback signature is `bool render(RenderInfo self, Vec2 offset, VanillaRenderContext vanilla_render_context)`
Virtual function docs:
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.
The callback signature is `nil render(RenderInfo self, Vec2 offset, VanillaRenderContext vanilla_render_context)`
Virtual function docs:
Offset used in CO to draw the fake image of the entity on the other side of a level
### RoomOwnerDetails
diff --git a/src/game_api/game_api.hpp b/src/game_api/game_api.hpp
index d60a5c601..9f1f6da3f 100644
--- a/src/game_api/game_api.hpp
+++ b/src/game_api/game_api.hpp
@@ -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;
@@ -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;
@@ -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
diff --git a/src/game_api/render_api.cpp b/src/game_api/render_api.cpp
index 2c22c2466..1562ce428 100644
--- a/src/game_api/render_api.cpp
+++ b/src/game_api/render_api.cpp
@@ -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;
@@ -660,7 +659,7 @@ void init_render_api_hooks()
Entity* RenderInfo::get_entity() const
{
- return OnHeapPointer{entity_offset}.decode_local();
+ return entity_offset.decode_local();
}
uint32_t RenderInfo::get_aux_id() const
@@ -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;
@@ -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;
@@ -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;
}
@@ -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;
}
diff --git a/src/game_api/render_api.hpp b/src/game_api/render_api.hpp
index 7269b8acf..e4dea8a3b 100644
--- a/src/game_api/render_api.hpp
+++ b/src/game_api/render_api.hpp
@@ -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;
@@ -261,12 +262,13 @@ 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;
@@ -274,7 +276,7 @@ struct RenderInfo
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
@@ -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;
@@ -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_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;
diff --git a/src/game_api/script/lua_backend.cpp b/src/game_api/script/lua_backend.cpp
index 3bf95bd4e..39cf1ecad 100644
--- a/src/game_api/script/lua_backend.cpp
+++ b/src/game_api/script/lua_backend.cpp
@@ -11,31 +11,30 @@
#include // for get
#include // for vector
-#include "aliases.hpp" // for IMAGE, JournalPageType
-#include "bucket.hpp" // for Bucket
-#include "constants.hpp" // for no_return_str
-#include "entities_chars.hpp" // for Player
-#include "entity.hpp" // for Entity, get_entity_ptr
-#include "handle_lua_function.hpp" // for handle_function
-#include "items.hpp" // for Inventory
-#include "level_api.hpp" // for LevelGenData, LevelGenSy...
-#include "level_api_types.hpp" // for LevelGenRoomData
-#include "lua_console.hpp" // for LuaConsole
-#include "lua_vm.hpp" // for acquire_lua_vm, get_lua_vm
-#include "math.hpp" // for AABB
-#include "movable_behavior.hpp" // for CustomMovableBehavior
-#include "overloaded.hpp" // for overloaded
-#include "rpc.hpp" // for get_frame_count, get_pla...
-#include "screen.hpp" // for get_screen_ptr, Screen
-#include "script_util.hpp" // for InputString
-#include "sound_manager.hpp" // for SoundManager
-#include "state.hpp" // for StateMemory, State, get_...
-#include "strings.hpp" // for clear_custom_shopitem_names
-#include "usertypes/gui_lua.hpp" // for GuiDrawContext
-#include "usertypes/level_lua.hpp" // for PreHandleRoomTilesContext
-#include "usertypes/save_context.hpp" // for LoadContext, SaveContext
-#include "usertypes/vanilla_render_lua.hpp" // for VanillaRenderContext
-#include "window_api.hpp" // for get_window
+#include "aliases.hpp" // for IMAGE, JournalPageType
+#include "bucket.hpp" // for Bucket
+#include "constants.hpp" // for no_return_str
+#include "entities_chars.hpp" // for Player
+#include "entity.hpp" // for Entity, get_entity_ptr
+#include "handle_lua_function.hpp" // for handle_function
+#include "items.hpp" // for Inventory
+#include "level_api.hpp" // for LevelGenData, LevelGenSy...
+#include "level_api_types.hpp" // for LevelGenRoomData
+#include "lua_console.hpp" // for LuaConsole
+#include "lua_vm.hpp" // for acquire_lua_vm, get_lua_vm
+#include "math.hpp" // for AABB
+#include "movable_behavior.hpp" // for CustomMovableBehavior
+#include "overloaded.hpp" // for overloaded
+#include "rpc.hpp" // for get_frame_count, get_pla...
+#include "screen.hpp" // for get_screen_ptr, Screen
+#include "script_util.hpp" // for InputString
+#include "sound_manager.hpp" // for SoundManager
+#include "state.hpp" // for StateMemory, State, get_...
+#include "strings.hpp" // for clear_custom_shopitem_names
+#include "usertypes/gui_lua.hpp" // for GuiDrawContext
+#include "usertypes/level_lua.hpp" // for PreHandleRoomTilesContext
+#include "usertypes/save_context.hpp" // for LoadContext, SaveContext
+#include "window_api.hpp" // for get_window
std::vector> g_all_backends;
std::unordered_map g_hotkeys;
diff --git a/src/game_api/script/lua_backend.hpp b/src/game_api/script/lua_backend.hpp
index 09d12a72d..f20c0fc3c 100644
--- a/src/game_api/script/lua_backend.hpp
+++ b/src/game_api/script/lua_backend.hpp
@@ -24,12 +24,13 @@
#include // for variant
#include // for vector
-#include "aliases.hpp" // for IMAGE, JournalPageType, SPAWN_TYPE
-#include "hook_handler.hpp" // for HookHandler
-#include "level_api.hpp" // IWYU pragma: keep
-#include "logger.h" // for DEBUG
-#include "script.hpp" // for ScriptMessage, ScriptImage (ptr only), Scri...
-#include "util.hpp" // for GlobalMutexProtectedResource, ON_SCOPE_EXIT
+#include "aliases.hpp" // for IMAGE, JournalPageType, SPAWN_TYPE
+#include "hook_handler.hpp" // for HookHandler
+#include "level_api.hpp" // IWYU pragma: keep
+#include "logger.h" // for DEBUG
+#include "script.hpp" // for ScriptMessage, ScriptImage (ptr only), Scri...
+#include "usertypes/vanilla_render_lua.hpp" // for VanillaRenderContext, CORNER_FINISH
+#include "util.hpp" // for GlobalMutexProtectedResource, ON_SCOPE_EXIT
extern std::recursive_mutex global_lua_lock;
@@ -352,6 +353,7 @@ class LuaBackend
size_t frame_counter{0};
bool infinite_loop_detection{true};
+ CORNER_FINISH vanilla_render_corner_finish = CORNER_FINISH::ADAPTIVE;
LuaBackend(SoundManager* sound_manager, LuaConsole* console);
virtual ~LuaBackend();
diff --git a/src/game_api/script/usertypes/entity_lua.cpp b/src/game_api/script/usertypes/entity_lua.cpp
index 5a37bb72f..59884962c 100644
--- a/src/game_api/script/usertypes/entity_lua.cpp
+++ b/src/game_api/script/usertypes/entity_lua.cpp
@@ -91,6 +91,10 @@ void register_usertypes(sol::state& lua)
&RenderInfo::x,
"y",
&RenderInfo::y,
+ "offset_x",
+ &RenderInfo::offset_x,
+ "offset_y",
+ &RenderInfo::offset_y,
"shader",
&RenderInfo::shader,
"source",
@@ -114,8 +118,14 @@ void register_usertypes(sol::state& lua)
&RenderInfo::tileh,
"facing_left",
&RenderInfo::flip_horizontal,
+ "angle",
+ &RenderInfo::angle1,
+ "animation_frame",
+ &RenderInfo::animation_frame,
"render_inactive",
&RenderInfo::render_inactive,
+ "brightness",
+ &RenderInfo::brightness,
"texture_num",
sol::readonly(&RenderInfo::texture_num),
"get_entity",
@@ -125,20 +135,20 @@ void register_usertypes(sol::state& lua)
"get_second_texture",
[](const RenderInfo& ri) -> std::optional
{
- if (!ri.second_texture_name || ri.texture_num < 2)
+ if (!ri.texture_names[1] || ri.texture_num < 2)
{
return std::nullopt;
}
- return ::get_texture(std::string_view(*ri.second_texture_name)) /**/;
+ return ::get_texture(std::string_view(*ri.texture_names[1])) /**/;
},
"get_third_texture",
[](const RenderInfo& ri) -> std::optional
{
- if (!ri.third_texture_name || ri.texture_num < 3)
+ if (!ri.texture_names[2] || ri.texture_num < 3)
{
return std::nullopt;
}
- return ::get_texture(std::string_view(*ri.third_texture_name)) /**/;
+ return ::get_texture(std::string_view(*ri.texture_names[2])) /**/;
},
"set_second_texture",
&RenderInfo::set_second_texture,
diff --git a/src/game_api/script/usertypes/vanilla_render_lua.cpp b/src/game_api/script/usertypes/vanilla_render_lua.cpp
index 655fc184a..a8c55fe02 100644
--- a/src/game_api/script/usertypes/vanilla_render_lua.cpp
+++ b/src/game_api/script/usertypes/vanilla_render_lua.cpp
@@ -9,10 +9,11 @@
#include // for get
#include // for move, declval
-#include "particles.hpp" // for ParticleEmitterInfo
-#include "render_api.hpp" // for TextureRenderingInfo, WorldShader, TextRen...
-#include "state.hpp" // for enum_to_layer
-#include "texture.hpp" // for Texture, get_texture
+#include "particles.hpp" // for ParticleEmitterInfo
+#include "render_api.hpp" // for TextureRenderingInfo, WorldShader, TextRen...
+#include "script/lua_backend.hpp" // for get_calling_backend
+#include "state.hpp" // for enum_to_layer
+#include "texture.hpp" // for Texture, get_texture
void VanillaRenderContext::draw_text(const std::string& text, float x, float y, float scale_x, float scale_y, Color color, VANILLA_TEXT_ALIGNMENT alignment, VANILLA_FONT_STYLE fontstyle)
{
@@ -134,18 +135,19 @@ void VanillaRenderContext::draw_screen_texture(TEXTURE texture_id, TextureRender
RenderAPI::get().draw_screen_texture(texture, std::move(tri), std::move(color), 0x29);
}
-auto g_angle_style = CORNER_FINISH::ADAPTIVE;
-
void VanillaRenderContext::set_corner_finish(CORNER_FINISH c)
{
- g_angle_style = c;
+ auto backend = LuaBackend::get_calling_backend();
+ backend->vanilla_render_corner_finish = c;
}
// get a Quad to fill out the corner between two lines and fix their overlap
Quad get_corner_quad(Quad& line1, Quad& line2)
{
- if (g_angle_style == CORNER_FINISH::NONE)
+ auto backend = LuaBackend::get_calling_backend();
+ if (backend->vanilla_render_corner_finish == CORNER_FINISH::NONE)
return {};
+
// save the corners as Vec2 for easier calculations
// and calculate inner and outer corner, we don't know which is which at this point
Vec2 A{line1.top_left_x, line1.top_left_y};
@@ -191,16 +193,17 @@ Quad get_corner_quad(Quad& line1, Quad& line2)
Vec2 middle_point = *first - (*first - *second) / 2;
- if (g_angle_style == CORNER_FINISH::ADAPTIVE && std::abs(true_angle) > 1.6f)
+ if (backend->vanilla_render_corner_finish == CORNER_FINISH::ADAPTIVE && std::abs(true_angle) > 1.6f)
{
Vec2 offset = *outer_corner - middle_point;
offset = offset * (float)std::pow((std::abs(true_angle) - 1.6f) / 1.54f, 2);
*outer_corner -= offset;
}
- else if (g_angle_style == CORNER_FINISH::CUT)
+ else if (backend->vanilla_render_corner_finish == CORNER_FINISH::CUT)
{
*outer_corner = *second;
}
+ // else CORNER_FINISH::REAL
if (std::abs(true_angle) > 3) // for small corners it's hard to do this right, so we give up on this
{
diff --git a/src/game_api/script/usertypes/vtables_lua.cpp b/src/game_api/script/usertypes/vtables_lua.cpp
index eafeb2028..536d358f3 100644
--- a/src/game_api/script/usertypes/vtables_lua.cpp
+++ b/src/game_api/script/usertypes/vtables_lua.cpp
@@ -95,7 +95,8 @@ void register_usertypes(sol::state& lua)
RenderInfo,
CallbackType::Entity,
VTableEntry<"dtor", 0x0, void()>,
- VTableEntry<"render", 0x3, void(float*), BackBinder>>;
+ VTableEntry<"draw", 0x1, void()>,
+ VTableEntry<"render", 0x3, void(Vec2*), BackBinder>>;
static RenderInfoVTable render_info_vtable(lua, lua["RenderInfo"], "RENDER_INFO_OVERRIDE");
// Define the implementations for the LuaBackend handlers
diff --git a/src/game_api/thread_utils.hpp b/src/game_api/thread_utils.hpp
index d36fd826d..73853283b 100644
--- a/src/game_api/thread_utils.hpp
+++ b/src/game_api/thread_utils.hpp
@@ -20,12 +20,12 @@ class OnHeapPointer
{
}
- T* decode()
+ T* decode() const
{
return reinterpret_cast(ptr_ + heap_base());
}
- T* decode_local()
+ T* decode_local() const
{
auto lhb = local_heap_base();
if (lhb == 0)
@@ -34,7 +34,7 @@ class OnHeapPointer
return reinterpret_cast(ptr_ + lhb);
}
- T* operator->()
+ T* operator->() const
{
return decode();
}