Skip to content

Commit

Permalink
add layer doors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Jan 2, 2021
1 parent 767e44b commit a1a6275
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ Current features and their keyboard shortcuts:
+ Lock horizontal scrolling with the *N*x buttons for *N* wide levels
+ Note: It only sets the *default* zoom level, which isn't used in camp or shops.
- **F11**: Hide overlay
- **Ctrl+G**: Toggle peaceful mode
- **Ctrl+G**: Toggle god mode
- **Ctrl+M**: Toggle click events
- **Ctrl+Numbers**: Set zoom level
- **RAlt+Arrows**: Teleport to direction
- **Shift+Enter**: Spawn a door to back layer
- Spawn or teleport to mouse cursor (see options)
- Peaceful mode (*nothing* takes damage from anything)

Expand Down
16 changes: 12 additions & 4 deletions crates/injected/cxx/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ bool process_keys(
teleport(0, -1, false);
return true;
}
else if (GetAsyncKeyState(VK_SHIFT) && wParam == VK_RETURN)
{
spawn_backdoor(0.0, 0.0);
return true;
}

ImGuiContext& g = *GImGui;
ImGuiWindow* current = g.NavWindow;
Expand Down Expand Up @@ -289,7 +294,6 @@ bool process_keys(
}
else if (enter && current == ImGui::FindWindowByName("Door to anywhere (F2)"))
{
spawn_entity(775, g_x, g_y, false);
spawn_door(0.0, 0.0, g_world, g_level, 1, g_to+1);
return true;
}
Expand Down Expand Up @@ -480,10 +484,13 @@ void render_narnia()
ImGui::SameLine(100);
ImGui::SetNextItemWidth(200);
render_themes();
if(ImGui::Button("Spawn")) {
spawn_entity(775, g_x, g_y, false);
if(ImGui::Button("Spawn warp door")) {
spawn_door(g_x, g_y, g_world, g_level, 1, g_to+1);
}
ImGui::SameLine();
if(ImGui::Button("Spawn layer door")) {
spawn_backdoor(g_x, g_y);
}
}

void render_camera()
Expand Down Expand Up @@ -694,7 +701,7 @@ HRESULT __stdcall hkPresent(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT
godmode(god);
}
ImGui::SameLine();
ImGui::Text("Enable peaceful mode");
ImGui::Text("Enable god mode");
ImGui::Text("Keys:");
if(clickevents) {
ImGui::Text("- (Enter) or (Mouse L) Use focused tool");
Expand All @@ -707,6 +714,7 @@ HRESULT __stdcall hkPresent(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT
ImGui::Text("- (Ctrl+Arrows) Change spawning coordinates");
ImGui::Text("- (RAlt+Arrows) Teleport to direction");
ImGui::Text("- (Ctrl+Comma/Period) Change zoom level");
ImGui::Text("- (Shift+Enter) Spawn a door to back layer");
ImGui::Text("Write many numerical IDs separated by space in");
ImGui::Text("the entity spawner to spawn many items at once.");
ImGui::PopItemWidth();
Expand Down
8 changes: 4 additions & 4 deletions crates/injected/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl Layer {
let load_item: extern "C" fn(usize, usize, f32, f32) -> usize =
std::mem::transmute(get_load_item());
if !s {
let addr: usize = load_item(self.pointer, id, x, y);
let addr: usize = load_item(self.pointer, id, x.round(), y.round());
log::debug!("Spawned {:x?}", addr);
Entity { pointer: addr }
} else {
Expand All @@ -269,7 +269,7 @@ impl Layer {
let cz = read_f32(get_zoom());
let rx = cx + 0.74 * cz * x;
let ry = cy + 0.41625 * cz * y;
let addr: usize = load_item(self.pointer, id, rx, ry);
let addr: usize = load_item(self.pointer, id, rx.round(), ry.round());
log::debug!("Spawned {:x?}", addr);
Entity { pointer: addr }
}
Expand All @@ -288,11 +288,11 @@ impl Layer {
let entity = match screen {
11 => {
log::debug!("In camp, spawning starting exit");
self.spawn_entity(25, x, y, false)
self.spawn_entity(25, x.round(), y.round(), false)
}
12 => {
log::debug!("In game, spawning regular exit");
self.spawn_entity(23, x, y, false)
self.spawn_entity(23, x.round(), y.round(), false)
}
_ => return,
};
Expand Down
37 changes: 37 additions & 0 deletions crates/injected/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod ffi {
extern "Rust" {
unsafe fn spawn_entity(id: usize, x: f32, y: f32, s: bool);
unsafe fn spawn_door(x: f32, y: f32, w: u8, l: u8, f: u8, t: u8);
unsafe fn spawn_backdoor(x: f32, y: f32);
unsafe fn teleport(x: f32, y: f32, s: bool);
unsafe fn godmode(g: bool);
unsafe fn zoom(level: f32);
Expand Down Expand Up @@ -53,6 +54,42 @@ pub unsafe fn spawn_door(x: f32, y: f32, l: u8, w: u8, f: u8, t: u8) {
state
.layer(player.layer())
.spawn_door(x + _x, y + _y, l, w, f, t);
state
.layer(player.layer())
.spawn_entity(37, x + _x, y + _y - 1.0, false);
state
.layer(player.layer())
.spawn_entity(775, x + _x, y + _y, false);
}
None => {}
}
}

pub unsafe fn spawn_backdoor(x: f32, y: f32) {
let state = State::new();

match state.items().player(0) {
Some(player) => {
let (_x, _y) = player.position();
log::debug!("Spawning backdoor on {}, {}", x + _x, y + _y);
state
.layer(0)
.spawn_entity(26, x + _x, y + _y, false);
state
.layer(1)
.spawn_entity(26, x + _x, y + _y, false);
state
.layer(0)
.spawn_entity(37, x + _x, y + _y - 1.0, false);
state
.layer(1)
.spawn_entity(37, x + _x, y + _y - 1.0, false);
state
.layer(0)
.spawn_entity(775, x + _x, y + _y, false);
state
.layer(1)
.spawn_entity(775, x + _x, y + _y, false);
}
None => {}
}
Expand Down

0 comments on commit a1a6275

Please sign in to comment.