From da2cb9b62548b645d6c4587ead923cf038ad2d00 Mon Sep 17 00:00:00 2001 From: IQuant Date: Tue, 17 Sep 2024 14:31:08 +0300 Subject: [PATCH] get_cell impl in ewext (maybe) --- .vscode/c_cpp_properties.json | 15 +++++++++++++++ .vscode/settings.json | 3 ++- ewext/src/lib.rs | 2 ++ ewext/src/noita.rs | 16 ++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 ewext/src/noita.rs diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 00000000..64d3f903 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,15 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "linux-clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index bcad2d74..095aab46 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,6 @@ "Lua.diagnostics.globals": [ "wait", "async" - ] + ], + "C_Cpp.default.compilerPath": "/usr/bin/clang++" } \ No newline at end of file diff --git a/ewext/src/lib.rs b/ewext/src/lib.rs index 8486b869..5e2715bf 100644 --- a/ewext/src/lib.rs +++ b/ewext/src/lib.rs @@ -4,6 +4,8 @@ use lua_bindings::{lua_State, Lua51}; mod lua_bindings; +mod noita; + static LUA: LazyLock = LazyLock::new(|| unsafe { let lib = libloading::Library::new("./lua51.dll").expect("library to exist"); Lua51::from_library(lib).expect("library to be lua") diff --git a/ewext/src/noita.rs b/ewext/src/noita.rs new file mode 100644 index 00000000..2425cb40 --- /dev/null +++ b/ewext/src/noita.rs @@ -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); + } +}