• Hey everyone happy Christmas Eve we're aware of what's happened with the source code so to keep this simple absolutely don't post it on the site or use it to make mods with (it's not particularly preferable toward this end anyway) and tread lightly in general until we see how this settles, thanks to all and have a great holiday season -DT

Weird instructions

Oct 15, 2009 at 5:11 AM
Hoxtilicious
"Life begins and ends with Nu."
Join Date: Dec 30, 2005
Location: Germany
Posts: 3218
Age: 33
Pronouns: No homie
I have a question for you guys.
At 004168C0, there is a function which executes this code:

Code:
   push ebp
mov ebp,esp
push ecx
movzx eax,byte ptr [PlayerFlags]
and eax,00000080
jne A
jmp B
A: cmp dword ptr [LvBarFlashesLeft],00
je C
mov ecx,[LvBarFlashesLeft]
sub ecx,01
mov [LvBarFlashesLeft],ecx
C: movzx edx,byte ptr [0049E6C8]
test edx,edx
je D
mov ax,[0049E6C8]
sub al,01
mov byte ptr [0049E6C8],al
jmp E
D: cmp dword ptr [ExpToGained],00
je E
mov ecx,[ExpToGained]
push ecx
push PlayerYPosition
push PlayerXPosition
call 00425BF0
add esp,0C
mov [ExpToGained],00000000
E: mov edx,[InFishBattle]
mov [ebp-0004],edx
cmp dword ptr [ebp-0004],00
je F
cmp dword ptr [ebp-0004],01
je G
jmp J
F: mov eax,[GameState]
and eax,04
jne K
cmp dword ptr [ebp+0008],00
je K
call 00416990
K: mov ecx,[ebp+0008]
push ecx
call 004156C0
add esp,04
jmp J
G: mov edx,[ebp+0008]
push edx
call 00416470
add esp,04
J: movzx eax,byte ptr [PlayerFlags]
and eax,DF
mov byte ptr [PlayerFlags],al
B: mov esp,ebp
pop ebp
ret

Now I have three questions:

Code:
   movzx eax,byte ptr [PlayerFlags]
and eax,00000080
jne A
jmp B

This. Why does it test if the player is visible and when he is not it executes code for the player, like movement and so on, what the fuck? This makes no sense.
It should be the other way round, or did I just got something wrong?

Code:
   movzx edx,byte ptr [0049E6C8]
test edx,edx
je D

Why is it moving a byte from memory into the edx and then tests edx with edx? Isn't this useless...?

Code:
   J: movzx eax,byte ptr [PlayerFlags]
and eax,DF
mov byte ptr [PlayerFlags],al

Allright, this just confuses me :S What does it do there anyway?
 
Oct 15, 2009 at 5:35 AM
Lvl 1
Forum Moderator
"Life begins and ends with Nu."
Join Date: May 28, 2008
Location: PMMM MMO
Posts: 3713
Age: 32
I don't know what those bits of code do, but if I were you I'd experiment with removing them during runtime. Messing with the code during runtime normally helps me figure out what does what.

And if that doesn't work then I don't know. Where is that bit of code called anyways? Every frame?
 
Oct 15, 2009 at 5:39 AM
Hoxtilicious
"Life begins and ends with Nu."
Join Date: Dec 30, 2005
Location: Germany
Posts: 3218
Age: 33
Pronouns: No homie
GIRakaCHEEZER said:
I don't know what those bits of code do, but if I were you I'd experiment with removing them during runtime. Messing with the code during runtime normally helps me figure out what does what.

I want to know what it does to the numbers stored in the registers :/
I'm not even sure what a "test" instruction is and how it differs from "compare".

GIRakaCHEEZER said:
And if that doesn't work then I don't know. Where is that bit of code called anyways? Every frame?

004103EC. Seems to be some kind of "main loop", when looking at all these calls.
 
Oct 15, 2009 at 5:50 AM
Lvl 1
Forum Moderator
"Life begins and ends with Nu."
Join Date: May 28, 2008
Location: PMMM MMO
Posts: 3713
Age: 32
Yeah as far as the testing with itself goes, I have no clue why it does that.
I have seen it before though in the code, but I've tried to ignore it.

I'll play with it later, shouldn't be too hard to figure out.
I recommend removing one of the paths it takes at a time, and seeing what that does. If you do that you should learn what it's checking for (if it's handling exp then i recommend doing tests with that as well).
 
Oct 15, 2009 at 1:35 PM
Been here way too long...
"Ha! Ha! Ha! Mega Man is no match for my Mimiga Man!"
Join Date: Jun 22, 2008
Location:
Posts: 251
The first one:

It looks lke when he is invisible, he doesn't move. This sounds pretty normal to me.

The second one:

testing something with itself will determine if it is zero. The reason its used instead of CMP is because it is faster. It can only tell equal, or not equal, though.

The third:

sets one of the flags with whatever is in DF. Check my flags topic if you aren't sure how this works.
 
Oct 15, 2009 at 2:47 PM
Lvl 1
Forum Moderator
"Life begins and ends with Nu."
Join Date: May 28, 2008
Location: PMMM MMO
Posts: 3713
Age: 32
dooey100 said:
The second one:

testing something with itself will determine if it is zero. The reason its used instead of CMP is because it is faster. It can only tell equal, or not equal, though.

So it's basically CMP EDX, 0 ?

And also does that mean it sets NOT EQUAL when it's zero? (I'd imagine that's how it was, but I'm not sure).

And I thought that last bit was a flag (thanks to what you taught me) but I wasn't sure and I didn't want to give SP any faulty advice.

[EDIT]: Also, dooey, do you know where the executable declares/sets how much ram it uses? Since if you did it would be great (I've been wanting to add a couple global variables.....).
 
Oct 15, 2009 at 4:47 PM
Been here way too long...
"Ha! Ha! Ha! Mega Man is no match for my Mimiga Man!"
Join Date: Jun 22, 2008
Location:
Posts: 251
yup, pretty much.


I have no idea. What I would do is look at FL+ to find out what space is used to store the flags, then use one of those variables. I'm pretty sure they are global variables, so you can do whatever you want with them, you don't have to use them for flags. Just make sure you don't set them in your TSC. One integer will use up 8 flags, though that shouldn't be a problem unless you are using a bazillions of flags in your mod.
 
Oct 15, 2009 at 5:33 PM
Hoxtilicious
"Life begins and ends with Nu."
Join Date: Dec 30, 2005
Location: Germany
Posts: 3218
Age: 33
Pronouns: No homie
dooey100 said:
It looks lke when he is invisible, he doesn't move. This sounds pretty normal to me.

That's not right actually :x

Code:
   movzx eax,byte ptr [PlayerFlags]
and eax,00000080
jne A
jmp EndOfFunction

The Flag 0x80 is the PlayerIsVisible Flag, when it's not set, the player isn't visible. If PlayerFlags & 0x80 are not equal to 0x80 it executes it and when they are it jumps out of the Function. But that is like this:

Code:
   IF !(PlayerFlags & Player.Flags.Visible) THEN
GOTO A
ELSE
GOTO EndofFunction
ENDIF

If the Player is visible it doesn't execute the whole function :/
I don't understand why. Now don't tell me it's only executed when he is not visible, because that's not right, it calls another function where player movement is executed.

dooey100 said:
testing something with itself will determine if it is zero. The reason its used instead of CMP is because it is faster. It can only tell equal, or not equal, though.

Ah, allright, thanks.

dooey100 said:
sets one of the flags with whatever is in DF. Check my flags topic if you aren't sure how this works.

I know it's a flag, and I know how flags work. Like I said I wasn't sure about the instructions. But this image answered my question actually: http://www.faculty.iu-bremen.de/bir... Architecture/Registers CS_files/image002.jpg
 
Back
Top