[class]MetaOffset

Discussion in 'Programming & Scripting' started by GoldBl4d3, Dec 16, 2008 with 2 replies and 190 views.

  1. GoldBl4d3

    GoldBl4d3 Retired Retired

    Messages:
    3,758
    Ratings:
    1,328
    Some programmers who like to make halo 2 applications might be struggling on how to swap the meta offsets like in dothalo. Well here is a class, and I will show the code for it. Hope this helps.

    *Depending on your configuration of the Header and Tags class, you may have to change some code.


    Code:
    [SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]static [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] Swap([/SIZE][SIZE=2][COLOR=#008080]FileStream[/COLOR][/SIZE][SIZE=2] fs, [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] currentTypeOvrwrte, [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] currentPathOvrwrte, [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] newTagType, [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] newTagPath)[/SIZE]
    [SIZE=2]{[/SIZE]
    [SIZE=2][COLOR=#008080]BinaryReader[/COLOR][/SIZE][SIZE=2] br = [/SIZE][SIZE=2][COLOR=#0000ff]new [/COLOR][/SIZE][SIZE=2][COLOR=#008080]BinaryReader[/COLOR][/SIZE][SIZE=2](fs);[/SIZE]
    [SIZE=2][COLOR=#008080]BinaryWriter[/COLOR][/SIZE][SIZE=2] bw = [/SIZE][SIZE=2][COLOR=#0000ff]new [/COLOR][/SIZE][SIZE=2][COLOR=#008080]BinaryWriter[/COLOR][/SIZE][SIZE=2](fs);[/SIZE]
    
    [SIZE=2]br.BaseStream.Position = [/SIZE][SIZE=2][COLOR=#008080]H2Header[/COLOR][/SIZE][SIZE=2].OffsetOfObjectIndex;[/SIZE]
    
    [SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] curMetaOffset = [/SIZE][SIZE=2][COLOR=#008080]H2Tags[/COLOR][/SIZE][SIZE=2].TagsList[[/SIZE][SIZE=2][COLOR=#008080]H2Tags[/COLOR][/SIZE][SIZE=2].FindTagIndexByTypeAndPath(currentTypeOvrwrte, currentPathOvrwrte)].MetaOffset;[/SIZE]
    [SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] newMetaOffset = [/SIZE][SIZE=2][COLOR=#008080]H2Tags[/COLOR][/SIZE][SIZE=2].TagsList[[/SIZE][SIZE=2][COLOR=#008080]H2Tags[/COLOR][/SIZE][SIZE=2].FindTagIndexByTypeAndPath(newTagType, newTagPath)].MetaOffset;[/SIZE]
    
    [SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i = 0; i < [/SIZE][SIZE=2][COLOR=#008080]H2Header[/COLOR][/SIZE][SIZE=2].ObjectCount; i++)[/SIZE]
    [SIZE=2]{[/SIZE]
    [SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] tagType = [/SIZE][SIZE=2][COLOR=#008080]H2Map[/COLOR][/SIZE][SIZE=2].Reverse([/SIZE][SIZE=2][COLOR=#0000ff]new [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2](br.ReadChars(4)));[/SIZE]
    
    [SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] id = br.ReadInt32();[/SIZE]
    [SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] metaOffset = br.ReadInt32() - [/SIZE][SIZE=2][COLOR=#008080]H2Header[/COLOR][/SIZE][SIZE=2].SecondaryMagic;[/SIZE]
    [SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] metaSize = br.ReadInt32();[/SIZE]
    
    [SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (currentTypeOvrwrte == tagType && curMetaOffset == metaOffset)[/SIZE]
    [SIZE=2]{[/SIZE]
    [SIZE=2]  bw.BaseStream.Position = (br.BaseStream.Position - 8);[/SIZE]
    [SIZE=2][SIZE=2]  bw.Write(([/SIZE][SIZE=2][COLOR=deepskyblue]Int32[/COLOR][/SIZE][SIZE=2])(newMetaOffset + [/SIZE][SIZE=2][COLOR=#008080]H2Header[/COLOR][/SIZE][SIZE=2].SecondaryMagic));[/SIZE]
    [/SIZE][SIZE=2][COLOR=#0000ff]  break[/COLOR][/SIZE][SIZE=2];[/SIZE]
    [SIZE=2]}[/SIZE]
    [SIZE=2]}[/SIZE]
    
    [SIZE=2]bw.Flush();[/SIZE]
    [SIZE=2]bw.Close();[/SIZE]
    [SIZE=2]br.Close();[/SIZE]
    [SIZE=2]}[/SIZE]
    
    
    Perameters Explination
    fs = input a filestream to the map
    currentTypeOvrwrte = this is the tagType that you want to swap out
    currentPathOvrwrte = this is the tagPath that you want to swap out
    newTagType = new tagType to overwrite with
    newTagPath = new tagPath to overwrite with

    currentTypeOvrwrte + currentPathOvrwrte = meta offset to swap out
    newTagType + newTagPath = gets metaoffset to swap with
     
  2. Mr Shrimpy

    Mr Shrimpy Banned

    Messages:
    22
    Ratings:
    0
  3. OP
    GoldBl4d3

    GoldBl4d3 Retired Retired

    Messages:
    3,758
    Ratings:
    1,328
    no problem, i should post different ways of doing it. but I just used it right out of my app.