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

StateMemory and State structs changes #379

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

estebanfer
Copy link
Contributor

Some StateMemory and State changes, discussion started in #369 (comment)

@@ -31,8 +31,7 @@ Entity* Layer::spawn_entity(ENT_TYPE id, float x, float y, bool screen, float vx
}
else if (screen)
{
auto& state = State::get();
std::tie(x, y) = state.click_position(x, y);
std::tie(x, y) = StateMemory::click_position(x, y);
min_speed_check = 0.04f;
if (snap && abs(vx) + abs(vy) <= min_speed_check)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove the screen param?
if i recall, it's only used by the UI, so we could move this feature to the ui_util

auto* state_ptr = State::get().ptr_local();
auto* state_ptr = State::ptr_local();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're changing every getter, can we get rid of the _local part?
I think there should always be just ptr() and ptr_main() (since the second one is the specific one used rarely)
But I'm open for discussion if someone have better idea/reasons to keep the naming

@@ -0,0 +1,24 @@
#include "savedata.hpp"
struct ModAPI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If everything is static, it begs the question what this struct is even for?

@@ -6,15 +6,12 @@

PRNG& PRNG::get_main()
{
const auto& state = State::get();
static PRNG* prng = (PRNG*)((size_t)state.ptr_main() - 0xb0);
static PRNG* prng = &State::get_main()->prng;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now confusing.

State::get_main()->prng
gets the prng

State::ptr()
gets the ptr to ... something

By the code itself I would assume it's State itself, but that's not the case

if (!functions_hooked)
{
auto memory = Memory::get();
auto addr_damage = memory.at_exe(get_virtual_function_address(VTABLE_OFFSET::CHAR_ANA_SPELUNKY, 48));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't write this code, but wondering why this is done via Detour probably better to do it via hook_vtable ?

@@ -260,7 +258,7 @@ std::vector<Player*> get_players(StateMemory* state)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should probably be just member of StateMemory

auto& state = State::get();
state.set_camera_position(cx, cy);
StateMemory* state = State::ptr();
state->set_camera_position(cx, cy);
}

void warp(uint8_t world, uint8_t level, uint8_t theme)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of those simple functions that just get StateMemory and return some value from it or based on it, should probably be just member functions of the StateMemory. Then in lua_vm just make lambda.

@Mr-Auto
Copy link
Contributor

Mr-Auto commented Aug 3, 2024

Would you mind if i try and make my own version of this PR ?

@estebanfer
Copy link
Contributor Author

Maybe it would be even better if you're the one that makes this PR tbh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants