Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Owner 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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Owner Author

ocornut commented Aug 7, 2017

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

@hinxx

This comment has been minimized.

Copy link

hinxx commented Mar 9, 2018

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

@hinxx

This comment has been minimized.

Copy link

hinxx commented Mar 9, 2018

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

@hinxx

This comment has been minimized.

Copy link

hinxx commented Mar 9, 2018

.. yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.