/// <summary> /// Gets a car code by raw index (not ID). /// </summary> /// <param name="index">Index within the table.</param> /// <returns></returns> public string GetCarLabelByIndex(int index) { int carLabelCount = GetLabelCountForTable(SpecDBTables.GENERIC_CAR); if (carLabelCount > -1 && index < carLabelCount) { //idi = MSpecDB::GetIDITableByIndex(pMVar2, 0); IDI idTable = Fixed_Tables[(int)SpecDBTables.GENERIC_CAR].IDI; SpanReader sr = new SpanReader(idTable.Buffer); // buf = buf + *(int*)(buf + param_1 * 8 + 0x10) + *(int*)(buf + 4) * 8 + 0x12; sr.Position = IDI.HeaderSize + (index * 8); int strOffset = sr.ReadInt32(); sr.Position = 4; int entryCount = sr.ReadInt32(); sr.Position = IDI.HeaderSize + (entryCount * 8) + strOffset; // str map offset + strOffset sr.Position += 2; // Ignore string size as per original implementation /* Original Returns the length of the string (pointer) and the buffer * strncpy(strOut, buf, strBufLen); * strOut[strBufLen + -1] = '\0'; * iVar1 = strlen(strOut, (char*)buf); * return iVar1; */ return(sr.ReadString0()); // Null-Terminated } return(null); }
public void ReadIDIMapOffsets(SpecDB specDb) { //if (TableName.Equals("CAR_NAME_")) // TableName += specDb.LocaleName; var buffer = File.ReadAllBytes(Path.Combine(specDb.FolderName, TableName) + ".idi"); SpanReader sr = new SpanReader(buffer); var magic = sr.ReadStringRaw(4); if (magic != "GTID") { throw new InvalidDataException("IDI Table had invalid magic."); } Endian endian = sr.ReadByte() != 0 ? Endian.Little : Endian.Big; IDI = new IDI(buffer, endian); sr.Endian = endian; sr.Position = 0x0C; TableID = sr.ReadInt32(); }
/// <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 }
public int GetLabelCountForTable(SpecDBTables table) { IDI idTable = Fixed_Tables[(int)table].IDI; return(idTable.KeyCount); }
public int GetCarLabelCount() { IDI idTable = Fixed_Tables[(int)SpecDBTables.GENERIC_CAR].IDI; return(idTable.KeyCount); }
/// <summary> /// Gets the ID/Code of a label. /// </summary> /// <param name="label">Label name.</param> /// <returns></returns> public int GetIDOfLabel(string label) => IDI.SearchLabelID(label);