/** * @file RDIDebug.cpp * @date 12/01/2023 * @author JackCarterSmith * @copyright GPL-v3.0 * @brief Debug app to test functions of RDI library. * */ #include #include #include #include #ifdef _WIN32 #include #endif using namespace boost::filesystem; using namespace std; void PrintVirtualDirectoryContents( path, string, bool ); int main( int argc, char *argv[] ) { unsigned int i; path pathBuilder; string prefix; bool use_unicode = true; #ifdef _WIN32 SetConsoleOutputCP(CP_UTF8); #endif cout << "Using RDI lib v" << RDI::RDI_getLibVersion() << endl << endl; // Initialize RDI (Erso and Krennic module) with folder provided in program // argument, or the current directory by default if ( argc > 2 ) { use_unicode = atoi(argv[2]); RDI::RDI_Init(argv[1]); } else if (argc > 1) { RDI::RDI_Init(argv[1]); } else { RDI::RDI_Init("."); } // Print details about legacy DATA.DAT file cout << "> Section found: " << RDI::RDI_getSectionCount() << endl; for ( i = 0; i < RDI::RDI_getSectionCount(); i++ ) { cout << " -Section " << i << " name: " << RDI::RDI_getSectionName(i) << endl; cout << " -Section " << i << " offset: 0x" << hex << uppercase << RDI::RDI_getSectionOffset(i) << dec << endl; } // Print DATA.DAT tree view with unicode "style" cout << endl << "DATA.DAT files tree view:" << endl; for ( i = 0; i < RDI::RDI_getSectionCount(); i++ ) { cout << RDI::RDI_getSectionName(i) << ":" << endl; pathBuilder.clear(); pathBuilder.concat(RDI::RDI_getSectionName(i)); PrintVirtualDirectoryContents(pathBuilder, prefix, use_unicode); } // Print game elements Krennic module found cout << endl << "Legacy files processing result:"; cout << endl << "> Levels found: " << RDI::RDI_getLevelsName().size() << endl; for ( std::string lname : RDI::RDI_getLevelsName() ) { cout << " " << lname << endl; } cout << endl << "> Models found: " << RDI::RDI_getModelsName().size() << endl; for ( std::string mdname : RDI::RDI_getModelsName() ) { cout << " " << mdname << endl; } cout << endl << "> Textures found: " << RDI::RDI_getTexturesName().size() << endl; for ( std::string txname : RDI::RDI_getTexturesName() ) { cout << " " << txname << endl; } cout << endl << "> Musics found: " << RDI::RDI_getMusicsName().size() << endl; for ( std::string mname : RDI::RDI_getMusicsName() ) { cout << " " << mname << endl; } // Release RDI library RDI::RDI_CleanUp(); return 0; } void PrintVirtualDirectoryContents( path p, string outPrefix, bool unicode ) { auto curDirElementsName = RDI::RDI_getDirectoryElements(p.string()); auto newPath = path(p); auto newOutPrefix = string(outPrefix); for ( string eName : curDirElementsName ) { newPath.clear(); newPath.concat(p); newOutPrefix.clear(); newOutPrefix.append(outPrefix); newPath.append(eName); if (RDI::RDI_isElementDirectory(newPath.string())) { if (unicode) { cout << outPrefix << "\u251C " << eName << endl; newOutPrefix.append("\u2502 "); } else { cout << outPrefix << "\\ " << eName << endl; newOutPrefix.append("| "); } PrintVirtualDirectoryContents(newPath, newOutPrefix, unicode); } else { if (unicode) { if (*--curDirElementsName.end() == eName) cout << newOutPrefix << "\u2514 " << eName << endl; else cout << newOutPrefix << "\u251C " << eName << endl; } else { cout << newOutPrefix << "+ " << eName << endl; } } } }