mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
remove material list ptr from init
This commit is contained in:
parent
8abc51ddd9
commit
f8c00de976
4 changed files with 42 additions and 15 deletions
|
@ -34,12 +34,5 @@ function OnWorldInitialized()
|
|||
started = 60
|
||||
local grid_world = world_ffi.get_grid_world()
|
||||
grid_world = tonumber(ffi.cast("intptr_t", grid_world))
|
||||
local material_list = tonumber(ffi.cast("intptr_t", world_ffi.get_material_ptr(0)))
|
||||
local mat_len = 0
|
||||
local name = CellFactory_GetName(mat_len)
|
||||
while name ~= "unknown" do
|
||||
mat_len = mat_len + 1
|
||||
name = CellFactory_GetName(mat_len)
|
||||
end
|
||||
blob_guy.init_particle_world_state(grid_world, material_list, mat_len)
|
||||
blob_guy.init_particle_world_state(grid_world)
|
||||
end
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use crate::noita::ntypes;
|
||||
use eyre::ContextCompat;
|
||||
use object::{Object, ObjectSection};
|
||||
use std::arch::asm;
|
||||
use std::ffi::c_void;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
pub fn get_functions() -> eyre::Result<(*const c_void, *const c_void, *const c_void)> {
|
||||
pub fn get_functions() -> eyre::Result<(*const c_void, *const c_void, *const ntypes::GameGlobal)> {
|
||||
let exe = std::env::current_exe()?;
|
||||
let mut file = File::open(exe)?;
|
||||
let mut vec = Vec::with_capacity(15460864);
|
||||
|
@ -30,9 +31,9 @@ pub fn get_functions() -> eyre::Result<(*const c_void, *const c_void, *const c_v
|
|||
let game_global_ptr = get_global(game_global_ptr);
|
||||
Ok((construct_ptr, remove_ptr, game_global_ptr))
|
||||
}
|
||||
fn get_global(global: *const c_void) -> *const c_void {
|
||||
fn get_global(global: *const c_void) -> *const ntypes::GameGlobal {
|
||||
unsafe {
|
||||
let ptr: *const c_void;
|
||||
let ptr: *const ntypes::GameGlobal;
|
||||
asm!(
|
||||
"call {global}",
|
||||
global = in(reg) global,
|
||||
|
|
|
@ -5,6 +5,7 @@ pub mod noita;
|
|||
use crate::blob_guy::Blob;
|
||||
use crate::chunk::Chunk;
|
||||
use crate::noita::ParticleWorldState;
|
||||
use eyre::ContextCompat;
|
||||
use noita_api::add_lua_fn;
|
||||
use noita_api::lua::LUA;
|
||||
use noita_api::lua::LuaState;
|
||||
|
@ -50,13 +51,20 @@ pub unsafe extern "C" fn luaopen_blob_guy(lua: *mut lua_State) -> c_int {
|
|||
fn init_particle_world_state(lua: LuaState) -> eyre::Result<()> {
|
||||
STATE.with(|state| {
|
||||
let mut state = state.try_borrow_mut()?;
|
||||
let (construct_ptr, remove_ptr, _) = init_data::get_functions()?;
|
||||
let (construct_ptr, remove_ptr, global_ptr) = init_data::get_functions()?;
|
||||
let global = unsafe { global_ptr.as_ref() }.wrap_err("no global?")?;
|
||||
let world_ptr = lua.to_integer(1) as *const noita::ntypes::GridWorld;
|
||||
let chunk_map = unsafe { world_ptr.as_ref().unwrap() }.chunk_map.cell_array;
|
||||
let material_list_ptr = lua.to_integer(2) as *const noita::ntypes::CellData;
|
||||
let mat_len = lua.to_integer(3);
|
||||
let cell_factory = unsafe {
|
||||
global
|
||||
.m_cell_factory
|
||||
.as_ref()
|
||||
.wrap_err("no cell factory??")?
|
||||
};
|
||||
let material_list_ptr = cell_factory.cell_data_ptr;
|
||||
let material_list =
|
||||
unsafe { std::slice::from_raw_parts(material_list_ptr, mat_len as usize) };
|
||||
unsafe { std::slice::from_raw_parts(material_list_ptr, cell_factory.cell_data_len) };
|
||||
|
||||
let blob_guy = noita_api::raw::cell_factory_get_type("blob_guy".into())? as u16;
|
||||
state.blob_guy = blob_guy;
|
||||
let pws = ParticleWorldState {
|
||||
|
|
|
@ -689,3 +689,28 @@ pub struct LiquidCell {
|
|||
pub color: Color,
|
||||
pub not_color: Color,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct GameWorld {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct CellFactory {
|
||||
unknown1: [isize; 5],
|
||||
pub cell_data_len: usize,
|
||||
pub cell_data_ptr: *const CellData,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
pub struct GameGlobal {
|
||||
pub frame_num: usize,
|
||||
unknown1: [isize; 2],
|
||||
pub m_game_world: *const GameWorld,
|
||||
pub m_grid_world: *const c_void,
|
||||
pub m_textures: *const c_void,
|
||||
pub m_cell_factory: *const CellFactory,
|
||||
unknown2: [isize; 11],
|
||||
pub pause_state: isize,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue