Interpreting Raw Offsets

Discuss Halo 2 modding, progress on figuring things out, mapfiles...you know the drill. Cheating discussion not allowed.
Post Reply
Choking Victim





Posts: 552
Joined: Thu May 12, 2005 4:12 am

Interpreting Raw Offsets

Post by Choking Victim »

I'm having trouble figuring out how to get a raw offset out of 4 bytes in the hex. In the whitepaper it says:
When referencing a raw offset, one should first determine the file being referenced, remove those two bits from the offset value (and with 0x3FFFFFFF), and then seek to that offset in the correct file to find the referenced data.
From what I understand, i take the 4 bytes i have, 00AC4988, and remove the first byte which points to which file the raw data is in (local, mainmenu, shared, and sp_shared). Now i get AC4988, is this the raw offset? What does he mean by "and with 0x3FFFFFFF" ? Thanks to anyone that can help.
-DeToX-




Illusionist Recreator Connoisseur Acolyte
Sigma Decryptor Droplet Pyre
Blacksmith Socialist New Age System Engineer
ONI

Posts: 4589
Joined: Sun Jun 18, 2006 3:58 pm
Location: ...

Post by -DeToX- »

Well if what he said is correct... Its the first two BITS, not the first byte.

8 bits make a byte.
Image
Choking Victim





Posts: 552
Joined: Thu May 12, 2005 4:12 am

Post by Choking Victim »

That's exactly what I removed...two bits = one byte. I have 00AC4988, remove the first two bits to get AC4988. I don't understand what he means when he says "and with 0x3FFFFFFF".
-DeToX-




Illusionist Recreator Connoisseur Acolyte
Sigma Decryptor Droplet Pyre
Blacksmith Socialist New Age System Engineer
ONI

Posts: 4589
Joined: Sun Jun 18, 2006 3:58 pm
Location: ...

Post by -DeToX- »

Choking Victim wrote:That's exactly what I removed...two bits = one byte. I have 00AC4988, remove the first two bits to get AC4988. I don't understand what he means when he says "and with 0x3FFFFFFF".
Did you not read what I said? 8 bits are in a byte...

Hence when using a binary Reader and your reading a short, its ReadInt16(16 bit integer)... A byte is half the size of a short... making it 8...

Bits = 0's and 1's.. Its the binary of the value being read...
Byte has 8
Short has 16
Long has 32
Quad has 64

You also asked me about JMAD Raw...

Add this method to determine where the raw is located:

Code: Select all

            map.Open(HaloMap.MapType.Internal);
            map.br.BaseStream.Position = meta.Offset + 172;
            int count = map.br.ReadInt32();
            int trans = map.br.ReadInt32() - map.secondaryMagic;
            for (int i = 0; i < count; i++)
            {
                RawChunk raw = new RawChunk();
                raw.offsetOfPointer = trans + (i * 20) + 8;                
                raw.type = RawType.jmad;
                map.br.BaseStream.Position = raw.offsetOfPointer - 4;
                raw.size = map.br.ReadInt32();
                raw.offset = map.br.ReadInt32();
                functions.GetRawLocation(ref raw.offset, ref raw.location);
                if (raw.size != -1)
                {
                    map.Open(raw.location);
                    map.br.BaseStream.Position = raw.offset;
                    raw.ms = new MemoryStream(raw.size);
                    raw.ms.Write(map.br.ReadBytes(raw.size), 0, raw.size);
                    map.Open(HaloMap.MapType.Internal);
                }
                chunks.Add(raw);
            }
And to get the raw Location... Heres a method...

Code: Select all

        public void GetRawLocation(ref int pointerOffset, ref HaloMap.MapType type)
        {
            long temp = pointerOffset & 0XC0000000;
            pointerOffset = pointerOffset & (int)0X3FFFFFFF;

            switch (temp)
            {
                case 0:
                    type = HaloMap.MapType.Internal;
                    break;
                case 0X40000000:
                    type = HaloMap.MapType.MainMenu;
                    break;
                case 0X80000000:
                    type = HaloMap.MapType.Shared;
                    break;
                case 0XC0000000:
                    type = HaloMap.MapType.SpShared;
                    break;
            }
        }
Writing you own code for this is self explanitory.
Image
Choking Victim





Posts: 552
Joined: Thu May 12, 2005 4:12 am

Post by Choking Victim »

Thanks for your help.
-DeToX-




Illusionist Recreator Connoisseur Acolyte
Sigma Decryptor Droplet Pyre
Blacksmith Socialist New Age System Engineer
ONI

Posts: 4589
Joined: Sun Jun 18, 2006 3:58 pm
Location: ...

Post by -DeToX- »

Yeah No problem.
Image
User avatar
shade45




Translator Artisan Enthraller Logistician
Stylist Wave Firestorm New Age

Posts: 2270
Joined: Fri Apr 01, 2005 1:04 pm

Post by shade45 »

Choking Victim wrote:I don't understand what he means when he says "and with 0x3FFFFFFF".
"AND" is a logical operation performed on bits. Windows calculator can perform this operation if you set it to scientific mode.

So basically

RawOffset AND 3FFFFFFF = Map Raw Data is Located In
ShadowSpartan





Posts: 151
Joined: Mon Jun 13, 2005 12:45 pm

Post by ShadowSpartan »

I have tried to convert that code to VB so that we could use it, but it keeps returning huge raw sizes and even some negative sizes like -874528752, the same goes for the raw offsets. Here is my code, maybe you guys can spot something I did wrong. Thanks.

Code: Select all

        Private Sub GetRawOffset

	         reader.BaseStream.Position = JmadOffset + 172

            Dim count As Integer = reader.ReadInt32()
            Dim trans As Integer = reader.ReadInt32()

            trans = trans - Me.HaloMap.mapSecondaryMagic
            
            For x As Integer = 0 To count - 1
                Dim offsetOfPointer As Integer
                Dim RawSize As Integer
                Dim RawOffset As Integer
                Dim RawLocation As String

                offsetOfPointer = trans + (x * 20) + 8
                reader.BaseStream.Position = offsetOfPointer - 4
                RawSize = reader.ReadInt32()
                RawOffset = reader.ReadInt32()

                GetRawLocation(RawOffset, RawLocation)

                If RawSize <> -1 Then
                    
                End If

            Next
        End Sub


        Sub GetRawLocation(ByRef pointerOffset As Integer, ByRef type As String)
            Dim temp As Long = pointerOffset And 3221225472
            pointerOffset = pointerOffset And CInt(1073741823)
            Select Case temp
                Case 0
                    type = "Internal"
                    Exit Select
                Case 1073741824
                    type = "MainMenu"
                    Exit Select
                Case 2147483648
                    type = "Shared"
                    Exit Select
                Case 3221225472
                    type = "SpShared"
                    Exit Select
            End Select
        End Sub
-DeToX-




Illusionist Recreator Connoisseur Acolyte
Sigma Decryptor Droplet Pyre
Blacksmith Socialist New Age System Engineer
ONI

Posts: 4589
Joined: Sun Jun 18, 2006 3:58 pm
Location: ...

Post by -DeToX- »

Are you using Anthony's classes? Because those use a different method of address modifying... His I beleive is offset + mapmagic.

Mine was - secondary Magic..
Image
ShadowSpartan





Posts: 151
Joined: Mon Jun 13, 2005 12:45 pm

Post by ShadowSpartan »

-DeToX- wrote:Are you using Anthony's classes? Because those use a different method of address modifying... His I beleive is offset + mapmagic.

Mine was - secondary Magic..
I believe that it is Anthony's classes but when I do what u said, with the offset + mapmagic, the program crashes. It gives me a really low negative number as the trans value.
-DeToX-




Illusionist Recreator Connoisseur Acolyte
Sigma Decryptor Droplet Pyre
Blacksmith Socialist New Age System Engineer
ONI

Posts: 4589
Joined: Sun Jun 18, 2006 3:58 pm
Location: ...

Post by -DeToX- »

ShadowSpartan wrote:
-DeToX- wrote:Are you using Anthony's classes? Because those use a different method of address modifying... His I beleive is offset + mapmagic.

Mine was - secondary Magic..
I believe that it is Anthony's classes but when I do what u said, with the offset + mapmagic, the program crashes. It gives me a really low negative number as the trans value.
Nevermind anthony's class aswell is - MapMagic, its not secondary for his...

Well did you fix the part for "FindTagIndexByPath"...

It will only find metas by that name... It doesnt look for the name and Class...

It should end up looking like this:

Code: Select all

        Public Function FindTagIndexByPath(ByVal TagClass As String, ByVal TagPath As String) As Integer

            Dim index As Integer = 0
            'Loop through all the tags and if we find a matching path then we return then index of it
            For i As Integer = 1 To objectCount Step 1
                If H2Tag(i).TagPath = TagPath Then
                    If H2Tag(i).TagClass = TagClass Then
                        index = i
                        Exit For
                    End If
                End If
            Next
            Return index

        End Function
Though I hate VB... And now you see why I dislike Anthony's classes ;P

Seriously though... if you plan to make a larger scale app, you should definitely write your own code.
Image
ShadowSpartan





Posts: 151
Joined: Mon Jun 13, 2005 12:45 pm

Post by ShadowSpartan »

When I changed it to Offset - mapmagic, everything came out positive but there is one thing I am unsure about. Is it possible for just one tag to have raw in multiple places, like for instance the MC tag having some raw in shared.map but others internal?

Also, I know I'm in the right tag, I've changed that function already.
-DeToX-




Illusionist Recreator Connoisseur Acolyte
Sigma Decryptor Droplet Pyre
Blacksmith Socialist New Age System Engineer
ONI

Posts: 4589
Joined: Sun Jun 18, 2006 3:58 pm
Location: ...

Post by -DeToX- »

ShadowSpartan wrote:When I changed it to Offset - mapmagic, everything came out positive but there is one thing I am unsure about. Is it possible for just one tag to have raw in multiple places, like for instance the MC tag having some raw in shared.map but others internal?

Also, I know I'm in the right tag, I've changed that function already.
Yes it is. But if you followed the code there, it will determine where the raw is located for every raw block, aswell as the offset in that map at which it is located.
Image
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post by Prey »

-DeToX- wrote:Well did you fix the part for "FindTagIndexByPath"...

It will only find metas by that name... It doesnt look for the name and Class...

It should end up looking like this:
[...]
!.. Doing that would mean that if no tag was 'found', 0 would still be returned :\

Fix..

Code: Select all

        Public Function IndexOf(ByVal TagClass As String, ByVal TagPath As String) As Integer

            For i As Integer = 1 To objectCount Step 1
                If H2Tag(i).TagClass = TagClass And H2Tag(i).TagPath = TagPath Then
                    Return i
                End If
            Next
            Return -1

        End Function
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
Post Reply