Example #1
0
        public static string RegionDirectory(string region_name)
        {
            FormatX.GetInt32(region_name, "L{X}R#", out int area);
            string loc = region_name.Substring(region_name.Length - 1, 1);

            return($"Location{area.ToString()}\\Region{loc.ToUpper()}");
        }
        /// <summary>
        /// Disperses all settings from the rim string passed.
        /// </summary>
        /// <param name="rim">Rim string to be dispersed.</param>
        /// <param name="brand">Brand of the rim.</param>
        /// <param name="style">Style of the rim brand.</param>
        /// <param name="size">Size of the rim brand.</param>
        /// <param name="max">Max outer size of the rim brand.</param>
        private void DisperseRimSettings(string rim)
        {
            bool potentialspi = false;

            if (rim.EndsWith("_SPI"))
            {
                potentialspi = true;
                rim          = rim.Substring(0, rim.Length - 4);
            }
            this._rim_brand = FormatX.GetString(rim, "{X}_STYLE##_##_##");
            if (!FormatX.GetByte(rim, this._rim_brand + "_STYLE{X}_##_##", out byte thisstyle))
            {
                thisstyle = 1;
            }
            if (!FormatX.GetByte(rim, this._rim_brand + "_STYLE##_{X}_##", out byte thissize))
            {
                thissize = 18;
            }
            if (!FormatX.GetByte(rim, this._rim_brand + "_STYLE##_##_{X}", out byte thismax))
            {
                thismax = 24;
            }
            this._rim_style       = thisstyle;
            this._rim_size        = thissize;
            this._rim_outer_max   = thismax;
            this._is_spinning_rim = potentialspi ? eBoolean.True : eBoolean.False;
        }
Example #3
0
 /// <summary>
 /// Gets pearl window tint string from a string passed.
 /// </summary>
 /// <param name="tint">String to get pearl window tint from.</param>
 /// <returns>Pearl tint string if was resolved, null otherwise.</returns>
 public static void GetWindowTintString(string tint)
 {
     try
     {
         if (!tint.StartsWith("WINDSHIELD_TINT"))
         {
             return;
         }
         if (!int.TryParse(tint.Substring(17, 1), out int level))
         {
             return;
         }
         if (level == 3)
         {
             string color = FormatX.GetString(tint, "WINDSHIELD_TINT_L3_{X}");
             string var1  = "WINDSHIELD_TINT_L3_PEARL_" + color;
             string var2  = "WINDSHIELD_TINT_L3_PEARL " + color;
             Map.WindowTintMap.Add(var1);
             Map.WindowTintMap.Add(var2);
             Bin.Hash(var1);
             Bin.Hash(var2);
             return;
         }
         else
         if (!Map.WindowTintMap.Contains(tint))
         {
             Map.WindowTintMap.Add(tint);
         }
     }
     catch (Exception) { }
 }
Example #4
0
 /// <summary>
 /// Gets blue parameter of a hexadecimal color passed.
 /// </summary>
 /// <param name="color">Hexadecimal color passed.</param>
 /// <returns>Blue parameter as a byte.</returns>
 public static byte GetBlue(string color)
 {
     try
     {
         string hex = FormatX.GetString(color, "0xABCDEF{XX}");
         return(Convert.ToByte(hex, 16));
     }
     catch (Exception) { return(0); }
 }
Example #5
0
        public static bool CareerStageCollectionName(string CName)
        {
            if (!CName.StartsWith("STAGE_"))
            {
                return(false);
            }
            string index = FormatX.GetString(CName, "STAGE_{X}");

            return(byte.TryParse(index, out byte _));
        }
Example #6
0
        public unsafe void Assemble(byte *byteptr_t)
        {
            FormatX.GetByte(this._collection_name, "STAGE_{X}", out byte stage);
            *byteptr_t = stage;
            *(byteptr_t + 0x01)          = this.NumberOfSponsorsToChoose;
            *(short *)(byteptr_t + 0x02) = this.OutrunCashValue;
            *(short *)(byteptr_t + 0x04) = this.Unknown0x04;
            *(short *)(byteptr_t + 0x06) = this.Unknown0x06;

            *(uint *)(byteptr_t + 0x08) = Bin.SmartHash(this._stage_sponsor1);
            *(uint *)(byteptr_t + 0x0C) = Bin.SmartHash(this._stage_sponsor2);
            *(uint *)(byteptr_t + 0x10) = Bin.SmartHash(this._stage_sponsor3);
            *(uint *)(byteptr_t + 0x14) = Bin.SmartHash(this._stage_sponsor4);
            *(uint *)(byteptr_t + 0x18) = Bin.SmartHash(this._stage_sponsor5);

            *(short *)(byteptr_t + 0x1C) = this.AttribSponsor1;
            *(short *)(byteptr_t + 0x1E) = this.AttribSponsor2;
            *(short *)(byteptr_t + 0x20) = this.AttribSponsor3;
            *(short *)(byteptr_t + 0x22) = this.AttribSponsor4;
            *(short *)(byteptr_t + 0x24) = this.AttribSponsor5;
            *(short *)(byteptr_t + 0x26) = this.Unknown0x26;

            *(uint *)(byteptr_t + 0x28) = Bin.SmartHash(this._last_stage_event);

            *(byteptr_t + 0x2C) = this.Unknown0x2C;
            *(byteptr_t + 0x2D) = this.Unknown0x2D;
            *(byteptr_t + 0x2E) = this.Unknown0x2E;
            *(byteptr_t + 0x2F) = this.Unknown0x2F;

            *(byteptr_t + 0x30) = this.MaxCircuitsShownOnMap;
            *(byteptr_t + 0x31) = this.MaxDragsShownOnMap;
            *(byteptr_t + 0x32) = this.MaxStreetXShownOnMap;
            *(byteptr_t + 0x33) = this.MaxDriftsShownOnMap;
            *(byteptr_t + 0x34) = this.MaxSprintsShownOnMap;

            *(byteptr_t + 0x35) = this.Unknown0x35;
            *(byteptr_t + 0x36) = this.Unknown0x36;
            *(byteptr_t + 0x37) = this.Unknown0x37;
            *(byteptr_t + 0x38) = this.Unknown0x38;
            *(byteptr_t + 0x39) = this.Unknown0x39;
            *(byteptr_t + 0x3A) = this.Unknown0x3A;
            *(byteptr_t + 0x3B) = this.Unknown0x3B;
            *(byteptr_t + 0x3C) = this.Unknown0x3C;
            *(byteptr_t + 0x3D) = this.Unknown0x3D;
            *(byteptr_t + 0x3E) = this.Unknown0x3E;
            *(byteptr_t + 0x3F) = this.Unknown0x3F;

            *(byteptr_t + 0x40)          = this.MaxOutrunEvents;
            *(byteptr_t + 0x41)          = this.Unknown0x41;
            *(byteptr_t + 0x42)          = this.Unknown0x42;
            *(byteptr_t + 0x43)          = this.Unknown0x43;
            *(float *)(byteptr_t + 0x44) = this.Unknown0x44;
            *(float *)(byteptr_t + 0x48) = this.Unknown0x48;
            *(float *)(byteptr_t + 0x4C) = this.Unknown0x4C;
        }
Example #7
0
        /// <summary>
        /// Disassembles frontend group array into separate properties.
        /// </summary>
        /// <param name="byteptr_t">Pointer to the frontend group array.</param>
        protected override unsafe void Disassemble(byte[] data)
        {
            this._DATA = new byte[data.Length];
            Buffer.BlockCopy(data, 0, this._DATA, 0, data.Length);

            fixed(byte *byteptr_t = &this._DATA[0])
            {
                this.Size = *(uint *)(byteptr_t + 4);

                // For some reason HUFF compression has the same ID as FEng files
                if (*(uint *)(byteptr_t + 8) == 0x46465548)
                {
                    this.Destroy = true;
                    return;
                }

                // Read CollectionName
                this.CollectionName = ScriptX.NullTerminatedString(byteptr_t + 0x30, this._DATA.Length - 0x30);
                if (this.CollectionName.EndsWith(".fng"))
                {
                    this.CollectionName = FormatX.GetString(this.CollectionName, "{X}.fng");
                }

                for (uint offset = 0x30; offset < this._DATA.Length; offset += 4)
                {
                    byte b1 = *(byteptr_t + offset);
                    byte b2 = *(byteptr_t + offset + 1);
                    byte b3 = *(byteptr_t + offset + 2);
                    byte b4 = *(byteptr_t + offset + 3);

                    // SAT, SAD, SA(0x90) or 1111
                    if ((b1 == 'S' && b2 == 'A') || (b1 == 0xFF && b2 == 0xFF && b3 == 0xFF && b4 == 0xFF))
                    {
                        uint Blue  = *(uint *)(byteptr_t + offset + 4);
                        uint Green = *(uint *)(byteptr_t + offset + 8);
                        uint Red   = *(uint *)(byteptr_t + offset + 12);
                        uint Alpha = *(uint *)(byteptr_t + offset + 16);

                        // If it is a color, add to the list
                        if (Resolve.IsColor(Alpha, Red, Green, Blue))
                        {
                            var TempColor = new FEngColor(this);
                            TempColor.Offset = offset;
                            TempColor.Alpha  = (byte)Alpha;
                            TempColor.Red    = (byte)Red;
                            TempColor.Green  = (byte)Green;
                            TempColor.Blue   = (byte)Blue;
                            this._colorinfo.Add(TempColor);
                        }
                        offset += 0x14;
                    }
                }
            }
        }
Example #8
0
 public static bool TrackCollectionName(string CName)
 {
     // Allowed format: Track_#, where # is ushort
     if (!CName.StartsWith("Track_"))
     {
         return(false);
     }
     if (!FormatX.GetInt32(CName, "Track_{X}", out int result))
     {
         return(false);
     }
     return(result <= ushort.MaxValue);
 }
Example #9
0
        public static bool BankTriggerCollectionName(string CName)
        {
            if (CName.Length != 15)
            {
                return(false);
            }
            if (!CName.StartsWith("BANK_TRIGGER_"))
            {
                return(false);
            }
            string index = FormatX.GetString(CName, "BANK_TRIGGER_{X}");

            return(byte.TryParse(index, out byte _));
        }
Example #10
0
        /// <summary>
        /// Sets first valid rim outer max radius based on current brand and style.
        /// </summary>
        private void SetValidRimSize()
        {
            string rim = $"{this._rim_brand}_STYLE{this._rim_style:00}";

            foreach (var str in Map.RimBrands)
            {
                if (str.StartsWith(rim))
                {
                    if (FormatX.GetByte(str, rim + "_{X}_##", out byte radius))
                    {
                        this._rim_size = radius;
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// Sets first valid rim outer max radius based on current brand, style and size.
        /// </summary>
        private void SetValidRimOuterMax()
        {
            string rim = $"{this._rim_brand}_STYLE{this._rim_style:00}_{this._rim_size}_";

            foreach (var str in Map.RimBrands)
            {
                if (str.StartsWith(rim))
                {
                    if (FormatX.GetByte(str, rim + "{X}", out byte radius))
                    {
                        this._rim_outer_max = radius;
                        return;
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Checks if a value passed is a valid rim size in terms of current
        /// brand and style.
        /// </summary>
        /// <param name="value">Rim size value to check.</param>
        /// <returns>True if value passed is valid, false otherwise.</returns>
        private bool IsValidRimSize(byte value)
        {
            string rim = $"{this._rim_brand}_STYLE{this._rim_style:00}_";

            foreach (var str in Map.RimBrands)
            {
                if (str.StartsWith(rim))
                {
                    if (!FormatX.GetByte(str, rim + "{X}_##", out byte radius))
                    {
                        continue;
                    }
                    if (value == radius)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #13
0
 public static bool TrackRegionName(string region_name)
 {
     // Allowed format: L#R&, where # = int number, & = ascii char
     if (!region_name.StartsWith("L"))
     {
         return(false);
     }
     if (region_name.Substring(region_name.Length - 2, 1) != "R")
     {
         return(false);
     }
     if ((byte)region_name[region_name.Length - 1] > sbyte.MaxValue)
     {
         return(false);
     }
     if (!FormatX.GetInt32(region_name, "L{X}R#", out int result))
     {
         return(false);
     }
     return(true);
 }
Example #14
0
        public static bool PartUnlockableCollectionName(string CName)
        {
            if (CName.Length != 10)
            {
                return(false);
            }
            if (!CName.StartsWith("CARPART_"))
            {
                return(false);
            }
            string index = FormatX.GetString(CName, "CARPART_{X}");

            if (ConvertX.ToInt32(index) == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #15
0
        /// <summary>
        /// Gets index from "Color[#]" string.
        /// </summary>
        /// <param name="field">String from which get the index.</param>
        /// <returns>Integer value of the index of the color.</returns>
        public static int GetIndex(string field)
        {
            int result = -1;

            if (!field.StartsWith("Color["))
            {
                return(-1);
            }
            if (!field.EndsWith("]"))
            {
                return(-1);
            }
            try
            {
                string str = FormatX.GetString(field, "Color[{X}]");
                if (!int.TryParse(str, out result))
                {
                    return(-1);
                }
            }
            catch { }
            return(result);
        }
Example #16
0
 public string EndTagToStartTag(string tag)
 {
     return(FormatX.GetString(tag, "/{X}"));
 }
Example #17
0
        private static string ExecuteUpdateFNG(BasicBase db, string node, string field, string value)
        {
            if (!db.TryGetCollection(node, FNGroups, out var collection))
            {
                return($"Collection {node} does not exist in root {FNGroups}.");
            }
            if (!(collection is FNGroup fng))
            {
                return($"Collection {node} is not a {FNGroups} collection.");
            }

            if (!SAT.CanBeColor(value))
            {
                return($"Value {value} is not an 8-digit hexadecimal color-type.");
            }

            var color = new FEngColor(null);

            color.Alpha = SAT.GetAlpha(value);
            color.Red   = SAT.GetRed(value);
            color.Green = SAT.GetGreen(value);
            color.Blue  = SAT.GetBlue(value);

            if (field.StartsWith("ReplaceSame"))
            {
                if (field.StartsWith("ReplaceSameNoAlpha[") && field.EndsWith("]"))
                {
                    if (FormatX.GetInt32(field, "ReplaceSameNoAlpha[{X}]", out int index))
                    {
                        fng.TrySetSame(index, color, true);
                    }
                    else
                    {
                        return($"Unable to get color index from field named {field}.");
                    }
                }
                else if (field.StartsWith("ReplaceSameWithAlpha[") && field.EndsWith("]"))
                {
                    if (FormatX.GetInt32(field, "ReplaceSameWithAlpha[{X}]", out int index))
                    {
                        fng.TrySetSame(index, color, false);
                    }
                    else
                    {
                        return($"Unable to get color index from field named {field}.");
                    }
                }
                else
                {
                    return($"Incorrect passed parameter named {field}.");
                }
            }
            else if (field == "ReplaceAllNoAlpha")
            {
                fng.TrySetAll(color, true);
            }
            else if (field == "ReplaceAllWithAlpha")
            {
                fng.TrySetAll(color, false);
            }
            else
            {
                int index = SAT.GetIndex(field);
                if (index >= fng.InfoLength || index == -1)
                {
                    return($"Field named {field} does not exist.");
                }
                fng.TrySetOne(index, color);
            }
            return(null);
        }
Example #18
0
 public static string TrackDirectory(string region_name, string CName)
 {
     FormatX.GetInt32(region_name, "L{X}R#", out int area);
     return($"Location{area.ToString()}\\{CName}");
 }
Example #19
0
        /// <summary>
        /// Loads Wheels files and reads its rim brand strings
        /// </summary>
        /// <param name="Wheels_dir">Directory of the game.</param>
        /// <param name="db">Database of classes.</param>
        /// <returns>True if success.</returns>
        public static unsafe bool LoadWheels(string Wheels_dir)
        {
            Wheels_dir += @"\CARS\WHEELS";
            if (!Directory.Exists(Wheels_dir))
            {
                if (Process.MessageShow)
                {
                    MessageBox.Show(@"Directory CARS\WHEELS does not exist.", "Failure");
                }
                else
                {
                    Console.WriteLine(@"Directory CARS\WHEELS does not exist.");
                }
                return(false);
            }

            var files = Directory.GetFiles(Wheels_dir);

            if (files == null || files.Length == 0)
            {
                if (Process.MessageShow)
                {
                    MessageBox.Show(@"Directory CARS\WHEELS is empty.", "Failure");
                }
                else
                {
                    Console.WriteLine(@"Directory CARS\WHEELS is empty.");
                }
                return(false);
            }

            foreach (var file in files)
            {
                string ext = Path.GetExtension(file).ToUpper();
                if (!Path.GetFileName(file).StartsWith("GEOMETRY_") || (Path.GetExtension(file).ToUpper() != ".BIN"))
                {
                    continue;
                }
                try
                {
                    using (var br = new BinaryReader(File.Open(file, FileMode.Open, FileAccess.Read)))
                    {
                        if (br.ReadUInt32() != 0x80134000)
                        {
                            continue;                                        // if not a wheels file
                        }
                        br.BaseStream.Position += 4;                         // skip size
                        while (br.BaseStream.Position < br.BaseStream.Length)
                        {
                            uint ID   = br.ReadUInt32();
                            int  size = br.ReadInt32();
                            int  off  = (int)br.BaseStream.Position;
                            if (ID != 0x80134010)
                            {
                                br.ReadBytes(size);
                                continue;
                            }
                            while ((int)br.BaseStream.Position < off + size)
                            {
                                ID   = br.ReadUInt32();
                                size = br.ReadInt32();
                                if (ID == 0x00134011)
                                {
                                    break;
                                }
                            }
                            if (ID != 0x00134011)
                            {
                                continue;
                            }
                            br.BaseStream.Position += 0xA4;
                            string rim = ScriptX.NullTerminatedString(br);
                            br.BaseStream.Position -= 0xB0 + rim.Length + 1;
                            rim = FormatX.GetString(rim, "{X}_X");
                            if (!Map.RimBrands.Contains(rim))
                            {
                                Map.RimBrands.Add(rim);
                            }
                            br.ReadBytes(br.ReadInt32());
                        }
                    }
                }
                catch (Exception e)
                {
                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }
                    if (Process.MessageShow)
                    {
                        MessageBox.Show(e.Message, "Failure");
                    }
                    else
                    {
                        Console.WriteLine(e.Message);
                    }
                    return(false);
                }
            }
            foreach (var rim in Map.RimBrands)
            {
                Bin.Hash(rim);
            }
            return(true);
        }