ClassMemory - Best way to processPatternScan several AOBs?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mebo
Posts: 14
Joined: 22 Apr 2021, 16:08

ClassMemory - Best way to processPatternScan several AOBs?

15 May 2021, 22:03

Hey there!

I'm using RHCP's classMemory library and had a question around efficiency.

I'm currently using the following code for a function:

Code: Select all

memWrite(jp, en, loopCount := "1", start:= "0x46000000", end:= "0x50000000")
{
  loop, %loopCount%
  {
    AOB:= mem.hexStringToPattern(jp)
    Address:= mem.processPatternScan(start, end, AOB*)

    if (%loopCount% > 1)
    {
      Address:= Address + 1
    }

    Address:= mem.processPatternScan(Address,,AOB*)
    mem.writeBytes(Address, en)
  }
}
What I'm doing is iterating over several json objects, converting them to hex and doing processPatternScans on them to replace them with the text I want to see instead. The problem here of course is scanning through that memory range can be slow the more you scale the list of things you want to scan. I don't know where my string is going to be, but it's always in that region of memory.

I read a little bit about readRaw(), which lets you dump large chunks of memory. Would something like that be feasible with the amount of memory I'm wanting to store in a variable to scan through? Something like dumping that region of memory to a variable, doing all of my searches in that buffer to find the address, then write to the actual addresses.

Thanks for your help.
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: ClassMemory - Best way to processPatternScan several AOBs?

16 May 2021, 06:24

mebo wrote: What I'm doing is iterating over several json objects
Little is clear. What do you mean by "json objects"? Can you provide an example, what you have, and what you want to get as a result?
mebo
Posts: 14
Joined: 22 Apr 2021, 16:08

Re: ClassMemory - Best way to processPatternScan several AOBs?

16 May 2021, 10:54

Hey teadrinker,

Sorry, I didn't share that because it wasn't too relevant, but the json I'm iterating over stores the utf-8 text for both Japanese and English. I'm using a function (https://www.autohotkey.com/boards/viewtopic.php?t=68782) to convert the Japanese to hex and the same for English. I'm using those hex values to do pattern scans against the process.

For instance, I have the following:

Code: Select all

[
  {
    "jp_string": "冒険をする",
    "en_string": "Open Adventure"
  },
  {
    "jp_string": "冒険の書をつくる",
    "en_string": "Create Adventure"
  },
  {
    "jp_string": "冒険の書を消す",
    "en_string": "Erase Adventure"
  }
 ]
The parsing part works and does exactly what I need to. But, I may have hundreds of records I want to scan for and update with the en_string hex output instead. Doing the entire scan and write can take minutes against the list I currently have and I intend to only grow the list.

Does that help?
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: ClassMemory - Best way to processPatternScan several AOBs?

16 May 2021, 12:10

mebo wrote: For instance, I have the following
What do you need to do with it?
mebo
Posts: 14
Joined: 22 Apr 2021, 16:08

Re: ClassMemory - Best way to processPatternScan several AOBs?

16 May 2021, 12:29

teadrinker wrote:
16 May 2021, 12:10
mebo wrote: For instance, I have the following
What do you need to do with it?
I guess my question is this:

With the above context, I am converting utf-8 strings to hex, searching for the JP hex and replacing with the EN hex. The actual processPatternScan method that is used to search for the JP hex'd string value is executed for every single string in the json file.

So, I'm producing probably 100+ processPatternScans at the moment, where they start at 0x46000000 and stop at 0x50000000. This is slow -- so I'm wanting to know how I can speed this process up.
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: ClassMemory - Best way to processPatternScan several AOBs?

17 May 2021, 02:09

Until you clarify your goal, everything you do looks weird and unnecessary. As I undestand, you need to change the JSON string. There are a lot of more straight ways to achieve this, rather than memory parsing.
mebo
Posts: 14
Joined: 22 Apr 2021, 16:08

Re: ClassMemory - Best way to processPatternScan several AOBs?

17 May 2021, 15:44

Sorry, I'll try to be as descriptive as possible on what I'm trying to accomplish here.

I have a game that's written entirely in Japanese. I don't have access to modify the game's files, but I had the idea of automatically searching for said Japanese and replacing the Japanese text with English. Using autohotkey, I'm using RHCP's Memory class for the heavy lifting of specifically the `processPatternScan` and `write` functions to find this Japanese text and replace it with English text.

The json that exists is basically a dictionary of objects. My script says: find this Japanese text (from the json files) in memory by first converting the string to hex (as this is one of the supported formats for `processPatternScan`), convert the English to hex as well, find the Japanese text with `processPatternScan` and replace with the English hex exactly as you see it.

The code that I've written is published in https://github.com/jmctune/dqxclarity if you'd like a quick look, but the json here isn't really relevant other than seeing what I'm using `processPatternScan` for. What's relevant (and what I'm trying to ask for help on) is this:

- I have 100+ unique patterns I need to scan for in memory
- What's the most efficient way to scan for and write to memory for these unique patterns

From an iterative list of 100+ unique patterns, I'm scanning one, then writing, then scanning, then writing, over and over. I'm trying to figure out the most efficient way to do this in one go, versus having to iterate over each json object one at a time.

I hope this clears things up.
teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: ClassMemory - Best way to processPatternScan several AOBs?

17 May 2021, 16:40

Thanks for clarifications. I have no experience with such tasks, perhaps someone else can help. Anyway you can try what you metioned:
Would something like that be feasible with the amount of memory I'm wanting to store in a variable to scan through?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: ClassMemory - Best way to processPatternScan several AOBs?

17 May 2021, 20:08

its unlikely that these strings always appear randomized in different places in memory, rather theyre at particular offsets depending on whats currently showing on screen(eg if the pause menu is up, pause menu strings is what u see).
i think u need to reverse further, find and record all offsets, then detect the current state and simply overwrite memory at the specified offsets without checking or looking for it
mebo
Posts: 14
Joined: 22 Apr 2021, 16:08

Re: ClassMemory - Best way to processPatternScan several AOBs?

18 May 2021, 07:37

Hey swagfag,

Thanks for replying.

These values are loaded into memory the second you load the game up. They're UI elements that display various things.

I would love to know the exact placement of these addresses instead as that'd be near instant.

You bring up a good point though about them just being offset. I am going to have to dig into that more.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Billykid, Google [Bot], Rohwedder and 205 guests