Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FontXY and scummfont use the internal I/O lib for big-endian support #24

Merged
merged 12 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ endif()
include(GNUInstallDirs)

include_directories ("src")
add_subdirectory ("src/common")
add_subdirectory ("src/FontXY")
add_subdirectory ("src/ScummFont")
add_subdirectory ("src/ScummRp")
Expand Down
2 changes: 2 additions & 0 deletions src/FontXY/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_executable (FontXY "FontXY.cpp")

target_link_libraries (FontXY PUBLIC scummiolib)

install(TARGETS FontXY RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
62 changes: 43 additions & 19 deletions src/FontXY/FontXY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "common/types.hpp"
#include "common/file.hpp"

#include <algorithm>
#include <fstream>
Expand All @@ -40,27 +41,34 @@ int main(int argc, char **argv)
return 0;
}

if (!cpu_is_little_endian())
{
std::cerr << "ERROR: FontXY is currently only compatible with little-endian systems" << std::endl;
return 1;
}

bool bImport = argv[1][0] == 'i';
char *pszChar = argv[2];
char szTxt[] = "XY.txt"; // TODO: param

if (bImport)
{
char szLine[1024];
std::fstream fChar(pszChar, std::fstream::in | std::fstream::out | std::fstream::binary);
std::ifstream fTxt(szTxt, std::ifstream::in);
File fChar;

if (!fTxt.is_open())
{
std::cerr << "Error: cannot open " << szTxt << std::endl;
return 1;
}

fChar.open(pszChar, std::ios::in | std::ios::out | std::ios::binary);
if (!fChar.is_open())
{
std::cerr << "Error: cannot open " << pszChar << std::endl;
return 1;
}

// Seek after the header
fChar.seekg(8 + 0x17);
fChar.seekg(8 + 0x17, std::ios::beg);

int16 snNumChars; // <= 0x100
fChar.read((char *)&snNumChars, 2);
fChar->getLE16(snNumChars);
int nNumChars = snNumChars;
if (nNumChars > 0x100 || nNumChars <= 0)
{
Expand All @@ -71,8 +79,8 @@ int main(int argc, char **argv)
for (int i = 0; i < nNumChars; ++i)
{
uint32 uOffset;
fChar.seekg(8 + 0x19 + i * 4);
fChar.read((char *)&uOffset, 4);
fChar.seekg(8 + 0x19 + i * 4, std::ios::beg);
fChar->getLE32(uOffset);

if (uOffset == 0)
{
Expand All @@ -89,22 +97,37 @@ int main(int argc, char **argv)
fTxt.getline(szLine, sizeof szLine, '\n');
byLeft = (int8)nLeft;
byTop = (int8)nTop;
fChar.seekp(8 + 0x15 + uOffset + 2);
fChar.seekp(8 + 0x15 + uOffset + 2, std::ios::beg);
fChar.write((char *)&byLeft, 1);
fChar.write((char *)&byTop, 1);
}
}
fTxt.close();
fChar.close();
}
else
{
std::ifstream fChar(pszChar, std::ifstream::in | std::ifstream::binary);
File fChar;
std::ofstream fTxt(szTxt, std::ofstream::out | std::ofstream::trunc);

if (!fTxt.is_open())
{
std::cerr << "Error: cannot open " << szTxt << std::endl;
return 1;
}

fChar.open(pszChar, std::ios::in | std::ios::binary);
if (!fChar.is_open())
{
std::cerr << "Error: cannot open " << pszChar << std::endl;
return 1;
}

// Seek after the header
fChar.seekg(8 + 0x17);
fChar.seekg(8 + 0x17, std::ios::beg);

int16 snNumChars; // <= 0x100
fChar.read((char *)&snNumChars, 2);
fChar->getLE16(snNumChars);
int nNumChars = snNumChars;
if (nNumChars > 0x100 || nNumChars <= 0)
{
Expand All @@ -115,8 +138,8 @@ int main(int argc, char **argv)
for (int i = 0; i < nNumChars; ++i)
{
uint32 uOffset;
fChar.seekg(8 + 0x19 + i * 4);
fChar.read((char *)&uOffset, 4);
fChar.seekg(8 + 0x19 + i * 4, std::ios::beg);
fChar->getLE32(uOffset);

// Just add an empty line
if (uOffset == 0)
Expand All @@ -126,14 +149,15 @@ int main(int argc, char **argv)
// Read the values, and write them in the TXT file
else
{
fChar.seekg(8 + 0x15 + uOffset + 2);
int8 byLeft;
int8 byTop;
fChar.seekg(8 + 0x15 + uOffset + 2, std::ios::beg);
fChar.read((char *)&byLeft, 1);
fChar.read((char *)&byTop, 1);
fTxt << (int)byLeft << ";" << (int)byTop << "\n";
}
}
fTxt << std::flush;
fTxt.close();
fChar.close();
}
}
2 changes: 2 additions & 0 deletions src/ScummFont/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_executable (scummfont "scummfont.cpp")

target_link_libraries (scummfont PUBLIC scummiolib)

install(TARGETS scummfont RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
Loading