Exemplo n.º 1
0
        private void ProcessCarInfoArrayChunk(Chunk chunk, BinaryReader reader)
        {
            int alignedSize = chunk.GetAlignedSize(0x10);

            if (alignedSize % 0xD0 != 0)
            {
                throw new ChunkCorruptedException("CarTypeInfoArray is malformed!");
            }

            reader.AlignToBoundary(0x10);

            for (int i = 0; i < alignedSize / 0xD0; i++)
            {
                CarTypeInfo carTypeInfo = BinaryHelpers.ReadStruct <CarTypeInfo>(reader);
                CarRecord   carRecord   = new CarRecord
                {
                    BaseModelName     = carTypeInfo.BaseModelName,
                    CarTypeName       = carTypeInfo.CarTypeName,
                    DefaultBasePaint  = carTypeInfo.DefaultBasePaint,
                    DefaultSkinNumber = carTypeInfo.DefaultSkinNumber,
                    GeometryFilename  = carTypeInfo.GeometryFilename,
                    ManufacturerName  = carTypeInfo.ManufacturerName,
                    MemoryType        = (CarMemoryType)carTypeInfo.CarMemTypeHash,
                    Skinnable         = carTypeInfo.Skinnable,
                    UsageType         = carTypeInfo.UsageType
                };

                Database.CarRecordManager.AddCarRecord(carRecord);
            }
        }
Exemplo n.º 2
0
        public static VehiclePropArr GetVehiclePropArr(string vehicle_id)
        {
            VehiclePropArr model = null;

            try
            {
                #region strCommand
                string strCommand = "  SELECT DISTINCT " +
                                    "  p.hmodtyp vehicle_id, " +
                                    "  p.cmodnamepc model_name, " +
                                    "  p.xcardrs, " +
                                    "  p.dmodyr, " +
                                    "  p.xgradefulnam, " +
                                    "  p.ctrsmtyp, " +
                                    "  p.cmftrepc, " +
                                    "  p.carea, " +
                                    "  p.nengnpf " +
                                    "  FROM pmotyt p " +
                                    "  WHERE p.hmodtyp = @vehicle_id LIMIT 1; ";
                #endregion

                using (IDbConnection db = new MySqlConnection(strConn))
                {
                    CarTypeInfo carType = db.Query <CarTypeInfo>(strCommand, new { vehicle_id }).FirstOrDefault();

                    List <attributes> list = GetAttributes();

                    list[0].value = carType.model_name;
                    list[1].value = carType.xcardrs;
                    list[2].value = carType.dmodyr;
                    list[3].value = carType.xgradefulnam;
                    list[4].value = carType.ctrsmtyp;
                    list[5].value = carType.cmftrepc;
                    list[6].value = carType.carea;
                    list[7].value = carType.nengnpf;

                    model = new VehiclePropArr {
                        model_name = carType.model_name
                    };
                    model.attributes = list;
                }
            }
            catch (Exception ex)
            {
                string Errror = ex.Message;
                int    y      = 0;
            }

            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Decompile entire cartypeinfo block into Vector of separate elements.
        /// </summary>
        /// <param name="byteptr_t">Pointer to the beginning of cartypeinfo block in Global data.</param>
        /// <param name="length">Length of the block to be read.</param>
        /// <param name="db">Database to which add classes.</param>
        private static unsafe void E_CarTypeInfo(byte *byteptr_t, uint length, Database.Underground2 db)
        {
            const uint size = 0x890;

            for (uint loop = 0; loop < length / size; ++loop)
            {
                uint offset = 8 + loop * size; // current offset of the cartypeinfo (padding included)

                // Get CollectionName
                string CName = ScriptX.NullTerminatedString(byteptr_t + offset, 0x10);

                CName = Resolve.GetPathFromCollection(CName);
                Map.BinKeys[Bin.Hash(CName)] = CName;

                var Class = new CarTypeInfo((IntPtr)(byteptr_t + offset), CName, db);
                db.CarTypeInfos.Collections.Add(Class);
            }
        }
Exemplo n.º 4
0
        public void AddCarinfo(CarTypeInfo item)
        {
            int error = 0;

            do
            {
                try
                {
                    using (var db = _dbFactory.OpenDbConnection())
                    {
                        db.Insert(item);
                    }
                    break;
                }
                catch (Exception ex1)
                {
                    error++;
                    Thread.Sleep(10000);
                    LogServer.WriteLog(ex1.Message, "DBError");
                }
            } while (error < 4);
        }
Exemplo n.º 5
0
        public CarTypeInfo GetCarinfo(CarTypeInfo item)
        {
            int error = 0;

            do
            {
                try
                {
                    using (var db = _dbFactory.OpenDbConnection())
                    {
                        return(db.Single <CarTypeInfo>(c => c.DisplayName == item.DisplayName));
                    }
                    break;
                }
                catch (Exception ex1)
                {
                    error++;
                    Thread.Sleep(10000);
                    LogServer.WriteLog(ex1.Message, "DBError");
                }
            } while (error < 4);

            return(null);
        }
Exemplo n.º 6
0
        protected override void Write(IProgress <string> progress = null)
        {
            progress?.Report("Generating car array");

            BeginChunk(0x34600);
            NextAlignment(0x10);

            var cars = _carService.GetCars();

            for (var index = 0; index < cars.Count; index++)
            {
                var aaronCarRecord = cars[index];
                var cti            = new CarTypeInfo
                {
                    MaxInstances         = new byte[5],
                    WantToKeepLoaded     = new byte[5],
                    pad4                 = new byte[2],
                    MinTimeBetweenUses   = new float[5],
                    AvailableSkinNumbers = new byte[10],

                    CarTypeName         = aaronCarRecord.CarTypeName,
                    BaseModelName       = aaronCarRecord.BaseModelName,
                    GeometryFilename    = @"CARS\" + aaronCarRecord.CarTypeName + @"\GEOMETRY.BIN",
                    CarMemTypeHash      = Hashing.BinHash(aaronCarRecord.UsageType.ToString()),
                    CarTypeNameHash     = aaronCarRecord.BaseCarID,
                    UsageType           = aaronCarRecord.UsageType,
                    ManufacturerName    = aaronCarRecord.ManufacturerName,
                    DefaultSkinNumber   = aaronCarRecord.DefaultSkinNumber,
                    WhatGame            = '\x01',
                    WheelInnerRadiusMax = '\x14',
                    WheelInnerRadiusMin = '\x11',
                    WheelOuterRadius    = '\x1a',

                    DefaultBasePaint = aaronCarRecord.DefaultBasePaint,
                    Skinnable        = aaronCarRecord.Skinnable,

                    DriverRenderingOffset             = new bVector3(),
                    HeadlightPosition                 = new bVector3(),
                    InCarSteeringWheelRenderingOffset = new bVector3(),

                    Type = index
                };

                BinaryHelpers.WriteStruct(Writer, cti);
            }

            EndChunk();

            progress?.Report("Generating AnimHookupTable");

            BeginChunk(0x34608);

            for (int i = 0; i < 123; i++)
            {
                Writer.Write((byte)0xff);
            }

            Writer.Write((byte)0x00);

            EndChunk();

            progress?.Report("Generating AnimHideTables");
            BeginChunk(0x34609);

            for (int i = 0; i < 256; i++)
            {
                Writer.Write((byte)0xff);
            }
            EndChunk();

            progress?.Report("Generating SlotTypes");
            BeginChunk(0x34607);

            Writer.Write(_projectService.GetCurrentProject().SlotOverrideData);

            foreach (var aaronCarRecord in _carService.GetCars())
            {
                if (aaronCarRecord.Spoiler == null)
                {
                    continue;
                }

                var ss = new SpoilerStructure();
                ss.CarTypeNameHash = ss.CarTypeNameHash2 = aaronCarRecord.BaseCarID;
                ss.Unknown         = 0x3C;
                ss.SpoilerHash     = (uint)aaronCarRecord.Spoiler.SpoilerType;

                BinaryHelpers.WriteStruct(Writer, ss);
            }

            EndChunk();

            PaddingAlignment(0x10);

            this.GenerateCarPartData(progress);

            PaddingAlignment(0x10);
            DifferenceAlignment(0x8);

            progress?.Report("Writing collision data");
            BeginChunk(0x8003B900);

            foreach (var aaronCarRecord in cars)
            {
                if (aaronCarRecord.BoundsPack == null)
                {
                    continue;
                }

                BeginChunk(0x3b901);

                NextAlignment(0x10);

                var boundsPack = aaronCarRecord.BoundsPack;

                var bh = new BoundsHeader
                {
                    NameHash  = aaronCarRecord.CollisionHash,
                    NumBounds = boundsPack.Entries.Count
                };

                BinaryHelpers.WriteStruct(Writer, bh);

                foreach (var aaronBoundsEntry in boundsPack.Entries)
                {
                    var bounds = new Bounds
                    {
                        AttributeName  = aaronBoundsEntry.AttributeName,
                        Position       = aaronBoundsEntry.Position,
                        ChildIndex     = aaronBoundsEntry.ChildIndex,
                        CollectionPtr  = 0,
                        HalfDimensions = aaronBoundsEntry.HalfDimensions,
                        Pivot          = aaronBoundsEntry.Pivot,
                        NameHash       = aaronBoundsEntry.NameHash,
                        PCloudIndex    = aaronBoundsEntry.PCloudIndex,
                        NumChildren    = aaronBoundsEntry.NumChildren,
                        Orientation    = aaronBoundsEntry.Orientation,
                        Surface        = aaronBoundsEntry.Surface,
                        Flags          = (ushort)aaronBoundsEntry.Flags
                    };

                    BinaryHelpers.WriteStruct(Writer, bounds);
                }

                BinaryHelpers.WriteStruct(Writer, new PCloudHeader
                {
                    NumPClouds = boundsPack.PointClouds.Count
                });

                foreach (var aaronBoundsPointCloud in boundsPack.PointClouds)
                {
                    Writer.Write(aaronBoundsPointCloud.Vertices.Count);
                    Writer.Write(0);
                    Writer.Write(0L);

                    foreach (var vertex in aaronBoundsPointCloud.Vertices)
                    {
                        BinaryHelpers.WriteStruct(Writer, vertex);
                    }
                }

                EndChunk();
            }

            EndChunk();

            PaddingAlignment(0x10);

            progress?.Report("Writing preset cars");

            BeginChunk(0x30220);

            foreach (var aaronPresetCar in _presetCarService.GetPresetCars())
            {
                BinaryHelpers.WriteStruct(Writer, PresetConverter.ConvertAaronPresetToFEPreset(aaronPresetCar));
            }

            EndChunk();

            PaddingAlignment(0x10);

            progress?.Report("Writing preset skins");
            BeginChunk(0x30250);

            foreach (var aaronPresetSkinRecord in _presetSkinService.GetPresetSkins())
            {
                var ps = new PresetSkin
                {
                    Null  = new byte[0x8],
                    Null3 = new byte[0x38],

                    PresetName      = aaronPresetSkinRecord.PresetName,
                    PaintGroup      = aaronPresetSkinRecord.PaintGroup,
                    PaintHue        = aaronPresetSkinRecord.PaintHue,
                    PaintVariance   = aaronPresetSkinRecord.Variance,
                    PaintSaturation = aaronPresetSkinRecord.Saturation,
                    VinylHash       = 0xFFFFFFFFu
                };

                BinaryHelpers.WriteStruct(Writer, ps);
            }

            EndChunk();

            progress?.Report("Writing data tables");

            foreach (var aaronDataTable in _dataTableService.GetDataTables())
            {
                PaddingAlignment(0x10);
                BeginChunk(0x3CE14);
                NextAlignment(0x10);

                Writer.Write(aaronDataTable.Hash);

                foreach (var aaronDataTableEntry in aaronDataTable.Entries)
                {
                    Writer.Write(aaronDataTableEntry.Hash);
                    Writer.Write(aaronDataTableEntry.Unknown);
                    Writer.Write(aaronDataTableEntry.Unknown2);
                }

                EndChunk();
            }

            progress?.Report("Post-processing");

            //BeginChunk(0);

            //var watermarkStr = "File generated by Aaron+ (commit hash: " + VersionReader.AppVersion + ") on ";
            //watermarkStr += DateTime.Now.ToShortDateString();
            //watermarkStr += " @ " + DateTime.Now.ToShortTimeString();
            //watermarkStr += " | Created by heyitsleo";

            //Writer.Write(watermarkStr);

            //EndChunk();
        }