Exemple #1
0
        /* Code: ID of the column.
         * Label: name of the row i.e: _117_coupe_68.
         */


        public SpecDB(string folderName, SpecDBFolder type, bool loadAsOriginalImplementation)
        {
            FolderName = folderName;

            if (folderName.Length > 4 && int.TryParse(folderName.Substring(folderName.Length - 4, 4), out int vers))
            {
                Version = vers;
            }
            else
            {
                string typeName = type.ToString();
                Version = int.Parse(typeName.Substring(typeName.Length - 4, 4));
            }


            SpecDBFolderType = type;

            SpecDBName = Path.GetFileNameWithoutExtension(folderName);
            LoadingAsOriginalImplementation = loadAsOriginalImplementation;

            if (LoadingAsOriginalImplementation)
            {
                Fixed_Tables = new SpecDBTable[SPEC_DB_TABLE_COUNT];
                for (int i = 0; i < Fixed_Tables.Length; i++)
                {
                    Fixed_Tables[i] = new SpecDBTable(TABLE_NAMES[i]);
                }
            }
            else
            {
                Tables = new Dictionary <string, SpecDBTable>();
            }
        }
Exemple #2
0
        // Non Original Implementations
        public void PreLoadAllTablesFromCurrentFolder()
        {
            var tablePaths = Directory.GetFiles(FolderName, "*.dbt", SearchOption.TopDirectoryOnly);

            foreach (var table in tablePaths)
            {
                string tableName = Path.GetFileNameWithoutExtension(table);
                if (!File.Exists(Path.Combine(FolderName, tableName) + ".idi"))
                {
                    continue;
                }

                var specdbTable = new SpecDBTable(tableName);
                specdbTable.AddressInitialize(this);
                specdbTable.ReadIDIMapOffsets(this);
                Tables.Add(specdbTable.TableName, specdbTable);
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets the offset of the string key for a row code in the IDI.
        /// </summary>
        /// <param name="table">Table to look at.</param>
        /// <param name="code">Code of the row.</param>
        /// <returns></returns>
        public int GetLabelOffsetByIDFromTable(SpecDBTables table, int code)
        {
            SpecDBTable sTable = Fixed_Tables[(int)table];
            IDI         idi    = sTable.IDI;

            SpanReader sr = new SpanReader(idi.Buffer);

            sr.Position = 4;
            int entryCount = sr.ReadInt32();

            // "original" implementation had one while and one do loop, probably decompiler that just failed
            for (int i = 0; i < entryCount; i++)
            {
                sr.Position = IDI.HeaderSize + (i * 8) + 4;
                int entryCode = sr.ReadInt32();
                if (entryCode == code)
                {
                    // Original: return (char*)(idiFile + index * 8 + *(int*)(iVar3 * 8 + idiFile + 0x10) + 0x12);

                    // *(int*)(iVar3 * 8 + idiFile + 0x10)
                    int entryPos = IDI.HeaderSize + (i * 8);
                    sr.Position = entryPos;
                    int stringOffset = sr.ReadInt32();

                    // idiFile + index * 8 (go to the beginning of the second table)
                    sr.Position = IDI.HeaderSize + entryCount * 8; // Header is added due to below

                    // Add the two
                    sr.Position += stringOffset;

                    //0x12 is just the base header + the string length as short, optimized
                    return(sr.Position + 2);
                }
            }

            return(-1); // NULL
        }