Page 1 of 1
binary reader jumper to random offset
Posted: Thu Dec 13, 2007 9:36 am
by grimdoomer
Ok I Delecare a new binaryreader, then set the position like so:
Code: Select all
BR.basestream.position = metaoffset + i
But no matter how I arange that the binaryreader always jumps a head by a cuple offsets, there is a pic of what im talking about:
I know its choppy but look at the filetableoffset and where the BR is, the BR should be at the filetableoffset but its not!, how can I fix this?
Posted: Thu Dec 13, 2007 9:54 am
by Patrickssj6
That pictures tells us nothing if I'm not mistaken. Only if you step into the next line it will set the BR to the filetableoffset.
Posted: Thu Dec 13, 2007 9:58 am
by grimdoomer
yes but see the line highlighted in yello, thats where i got an exception because the BR was off. Then i just red the position from it.
Posted: Thu Dec 13, 2007 10:21 am
by Prey
It's the .ReadChar() method - If at the current position there is not a valid character, the stream's position is incremented by one, and then the valid-char-check is done again.. and again...
Posted: Thu Dec 13, 2007 10:40 am
by grimdoomer
because the BR is not where i tell it to go, i even set its position to 0 then set a breakpoint right after that. It wasent at 0 but at 25?????
Posted: Thu Dec 13, 2007 10:47 am
by Patrickssj6
grimdoomer wrote:because the BR is not where i tell it to go, i even set its position to 0 then set a breakpoint right after that. It wasent at 0 but at 25?????
Didn't you read what Prey said? Yes you can set it to 0 but if the offset doesn't have a valid character it loops until it finds one...in this case at offset 25.
Posted: Thu Dec 13, 2007 11:11 am
by Altimit01
Prey wrote:It's the .ReadChar() method - If at the current position there is not a valid character, the stream's position is incremented by one, and then the valid-char-check is done again.. and again...
That just seems screwy to me. Most readchar methods should just read the byte and interpret it as a character as best they can (defaulting to a certain encoding if it's outside the normal 128 range). But I guess if .net wants to be "smart" about it it can.
MSDN wrote:If the ReadChar method attempts to read a surrogate character in the stream an exception will be raised and the position in the stream will advance. The position is restored to the original location before ReadChar was called if the stream is seekable; however, if the stream is unseekable, the position will not be corrected. If surrogate characters can be expected in the stream, use the
ReadChars method instead.
I don't remember offhand if H2 tags use the same naming convention of tag classes but it could be you're reading what should be rendered as
Posted: Thu Dec 13, 2007 11:52 am
by Prey
I agree Altimit, it is pretty crap.. and not very clear either. Also we're on the FileTable here.. nowhere near Tag classes =P
Anyway, .ReadChars() would be more ideal.. faster too. Just get the string offsets in the FileTable from the FileIndex, then find the string lengths by doing a 'offsets[x + 1] - offsets[x]', using the FileTableSize for the last string.
Posted: Thu Dec 13, 2007 12:17 pm
by grimdoomer
Patrickssj6 wrote:grimdoomer wrote:because the BR is not where i tell it to go, i even set its position to 0 then set a breakpoint right after that. It wasent at 0 but at 25?????
Didn't you read what Prey said? Yes you can set it to 0 but if the offset doesn't have a valid character it loops until it finds one...in this case at offset 25.
any way I have a bigger problem then that right now, My dependancys for halo 2 stoped working. Smae problem the BR keeps jumping.
Code: Select all
For i As Integer = 0 To MetaSize - 4 Step 4
BR.BaseStream.Position = MetaOffset + i
Dim temp As String = BR.ReadChars(4)
temp = StrReverse(temp)
there is my code (that part that i get an exception) it worked befor but doesent any ore, all i did was stick it into a seperate class, I made sure i gave it the right info, I even copy and pasted right out of the old code to see if something was missing. Nothing, I get an exception right at
and I checked the BR and its still 5-10 offsets ahaed. I dont think it keeps going till it finds readable Characters, cus then it would throw an exception right? mabey not, but the exception says that there is less then 4 readable characters.
Posted: Sun Dec 16, 2007 2:29 pm
by Prey
Perhaps try the reader and writer from
HERE.. also I just remembered the .ReadChars() method has the same "fault" as the ReadChar() method... =x
Posted: Sun Dec 16, 2007 4:36 pm
by grimdoomer
thanks prey but me and hawaiian modder fixed it a cuple days ago. Poke sayed to read 4 bytes insetead of 4 characters and it worked perfect.