LocHelper.cs
/// <summary>
/// String size seem to be always be a multiple of 4. With 4-6 'zero bytes' at the end
/// </summary>
/// <param name="stringId">the id of the string to modify</param>
/// <param name="newValue">the new value</param>
/// <returns>The string location, -1 if not found</returns>
String size seem to be always be a multiple of 4. With 4-6 'zero bytes' at the end
String size seem to be always be a multiple of 4 . With 4 - 6 ' zero bytes ' at the end
public int SetString(string stringId, string newValue)
        {
            uint hashId = GetHashId(stringId);
            StringBuilder sb = new StringBuilder(20);
            int stringLoc = GetString(hashId, sb);
            string prevValue = sb.ToString();
            if (stringLoc > 0 && prevValue != newValue)
            {
                UInt32 oldSz = BinUtils.Get2ByteNumberAtLocation(stringLoc + 4, mData);
                UInt16 sz = (UInt16)((newValue.Length * 2) + 2 + 4 + 4); 
                if (sz % 4 != 0)
                    sz += (UInt16)2;
                bool sixZeros = false;
                int diff = (int)(sz - oldSz);  
                if (diff % 4 != 0)
                {
                    diff = diff + 2;
                    sixZeros = true;
                }
                int dataEnd = mData.Count + diff;
                if (diff > 0)
                {
                    AddBytes(diff);
                    ShiftDataDown(stringLoc, diff, dataEnd);
                }
                else if (diff < 0)
                {
                    ShiftDataUp(stringLoc, -1* diff, dataEnd);
                }
                BinUtils.WriteNumberAtLocation(stringLoc, hashId, mData);
                BinUtils.Write2ByteNumberAtLocation(stringLoc + 4,sz, mData);
                stringLoc += 6; 
                for (int i = 0; i < newValue.Length; i++)
                {
                    BinUtils.Write2ByteNumberAtLocation(stringLoc, newValue[i], mData);
                    stringLoc += 2;
                }
                BinUtils.WriteNumberAtLocation(stringLoc, 0, mData);
                if( sixZeros )
                    BinUtils.Write2ByteNumberAtLocation(stringLoc+4, 0, mData);
                AddBodySize(diff);
            }
            return stringLoc;
        }
public int SetString ( string stringId , string newValue ) { uint hashId = GetHashId ( stringId ) ; StringBuilder sb = new StringBuilder ( 20 ) ; int stringLoc = GetString ( hashId , sb ) ; string prevValue = sb . ToString ( ) ; if ( stringLoc > 0 && prevValue != newValue ) { UInt32 oldSz = BinUtils . Get2ByteNumberAtLocation ( stringLoc + 4 , mData ) ; UInt16 sz = ( UInt16 ) ( ( newValue . Length * 2 ) + 2 + 4 + 4 ) ; if ( sz % 4 != 0 ) sz += ( UInt16 ) 2 ; bool sixZeros = false ; int diff = ( int ) ( sz - oldSz ) ; if ( diff % 4 != 0 ) { diff = diff + 2 ; sixZeros = true ; } int dataEnd = mData . Count + diff ; if ( diff > 0 ) { AddBytes ( diff ) ; ShiftDataDown ( stringLoc , diff , dataEnd ) ; } else if ( diff < 0 ) { ShiftDataUp ( stringLoc , - 1 * diff , dataEnd ) ; } BinUtils . WriteNumberAtLocation ( stringLoc , hashId , mData ) ; BinUtils . Write2ByteNumberAtLocation ( stringLoc + 4 , sz , mData ) ; stringLoc += 6 ; for ( int i = 0 ; i < newValue . Length ; i ++ ) { BinUtils . Write2ByteNumberAtLocation ( stringLoc , newValue [ i ] , mData ) ; stringLoc += 2 ; } BinUtils . WriteNumberAtLocation ( stringLoc , 0 , mData ) ; if ( sixZeros ) BinUtils . Write2ByteNumberAtLocation ( stringLoc + 4 , 0 , mData ) ; AddBodySize ( diff ) ; } return stringLoc ; }
String size seem to be always be a multiple of 4.
String size seem to be always be a multiple of 4 .
// 2:size info 4:hashId 4 min zero bytes //2 * (newValue.Length - prevValue.Length); //write hashId // write the size // lay down string  /** MODIFYING 'stringLoc' NOW!! **/
The string location, -1 if not found
The string location - 1 if not found
stringId
string
the id of the string to modify
the id of the string to modify
newValue
string
the new value
the new value