get_cell impl in ewext (maybe)

This commit is contained in:
IQuant 2024-09-17 14:31:08 +03:00
parent eaa8c2832c
commit da2cb9b625
4 changed files with 35 additions and 1 deletions

15
.vscode/c_cpp_properties.json vendored Normal file
View file

@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}

View file

@ -9,5 +9,6 @@
"Lua.diagnostics.globals": [ "Lua.diagnostics.globals": [
"wait", "wait",
"async" "async"
] ],
"C_Cpp.default.compilerPath": "/usr/bin/clang++"
} }

View file

@ -4,6 +4,8 @@ use lua_bindings::{lua_State, Lua51};
mod lua_bindings; mod lua_bindings;
mod noita;
static LUA: LazyLock<Lua51> = LazyLock::new(|| unsafe { static LUA: LazyLock<Lua51> = LazyLock::new(|| unsafe {
let lib = libloading::Library::new("./lua51.dll").expect("library to exist"); let lib = libloading::Library::new("./lua51.dll").expect("library to exist");
Lua51::from_library(lib).expect("library to be lua") Lua51::from_library(lib).expect("library to be lua")

16
ewext/src/noita.rs Normal file
View file

@ -0,0 +1,16 @@
use std::ffi::c_void;
pub(crate) struct ChunkMap {
this: *mut c_void,
}
impl ChunkMap {
unsafe fn get_cell(&self, x: u32, y: u32) {
let x = x as isize;
let y = y as isize;
let index = ((((y) >> 9) - 256 & 511) * 512 + (((x) >> 9) - 256 & 511)) * 4;
let chunk_arr = self.this.offset(8).cast::<*const c_void>().read();
let chunk = chunk_arr.offset(index).cast::<*const c_void>().read();
let pixel = chunk.offset(((y & 511) << 9 | x & 511) * 4);
}
}