Gets a name variable from the file. Keep in mind that the return value must be freed.
| 104 | |
| 105 | // Gets a name variable from the file. Keep in mind that the return value must be freed. |
| 106 | string GetUtxName(UTXHEADER &Header) |
| 107 | { |
| 108 | #define NAME_MAX_LEN 256 //@TODO: Figure out if these can possibly be longer. |
| 109 | char Name[NAME_MAX_LEN]; |
| 110 | ILubyte Length = 0; |
| 111 | |
| 112 | // New style (Unreal Tournament) name. This has a byte at the beginning telling |
| 113 | // how long the string is (plus terminating 0), followed by the terminating 0. |
| 114 | if (Header.Version >= 64) { |
| 115 | Length = igetc(); |
| 116 | if (iread(Name, Length, 1) != 1) |
| 117 | return ""; |
| 118 | if (Name[Length-1] != 0) |
| 119 | return ""; |
| 120 | return string(Name); |
| 121 | } |
| 122 | |
| 123 | // Old style (Unreal) name. This string length is unknown, but it is terminated |
| 124 | // by a 0. |
| 125 | do { |
| 126 | Name[Length++] = igetc(); |
| 127 | } while (!ieof() && Name[Length-1] != 0 && Length < NAME_MAX_LEN); |
| 128 | |
| 129 | // Never reached the terminating 0. |
| 130 | if (Length == NAME_MAX_LEN && Name[Length-1] != 0) |
| 131 | return ""; |
| 132 | |
| 133 | return string(Name); |
| 134 | #undef NAME_MAX_LEN |
| 135 | } |
| 136 | |
| 137 | |
| 138 | bool GetUtxNameTable(vector <UTXENTRYNAME> &NameEntries, UTXHEADER &Header) |