grumpycoders / pcsx-redux

The PCSX-Redux project is a collection of tools, research, hardware design, and libraries aiming at development and reverse engineering on the PlayStation 1. The core product itself, PCSX-Redux, is yet another fork of the Playstation emulator, PCSX.
https://pcsx-redux.consoledev.net
GNU General Public License v2.0
603 stars 93 forks source link

[Feature Request] Copy text from the contents of windows eg Assembly, Memory Editor, Registers. #1571

Open potus-barret opened 4 months ago

potus-barret commented 4 months ago

Fist off, awesome tool. Seriously. But I am finding my self wanting to copy sections of text from the memory, assembly and registers to paste into my notes and am resorting to a ocr tool of mine, which can mess up from time to time.

Ive seen that logs has a copy button and at one point was grabbing the content from other windows as a bug ( #721 ). I dont know if it was grabbing the whole contents of other windows or just what was at that point in time visible in the window.

I dont intend to distract from more important things and as I said I have a workaround that is at least better than transcribing, so not at all urgent in my case. Just a thought.

nicolasnoble commented 4 months ago

These are absolutely valid requests, yes. The registers one is the one that's bugging me the most personally at the moment, tho there's a sort of derpy workaround: you can edit a register, and copy its value there. I need to think of a UX method to copy the values directly instead, maybe with a middle click or something. This may be a quick change I could do tonight, even.

Concerning the hex viewers, the main memory is available externally (1) through a REST-compliant web server, and (2) through read-write shared memory blocks. My thinking is that it'd be better to have something like ImHex being able to access either of these, and just use the internal hex viewer for quick visualization and editing, while leaving the heavy lifting of a fully-featured hex editor to an external application. I probably should file a feature request there and discuss how we could proceed. The plugin API may or may not allow for this already.

For the assembly window, I'd need to think about how I'd do it exactly, but what you're talking about is doable, I think, without too much fuss.

nicolasnoble commented 4 months ago

So interestingly, on Linux, ImHex already can read the memory mappings of the memory natively. If you run Redux on Linux, check /dev/shm, there ought to be a mapping for its main ram. Opening it with ImHex should work straight, and will automatically notice changes, as expected. No idea how that'd work on MacOS.

Might need to create a plugin for ImHex to add a provider for these. I could see how we'd want to add some more ImHex features dedicated to PSX too.

potus-barret commented 4 months ago

I am indeed on linux Ill look into shm, for the moment my workaround has become pretty reliable. I may as well share it as it isnt too complex, just bind it to some key combination of your choosing and then its simply a case of :

  1. press keybind
  2. click and drag
  3. paste

maim -s | tesseract stdin stdout --psm 6 --dpi 72 | xclip -i -selection clipboard -f | xclip -i -selection primary

or

maim -s | mogrify -modulate 100,0 -normalize -channel RGB -negate -scale 100% png:- | tesseract stdin stdout --psm 6 --dpi 72 | xclip -i -selection clipboard -f | xclip -i -selection primary

Obviously you'd require the prerequisite programs, or perhaps if under wayland, counterparts if there are any. They should be in every distro's repo's as written except for mogrify.

The second line throws imagemagik (mogrify) into the mix to produce a better contrast for tesseract to chew on if its making a lot of mistakes. Screen resolution and redux's theme and font scale will effect results, so you can tweak them if your hunting goldilocks but it should not be necessary.

--psm 6 on tesseract's call was necessary to prevent it treating separate columns in assembly view as different pages and breaking up addresses, bytes and instructions.

It will miss a char here and there and on occasion confuse l whit 1. But for note taking purposes its dandy. (And damn useful whenever you want to pull text from an image quickly)

unrelated to this use case, day to day i often use this in a keybind to copy unselectable text and put it in the clipboard as 1 continuos string of text with no line breaks. (though ive added --psm 6 last night after fighting with redux's assembly view as i dont see myself needing to ocr pages side by side)

maim -s | tesseract stdin stdout --psm 6 --dpi 72 | tr '\n' ' ' | xclip -i -selection clipboard -f | xclip -i -selection primary

EDIT: oh, forgot to mention, if installing tesseract for the first time you will need to also install a tesseract language model, English will do fine. Searching the repos for 'tesseract english' should find what you need.

notdodgeball commented 4 months ago

image

I have a working prototype using lua (ugh, proportional font) I'm glad I saved it, it may help @potus-barret. Turns out I can't copy from it as well. Curiously, we have ImGui::LogToClipboard and ImGui::LogFinish but no ImGui::LogText:

image

So I'm not able to copy anything. Do you want me to open an issue?

I can use print() and copy from console though.

nicolasnoble commented 4 months ago

image

I have a working prototype using lua (ugh, proportional font) I'm glad I saved it, it may help @potus-barret. Turns out I can't copy from it as well. Curiously, we have ImGui::LogToClipboard and ImGui::LogFinish but no ImGui::LogText:

image

So I'm not able to copy anything. Do you want me to open an issue?

I can use print() and copy from console though.

Regarding the fonts, I should add API functions to allow using the non-proportional fonts that Redux possesses. Regarding the LogText function, this is because the Lua binding doesn't really handle the vararg mechanism at the moment: https://github.com/grumpycoders/pcsx-redux/blob/e1465ba508e5d3b9b3c09ae08e1c287153c55e22/third_party/imgui_lua_bindings/imgui_iterator.inl#L1574-L1578

But I can easily add extra APIs for these, without the vararg: it'd only take a single string, which would need to be formatted Lua-side.

nicolasnoble commented 4 months ago

@notdodgeball check the latest documentation push: https://github.com/grumpycoders/pcsx-redux/commit/df959fa06b0bd1a72e8ec095e32d1f3396979b84

notdodgeball commented 4 months ago

https://pastebin.com/31yZE8E6

Sorry, I forgot. Here is the lua script, hope it helps somehow.