Skip to content

Commit

Permalink
more snappiness
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Jan 6, 2021
1 parent a526692 commit 877bda3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Current features and their *default* keyboard shortcuts:
+ **Ctrl+Shift+Space**: Teleport to coordinates
+ **Mouse left**: Spawn entity at mouse cursor
+ **Mouse right**: Teleport to mouse cursor
+ **Mouse middle**: Drag most entities around (not stuff like walls)
+ **Shift+Mouse middle**: Drag all entities around (even walls and background)
+ **Ctrl+Mouse middle**: Launch dragged entity with velocity
+ You can also draw a velocity vector for spawn/teleport by holding the mouse button
+ Dragged entities have noclip on, so you can drag yourself through walls etc
+ Enter multiple numeric IDs like `526 560 570` to spawn them all at once. Useful for making a kit you can just paste in.
- **F2**: Spawn doors to many places
+ **Enter**: Spawn warp door (when tool is active)
Expand Down
28 changes: 14 additions & 14 deletions crates/injected/cxx/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ bool clickevents = false;
bool file_written = false;
bool god = false;
bool hidedebug = true;
bool snap_to_grid = true;
bool snap_to_grid = false;
bool throw_held = false;

const char* themes[] = { "1: Dwelling", "2: Jungle", "2: Volcana", "3: Olmec", "4: Tide Pool", "4: Temple", "5: Ice Caves", "6: Neo Babylon", "7: Sunken City", "8: Cosmic Ocean", "4: City of Gold", "4: Duat", "4: Abzu", "6: Tiamat", "7: Eggplant World", "7: Hundun" };

const char* flagnames[] = { "1: Invisible", "2: ", "3: ", "4: Passes through objects", "5: Passes through everything", "6: Take no damage", "7: Throwable/Knockbackable", "8: ", "9: ", "10: ", "11: ", "12: ", "13: Collides walls", "14: ", "15: Can be stomped", "16: ", "17: Going left", "18: Pickupable", "19: ", "20: Enterable (door)", "21: ", "22: ", "23: ", "24: ", "25: Passes through player", "26: ", "27: ", "28: Pause AI and physics", "29: Dead", "30: ", "31: ", "32: " };
const char* flagnames[] = { "1: Invisible", "2: ", "3: ", "4: Passes through objects", "5: Passes through everything", "6: Take no damage", "7: Throwable/Knockbackable", "8: ", "9: ", "10: ", "11: ", "12: ", "13: Collides walls", "14: ", "15: Can be stomped", "16: ", "17: Facing left", "18: Pickupable", "19: ", "20: Enterable (door)", "21: ", "22: ", "23: ", "24: ", "25: Passes through player", "26: ", "27: ", "28: Pause AI and physics", "29: Dead", "30: ", "31: ", "32: " };

bool process_keys(
_In_ int nCode,
Expand Down Expand Up @@ -380,27 +380,27 @@ bool process_keys(
}
else if (pressed("teleport_left", wParam))
{
teleport(-3, 0, false, 0, 0);
teleport(-3, 0, false, 0, 0, snap_to_grid);
}
else if (pressed("teleport_right", wParam))
{
teleport(3, 0, false, 0, 0);
teleport(3, 0, false, 0, 0, snap_to_grid);
}
else if (pressed("teleport_up", wParam))
{
teleport(0, 3, false, 0, 0);
teleport(0, 3, false, 0, 0, snap_to_grid);
}
else if (pressed("teleport_down", wParam))
{
teleport(0, -3, false, 0, 0);
teleport(0, -3, false, 0, 0, snap_to_grid);
}
else if (pressed("spawn_layer_door", wParam))
{
spawn_backdoor(0.0, 0.0);
}
else if(pressed("teleport", wParam))
{
teleport(g_x, g_y, false, 0, 0);
teleport(g_x, g_y, false, 0, 0, snap_to_grid);
}
else if (pressed("coordinate_left", wParam))
{
Expand Down Expand Up @@ -773,7 +773,7 @@ void render_clickhandler()
{
set_pos(startpos);
set_vel(ImGui::GetMousePos());
teleport(g_x, g_y, true, g_vx, g_vy);
teleport(g_x, g_y, true, g_vx, g_vy, snap_to_grid);
g_x = 0; g_y = 0; g_vx = 0; g_vy = 0;
}
if(ImGui::IsMouseReleased(0) || ImGui::IsMouseReleased(1))
Expand Down Expand Up @@ -805,15 +805,15 @@ void render_clickhandler()
throw_held = true;
}
set_pos(startpos);
move_entity(g_held_entity, g_x, g_y, true, 0, 0);
move_entity(g_held_entity, g_x, g_y, true, 0, 0, false);
render_arrow();
}
else if(ImGui::IsMouseDown(2) && g_held_entity > 0)
{
throw_held = false;
io.MouseDrawCursor = false;
set_pos(ImGui::GetMousePos());
move_entity(g_held_entity, g_x, g_y, true, 0, 0);
move_entity(g_held_entity, g_x, g_y, true, 0, 0, false);
}
if(ImGui::IsMouseReleased(2) && GetAsyncKeyState(keys["mod_throw"]) & 0x8000 && g_held_entity > 0)
{
Expand All @@ -824,7 +824,7 @@ void render_clickhandler()
set_entity_flags(g_held_entity, g_flags);
set_pos(startpos);
set_vel(ImGui::GetMousePos());
move_entity(g_held_entity, g_x, g_y, true, g_vx, g_vy);
move_entity(g_held_entity, g_x, g_y, true, g_vx, g_vy, snap_to_grid);
g_x = 0; g_y = 0; g_vx = 0; g_vy = 0; g_held_entity = 0;
}
else if(ImGui::IsMouseReleased(2) && g_held_entity > 0)
Expand All @@ -834,7 +834,8 @@ void render_clickhandler()
g_flags = get_entity_flags(g_held_entity);
g_flags &= ~(1 << 4);
set_entity_flags(g_held_entity, g_flags);
g_held_entity = 0;
move_entity(g_held_entity, g_x, g_y, true, 0, 0, snap_to_grid);
g_x = 0; g_y = 0; g_vx = 0; g_vy = 0; g_held_entity = 0;
}
ImGui::End();
}
Expand All @@ -856,7 +857,7 @@ void render_options()

void render_debug()
{
ImGui::Text("You're not supposed to be here!");
ImGui::TextWrapped("You're not supposed to be here, but since you already are, you could help me document what all these unknown flags do!");
if(ImGui::Button("List items"))
{
list_items();
Expand All @@ -877,7 +878,6 @@ void render_debug()
if(ImGui::Button("Set flags"))
{
set_entity_flags(g_last_entity, g_flags);
g_flags = get_entity_flags(g_last_entity);
}
unsigned int old_flags = g_flags;
ImGui::Text("Flags:");
Expand Down
14 changes: 11 additions & 3 deletions crates/injected/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,18 @@ impl Entity {
}
}

pub fn teleport(&self, dx: f32, dy: f32, s: bool, vx: f32, vy: f32) {
pub fn teleport(&self, dx: f32, dy: f32, s: bool, vx: f32, vy: f32, snap: bool) {
// e.g. topmost == turkey if riding turkey. player has relative coordinate to turkey.
let topmost = self.topmost();
let (mut x, mut y) = topmost.position();
if !s {
// player relative coordinates
x += dx;
y += dy;
if snap {
x = x.round();
y = y.round();
}
let px = topmost.pointer + 0x40;
let py = topmost.pointer + 0x44;
log::debug!("Teleporting to {}, {}", x, y);
Expand All @@ -441,6 +445,10 @@ impl Entity {
log::debug!("Camera is at {}, {}", cx, cy);
x = cx + 0.74 * cz * dx;
y = cy + 0.41625 * cz * dy;
if snap && vx.abs() + vy.abs() <= 0.04 {
x = x.round();
y = y.round();
}
log::debug!("Teleporting to {}, {}", x, y);
write_mem(px, &x.to_le_bytes());
write_mem(py, &y.to_le_bytes());
Expand Down Expand Up @@ -515,8 +523,8 @@ impl Player {
self.entity.layer()
}

pub fn teleport(&self, dx: f32, dy: f32, s: bool, vx: f32, vy: f32) {
self.entity.teleport(dx, dy, s, vx, vy)
pub fn teleport(&self, dx: f32, dy: f32, s: bool, vx: f32, vy: f32, snap: bool) {
self.entity.teleport(dx, dy, s, vx, vy, snap)
}

pub fn status(&self) -> PlayerStatus {
Expand Down
12 changes: 6 additions & 6 deletions crates/injected/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub mod ffi {
unsafe fn spawn_entity(id: usize, x: f32, y: f32, s: bool, vx: f32, vy: f32, snap: bool) -> u32;
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, vx: f32, vy: f32);
unsafe fn teleport(x: f32, y: f32, s: bool, vx: f32, vy: f32, snap: bool);
unsafe fn godmode(g: bool);
unsafe fn zoom(level: f32);
unsafe fn list_items();
unsafe fn get_entity_at(x: f32, y: f32, s: bool, r: f32, mask: u32) -> u32;
unsafe fn move_entity(id: u32, x: f32, y: f32, s: bool, vx: f32, vy: f32);
unsafe fn move_entity(id: u32, x: f32, y: f32, s: bool, vx: f32, vy: f32, snap: bool);
unsafe fn get_entity_flags(id: u32) -> u32;
unsafe fn set_entity_flags(id: u32, flags: u32);
unsafe fn player_status();
Expand Down Expand Up @@ -102,13 +102,13 @@ pub unsafe fn spawn_backdoor(x: f32, y: f32) {
}
}

pub unsafe fn teleport(x: f32, y: f32, s: bool, vx: f32, vy: f32) {
pub unsafe fn teleport(x: f32, y: f32, s: bool, vx: f32, vy: f32, snap: bool) {
let state = State::new();

match state.items().player(0) {
Some(player) => {
log::debug!("Teleporting to relative {}, {}, {}", x, y, s);
player.teleport(x, y, s, vx, vy);
player.teleport(x, y, s, vx, vy, snap);
}
None => {}
}
Expand Down Expand Up @@ -174,13 +174,13 @@ pub unsafe fn get_entity_at(mut x: f32, mut y: f32, s: bool, r: f32, mask: u32)
}
}

pub unsafe fn move_entity(id: u32, x: f32, y: f32, s: bool, vx: f32, vy: f32) {
pub unsafe fn move_entity(id: u32, x: f32, y: f32, s: bool, vx: f32, vy: f32, snap: bool) {
let state = State::new();
match state.items().player(0) {
Some(player) => {
for item in state.layer(player.layer()).items() {
if item.unique_id() == id {
item.teleport(x, y, s, vx, vy);
item.teleport(x, y, s, vx, vy, snap);
}
}
}
Expand Down

0 comments on commit 877bda3

Please sign in to comment.