+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  GBA Pointer searching?
Pages: 1 [2]
Author Topic: GBA Pointer searching?  (Read 2 times)
rmco2003
Guest
« Reply #15 on: March 11, 2009, 01:16:31 pm »

afaik the pointers are word aligned but I haven't looked at this too closely recently.
Tauwasser
Guest
« Reply #16 on: March 11, 2009, 03:47:16 pm »

Gosh guys, I'm fucking telling you that I am specifically talking about reads from procedures that can read unaligned data. If your game only uses asm/thumb, it is always going to be word-aligned. However, many games use ingame scripting and crazy tables that do not necessarily need to be word aligned because of the nature of the data stored. It would be silly to have an ingame scripting engine that only has four byte long opcodes just because then pointers would be aligned!

Also, it sounded like it might be such a case when he already found odd offsets, at least that's what I got from the posts.

cYa,

Tauwasser
rmco2003
Guest
« Reply #17 on: March 12, 2009, 02:21:21 am »

As I'm coding a new search app I realised I need that text concatenation because I need to swap the bytes, and if the 0's been stripped from the start it won't work properly.
creaothceann
Guest
« Reply #18 on: March 12, 2009, 03:02:25 am »

Quote from: Rhys on March 12, 2009, 02:21:21 am
As I'm coding a new search app I realised I need that text concatenation because I need to swap the bytes, and if the 0's been stripped from the start it won't work properly.

There's something wrong if you think you need text conversions to swap bytes. Roll Eyes
rmco2003
Guest
« Reply #19 on: March 12, 2009, 03:07:13 am »

Tell me how I do it in realbasic then Tongue
Kajitani-Eizan
Guest
« Reply #20 on: March 12, 2009, 03:15:34 am »

i can say this -- my code for doing similar stuff is in C/C++. i'm using Borland C++ 5.0 to compile, which for whatever reason seems to yield much faster-running code than visual studio. (i probably don't know which checkboxes to check to remove debug, optimize for speed, etc. -- also, i'm comparing a SUPER OLD compiler for DOS command line to a recent compiler that may not care THAT much about speed Tongue)

i also don't load the file into RAM. i'm not actually sure i should change it to do so, because the way it works now, the program runs separately for each file inserted. (and then quits, and then is run again, etc. using command line scripting.) *each time* a string is inserted, it searches an area of the ROM for relevant pointers -- this relevant area can be anywhere from 50k or so to about a meg. (yeah, it would probably make more sense to record these pointer locations so you only have to do it once, but i'll revise it to work that way once atlas is updated to have the features i want (KLARTH!) Tongue) while the process is pretty darn slow, it's not THAT slow... inserting a crapload of game text (probably like 70% of it, rough estimate? like 300k or so?), doing probably thousands of pointer searches, takes maybe a few minutes, total, on my core 2 duo 2 ghz system.

so i guess my point is, between your choice of language and your coding style, there is probably some SERIOUS inefficiency Tongue  glancing at your code, i can see the following:
- i assume that those App.DoEvents in the middle of the loops passes control to the windows application to let it do its thing, like increment the progress bar and check to see if any events have been triggered. having that execute EVERY TIME will slow things down like crazy. either get rid of it (no progress bar, sorry), or do it every so often, or something.
- there's no point in forming the full pointer and then string comparing it to the pointer you're looking for, or whatever. compare them byte by byte in nested if statements (which looks a bit messier but would be faster... the way it's written right now i doubt the compiler can manage to optimize it well). it would look something like:

if first byte matches then
{
  if second byte matches then
  {
    if third byte matches then
    {
      found = true, etc.
    }
  }
}
« Last Edit: March 12, 2009, 03:28:18 am by Kajitani-Eizan »
rmco2003
Guest
« Reply #21 on: March 12, 2009, 03:24:09 am »

Yeah I get that, but it shouldn't run slower than a Pentium 2 running Crysis Tongue

fyi Realbasic doesn't allow for changing the endianess of what's being read in the filestream, so I can't simply swap it to little endian and search for the value directly, that's why I have to swap the bytes myself.

I -may- just redo this in C, since I know that from dealing with Objective-C on mac, but the thing is I just code much quicker in VB.net / RB because I'm more familiar with them, and plus I hate semicolons.
Tauwasser
Guest
« Reply #22 on: March 12, 2009, 03:52:22 am »

Why do you compare it like that? BRPXQZME already posted an example where you just get the pointer as long and compare those two then. Of course then you can just do the math on your own and times the pointer you are comparing by 0x100 (and with 0xFFFFFFFF when necessary) and then ORing the next byte of the stream and so on. Those are all bit-operations so they should be pretty fast, too! Also, like I said, you could even use a little heuristic and look if the MSB is 0x08 or even 0x09 if your rom is really big. That way you don't even look at all the stuff in there.

cYa,

Tauwasser
rmco2003
Guest
« Reply #23 on: March 12, 2009, 03:55:24 am »

oops! I forgot about the whole 08 being at the end of the pointer thing /facepalm

updating my code now

[edit]

My code's still slow as hell so I think I might just output the pointers for all the blocks with my current code then search for the pointer locations in a C app so I can just make a batch script to find them all.
Code:
    Do Until Done = True Or bs.EOF = True
      If OffsetArray(OffsetArray.UBound) = Hex(bs.ReadInt32) Then
        bs.Position = bs.Position - 3
        Done = True
      End If
    Loop

[edit 2]

I've been writing some godawful C code all day but it's paid off! I finished my console application and shockingly it found the pointer in under a second! I know what I'll be using from now on Shocked

The funny thing is that it doesn't even have any of the optimization talked about in this thread, it literally searches byte by byte through the rom.

Now to finish my realbasic portion of the tools that'll generate the batch scripts for me to find these pointers.
« Last Edit: March 12, 2009, 10:11:06 am by Rhys »
Pages: 1 [2]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC