Skip to content

Instantly share code, notes, and snippets.

@ocornut
Last active January 1, 2024 04:27
Show Gist options
  • Star 78 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save ocornut/0673e37e54aff644298b to your computer and use it in GitHub Desktop.
Save ocornut/0673e37e54aff644298b to your computer and use it in GitHub Desktop.
Mini memory editor for dear imgui (to embed in your game/tools)
// Mini memory editor for Dear ImGui (to embed in your game/tools)
// Animated GIF: https://twitter.com/ocornut/status/894242704317530112
// THE MEMORY EDITOR CODE HAS MOVED TO GIT:
// https://github.com/ocornut/imgui_club/tree/master/imgui_memory_editor
// Click "Revisions" on the Gist to see old version.
@leiradel
Copy link

leiradel commented Jul 8, 2017

I'm using it and works great, but when the memory is being changed outside of the control (I'm watching memory from an emulator) the content under the cursor doesn't change. I was puzzled for a while before moving the cursor and seeing the byte updating to the expected value :D

@ocornut
Copy link
Author

ocornut commented Aug 6, 2017

Hello @leiradel, sorry I missed your question earlier.
It is a little tricky because the InputText widget is currently always "owning" the active text.
I've came up with a workaround by rewriting the content of the text. The gist above has been update to v0.11.

And here is the test code I used to verify it worked:

static unsigned char ram[0x1000] = { 0 };
if ((ImGui::GetFrameCount() % 60) == 0)
    for (int n = 0; n < 0x1000; n++)
        ram[n] = ((n % 16) << 4) | ((ram[n]+1) & 0x0F);
static MemoryEditor mem_editor;
mem_editor.Draw("Test", ram, 0x1000);

@bkaradzic
Copy link

bkaradzic commented Aug 7, 2017

I had to add following to build:

#include <stdio.h>
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wtype-limits"
imgui_memory_editor.h:229:94: error: suggest parentheses around ‘&&’ within ‘||’ [-Werror=parentheses]
                     bool is_next_byte_highlighted = (n + 1 == Rows) || (addr + 1 < mem_size) && ((HighlightMax != (size_t)-1 && addr + 1 < HighlightMax) || (HighlightFn && HighlightFn(mem_data, addr + 1)));
imgui_memory_editor.h:286:24: error: suggest explicit braces to avoid ambiguous ‘else’ [-Werror=parentheses]
                     if (data_write && sscanf(DataInputBuf, "%X", &data_input_value) == 1
imgui_memory_editor.h:387:26: error: comparison of unsigned expression >= 0 is always true [-Werror=type-limits]
             if (GotoAddr >= 0 && GotoAddr < mem_size)

@ocornut
Copy link
Author

ocornut commented Aug 7, 2017

@bkaradzic: thanks, all 4 (inc. stdio) should be fixed now.

@hinxx
Copy link

hinxx commented Mar 9, 2018

Great gadget @ocornut!
If only I could get a callback when user changes a byte..

@hinxx
Copy link

hinxx commented Mar 9, 2018

.. or is it WriteFn() I want ..

@hinxx
Copy link

hinxx commented Mar 9, 2018

.. yes

@Jenrikku
Copy link

Jenrikku commented Jul 14, 2022

Hello! I know this gist is pretty old now but I find it very interesting. Could it be possible to update it so it works with the newest versions of imgui?
Nevermind! I see that it has been moved. It's really nice, by the way.

@ocornut
Copy link
Author

ocornut commented Jul 14, 2022

The header of the file has a link to the repository where this is now located and up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment