Jump to content

Recommended Posts

Posted

Actually, the way I was currently checking, it was using the FE. When I programmed it, I saw the part about male and female so I did that. However, I ran into a slight problem. For the few pokemon that have alternate forms, their FE doesn't respond to male or female. What of those few?

  • Replies 89
  • Created
  • Last Reply

Top Posters In This Topic

Posted (edited)

EDIT: Ah, son of a gun. Jiggy got me again. :(

The information for Fateful Encounter, gender, and alternate forms are stored in completely separate bits of the bytes at 0x40-0x41. Look at the two bytes this way:

0|0|0|0 0000 0000 0000

Where Blue is the flag for Fateful Encounter, Red is the flag for female, dark red is the flag for genderless, and the rest is for alternate forms.

Bear in mind that the data is stored in little-endian, which means the bits (and bytes) go from least significant to most significant from right to left.

Edited by codemonkey85
Posted
Bear in mind that the data is stored in little-endian, which means the bits (and bytes) go from least significant to most significant from right to left.

You have bit dyslexia again.

Little Endian has the least significant bits on the left side. It's the exact opposite of our normal number system, which is Big Endian.

You're color coded diagram is written in Big Endian.

Posted

I guess I gotta review some stuff about bits and bytes.

From what I understand though, I just need to access the first 3 parts of the binary to check. I guess it's simple enough as long as I understand the bits and bytes, haha. And I guess I can assume non-female, non-genderless is male.

You guys always come to my rescue. This is what happens when you take a mixed (in between college level and university level) CS course. That you ace (with 100%) and do nothing half the time cause you're done (and everyone but one aren't) because they're stupid. Did I mention the class average was 68% and my teacher knows C/C++ and never did VB? If I had learned any of this... hahaha

Posted

I took a VB beginner's course recently because I have to (college degree and all), and the teacher knew nothing at all about binary file handling. I was disappointed to find this out when I asked him some questions.

But anyway.

Just remember that VB handles a lot of things for you. Don't go reinventing the wheel; if you need to do some kind of bitwise operation or conversion, look and see what VB has to offer first.

Posted

I have been asking help on VB forums throughout the program, so I'm not going to redo some code I don't have to.

And "Don't go reinventing the wheel" was a phrase my tech teacher used to use a lot.

I'm glad everyone is so helpful. Ya know, I didn't expect it to be this much work when I started, I'm nearing the end of it though. There's only a few things left, and this is half of it. I have like OT gender and moves after this.

I asked for a code on integer (long in this circumstance) to binary, since I couldn't google one that works, nor did by attempts work. I think if I have it in binary, it will be easier to work with. The way I display alternate forms right now does work though, but for gender, it will be better.

I also have a C++ book sitting beside me because I plan to learn it. I am actually planning on a Comp. Eng. program post secondary, I thought it would be useful to learn a popular language instead of VB.NET that sucks. Once I finish this program or the bulk of it at least, I'll be using that book. I still have another year of HS so I have time to learn it.

So I make sure, when I convert the FE to binary. I convert it in little endian, so 41 then 40, and then I print the leading or trailing zeros?

Posted
I have been asking help on VB forums throughout the program, so I'm not going to redo some code I don't have to.

And "Don't go reinventing the wheel" was a phrase my tech teacher used to use a lot.

I'm glad everyone is so helpful. Ya know, I didn't expect it to be this much work when I started, I'm nearing the end of it though. There's only a few things left, and this is half of it. I have like OT gender and moves after this.

I asked for a code on integer (long in this circumstance) to binary, since I couldn't google one that works, nor did by attempts work. I think if I have it in binary, it will be easier to work with. The way I display alternate forms right now does work though, but for gender, it will be better.

I also have a C++ book sitting beside me because I plan to learn it. I am actually planning on a Comp. Eng. program post secondary, I thought it would be useful to learn a popular language instead of VB.NET that sucks. Once I finish this program or the bulk of it at least, I'll be using that book. I still have another year of HS so I have time to learn it.

So I make sure, when I convert the FE to binary. I convert it in little endian, so 41 then 40, and then I print the leading or trailing zeros?

Binary operations should still work on normal integers, since all computers store data in binary.

If you would like to study C++ source code, PPSE is written in C++. You are also free to contribute to it if you want to. It'd be great having someone else besides me working on it.

If you think it'd be too much for you, I have had exactly 0 formal programming training. All of my knowledge comes from books, online tutorials, documentation, and asking helpful people questions, like you're doing now.

Posted

It's not it is too much, I just didn't expect it to be this much. It is coming along well at least.

I know it's all stored in binary, but I have no idea how to print the appropriate extra 0's. I don't know if they are trailing 0's even. Like the file I checked, it was a Chansey with FE 02 00, so 0002. Comes up with 10 obviously in decimal. According to the information, it has FE ticked and is male, unless I'm doing something wrong.

I'll likely be taking more programming courses in university. I've taken 3 computer courses so far, one that was basically an intro, we did flow chart programming, Flash Action Script programming to make games like Tetris and Pong, overview of computer parts and circuitry. I took the CS one where we did VB Express, and then a comp. eng. where we learned about all the parts and how to put computers together, reformat and stuff like that. I did get proficiency in all 3 courses (1 was in g10).

The main thing is syntax between programs, and AS was based on C. I will be reading that book though, but I wanna finish this first tbh.

Posted

FE was supposed to be Fateful encounter part is : 02 00.

As you can probably see, I'm not that great with bits and bits, and all this stuff, even though I know what they are.

Since you guys stated that I can check the gender based on the FE, I'd do that. I already have code that does work for the alternate forms and FE ticked or not, I just need to check the gender this way.

The part we're checking is two bytes long, so in my case of 02 00, I only get a 2 bit answer. How exactly do I deal with that? 02 00 becomes 00 02 in little endian. Converted to binary, that's only 10. Where do I place the extra 0's, how do I do this? It's a Chansey with no FE, so it basically has to be 010 etc according to what Codemonkey posted.

Posted

You could have done a better job separating that from the number. Being next to 02 00, I thought FE was a hex number too, not an abbreviation. The fact that it happens to be 254, the number used to denote an all female Pokemon in the base stats and that you were discussing the gender of an all female Pokemon didn't help any either. Remember, we aren't mind readers.

0002 is in big endian, not little. 02 00 is the little endian form. Remember, big endian is like our normal English number system. The big numbers come first. We write the 100s place before the 10s.

Whenever you want to add 0s to an integer without changing its value, you always add them in the direction of most significance. For numbers written in big endian, most significance is to the left, so you add leading 0s. For little endian, it's the opposite, you add trailing 0s.

Also, you have your flags backwards. 0002 means that the "Fateful Encounter" flag is false (since bit #0 is 0) and the Pokemon is female (since bit #1 is 1 and bit #2 is 0).

Posted

I think I'm totally confused now. My understanding of little endian was it was in reverse of things. I was doing the higher offsets came first. If that's the little endian format, then it's going offset 40, offset 41, in that order to make it little endian.

I think I thought about just adding 0's statically, but how does it work if the number I'm using is still in some sort of non-binary form?

So lets get this straight then. If I use it in big endian, it's 0002, and then it produces 10 in binary. Then I put it into little endian from there, so I get 010000 etc and have flag off, female, rest 0's. And then If I use a Lugia that is 0400, I make it 0004, and it produces 100 in binary. I flip that around and get 001, which is flag off, no female, genderless.

Posted

First off, been busy for a few days, family reunion and stuff, but I'm back now. I got the gender working fine yesterday. But now I'm stuck with the shiny part. Here's the code I have so far (sorry it's a little messy).

'sends the hex array, IDnumber and SIDnumber to the function

Function SHINY(ByVal data() As Byte, ByVal IDnumber As Integer, ByVal SIDnumber As Integer)

Dim PID, PIDhex As String

'sets the PID equal to the hex value

PIDhex = String.Format("{0,2:X2}", data(3)) + String.Format("{0,2:X2}", data(2)) + String.Format("{0,2:X2}", data(1)) + String.Format("{0,2:X2}", data(0))

'converts the PID to long

PID = Long.Parse(PIDhex, Globalization.NumberStyles.HexNumber)

'this whole next part is a conversion to binary I personally coded

Dim temp As String

Dim Binary As String

Dim counter As Integer = 0

While PID > 0

temp = PID Mod 2

If PID Mod 2 = 1 Then

PID -= 1

End If

Binary = Binary + temp

PID = PID / 2

counter += 1

If counter Mod 8 = 0 Then 'displays it in groups of 8 like on Bulbapedia

Binary = Binary + " "

End If

End While

'sets the binary to a char array so you can reverse it and so forth

Dim reverse() As Char

reverse = Binary.ToCharArray()

Dim length As Integer = reverse.GetUpperBound(0)

Dim E, F, p1, p2 As Long

Dim shininess As Long

'since I did it in reverse, had to do it like this. skips leading 0's, won't make a diff.

For counter = length To 15 Step -1

p1 = p1 & reverse(counter)

Next

For counter = 15 To 0 Step -1

p2 = p2 & reverse(counter)

Next

E = IDnumber Xor SIDnumber

F = p1 Xor p2

shininess = E Xor F

The F value is what messes up, at least I think.

On this particular file

p1 = 11001011100011

p2 = 100101101011100

F = 89111004879351

E = 6227

PID = 123364262

PID in binary = 111 0101 1010 0110 0011 1010 0110 (reverse returns the reverse value however, but I accounted for that as you can see).

As you can see, it returns a really big number, even when I use a shiny pokemon. I obviously did something wrong somewhere, but knowing me, I can't figure it out.

Posted (edited)

This is what I don't get. You're converting the data in your byte array the hard way. Just do it the easy way. Instead of doing this:

Dim PID, PIDhex As String

'sets the PID equal to the hex value
PIDhex = String.Format("{0,2:X2}", data(3)) + String.Format("{0,2:X2}", data(2)) + String.Format("{0,2:X2}", data(1)) + String.Format("{0,2:X2}", data(0))

'converts the PID to long
PID = Long.Parse(PIDhex, Globalization.NumberStyles.HexNumber)

Do this:

Dim PID As UInt32

PID = BitConverter.ToUInt32(data, 0)

That is of course assuming that "data" is a byte array containing the PKM file data.

And anywhere that you use Integer you should switch to unsigned integers; either UInt16 or UInt32 depending on the size. In other words, the ID and SID are two bytes each, so they should be UInt16. And you don't need to "convert" them to binary to do a bitwise operation on them.

When I get home I will examine my shiny code and make further suggestions.

Edited by codemonkey85
Posted

I had to convert the PID to binary so I could access it properly. Bulbapedia works with it in binary, and it splits it in half, so I did that conversion. I just decided to convert to make it easier for me to understand, that is, for the other values.

Does it really matter which way I convert it? It works either way.

Posted

I know all my conversions in that code work, I tested them out. The binary one, I actually ended up making from scratch, but I did test it, and the long one already works to display the PID.

The likeliest place for an error is when I'm assigning the values of F.

Posted

Let me try and help out my own cause by explaining what I did and how I did it. Hopefully we can get to the bottom of this.

First off, all my conversions have been tested and work. There is nothing wrong with them. I know there are possibly better ways to do it, but as it stands, I really don't care since it works fine for me. The long one, it works to convert hex to long, integer etc., and I've displayed info accurately. The binary one, I made myself the other day and I tested it out to make sure it converts properly, and it does.

The reason I converted to binary was because of how Bulbapedia explained it all. They coded F as p1 and p2. They were separate parts of the PID in binary form, so I decided it would be easier if I did that. The way it was assigned into the char array, the highest index stores the highest value of the binary (ie the most left value). I did not add any leading or trailing 0's to the binary however, which may cause it to be the way it is. p2 is 0 to 15, so the latter 16 digits of the binary (the lower values), and then p1 becomes the higher values minus leading 0's that I didn't bother with.

ID Xor SID produces a 4 digit integer while p1 Xor p2 produces a number I believe I had to use long to store, it was very large, as was the outcome of E Xor F.

Posted

Yes, I agree. I put a spoiler for all the values I was producing, and I'm likely producing an error on the p1 or p2 values. I just explained how it works, so we need to figure out why I'm assigning it an incorrect value.

Posted

Hey, haven't worked on it in a few days. But I figured out where I was going wrong. I did some manual stuff, writing it all down, converting with calculator and so forth. What was wrong was reversing it and not adding the extra 0's. I had to do it the hard way to figure it out, but I'm sure of the problem now, or at least, pretty sure, it worked on the file I tested yielding 2 for shininess. Coding it may take some time, I probably won't do it today and I'll have to think about how I'm doing it, but at least I got it sorted out.

Posted

Hey guys, I hope someone can help me with this. I have a problem and for the life of me, I don't know why it does this. What this code does is check for the shininess. There is some other coding that is unnecessary. Before coding this, I did testing manually and I am sure it should work.

'assigns variables like on Bulbapedia

'used string to retain leading 0's as an integer would remove them

Dim E, F, p1, p2 As String

Dim shininess As String

'makes p1 equal to the first half since the way I coded it, it works backwards xD

For counter = length To 16 Step -1

p1 = p1 & reverse(counter)

Next

'makes p2 equal to the second half

For counter = 15 To 0 Step -1

p2 = p2 & reverse(counter)

Next

'the equations as seen on bulbapedia

E = IDnumber Xor SIDnumber

F = p1 Xor p2

shininess = E Xor F

E returns the value it is supposed to, I can tell you that much. But F does not. I am positive that p1 and p2 are assigned correctly.

Here is a spoiler with some values

0000011101011010 = P1

0110001110100110 = P2

0110010011111100 = F

0000011101011010 0110001110100110 = PID in binary with lead 0's

PID = 123364262

Putting the PID into calculator, it returns the PID in binary. I had to add the lead 0's manually, it still produces the correct PID like it should. I split the PID into p1 and p2 correctly, I printed to make sure the values were the proper ones.

When it gets to p1 xor p2, it somehow messes up. p1 xor p2 in calculator produces 25,852. However, in my program, it produces 109990702240972.

Manual testing proves this.

0000011101011010 <-P1

0110001110100110 <-P2

0110010011111100 <-F

F in decimal is equal to 25,852.

Any ideas?

---------- Post added at 03:17 PM ---------- Previous post was at 03:08 PM ----------

Oh snap, I think I just figured it out. It treats the two numbers as decimals and converts them to binary to use. I need to convert those binary values into decimal, but know how I do not.

Posted

Haha, I got it all sorted out. Convert.Int32, and you already told me about it. Oh well, it works now, so no harm.

I'm going to get someone to work on a list of Pokemon and their ability for me.

I could not find a list of moves on the site you gave me CodeMonkey. Every one I found listed too much information, I would likely be sitting here for ages trying to remove it all. If you don't have it or anything close, don't bother, I can get someone to do it for me probably, but if you do, I only need the name and the hex value of it so I can read it in and translate. The PP would be nice, but I can easily do that myself or have someone do it.

Oh, and while I'm at it, anyone have any idea on coding the OT gender? I don't seem to see any information on it documented here, bulbapedia or by anyone I know outside of the two.

Posted

OK, I didn't realize why they were listing Pound as 1, but that makes sense now. I will have to get someone to do that for me as well, someone is already doing the ability part. It should prove easier, there are less and all the moves are on one page, not like search for abilities. Of course, I'll have to do a hex conversion or something, but it will be fine.

It says it is stored in bit 7, for the OT gender. So I guess I can assume I convert to binary and look at the 7th bit? Correct me if I'm wrong, but I take it, do a left bit shift of 7 and use the number there. Example:

Female, hex is C6, that's 1100 0110 in binary. 8 digits long, counting from 0 at the right, so 7 is the first 1, and female. Male, hex is 46, that's 100 0110 in binary. Since it only goes up to an upperbound of 6, 7 is 0 and thus male.

EDIT: I just did a bit of checking with it and I see how it works. Convert it to decimal to get the value. If it is female, then you must get rid of the leftmost value in binary.

Thanks again codemonkey.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...