Skip to content

Commit

Permalink
cleaned up ui, write the entity list to file on launch
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Nov 19, 2020
1 parent 01a23a9 commit 12e06a2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Current features and their keyboard shortcuts:
+ **Ctrl+Arrows**: Move spawn coordinates around you
+ **Ctrl+Enter**: Teleport to coordinates
+ Enter multiple numeric IDs like `526 560 570` to spawn them all at once. Useful for making a kit you can just paste in.
+ Note: Item numbers can change between versions, so use the search to find the latest ones!
+ Note: Item numbers can change between versions, so use the search to find the latest ones or check `Spelunky 2/entities.txt`
- **F2**: Spawn a warp door to any world, level and theme
+ **Enter**: Spawn door. Set the appropriate theme theme too or you will get weird results.
- **F11**: Hide overlay completely for screenshots and faking being a god gamer
Expand Down
76 changes: 58 additions & 18 deletions crates/injected/cxx/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <algorithm>
#include <sstream>
#include <string>
#include <iostream>
#include <fstream>

IDXGISwapChain *pSwapChain;
ID3D11Device *pDevice;
Expand Down Expand Up @@ -49,6 +51,7 @@ bool click_spawn = false;
bool click_teleport = false;
bool hidegui = false;
bool clickevents = false;
bool file_written = 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" };

Expand Down Expand Up @@ -161,6 +164,11 @@ bool process_keys(
}
return true;
}
else if (wParam == VK_F9)
{
toggle("Help and Options (F9)");
return true;
}

ImGuiContext& g = *GImGui;
ImGuiWindow* current = g.NavWindow;
Expand Down Expand Up @@ -265,6 +273,18 @@ void update_filter(const char *s)
g_current_item = 0;
}

void write_file()
{
std::ofstream file;
file.open("entities.txt");
for (int i = 0; i < g_items.size(); i++)
{
file << g_items[i].id << ": " << g_items[i].name.data() << std::endl;
}
file.close();
file_written = true;
}

void render_list()
{
// ImGui::ListBox with filter
Expand Down Expand Up @@ -328,13 +348,19 @@ void render_input()
ImGui::SetKeyboardFocusHere();
set_focus_entity = false;
}
ImVec2 region = ImGui::GetContentRegionMax();
ImGui::PushItemWidth(region.x-70);
if (ImGui::InputText("##Input", text, sizeof(text), 0, NULL))
{
update_filter(text);
}
if(ImGui::Button("Spawn entity")) {
ImGui::PopItemWidth();
ImGui::SameLine();
ImGui::PushItemWidth(60);
if(ImGui::Button("Spawn")) {
spawn_entities(false);
}
ImGui::PopItemWidth();
}

void render_narnia()
Expand All @@ -347,7 +373,7 @@ void render_narnia()
ImGui::SameLine(53);
ImGui::Text("Level");
ImGui::SameLine(100);
ImGui::Text("Theme (Arrows)");
ImGui::Text("Theme");
ImGui::SetNextItemWidth(40);
if(set_focus_world) {
ImGui::SetKeyboardFocusHere();
Expand All @@ -370,7 +396,7 @@ void render_narnia()
ImGui::SameLine(100);
ImGui::SetNextItemWidth(200);
render_themes();
if(ImGui::Button("Spawn door")) {
if(ImGui::Button("Spawn")) {
spawn_entity(770, g_x, g_y, false);
spawn_door(g_x, g_y, g_world, g_level, 1, g_to+1);
}
Expand Down Expand Up @@ -481,39 +507,53 @@ HRESULT __stdcall hkPresent(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT
if(clickevents) {
render_clickhandler();
}
ImGui::SetNextWindowSize({400, 400}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize({400, 300}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos({0, 0}, ImGuiCond_FirstUseEver);
ImGui::Begin("Entity spawner (F1)");
ImGui::PushItemWidth(-1);
ImGui::Checkbox("##clickevents", &clickevents);
ImGui::SameLine();
ImGui::Text("Enable click to spawn/teleport (bit buggy)");
if(clickevents) {
ImGui::Text("(Enter) or left click to spawn");
ImGui::Text("(Ctrl+Enter) or right click to teleport");
} else {
ImGui::Text("(Enter) to spawn");
ImGui::Text("(Ctrl+Enter) to teleport");
}
ImGui::Text("(Ctrl+Arrow) Spawning at x: %+.2f, y: %+.2f", g_x, g_y);
ImGui::Text("Enter numeric IDs separated by space to spawn many.");
ImGui::Text("Spawning at x: %+.2f, y: %+.2f", g_x, g_y);
render_input();
render_list();
ImGui::PopItemWidth();
ImGui::End();

ImGui::SetNextWindowSize({300, 200}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize({300, 125}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos({400, 0}, ImGuiCond_FirstUseEver);
ImGui::Begin("Door to anywhere (F2)");
ImGui::PushItemWidth(-1);
ImGui::Text("Spawn a door to:");
render_narnia();
ImGui::PopItemWidth();
ImGui::End();

ImGui::SetNextWindowSize({400, 300}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos({ImGui::GetIO().DisplaySize.x-400, 0}, ImGuiCond_FirstUseEver);
ImGui::Begin("Help and Options (F9)");
ImGui::PushItemWidth(-1);
ImGui::Checkbox("##clickevents", &clickevents);
ImGui::SameLine();
ImGui::Text("Enable click to spawn/teleport");
ImGui::Text("Keys:");
if(clickevents) {
ImGui::Text("- (Enter) or (Mouse L) Use focused tool");
ImGui::Text("- (Ctrl+Enter) or (Mouse R) Teleport");
} else {
ImGui::Text("- (Enter) Use focused tool");
ImGui::Text("- (Ctrl+Enter) Teleport");
}
ImGui::Text("- (Arrows) Change selection in lists");
ImGui::Text("- (Ctrl+Arrows) Change spawning coordinates");
ImGui::Text("Write many numerical IDs separated by space in");
ImGui::Text("the entity spawner to spawn many items at once.");
ImGui::PopItemWidth();
ImGui::End();
}

ImGui::Render();

if(!file_written)
write_file();


pContext->OMSetRenderTargets(1, &mainRenderTargetView, NULL);
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
return oPresent(pSwapChain, SyncInterval, Flags);
Expand Down
4 changes: 2 additions & 2 deletions crates/injected/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Layer {
let cx = read_f32(get_camera(&memory));
let cy = read_f32(get_camera(&memory) + 4);
let rx = cx + 10.0 * x;
let ry = cy + 5.5 * y;
let ry = cy + 5.625 * y;
let addr: usize = load_item(self.pointer, id, rx, ry);
log::info!("Spawned {:x?}", addr);
}
Expand Down Expand Up @@ -203,7 +203,7 @@ impl Player {
let cy = read_f32(get_camera(&memory) + 4);
log::info!("Camera is at {}, {}", cx, cy);
x = (cx + 10.0 * dx).round();
y = (cy + 5.5 * dy).round();
y = (cy + 5.625 * dy).round();
log::info!("Teleporting to {}, {}", x, y);
write_mem(px, &x.to_le_bytes());
write_mem(py, &y.to_le_bytes());
Expand Down
4 changes: 2 additions & 2 deletions crates/injector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ fn main() {
};
log::info!("Found Spel2.exe PID: {}", proc.pid);
if !started {
log::info!("Waiting a while for the game to load...");
thread::sleep(time::Duration::from_millis(3000));
log::info!("Game was just started, waiting a few seconds for it to load before injecting...");
thread::sleep(time::Duration::from_millis(8000));
}
inject_dll(&proc, temp_path.to_str().unwrap());
call(
Expand Down

0 comments on commit 12e06a2

Please sign in to comment.