TryGetUInt32() 공개 메소드

Try to get an unsigned 32-bit integer from the blob at the given offset. If successful, increment the offset.
public TryGetUInt32 ( uint &result, int &offset ) : bool
result uint
offset int
리턴 bool
예제 #1
0
        /// <summary>
        /// Read a single string from the metadata blob.
        /// </summary>
        /// <remarks>
        /// Consider returning false, printing error message.  But, need to
        /// be certain to abort the whole process at that point...
        /// </remarks>
        public bool TryReadDefData(Blob metadata, out string metaString, out uint metaOffset, ref int offset)
        {
            metaString = null;
            metaOffset = 0;
            UInt32      cookie       = 0;
            List <byte> tempbytelist = new List <byte>();

            metadata.TryGetUInt32(ref metaOffset, ref offset);


            while ((metadata.Content.Count > offset + 8) &&
                   metadata.TryGetUInt32(ref cookie, ref offset))
            {
                if ((cookie < 0x43210010 && cookie > 0x43210000) || cookie == 0x00090009)
                {
                    if (cookie != 0x00090009)
                    {
                        offset -= 4;
                    }

                    char[] splitter   = { '\0' };
                    string tempstring = System.Text.Encoding.ASCII.GetString(tempbytelist.ToArray());
                    metaString = tempstring.Split(splitter)[0];
                    return(true);
                }

                byte tempbyte = new byte();
                offset -= 4;
                for (int i = 0; i < 4; i++)
                {
                    if (!metadata.TryGetByte(ref tempbyte, ref offset))
                    {
                        return(false);
                    }
                    tempbytelist.Add(tempbyte);
                }
            }

            tempbytelist.ToString();
            return(false);
        }
예제 #2
0
        /// <summary>
        /// Try to read the Patch metadata from the file and add this data to table lists.
        /// </summary>
        private bool TryParseDefs(Blob metadata, ref int offset, String defPath)
        {
            UInt32 cookie = 0;
            while ((metadata.Content.Count > offset + 8) &&
                metadata.TryGetUInt32(ref cookie, ref offset))
            {
                if (cookie == OpTable3d)//TODO CONDITIONALLY READ LUTS!
                {
                    string metaString = null;
                    uint metaOffset = 0;
                    if (metadata.TryGetUInt32(ref metaOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out metaString, ref offset))
                        {

                            Blob tableBlob;
                            this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs);
                            LookupTable3D lut = new LookupTable3D(metaString, tableBlob, metaOffset);
                            if (metaString != null) RomLutList.Add(lut);
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found.");
                            return false;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == OpTable2d)//TODO CONDITIONALLY READ LUTS!
                {
                    string metaString = null;
                    uint metaOffset = 0;
                    if (metadata.TryGetUInt32(ref metaOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out metaString, ref offset))
                        {

                            Blob tableBlob;
                            this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs);
                            LookupTable2D lut = new LookupTable2D(metaString, tableBlob, metaOffset);
                            if (metaString != null) RomLutList.Add(lut);
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found.");
                            return false;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == OpTable1d)
                {
                    string metaString = null;
                    uint metaOffset = 0;
                    if (metadata.TryGetUInt32(ref metaOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out metaString, ref offset))
                        {

                            LookupTable lut = new LookupTable(metaString, metaOffset);
                            if (metaString != null) RomLutList.Add(lut);
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found.");
                            return false;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == OpRAM)
                {
                    string paramName = null;
                    string paramId = null;
                    string paramType = null;
                    uint paramOffset = 0;

                    if (metadata.TryGetUInt32(ref paramOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out paramId, ref offset))
                        {
                            if (this.TryReadDefString(metadata, out paramType, ref offset))
                            {
                                if (this.TryReadDefString(metadata, out paramName, ref offset))
                                {
                                    // found modName, output to string!
                                    KeyValuePair<String, TableMetaData> tempTable = CreateRomRaiderRamTable(paramName, (int)paramOffset, paramId, paramType);
                                    if (tempTable.Key != null) this.RamTableList.Add(tempTable.Key, tempTable.Value);
                                }
                                else
                                {
                                    Trace.WriteLine("Invalid definition found.");
                                    return false;
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Invalid definition found.");
                                return false;
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found.");
                            return false;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == OpRAMAllBits)
                {
                    string paramName = null;
                    string paramId = null;
                    string paramType = null;
                    uint paramOffset = 0;
                    if (metadata.TryGetUInt32(ref paramOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out paramId, ref offset))
                        {
                            if (this.TryReadDefString(metadata, out paramType, ref offset))
                            {
                                if (this.TryReadDefString(metadata, out paramName, ref offset))
                                {

                                    // found modName, output to string!
                                    int len = Utils.ConvertStorageTypeToIntBytes(paramType);
                                    uint address = paramOffset;
                                    for (int i = 0; i < len; i++)
                                    {

                                        for (int j = 0; j < 8; j++)
                                        {
                                            int bit = ((j) + (8 * (i)));
                                            string bitstring = bit.ToString();
                                            KeyValuePair<String, TableMetaData> tempTable = CreateRomRaiderRamTableBit(paramName + " Bit " + bitstring, (int)address, paramId, j);
                                            if (tempTable.Key != null) this.RamTableList.Add(tempTable.Key, tempTable.Value);

                                        }
                                        address++;
                                    }
                                }
                                else
                                {
                                    Trace.WriteLine("Invalid definition found.");
                                    return false;
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Invalid definition found.");
                                return false;
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found.");
                            return false;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == OpRAMBit)
                {
                    string paramName = null;
                    string paramId = null;
                    uint paramOffset = 0;
                    uint paramBit = 0;
                    if (metadata.TryGetUInt32(ref paramOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out paramId, ref offset))
                        {
                            if (metadata.TryGetUInt32(ref paramBit, ref offset))
                            {
                                if (this.TryReadDefString(metadata, out paramName, ref offset))
                                {
                                    int bit = bit = Utils.SingleBitBitmaskToBit((int)paramBit);
                                    // found modName, output to string!
                                    KeyValuePair<String, TableMetaData> tempTable = CreateRomRaiderRamTableBit(paramName, (int)paramOffset, paramId, bit);
                                    if (tempTable.Key != null) this.RamTableList.Add(tempTable.Key, tempTable.Value);
                                }
                                else
                                {
                                    Trace.WriteLine("Invalid definition found.");
                                    return false;
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Invalid definition found.");
                                return false;
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found.");
                            return false;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == Mod.endoffile)
                {
                    break;
                }
            }

            return true;
        }
예제 #3
0
        /// <summary>
        /// Read a single string from the metadata blob.
        /// </summary>
        /// <remarks>
        /// Consider returning false, printing error message.  But, need to 
        /// be certain to abort the whole process at that point...
        /// </remarks>
        public bool TryReadDefString(Blob metadata, out string metaString, ref int offset)
        {
            metaString = null;
            UInt32 cookie = 0;
            List<byte> tempbytelist = new List<byte>();

            while ((metadata.Content.Count > offset + 8) &&
                metadata.TryGetUInt32(ref cookie, ref offset))
            {
                if ((cookie < cookieMax && cookie > cookieMin) || cookie == cookieEnd)
                {
                    if (cookie != cookieEnd)
                    {
                        offset -= 4;
                    }

                    char[] splitter = { '\0' };
                    string tempstring = System.Text.Encoding.ASCII.GetString(tempbytelist.ToArray());
                    metaString = tempstring.Split(splitter)[0];
                    return true;
                }

                byte tempbyte = new byte();
                offset -= 4;
                for (int i = 0; i < 4; i++)
                {
                    if (!metadata.TryGetByte(ref tempbyte, ref offset))
                    {
                        return false;
                    }
                    tempbytelist.Add(tempbyte);

                }

            }

            tempbytelist.ToString();
            return false;
        }
예제 #4
0
파일: Mod.cs 프로젝트: segapsh2/SharpTune
        /// <summary>
        /// Try to read the initial and final calibration IDs
        /// </summary>
        private bool TryReadCalibrationChange(Blob blob, ref int offset)
        {
            uint tempUInt32 = 0;

            if (!blob.TryGetUInt32(ref tempUInt32, ref offset))
            {
                Trace.WriteLine("This patch file's metadata is way too short (no calibration metadata).");
                return false;
            }

            if (tempUInt32 != calibrationIdPrefix)
            {
                Trace.WriteLine(String.Format("Expected calibration id prefix {0:X8}, found {1:X8}", calibrationIdPrefix, tempUInt32));
                return false;
            }

            if (!blob.TryGetUInt32(ref tempUInt32, ref offset))
            {
                Trace.WriteLine("This patch file's metadata is way too short (no calibration address).");
                return false;
            }

            uint calibrationAddress = tempUInt32;

            if (!blob.TryGetUInt32(ref tempUInt32, ref offset))
            {
                Trace.WriteLine("This patch file's metadata is way too short (no calibration length).");
                return false;
            }

            uint calibrationLength = tempUInt32;

            string initialCalibrationId;
            if (!this.TryReadCalibrationId(blob, ref offset, out initialCalibrationId))
            {
                return false;
            }

            this.InitialCalibrationId = initialCalibrationId;

            string finalCalibrationId;
            if (!this.TryReadCalibrationId(blob, ref offset, out finalCalibrationId))
            {
                return false;
            }

            this.FinalCalibrationId = finalCalibrationId;

            // Synthesize calibration-change patch and blobs.
            Patch patch = new Patch( "Calibration ID Patch",
                calibrationAddress,
                calibrationAddress + (calibrationLength - 1));

            patch.IsMetaChecked = true;

            patch.Baseline = new Blob(
                calibrationAddress + Mod.BaselineOffset,
                Encoding.ASCII.GetBytes(initialCalibrationId));

            patch.Payload = new Blob(
                calibrationAddress,
                Encoding.ASCII.GetBytes(finalCalibrationId));

            this.patchList.AddPatch(patch);

            return true;
        }
예제 #5
0
파일: Mod.cs 프로젝트: segapsh2/SharpTune
        /// <summary>
        /// Try to read the 'required version' metadata.
        /// </summary>
        private bool TryConfirmPatchVersion(Blob blob, ref int offset)
        {
            uint tempUInt32 = 0;

            if (!blob.TryGetUInt32(ref tempUInt32, ref offset))
            {
                Trace.WriteLine(String.Format("This patch file's metadata is way too short (no version metadata)."));
                return false;
            }

            if (tempUInt32 != requiredVersionPrefix)
            {
                Trace.WriteLine(String.Format("This patch file's metadata starts with {0}, it should start with {1}", tempUInt32, requiredVersionPrefix));
                return false;
            }

            if (!blob.TryGetUInt32(ref tempUInt32, ref offset))
            {
                Trace.WriteLine("This patch file's metadata is way too short (no version).");
                return false;
            }
            if (tempUInt32 == RomMod.AuthVersion)
            {
                isAuthd = true;
                return true;
            }

            if (tempUInt32 != RomMod.Version)
            {
                Trace.WriteLine(String.Format("This is RomPatch.exe version {0}.", RomMod.Version));
                Trace.WriteLine(String.Format("This patch file requires version {0}.", tempUInt32));
                return false;
            }

            return true;
        }
예제 #6
0
파일: Mod.cs 프로젝트: segapsh2/SharpTune
        /// <summary>
        /// Read a single string from the metadata blob.
        /// </summary>
        /// <remarks>
        /// Consider returning false, printing error message.  But, need to 
        /// be certain to abort the whole process at that point...
        /// </remarks>
        public bool TryReadMetaString(Blob metadata, out string metaString, ref int offset)
        {
            metaString = null;
            UInt32 cookie = 0;
            List<byte> tempbytelist = new List<byte>();

             while ((metadata.Content.Count > offset + 4) &&
                 metadata.TryGetUInt32(ref cookie, ref offset))
             {
                 if ((cookie < 0x12340010 && cookie > 0x12340000) || cookie == 0x00090009)
                 {
                     offset -= 4;

                     char[] splitter = { '\0' }; //TODO FIX THIS
                     string tempstring = System.Text.Encoding.ASCII.GetString(tempbytelist.ToArray());
                     metaString = tempstring.Split(splitter)[0];
                     return true;
                 }

                 byte tempbyte = new byte();
                  offset -= 4;
                 for (int i = 0; i < 4; i++)
                 {
                     if (!metadata.TryGetByte(ref tempbyte,ref offset))
                     {
                         return false;
                     }
                     tempbytelist.Add(tempbyte);

                 }

             }

            tempbytelist.ToString();
            return false;
        }
예제 #7
0
파일: Mod.cs 프로젝트: segapsh2/SharpTune
        /// <summary>
        /// Construct a Pull JSR HOOK patch from the metadata blob.
        /// </summary>
        private bool TrySynthesizePullJsrHookPatch(Blob metadata, out Patch patch, ref int offset, List<Blob> blobs)
        {
            uint address = 0;
            string name;

            if (!metadata.TryGetUInt32(ref address, ref offset))
            {
                throw new InvalidDataException("This patch's metadata contains an incomplete 4-byte patch record (no address).");
            }

            if (!TryReadMetaString(metadata, out name, ref offset))
            {
                Trace.WriteLine("Patch at metadata offset: " + offset + "contains invalid name."); name ="UNKNOWN PATCH";
            }

            byte[] jsrbytes = new byte[] {0xF0,0x48,0x00,0x09};

            patch = new PullJSRHookPatch(name, address, address + 3);

            patch.IsMetaChecked = true;//remove thsi

            patch.Payload = new Blob(patch.StartAddress, jsrbytes);

            //this.blobs.Add(new Blob(address, BitConverter.GetBytes(newValue).Reverse()));
            //this.blobs.Add(new Blob(address + BaselineOffset, BitConverter.GetBytes(oldValue).Reverse()));
            return true;
        }
예제 #8
0
파일: Mod.cs 프로젝트: segapsh2/SharpTune
        /// <summary>
        /// Construct a Last 2 of 4-byte patch from the metadata blob.
        /// </summary>
        private bool TrySynthesizeLast2Of4BytePatch(Blob metadata, out Patch patch, ref int offset)
        {
            uint address = 0;
            uint oldValue = 0;
            uint newValue = 0;
            string name;

            if (!metadata.TryGetUInt32(ref address, ref offset))
            {
                throw new InvalidDataException("This patch's metadata contains an incomplete l2o4-byte patch record (no address).");
            }

            if (!metadata.TryGetUInt32(ref oldValue, ref offset))
            {
                throw new InvalidDataException("This patch's metadata contains an incomplete l2o4-byte patch record (no baseline value).");
            }

            if (!metadata.TryGetUInt32(ref newValue, ref offset))
            {
                throw new InvalidDataException("This patch's metadata contains an incomplete l2o4-byte patch record (no patch value).");
            }

            if (!TryReadMetaString(metadata, out name, ref offset))
            {
                Trace.WriteLine("Patch at metadata offset: " + offset + "contains invalid name."); name ="UNKNOWN PATCH";
            }

            patch = new Patch(name, address + 2, address + 3);
            patch.IsMetaChecked = true;
            patch.Baseline = new Blob(address + 2 + BaselineOffset, BitConverter.GetBytes(oldValue).Take(2).Reverse());
            patch.Payload = new Blob(address + 2, BitConverter.GetBytes(newValue).Take(2).Reverse());

            return true;
        }
예제 #9
0
파일: Mod.cs 프로젝트: segapsh2/SharpTune
        /// <summary>
        /// Try to read the Patch metadata from the file.
        /// </summary>
        private bool TryReadPatches(Blob metadata, ref int offset, List<Blob> blobs)
        {
            UInt32 cookie = 0;
            while ((metadata.Content.Count > offset + 8) &&
                metadata.TryGetUInt32(ref cookie, ref offset))
            {
                Patch patch = null;
                if (cookie == patchPrefix)
                {
                    if (!this.TryReadPatch(metadata, out patch, ref offset, blobs))
                    {
                        Trace.WriteLine("Invalid patch found." + patch.ToString());
                        return false;
                    }
                }
                else if (cookie == copyPatchPrefix)
                {
                    if (!this.TryReadCopyPatch(metadata, out patch, ref offset, blobs))
                    {
                        Trace.WriteLine("Invalid patch found." + patch.ToString());
                        return false;
                    }
                }
                else if (cookie == replace4BytesPrefix)
                {
                    if (!this.TrySynthesize4BytePatch(metadata, out patch, ref offset))
                    {
                        Trace.WriteLine("Invalid 4-byte patch found." + patch.ToString());
                        return false;
                    }

                }
                else if (cookie == replaceLast2Of4BytesPrefix)
                {
                    if (!this.TrySynthesizeLast2Of4BytePatch(metadata, out patch, ref offset))
                    {
                        Trace.WriteLine("Invalid Last 2 Of 4-byte patch found." + patch.ToString());
                        return false;
                    }

                }
                else if (cookie == newPatchPrefix)
                {
                    if (!this.TryReadPatch(metadata, out patch, ref offset, blobs))
                    {
                        Trace.WriteLine("Invalid patch found." + patch.ToString());
                        return false;
                    }

                    patch.IsNewPatch = true;
                }
                else if (cookie == copyNewPatchPrefix)
                {
                    if (!this.TryReadCopyPatch(metadata, out patch, ref offset, blobs))
                    {
                        Trace.WriteLine("Invalid patch found." + patch.ToString());
                        return false;
                    }

                    patch.IsNewPatch = true;
                }
                else if (cookie == jsrhookPrefix)
                {
                    if (!this.TrySynthesizePullJsrHookPatch(metadata, out patch, ref offset, blobs))
                    {
                        Trace.WriteLine("Invalid patch found." + patch.ToString());
                        return false;
                    }
                }
                else if (cookie == endoffile)
                {
                    break;
                }
                this.patchList.AddPatch(patch);
            }
            return true;
        }
예제 #10
0
파일: Mod.cs 프로젝트: segapsh2/SharpTune
        /// <summary>
        /// Read a single Patch from the metadata blob.
        /// </summary>
        /// <remarks>
        /// Consider returning false, printing error message.  But, need to 
        /// be certain to abort the whole process at that point...
        /// </remarks>
        private bool TryReadPatch(Blob metadata, out Patch patch, ref int offset, List<Blob> blobs )
        {
            uint start = 0;
            uint end = 0;
            string name;

            if (!metadata.TryGetUInt32(ref start, ref offset))
            {
                throw new InvalidDataException("Patch at metadata offset: " + offset + " contains an incomplete patch record (no start address).");
            }

            if (!metadata.TryGetUInt32(ref end, ref offset))
            {
                throw new InvalidDataException("Patch at metadata offset: " + offset + " contains an incomplete patch record (no end address).");
            }

            if(!TryReadMetaString(metadata,out name, ref offset))
            {
                Trace.WriteLine("Patch at metadata offset: " + offset + "contains invalid name."); name ="UNKNOWN PATCH";
            }

            patch = new Patch(name,start, end);

            Blob baselineBlob;

            if (!this.TryGetPatchBlob(patch.StartAddress + BaselineOffset, patch.Length, out baselineBlob, blobs))
            {
                if (baselineBlob != null)  return false;
            }

                patch.Baseline = baselineBlob;

            Blob payloadBlob;
            if (!this.TryGetPatchBlob(patch.StartAddress, patch.Length, out payloadBlob, blobs))
            {
                return false;
            }

            patch.Payload = payloadBlob;
            return true;
        }
예제 #11
0
파일: Mod.cs 프로젝트: segapsh2/SharpTune
        private bool TryReadMetaHeader8(Blob metadata, ref int offset)
        {
            UInt32 cookie = 0;
            uint tempInt = 0;
            Patch patch = null;
            while ((metadata.Content.Count > offset + 8) &&
                metadata.TryGetUInt32(ref cookie, ref offset))
            {
                if (cookie == Mod.calibrationIdPrefix)
                {
                    if (!metadata.TryGetUInt32(ref tempInt, ref offset))
                    {
                        Trace.WriteLine("This patch file's metadata is way too short (no calibration address).");
                        return false;
                    }

                    this.CalIdAddress = tempInt;

                    if (!metadata.TryGetUInt32(ref tempInt, ref offset))
                    {
                        Trace.WriteLine("This patch file's metadata is way too short (no calibration length).");
                        return false;
                    }

                    this.CalIdLength = tempInt;

                    string initialCalibrationId;
                    if (!this.TryReadCalibrationId(metadata, ref offset, out initialCalibrationId))
                    {
                        return false;
                    }

                    this.InitialCalibrationId = initialCalibrationId;

                    string finalCalibrationId;
                    if (!this.TryReadCalibrationId(metadata, ref offset, out finalCalibrationId))
                    {
                        return false;
                    }

                    if (finalCalibrationId.ContainsCI("ffffffff"))
                    {
                        StringBuilder s = new StringBuilder(initialCalibrationId, 0,initialCalibrationId.Length, initialCalibrationId.Length);
                        s.Remove(initialCalibrationId.Length-2,2);
                        s.Insert(initialCalibrationId.Length-2,"MM");
                        FinalCalibrationId = s.ToString();
                    }

                    this.FinalCalibrationId = finalCalibrationId;
                    // Synthesize calibration-change patch and blobs.
                    patch = new Patch( "Calibration ID Patch",
                        CalIdAddress,
                        CalIdAddress + (CalIdLength - 1));

                    patch.IsMetaChecked = true;

                    patch.Baseline = new Blob(
                        CalIdAddress + Mod.BaselineOffset,
                        Encoding.ASCII.GetBytes(initialCalibrationId));

                    patch.Payload = new Blob(
                        CalIdAddress,
                        Encoding.ASCII.GetBytes(finalCalibrationId));

                    this.patchList.AddPatch(patch);
                }
                else if (cookie == modIdPrefix)
                {
                    if (metadata.TryGetUInt32(ref tempInt, ref offset))
                    {
                        this.ModIdentAddress = tempInt;
                    }
                    string metaString = null;
                    if (this.TryReadMetaString(metadata, out metaString, ref offset))
                    {
                        // found modName, output to string!
                        this.ModIdent = metaString;
                    }
                }
                else if (cookie == ecuIdPrefix)
                {
                    if (metadata.TryGetUInt32(ref tempInt, ref offset))
                    {
                        this.EcuIdAddress = tempInt;
                    }
                    if (metadata.TryGetUInt32(ref tempInt, ref offset))
                    {
                        this.EcuIdLength = tempInt;
                    }
                    string metaString = null;
                    if (this.TryReadMetaString(metadata, out metaString, ref offset))
                    {
                        // found modName, output to string!
                        this.InitialEcuId = metaString;
                    }
                    metadata.TryGetUInt32(ref tempInt, ref offset);
                    if (this.TryReadMetaString(metadata, out metaString, ref offset))
                    {
                        // found modName, output to string!
                        this.FinalEcuId = metaString;
                    }
                }
                else if (cookie == modAuthorPrefix)
                {
                    string metaString = null;
                    if (this.TryReadMetaString(metadata, out metaString, ref offset))
                    {
                        // found modName, output to string!
                        this.ModAuthor = metaString;
                    }
                    else
                    {
                        Trace.WriteLine("Invalid patch found." + patch.ToString());
                        return false;
                    }
                }
                else if (cookie == modBuildPrefix)
                {
                    string metaString = null;
                    if (this.TryReadMetaString(metadata, out metaString, ref offset))
                    {
                        // found modName, output to string!
                        this.ModBuild = metaString;
                    }
                    else
                    {
                        Trace.WriteLine("Invalid patch found." + patch.ToString());
                        return false;
                    }
                }
                else if (cookie == modInfoPrefix)
                {
                    string metaString = null;
                    if (this.TryReadMetaString(metadata, out metaString, ref offset))
                    {
                        // found Trace.WriteLine("Patch at metadata offset: " + offset + "contains invalid name."); name ="UNKNOWN PATCH";, output to string!
                        this.ModInfo = metaString.Replace("__", Environment.NewLine);
                    }
                    else
                    {
                        Trace.WriteLine("Invalid ModInfo found." + patch.ToString());
                        return false;
                    }
                }
                else if (cookie == endoffile)
                {
                    break;
                }
            }
            if (this.InitialEcuId.Length == this.FinalEcuId.Length)
            {
                // Synthesize calibration-change patch and blobs.
                if (FinalEcuId.ContainsCI("ffffffff"))
                {
                    StringBuilder feid = new StringBuilder(Regex.Split(this.ModIdent,".v")[1].Replace(".", ""));
                    while (feid.Length < this.InitialEcuId.Length)
                    {
                        feid.Append("F");
                    }
                    this.FinalEcuId = feid.ToString();
                }
                patch = new Patch( "ECU ID Patch",
                    EcuIdAddress,
                    EcuIdAddress + ((EcuIdLength / 2) - 1));

                patch.IsMetaChecked = true;

                patch.Baseline = new Blob(
                    EcuIdAddress + Mod.BaselineOffset,
                    InitialEcuId.ToByteArray());

                patch.Payload = new Blob(
                    EcuIdAddress,
                    FinalEcuId.ToByteArray());

                this.patchList.AddPatch(patch);
            }
            if (this.patchList.Count < 2)
            {
                Trace.WriteLine("This patch file's metadata contains no CALID or ECUID patch!!.");
                return false;
            }
            return true;
        }
예제 #12
0
        /// <summary>
        /// Try to read the Patch metadata from the file and add this data to table lists.
        /// </summary>
        private bool TryParseDefs(Blob metadata, ref int offset, String defPath)
        {
            UInt32 cookie = 0;

            while ((metadata.Content.Count > offset + 8) &&
                   metadata.TryGetUInt32(ref cookie, ref offset))
            {
                if (cookie == OpTable3d)//TODO CONDITIONALLY READ LUTS!
                {
                    string metaString = null;
                    uint   metaOffset = 0;
                    if (metadata.TryGetUInt32(ref metaOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out metaString, ref offset))
                        {
                            Blob tableBlob;
                            this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs);
                            LookupTable3D lut = new LookupTable3D(metaString, tableBlob, metaOffset);
                            if (metaString != null)
                            {
                                RomLutList.Add(lut);
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found.");
                            return(false);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return(false);
                    }
                }
                else if (cookie == OpTable2d)//TODO CONDITIONALLY READ LUTS!
                {
                    string metaString = null;
                    uint   metaOffset = 0;
                    if (metadata.TryGetUInt32(ref metaOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out metaString, ref offset))
                        {
                            Blob tableBlob;
                            this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs);
                            LookupTable2D lut = new LookupTable2D(metaString, tableBlob, metaOffset);
                            if (metaString != null)
                            {
                                RomLutList.Add(lut);
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found.");
                            return(false);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return(false);
                    }
                }
                else if (cookie == OpTable1d)
                {
                    string metaString = null;
                    uint   metaOffset = 0;
                    if (metadata.TryGetUInt32(ref metaOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out metaString, ref offset))
                        {
                            LookupTable lut = new LookupTable(metaString, metaOffset);
                            if (metaString != null)
                            {
                                RomLutList.Add(lut);
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found.");
                            return(false);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return(false);
                    }
                }
                else if (cookie == OpRAM)
                {
                    string paramName   = null;
                    string paramId     = null;
                    string paramType   = null;
                    uint   paramOffset = 0;

                    if (metadata.TryGetUInt32(ref paramOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out paramId, ref offset))
                        {
                            if (this.TryReadDefString(metadata, out paramType, ref offset))
                            {
                                if (this.TryReadDefString(metadata, out paramName, ref offset))
                                {
                                    // found modName, output to string!
                                    KeyValuePair <String, TableMetaData> tempTable = CreateRomRaiderRamTable(paramName, (int)paramOffset, paramId, paramType);
                                    if (tempTable.Key != null)
                                    {
                                        this.RamTableList.Add(tempTable.Key, tempTable.Value);
                                    }
                                }
                                else
                                {
                                    Trace.WriteLine("Invalid definition found in mod metadata.");
                                    return(false);
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Invalid definition found in mod metadata.");
                                return(false);
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found in mod metadata.");
                            return(false);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found in mod metadata.");
                        return(false);
                    }
                }
                else if (cookie == OpRAMAllBits)
                {
                    string paramName   = null;
                    string paramId     = null;
                    string paramType   = null;
                    uint   paramOffset = 0;
                    if (metadata.TryGetUInt32(ref paramOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out paramId, ref offset))
                        {
                            if (this.TryReadDefString(metadata, out paramType, ref offset))
                            {
                                if (this.TryReadDefString(metadata, out paramName, ref offset))
                                {
                                    // found modName, output to string!
                                    int  len     = Utils.ConvertStorageTypeToIntBytes(paramType);
                                    uint address = paramOffset;
                                    for (int i = 0; i < len; i++)
                                    {
                                        for (int j = 0; j < 8; j++)
                                        {
                                            int    bit       = ((j) + (8 * (i)));
                                            string bitstring = bit.ToString();
                                            KeyValuePair <String, TableMetaData> tempTable = CreateRomRaiderRamTableBit(paramName + " Bit " + bitstring, (int)address, paramId, j);
                                            if (tempTable.Key != null)
                                            {
                                                this.RamTableList.Add(tempTable.Key, tempTable.Value);
                                            }
                                        }
                                        address++;
                                    }
                                }
                                else
                                {
                                    Trace.WriteLine("Invalid definition found in mod metadata.");
                                    return(false);
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Invalid definition found in mod metadata.");
                                return(false);
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found in mod metadata.");
                            return(false);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found in mod metadata.");
                        return(false);
                    }
                }
                else if (cookie == OpRAMBit)
                {
                    string paramName   = null;
                    string paramId     = null;
                    uint   paramOffset = 0;
                    uint   paramBit    = 0;
                    if (metadata.TryGetUInt32(ref paramOffset, ref offset))
                    {
                        if (this.TryReadDefString(metadata, out paramId, ref offset))
                        {
                            if (metadata.TryGetUInt32(ref paramBit, ref offset))
                            {
                                if (this.TryReadDefString(metadata, out paramName, ref offset))
                                {
                                    int bit = bit = Utils.SingleBitBitmaskToBit((int)paramBit);
                                    // found modName, output to string!
                                    KeyValuePair <String, TableMetaData> tempTable = CreateRomRaiderRamTableBit(paramName, (int)paramOffset, paramId, bit);
                                    if (tempTable.Key != null)
                                    {
                                        this.RamTableList.Add(tempTable.Key, tempTable.Value);
                                    }
                                }
                                else
                                {
                                    Trace.WriteLine("Invalid definition found in mod metadata.");
                                    return(false);
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Invalid definition found in mod metadata.");
                                return(false);
                            }
                        }
                        else
                        {
                            Trace.WriteLine("Invalid definition found in mod metadata.");
                            return(false);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found in mod metadata.");
                        return(false);
                    }
                }
                else if (cookie == Mod.endoffile)
                {
                    break;
                }
            }

            return(true);
        }
예제 #13
0
파일: Lut.cs 프로젝트: segapsh2/SharpTune
 /// <summary>
 /// TODO: do 2d tables have grad/offs??
 /// </summary>
 /// <param name="blob"></param>
 /// <param name="address"></param>
 public Lut2D(string name,Blob blob, uint address)
 {
     Name = name;
     int addr = (int)(address - (uint)blob.StartAddress);
     blob.TryGetUInt16(ref cols, ref addr);
     addr += 2;
     blob.TryGetUInt32(ref colsAddress, ref addr);
     blob.TryGetUInt32(ref dataAddress, ref addr);
 }
예제 #14
0
파일: Lut.cs 프로젝트: segapsh2/SharpTune
 /// <summary>
 /// WARNING ONLY USE FOR 3d TABLES
 /// TODO arrange classes as 2D/3D and base
 /// </summary>
 /// <param name="blob"></param>
 /// <param name="address"></param>
 public Lut3D(string name, Blob blob, uint address)
 {
     Name = name;
     int addr = (int)(address - (uint)blob.StartAddress);
     blob.TryGetUInt16(ref cols, ref addr);
     blob.TryGetUInt16(ref rows, ref addr);
     blob.TryGetUInt32(ref colsAddress, ref addr);
     blob.TryGetUInt32(ref rowsAddress, ref addr);
     blob.TryGetUInt32(ref dataAddress, ref addr);
     blob.TryGetUInt32(ref tableType, ref addr);
     blob.TryGetUInt32(ref gradient, ref addr);
     blob.TryGetUInt32(ref offset, ref addr);
 }
예제 #15
0
        /// <summary>
        /// Try to read the Patch metadata from the file and add this data to table lists.
        /// </summary>
        private bool TryParseDefs(Blob metadata, ref int offset, String defPath)
        {
            UInt32 cookie = 0;

            while ((metadata.Content.Count > offset + 8) &&
                   metadata.TryGetUInt32(ref cookie, ref offset))
            {
                if (cookie == OpTable3d)//TODO CONDITIONALLY READ LUTS!
                {
                    string metaString = null;
                    uint   metaOffset = 0;
                    if (this.TryReadDefData(metadata, out metaString, out metaOffset, ref offset))
                    {
                        Blob tableBlob;
                        this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs);
                        Lut3D lut = new Lut3D(metaString, tableBlob, metaOffset);
                        if (metaString != null)
                        {
                            RomLutList.Add(lut);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return(false);
                    }
                }
                else if (cookie == OpTable2d)//TODO CONDITIONALLY READ LUTS!
                {
                    string metaString = null;
                    uint   metaOffset = 0;
                    if (this.TryReadDefData(metadata, out metaString, out metaOffset, ref offset))
                    {
                        Blob tableBlob;
                        this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs);
                        Lut2D lut = new Lut2D(metaString, tableBlob, metaOffset);
                        if (metaString != null)
                        {
                            RomLutList.Add(lut);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return(false);
                    }
                }
                else if (cookie == OpTable1d)
                {
                    string metaString = null;
                    uint   metaOffset = 0;
                    if (this.TryReadDefData(metadata, out metaString, out metaOffset, ref offset))
                    {
                        Lut lut = new Lut(metaString, metaOffset);
                        if (metaString != null)
                        {
                            RomLutList.Add(lut);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return(false);
                    }
                }
                else if (cookie == OpRAM)
                {
                    string paramName   = null;
                    string paramId     = null;
                    uint   paramOffset = 0;
                    uint   paramLenght = 0;
                    if (this.TryReadDefData(metadata, out paramId, out paramOffset, ref offset))
                    {
                        if (this.TryReadDefData(metadata, out paramName, out paramLenght, ref offset))
                        {
                            // found modName, output to string!
                            KeyValuePair <String, Table> tempTable = CreateRomRaiderRamTable(paramName, (int)paramOffset, paramId, (int)paramLenght);
                            if (tempTable.Key != null)
                            {
                                this.RamTableList.Add(tempTable.Key, tempTable.Value);
                            }
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return(false);
                    }
                }
                else if (cookie == Mod.endoffile)
                {
                    break;
                }
            }

            return(true);
        }
예제 #16
0
        /// <summary>
        /// Try to read the Patch metadata from the file and add this data to table lists.
        /// </summary>
        private bool TryParseDefs(Blob metadata, ref int offset, String defPath)
        {
            UInt32 cookie = 0;
            while ((metadata.Content.Count > offset + 8) &&
                metadata.TryGetUInt32(ref cookie, ref offset))
            {
                if (cookie == OpTable3d)//TODO CONDITIONALLY READ LUTS!
                {
                    string metaString = null;
                    uint metaOffset = 0;
                    if (this.TryReadDefData(metadata, out metaString, out metaOffset, ref offset))
                    {
                        Blob tableBlob;
                        this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs);
                        Lut3D lut = new Lut3D(metaString,tableBlob, metaOffset);
                        if (metaString != null) RomLutList.Add(lut);
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == OpTable2d)//TODO CONDITIONALLY READ LUTS!
                {
                    string metaString = null;
                    uint metaOffset = 0;
                    if (this.TryReadDefData(metadata, out metaString, out metaOffset, ref offset))
                    {
                        Blob tableBlob;
                        this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs);
                        Lut2D lut = new Lut2D(metaString,tableBlob, metaOffset);
                        if (metaString != null) RomLutList.Add(lut);
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == OpTable1d)
                {
                    string metaString = null;
                    uint metaOffset = 0;
                    if (this.TryReadDefData(metadata, out metaString, out metaOffset, ref offset))
                    {
                        Lut lut = new Lut(metaString,metaOffset);
                        if (metaString != null) RomLutList.Add(lut);
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == OpRAM)
                {
                    string paramName = null;
                    string paramId = null;
                    uint paramOffset = 0;
                    uint paramLenght = 0;
                    if (this.TryReadDefData(metadata, out paramId, out paramOffset, ref offset))
                    {
                        if (this.TryReadDefData(metadata, out paramName, out paramLenght, ref offset))
                        {
                            // found modName, output to string!
                            KeyValuePair<String, Table> tempTable = CreateRomRaiderRamTable(paramName, (int)paramOffset, paramId, (int)paramLenght);
                            if (tempTable.Key != null) this.RamTableList.Add(tempTable.Key, tempTable.Value);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Invalid definition found.");
                        return false;
                    }
                }
                else if (cookie == Mod.endoffile)
                {
                    break;
                }
            }

            return true;
        }