Skip to content

Commit 6d3eceb

Browse files
committed
feat(core): add BOM detection and skipping for mods.txt
1 parent 8b5770e commit 6d3eceb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

UE4SS/src/UE4SSProgram.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,8 +1324,23 @@ namespace RC
13241324
else
13251325
{
13261326
// 'mods.txt' exists, lets parse it
1327+
1328+
// First, check for BOM using a byte stream
1329+
std::ifstream bom_check(enabled_mods_file, std::ios::binary);
1330+
char bom[3] = {0};
1331+
bom_check.read(bom, 3);
1332+
bool has_bom = (bom[0] == '\xEF' && bom[1] == '\xBB' && bom[2] == '\xBF');
1333+
bom_check.close();
1334+
1335+
// Now open the actual stream
13271336
StreamIType mods_stream{enabled_mods_file};
13281337

1338+
// If BOM was detected, skip the first "character" (which will be the BOM interpreted as a wide char)
1339+
if (has_bom) {
1340+
wchar_t discard;
1341+
mods_stream.get(discard);
1342+
}
1343+
13291344
StringType current_line;
13301345
while (std::getline(mods_stream, current_line))
13311346
{

0 commit comments

Comments
 (0)