diff --git a/.github/workflows/build_language.yml b/.github/workflows/build_language.yml index bea5a00a..f82f2754 100644 --- a/.github/workflows/build_language.yml +++ b/.github/workflows/build_language.yml @@ -41,6 +41,7 @@ jobs: shell: bash run: cat artifacts/versions.env >> $GITHUB_ENV + # TODO: Move this into CMake, just taking the GitHub Actions parameters as -D variables - name: Update GameVersion.cpp shell: bash run: | @@ -49,9 +50,9 @@ jobs: GAME_VERSION=$(echo "$GAME_VERSION" | tr -cd '[:print:]' | tr -d '"\\') GAME_BUILD="${INPUTS_LANGUAGE:0:2} $GAME_BUILD_INFORMATION" GAME_BUILD=$(echo "$GAME_BUILD" | tr -cd '[:print:]' | tr -d '"\\') - sed -i "s|@Version@|${GAME_VERSION:0:15}|" GameVersion.cpp - sed -i "s|@Build@|${GAME_BUILD:0:255}|" GameVersion.cpp - cat GameVersion.cpp + sed -i "s|@Version@|${GAME_VERSION:0:15}|" Ja2/GameVersion.cpp + sed -i "s|@Build@|${GAME_BUILD:0:255}|" Ja2/GameVersion.cpp + cat Ja2/GameVersion.cpp - name: Prepare build properties shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index b196f87e..e70ac481 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,8 +22,8 @@ set(usingMsBuild $) # TODO: build our own Lua 5.1.2 from source so we can use whichever set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") -add_compile_definitions(CINTERFACE XML_STATIC VFS_STATIC VFS_WITH_SLF VFS_WITH_7ZIP USE_VFS _CRT_SECURE_NO_DEPRECATE) -include_directories(${CMAKE_SOURCE_DIR} "ext/VFS/include" Utils TileEngine TacticalAI ModularizedTacticalAI Tactical Strategic "Standard Gaming Platform" Res Lua Laptop Multiplayer "Multiplayer/raknet" Editor Console) +add_compile_definitions(CINTERFACE XML_STATIC VFS_STATIC VFS_WITH_SLF VFS_WITH_7ZIP _CRT_SECURE_NO_DEPRECATE) +include_directories(Ja2 "ext/VFS/include" Utils TileEngine TacticalAI "ModularizedTacticalAI/include" Tactical Strategic sgp "Ja2/Res" Lua Laptop Multiplayer Editor Console) # external libraries add_subdirectory("ext/libpng") @@ -38,90 +38,28 @@ add_subdirectory("ext/export/src") # by header files do not rely on Applications or Languages preprocessor definitions, # and therefore only need to be compiled once. Good. add_subdirectory(Lua) +add_subdirectory(Multiplayer) # static libraries whose source files, header files or header files included # by header files rely on Application and Language preprocessor definitions, and # therefore need to be compiled multiple times. Very Bad. -add_subdirectory(TileEngine) -add_subdirectory(TacticalAI) -add_subdirectory(Utils) -add_subdirectory(Strategic) -add_subdirectory("Standard Gaming Platform") -add_subdirectory(Laptop) -add_subdirectory(Editor) -add_subdirectory(Console) -add_subdirectory(Tactical) -add_subdirectory(ModularizedTacticalAI) -# TODO: Rename 'Standard Gaming Platform' directory to 'SGP' so this can be refactored away set(Ja2_Libs TileEngine TacticalAI Utils Strategic -SGP +sgp Laptop Editor Console Tactical ModularizedTacticalAI ) +foreach(lib IN LISTS Ja2_Libs) + add_subdirectory(${lib}) +endforeach() -# TODO: Move these units into their own directory to declutter the root dir and CMakeLists.txt file -set(Ja2Src -"aniviewscreen.cpp" -"Credits.cpp" -"Fade Screen.cpp" -"FeaturesScreen.cpp" -"GameInitOptionsScreen.cpp" -"gameloop.cpp" -"gamescreen.cpp" -"GameSettings.cpp" -"GameVersion.cpp" -"HelpScreen.cpp" -"Init.cpp" -"Intro.cpp" -"JA2 Splash.cpp" -"Ja25Update.cpp" -"jascreens.cpp" -"Language Defines.cpp" -"Loading Screen.cpp" -"MainMenuScreen.cpp" -"MessageBoxScreen.cpp" -"MPChatScreen.cpp" -"MPConnectScreen.cpp" -"MPHostScreen.cpp" -"MPJoinScreen.cpp" -"MPScoreScreen.cpp" -"MPXmlTeams.cpp" -"Multiplayer/client.cpp" -"Multiplayer/server.cpp" -"Multiplayer/transfer_rules.cpp" -"Options Screen.cpp" -"profiler.cpp" -"SaveLoadGame.cpp" -"SaveLoadScreen.cpp" -"SCREENS.cpp" -"Sys Globals.cpp" -"ub_config.cpp" -"XML_DifficultySettings.cpp" -"XML_IntroFiles.cpp" -"XML_Layout_MainMenu.cpp" -Res/ja2.rc -) - -set(Ja2_Libraries -"${PROJECT_SOURCE_DIR}/libexpatMT.lib" -"Dbghelp.lib" -Lua -"${PROJECT_SOURCE_DIR}/lua51.lib" -"${PROJECT_SOURCE_DIR}/lua51.vc9.lib" -"Winmm.lib" -"${PROJECT_SOURCE_DIR}/SMACKW32.LIB" -"${PROJECT_SOURCE_DIR}/binkw32.lib" -bfVFS -"${PROJECT_SOURCE_DIR}/Multiplayer/raknet/RakNetLibStatic.lib" -"ws2_32.lib" -) +add_subdirectory(Ja2) # simple function to validate Languages and Application choices include(cmake/ValidateOptions.cmake) @@ -160,7 +98,7 @@ foreach(lang IN LISTS LangTargets) set(isUb $) set(isUbEditor $) - # static library for an app/lang combination, e.g. JA2_ENGLISH_SGP.lib + # static library for an app/lang combination, e.g. JA2_ENGLISH_sgp.lib add_library(${VeryBadLib}) target_sources(${VeryBadLib} PRIVATE ${${lib}Src}) @@ -174,9 +112,9 @@ foreach(lang IN LISTS LangTargets) target_link_libraries(${Executable} PUBLIC ${VeryBadLib}) endforeach() - # for SGP only - target_link_libraries(${Executable}_SGP PRIVATE "ddraw.lib" "${PROJECT_SOURCE_DIR}/fmodvc.lib") - target_link_libraries(${Executable}_SGP PUBLIC libpng) - target_compile_definitions(${Executable}_SGP PRIVATE NO_ZLIB_COMPRESSION) + # for sgp only + target_link_libraries(${Executable}_sgp PRIVATE "ddraw.lib" "${PROJECT_SOURCE_DIR}/fmodvc.lib") + target_link_libraries(${Executable}_sgp PUBLIC libpng) + target_compile_definitions(${Executable}_sgp PRIVATE NO_ZLIB_COMPRESSION) endforeach() endforeach() diff --git a/Editor/LoadScreen.cpp b/Editor/LoadScreen.cpp index 81a9e024..7c7d70b4 100644 --- a/Editor/LoadScreen.cpp +++ b/Editor/LoadScreen.cpp @@ -83,9 +83,7 @@ INT32 iCurrFileShown; INT32 iLastFileClicked; INT32 iLastClickTime; -#ifdef USE_VFS CHAR8 gzProfileName[FILENAME_BUFLEN];//dnl ch81 021213 -#endif CHAR16 gzFilename[FILENAME_BUFLEN];//dnl ch39 190909 extern INT16 gsSelSectorX; extern INT16 gsSelSectorY; @@ -165,7 +163,6 @@ void LoadSaveScreenEntry() } iTopFileShown = iTotalFiles = 0; -#ifdef USE_VFS//dnl ch37 300909 gzProfileName[0] = 0;//dnl ch81 021213 FDLG_LIST* TempFileList = NULL; vfs::CProfileStack* st = getVFS()->getProfileStack(); @@ -220,25 +217,6 @@ void LoadSaveScreenEntry() } while(FileList->pPrev) FileList = FileList->pPrev; -#else - if(GetFileFirst("MAPS\\*.dat", &FileInfo)) - { - if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) - { - FileList = AddToFDlgList(FileList, &FileInfo); - iTotalFiles++; - } - while(GetFileNext(&FileInfo)) - { - if(strlen(FileInfo.zFileName) < FILENAME_BUFLEN) - { - FileList = AddToFDlgList(FileList, &FileInfo); - iTotalFiles++; - } - } - GetFileClose(&FileInfo); - } -#endif swprintf( zOrigName, L"%s Map (*.dat)", iCurrentAction == ACTION_SAVE_MAP ? L"Save" : L"Load" ); swprintf( gzFilename, L"%S", gubFilename ); @@ -283,7 +261,8 @@ UINT32 ProcessLoadSaveScreenMessageBoxResult() { if( gfReadOnly ) { - FileClearAttributes( gszCurrFilename ); + // Other call sites have replaced this with FileDelete(); for VFS, should we do the same here? + //FileClearAttributes( gszCurrFilename ); gfReadOnly = FALSE; } FileDelete( gszCurrFilename ); @@ -468,19 +447,6 @@ UINT32 LoadSaveScreenHandle(void) } sprintf(gszCurrFilename, "MAPS\\%S", gzFilename); gfFileExists = FALSE; -#ifndef USE_VFS - gfReadOnly = FALSE; - if(FileExists(gszCurrFilename)) - { - gfFileExists = TRUE; - if(GetFileFirst(gszCurrFilename, &FileInfo)) - { - if(FileInfo.uiFileAttribs & (FILE_IS_READONLY|FILE_IS_DIRECTORY|FILE_IS_HIDDEN|FILE_IS_SYSTEM|FILE_IS_OFFLINE|FILE_IS_TEMPORARY)) - gfReadOnly = TRUE; - GetFileClose(&FileInfo); - } - } -#else gfReadOnly = TRUE; vfs::CProfileStack* st = getVFS()->getProfileStack(); vfs::CProfileStack::Iterator it = st->begin(); @@ -502,7 +468,6 @@ UINT32 LoadSaveScreenHandle(void) } it.next(); } -#endif if(gfReadOnly) { CreateMessageBox(L" File is read only! Choose a different name? "); @@ -726,7 +691,6 @@ void SelectFileDialogYPos( UINT16 usRelativeYPos ) iLastClickTime = iCurrClickTime; iLastFileClicked = x; //dnl ch81 021213 -#ifdef USE_VFS gzProfileName[0] = 0; while(FListNode = FListNode->pPrev) { @@ -737,7 +701,6 @@ void SelectFileDialogYPos( UINT16 usRelativeYPos ) break; } } -#endif break; } FListNode = FListNode->pNext; @@ -950,7 +913,6 @@ void HandleMainKeyEvents( InputAtom *pEvent ) SetInputFieldStringWith16BitString(0, L""); wcscpy(gzFilename, L""); } -#ifdef USE_VFS gzProfileName[0] = 0; while(curr = curr->pPrev) { @@ -961,7 +923,6 @@ void HandleMainKeyEvents( InputAtom *pEvent ) break; } } -#endif } } } diff --git a/Editor/LoadScreen.h b/Editor/LoadScreen.h index 07b08c74..c8adac4c 100644 --- a/Editor/LoadScreen.h +++ b/Editor/LoadScreen.h @@ -51,9 +51,7 @@ extern CHAR16 gzErrorCatchString[ 256 ]; //dnl ch81 031213 extern CHAR16 gzFilename[FILENAME_BUFLEN]; -#ifdef USE_VFS extern CHAR8 gzProfileName[FILENAME_BUFLEN]; -#endif #endif #endif diff --git a/Editor/Sector Summary.cpp b/Editor/Sector Summary.cpp index aa486552..9c328cfa 100644 --- a/Editor/Sector Summary.cpp +++ b/Editor/Sector Summary.cpp @@ -1923,40 +1923,14 @@ BOOLEAN HandleSummaryInput( InputAtom *pEvent ) void CreateGlobalSummary() { -#ifndef USE_VFS - FILE *fp; - STRING512 Dir; - STRING512 ExecDir; -#endif OutputDebugString( "Generating GlobalSummary Information...\n" ); gfGlobalSummaryExists = FALSE; //Set current directory to JA2\DevInfo which contains all of the summary data -#ifndef USE_VFS - GetExecutableDirectory( ExecDir ); - sprintf( Dir, "%s\\DevInfo", ExecDir ); - - // Snap: save current directory - //GetFileManCurrentDirectory( DataDir ); - - //Directory doesn't exist, so create it, and continue. - if( !MakeFileManDirectory( Dir ) ) - AssertMsg( 0, "Can't create new directory, JA2\\DevInfo for summary information." ); - if( !SetFileManCurrentDirectory( Dir ) ) - AssertMsg( 0, "Can't set to new directory, JA2\\DevInfo for summary information." ); - - //Generate a simple readme file. - fp = fopen( "readme.txt", "w" ); - Assert( fp ); - fprintf( fp, "%s\n%s\n", "This information is used in conjunction with the editor.", - "This directory or it's contents shouldn't be included with final release." ); - fclose( fp ); -#else vfs::COpenWriteFile wfile(L"DevInfo\\readme.txt",true,true); std::string str = "This information is used in conjunction with the editor.\n"; str += "This directory or it's contents shouldn't be included with final release.\n"; SGP_TRYCATCH_RETHROW( wfile->write(str.c_str(), str.length()), L"" ); -#endif // Snap: Restore the data directory once we are finished. //SetFileManCurrentDirectory( DataDir ); @@ -2203,7 +2177,8 @@ void SummarySaveMapCallback( GUI_BUTTON *btn, INT32 reason ) { CHAR8 filename[40]; sprintf( filename, "MAPS\\%S", gszDisplayName ); - FileClearAttributes( filename ); + // Other call sites have replaced this with FileDelete(); for VFS, should we do the same here? + //FileClearAttributes( filename ); } if( ExternalSaveMap( gszDisplayName ) ) { @@ -2281,12 +2256,6 @@ void CalculateOverrideStatus() void LoadGlobalSummary() { HWFILE hfile; -#ifndef USE_VFS - STRING512 DataDir; - STRING512 ExecDir; - STRING512 DevInfoDir; - STRING512 MapsDir; -#endif UINT32 uiNumBytesRead; FLOAT dMajorVersion; INT32 x,y; @@ -2295,34 +2264,16 @@ void LoadGlobalSummary() OutputDebugString( "Executing LoadGlobalSummary()...\n" ); // Snap: save current directory -#ifndef USE_VFS - GetFileManCurrentDirectory( DataDir ); -#endif gfMustForceUpdateAllMaps = FALSE; gusNumberOfMapsToBeForceUpdated = 0; gfGlobalSummaryExists = FALSE; //Set current directory to JA2\DevInfo which contains all of the summary data -#ifndef USE_VFS - GetExecutableDirectory( ExecDir ); - sprintf( DevInfoDir, "%s\\DevInfo", ExecDir ); - sprintf( MapsDir, "%s\\Maps", DataDir ); - //Check to make sure we have a DevInfo directory. If we don't create one! - if( !SetFileManCurrentDirectory( DevInfoDir ) ) - { - OutputDebugString( "LoadGlobalSummary() aborted -- doesn't exist on this local computer.\n"); - return; - } -#endif //TEMP -#ifndef USE_VFS - FileDelete( "_global.sum" ); -#else if(FileExists("DevInfo\\_global.sum")) { FileDelete( "DevInfo\\_global.sum" ); } -#endif gfGlobalSummaryExists = TRUE; //Analyse all sectors to see if matching maps exist. For any maps found, the information @@ -2337,19 +2288,12 @@ void LoadGlobalSummary() sprintf( szSector, "%c%d", 'A' + y, x + 1 ); //main ground level -#ifndef USE_VFS - sprintf( szFilename, "%c%d.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= GROUND_LEVEL_MASK; @@ -2359,27 +2303,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s.sum", szSector ); -#endif FileDelete( szFilename ); } //main B1 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b1.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b1.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= BASEMENT1_LEVEL_MASK; @@ -2389,27 +2322,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b1.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b1.sum", szSector ); -#endif FileDelete( szFilename ); } //main B2 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b2.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b2.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= BASEMENT2_LEVEL_MASK; @@ -2419,27 +2341,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b2.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b2.sum", szSector ); -#endif FileDelete( szFilename ); } //main B3 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b3.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b3.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= BASEMENT3_LEVEL_MASK; @@ -2449,27 +2360,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b3.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b3.sum", szSector ); -#endif FileDelete( szFilename ); } //alternate ground level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_a.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_a.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= ALTERNATE_GROUND_MASK; @@ -2479,27 +2379,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_a.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_a.sum", szSector ); -#endif FileDelete( szFilename ); } //alternate B1 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b1_a.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b1_a.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= ALTERNATE_B1_MASK; @@ -2509,27 +2398,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b1_a.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b1_a.sum", szSector ); -#endif FileDelete( szFilename ); } //alternate B2 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b2_a.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b2_a.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= ALTERNATE_B2_MASK; @@ -2539,27 +2417,16 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b2_a.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b2_a.sum", szSector ); -#endif FileDelete( szFilename ); } //alternate B3 level -#ifndef USE_VFS - sprintf( szFilename, "%c%d_b3_a.dat", 'A' + y, x + 1 ); - SetFileManCurrentDirectory( MapsDir ); - hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - SetFileManCurrentDirectory( DevInfoDir ); -#else sprintf( szFilename, "Maps\\%c%d_b3_a.dat", 'A' + y, x + 1 ); hfile = NULL; if(FileExists(szFilename)) { hfile = FileOpen( szFilename, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); } -#endif if( hfile ) { gbSectorLevels[x][y] |= ALTERNATE_B1_MASK;; @@ -2569,20 +2436,12 @@ void LoadGlobalSummary() } else { -#ifndef USE_VFS - sprintf( szFilename, "%s_b3_a.sum", szSector ); -#else sprintf( szFilename, "DevInfo\\%s_b3_a.sum", szSector ); -#endif FileDelete( szFilename ); } } OutputDebugString( (LPCSTR)String("Sector Row %c complete... \n", y + 'A') ); } -#ifndef USE_VFS - // Snap: Restore the data directory once we are finished. - SetFileManCurrentDirectory( DataDir ); -#endif //sprintf( MapsDir, "%s\\Data", ExecDir ); //SetFileManCurrentDirectory( MapsDir ); @@ -2599,39 +2458,6 @@ void LoadGlobalSummary() void GenerateSummaryList() { -#ifndef USE_VFS - FILE *fp; - STRING512 DataDir; - STRING512 ExecDir; - STRING512 Dir; - - // Snap: save current directory - GetFileManCurrentDirectory( DataDir ); - - //Set current directory to JA2\DevInfo which contains all of the summary data - GetExecutableDirectory( ExecDir ); - sprintf( Dir, "%s\\DevInfo", ExecDir ); - if( !SetFileManCurrentDirectory( Dir ) ) - { - //Directory doesn't exist, so create it, and continue. - if( !MakeFileManDirectory( Dir ) ) - AssertMsg( 0, "Can't create new directory, JA2\\DevInfo for summary information." ); - if( !SetFileManCurrentDirectory( Dir ) ) - AssertMsg( 0, "Can't set to new directory, JA2\\DevInfo for summary information." ); - //Generate a simple readme file. - fp = fopen( "readme.txt", "w" ); - Assert( fp ); - fprintf( fp, "%s\n%s\n", "This information is used in conjunction with the editor.", - "This directory or it's contents shouldn't be included with final release." ); - fclose( fp ); - } - - // Snap: Restore the data directory once we are finished. - SetFileManCurrentDirectory( DataDir ); - //Set current directory back to data directory! - //sprintf( Dir, "%s\\Data", ExecDir ); - //SetFileManCurrentDirectory( Dir ); -#else try { vfs::COpenWriteFile wfile(L"DevInfo/readme.txt",true,true); @@ -2643,7 +2469,6 @@ void GenerateSummaryList() { SGP_RETHROW(L"Could not create readme.txt", ex); } -#endif } //dnl ch28 260909 diff --git a/JA2 Demo Ads.h b/JA2 Demo Ads.h deleted file mode 100644 index 2d5d97c7..00000000 --- a/JA2 Demo Ads.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _JA2_DEMO_ADS_H -#define _JA2_DEMO_ADS_H - -#include "types.h" - -#endif \ No newline at end of file diff --git a/JA2Prototypes.h b/JA2Prototypes.h deleted file mode 100644 index bb7e6d8c..00000000 --- a/JA2Prototypes.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _JA2PROTOTYPES_H -#define _JA2PROTOTYPES_H - -/* - * This header does not define any structures. It simply provides a way for all code that only needs a pointer - * reference to structures, to have it without getting locked into mutual includes and other - * hard-to-trace-and-fix behavior. More class and struct defs can be added as necessary. - */ - -class SOLDIERTYPE; -struct AnimationSurfaceType; - -#endif diff --git a/Ja2/CMakeLists.txt b/Ja2/CMakeLists.txt new file mode 100644 index 00000000..aeafd680 --- /dev/null +++ b/Ja2/CMakeLists.txt @@ -0,0 +1,52 @@ +set(Ja2Src +"${CMAKE_CURRENT_SOURCE_DIR}/aniviewscreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Credits.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Fade Screen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/FeaturesScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/GameInitOptionsScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/gameloop.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/gamescreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/GameSettings.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/GameVersion.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/HelpScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Init.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Intro.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/JA2 Splash.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Ja25Update.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/jascreens.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Language Defines.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Loading Screen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MainMenuScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MessageBoxScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPChatScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPConnectScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPHostScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPJoinScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPScoreScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/MPXmlTeams.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Options Screen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/profiler.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/SaveLoadGame.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/SaveLoadScreen.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/SCREENS.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/Sys Globals.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/ub_config.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/XML_DifficultySettings.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/XML_IntroFiles.cpp" +"${CMAKE_CURRENT_SOURCE_DIR}/XML_Layout_MainMenu.cpp" +${CMAKE_CURRENT_SOURCE_DIR}/Res/ja2.rc +PARENT_SCOPE) + +set(Ja2_Libraries +"${CMAKE_SOURCE_DIR}/libexpatMT.lib" +"Dbghelp.lib" +Lua +"${CMAKE_SOURCE_DIR}/lua51.lib" +"${CMAKE_SOURCE_DIR}/lua51.vc9.lib" +"Winmm.lib" +"${CMAKE_SOURCE_DIR}/SMACKW32.LIB" +"${CMAKE_SOURCE_DIR}/binkw32.lib" +bfVFS +"ws2_32.lib" +Multiplayer +PARENT_SCOPE) diff --git a/Cheats.h b/Ja2/Cheats.h similarity index 100% rename from Cheats.h rename to Ja2/Cheats.h diff --git a/Credits.cpp b/Ja2/Credits.cpp similarity index 100% rename from Credits.cpp rename to Ja2/Credits.cpp diff --git a/Credits.h b/Ja2/Credits.h similarity index 100% rename from Credits.h rename to Ja2/Credits.h diff --git a/Fade Screen.cpp b/Ja2/Fade Screen.cpp similarity index 100% rename from Fade Screen.cpp rename to Ja2/Fade Screen.cpp diff --git a/Fade Screen.h b/Ja2/Fade Screen.h similarity index 100% rename from Fade Screen.h rename to Ja2/Fade Screen.h diff --git a/FeaturesScreen.cpp b/Ja2/FeaturesScreen.cpp similarity index 100% rename from FeaturesScreen.cpp rename to Ja2/FeaturesScreen.cpp diff --git a/FeaturesScreen.h b/Ja2/FeaturesScreen.h similarity index 100% rename from FeaturesScreen.h rename to Ja2/FeaturesScreen.h diff --git a/GameInitOptionsScreen.cpp b/Ja2/GameInitOptionsScreen.cpp similarity index 100% rename from GameInitOptionsScreen.cpp rename to Ja2/GameInitOptionsScreen.cpp diff --git a/GameInitOptionsScreen.h b/Ja2/GameInitOptionsScreen.h similarity index 100% rename from GameInitOptionsScreen.h rename to Ja2/GameInitOptionsScreen.h diff --git a/GameSettings.cpp b/Ja2/GameSettings.cpp similarity index 98% rename from GameSettings.cpp rename to Ja2/GameSettings.cpp index e8170449..00802dcb 100644 --- a/GameSettings.cpp +++ b/Ja2/GameSettings.cpp @@ -1185,6 +1185,12 @@ void LoadGameExternalOptions() // Flugente: additional decals on objects (cracked walls, blood spatters etc.) gGameExternalOptions.fAdditionalDecals = iniReader.ReadBoolean( "Graphics Settings", "ADDITIONAL_DECALS", FALSE ); + // anv: map color variants + gGameExternalOptions.ubRadarMapModeDay = iniReader.ReadInteger("Graphics Settings", "RADAR_MAP_MODE_DAY", 0, 0, 2); + gGameExternalOptions.ubRadarMapModeNight = iniReader.ReadInteger("Graphics Settings", "RADAR_MAP_MODE_NIGHT", 3, 0, 3); + gGameExternalOptions.ubOverheadMapModeDay = iniReader.ReadInteger("Graphics Settings", "OVERHEAD_MAP_MODE_DAY", 0, 0, 2); + gGameExternalOptions.ubOverheadMapModeNight = iniReader.ReadInteger("Graphics Settings", "OVERHEAD_MAP_MODE_NIGHT", 0, 0, 3); + //################# Sound Settings ################# gGameExternalOptions.guiWeaponSoundEffectsVolume = iniReader.ReadInteger("Sound Settings","WEAPON_SOUND_EFFECTS_VOLUME", 0, 0, 1000 /*1000 = 10x?*/); diff --git a/GameSettings.h b/Ja2/GameSettings.h similarity index 97% rename from GameSettings.h rename to Ja2/GameSettings.h index 33c87d16..b5df2be5 100644 --- a/GameSettings.h +++ b/Ja2/GameSettings.h @@ -952,6 +952,12 @@ typedef struct BOOLEAN fAdditionalDecals; // Flugente: show additional decals on objects (cracked walls, blood spatters etc.) + // anv: map color variants + UINT8 ubRadarMapModeDay; + UINT8 ubRadarMapModeNight; + UINT8 ubOverheadMapModeDay; + UINT8 ubOverheadMapModeNight; + //enable ext mouse key BOOLEAN bAltAimEnabled; BOOLEAN bAimedBurstEnabled; diff --git a/GameVersion.cpp b/Ja2/GameVersion.cpp similarity index 100% rename from GameVersion.cpp rename to Ja2/GameVersion.cpp diff --git a/GameVersion.h b/Ja2/GameVersion.h similarity index 100% rename from GameVersion.h rename to Ja2/GameVersion.h diff --git a/HelpScreen.cpp b/Ja2/HelpScreen.cpp similarity index 100% rename from HelpScreen.cpp rename to Ja2/HelpScreen.cpp diff --git a/HelpScreen.h b/Ja2/HelpScreen.h similarity index 100% rename from HelpScreen.h rename to Ja2/HelpScreen.h diff --git a/HelpScreenText.h b/Ja2/HelpScreenText.h similarity index 100% rename from HelpScreenText.h rename to Ja2/HelpScreenText.h diff --git a/Init.cpp b/Ja2/Init.cpp similarity index 96% rename from Init.cpp rename to Ja2/Init.cpp index 20788424..605a13a7 100644 --- a/Init.cpp +++ b/Ja2/Init.cpp @@ -1514,12 +1514,6 @@ UINT32 InitializeJA2(void) // INit intensity tables BuildIntensityTable( ); - // Init Event Manager - if ( !InitializeEventManager( ) ) - { - return( ERROR_SCREEN ); - } - // Initailize World if ( !InitializeWorld( ) ) { @@ -1698,8 +1692,6 @@ void ShutdownJA2(void) ShutdownJA2Sound( ); - ShutdownEventManager( ); - ShutdownBaseDirtyRectQueue( ); // Unload any text box images! diff --git a/Init.h b/Ja2/Init.h similarity index 100% rename from Init.h rename to Ja2/Init.h diff --git a/Intro.cpp b/Ja2/Intro.cpp similarity index 100% rename from Intro.cpp rename to Ja2/Intro.cpp diff --git a/Intro.h b/Ja2/Intro.h similarity index 100% rename from Intro.h rename to Ja2/Intro.h diff --git a/JA2 Splash.cpp b/Ja2/JA2 Splash.cpp similarity index 100% rename from JA2 Splash.cpp rename to Ja2/JA2 Splash.cpp diff --git a/JA2 Splash.h b/Ja2/JA2 Splash.h similarity index 100% rename from JA2 Splash.h rename to Ja2/JA2 Splash.h diff --git a/Ja25Update.cpp b/Ja2/Ja25Update.cpp similarity index 94% rename from Ja25Update.cpp rename to Ja2/Ja25Update.cpp index 101b1152..4fd737e1 100644 --- a/Ja25Update.cpp +++ b/Ja2/Ja25Update.cpp @@ -11,7 +11,6 @@ #include "Animation Cache.h" #include "Animation Data.h" #include "Animation Control.h" -#include "container.h" #include #include "pathai.h" #include "Random.h" diff --git a/Ja25Update.h b/Ja2/Ja25Update.h similarity index 100% rename from Ja25Update.h rename to Ja2/Ja25Update.h diff --git a/Language Defines.cpp b/Ja2/Language Defines.cpp similarity index 100% rename from Language Defines.cpp rename to Ja2/Language Defines.cpp diff --git a/Language Defines.h b/Ja2/Language Defines.h similarity index 100% rename from Language Defines.h rename to Ja2/Language Defines.h diff --git a/Loading Screen.cpp b/Ja2/Loading Screen.cpp similarity index 100% rename from Loading Screen.cpp rename to Ja2/Loading Screen.cpp diff --git a/Loading Screen.h b/Ja2/Loading Screen.h similarity index 100% rename from Loading Screen.h rename to Ja2/Loading Screen.h diff --git a/MPChatScreen.cpp b/Ja2/MPChatScreen.cpp similarity index 100% rename from MPChatScreen.cpp rename to Ja2/MPChatScreen.cpp diff --git a/MPChatScreen.h b/Ja2/MPChatScreen.h similarity index 100% rename from MPChatScreen.h rename to Ja2/MPChatScreen.h diff --git a/MPConnectScreen.cpp b/Ja2/MPConnectScreen.cpp similarity index 100% rename from MPConnectScreen.cpp rename to Ja2/MPConnectScreen.cpp diff --git a/MPConnectScreen.h b/Ja2/MPConnectScreen.h similarity index 100% rename from MPConnectScreen.h rename to Ja2/MPConnectScreen.h diff --git a/MPHostScreen.cpp b/Ja2/MPHostScreen.cpp similarity index 100% rename from MPHostScreen.cpp rename to Ja2/MPHostScreen.cpp diff --git a/MPHostScreen.h b/Ja2/MPHostScreen.h similarity index 100% rename from MPHostScreen.h rename to Ja2/MPHostScreen.h diff --git a/MPJoinScreen.cpp b/Ja2/MPJoinScreen.cpp similarity index 100% rename from MPJoinScreen.cpp rename to Ja2/MPJoinScreen.cpp diff --git a/MPJoinScreen.h b/Ja2/MPJoinScreen.h similarity index 100% rename from MPJoinScreen.h rename to Ja2/MPJoinScreen.h diff --git a/MPScoreScreen.cpp b/Ja2/MPScoreScreen.cpp similarity index 100% rename from MPScoreScreen.cpp rename to Ja2/MPScoreScreen.cpp diff --git a/MPScoreScreen.h b/Ja2/MPScoreScreen.h similarity index 100% rename from MPScoreScreen.h rename to Ja2/MPScoreScreen.h diff --git a/MPXmlTeams.cpp b/Ja2/MPXmlTeams.cpp similarity index 100% rename from MPXmlTeams.cpp rename to Ja2/MPXmlTeams.cpp diff --git a/MPXmlTeams.hpp b/Ja2/MPXmlTeams.hpp similarity index 100% rename from MPXmlTeams.hpp rename to Ja2/MPXmlTeams.hpp diff --git a/MainMenuScreen.cpp b/Ja2/MainMenuScreen.cpp similarity index 96% rename from MainMenuScreen.cpp rename to Ja2/MainMenuScreen.cpp index bebe6193..22d2a266 100644 --- a/MainMenuScreen.cpp +++ b/Ja2/MainMenuScreen.cpp @@ -248,7 +248,6 @@ BOOLEAN InitMainMenu( ) { is_networked = FALSE; -#ifdef USE_VFS // remove Multiplayer profile if it exists vfs::CProfileStack *PS = getVFS()->getProfileStack(); vfs::CVirtualProfile *pProf = PS->getProfile("_MULTIPLAYER"); @@ -256,7 +255,6 @@ BOOLEAN InitMainMenu( ) { SGP_THROW_IFFALSE(PS->popProfile(), "Leaving Multiplayer mode : Could not remove \"_MULTIPLAYER\" profile"); } -#endif // Snap: UN-Init MP save game directory if ( !InitSaveDir() ) diff --git a/MessageBoxScreen.cpp b/Ja2/MessageBoxScreen.cpp similarity index 100% rename from MessageBoxScreen.cpp rename to Ja2/MessageBoxScreen.cpp diff --git a/MessageBoxScreen.h b/Ja2/MessageBoxScreen.h similarity index 100% rename from MessageBoxScreen.h rename to Ja2/MessageBoxScreen.h diff --git a/Options Screen.cpp b/Ja2/Options Screen.cpp similarity index 100% rename from Options Screen.cpp rename to Ja2/Options Screen.cpp diff --git a/Options Screen.h b/Ja2/Options Screen.h similarity index 100% rename from Options Screen.h rename to Ja2/Options Screen.h diff --git a/Res/ja2.aps b/Ja2/Res/ja2.aps similarity index 100% rename from Res/ja2.aps rename to Ja2/Res/ja2.aps diff --git a/Res/ja2.rc b/Ja2/Res/ja2.rc similarity index 100% rename from Res/ja2.rc rename to Ja2/Res/ja2.rc diff --git a/Res/jagged3.ico b/Ja2/Res/jagged3.ico similarity index 100% rename from Res/jagged3.ico rename to Ja2/Res/jagged3.ico diff --git a/Res/resource.h b/Ja2/Res/resource.h similarity index 100% rename from Res/resource.h rename to Ja2/Res/resource.h diff --git a/SaveLoadGame.cpp b/Ja2/SaveLoadGame.cpp similarity index 96% rename from SaveLoadGame.cpp rename to Ja2/SaveLoadGame.cpp index 3d90f27e..7d8cc015 100644 --- a/SaveLoadGame.cpp +++ b/Ja2/SaveLoadGame.cpp @@ -3553,33 +3553,6 @@ BOOLEAN Inventory::Save( HWFILE hFile, bool fSavingMap ) // The save directory now resides in the data directory (default or custom) BOOLEAN InitSaveDir() { -#ifndef USE_VFS - // Look for a custom data dir first - std::string dataDir = gCustomDataCat.GetRootDir(); - if( dataDir.empty() || FileGetAttributes( (STR) dataDir.c_str() ) == 0xFFFFFFFF ) { - dataDir = gDefaultDataCat.GetRootDir(); - } - - // The locale-specific save dir location is of the form L"..\\SavedGames" - // This has not changed; instead, we strip the ".." at the beginning - if(is_networked) - { - sprintf( gSaveDir, "%s%S", dataDir.c_str(), pMessageStrings[ MSG_MPSAVEDIRECTORY ] + 2 ); - } - else - sprintf( gSaveDir, "%s%S", dataDir.c_str(), pMessageStrings[ MSG_SAVEDIRECTORY ] + 2 ); - - // This was moved here from SaveGame - //Check to see if the save directory exists - if( FileGetAttributes( (STR) gSaveDir ) == 0xFFFFFFFF ) - { - //ok the direcotry doesnt exist, create it - if( !MakeFileManDirectory( (CHAR8 *)gSaveDir ) ) - { - return FALSE; - } - } -#else if(is_networked) { sprintf( gSaveDir, "%s", vfs::String::as_utf8(pMessageStrings[ MSG_MPSAVEDIRECTORY ] + 3).c_str() ); @@ -3588,7 +3561,6 @@ BOOLEAN InitSaveDir() { sprintf( gSaveDir, "%s", vfs::String::as_utf8(pMessageStrings[ MSG_SAVEDIRECTORY ] + 3).c_str() ); } -#endif return TRUE; } @@ -9711,21 +9683,6 @@ BOOLEAN SaveMeanwhileDefsFromSaveGameFile( HWFILE hFile ) return( TRUE ); } -BOOLEAN DoesUserHaveEnoughHardDriveSpace() -{ - UINT32 uiBytesFree=0; - - uiBytesFree = GetFreeSpaceOnHardDriveWhereGameIsRunningFrom( ); - - //check to see if there is enough hard drive space - if( uiBytesFree < REQUIRED_FREE_SPACE ) - { - return( FALSE ); - } - - return( TRUE ); -} - #ifdef JA2BETAVERSION void InitShutDownMapTempFileTest( BOOLEAN fInit, STR pNameOfFile, UINT8 ubSaveGameID ) @@ -9989,69 +9946,6 @@ void UpdateMercMercContractInfo() } } -INT8 GetNumberForAutoSave( BOOLEAN fLatestAutoSave ) -{ - CHAR zFileName1[MAX_PATH]; - CHAR zFileName2[MAX_PATH]; - HWFILE hFile; - BOOLEAN fFile1Exist, fFile2Exist; - SGP_FILETIME CreationTime1, LastAccessedTime1, LastWriteTime1; - SGP_FILETIME CreationTime2, LastAccessedTime2, LastWriteTime2; - - fFile1Exist = FALSE; - fFile2Exist = FALSE; - - - //The name of the file - sprintf( zFileName1, "%s\\Auto%02d.%S", gSaveDir, 0, pMessageStrings[ MSG_SAVEEXTENSION ] ); - sprintf( zFileName2, "%s\\Auto%02d.%S", gSaveDir, 1, pMessageStrings[ MSG_SAVEEXTENSION ] ); - - if( FileExists( zFileName1 ) ) - { - hFile = FileOpen( zFileName1, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - - GetFileManFileTime( hFile, &CreationTime1, &LastAccessedTime1, &LastWriteTime1 ); - - FileClose( hFile ); - - fFile1Exist = TRUE; - } - - if( FileExists( zFileName2 ) ) - { - hFile = FileOpen( zFileName2, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE ); - - GetFileManFileTime( hFile, &CreationTime2, &LastAccessedTime2, &LastWriteTime2 ); - - FileClose( hFile ); - - fFile2Exist = TRUE; - } - - if( !fFile1Exist && !fFile2Exist ) - return( -1 ); - else if( fFile1Exist && !fFile2Exist ) - { - if( fLatestAutoSave ) - return( 0 ); - else - return( -1 ); - } - else if( !fFile1Exist && fFile2Exist ) - { - if( fLatestAutoSave ) - return( 1 ); - else - return( -1 ); - } - else - { - if( CompareSGPFileTimes( &LastWriteTime1, &LastWriteTime2 ) > 0 ) - return( 0 ); - else - return( 1 ); - } -} void HandleOldBobbyRMailOrders() { diff --git a/SaveLoadGame.h b/Ja2/SaveLoadGame.h similarity index 94% rename from SaveLoadGame.h rename to Ja2/SaveLoadGame.h index a1f9664a..3cc011f6 100644 --- a/SaveLoadGame.h +++ b/Ja2/SaveLoadGame.h @@ -93,13 +93,10 @@ BOOLEAN CopySavedSoldierInfoToNewSoldier( SOLDIERTYPE *pDestSourceInfo, SOLDIERT BOOLEAN SaveFilesToSavedGame( STR pSrcFileName, HWFILE hFile ); BOOLEAN LoadFilesFromSavedGame( STR pSrcFileName, HWFILE hFile ); -BOOLEAN DoesUserHaveEnoughHardDriveSpace(); - void GetBestPossibleSectorXYZValues( INT16 *psSectorX, INT16 *psSectorY, INT8 *pbSectorZ ); extern UINT32 guiLastSaveGameNum; // The end turn auto save number (0 = Auto00.sav, 1 = Auto01.sav) -INT8 GetNumberForAutoSave( BOOLEAN fLatestAutoSave ); /*CHRISL: This function is designed to allow reading the save game file one field at a time. We currently save structures by saving a block of memory, but variables are stored in memory so that they fit neatly into a WORD resulting in the program automatically adding some padding. This padding is saved diff --git a/SaveLoadScreen.cpp b/Ja2/SaveLoadScreen.cpp similarity index 96% rename from SaveLoadScreen.cpp rename to Ja2/SaveLoadScreen.cpp index 5fe319ff..e5442659 100644 --- a/SaveLoadScreen.cpp +++ b/Ja2/SaveLoadScreen.cpp @@ -1350,7 +1350,6 @@ BOOLEAN InitSaveGameArray() gbSaveGameArray[VAL_SLOT_START + cnt] = TRUE; // anv: read last modified date property of save file -#ifdef USE_VFS // get full path to save file vfs::Path vfsPath; vfs::COpenReadFile rfile(zSaveGameName); @@ -1369,7 +1368,6 @@ BOOLEAN InitSaveGameArray() // close CloseHandle( hFile ); rfile->close(); -#endif } } else diff --git a/SaveLoadScreen.h b/Ja2/SaveLoadScreen.h similarity index 100% rename from SaveLoadScreen.h rename to Ja2/SaveLoadScreen.h diff --git a/Screens.cpp b/Ja2/Screens.cpp similarity index 100% rename from Screens.cpp rename to Ja2/Screens.cpp diff --git a/Screens.h b/Ja2/Screens.h similarity index 100% rename from Screens.h rename to Ja2/Screens.h diff --git a/Sys Globals.cpp b/Ja2/Sys Globals.cpp similarity index 100% rename from Sys Globals.cpp rename to Ja2/Sys Globals.cpp diff --git a/Sys Globals.h b/Ja2/Sys Globals.h similarity index 100% rename from Sys Globals.h rename to Ja2/Sys Globals.h diff --git a/VtuneApi.h b/Ja2/VtuneApi.h similarity index 100% rename from VtuneApi.h rename to Ja2/VtuneApi.h diff --git a/XML_DifficultySettings.cpp b/Ja2/XML_DifficultySettings.cpp similarity index 100% rename from XML_DifficultySettings.cpp rename to Ja2/XML_DifficultySettings.cpp diff --git a/XML_IntroFiles.cpp b/Ja2/XML_IntroFiles.cpp similarity index 100% rename from XML_IntroFiles.cpp rename to Ja2/XML_IntroFiles.cpp diff --git a/XML_Layout_MainMenu.cpp b/Ja2/XML_Layout_MainMenu.cpp similarity index 100% rename from XML_Layout_MainMenu.cpp rename to Ja2/XML_Layout_MainMenu.cpp diff --git a/aniviewscreen.cpp b/Ja2/aniviewscreen.cpp similarity index 95% rename from aniviewscreen.cpp rename to Ja2/aniviewscreen.cpp index 8f05104d..638e67a2 100644 --- a/aniviewscreen.cpp +++ b/Ja2/aniviewscreen.cpp @@ -11,7 +11,6 @@ #include "input.h" #include "font.h" #include "screenids.h" - #include "container.h" #include "overhead.h" #include "sysutil.h" #include "Font Control.h" diff --git a/builddefines.h b/Ja2/builddefines.h similarity index 100% rename from builddefines.h rename to Ja2/builddefines.h diff --git a/gameloop.cpp b/Ja2/gameloop.cpp similarity index 100% rename from gameloop.cpp rename to Ja2/gameloop.cpp diff --git a/gameloop.h b/Ja2/gameloop.h similarity index 100% rename from gameloop.h rename to Ja2/gameloop.h diff --git a/gamescreen.cpp b/Ja2/gamescreen.cpp similarity index 95% rename from gamescreen.cpp rename to Ja2/gamescreen.cpp index 67e70d99..28fd812d 100644 --- a/gamescreen.cpp +++ b/Ja2/gamescreen.cpp @@ -166,6 +166,7 @@ UINT32 MainGameScreenInit(void) UnLockVideoSurface( FRAME_BUFFER); InitializeBackgroundRects(); + InitializeBaseDirtyRectQueue(); //EnvSetTimeInHours(ENV_TIME_12); @@ -188,8 +189,8 @@ UINT32 MainGameScreenInit(void) giFPSOverlay = RegisterVideoOverlay( ( VOVERLAY_STARTDISABLED | VOVERLAY_DIRTYBYTEXT ), &VideoOverlayDesc ); // SECOND, PERIOD COUNTER - VideoOverlayDesc.sLeft = 30; - VideoOverlayDesc.sTop = 0; + VideoOverlayDesc.sLeft = 0; + VideoOverlayDesc.sTop = 12; VideoOverlayDesc.sX = VideoOverlayDesc.sLeft; VideoOverlayDesc.sY = VideoOverlayDesc.sTop; swprintf( VideoOverlayDesc.pzText, L"Levelnodes: 100000" ); diff --git a/gamescreen.h b/Ja2/gamescreen.h similarity index 100% rename from gamescreen.h rename to Ja2/gamescreen.h diff --git a/ja2.h b/Ja2/ja2.h similarity index 100% rename from ja2.h rename to Ja2/ja2.h diff --git a/jascreens.cpp b/Ja2/jascreens.cpp similarity index 89% rename from jascreens.cpp rename to Ja2/jascreens.cpp index 80f5188a..b431dd2e 100644 --- a/jascreens.cpp +++ b/Ja2/jascreens.cpp @@ -122,46 +122,33 @@ void DisplayFrameRate( ) uiFrameCount = 0; } - // Create string - SetFont( SMALLFONT1 ); - - //DebugMsg(TOPIC_JA2, DBG_LEVEL_0, String( "FPS: %d ", __min( uiFPS, 1000 ) ) ); - - if ( uiFPS < 20 ) - { - SetFontBackground( FONT_MCOLOR_BLACK ); - SetFontForeground( FONT_MCOLOR_LTRED ); - } - else - { - SetFontBackground( FONT_MCOLOR_BLACK ); - SetFontForeground( FONT_MCOLOR_DKGRAY ); - } - if ( gbFPSDisplay == SHOW_FULL_FPS ) { + memset(&VideoOverlayDesc, 0, sizeof(VideoOverlayDesc)); + // FRAME RATE - memset( &VideoOverlayDesc, 0, sizeof( VideoOverlayDesc ) ); - swprintf( VideoOverlayDesc.pzText, L"%ld", __min( uiFPS, 1000 ) ); - VideoOverlayDesc.uiFlags = VOVERLAY_DESC_TEXT; + VideoOverlayDesc.uiFontID = SMALLFONT1; + VideoOverlayDesc.ubFontBack = FONT_MCOLOR_BLACK; + VideoOverlayDesc.ubFontFore = uiFPS < 20 ? FONT_MCOLOR_LTRED : FONT_MCOLOR_DKGRAY; + swprintf( VideoOverlayDesc.pzText, L"FPS: %ld", __min( uiFPS, 1000 ) ); + VideoOverlayDesc.uiFlags = VOVERLAY_DESC_TEXT | VOVERLAY_DESC_FONT | VOVERLAY_DESC_DISABLED; UpdateVideoOverlay( &VideoOverlayDesc, giFPSOverlay, FALSE ); // TIMER COUNTER - swprintf( VideoOverlayDesc.pzText, L"%ld", __min( giTimerDiag, 1000 ) ); - VideoOverlayDesc.uiFlags = VOVERLAY_DESC_TEXT; + swprintf( VideoOverlayDesc.pzText, L"Frame: %04ld ms", __min( giTimerDiag, 10000 ) ); + VideoOverlayDesc.uiFlags = VOVERLAY_DESC_TEXT | VOVERLAY_DESC_DISABLED; UpdateVideoOverlay( &VideoOverlayDesc, giCounterPeriodOverlay, FALSE ); - - if( GetMouseMapPos( &usMapPos) ) - { + //if( GetMouseMapPos( &usMapPos) ) + //{ //gprintfdirty( 0, 315, L"(%d)",sMapPos); //mprintf( 0,315,L"(%d)",sMapPos); - } - else - { + //} + //else + //{ //gprintfdirty( 0, 315, L"(%d %d)",gusMouseXPos, gusMouseYPos - INTERFACE_START_Y ); //mprintf( 0,315,L"(%d %d)",gusMouseXPos, gusMouseYPos - INTERFACE_START_Y ); - } + //} } if ( ( gTacticalStatus.uiFlags & GODMODE ) ) @@ -409,48 +396,28 @@ UINT32 InitScreenHandle(void) // Handle queued .ini file error messages int y = 40; -#ifdef USE_VFS sgp::Logger_ID ini_id = sgp::Logger::instance().createLogger(); - sgp::Logger::instance().connectFile(ini_id, L"ERROR_REPORT.iniErrorMessages.txt", false, sgp::Logger::FLUSH_ON_DELETE); + sgp::Logger::instance().connectFile(ini_id, L"iniErrorReport.txt", false, sgp::Logger::FLUSH_ON_DELETE); sgp::Logger::LogInstance logger = sgp::Logger::instance().logger(ini_id); -#endif while (! iniErrorMessages.empty()) { -#ifndef USE_VFS - FILE *file_pointer; -#endif static BOOL iniErrorMessage_create_out_file = TRUE; std::string iniErrorMessage = iniErrorMessages.top(); CHAR16 str[256]; if (iniErrorMessage_create_out_file) { -#ifndef USE_VFS - fopen_s( &file_pointer, "..\\ERROR_REPORT.iniErrorMessages.txt", "w" ); -#endif y += 25; - swprintf( str, L"%S", "ERROR_REPORT.iniErrorMessages.txt has been created. Please review its content." ); - DisplayWrappedString( 10, y, 560, 2, FONT12ARIAL, FONT_RED, str, FONT_BLACK, TRUE, LEFT_JUSTIFIED ); + swprintf( str, L"%S", "Warning: found the following ini errors. iniErrorReport.txt has been created." ); + DisplayWrappedString( 10, y, 560, 2, FONT12ARIAL, FONT_ORANGE, str, FONT_BLACK, TRUE, LEFT_JUSTIFIED ); iniErrorMessage_create_out_file = FALSE; } - else - { -#ifndef USE_VFS - fopen_s( &file_pointer, "..\\ERROR_REPORT.iniErrorMessages.txt", "a+" ); -#endif - } y += 25; swprintf( str, L"%S", iniErrorMessage.c_str() ); -#ifndef USE_VFS - fprintf_s (file_pointer , "%S\n" , str ); - fclose( file_pointer ); -#else logger << iniErrorMessage << sgp::endl; -#endif - DisplayWrappedString( 10, y, 560, 2, FONT12ARIAL, FONT_RED, str, FONT_BLACK, TRUE, LEFT_JUSTIFIED ); - iniErrorMessages.pop(); + DisplayWrappedString( 10, y, 560, 2, FONT12ARIAL, FONT_ORANGE, str, FONT_BLACK, TRUE, LEFT_JUSTIFIED ); - if (iniErrorMessages.empty()) {for(int x=0 ; x <= 65535*2 ; x++);} + iniErrorMessages.pop(); } InvalidateScreen( ); diff --git a/jascreens.h b/Ja2/jascreens.h similarity index 100% rename from jascreens.h rename to Ja2/jascreens.h diff --git a/legion cfg.cpp b/Ja2/legion cfg.cpp similarity index 100% rename from legion cfg.cpp rename to Ja2/legion cfg.cpp diff --git a/legion cfg.h b/Ja2/legion cfg.h similarity index 100% rename from legion cfg.h rename to Ja2/legion cfg.h diff --git a/local.h b/Ja2/local.h similarity index 100% rename from local.h rename to Ja2/local.h diff --git a/mainmenuscreen.h b/Ja2/mainmenuscreen.h similarity index 100% rename from mainmenuscreen.h rename to Ja2/mainmenuscreen.h diff --git a/profiler.cpp b/Ja2/profiler.cpp similarity index 100% rename from profiler.cpp rename to Ja2/profiler.cpp diff --git a/profiler.h b/Ja2/profiler.h similarity index 100% rename from profiler.h rename to Ja2/profiler.h diff --git a/screenids.h b/Ja2/screenids.h similarity index 100% rename from screenids.h rename to Ja2/screenids.h diff --git a/ub_config.cpp b/Ja2/ub_config.cpp similarity index 100% rename from ub_config.cpp rename to Ja2/ub_config.cpp diff --git a/ub_config.h b/Ja2/ub_config.h similarity index 100% rename from ub_config.h rename to Ja2/ub_config.h diff --git a/Laptop/BobbyRGuns.cpp b/Laptop/BobbyRGuns.cpp index 479a1ef7..01136a57 100644 --- a/Laptop/BobbyRGuns.cpp +++ b/Laptop/BobbyRGuns.cpp @@ -362,6 +362,29 @@ void GetHelpTextForItemInLaptop( STR16 pzStr, UINT16 usItemNumber ); void HandleBobbyRGunsKeyBoardInput(); void HandleBobbyRayMouseWheel(void); +// Appends source STR16 to target STR16 using decorators ("\n" and "..."). +// Returns TRUE if everything fits target, FALSE otherwise. +static BOOLEAN DecorateAppendString(STR16 target, size_t targetCapacity, STR16 source, UINT32 frontDecoratorsCnt = 1) +{ + const CHAR16 DECORATOR0[] = L"\n"; + const CHAR16 DECORATOR1[] = L"\n..."; + BOOLEAN result = FALSE; + size_t decoratorLen = wcslen(DECORATOR0) * frontDecoratorsCnt; + + if (wcslen(target) + decoratorLen + wcslen(source) + 1 < targetCapacity) + { + for (UINT32 i = 0; i < frontDecoratorsCnt; i++) + wcscat(target, DECORATOR0); + wcscat(target, source); + result = TRUE; + } + else if (wcslen(target) + wcslen(DECORATOR1) + 1 < targetCapacity) + { + wcscat(target, DECORATOR1); + } // otherwise don't even touch the target + return result; +} + void GameInitBobbyRGuns() { guiTempCurrentMode=0; @@ -4088,7 +4111,8 @@ void HandleBobbyRayMouseWheel(void) } void GetHelpTextForItemInLaptop( STR16 pzStr, UINT16 usItemNumber ) -{ +{ + const size_t ATTACHMENTS_STRBUF_SIZE = 3800; CHAR16 zItemName[ SIZE_ITEM_NAME ]; UINT8 ubItemCount=0; @@ -4115,12 +4139,9 @@ void GetHelpTextForItemInLaptop( STR16 pzStr, UINT16 usItemNumber ) // HEADROCK HAM 3: Variables for "Possible Attachment List" BOOLEAN fAttachmentsFound = FALSE; // Contains entire string of attachment names - CHAR16 attachStr[3900]; - // Contains current attachment string - CHAR16 attachStr2[100]; + CHAR16 attachStr[ATTACHMENTS_STRBUF_SIZE]; // Contains temporary attachment list before added to string constant from text.h - CHAR16 attachStr3[3900]; - UINT16 usAttachment; + CHAR16 attachStr3[ATTACHMENTS_STRBUF_SIZE]; CreateItem(usItemNumber, 100, &pObject); INT16 ubAttackAPs = BaseAPsToShootOrStab( APBPConstants[DEFAULT_APS], APBPConstants[DEFAULT_AIMSKILL], &pObject, NULL ); @@ -4146,109 +4167,69 @@ void GetHelpTextForItemInLaptop( STR16 pzStr, UINT16 usItemNumber ) else wcscat( apStr, L" / -" ); - // HEADROCK HAM 3: Empty these strings first, to avoid crashes. Please keep this here. - swprintf( attachStr, L"" ); - swprintf( attachStr2, L"" ); - swprintf( attachStr3, L"" ); + attachStr[0] = 0; + attachStr3[0] = 0; // HEADROCK HAM 3: Generate list of possible attachments to a gun (Guns only!) if (gGameExternalOptions.fBobbyRayTooltipsShowAttachments) { - UINT16 iLoop = 0; - // Check entire attachment list - while( 1 ) + if (UsingNewAttachmentSystem()) { - //Madd: Common Attachment Framework - //TODO: Note that the items in this list will be duplicated if they are present in both the CAF and the old attachment method - //need to refactor this to work more like the NAS attachment slots method - usAttachment = 0; - if ( IsAttachmentPointAvailable(Item[usItemNumber].uiIndex, iLoop) ) - { - usAttachment = iLoop; - // If the attachment is not hidden - if (usAttachment > 0 && !Item[ usAttachment ].hiddenaddon && !Item[ usAttachment ].hiddenattachment) - { - if (wcslen( attachStr3 ) + wcslen(Item[usAttachment].szItemName) > 3800) - { - // End list early to avoid stack overflow - wcscat( attachStr3, L"\n..." ); - break; - } - else - {// Add the attachment's name to the list. - fAttachmentsFound = TRUE; - swprintf( attachStr2, L"\n%s", Item[ usAttachment ].szItemName ); - wcscat( attachStr3, attachStr2); - } - } - } - - // Is the weapon we're checking the same as the one we're tooltipping? - usAttachment = 0; - if (Attachment[iLoop][1] == Item[usItemNumber].uiIndex) + std::pair::iterator, std::multimap::iterator> range; + std::multimap::iterator it; + range = AttachmentBackmap.equal_range(Item[usItemNumber].uiIndex); + for (it = range.first; it != range.second; it++) { - usAttachment = Attachment[iLoop][0]; - } - - // If the attachment is not hidden - if (usAttachment > 0 && !Item[ usAttachment ].hiddenaddon && !Item[ usAttachment ].hiddenattachment) - { - if (wcslen( attachStr3 ) + wcslen(Item[usAttachment].szItemName) > 3800) + UINT16 attachmentId = it->second.attachmentIndex; + if (!Item[attachmentId].hiddenaddon && !Item[attachmentId].hiddenattachment && ItemIsLegal(attachmentId, TRUE)) { - // End list early to avoid stack overflow - wcscat( attachStr3, L"\n..." ); - break; - } - else - {// Add the attachment's name to the list. fAttachmentsFound = TRUE; - swprintf( attachStr2, L"\n%s", Item[ usAttachment ].szItemName ); - wcscat( attachStr3, attachStr2); + if (DecorateAppendString(attachStr3, ATTACHMENTS_STRBUF_SIZE, Item[attachmentId].szItemName) == FALSE) + break; } } - - - iLoop++; - if (Attachment[iLoop][0] == 0 && Item[iLoop].usItemClass == 0) - { - // Reached end of list - break; - } } + else // old attachment system + { + for (UINT32 itemId = 1; itemId < gMAXITEMS_READ; itemId++) + { + // If the attachment is not hidden and attachable to the gun (usItemNumber) + if (!Item[itemId].hiddenaddon && !Item[itemId].hiddenattachment && + ItemIsLegal(itemId, TRUE) && IsAttachmentPointAvailable(Item[usItemNumber].uiIndex, itemId)) + { + fAttachmentsFound = TRUE; + if (DecorateAppendString(attachStr3, ATTACHMENTS_STRBUF_SIZE, Item[itemId].szItemName) == FALSE) + break; + } + } + } + if (fAttachmentsFound) { - // Add extra empty line and attachment list title - swprintf( attachStr, L"\n \n%s", gWeaponStatsDesc[ 14 ] ); - wcscat( attachStr, attachStr3 ); + DecorateAppendString(attachStr, ATTACHMENTS_STRBUF_SIZE, gWeaponStatsDesc[14], 2); // 2 new lines and "Attachments:" title + DecorateAppendString(attachStr, ATTACHMENTS_STRBUF_SIZE, attachStr3, 0); // no new line, list of attachments (starts with new line) } } //Sum up default attachments. BOOLEAN fFoundDefault = FALSE; - swprintf( attachStr2, L"" ); - swprintf( attachStr3, L"" ); - for(UINT8 cnt = 0; cnt < MAX_DEFAULT_ATTACHMENTS; cnt++){ - if(Item[usItemNumber].defaultattachments[cnt] != 0){ - if (wcslen( attachStr ) + wcslen(attachStr3) + wcslen(Item[ Item[usItemNumber].defaultattachments[cnt] ].szItemName) > 3800) - { - // End list early to avoid stack overflow - wcscat( attachStr3, L"\n..." ); + attachStr3[0] = 0; + for (UINT8 cnt = 0; cnt < MAX_DEFAULT_ATTACHMENTS; cnt++) + { + if (Item[usItemNumber].defaultattachments[cnt] != 0) + { + if (DecorateAppendString(attachStr3, ATTACHMENTS_STRBUF_SIZE, Item[Item[usItemNumber].defaultattachments[cnt]].szItemName) == FALSE) break; - } fFoundDefault = TRUE; - swprintf( attachStr2, L"\n%s", Item[ Item[usItemNumber].defaultattachments[cnt] ].szItemName ); - wcscat( attachStr3, attachStr2 ); - } else { - //If we found an empty entry, we can assume the rest will be empty too. - break; } + else // If we found an empty entry, we can assume the rest will be empty too. + break; } - if(fFoundDefault){ - //Found at least one default attachment, write it to the attachment string. - CHAR16 defaultStr[50]; - swprintf( defaultStr, L"\n \n%s", gWeaponStatsDesc[ 17 ] ); - wcscat( attachStr, defaultStr ); - wcscat( attachStr, attachStr3 ); + + if (fFoundDefault) + { + DecorateAppendString(attachStr, ATTACHMENTS_STRBUF_SIZE, gWeaponStatsDesc[17], 2); // 2 new lines and "Default:" title + DecorateAppendString(attachStr, ATTACHMENTS_STRBUF_SIZE, attachStr3, 0); // no new line, list of attachments (starts with new line) } // HEADROCK HAM 3: Added last string (attachStr), for display of the possible attachment list. diff --git a/Laptop/Encyclopedia_Data_new.cpp b/Laptop/Encyclopedia_Data_new.cpp index 5de9ac67..2dff5b82 100644 --- a/Laptop/Encyclopedia_Data_new.cpp +++ b/Laptop/Encyclopedia_Data_new.cpp @@ -21,7 +21,7 @@ #include "QuestText.h" //quest: name #include "laptop.h" //ui positions #include "Utilities.h" - #include "Utils/Cursors.h" + #include "Cursors.h" #include "sysutil.h" //extra Buffer for scaling image #include "vsurface.h" //fill extra buffer with black color #include "Text.h" diff --git a/Laptop/Encyclopedia_new.cpp b/Laptop/Encyclopedia_new.cpp index e1c5ac39..08596e8c 100644 --- a/Laptop/Encyclopedia_new.cpp +++ b/Laptop/Encyclopedia_new.cpp @@ -36,7 +36,7 @@ #include "laptop.h"//UI dimensions, mouse regions #include "Utilities.h"//file names #include "vobject.h"//video objects - #include "Utils/Cursors.h" + #include "Cursors.h" #include "Text.h"//button text #include "Button System.h" #include "Encyclopedia_new.h" diff --git a/Laptop/IMP Confirm.cpp b/Laptop/IMP Confirm.cpp index 81780462..fd74d9f2 100644 --- a/Laptop/IMP Confirm.cpp +++ b/Laptop/IMP Confirm.cpp @@ -1336,16 +1336,6 @@ void WriteOutCurrentImpCharacter( INT32 iProfileId ) DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("WriteOutCurrentImpCharacter: Nickname.dat")); -#ifndef USE_VFS - char zFileName[13]; - char temp; - - for(int i=0;i < 9;i++) // Madd: I couldn't get strcpy or anything to work here... weird... if s/o wants to fix it, go ahead - { - temp = (char) gMercProfiles[iProfileId].zNickname[i]; - zFileName[i] = temp; - } -#else char zFileName[32]; if(vfs::Settings::getUseUnicode()) { @@ -1355,7 +1345,6 @@ void WriteOutCurrentImpCharacter( INT32 iProfileId ) { vfs::String::narrow(gMercProfiles[iProfileId].zNickname, 10, zFileName, 32); } -#endif // Changed by ADB, rev 1513 //strcat(zFileName,IMP_FILENAME_SUFFIX); diff --git a/Laptop/files.cpp b/Laptop/files.cpp index feb80271..3de647b9 100644 --- a/Laptop/files.cpp +++ b/Laptop/files.cpp @@ -476,7 +476,6 @@ void GameInitFiles( ) { if ( FileExists( FILES_DAT_FILE ) == TRUE ) { - FileClearAttributes( FILES_DAT_FILE ); FileDelete( FILES_DAT_FILE ); } diff --git a/Laptop/finances.cpp b/Laptop/finances.cpp index 57c8acba..ac542863 100644 --- a/Laptop/finances.cpp +++ b/Laptop/finances.cpp @@ -460,7 +460,6 @@ void GameInitFinances() // unlink Finances data file if( (FileExists( FINANCES_DATA_FILE ) ) ) { - FileClearAttributes( FINANCES_DATA_FILE ); FileDelete( FINANCES_DATA_FILE ); } GetBalanceFromDisk( ); diff --git a/Laptop/history.cpp b/Laptop/history.cpp index 6067098d..3ca4a8c4 100644 --- a/Laptop/history.cpp +++ b/Laptop/history.cpp @@ -227,7 +227,6 @@ void GameInitHistory() if( ( FileExists( HISTORY_DATA_FILE ) ) ) { // unlink history file - FileClearAttributes( HISTORY_DATA_FILE ); FileDelete( HISTORY_DATA_FILE ); } diff --git a/Laptop/laptop.cpp b/Laptop/laptop.cpp index 33e95d76..00c2f161 100644 --- a/Laptop/laptop.cpp +++ b/Laptop/laptop.cpp @@ -7136,28 +7136,24 @@ void ClearOutTempLaptopFiles( void ) // file file if ( (FileExists( "files.dat" ) == TRUE ) ) { - FileClearAttributes( "files.dat" ); FileDelete( "files.dat" ); } // finances if ( (FileExists( "finances.dat" ) == TRUE ) ) { - FileClearAttributes( "finances.dat" ); FileDelete( "finances.dat" ); } // email if ( (FileExists( "email.dat" ) == TRUE ) ) { - FileClearAttributes( "email.dat" ); FileDelete( "email.dat" ); } // history if ( (FileExists( "history.dat" ) == TRUE ) ) { - FileClearAttributes( "history.dat" ); FileDelete( "history.dat" ); } } diff --git a/Multiplayer/CMakeLists.txt b/Multiplayer/CMakeLists.txt new file mode 100644 index 00000000..e48f407f --- /dev/null +++ b/Multiplayer/CMakeLists.txt @@ -0,0 +1,12 @@ +add_library(Multiplayer +"client.cpp" +"server.cpp" +"transfer_rules.cpp" +) +target_include_directories(Multiplayer PUBLIC +${CMAKE_CURRENT_SOURCE_DIR} +"raknet" +) +target_link_libraries(Multiplayer PRIVATE +"${CMAKE_CURRENT_SOURCE_DIR}/raknet/RakNetLibStatic.lib" +) diff --git a/Multiplayer/client.cpp b/Multiplayer/client.cpp index d66e0f8b..05803259 100644 --- a/Multiplayer/client.cpp +++ b/Multiplayer/client.cpp @@ -815,10 +815,8 @@ void recievePATH(RPCParameters *rpcParameters) SendGetNewSoldierPathEvent( pSoldier, SNetPath->sDestGridNo, SNetPath->ubNewState ); INT16 sCellX, sCellY; - - sCellX = CenterX( SNetPath->sAtGridNo ); - sCellY = CenterY( SNetPath->sAtGridNo ); - + ConvertGridNoToCenterCellXY(SNetPath->sAtGridNo, &sCellX, &sCellY); + if (( gAnimControl[ pSoldier->usAnimState ].uiFlags & ( ANIM_MOVING | ANIM_SPECIALMOVE ) ) && !(pSoldier->flags.fNoAPToFinishMove ) ) { } @@ -4251,8 +4249,7 @@ void UpdateSoldierFromNetwork (RPCParameters *rpcParameters) pSoldier->stats.bLife=SUpdateNetworkSoldier->bLife; INT16 sCellX, sCellY; - sCellX = CenterX( SUpdateNetworkSoldier->sAtGridNo ); - sCellY = CenterY( SUpdateNetworkSoldier->sAtGridNo ); + ConvertGridNoToCenterCellXY(SUpdateNetworkSoldier->sAtGridNo, &sCellX, &sCellY); if( pSoldier->sGridNo != SUpdateNetworkSoldier->sAtGridNo) { @@ -5281,4 +5278,4 @@ void ChatCallback( UINT8 ubResult ) void OpenChatMsgBox( void ) { DoChatBox((guiCurrentScreen == GAME_SCREEN? true : false),gzMPChatboxText[1],guiCurrentScreen,ChatCallback,NULL); -} \ No newline at end of file +} diff --git a/Standard Gaming Platform/Container.cpp b/Standard Gaming Platform/Container.cpp deleted file mode 100644 index ad140dd5..00000000 --- a/Standard Gaming Platform/Container.cpp +++ /dev/null @@ -1,2104 +0,0 @@ -//***************************************************************************** -// -// Filename : Container.c -// -// Purpose : Function definition for the Container -// -// Modification History : -// 25 nov 96 TS creation -// -// 19 Dec 97 AM Replace all memcpy() with memmove(), since overlap possibilities -// abound (and there were already bugs in do_copy() for ordered lists) -// While the memcpy() was working in _DEBUG mode, it was failing -// reproducibly in RELEASE mode whenever regions overlapped! -// Having read the code, I strongly suggest that you DO NOT use this -// stuff at all and write your own instead. Tarun was no Carmack... -// - Alex Meduna -// 1998 KM Detached all references to this file from JA2 as it caused a lot of hard to debug -// crashes. The VOBJECT/VSURFACE lists are now self-maintained and no longer use the -// this crap. DON'T USE THIS -- NO MATTER WHAT!!! -//***************************************************************************** - - #include "types.h" - #include - #include - #include - #include "windows.h" - #include "MemMan.h" - #include "Debug.h" - #include "Container.h" - #if _MSC_VER < 1300 //(iostream.h was removed from VC.NET2003) - #include - #endif - - -//***************************************************************************** -// -// Defines and typedefs -// -// -//***************************************************************************** - -typedef struct StackHeaderTag -{ - UINT32 uiTotal_items; - UINT32 uiSiz_of_elem; - UINT32 uiMax_size; - -} StackHeader; - -typedef struct HeaderTag -{ - UINT32 uiTotal_items; - UINT32 uiSiz_of_elem; - UINT32 uiMax_size; - UINT32 uiHead; - UINT32 uiTail; - -} QueueHeader , ListHeader; - -typedef struct OrdHeaderTag -{ - UINT32 uiTotal_items; - UINT32 uiSiz_of_elem; - UINT32 uiMax_size; - UINT32 uiHead; - UINT32 uiTail; - INT8 (*pCompare)(void *,void *, UINT32); - -} OrdListHeader; - - typedef struct test - { - UINT32 me; - long you; - STR8 k; - STR8 p; - - } TEST; - -//***************************************************************************** -// -// CreateStack -// -// Parameter List : num_items - estimated number -// of items in stack -// siz_each - size of each item -// Return Value NULL if unsuccesful -// pointer to allocated memory -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** - -HSTACK CreateStack(UINT32 uiNum_items, UINT32 uiSiz_each) -{ - UINT32 uiAmount; - HSTACK hStack; - StackHeader *pStack; - - // assign an initial amount of memory to allocate - if ((uiNum_items > 0) && (uiSiz_each > 0)) - uiAmount = uiNum_items * uiSiz_each; - else - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Requested stack items and size have to be >0"); - return NULL; - } - // allocate the container memory - if ((hStack = MemAlloc(uiAmount + sizeof(StackHeader))) == 0) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Could not allocate stack container memory"); - return NULL; - } - pStack = (StackHeader *)hStack; - //initialize the header variables - pStack->uiMax_size = uiAmount + sizeof(StackHeader); - pStack->uiTotal_items = 0; - pStack->uiSiz_of_elem = uiSiz_each; - - // return the pointer to the memory - - return hStack; -} - -//***************************************************************************** -// -// CreateQueue -// -// Parameter List : num_items - estimated number -// of items in queue -// siz_each - size of each item -// Return Value NULL if unsuccesful -// pointer to allocated memory -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HQUEUE CreateQueue(UINT32 uiNum_items, UINT32 uiSiz_each) -{ - UINT32 uiAmount; - HQUEUE hQueue; - QueueHeader *pQueue; - - // check to see if the queue has more than 1 - // element to be created and that the size > 1 - - if ((uiNum_items > 0) && (uiSiz_each > 0)) - uiAmount = uiNum_items * uiSiz_each; - else - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Requested queue items and size have to be >0"); - return NULL; - } - - // allocate the queue memory - if ((hQueue = MemAlloc(uiAmount + sizeof(QueueHeader))) == 0) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Could not allocate queue container memory"); - return NULL; - } - - pQueue = (QueueHeader *)hQueue; - //initialize the queue structure - - pQueue->uiMax_size = uiAmount + sizeof(QueueHeader); - pQueue->uiTotal_items = 0; - pQueue->uiSiz_of_elem = uiSiz_each; - pQueue->uiTail = pQueue->uiHead = sizeof(QueueHeader); - - // return the pointer to memory - return hQueue; -} -//***************************************************************************** -// -// CreateList -// -// Parameter List : num_items - estimated number -// of items in ordered list -// siz_each - size of each item -// Return Value NULL if unsuccesful -// pointer to allocated memory -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HLIST CreateList(UINT32 uiNum_items, UINT32 uiSiz_each) -{ - UINT32 uiAmount; - HLIST hList; - ListHeader *pList; - - // check to see if the queue has more than 1 - // element to be created and that the size > 1 - - if ((uiNum_items > 0) && (uiSiz_each > 0)) - uiAmount = uiNum_items * uiSiz_each; - else - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Requested queue items and size have to be >0"); - return 0; - } - - // allocate the list memory - if ((hList = MemAlloc(uiAmount + sizeof(ListHeader))) == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not allocate queue container memory"); - return 0; - } - - pList = (ListHeader *)hList; - //initialize the list structure - - pList->uiMax_size = uiAmount + sizeof(ListHeader); - pList->uiTotal_items = 0; - pList->uiSiz_of_elem = uiSiz_each; - pList->uiTail = pList->uiHead = sizeof(ListHeader); - - // return the pointer to memory - - return hList; - -} - - - -//***************************************************************************** -// -// CreateOrdList -// -// Parameter List : num_items - estimated number -// of items in ordered list -// siz_each - size of each item -// Return Value NULL if unsuccesful -// pointer to allocated memory -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HORDLIST CreateOrdList(UINT32 uiNum_items, UINT32 uiSiz_each, INT8 (*compare)(void *, void *, UINT32)) -{ - UINT32 uiAmount; - HLIST hOrdList; - OrdListHeader *pOrdList; - - // check to see if the ordered list has more than 1 - // element to be created and that the size > 1 - - if ((uiNum_items > 0) && (uiSiz_each > 0)) - uiAmount = uiNum_items * uiSiz_each; - else - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Requested ordered list items and size have to be >0"); - return 0; - } - - // allocate the list memory - if ((hOrdList = MemAlloc(uiAmount + sizeof(OrdListHeader))) == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not allocate queue container memory"); - return 0; - } - - pOrdList = (OrdListHeader *)hOrdList; - //initialize the list structure - - pOrdList->uiMax_size = uiAmount + sizeof(OrdListHeader); - pOrdList->uiTotal_items = 0; - pOrdList->uiSiz_of_elem = uiSiz_each; - pOrdList->uiTail = pOrdList->uiHead = sizeof(OrdListHeader); - pOrdList->pCompare = compare; - - // return the pointer to memory - - return hOrdList; -} - - - -//***************************************************************************** -// -// push -// -// Parameter List : void * - pointer to stack -// container -// data - data to add to stack -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HSTACK Push(HSTACK hStack, void *pdata) -{ - StackHeader *pTemp_cont; - UINT32 uiOffset; - UINT32 uiNew_size; - void *pvoid; - BYTE *pbyte; - - // check for a NULL pointer - - if (hStack == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the stack"); - return NULL; - } - - // some valid data should be passed in - if (pdata == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto stack is NULL"); - return NULL; - } - - //perform operations to calculate offset and decide if the container has to resized - pTemp_cont = (StackHeader *)hStack; - uiOffset = (pTemp_cont->uiSiz_of_elem * pTemp_cont->uiTotal_items) + sizeof(StackHeader); - - if ((uiOffset + pTemp_cont->uiSiz_of_elem) > pTemp_cont->uiMax_size) - { - uiNew_size = pTemp_cont->uiMax_size + (pTemp_cont->uiMax_size - sizeof(StackHeader)); - pTemp_cont->uiMax_size = uiNew_size; - if ((hStack = MemRealloc(hStack, uiNew_size)) == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Could not resize stack container memory"); - return NULL; - } - pTemp_cont = (StackHeader *)hStack; - } - pbyte = (BYTE *)hStack; - pbyte += uiOffset; - pvoid = (void *)pbyte; - //copy data from pdata to pvoid - the stack - memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - pTemp_cont->uiTotal_items++; - //return push succeeded - return hStack; -} -//***************************************************************************** -// -// pop -// -// Parameter List : void * - pointer to stack -// container -// -// -// Return Value : void * - pointer to stack -// after pushing element -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN Pop(HSTACK hStack, void *pdata) -{ - StackHeader *pTemp_cont; - UINT32 uiOffset; - UINT32 uiSize_of_each; - UINT32 uiTotal; - void *pvoid; - BYTE *pbyte; - - // check for a NULL queue - - if (hStack == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the stack"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Variable where data is to be stored is NULL"); - return FALSE; - } - pTemp_cont = (StackHeader *)hStack; - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - if (uiTotal == 0) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "There is no data in stack to pop"); - return FALSE; - } - - // calculate offsets to decide if the page should be rezied - uiOffset = (uiSize_of_each * uiTotal) + sizeof(StackHeader); - uiOffset -= uiSize_of_each; - pbyte = (BYTE *)hStack; - pbyte += uiOffset; - pvoid = (void *)pbyte; - // get the data from pvoid and store in pdata - memmove(pdata, pvoid, uiSize_of_each); - pTemp_cont->uiTotal_items--; - return TRUE; -} -//***************************************************************************** -// -// PeekStack -// -// Parameter List : void * - buffer to hold data -// -// -// Return Value : TRUE if stack not empty -// -// Modification History : -// Apr 14 2000 SCT->Created -// -//***************************************************************************** -BOOLEAN PeekStack(HSTACK hStack, void *pdata) -{ - StackHeader *pTemp_cont; - UINT32 uiOffset; - UINT32 uiSize_of_each; - UINT32 uiTotal; - void *pvoid; - BYTE *pbyte; - - // check for a NULL queue - - if (hStack == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the stack"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "Variable where data is to be stored is NULL"); - return FALSE; - } - pTemp_cont = (StackHeader *)hStack; - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - if (uiTotal == 0) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "There is no data in stack to pop"); - return FALSE; - } - - // calculate offsets to decide if the page should be rezied - uiOffset = (uiSize_of_each * uiTotal) + sizeof(StackHeader); - uiOffset -= uiSize_of_each; - pbyte = (BYTE *)hStack; - pbyte += uiOffset; - pvoid = (void *)pbyte; - // get the data from pvoid and store in pdata - memmove(pdata, pvoid, uiSize_of_each); - return TRUE; -} -//***************************************************************************** -// -// DeleteStack -// -// Parameter List : pointer to memory -// -// Return Value : BOOLEAN -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN DeleteStack(HSTACK hStack) -{ - if (hStack == NULL) - { - DbgMessage(TOPIC_STACK_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the stack"); - return FALSE; - } - // free the memory assigned to the handle - MemFree(hStack); - return TRUE; -} -//***************************************************************************** -// -// DeleteQueue -// -// Parameter List : pointer to memory -// -// Return Value : BOOLEAN -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN DeleteQueue(HQUEUE hQueue) -{ - if (hQueue == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the queue"); - return FALSE; - } - // free the memory assigned to the handle - MemFree(hQueue); - return TRUE; -} -//***************************************************************************** -// -// DeleteList -// -// Parameter List : pointer to memory -// -// Return Value : BOOLEAN -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN DeleteList(HLIST hList) -{ - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the list"); - return FALSE; - } - // free the memory assigned to the list - MemFree(hList); - return TRUE; -} -//***************************************************************************** -// -// DeleteOrdList -// -// Parameter List : pointer to memory -// -// Return Value : BOOLEAN -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN DeleteOrdList(HORDLIST hOrdList) -{ - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the ordered list"); - return FALSE; - } - // free the memory assigned to the list - MemFree(hOrdList); - return TRUE; -} -//***************************************************************************** -// -// InitializeContainers -// -// Parameter List : none -// -// Return Value : void -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** - -void InitializeContainers(void) -{ - // register the appropriate debug topics - RegisterDebugTopic(TOPIC_STACK_CONTAINERS, "Stack Container"); - RegisterDebugTopic(TOPIC_LIST_CONTAINERS, "List Container"); - RegisterDebugTopic(TOPIC_QUEUE_CONTAINERS, "Queue Container"); - RegisterDebugTopic(TOPIC_ORDLIST_CONTAINERS, "Ordered List Container"); -} - -//***************************************************************************** -// -// ShutdownContainers -// -// Parameter List : none -// -// Return Value : void -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** - -void ShutdownContainers( void ) -{ - UnRegisterDebugTopic(TOPIC_STACK_CONTAINERS, "Stack Container"); - UnRegisterDebugTopic(TOPIC_LIST_CONTAINERS, "List Container"); - UnRegisterDebugTopic(TOPIC_QUEUE_CONTAINERS, "Queue Container"); - UnRegisterDebugTopic(TOPIC_ORDLIST_CONTAINERS, "Ordered List Container"); -} -//***************************************************************************** -// -// PeekQueue - gets the first item in queue without -// actually deleting it. -// -// Parameter List : pvoid_queue - pointer to queue -// container -// data - data removed from queue -// -// Return Value pointer to queue with data removed -// or NULL if failed -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN PeekQueue(HQUEUE hQueue, void *pdata) -{ - QueueHeader *pTemp_cont; - void *pvoid; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hQueue == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the queue"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Memory fo Data to be removed from queue is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (QueueHeader *)hQueue; - - // if theres no elements to remove return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "There is nothing in the queue"); - return FALSE; - } - - //copy the element pointed to by uiHead - - pbyte = (BYTE *)hQueue; - pbyte += pTemp_cont->uiHead; - pvoid = (void *)pbyte; - memmove(pdata, pvoid, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} -//***************************************************************************** -// -// PeekList - gets the specified item in the list without -// actually deleting it. -// -// Parameter List : hList - pointer to list -// container -// data - data where list element is stored -// -// Return Value BOOLEAN -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN PeekList(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - void *pvoid; - UINT32 uiOffsetSrc; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the list"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Memory fo Data to be removed from list is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (ListHeader *)hList; - - // if theres no elements to peek return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "There is nothing in the list"); - return FALSE; - } - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "There is no item at this position"); - return FALSE; - } - - //copy the element pointed to by uiHead - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= pTemp_cont->uiMax_size) - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - pTemp_cont->uiMax_size); - - pbyte = (BYTE *)hList; - pbyte += uiOffsetSrc; - pvoid = (void *)pbyte; - memmove(pdata, pvoid, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} - - -//***************************************************************************** -// -// SwapListNode - Swaps the contents of a list node with the given parameter. -// Note: The data being swapped in MUST have the same size as -// the current node size or strange things could happen. -// Contents of node and pdata parameter are swapped. -// -// Parameter List : hList - pointer to list container -// pdata - pointer to data to be swapped -// uiPos - List position with which to swap. -// -// Return Value BOOLEAN - TRUE if successful, FALSE if function fails. -// -// -// Modification History : -// Added to SGP by Bret Rowdon for use with JA2. May 1 '97. -// - This function was based on the PeekList function. -// -//***************************************************************************** -BOOLEAN SwapListNode(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - BYTE *pvoid; - UINT32 uiOffsetSrc; - BYTE *pbyte; - BYTE *pSrc; - - - // cannot check for invalid handle, only 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid pointer to list"); - return FALSE; - } - - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data pointer to be swapped from list is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (ListHeader *)hList; - - // if theres no elements to peek return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Empty list"); - return FALSE; - } - - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid list position"); - return FALSE; - } - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= pTemp_cont->uiMax_size) - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - pTemp_cont->uiMax_size); - - pbyte = (BYTE *)hList; - pbyte += uiOffsetSrc; - pvoid = pbyte; - pSrc = (BYTE *) pdata; - - // possible overlap, use memmove() - memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - //memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} - - - -//***************************************************************************** -// -// StoreListNode - Stores the contents of a list node with the given parameter. -// Unlike SwapListNode(), this does NOT swap previous contents -// back into the pdata buffer! -// -// Parameter List : hList - pointer to list container -// pdata - pointer to data to be stored -// uiPos - List position into which to store. -// -// Return Value BOOLEAN - TRUE if successful, FALSE if function fails. -// -// -// Modification History : -// Added to SGP by Alex Meduna for use with Wiz8. Oct 31 '97. -// - This function is nearly identical to the SwapListNode() function. -// -//***************************************************************************** -BOOLEAN StoreListNode(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - UINT32 uiOffsetSrc; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid pointer to list"); - return FALSE; - } - - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data pointer to be swapped from list is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (ListHeader *)hList; - - // if theres no elements to peek return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Empty list"); - return FALSE; - } - - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid list position"); - return FALSE; - } - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= pTemp_cont->uiMax_size) - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - pTemp_cont->uiMax_size); - - pbyte = (BYTE *)hList; - pbyte += uiOffsetSrc; - - memmove(pbyte, pdata, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} - - - -//***************************************************************************** -// -// PeekOrdList - gets the specified item in the list without -// actually deleting it. -// -// Parameter List : hList - pointer to ordered list -// container -// data - data where list element is stored -// -// Return Value BOOLEAN -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN PeekOrdList(HORDLIST hOrdList, void *pdata, UINT32 uiPos) -{ - OrdListHeader *pTemp_cont; - void *pvoid; - UINT32 uiOffsetSrc; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the ordered list"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Memory fo Data to be removed from ordered list is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (OrdListHeader *)hOrdList; - - // if theres no elements to peek return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "There is nothing in the list"); - return FALSE; - } - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "There is no item at this position"); - return FALSE; - } - - //copy the element pointed to by uiHead - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= pTemp_cont->uiMax_size) - uiOffsetSrc = sizeof(OrdListHeader) + (uiOffsetSrc - pTemp_cont->uiMax_size); - - pbyte = (BYTE *)hOrdList; - pbyte += uiOffsetSrc; - pvoid = (void *)pbyte; - memmove(pdata, pvoid, pTemp_cont->uiSiz_of_elem); - - return TRUE; -} -//***************************************************************************** -// -// RemfromQueue -// -// Parameter List : pvoid_queue - pointer to queue -// container -// data - data removed from queue -// -// Return Value pointer to queue with data removed -// or NULL if failed -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN RemfromQueue(HQUEUE hQueue, void *pdata) -{ - QueueHeader *pTemp_cont; - void *pvoid; - BYTE *pbyte; - - // cannot check for invalid handle , only 0 - if (hQueue == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the queue"); - return FALSE; - } - if (pdata == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Memory fo Data to be removed from queue is NULL"); - return FALSE; - } - - //assign to temporary variables - pTemp_cont = (QueueHeader *)hQueue; - - // if theres no elements to remove return error - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "There is nothing in the queue to remove"); - return FALSE; - } - - //remove the element pointed to by uiHead - - pbyte = (BYTE *)hQueue; - pbyte += pTemp_cont->uiHead; - pvoid = (void *)pbyte; - memmove(pdata, pvoid, pTemp_cont->uiSiz_of_elem); - pTemp_cont->uiTotal_items--; - pTemp_cont->uiHead += pTemp_cont->uiSiz_of_elem; - - // if after removing an element head = tail then set them both - // to the beginning of the container as it is empty - - if (pTemp_cont->uiHead == pTemp_cont->uiTail) - pTemp_cont->uiHead = pTemp_cont->uiTail = sizeof(QueueHeader); - - // if only the head is at the end of the container then make it point - // to the beginning of the container - - if (pTemp_cont->uiHead == pTemp_cont->uiMax_size) - pTemp_cont->uiHead = sizeof(QueueHeader); - - return TRUE; -} - -//***************************************************************************** -// -// AddtoQueue -// -// Parameter List : pvoid_queue - pointer to queue -// container -// pdata - pointer to data to add to queue -// -// Return Value pointer to queue with data added -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HQUEUE AddtoQueue(HQUEUE hQueue, void *pdata) -{ - QueueHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiNew_size; - UINT32 uiHead; - UINT32 uiTail; - void *pvoid; - BYTE *pbyte; - BYTE *pmaxsize; - BYTE *presize; - BOOLEAN fresize; - - // check for invalid handle = 0 - if (hQueue == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "This is not a valid pointer to the queue"); - return NULL; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Data to be added onto queue is NULL"); - return NULL; - } - - // assign some temporary variables - fresize = FALSE; - pTemp_cont = (QueueHeader *)hQueue; - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - if ((uiTail + uiSize_of_each) > uiMax_size) - { - uiTail = pTemp_cont->uiTail = sizeof(QueueHeader); - fresize = TRUE; - } - if ((uiHead == uiTail) && ((uiHead >= (sizeof(QueueHeader) + uiSize_of_each)) || (fresize == TRUE))) - { - uiNew_size = uiMax_size + (uiMax_size - sizeof(QueueHeader)); - pTemp_cont->uiMax_size = uiNew_size; - if ((hQueue = MemRealloc(hQueue, uiNew_size)) == NULL) - { - DbgMessage(TOPIC_QUEUE_CONTAINERS, DBG_LEVEL_0, "Could not resize queue container memory"); - return NULL; - } - // copy memory from beginning of container to end of container - // so that all the data is in one continuous block - - pTemp_cont = (QueueHeader *)hQueue; - presize = (BYTE *)hQueue; - pmaxsize = (BYTE *)hQueue; - presize += sizeof(QueueHeader); - pmaxsize += uiMax_size; - if (uiHead > sizeof(QueueHeader)) - memmove(pmaxsize, presize, uiHead-sizeof(QueueHeader)); - pTemp_cont->uiTail = uiMax_size + (uiHead-sizeof(QueueHeader)); - } - pbyte = (BYTE *)hQueue; - pbyte += pTemp_cont->uiTail; - pvoid = (void *)pbyte; - memmove(pvoid, pdata, uiSize_of_each); - pTemp_cont->uiTotal_items++; - pTemp_cont->uiTail += uiSize_of_each; - return hQueue; -} - -//***************************************************************************** -// -// do_copy -// -// Parameter List : pointer to mem, source offset, dest offset, size -// -// Return Value BOOLEAN -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN do_copy(void *pmem_void, UINT32 uiSourceOfst, UINT32 uiDestOfst, UINT32 uiSize) -{ - BYTE *pOffsetSrc; - BYTE *pOffsetDst; - void *pvoid_src; - void *pvoid_dest; - - if ((uiSourceOfst < 0) || (uiDestOfst < 0) || (uiSize < 0)) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid parameters passed to do_copy"); - return FALSE; - } - - if (pmem_void == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid pointer passed to do_copy"); - return FALSE; - } - pOffsetSrc = (BYTE *)pmem_void; - pOffsetSrc += uiSourceOfst; - pOffsetDst = (BYTE *)pmem_void; - pOffsetDst += uiDestOfst; - pvoid_src = (void *)pOffsetSrc; - pvoid_dest = (void *)pOffsetDst; - memmove(pvoid_dest, pvoid_src, uiSize); - return TRUE; -} -//***************************************************************************** -// -// do_copy_data -// -// Parameter List : pointer to mem, pointer to data, source offset, size -// -// Return Value BOOLEAN -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN do_copy_data(void *pmem_void, void *data, UINT32 uiSrcOfst, UINT32 uiSize) -{ - BYTE *pOffsetSrc; - void *pvoid_src; - - if ((uiSrcOfst < 0) || (uiSize < 0)) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid parameters passed to do_copy_data"); - return FALSE; - } - - if (pmem_void == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Invalid pointer passed to do_copy_data"); - return FALSE; - } - pOffsetSrc = (BYTE *)pmem_void; - pOffsetSrc += uiSrcOfst; - pvoid_src = (void *)pOffsetSrc; - memmove(data, pvoid_src, uiSize); - return TRUE; -} -//***************************************************************************** -// -// StackSize -// -// Parameter List : pointer to stack -// -// Return Value UINT32 stack size -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -UINT32 StackSize(HSTACK hStack) -{ - StackHeader *pTemp_cont; - if (hStack == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Stack pointer is NULL"); - return 0; - } - pTemp_cont = (StackHeader *)hStack; - return pTemp_cont->uiTotal_items; -} -//***************************************************************************** -// -// QueueSize -// -// Parameter List : pointer to queue -// -// Return Value UINT32 queue size -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -UINT32 QueueSize(HQUEUE hQueue) -{ - QueueHeader *pTemp_cont; - if (hQueue == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Queue pointer is NULL"); - return 0; - } - pTemp_cont = (QueueHeader *)hQueue; - return pTemp_cont->uiTotal_items; -} -//***************************************************************************** -// -// ListSize -// -// Parameter List : pointer to queue -// -// Return Value UINT32 list size -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -UINT32 ListSize(HLIST hList) -{ - ListHeader *pTemp_cont; - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "List pointer is NULL"); - return 0; - } - pTemp_cont = (ListHeader *)hList; - return pTemp_cont->uiTotal_items; -} -//***************************************************************************** -// -// OrdListSize -// -// Parameter List : pointer to list -// -// Return Value UINT32 Ordlist size -// -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -UINT32 OrdListSize(HORDLIST hOrdList) -{ - OrdListHeader *pTemp_cont; - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Ordered List pointer is NULL"); - return 0; - } - pTemp_cont = (OrdListHeader *)hOrdList; - return pTemp_cont->uiTotal_items; -} -//***************************************************************************** -// -// AddtoList -// -// Parameter List : HCONTAINER - handle to list -// container -// data - data to add to queue -// position - position after which data is to added -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HLIST AddtoList(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiNew_size; - UINT32 uiHead; - UINT32 uiTail; - void *pvoid; - BYTE *pbyte; - UINT32 uiOffsetSrc; - UINT32 uiOffsetDst; - UINT32 uiFinalLoc = 0; - BOOLEAN fTail_check=FALSE; - - // check for invalid handle = 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid handle to the list"); - return NULL; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto list is NULL"); - return NULL; - } - // check for a 0 or negative position passed in - if (uiPos < 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto list is NULL"); - return NULL; - } - - // assign some temporary variables - - pTemp_cont = (ListHeader *)hList; - if (uiPos > pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "There are not enough elements in the list"); - return NULL; - } - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - if (uiOffsetSrc >= uiMax_size) - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - uiMax_size); - if (uiTail == uiOffsetSrc) - fTail_check = TRUE; - // copy appropriate blocks - if (((uiTail + uiSize_of_each) <= uiMax_size) && - ((uiTail > uiHead) || ((uiTail == uiHead) && (uiHead == sizeof(ListHeader))))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - if (fTail_check == FALSE) - { - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - } - if (fTail_check == FALSE) - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - } - - - if ((((uiTail + uiSize_of_each) <= uiMax_size) && (uiTail < uiHead)) - || (((uiTail + uiSize_of_each) > uiMax_size) && (uiHead >= (sizeof(ListHeader) + uiSize_of_each)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - - if (uiOffsetSrc >= uiMax_size) - { - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - uiMax_size); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy(hList, uiOffsetDst, uiOffsetSrc, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - uiFinalLoc = uiOffsetSrc; - } else - { - uiOffsetSrc = sizeof(ListHeader); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - - uiOffsetSrc = uiMax_size - uiSize_of_each; - uiOffsetDst = sizeof(ListHeader); - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, (uiMax_size-uiSize_of_each) - uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - } - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - }// end if - - - - if ((((uiTail + uiSize_of_each) <= uiMax_size) && (uiTail == uiHead) && (uiHead >= (sizeof(ListHeader) + uiSize_of_each))) - || (((uiTail + uiSize_of_each) > uiMax_size) && (uiHead == sizeof(ListHeader)))) - { - // need to resize the container - uiNew_size = uiMax_size + (uiMax_size - sizeof(ListHeader)); - pTemp_cont->uiMax_size = uiNew_size; - if ((hList = MemRealloc(hList, uiNew_size)) == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not resize list container memory"); - return NULL; - } - pTemp_cont = (ListHeader *)hList; - if (do_copy(hList, sizeof(ListHeader), uiMax_size, uiHead - sizeof(ListHeader)) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not copy list container memory"); - return NULL; - } - pTemp_cont->uiTail = uiMax_size + (uiHead-sizeof(ListHeader)); - - // now make place for the actual element - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - } - - - // finally insert data at position uiFinalLoc - - pbyte = (BYTE *)hList; - if (uiFinalLoc == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This should never happen! report this problem!"); - return NULL; - } - pbyte += uiFinalLoc; - pvoid = (void *)pbyte; - - memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - pTemp_cont->uiTotal_items++; - if (fTail_check == TRUE) - pTemp_cont->uiTail += pTemp_cont->uiSiz_of_elem; - return hList; -} - -//***************************************************************************** -// -// RemfromList -// -// Parameter List : HLIST - handle to list -// container -// data - data to remove from list -// position - position after which data is to added -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN RemfromList(HLIST hList, void *pdata, UINT32 uiPos) -{ - ListHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiHead; - UINT32 uiTail; - UINT32 uiOffsetSrc; - UINT32 uiOffsetDst; - UINT32 uiFinalLoc = 0; - - // check for invalid handle = 0 - if (hList == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid handle to the list"); - return FALSE; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto list is NULL"); - return FALSE; - } - // check for a 0 or negative position passed in - if (uiPos < 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto list is NULL"); - return FALSE; - } - - // assign some temporary variables - pTemp_cont = (ListHeader *)hList; - - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Cannot delete at the specified position"); - return FALSE; - } - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "There are no elements in the list to remove"); - return FALSE; - } - - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - - // copy appropriate blocks - if ((uiTail > uiHead) || ((uiTail == uiHead) && (uiHead == sizeof(ListHeader)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - if (do_copy_data(hList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - if (do_copy(hList, uiOffsetDst, uiOffsetSrc, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not remove the data the list"); - return FALSE; - } - pTemp_cont->uiTail -= uiSize_of_each; - pTemp_cont->uiTotal_items--; - } - - - if ((uiTail < uiHead) || ((uiTail == uiHead) && (uiHead <= (sizeof(ListHeader)+uiSize_of_each)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - - if (uiOffsetSrc >= uiMax_size) - { - uiOffsetSrc = sizeof(ListHeader) + (uiOffsetSrc - uiMax_size); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy_data(hList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - uiFinalLoc = uiOffsetSrc; - } - else - { - uiOffsetSrc = sizeof(ListHeader); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - - uiOffsetSrc = uiMax_size - uiSize_of_each; - uiOffsetDst = sizeof(ListHeader); - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy_data(hList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - if (do_copy(hList, uiOffsetSrc, uiOffsetDst, (uiMax_size-uiSize_of_each) - uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_LIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - } - pTemp_cont->uiTail -= uiSize_of_each; - pTemp_cont->uiTotal_items--; - } // end if - - return TRUE; -} - - - -//***************************************************************************** -// -// RemfromOrdList -// -// Parameter List : HORDLIST - handle to ordered list -// container -// data - data to remove from ordered list -// position - position after which data is to added -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -BOOLEAN RemfromOrdList(HORDLIST hOrdList, void *pdata, UINT32 uiPos) -{ - OrdListHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiHead; - UINT32 uiTail; - UINT32 uiOffsetSrc; - UINT32 uiOffsetDst; - UINT32 uiFinalLoc = 0; - - - // check for invalid handle = 0 - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid handle to the ordered list"); - return FALSE; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto ordered list is NULL"); - return FALSE; - } - // check for a 0 or negative position passed in - if (uiPos < 0) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto ordered list is NULL"); - return FALSE; - } - - // assign some temporary variables - - pTemp_cont = (OrdListHeader *)hOrdList; - if (uiPos >= pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Cannot delete at the specified position"); - return FALSE; - } - - if (pTemp_cont->uiTotal_items == 0) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "There are no elements in the ordered list to remove"); - return FALSE; - } - - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - - // copy appropriate blocks - if ((uiTail > uiHead) || ((uiTail == uiHead) && (uiHead == sizeof(OrdListHeader)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - if (do_copy_data(hOrdList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from ordered list"); - return FALSE; - } - - if (do_copy(hOrdList, uiOffsetDst, uiOffsetSrc, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not remove the data from the ordered list"); - return FALSE; - } - - pTemp_cont->uiTail -= uiSize_of_each; - pTemp_cont->uiTotal_items--; - } - - - if ((uiTail < uiHead) || ((uiTail == uiHead) && (uiHead <= (sizeof(OrdListHeader)+uiSize_of_each)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - - if (uiOffsetSrc >= uiMax_size) - { - uiOffsetSrc = sizeof(OrdListHeader) + (uiOffsetSrc - uiMax_size); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy_data(hOrdList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - - uiFinalLoc = uiOffsetSrc; - } - else - { - uiOffsetSrc = sizeof(OrdListHeader); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - - uiOffsetSrc = uiMax_size - uiSize_of_each; - uiOffsetDst = sizeof(OrdListHeader); - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - if (do_copy_data(hOrdList, pdata, uiOffsetSrc, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - return FALSE; - } - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, (uiMax_size-uiSize_of_each) - uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return FALSE; - } - } - - pTemp_cont->uiTail -= uiSize_of_each; - pTemp_cont->uiTotal_items--; - } // end if - - - return TRUE; -} - - - -//***************************************************************************** -// -// StoreinOrdList -// -// Parameter List : HORDLIST - handle to ordered list -// container -// data - data to add to the ordered list -// position - position after which data is to added -// -// Return Value BOOLEAN true if push ok -// else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// -//***************************************************************************** -HORDLIST StoreinOrdList(HORDLIST hOrdList, void *pdata, UINT32 uiPos) -{ - OrdListHeader *pTemp_cont; - UINT32 uiMax_size; - UINT32 uiSize_of_each; - UINT32 uiTotal; - UINT32 uiNew_size; - UINT32 uiHead; - UINT32 uiTail; - void *pvoid; - BYTE *pbyte; - UINT32 uiOffsetSrc; - UINT32 uiOffsetDst; - UINT32 uiFinalLoc = 0; - BOOLEAN fTail_check=FALSE; - - - // check for invalid handle = 0 - if (hOrdList == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This is not a valid handle to the ordered list"); - return NULL; - } - - // check for data = NULL - if (pdata == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Data to be pushed onto ordered list is NULL"); - return NULL; - } - - // assign some temporary variables - pTemp_cont = (OrdListHeader *)hOrdList; - - // check for invalid position - if (uiPos > pTemp_cont->uiTotal_items) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "There are not enough elements in the ordered list to add after"); - return NULL; - } - - - uiTotal = pTemp_cont->uiTotal_items; - uiSize_of_each = pTemp_cont->uiSiz_of_elem; - uiMax_size = pTemp_cont->uiMax_size; - uiHead = pTemp_cont->uiHead; - uiTail = pTemp_cont->uiTail; - uiOffsetSrc = pTemp_cont->uiHead + (uiPos * pTemp_cont->uiSiz_of_elem); - - - // this shouldn't be necessary? position should never be outside the range? - if (uiOffsetSrc >= uiMax_size) - uiOffsetSrc = sizeof(OrdListHeader) + (uiOffsetSrc - uiMax_size); - - if (uiTail == uiOffsetSrc) - fTail_check = TRUE; - - - // now copy the appropriate blocks to make room... - - if (((uiTail + uiSize_of_each) <= uiMax_size) && - ((uiTail > uiHead) || ((uiTail == uiHead) && (uiHead == sizeof(OrdListHeader))))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - - if (fTail_check == FALSE) - { - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in ordered list"); - return NULL; - } - } - - if (fTail_check == FALSE) - pTemp_cont->uiTail += uiSize_of_each; - - uiFinalLoc = uiOffsetSrc; - } - - - if ((((uiTail + uiSize_of_each) <= uiMax_size) && (uiTail < uiHead)) || - (((uiTail + uiSize_of_each) > uiMax_size) && (uiHead >= (sizeof(OrdListHeader) + uiSize_of_each)))) - { - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - - if (uiOffsetSrc >= uiMax_size) - { - uiOffsetSrc = sizeof(OrdListHeader) + (uiOffsetSrc - uiMax_size); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - - if (do_copy(hOrdList, uiOffsetDst, uiOffsetSrc, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - uiFinalLoc = uiOffsetSrc; - } - else - { - uiOffsetSrc = sizeof(OrdListHeader); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - - uiOffsetSrc = uiMax_size - uiSize_of_each; - uiOffsetDst = sizeof(OrdListHeader); - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiSize_of_each) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + uiSize_of_each; - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, (uiMax_size-uiSize_of_each) - uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - } - - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - } // end if - - - - if ((((uiTail + uiSize_of_each) <= uiMax_size) && (uiTail == uiHead) && (uiHead >= (sizeof(OrdListHeader) + uiSize_of_each))) - || (((uiTail + uiSize_of_each) > uiMax_size) && (uiHead == sizeof(OrdListHeader)))) - { - // need to resize the container - uiNew_size = uiMax_size + (uiMax_size - sizeof(OrdListHeader)); - pTemp_cont->uiMax_size = uiNew_size; - - if ((hOrdList = MemRealloc(hOrdList, uiNew_size)) == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not resize ordered list container memory"); - return NULL; - } - - pTemp_cont = (OrdListHeader *)hOrdList; - - if (do_copy(hOrdList, sizeof(OrdListHeader), uiMax_size, uiHead - sizeof(OrdListHeader)) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy ordered list container memory"); - return NULL; - } - - pTemp_cont->uiTail = uiMax_size + (uiHead-sizeof(OrdListHeader)); - - // now make place for the actual element - - uiOffsetSrc = pTemp_cont->uiHead + (uiPos*pTemp_cont->uiSiz_of_elem); - uiOffsetDst = uiOffsetSrc + pTemp_cont->uiSiz_of_elem; - - if (do_copy(hOrdList, uiOffsetSrc, uiOffsetDst, uiTail-uiOffsetSrc) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not store the data in list"); - return NULL; - } - pTemp_cont->uiTail += uiSize_of_each; - uiFinalLoc = uiOffsetSrc; - } - - if (uiFinalLoc == 0) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "This should never happen! report this problem!"); - return NULL; - } - - - // finally insert data at position uiFinalLoc - pbyte = (BYTE *)hOrdList; - pbyte += uiFinalLoc; - pvoid = (void *)pbyte; - memmove(pvoid, pdata, pTemp_cont->uiSiz_of_elem); - pTemp_cont->uiTotal_items++; - - if (fTail_check == TRUE) - pTemp_cont->uiTail += pTemp_cont->uiSiz_of_elem; - - return hOrdList; -} - - - -//***************************************************************************** -// -// AddtoOrdList -// -// Parameter List : HORDLIST - handle to ordered list -// container -// data - data to add to the ordered list -// -// Return Value BOOLEAN true if Add ok else false -// -// Modification History : -// Nov 26th 1996->modified for use by Wizardry -// Dec 19th 1997->verified, cleaned up, and heavily commented by AM -// -//***************************************************************************** -HORDLIST AddtoOrdList(HORDLIST hOrdList, void *pdata) -{ - OrdListHeader *pOrdList; - void *pTemp_data; - UINT32 uiOffset; - BOOLEAN fContinue = FALSE; - INT8 sbResult; - UINT32 uiPosition; - - - // get a pointer into the list header - pOrdList = (OrdListHeader *)hOrdList; - - - // if the list is empty or full) - if (pOrdList->uiHead == pOrdList->uiTail) - { - // if the head offset points to position 0, presumably that means it's empty (?) - if (pOrdList->uiHead == sizeof(OrdListHeader)) - { - // so store it in position 0 - if ((hOrdList = StoreinOrdList(hOrdList, pdata, 0)) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data into ordered list"); - return NULL; - } - - return hOrdList; - } - - // set flag to go through the while loop even though head == tail - fContinue = TRUE; - } - - - // grab enough space to store one list entry - pTemp_data = MemAlloc(pOrdList->uiSiz_of_elem); - - // start offset by pointing at the last entry in the the list - uiOffset = pOrdList->uiTail; - - // figure out the index of the entry that the tail points to - uiPosition = (pOrdList->uiTail - sizeof(OrdListHeader)) / pOrdList->uiSiz_of_elem; - - - // continue looping while offset hasn't reached the start of the list yet (or at least once if list is full) - while ((uiOffset != pOrdList->uiHead) || (fContinue)) - { - // when offset reaches the top of the list - if (uiOffset == sizeof(OrdListHeader)) - { - // wrap around to the very bottom of the list (guaranteed to hold data?) - uiOffset = pOrdList->uiMax_size; - uiPosition = (pOrdList->uiMax_size - sizeof(OrdListHeader)) / pOrdList->uiSiz_of_elem; - } - - // get entry data at the current offset position and store it in pTemp_data - if (do_copy_data(hOrdList, pTemp_data, (uiOffset - pOrdList->uiSiz_of_elem), pOrdList->uiSiz_of_elem ) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data from list"); - MemFree(pTemp_data); - return NULL; - } - - // run the compare function - sbResult = pOrdList->pCompare(pTemp_data, pdata, pOrdList->uiSiz_of_elem); - - // and do the right thing based on the result... - switch (sbResult) - { - case ORDLIST_ERROR : - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not perform comparison for ordered lists"); - MemFree(pTemp_data); - return NULL; - } - - case ORDLIST_EQUAL : - case ORDLIST_LEFT_LESS : - { - // found the right spot! Insert it at the current position - if ((hOrdList = StoreinOrdList(hOrdList, pdata, uiPosition)) == NULL) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data into ordered list"); - MemFree(pTemp_data); - return NULL; - } - return hOrdList; - } - - case ORDLIST_RIGHT_LESS : - { - // keep looking - uiOffset -= pOrdList->uiSiz_of_elem; - uiPosition--; - break; - } - - default : - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Invalid result received from Compare function"); - MemFree(pTemp_data); - return NULL; - } - } // end switch - - fContinue = FALSE; - } // end while - - - // don't need this anymore - MemFree(pTemp_data); - pTemp_data = NULL; - - - // never found the right spot, which means we must have reached the head (damn well better) - if (uiOffset != pOrdList->uiHead) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "ERROR - left the while loop but not at the head"); - return NULL; - } - - // the new item will be first in list, so calculate the position based on the head - uiPosition = (pOrdList->uiHead - sizeof(OrdListHeader)) / pOrdList->uiSiz_of_elem; - - // and stick it in there... - if ((hOrdList = StoreinOrdList(hOrdList, pdata, uiPosition)) == FALSE) - { - DbgMessage(TOPIC_ORDLIST_CONTAINERS, DBG_LEVEL_0, "Could not copy the data into ordered list"); - return NULL; - } - - - return hOrdList; -} - - - -INT8 Compare(void *p, void *q, UINT32 size) -{ - TEST *temp1; - TEST *temp2; - - - temp1 = (TEST *)p; - temp2 = (TEST *)q; - - if (temp1->me < temp2->me) - return ORDLIST_LEFT_LESS; - - if (temp1->me > temp2->me) - return ORDLIST_RIGHT_LESS; - - if (temp1->me == temp2->me) - return ORDLIST_EQUAL; - - return ORDLIST_ERROR; -} diff --git a/Standard Gaming Platform/Container.h b/Standard Gaming Platform/Container.h deleted file mode 100644 index 69dfe1f5..00000000 --- a/Standard Gaming Platform/Container.h +++ /dev/null @@ -1,132 +0,0 @@ -//*********************************************** -// -// Filename : Container.h -// -// Purpose : prototypes for the container file -// -// Modification History : 25 Nov 96 Creation -// -//*********************************************** - -#ifndef _CONTAINER_H -#define _CONTAINER_H - -//*********************************************** -// -// Includes -// -// -//*********************************************** - -#include "types.h" - -//*********************************************** -// -// Defines and typedefs -// -//*********************************************** -#define ORDLIST_ERROR -1 -#define ORDLIST_EQUAL 0 -#define ORDLIST_LEFT_LESS 1 -#define ORDLIST_RIGHT_LESS 2 - -typedef void * HCONTAINER; -typedef HCONTAINER HSTACK; -typedef HCONTAINER HQUEUE; -typedef HCONTAINER HLIST; -typedef HCONTAINER HORDLIST; - -//*********************************************** -// -// Function Prototypes -// -//*********************************************** -#ifdef __cplusplus -extern "C" { -#endif - -// call these functions to initialize and shutdown the debug messages for -// containers -extern void InitializeContainers(void); -extern void ShutdownContainers(void); - -// Stack Functions -// CreateStack(estimated number of items in stack, size of each item -// Push(handle to container returned from CreateStack, data to be passed in (must be void *) -// : returns handle to new stack -// Pop(handle to container returned from CreateStack, data to be passed in (must be void *) -// : returns BOOLEAN -// DeleteStack deletes the stack container -// StackSize returns size of stack - -extern HSTACK CreateStack(UINT32 num_of_elem , UINT32 siz_of_each); -extern HSTACK Push(HSTACK hStack, void *data); -extern BOOLEAN Pop(HSTACK hStack, void *data); -extern UINT32 StackSize(HSTACK hStack); -extern BOOLEAN DeleteStack(HSTACK hStack); -extern BOOLEAN PeekStack(HSTACK hStack, void *data); - -// Queue Functions -// CreateQueue(estimated number of items in queue, size of each item -// AddtoQueue(handle to container returned from CreateQueue, data to be passed in (must be void *)) -// : returns handle to queue -// RemfromQueue(handle to container returned from CreateQueue, variable where data is stored (must be void *)) -// : returns BOOLEAN -// PeekQueue(handle to the queue, variable where peeked data is stored). Item is not deleted. -// : returns BOOLEAN -// QueueSize(handle to the queue) returns the queue size -// DeleteQueue(handle to container) Delete the queue container -// : returns BOOLEAN - -extern HQUEUE CreateQueue(UINT32 num_of_elem, UINT32 siz_of_each); -extern HQUEUE AddtoQueue(HQUEUE hQueue, void *data); -extern BOOLEAN RemfromQueue(HQUEUE hQueue,void *data); -extern BOOLEAN PeekQueue(HQUEUE hQueue, void *data); -extern UINT32 QueueSize(HQUEUE hQueue); -extern BOOLEAN DeleteQueue(HQUEUE hQueue); - -// List Functions -// CreateList(estimated number of items in queue, size of each item -// AddtoList(handle to container returned from CreateQueue, data to be passed in (must be void *) -// position where data is to be added (0...sizeof(list)) -// : returns handle to new list -// RemfromList(handle to container returned from CreateList, variable where data is stored (must be void *) -// position where data is to be deleted (0...sizeof(list)-1) -// PeekList(handle to the list, variable where peeked data is stored). Item is not deleted. -// position where data is to be peeked (0...sizeof(list)-1) -// ListSize(handle to the list) returns the list size -// DeleteList(handle to the list) Delete the list container - -extern HLIST CreateList(UINT32 num_of_elem, UINT32 siz_of_each); -extern HLIST AddtoList(HLIST hList, void *data, UINT32 position); -extern BOOLEAN RemfromList(HLIST hList,void *data, UINT32 position); -extern BOOLEAN PeekList(HLIST hList, void *data, UINT32 position); -extern UINT32 ListSize(HLIST hList); -extern BOOLEAN DeleteList(HLIST hList); -extern BOOLEAN SwapListNode(HLIST hList, void *pdata, UINT32 uiPos); -extern BOOLEAN StoreListNode(HLIST hList, void *pdata, UINT32 uiPos); - -// Ordered List Functions -// CreateOrdList(estimated number of items in ordered list, size of each item, -// pointer to a compare function that returns info on whether the data in the ordered stack -// is < or > the new data to be added into the ordered list. -// AddtoOrdList(handle to container returned from CreateOrdList, data to be passed in (must be void *) -// RemfromOrdList(handle to container returned from CreateList, variable where data is stored (must be void *) -// position where data is to be deleted (0...sizeof(list)-1) -// PeekOrdList(handle to the list, variable where peeked data is stored). Item is not deleted. -// position where data is to be peeked (0...sizeof(list)-1) -// OrdListSize(handle to the list) returns the ordered list size -// DeleteOrdList(handle to the list) Delete the ordered list container - -extern HLIST CreateOrdList(UINT32 num_of_elem, UINT32 siz_of_each, INT8 (*compare)(void *,void *, UINT32)); -extern HLIST AddtoOrdList(HLIST hList, void *data); -extern BOOLEAN RemfromOrdList(HLIST hList,void *data, UINT32 position); -extern BOOLEAN PeekOrdList(HLIST hList, void *data, UINT32 position); -extern UINT32 OrdListSize(HLIST hList); -extern BOOLEAN DeleteOrdList(HLIST hList); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/Standard Gaming Platform/FileCat.cpp b/Standard Gaming Platform/FileCat.cpp deleted file mode 100644 index a977d597..00000000 --- a/Standard Gaming Platform/FileCat.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// -// Snap: Implementation of the TFileCat class -// -#include "FileCat.h" -#include "readdir.h" - - -// Remove a slash or backslash (if any) from the end of a string -void ChompSlash(std::string& s) -{ - if ( s.empty() ) return; - - if ( *s.rbegin() == '\\' || *s.rbegin() == '/' ) { - s.erase( s.length() - 1 ); - } -} - - -// Build a new file catalogue by recursively traversing the root directory -void TFileCat::NewCat(std::string root) -{ - fRootDir = root; - ChompSlash(fRootDir); - - fFileCat.clear(); - - TraverseDir(fRootDir); -} - - -// Look for a given file in the catalogue -// Unless pathIncludesRoot == true, will prepend the root directory to path -bool TFileCat::FindFile(std::string path, bool pathIncludesRoot) const -{ - if (pathIncludesRoot) return fFileCat.find(path) != fFileCat.end(); - else return fFileCat.find(fRootDir + '\\' + path) != fFileCat.end(); -} - - -// Delete a given file from the catalogue -// Unless pathIncludesRoot == true, will prepend the root directory to path -size_t TFileCat::RemoveFile(std::string path, bool pathIncludesRoot) -{ - if (pathIncludesRoot) return fFileCat.erase(path); - else return fFileCat.erase(fRootDir + '\\' + path); -} - - -// Delete all files from a given directory in the catalogue -// Unless pathIncludesRoot == true, will prepend the root directory to path -size_t TFileCat::RemoveDir(std::string dir, bool pathIncludesRoot) -{ - if ( !pathIncludesRoot ) dir = fRootDir + '\\' + dir; - ChompSlash(dir); - std::string dirlower = dir + '\\'; - std::string dirupper = dir + char('\\'+1); - - TCatalogue::iterator upper = fFileCat.upper_bound(dirupper); - TCatalogue::iterator lower; - - int deleted = 0; - - while ( ( lower = fFileCat.lower_bound(dirlower) ) != upper) { - fFileCat.erase(lower); - deleted++; - } - - return deleted; -} - - -// Recursively traverse a directory, adding regular files to the catalogue -void TFileCat::TraverseDir(std::string dir, int depth) -{ - using std::string; - static string dot( "."); - static string dotdot( ".."); - static string svn( ".svn"); - - if (!dir.empty()) dir += '\\'; - - TReadDir readDir((dir + "*").c_str()); - - char const* fileName; - unsigned attrib; - - while ( readDir.NextFile(fileName, attrib) ) { - if (dot == fileName || dotdot == fileName || svn == fileName) continue; - - string fullPath = dir + fileName; - - if (attrib & FILE_ATTRIBUTE_DIRECTORY) { - if (depth < 0) TraverseDir(fullPath); - else if (depth > 0) TraverseDir(fullPath, depth-1); - } - else { - fFileCat.insert(fullPath); - } - } -} diff --git a/Standard Gaming Platform/FileCat.h b/Standard Gaming Platform/FileCat.h deleted file mode 100644 index 38d1fc27..00000000 --- a/Standard Gaming Platform/FileCat.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Snap: Declaration of the TFileCat class -// -// This class catalogues files in a directory and all its subdirectories -// -#ifndef FILECAT_H -#define FILECAT_H - -#include "stringicmp.h" -#include -#include - - -class TFileCat { -public: - - TFileCat(std::string root) { NewCat(root); } - TFileCat() {} - - // Build a new file catalogue by recursively traversing the root directory - void NewCat(std::string root); - - std::string GetRootDir() const { return fRootDir; } - - // Look for a given file in the catalogue - // Unless pathIncludesRoot == true, will prepend the root directory to path - bool FindFile(std::string path, bool pathIncludesRoot = false) const; - - // Delete a given file from the catalogue - // Unless pathIncludesRoot == true, will prepend the root directory to path - size_t RemoveFile(std::string path, bool pathIncludesRoot = false); - - // Delete all files from a given directory in the catalogue - // Unless pathIncludesRoot == true, will prepend the root directory to path - size_t RemoveDir(std::string dir, bool pathIncludesRoot = false); - -private: - - typedef std::set TCatalogue; - - std::string fRootDir; - TCatalogue fFileCat; - - // Recursively traverse a directory, adding regular files to the catalogue - void TraverseDir(std::string dir, int depth = -1); -}; - -#endif // FILECAT_H diff --git a/Standard Gaming Platform/FileMan.cpp b/Standard Gaming Platform/FileMan.cpp deleted file mode 100644 index 0de5e3d8..00000000 --- a/Standard Gaming Platform/FileMan.cpp +++ /dev/null @@ -1,2596 +0,0 @@ -//************************************************************************** -// -// Filename : FileMan.c -// -// Purpose : function definitions for the memory manager -// -// Modification history : -// -// 24sep96:HJH ->creation -// 08Apr97:ARM ->Assign return value from Push() calls back to HStack -// handle, because it may possibly do a MemRealloc() -// 29Dec97:Kris Morness -// ->Added functionality for setting file attributes which -// allows for read-only attribute overriding -// ->Also added a simple function that clears all file attributes -// to normal. -// -// 5 Feb 98:Dave French->extensive modification to support libraries -// -//************************************************************************** - -//************************************************************************** -// -// Includes -// -//************************************************************************** - #include "Types.h" - #include - #include - #include - #include - - - #include "windows.h" - #include "FileMan.h" - #include "MemMan.h" - #include "Debug.h" - #include "RegInst.h" - #include "Container.h" - #include "LibraryDataBase.h" - #include "io.h" - #include "sgp_logger.h" - -using namespace std; - -#include -#include -#include - -#ifdef USE_VFS - -#include -#include -#include - -struct SOperation -{ - enum EOperation - { - UNKNOWN, READ, WRITE, - }; - EOperation op; - SOperation() : op(UNKNOWN) {}; -}; - -typedef std::map tFILEMAP; -static tFILEMAP s_mapFiles; - -#endif -//************************************************************************** -// -// Defines -// -//************************************************************************** - -#define FILENAME_LENGTH 600 - -#define CHECKF(exp) if (!(exp)) { return(FALSE); } -#define CHECKV(exp) if (!(exp)) { return; } -#define CHECKN(exp) if (!(exp)) { return(NULL); } -#define CHECKBI(exp) if (!(exp)) { return(-1); } - -#define PRINT_DEBUG_INFO FileDebugPrint(); - -//************************************************************************** -// -// Typedefs -// -//************************************************************************** - -typedef struct FMFileInfoTag -{ - CHAR strFilename[FILENAME_LENGTH]; - UINT8 uiFileAccess; - UINT32 uiFilePosition; - HANDLE hFileHandle; - -} FMFileInfo; // for 'File Manager File Information' - -typedef struct FileSystemTag -{ - FMFileInfo *pFileInfo; - UINT32 uiNumHandles; - BOOLEAN fDebug; - BOOLEAN fDBInitialized; - - CHAR *pcFileNames; - UINT32 uiNumFilesInDirectory; -} FileSystem; - -//************************************************************************** -// -// Variables -// -//************************************************************************** - - -//The FileDatabaseHeader -DatabaseManagerHeaderStruct gFileDataBase; - - -//FileSystem gfs; - -WIN32_FIND_DATA Win32FindInfo[20]; -BOOLEAN fFindInfoInUse[20] = {FALSE,FALSE,FALSE,FALSE,FALSE, - FALSE,FALSE,FALSE,FALSE,FALSE, - FALSE,FALSE,FALSE,FALSE,FALSE, - FALSE,FALSE,FALSE,FALSE,FALSE }; -HANDLE hFindInfoHandle[20] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, - INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, - INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, - INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, - INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, - INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, - INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, - INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, - INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, - INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; - -// Snap: At program launch we build two directory catalogues: -// one for the default Data directory, the other for the custom Data directory. -TFileCat gDefaultDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) -TFileCat gCustomDataCat; // Init in InitializeStandardGamingPlatform (sgp.cpp) - -//************************************************************************** -// -// Function Prototypes -// -//************************************************************************** - -void W32toSGPFileFind( GETFILESTRUCT *pGFStruct, WIN32_FIND_DATA *pW32Struct ); - -void FileDebugPrint( void ); -HANDLE GetHandleToRealFile( HWFILE hFile, BOOLEAN *pfDatabaseFile ); -HWFILE CreateFileHandle( HANDLE hRealFile, BOOLEAN fDatabaseFile ); -void DestroyFileHandle( HWFILE hFile ); -void BuildFileDirectory( void ); -INT32 GetFilesInDirectory( HCONTAINER hStack, CHAR *, HANDLE hFile, WIN32_FIND_DATA *pFind ); - -//************************************************************************** -// -// Functions -// -//************************************************************************** - -//************************************************************************** -// -// FileSystemInit -// -// Starts up the file system. -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -//************************************************************************** -BOOLEAN InitializeFileManager( STR strIndexFilename ) -{ - RegisterDebugTopic( TOPIC_FILE_MANAGER, "File Manager" ); - return( TRUE ); -} - - - -//************************************************************************** -// -// FileSystemShutdown -// -// Shuts down the file system. -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** - -void ShutdownFileManager( void ) -{ - UnRegisterDebugTopic( TOPIC_FILE_MANAGER, "File Manager" ); -} - -//************************************************************************** -// -// FileDebug -// -// To set whether or not we should print debug info. -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -//************************************************************************** - -void FileDebug( BOOLEAN f ) -{ -// gfs.fDebug = f; -} - -//************************************************************************** -// -// FileExists -// -// Checks if a file exists. -// -// Parameter List : -// -// STR ->name of file to check existence of -// -// Return Value : -// -// BOOLEAN ->TRUE if it exists -// ->FALSE if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -// Oct 2005: Snap - Rewrote, made to check data catalogues -// -//************************************************************************** -BOOLEAN FileExists( STR strFilename ) -{ -#ifdef USE_VFS - return getVFS()->fileExists(vfs::Path(strFilename)); -#else - // First check to see if it's in a library (most files should be there) - if ( gFileDataBase.fInitialized && - CheckIfFileExistInLibrary( strFilename ) ) return TRUE; - - // ... then check if it's in the custom Data directory - if ( gCustomDataCat.FindFile(strFilename) ) return TRUE; - - // ... then check if it's in the default Data directory - if ( gDefaultDataCat.FindFile(strFilename) ) return TRUE; - - // ... lastly, try to locate it in the file system - DWORD attribs = GetFileAttributes(strFilename); - if ( attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY) ) - return TRUE; - - return FALSE; -#endif -} - -//************************************************************************** -// -// FileExistsNoDB -// -// Checks if a file exists, but doesn't check the database files. -// -// Parameter List : -// -// STR ->name of file to check existence of -// -// Return Value : -// -// BOOLEAN ->TRUE if it exists -// ->FALSE if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// -// Oct 2005: Snap - Rewrote, made to check data catalogues -// -//************************************************************************** -extern BOOLEAN FileExistsNoDB( STR strFilename ) -{ -#ifdef USE_VFS - return getVFS()->fileExists(vfs::Path(strFilename)); -#else - // First check if it's in the custom Data directory - if ( gCustomDataCat.FindFile(strFilename) ) return TRUE; - - // ... then check if it's in the default Data directory - if ( gDefaultDataCat.FindFile(strFilename) ) return TRUE; - - // ... lastly, try to locate it in the file system - DWORD attribs = GetFileAttributes(strFilename); - if ( attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY) ) - return TRUE; - - return FALSE; -#endif -} - -//************************************************************************** -// -// FileDelete -// -// Deletes a file. -// -// Parameter List : -// -// STR ->name of file to delete -// -// Return Value : -// -// BOOLEAN ->TRUE if successful -// ->FALSE if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// -//************************************************************************** -BOOLEAN FileDelete( STR strFilename ) -{ -#ifdef USE_VFS - return getVFS()->removeFileFromFS(vfs::Path(strFilename)); -#else - // Snap: delete the file from the default Data catalogue (if it is there) - // Since the path can be either relative or absolute, try both methods - gDefaultDataCat.RemoveFile(strFilename, true); - gDefaultDataCat.RemoveFile(strFilename, false); - - return( DeleteFile( (LPCSTR) strFilename ) ); -#endif -} - -//************************************************************************** -// -// FileOpen -// -// Opens a file. -// -// Parameter List : -// -// STR ->filename -// UIN32 ->access - read or write, or both -// BOOLEAN ->delete on close -// -// Return Value : -// -// HWFILE ->handle of opened file -// -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -// Oct 2005: Snap - modified to work with the custom Data directory -// -//************************************************************************** -HWFILE FileOpen( STR strFilename, UINT32 uiOptions, BOOLEAN fDeleteOnClose, STR strProfilename )//dnl ch81 021213 -{ -#ifdef USE_VFS - vfs::Path path(strFilename); - vfs::IBaseFile *pFile = NULL; - try - { - if(uiOptions & FILE_ACCESS_WRITE) - { - // 'vfs::CVirtualFile::SF_TOP' should be enough, but if for some strange reason - // file creation fails, we will stop at a writable profile - // and won't unintentionally mess up a file from another profile - vfs::COpenWriteFile open_w( path, true, false, vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE); - pFile = &open_w.file(); - open_w.release(); - s_mapFiles[pFile].op = SOperation::WRITE; - return (HWFILE)pFile; - } - else if(uiOptions & FILE_ACCESS_READ) - { - if(strProfilename && strProfilename[0]) - { - vfs::COpenReadFile open_r(vfs::tReadableFile::cast(getVFS()->getFile(path, strProfilename))); - pFile = &open_r.file(); - open_r.release(); - } - else - { - vfs::COpenReadFile open_r(path, vfs::CVirtualFile::SF_TOP); - pFile = &open_r.file(); - open_r.release(); - } - s_mapFiles[pFile].op = SOperation::READ; - return (HWFILE)pFile; - } - } - // sometimes a file is supposed to opened that does not exist (not tested with FileExists()) - // this operation can fail with an exception that the calling code doesn't catch - // instead we catch it (any exception, not just CBasicException) here and return 0 - catch(vfs::Exception& ex) { SGP_ERROR(ex.what()); } - catch(...) - { - SGP_ERROR( "Caught undefined exception" ); - } - return 0; -#else - HWFILE hFile; - HANDLE hRealFile; - DWORD dwAccess; - DWORD dwFlagsAndAttributes; - BOOLEAN fExists; - HDBFILE hDBFile; - DWORD dwCreationFlags; - HWFILE hLibFile; - - hFile = 0; - hDBFile = 0; - dwCreationFlags = 0; - - dwAccess = 0; - if ( uiOptions & FILE_ACCESS_READ ) - dwAccess |= GENERIC_READ; - if ( uiOptions & FILE_ACCESS_WRITE ) - dwAccess |= GENERIC_WRITE; - - dwFlagsAndAttributes = FILE_FLAG_RANDOM_ACCESS; - if ( fDeleteOnClose ) - dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; - - // Snap: This seems like an unnecessary check, but I don't feel like - // rewriting the function to eliminate it... - - // check if the file exists - note that we use the function FileExistsNoDB - // because it doesn't check the databases, and we don't want to do that here - fExists = FileExistsNoDB( strFilename ); - - // Snap: First see if the file is in the custom Data catalogue: - std::string filePath; - if ( gCustomDataCat.FindFile(strFilename) ) { - filePath = gCustomDataCat.GetRootDir() + '\\'; - } - filePath += strFilename; - // Bad cast! strFilename should have been const. Oh well... - strFilename = const_cast( filePath.c_str() ); - // Now strFilename points either to the original file name, - // or to the full file path in the custom Data directory. - // Except for this substitution, the rest of the function is unchanged. - - //if the file is on the disk - if ( fExists ) - { - hRealFile = CreateFile( (LPCSTR) strFilename, dwAccess, 0, NULL, OPEN_ALWAYS, - dwFlagsAndAttributes, NULL ); - - if ( hRealFile == INVALID_HANDLE_VALUE ) - { - return(0); - } - - //create a file handle for the 'real file' - hFile = CreateRealFileHandle( hRealFile ); - } - - // if the file did not exist, try to open it from the database - else if ( gFileDataBase.fInitialized ) - { - //if the file is to be opened for writing, return an error cause you cant write a file that is in the database library - if( fDeleteOnClose ) - { - return( 0 ); - } - - //if the file doesnt exist on the harddrive, but it is to be created, dont try to load it from the file database - if( uiOptions & FILE_ACCESS_WRITE ) - { - //if the files is to be written to - if( ( uiOptions & FILE_CREATE_NEW ) || ( uiOptions & FILE_OPEN_ALWAYS ) || ( uiOptions & FILE_CREATE_ALWAYS ) || ( uiOptions & FILE_TRUNCATE_EXISTING ) ) - { - hFile = 0; - } - } - //else if the file is to be opened using FILE_OPEN_EXISTING, and the file doesnt exists, fail out of the function) -// else if( uiOptions & FILE_OPEN_EXISTING ) -// { - //fail out of the function -// return( 0 ); -// } - else - { - //If the file is in the library, get a handle to it. - hLibFile = OpenFileFromLibrary( strFilename ); - - //tried to open a file that wasnt in the database - if( !hLibFile ) - return( 0 ); - else - return( hLibFile ); //return the file handle - } - } - - if ( !hFile ) - { - if ( uiOptions & FILE_CREATE_NEW ) - { - dwCreationFlags = CREATE_NEW; - } - else if ( uiOptions & FILE_CREATE_ALWAYS ) - { - dwCreationFlags = CREATE_ALWAYS; - } - else if ( uiOptions & FILE_OPEN_EXISTING || uiOptions & FILE_ACCESS_READ ) - { - dwCreationFlags = OPEN_EXISTING; - } - else if ( uiOptions & FILE_OPEN_ALWAYS ) - { - dwCreationFlags = OPEN_ALWAYS; - } - else if ( uiOptions & FILE_TRUNCATE_EXISTING ) - { - dwCreationFlags = TRUNCATE_EXISTING; - } - else - { - dwCreationFlags = OPEN_ALWAYS; - } - - - hRealFile = CreateFile( (LPCSTR) strFilename, dwAccess, 0, NULL, dwCreationFlags, - dwFlagsAndAttributes, NULL ); - if ( hRealFile == INVALID_HANDLE_VALUE ) - { - UINT32 uiLastError = GetLastError(); - char zString[1024]; - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, uiLastError, 0, zString, 1024, NULL); - - return(0); - } - - hFile = CreateRealFileHandle( hRealFile ); - } - - if ( !hFile ) - return(0); - - return(hFile); -#endif -} - -//************************************************************************** -// -// FileClose -// -// -// Parameter List : -// -// HWFILE hFile ->handle to file to close -// -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** -void FileClose( HWFILE hFile ) -{ -#ifdef USE_VFS - vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; - if(pFile) - { - pFile->close(); - s_mapFiles.erase(pFile); - } -#else - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its the 'real file' library - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //if its not already closed - if( gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].uiFileID != 0 ) - { - CloseHandle( gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle ); - gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].uiFileID = 0; - gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle= 0; - gFileDataBase.RealFiles.iNumFilesOpen--; - if( gFileDataBase.RealFiles.iNumFilesOpen < 0 ) - { - //if for some reason we are below 0, report an error ( should never be ) - Assert( 0 ); - } - } - } - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - CloseLibraryFile( sLibraryID, uiFileNum ); - } -#endif -} - -//************************************************************************** -// -// FileRead -// -// To read a file. -// -// Parameter List : -// -// HWFILE ->handle to file to read from -// void * ->source buffer -// UINT32 ->num bytes to read -// UINT32 ->num bytes read -// -// Return Value : -// -// BOOLEAN ->TRUE if successful -// ->FALSE if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// 08Dec97:ARM ->return FALSE if bytes to read != bytes read -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** - -#ifdef JA2TESTVERSION - extern UINT32 uiTotalFileReadTime; - extern UINT32 uiTotalFileReadCalls; - #include "Timer Control.h" - -class TimeCounter -{ -public: - TimeCounter() : start_time(GetJA2Clock()) {} - ~TimeCounter() - { - uiTotalFileReadTime += GetJA2Clock() - start_time; - uiTotalFileReadCalls++; - } -private: - UINT32 start_time; -}; - -#endif - -BOOLEAN FileRead( HWFILE hFile, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead ) -{ -#ifdef USE_VFS -#ifdef JA2TESTVERSION - TimeCounter timer; -#endif - vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; - if(pFile && (s_mapFiles[pFile].op == SOperation::READ)) - { - vfs::tReadableFile *pRF = vfs::tReadableFile::cast(pFile); - if(pRF) - { - UINT32 uiBytesRead = 0; - try - { - uiBytesRead = pRF->read((vfs::Byte*)pDest, uiBytesToRead); - } - catch(std::exception& ex) - { - pRF->close(); - SGP_RETHROW(L"", ex); - } - - if(puiBytesRead) - { - *puiBytesRead = uiBytesRead; - } - if(uiBytesToRead != uiBytesRead) - { - return FALSE; - } - return TRUE; - } - } - return FALSE; -#else - HANDLE hRealFile; - DWORD dwNumBytesToRead, dwNumBytesRead; - BOOLEAN fRet = FALSE; - INT16 sLibraryID; - UINT32 uiFileNum; - -#ifdef JA2TESTVERSION - UINT32 uiStartTime = GetJA2Clock(); -#endif - - //init the variables - dwNumBytesToRead = dwNumBytesRead = 0; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - dwNumBytesToRead = (DWORD)uiBytesToRead; - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //if the file is opened - if( uiFileNum != 0 ) - { - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - fRet = ReadFile( hRealFile, pDest, dwNumBytesToRead, &dwNumBytesRead, NULL ); - if ( dwNumBytesToRead != dwNumBytesRead ) - { - UINT32 uiLastError = GetLastError(); - char zString[1024]; - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, uiLastError, 0, zString, 1024, NULL); - - fRet = FALSE; - } - - if ( puiBytesRead ) - *puiBytesRead = (UINT32)dwNumBytesRead; - } - } - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - { - //if the file is opened - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - //read the data from the library - fRet = LoadDataFromLibrary( sLibraryID, uiFileNum, pDest, dwNumBytesToRead, (UINT32 *) &dwNumBytesRead ); - if ( puiBytesRead ) - { - *puiBytesRead = (UINT32)dwNumBytesRead; - } - } - } - } - } - #ifdef JA2TESTVERSION - //Add the time that we spent in this function to the total. - uiTotalFileReadTime += GetJA2Clock() - uiStartTime; - uiTotalFileReadCalls++; - #endif - - return(fRet); -#endif -} - -BOOLEAN FileReadLine( HWFILE hFile, std::string* pDest ) -{ -#ifdef USE_VFS - vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; - if ( pFile && FileCheckEndOfFile( hFile ) == FALSE && (s_mapFiles[pFile].op == SOperation::READ) ) - { - vfs::tReadableFile *pRF = vfs::tReadableFile::cast( pFile ); - if ( pRF && pDest ) - { - vfs::CReadLine rl( *pRF, false ); - rl.getLine( *pDest ); - return TRUE; - } - } -#endif // ifdef USE_VFS - return FALSE; -} - -BOOLEAN FileReadLine( HWFILE hFile, STR8 pDest, UINT32 uiDestSize, UINT32 *puiBytesRead ) -{ - std::string sBuffer; - BOOLEAN result = (pDest != NULL) && FileReadLine( hFile, &sBuffer ); - if ( result ) - { - if ( puiBytesRead ) - *puiBytesRead = sBuffer.length(); - - UINT32 uiCountToCopy = min( sBuffer.length(), uiDestSize - 1 ); - sBuffer.copy( pDest, uiCountToCopy ); - pDest[uiCountToCopy] = '\0'; // method copy() does not put a null-terminator - } - return result; -} - -//************************************************************************** -// -// FileWrite -// -// To write a file. -// -// Parameter List : -// -// HWFILE ->handle to file to write to -// void * ->destination buffer -// UINT32 ->num bytes to write -// UINT32 ->num bytes written -// -// Return Value : -// -// BOOLEAN ->TRUE if successful -// ->FALSE if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// 08Dec97:ARM ->return FALSE if dwNumBytesToWrite != dwNumBytesWritten -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** - -BOOLEAN FileWrite( HWFILE hFile, PTR pDest, UINT32 uiBytesToWrite, UINT32 *puiBytesWritten ) -{ -#ifdef USE_VFS - if(uiBytesToWrite == 0)//dnl ch38 110909 - { - *puiBytesWritten = 0; - return(TRUE); - } - vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; - if(pFile && (s_mapFiles[pFile].op == SOperation::WRITE)) - { - vfs::tWritableFile *pWF = vfs::tWritableFile::cast(pFile); - if(pWF) - { - UINT32 uiBytesWritten; - try - { - uiBytesWritten = pWF->write((vfs::Byte*)pDest, uiBytesToWrite); - } - catch(std::exception& ex) - { - pWF->close(); - SGP_RETHROW(L"", ex); - } - - if (uiBytesToWrite != uiBytesWritten) - { - return FALSE; - } - if ( puiBytesWritten ) - { - *puiBytesWritten = uiBytesWritten; - } - return TRUE; - } - } - return FALSE; -#else - HANDLE hRealFile; - DWORD dwNumBytesToWrite, dwNumBytesWritten; - BOOLEAN fRet; - INT16 sLibraryID; - UINT32 uiFileNum; - - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - dwNumBytesToWrite = (DWORD)uiBytesToWrite; - - //get the real file handle to the file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - fRet = WriteFile( hRealFile, pDest, dwNumBytesToWrite, &dwNumBytesWritten, NULL ); - - if (dwNumBytesToWrite != dwNumBytesWritten) - fRet = FALSE; - - if ( puiBytesWritten ) - *puiBytesWritten = (UINT32)dwNumBytesWritten; - } - else - { - //we cannot write to a library file - if ( puiBytesWritten ) - *puiBytesWritten = 0; - return(FALSE); - } - - return(fRet); -#endif -} - -//************************************************************************** -// -// FileLoad -// -// To open, read, and close a file. -// -// Parameter List : -// -// -// Return Value : -// -// BOOLEAN ->TRUE if successful -// ->FALSE if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// 08Dec97:ARM ->return FALSE if bytes to read != bytes read (CHECKF is inappropriate?) -// -//************************************************************************** - -BOOLEAN FileLoad( STR strFilename, PTR pDest, UINT32 uiBytesToRead, UINT32 *puiBytesRead ) -{ -#ifdef USE_VFS - vfs::tReadableFile *pFile = getVFS()->getReadFile(vfs::Path(strFilename)); - vfs::COpenReadFile rfile(pFile); - if(pFile) - { - UINT32 uiNumBytesRead; - SGP_TRYCATCH_RETHROW(uiNumBytesRead = pFile->read((vfs::Byte*)pDest,uiBytesToRead), L""); - - if (uiBytesToRead != uiNumBytesRead) - { - return FALSE; - } - if ( puiBytesRead ) - { - *puiBytesRead = uiNumBytesRead; - } - CHECKF( uiNumBytesRead == uiBytesToRead ); - return TRUE; - } - return FALSE; -#else - HWFILE hFile; - UINT32 uiNumBytesRead; - BOOLEAN fRet; - - hFile = FileOpen( strFilename, FILE_ACCESS_READ, FALSE ); - if ( hFile ) - { - fRet = FileRead( hFile, pDest, uiBytesToRead, &uiNumBytesRead ); - FileClose( hFile ); - - if (uiBytesToRead != uiNumBytesRead) - fRet = FALSE; - - if ( puiBytesRead ) - *puiBytesRead = uiNumBytesRead; - - CHECKF( uiNumBytesRead == uiBytesToRead ); - } - else - fRet = FALSE; - - return(fRet); -#endif -} - -//************************************************************************** -// -// FilePrintf -// -// To printf to a file. -// -// Parameter List : -// -// HWFILE ->handle to file to seek in -// ... ->arguments, 1st of which should be a string -// -// Return Value : -// -// BOOLEAN ->TRUE if successful -// ->FALSE if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** -#ifndef DIM -# define DIM(x) (sizeof(x)/sizeof(x[0])) /* made StringLen Save, Sergeant_Kolja, 2007-06-10 */ -#endif - - -BOOLEAN _cdecl FilePrintf( HWFILE hFile, STR8 strFormatted, ... ) -{ -#ifdef USE_VFS - CHAR8 strToSend[160]; /* itemdescription of item 0 will NOT fit if only 80 Chars per Line!, Sergeant_Kolja, 2007-06-10 */ - va_list argptr; - BOOLEAN fRetVal = FALSE; - - va_start(argptr, strFormatted); - _vsnprintf( strToSend, DIM(strToSend), strFormatted, argptr ); /* made StringLen Save, Sergeant_Kolja, 2007-06-10 */ - strToSend[ DIM(strToSend)-1 ] = 0; - va_end(argptr); - - fRetVal = FileWrite( hFile, strToSend, strlen(strToSend), NULL ); - return( fRetVal ); -#else - CHAR8 strToSend[160]; /* itemdescription of item 0 will NOT fit if only 80 Chars per Line!, Sergeant_Kolja, 2007-06-10 */ - va_list argptr; - BOOLEAN fRetVal = FALSE; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - va_start(argptr, strFormatted); - _vsnprintf( strToSend, DIM(strToSend), strFormatted, argptr ); /* made StringLen Save, Sergeant_Kolja, 2007-06-10 */ - strToSend[ DIM(strToSend)-1 ] = 0; - va_end(argptr); - - fRetVal = FileWrite( hFile, strToSend, strlen(strToSend), NULL ); - } - else - { - //its a library file, cant write to it so return an error - fRetVal = FALSE; - } - - return( fRetVal ); -#endif -} - -//************************************************************************** -// -// FileSeek -// -// To seek to a position in a file. -// -// Parameter List : -// -// HWFILE ->handle to file to seek in -// UINT32 ->distance to seek -// UINT8 ->how to seek -// -// Return Value : -// -// BOOLEAN ->TRUE if successful -// ->FALSE if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** - -BOOLEAN FileSeek( HWFILE hFile, UINT32 uiDistance, UINT8 uiHow ) -{ -#ifdef USE_VFS - INT32 iDistance = (INT32)uiDistance; - - vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; - if(pFile) - { - vfs::IBaseFile::ESeekDir eSD; - if ( uiHow == FILE_SEEK_FROM_START ) - { - eSD = vfs::IBaseFile::SD_BEGIN; - } - else if ( uiHow == FILE_SEEK_FROM_END ) - { - eSD = vfs::IBaseFile::SD_END; - if( iDistance > 0 ) - { - iDistance = -(iDistance); - } - } - else - { - eSD = vfs::IBaseFile::SD_CURRENT; - } - - if(s_mapFiles[pFile].op == SOperation::WRITE) - { - vfs::tWritableFile *pWF = vfs::tWritableFile::cast(pFile); - if(pWF) - { - SGP_TRYCATCH_RETHROW(pWF->setWritePosition(iDistance, eSD), L""); - return TRUE; - } - } - else if(s_mapFiles[pFile].op == SOperation::READ) - { - vfs::tReadableFile *pRF = vfs::tReadableFile::cast(pFile); - if(pRF) - { - SGP_TRYCATCH_RETHROW(pRF->setReadPosition(iDistance, eSD), L""); - return TRUE; - } - } - else - { - SGP_THROW(L"unknown operation"); - } - } - return FALSE; -#else - HANDLE hRealFile; - LONG lDistanceToMove; - DWORD dwMoveMethod; - INT32 iDistance=0; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to the real file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - iDistance = (INT32) uiDistance; - - if ( uiHow == FILE_SEEK_FROM_START ) - dwMoveMethod = FILE_BEGIN; - else if ( uiHow == FILE_SEEK_FROM_END ) - { - dwMoveMethod = FILE_END; - if( iDistance > 0 ) - iDistance = -(iDistance); - } - else - dwMoveMethod = FILE_CURRENT; - - lDistanceToMove = (LONG)uiDistance; - - if ( SetFilePointer( hRealFile, iDistance, NULL, dwMoveMethod ) == 0xFFFFFFFF ) - return(FALSE); - } - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - LibraryFileSeek( sLibraryID, uiFileNum, uiDistance, uiHow ); - } - - return(TRUE); -#endif -} - -//************************************************************************** -// -// FileGetPos -// -// To get the current position in a file. -// -// Parameter List : -// -// HWFILE ->handle to file -// -// Return Value : -// -// INT32 ->current offset in file if successful -// ->-1 if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** - -INT32 FileGetPos( HWFILE hFile ) -{ -#ifdef USE_VFS - vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; - if(pFile && (s_mapFiles[pFile].op == SOperation::WRITE)) - { - vfs::tWritableFile *pWF = vfs::tWritableFile::cast(pFile); - if(pWF) - { - return pWF->getWritePosition(); - } - } - else if(pFile && (s_mapFiles[pFile].op == SOperation::READ)) - { - vfs::tReadableFile *pRF = vfs::tReadableFile::cast(pFile); - if(pRF) - { - return pRF->getReadPosition(); - } - } - - return BAD_INDEX; -#else - HANDLE hRealFile; - UINT32 uiPositionInFile=0; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to the real file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - uiPositionInFile = SetFilePointer( hRealFile, 0, NULL, FILE_CURRENT); - if( uiPositionInFile == 0xFFFFFFFF ) - { - uiPositionInFile = 0; - } - return( uiPositionInFile ); - } - else - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - { - //check if the file is open - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - uiPositionInFile = gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFilePosInFile; - return( uiPositionInFile ); - } - } - } - - return(BAD_INDEX); -#endif -} - -//************************************************************************** -// -// FileGetSize -// -// To get the current file size. -// -// Parameter List : -// -// HWFILE ->handle to file -// -// Return Value : -// -// INT32 ->file size in file if successful -// ->0 if not -// -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** - -UINT32 FileGetSize( HWFILE hFile ) -{ -#ifdef USE_VFS - vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; - if(pFile) - { - return pFile->getSize(); - } - return 0; -#else - HANDLE hRealHandle; - UINT32 uiFileSize = 0xFFFFFFFF; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to a real file - hRealHandle = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - uiFileSize = GetFileSize( hRealHandle, NULL ); - } - else - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - uiFileSize = gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].pFileHeader->uiFileLength; - } - - - if ( uiFileSize == 0xFFFFFFFF ) - return(0); - else - return( uiFileSize ); -#endif -} - -//************************************************************************** -// -// FileDebugPrint -// -// To print the state of memory to output. -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -//************************************************************************** - -void FileDebugPrint( void ) -{ -} - -//************************************************************************** -// -// GetHandleToRealFile -// -// -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -// 9 Feb 98 DEF - modified to work with the library system -// -//************************************************************************** - -HANDLE GetHandleToRealFile( HWFILE hFile, BOOLEAN *pfDatabaseFile ) -{ - HANDLE hRealFile; - - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to the real file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - *pfDatabaseFile = FALSE; - } - else - { - *pfDatabaseFile = TRUE; - hRealFile = (HANDLE) hFile; - } - - return(hRealFile); -} - -//************************************************************************** -// -// CreateFileHandle -// -// -// -// Parameter List : -// Return Value : -// Modification history : -// -// 24sep96:HJH ->creation -// -//************************************************************************** -/* - - not needed anymore - -HWFILE CreateFileHandle( HANDLE hRealFile, BOOLEAN fDatabaseFile ) -{ - UINT32 i, uiOldNumHandles; - FMFileInfo *pNewFileInfo; - - Assert( !fDatabaseFile || (fDatabaseFile && gfs.fDBInitialized) ); - - // don't use 1st position - it'll confuse the users - for ( i=1 ; icreation -// -//************************************************************************** -/* -void DestroyFileHandle( HWFILE hFile ) -{ - if ( hFile < gfs.uiNumHandles && hFile ) - { - gfs.pFileInfo[hFile].hFileHandle = 0; - gfs.pFileInfo[hFile].hDBFile = 0; - } -} -*/ - - - -//************************************************************************** -// -// BuildFileDirectory -// -// -// -// Parameter List : -// Return Value : -// Modification history : -// -// ??nov96:HJH ->creation -// -//************************************************************************** - -void BuildFileDirectory( void ) -{ - - return; // temporary until container stuff is fixed -/* - INT32 i, iNumFiles = 0; - HANDLE hFile, hFileIn; - WIN32_FIND_DATA find, inFind; - BOOLEAN fMore = TRUE; - CHAR cName[FILENAME_LENGTH], cDir[FILENAME_LENGTH], cSubDir[FILENAME_LENGTH]; - HCONTAINER hStack; - - - - // - // First, push all the file names in the directory (and subdirectories) - // onto the stack. - // - - GetProfileChar( "Startup", "InstPath", "", cDir ); - - if ( strlen( cDir ) == 0 ) - return; - - hStack = CreateStack( 100, FILENAME_LENGTH ); - if (hStack == NULL) - { - FastDebugMsg(String("BuildFileDirectory: CreateStack Failed for the filename stack")); - return; - } - - find.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - - strcpy( &(cDir[strlen(cDir)]), "\\*.*\0" ); - hFile = FindFirstFile( cDir, &find ); - while ( fMore ) - { - if ( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) - { - if ( strcmp( find.cFileName, "." ) != 0 && strcmp( find.cFileName, ".." ) != 0 ) - { - // a valid directory - inFind.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - strcpy( cSubDir, cDir ); - strcpy( &(cSubDir[strlen(cDir)-3]), find.cFileName ); - strcpy( &(cSubDir[strlen(cSubDir)]), "\\*.*\0" ); - hFileIn = FindFirstFile( cSubDir, &inFind ); - iNumFiles += GetFilesInDirectory( hStack, cSubDir, hFileIn, &inFind ); - FindClose( hFileIn ); - } - } - else - { - iNumFiles++; - strcpy( cName, cDir ); - strcpy( &(cName[strlen(cName)-3]), find.cFileName ); - CharLower( cName ); - hStack = Push( hStack, cName ); - } - find.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - fMore = FindNextFile( hFile, &find ); - } - FindClose( hFile ); - - // - // Okay, we have all the files in the stack, now put them in place. - // - gfs.uiNumFilesInDirectory = iNumFiles; - - gfs.pcFileNames = (STR8)MemAlloc( iNumFiles * FILENAME_LENGTH ); - - if ( gfs.pcFileNames ) - { - for ( i=0 ; icreation -// -//************************************************************************** - -INT32 GetFilesInDirectory( HCONTAINER hStack, CHAR *pcDir, HANDLE hFile, WIN32_FIND_DATA *pFind ) -{ - INT32 iNumFiles; - WIN32_FIND_DATA inFind; - BOOLEAN fMore; - CHAR cName[FILENAME_LENGTH], cDir[FILENAME_LENGTH]; - HANDLE hFileIn; - - fMore = TRUE; - iNumFiles = 0; - - while ( fMore ) - { - if ( pFind->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) - { - if ( strcmp( pFind->cFileName, "." ) != 0 && strcmp( pFind->cFileName, ".." ) != 0 ) - { - // a valid directory - recurse and find the files in that directory - - inFind.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - strcpy( cDir, pcDir ); - strcpy( &(cDir[strlen(cDir)-3]), pFind->cFileName ); - strcpy( &(cDir[strlen(cDir)]), "\\*.*\0" ); - hFileIn = FindFirstFile( cDir, &inFind ); - iNumFiles += GetFilesInDirectory( hStack, cDir, hFileIn, &inFind ); - FindClose( hFileIn ); - } - } - else - { - iNumFiles++; - strcpy( cName, pcDir ); - strcpy( &(cName[strlen(cName)-3]), pFind->cFileName ); - CharLower( cName ); - hStack = Push( hStack, cName ); - } - pFind->dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY; - fMore = FindNextFile( hFile, pFind ); - } - - return(iNumFiles); -} - -BOOLEAN SetFileManCurrentDirectory( STR pcDirectory ) -{ -#ifndef USE_VFS - return( SetCurrentDirectory( pcDirectory ) ); -#else - try - { - vfs::OS::setCurrectDirectory(pcDirectory); - } - catch(vfs::Exception& ex) - { - SGP_ERROR(ex.what()); - return FALSE; - } - return TRUE; -#endif -} - - -BOOLEAN GetFileManCurrentDirectory( STRING512 pcDirectory ) -{ -#ifndef USE_VFS - if (GetCurrentDirectory( 512, pcDirectory ) == 0) - { - return( FALSE ); - } - return( TRUE ); -#else - try - { - vfs::Path sDir; - vfs::OS::getCurrentDirectory(sDir); - strncpy(pcDirectory, sDir.to_string().c_str(), 512); - } - catch(vfs::Exception& ex) - { - SGP_ERROR(ex.what()); - return FALSE; - } - return TRUE; -#endif -} - - -BOOLEAN DirectoryExists( STRING512 pcDirectory ) -{ - UINT32 uiAttribs; - DWORD uiLastError; - - uiAttribs = GetFileAttributes( pcDirectory ); - - if ( uiAttribs == 0xFFFFFFFF ) - { - // an error, make sure it's the right error - uiLastError = GetLastError(); - - if (uiLastError != ERROR_FILE_NOT_FOUND) - { - FastDebugMsg(String("DirectoryExists: ERROR - GetFileAttributes failed, error #%d on file %s", uiLastError, pcDirectory)); - } - } - else - { - // something's there, make sure it's a directory - if ( uiAttribs & FILE_ATTRIBUTE_DIRECTORY ) - { - return TRUE; - } - } - - // this could also mean that the name given is that of a file, or that an error occurred - return FALSE; -} - - -BOOLEAN MakeFileManDirectory( STRING512 pcDirectory ) -{ -#ifndef USE_VFS - return CreateDirectory( pcDirectory, NULL ); -#else - return FALSE; -#endif -} - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Removes ALL FILES in the specified directory (and all subdirectories with their files if fRecursive is TRUE) -// Use EraseDirectory() to simply delete directory contents without deleting the directory itself -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -BOOLEAN RemoveFileManDirectory( STRING512 pcDirectory, BOOLEAN fRecursive ) -{ -#ifdef USE_VFS - // ignore 'recursive' flag, just delete every file in that subtree (but leave the directories) - return getVFS()->removeDirectoryFromFS(pcDirectory); -#else - WIN32_FIND_DATA sFindData; - HANDLE SearchHandle; - const CHAR8 *pFileSpec = "*.*"; - BOOLEAN fDone = FALSE; - BOOLEAN fRetval=FALSE; - CHAR8 zOldDir[512]; - CHAR8 zSubdirectory[512]; - - GetFileManCurrentDirectory( zOldDir ); - - if( !SetFileManCurrentDirectory( pcDirectory ) ) - { - FastDebugMsg(String("RemoveFileManDirectory: ERROR - SetFileManCurrentDirectory on %s failed, error %d", pcDirectory, GetLastError())); - return( FALSE ); //Error going into directory - } - - //If there are files in the directory, DELETE THEM - SearchHandle = FindFirstFile( pFileSpec, &sFindData); - if( SearchHandle != INVALID_HANDLE_VALUE ) - { - - fDone = FALSE; - do - { - // if the object is a directory - if( GetFileAttributes( sFindData.cFileName ) == FILE_ATTRIBUTE_DIRECTORY ) - { - // only go in if the fRecursive flag is TRUE (like Deltree) - if (fRecursive) - { - sprintf(zSubdirectory, "%s\\%s", pcDirectory, sFindData.cFileName); - - if ((strcmp(sFindData.cFileName, ".") != 0) && (strcmp(sFindData.cFileName, "..") != 0)) - { - if (!RemoveFileManDirectory(zSubdirectory, TRUE)) - { - FastDebugMsg(String("RemoveFileManDirectory: ERROR - Recursive call on %s failed", zSubdirectory)); - break; - } - } - } - // otherwise, all the individual files will be deleted, but the subdirectories remain, causing - // RemoveDirectory() at the end to fail, thus this function will return FALSE in that event (failure) - } - else - { - FileDelete( sFindData.cFileName ); - } - - //find the next file in the directory - fRetval = FindNextFile( SearchHandle, &sFindData ); - if( fRetval == 0 ) - { - fDone = TRUE; - } - } while(!fDone); - - // very important: close the find handle, or subsequent RemoveDirectory() calls will fail - FindClose( SearchHandle ); - } - - if( !SetFileManCurrentDirectory( zOldDir ) ) - { - FastDebugMsg(String("RemoveFileManDirectory: ERROR - SetFileManCurrentDirectory on %s failed, error %d", zOldDir, GetLastError())); - return( FALSE ); //Error returning from subdirectory - } - - - // The directory MUST be empty - fRetval = RemoveDirectory( pcDirectory ); - if (!fRetval) - { - FastDebugMsg(String("RemoveFileManDirectory: ERROR - RemoveDirectory on %s failed, error %d", pcDirectory, GetLastError())); - } - - return fRetval; -#endif -} - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Removes ALL FILES in the specified directory but leaves the directory alone. Does not affect any subdirectories! -// Use RemoveFilemanDirectory() to also delete the directory itself, or to recursively delete subdirectories. -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -BOOLEAN EraseDirectory( STRING512 pcDirectory) -{ -#ifdef USE_VFS - // ignore 'recursive' flag, just delete every file in that subtree (but leave the directories) - return getVFS()->removeDirectoryFromFS(pcDirectory); -#else - WIN32_FIND_DATA sFindData; - HANDLE SearchHandle; - const CHAR8 *pFileSpec = "*.*"; - BOOLEAN fDone = FALSE; - CHAR8 zOldDir[512]; - - GetFileManCurrentDirectory( zOldDir ); - - if( !SetFileManCurrentDirectory( pcDirectory ) ) - { - FastDebugMsg(String("EraseDirectory: ERROR - SetFileManCurrentDirectory on %s failed, error %d", pcDirectory, GetLastError())); - return( FALSE ); //Error going into directory - } - - //If there are files in the directory, DELETE THEM - SearchHandle = FindFirstFile( pFileSpec, &sFindData); - if( SearchHandle != INVALID_HANDLE_VALUE ) - { - - fDone = FALSE; - do - { - // if it's a file, not a directory - if( GetFileAttributes( sFindData.cFileName ) != FILE_ATTRIBUTES_DIRECTORY ) - { - FileDelete( sFindData.cFileName ); - } - - //find the next file in the directory - if ( !FindNextFile( SearchHandle, &sFindData )) - { - fDone = TRUE; - } - } while(!fDone); - - // very important: close the find handle, or subsequent RemoveDirectory() calls will fail - FindClose( SearchHandle ); - } - - // Snap: Delete the directory from the default Data catalogue (if it is there) - // Since the path can be either relative or absolute, try both methods - gDefaultDataCat.RemoveDir(pcDirectory, true); - gDefaultDataCat.RemoveDir(pcDirectory, false); - - if( !SetFileManCurrentDirectory( zOldDir ) ) - { - FastDebugMsg(String("EraseDirectory: ERROR - SetFileManCurrentDirectory on %s failed, error %d", zOldDir, GetLastError())); - return( FALSE ); //Error returning from directory - } - - return( TRUE ); -#endif -} - - -BOOLEAN GetExecutableDirectory( STRING512 pcDirectory ) -{ -#ifdef USE_VFS - vfs::Path exe_dir, exe_file; - vfs::OS::getExecutablePath(exe_dir, exe_file); - strncpy(pcDirectory, exe_dir.to_string().c_str(), 512); - return true; -#else - SGPFILENAME ModuleFilename; - UINT32 cnt; - - if ( GetModuleFileName( NULL, ModuleFilename, sizeof( ModuleFilename ) ) == 0 ) - { - return( FALSE ); - } - - // Now get directory - strcpy( pcDirectory, ModuleFilename ); - - for ( cnt = strlen( pcDirectory ) - 1; cnt >= 0; cnt -- ) - { - if ( pcDirectory[ cnt ] == '\\' ) - { - pcDirectory[ cnt ] = '\0'; - break; - } - } -#endif - return( TRUE ); -} - -#ifdef USE_VFS -static vfs::CVirtualFileSystem::Iterator file_iter; -#endif -BOOLEAN GetFileFirst( CHAR8 * pSpec, GETFILESTRUCT *pGFStruct ) -{ -#ifdef USE_VFS - CHECKF( pSpec != NULL ); - CHECKF( pGFStruct != NULL ); - - file_iter = getVFS()->begin(pSpec); - if(!file_iter.end()) - { - vfs::Path const& path = file_iter.value()->getName(); - std::string s = path.to_string(); - ::size_t size = s.length(); - size = std::min< ::size_t>(size,260-1); - sprintf( pGFStruct->zFileName, s.c_str()); - pGFStruct->zFileName[size] = 0; - - pGFStruct->iFindHandle = 0; - pGFStruct->uiFileSize = file_iter.value()->getSize(); - pGFStruct->uiFileAttribs = ( file_iter.value()->implementsWritable() ? FILE_IS_NORMAL : FILE_IS_READONLY ); - - return TRUE; - } - return FALSE; -#else - INT32 x,iWhich=0; - BOOLEAN fFound; - - CHECKF( pSpec != NULL ); - CHECKF( pGFStruct != NULL ); - - fFound = FALSE; - for( x = 0; x < 20 && !fFound; x++) - { - if( !fFindInfoInUse[x] ) - { - iWhich = x; - fFound = TRUE; - } - } - - if ( !fFound ) - return(FALSE); - - pGFStruct->iFindHandle = iWhich; - - hFindInfoHandle[iWhich] = FindFirstFile( pSpec, &Win32FindInfo[iWhich] ); - - if ( hFindInfoHandle[iWhich] == INVALID_HANDLE_VALUE ) - return(FALSE); - fFindInfoInUse[iWhich] = TRUE; - - W32toSGPFileFind( pGFStruct, &Win32FindInfo[iWhich] ); - - return(TRUE); -#endif -} - -BOOLEAN GetFileNext( GETFILESTRUCT *pGFStruct ) -{ -#ifdef USE_VFS - if(!file_iter.end()) - { - file_iter.next(); - } - if(!file_iter.end()) - { - vfs::Path const& path = file_iter.value()->getName(); - std::string s = path.to_string(); - ::size_t size = s.length(); - size = std::min< ::size_t>(size,260-1); - sprintf( pGFStruct->zFileName, s.c_str()); - pGFStruct->zFileName[size] = 0; - - pGFStruct->iFindHandle = 0; - pGFStruct->uiFileSize = file_iter.value()->getSize(); - pGFStruct->uiFileAttribs = ( file_iter.value()->implementsWritable() ? FILE_IS_NORMAL : FILE_IS_READONLY ); - - return TRUE; - } - return FALSE; -#else - CHECKF( pGFStruct != NULL ); - - if ( FindNextFile(hFindInfoHandle[pGFStruct->iFindHandle], &Win32FindInfo[pGFStruct->iFindHandle]) ) - { - W32toSGPFileFind( pGFStruct, &Win32FindInfo[pGFStruct->iFindHandle] ); - return(TRUE); - } - return(FALSE); -#endif -} - -void GetFileClose( GETFILESTRUCT *pGFStruct ) -{ -#ifdef USE_VFS - file_iter = vfs::CVirtualFileSystem::Iterator(); -#else - if ( pGFStruct == NULL ) - return; - - FindClose( hFindInfoHandle[pGFStruct->iFindHandle] ); - hFindInfoHandle[pGFStruct->iFindHandle] = INVALID_HANDLE_VALUE; - fFindInfoInUse[pGFStruct->iFindHandle] = FALSE; - - return; -#endif -} - -void W32toSGPFileFind( GETFILESTRUCT *pGFStruct, WIN32_FIND_DATA *pW32Struct ) -{ - UINT32 uiAttribMask; - - // Copy the filename - strcpy(pGFStruct->zFileName, pW32Struct->cFileName); - - // Get file size - if ( pW32Struct->nFileSizeHigh != 0 ) - pGFStruct->uiFileSize = 0xffffffff; - else - pGFStruct->uiFileSize = pW32Struct->nFileSizeLow; - - // Copy the file attributes - pGFStruct->uiFileAttribs = 0; - - for( uiAttribMask = 0x80000000; uiAttribMask > 0; uiAttribMask >>= 1) - { - switch( pW32Struct->dwFileAttributes & uiAttribMask ) - { - case FILE_ATTRIBUTE_ARCHIVE: - pGFStruct->uiFileAttribs |= FILE_IS_ARCHIVE; - break; - - case FILE_ATTRIBUTE_DIRECTORY: - pGFStruct->uiFileAttribs |= FILE_IS_DIRECTORY; - break; - - case FILE_ATTRIBUTE_HIDDEN: - pGFStruct->uiFileAttribs |= FILE_IS_HIDDEN; - break; - - case FILE_ATTRIBUTE_NORMAL: - pGFStruct->uiFileAttribs |= FILE_IS_NORMAL; - break; - - case FILE_ATTRIBUTE_READONLY: - pGFStruct->uiFileAttribs |= FILE_IS_READONLY; - break; - - case FILE_ATTRIBUTE_SYSTEM: - pGFStruct->uiFileAttribs |= FILE_IS_SYSTEM; - break; - - case FILE_ATTRIBUTE_TEMPORARY: - pGFStruct->uiFileAttribs |= FILE_IS_TEMPORARY; - break; - - case FILE_ATTRIBUTE_COMPRESSED: - pGFStruct->uiFileAttribs |= FILE_IS_COMPRESSED; - break; - - case FILE_ATTRIBUTE_OFFLINE: - pGFStruct->uiFileAttribs |= FILE_IS_OFFLINE; - break; - } - } -} - - - -BOOLEAN FileCopy(STR strSrcFile, STR strDstFile, BOOLEAN fFailIfExists) -{ - return(CopyFile(strSrcFile, strDstFile, fFailIfExists)); - -// Not needed, use Windows CopyFile -/* - HWFILE hFile; - UINT32 uiSize; - CHAR *pBuffer; - UINT32 uiBytesRead, uiBytesWritten; - - - // open source file - hFile = FileOpen(strSrcFile, FILE_ACCESS_READ, FALSE); - if (hFile == 0) - { - FastDebugMsg(String("FileCopy: FileOpen failed on Src file %s", strSrcFile)); - return(FALSE); - } - - // get its size - uiSize = FileGetSize(hFile); - if (uiSize == 0) - { - FastDebugMsg(String("FileCopy: size is 0, Src file %s", strSrcFile)); - FileClose(hFile); - return(FALSE); - } - - // allocate a buffer big enough to hold the entire file - pBuffer = MemAlloc(uiSize); - if (pBuffer == NULL) - { - FastDebugMsg(String("FileCopy: ERROR - MemAlloc pBuffer failed, size %d", uiSize)); - FileClose(hFile); - return(FALSE); - } - - // read the file into memory - if (!FileRead(hFile, pBuffer, uiSize, &uiBytesRead)) - { - FastDebugMsg(String("FileCopy: FileRead failed, file %s", strSrcFile)); - FileClose(hFile); - return(FALSE); - } - - // close source file - FileClose(hFile); - - - // open destination file - hFile = FileOpen(strDstFile, FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE); - if (hFile == 0) - { - FastDebugMsg(String("FileCopy: FileOpen failed on Dst file %s", strDstFile)); - return(FALSE); - } - - // write buffer to the destination file - if (!FileWrite(hFile, pBuffer, uiSize, &uiBytesWritten)) - { - FastDebugMsg(String("FileCopy: FileWrite failed, file %s", strDstFile)); - FileClose(hFile); - return(FALSE); - } - - // close destination file - FileClose(hFile); - - - MemFree(pBuffer); - pBuffer = NULL; - return(TRUE); -*/ -} - -BOOLEAN FileMove(STR strOldName, STR strNewName) -{ - // rename - return(MoveFile(strOldName, strNewName)); -} - -//Additions by Kris Morness -BOOLEAN FileSetAttributes( STR strFilename, UINT32 uiNewAttribs ) -{ - UINT32 uiFileAttrib = 0; - - if( uiNewAttribs & FILE_ATTRIBUTES_ARCHIVE ) - uiFileAttrib |= FILE_ATTRIBUTE_ARCHIVE; - - if( uiNewAttribs & FILE_ATTRIBUTES_HIDDEN ) - uiFileAttrib |= FILE_ATTRIBUTE_HIDDEN; - - if( uiNewAttribs & FILE_ATTRIBUTES_NORMAL ) - uiFileAttrib |= FILE_ATTRIBUTE_NORMAL; - - if( uiNewAttribs & FILE_ATTRIBUTES_OFFLINE ) - uiFileAttrib |= FILE_ATTRIBUTE_OFFLINE; - - if( uiNewAttribs & FILE_ATTRIBUTES_READONLY ) - uiFileAttrib |= FILE_ATTRIBUTE_READONLY; - - if( uiNewAttribs & FILE_ATTRIBUTES_SYSTEM ) - uiFileAttrib |= FILE_ATTRIBUTE_SYSTEM; - - if( uiNewAttribs & FILE_ATTRIBUTES_TEMPORARY ) - uiFileAttrib |= FILE_ATTRIBUTE_TEMPORARY; - - return SetFileAttributes( strFilename, uiFileAttrib ); -} - - -UINT32 FileGetAttributes( STR strFilename ) -{ - UINT32 uiAttribs = 0; - UINT32 uiFileAttrib = 0; - - uiAttribs = GetFileAttributes( strFilename ); - - if( uiAttribs == 0xFFFFFFFF ) - return( uiAttribs ); - - if( uiAttribs & FILE_ATTRIBUTE_ARCHIVE ) - uiFileAttrib |= FILE_ATTRIBUTES_ARCHIVE; - - if( uiAttribs & FILE_ATTRIBUTE_HIDDEN ) - uiFileAttrib |= FILE_ATTRIBUTES_HIDDEN; - - if( uiAttribs & FILE_ATTRIBUTE_NORMAL ) - uiFileAttrib |= FILE_ATTRIBUTES_NORMAL; - - if( uiAttribs & FILE_ATTRIBUTE_OFFLINE ) - uiFileAttrib |= FILE_ATTRIBUTES_OFFLINE; - - if( uiAttribs & FILE_ATTRIBUTE_READONLY ) - uiFileAttrib |= FILE_ATTRIBUTES_READONLY; - - if( uiAttribs & FILE_ATTRIBUTE_SYSTEM ) - uiFileAttrib |= FILE_ATTRIBUTES_SYSTEM; - - if( uiAttribs & FILE_ATTRIBUTE_TEMPORARY ) - uiFileAttrib |= FILE_ATTRIBUTES_TEMPORARY; - - if( uiAttribs & FILE_ATTRIBUTE_DIRECTORY ) - uiFileAttrib |= FILE_ATTRIBUTES_DIRECTORY; - - - - return( uiFileAttrib ); -} - -BOOLEAN FileClearAttributes( STR strFilename ) -{ -#ifndef USE_VFS - return SetFileAttributes( (LPCSTR) strFilename, FILE_ATTRIBUTE_NORMAL ); -#else - return TRUE; -#endif -} - - -//returns true if at end of file, else false -BOOLEAN FileCheckEndOfFile( HWFILE hFile ) -{ -#ifdef USE_VFS - vfs::size_t current_position, max_position; - vfs::IBaseFile *pFile = (vfs::IBaseFile*)hFile; - - if(pFile && (s_mapFiles[pFile].op == SOperation::WRITE)) - { - vfs::tWritableFile *pWF = vfs::tWritableFile::cast(pFile); - if(pWF) - { - current_position = pWF->getWritePosition(); - max_position = pWF->getSize(); - return current_position >= max_position; - } - } - else if(pFile && (s_mapFiles[pFile].op == SOperation::READ)) - { - vfs::tReadableFile *pRF = vfs::tReadableFile::cast(pFile); - if(pRF) - { - current_position = pRF->getReadPosition(); - max_position = pRF->getSize(); - return current_position >= max_position; - } - } - return FALSE; -#else - INT16 sLibraryID; - UINT32 uiFileNum; - HANDLE hRealFile; -// UINT8 Data; - UINT32 uiOldFilePtrLoc=0; - UINT32 uiEndOfFilePtrLoc=0; - UINT32 temp=0; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //Get the handle to the real file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - //Get the current position of the file pointer - uiOldFilePtrLoc = SetFilePointer( hRealFile, 0, NULL, FILE_CURRENT ); - - //Get the end of file ptr location - uiEndOfFilePtrLoc = SetFilePointer( hRealFile, 0, NULL, FILE_END ); - - //reset back to the original location - temp = SetFilePointer( hRealFile, -( (INT32)( uiEndOfFilePtrLoc - uiOldFilePtrLoc ) ), NULL, FILE_END ); - - //if the 2 pointers are the same, we are at the end of a file - if( uiEndOfFilePtrLoc <= uiOldFilePtrLoc ) - { - return( 1 ); - } - } - - //else it is a library file - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - { - //if the file is opened - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - UINT32 uiLength; //uiOffsetInLibrary -// HANDLE hLibraryFile; -// UINT32 uiNumBytesRead; - UINT32 uiCurPos; - - uiLength = gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].pFileHeader->uiFileLength; - uiCurPos = gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFilePosInFile; - - //if we are trying to read more data then the size of the file, return an error - if( uiCurPos >= uiLength ) - { - return( TRUE ); - } - } - } - } - } - - //we are not and the end of a file - return( 0 ); -#endif -} - - - -BOOLEAN GetFileManFileTime( HWFILE hFile, SGP_FILETIME *pCreationTime, SGP_FILETIME *pLastAccessedTime, SGP_FILETIME *pLastWriteTime ) -{ -#ifndef USE_VFS - HANDLE hRealFile; - INT16 sLibraryID; - UINT32 uiFileNum; - - FILETIME sCreationUtcFileTime; - FILETIME sLastAccessedUtcFileTime; - FILETIME sLastWriteUtcFileTime; - - //Initialize the passed in variables - if (pCreationTime) memset( pCreationTime, 0, sizeof( SGP_FILETIME ) ); - if (pLastAccessedTime) memset( pLastAccessedTime, 0, sizeof( SGP_FILETIME ) ); - if (pLastWriteTime) memset( pLastWriteTime, 0, sizeof( SGP_FILETIME ) ); - - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its a real file, read the data from the file - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //get the real file handle to the file - hRealFile = gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle; - - //Gets the UTC file time for the 'real' file - GetFileTime( hRealFile, &sCreationUtcFileTime, &sLastAccessedUtcFileTime, &sLastWriteUtcFileTime ); - - //converts the creation UTC file time to the current time used for the file - if(pCreationTime) - FileTimeToLocalFileTime( &sCreationUtcFileTime, pCreationTime ); - - //converts the accessed UTC file time to the current time used for the file - if (pLastAccessedTime) - FileTimeToLocalFileTime( &sLastAccessedUtcFileTime, pLastAccessedTime ); - - //converts the write UTC file time to the current time used for the file - if (pLastWriteTime) - FileTimeToLocalFileTime( &sLastWriteUtcFileTime, pLastWriteTime ); - } - else - { - //if the database is initialized - if( gFileDataBase.fInitialized ) - { - //if the library is open - if( IsLibraryOpened( sLibraryID ) ) - { - //if the file is opened - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - if( !GetLibraryFileTime( sLibraryID, uiFileNum, pLastWriteTime ) ) - { - return( FALSE ); - } - } - } - } - } - return( TRUE ); -#else - return( FALSE ); -#endif -} - - -INT32 CompareSGPFileTimes( SGP_FILETIME *pFirstFileTime, SGP_FILETIME *pSecondFileTime ) -{ - return( CompareFileTime( pFirstFileTime, pSecondFileTime ) ); -} - -UINT32 FileSize(STR strFilename) -{ -#ifdef USE_VFS - vfs::IBaseFile *pFile = getVFS()->getFile(vfs::Path(strFilename)); - if(pFile) - { - return pFile->getSize(); - } - return 0; -#else -HWFILE hFile; -UINT32 uiSize; - - if((hFile=FileOpen(strFilename, FILE_OPEN_EXISTING | FILE_ACCESS_READ, FALSE))==0) - return(0); - - uiSize=FileGetSize(hFile); - FileClose(hFile); - - return(uiSize); -#endif -} - - - -HANDLE GetRealFileHandleFromFileManFileHandle( HWFILE hFile ) -{ -#ifndef USE_VFS - INT16 sLibraryID; - UINT32 uiFileNum; - - GetLibraryAndFileIDFromLibraryFileHandle( hFile, &sLibraryID, &uiFileNum ); - - //if its the 'real file' library - if( sLibraryID == REAL_FILE_LIBRARY_ID ) - { - //if its not already closed - if( gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].uiFileID != 0 ) - { - return( gFileDataBase.RealFiles.pRealFilesOpen[ uiFileNum ].hRealFileHandle ); - } - } - else - { - //if the file is not opened, dont close it - if( gFileDataBase.pLibraries[ sLibraryID ].pOpenFiles[ uiFileNum ].uiFileID != 0 ) - { - return( gFileDataBase.pLibraries[ sLibraryID ].hLibraryHandle ); - } - } -#endif - return( 0 ); -} - - - -//************************************************************************** -// -// AddSubdirectoryToPath -// -// Puts a subdirectory of the current working directory into the current -// task's system path. -// -// Parameter List : -// Return Value : -// Modification history : -// -// 10June98:DB ->creation -// -//************************************************************************** -BOOLEAN AddSubdirectoryToPath(CHAR8 *pDirectory) -{ -CHAR8 *pSystemPath; -CHAR8 *pPath; -UINT32 uiPathLen; - - // Check for NULL - if(!pDirectory) - return(FALSE); - - // Check for zero length string - if(!strlen(pDirectory)) - return(FALSE); - - if((pSystemPath=(CHAR8 *)MemAlloc(_MAX_PATH))==NULL) - return(FALSE); - - memset(pSystemPath, 0, _MAX_PATH); - - if((pPath=(CHAR8 *)MemAlloc(_MAX_PATH))==NULL) - { - MemFree(pSystemPath); - return(FALSE); - } - - memset(pPath, 0, _MAX_PATH); - - // Builds a path to the directory with the SR DLL files. - _getcwd(pPath, _MAX_PATH); - uiPathLen=strlen(pPath); - if(uiPathLen) - uiPathLen--; - if(pPath[uiPathLen]!='\\') - strcat(pPath, "\\"); - - strcat(pPath, pDirectory); - - // Appends it to the path for the current task - if(GetEnvironmentVariable("PATH", pSystemPath, _MAX_PATH)) - { - strcat(pSystemPath, ";"); - strcat(pSystemPath, pPath); - SetEnvironmentVariable("PATH", pSystemPath); - MemFree(pSystemPath); - MemFree(pPath); - return(TRUE); - } - else - { - MemFree(pSystemPath); - MemFree(pPath); - return(FALSE); - } - -} - - -UINT32 GetFreeSpaceOnHardDriveWhereGameIsRunningFrom( ) -{ - STRING512 zExecDir; - STRING512 zDrive; - STRING512 zDir; - STRING512 zFileName; - STRING512 zExt; - - UINT32 uiFreeSpace = 0; - - GetExecutableDirectory( zExecDir ); - - //get the drive letter from the exec dir - _splitpath( zExecDir, zDrive, zDir, zFileName, zExt); - - sprintf( zDrive, "%s\\", zDrive ); - - uiFreeSpace = GetFreeSpaceOnHardDrive( zDrive ); - - return( uiFreeSpace ); -} - - - - -UINT32 GetFreeSpaceOnHardDrive( STR pzDriveLetter ) -{ - UINT32 uiBytesFree=0; - - UINT32 uiSectorsPerCluster=0; - UINT32 uiBytesPerSector=0; - UINT32 uiNumberOfFreeClusters=0; - UINT32 uiTotalNumberOfClusters=0; - - if( !GetDiskFreeSpace( pzDriveLetter, (LPDWORD) &uiSectorsPerCluster, (LPDWORD) &uiBytesPerSector, - (LPDWORD) &uiNumberOfFreeClusters, (LPDWORD) &uiTotalNumberOfClusters ) ) - { - UINT32 uiLastError = GetLastError(); - char zString[1024]; - FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, 0, uiLastError, 0, zString, 1024, NULL); - - return( TRUE ); - } - - uiBytesFree = uiBytesPerSector * uiNumberOfFreeClusters * uiSectorsPerCluster; - - return( uiBytesFree ); -} - -// Flugente: simple wrapper to check whether an audio file in mp3/ogg/wav format exists -BOOLEAN SoundFileExists( STR strFilename, STR zFoundFilename ) -{ - sprintf( zFoundFilename, "%s.mp3", strFilename ); - if ( !FileExists( zFoundFilename ) ) - { - sprintf( zFoundFilename, "%s.ogg", strFilename ); - if ( !FileExists( zFoundFilename ) ) - { - sprintf( zFoundFilename, "%s.wav", strFilename ); - } - } - - return FileExists( zFoundFilename ); -} diff --git a/Standard Gaming Platform/Flic.cpp b/Standard Gaming Platform/Flic.cpp deleted file mode 100644 index 7d278a25..00000000 --- a/Standard Gaming Platform/Flic.cpp +++ /dev/null @@ -1,1696 +0,0 @@ -//************************************************************************** -// -// Filename : flic.c -// -// Purpose : Display System for .flc and .fli Flic Files -// -// This program is derived from the program decribed in the article "The -// Flic File Format" on page 18 of the March 1993 edition of Dr. Dobb's -// Journal. It was restructured from the top down to meet the -// requirements of Sir-Tech. The high level routines were designed to -// provided easy integration with existing applications. Except for a few -// identifiers, the low level routines were not modified. -// -// All of the code for these routines in contained in this file and the -// file "flic.h". -// -// Modification history : -// -// 06-09-94:??? - Creation -// ???:David Smoth - ??? -// ???:Bret Rowdon for RIO/GORGE - added 640x480 SVGA support -// 05-11jun96:HJH - added routines for bitmap use, and -// other utilities -// 08-May-97 ARM Adapted for Win95 Standard Gaming Platform -// -//************************************************************************** - -//************************************************************************** -// -// Includes -// -//************************************************************************** - -#include -#include "flic.h" -#include "windows.h" -#include "types.h" -#include "wcheck.h" - -//************************************************************************** -// -// Variables -// -//************************************************************************** - -//Flic flic; -char pcxbuf[(640*480)]; -char FlicPal[768]; - -//extern char buffer[(640*480)]; -//extern char buffer2[(640*480)]; - -//************************************************************************** -// -// Function prototypes. -// -//************************************************************************** - -static ErrCode flic_next_frame(Flic *flic, BOOL fDecode); - -//************************************************************************** -// -// Functions -// -//************************************************************************** - -//************************************************************************** -// -// Low level Functions -// -//************************************************************************** - -//************************************************************************** -// -// screen_put_dot -// -// Set one dot. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -static void screen_put_dot(FlicScreen *s, int x, int y, Pixel color) -{ - // First clip it. - if (x < 0 || y < 0 || x >= s->width || y >= s->height) - return; - - // Then set it. - s->pixels[(unsigned)(s->height-y-1) * s->width + x] = color; -} - -//************************************************************************** -// -// line_clip -// -// Clip a horizontal line segment so that it fits on the screen. -// Return FALSE if clipped out entirely. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -static Boolean line_clip(FlicScreen *s, int *px, int *py, int *pwidth) -{ - int x = *px; - int y = *py; - int width = *pwidth; - int xend = x + width; - - if (y < 0 || y >= s->height || xend < 0 || x >= s->width) - return FALSE; /* Clipped off screen. */ - if (x < 0) - { - *pwidth = width = width + x; /* and shortens width. */ - *px = 0; - } - if (xend > s->width) - { - *pwidth = width = width - (xend - s->width); - } - if (width < 0) - return FALSE; - return TRUE; -} - -//************************************************************************** -// -// oldscreen_copy_seg -// -// Copy pixels from memory into screen. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -static void oldscreen_copy_seg(FlicScreen *s, int x, int y, Pixel *pixels, int count) -{ - Pixel *pt; - //int xend; - int unclipped_x = x; - int dx; - - // First let's do some clipping. - if (!line_clip(s, &x, &y, &count)) - return; - - dx = x - unclipped_x; // Clipping change in start position. - if (dx != 0) - pixels += dx; // Advance over clipped pixels. - - // Calculate start screen address. - //pt = s->pixels + (unsigned)y * (unsigned)s->width + (unsigned)x; - pt = s->pixels + (unsigned)(s->height-y-1) * (unsigned)s->width + (unsigned)x; - - // Copy pixels to display. - while (--count >= 0) - *pt++ = *pixels++; -} - -//************************************************************************** -// -// screen_repeat_one -// -// Draw a horizontal line of a solid color -// -// Parameter List : -// -// FlicScreen *s -> screen to write to -// int x -> x position to write to -// int y -> y position to write to -// Pixel color -> colour to write -// int count -> how many times to write -// -// Return Value : -// -// Modification history : -// -// 01jun96:HJH -> reversed the screen up and down so that the -// bitmaps wouldn't come out upside down (I put in -// the "s->height -") -// -//************************************************************************** - -static void screen_repeat_one(FlicScreen *s, int x, int y, Pixel color, int count) -{ - Pixel *pt; - - // First let's do some clipping. - if (!line_clip(s, &x, &y, &count)) - return; - - // Calculate start screen address. - pt = s->pixels + (unsigned)(s->height-y-1) * (unsigned)s->width + (unsigned)x; - - // Repeat pixel on display. - while (--count >= 0) - *pt++ = color; -} - -//************************************************************************** -// -// screen_repeat_two -// -// Repeat 2 pixels count times on screen. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -static void screen_repeat_two(FlicScreen *s, int x, int y, Pixels2 pixels2, int count) -{ - Pixels2 *pt; - int is_odd; - - // First let's do some clipping. - count <<= 1; // Convert from word to pixel count. - if (!line_clip(s, &x, &y, &count)) - return; - is_odd = (count&1); // Did it turn odd after clipping? Ack! - count >>= 1; // Convert back to word count. - - // Calculate start screen address. - pt = (Pixels2 *)(s->pixels + (unsigned)(s->height-y-1) * (unsigned)s->width + (unsigned)x); - - while (--count >= 0) // Go set screen 2 pixels at a time. - *pt++ = pixels2; - - if (is_odd) // Deal with pixel at end of screen if needed. - { - Pixel *end = (Pixel *)pt; - *end = pixels2.pixels[0]; - } -} - -//************************************************************************** -// -// screen_put_colors -// -// Set count colors in color map starting at start. RGB values -// go from 0 to 255. -// -// Parameter List : -// -// FlicScreen *s -> screen data -// int start -> start position -// Colour *colors -> the colors, of course -// int count -> how many -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void screen_put_colors(FlicScreen *s, int start, Colour *colors, int count) -{ - int end = start + count; - int ix; - - for (ix = start; ix < end; ++ix) - { - FlicPal[ix*3]=colors->r>>2; - FlicPal[ix*3+1]=colors->g>>2; - FlicPal[ix*3+2]=colors->b>>2; - ++colors; - } -} - -//************************************************************************** -// -// screen_put_colors_64 -// -// Set count colors in color map starting at start. RGB values -// go from 0 to 64. */ -// -// Parameter List : -// -// FlicScreen *s -> screen data -// int start -> start position -// Colour *colors -> the colors, of course -// int count -> how many -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void screen_put_colors_64(FlicScreen *s, int start, Colour *colors, int count) -{ - int end = start + count; - int ix; - - for (ix = start; ix < end; ++ix) - { - FlicPal[ix*3]=colors->r; - FlicPal[ix*3+1]=colors->g; - FlicPal[ix*3+2]=colors->b; - - ++colors; - } -} - -//************************************************************************** -// -// decode_byte_run -// -// Byte-run-length decompression. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_byte_run(Uchar *data, Flic *flic) -{ - int x,y; - int width = flic->head.width; - int height = flic->head.height; - int psize; // was char -> HJH - Char *cpt = (Char *)data; - int end; - - y = flic->yoff; - end = flic->xoff + width; - while (--height >= 0) - { - x = flic->xoff; - cpt += 1; /* skip over obsolete opcount byte */ - psize = 0; - while ((x+=psize) < end) - { - psize = (char)(*cpt++); - if (psize >= 0) - { - screen_repeat_one(&flic->screen, x, y, *cpt++, psize); - } - else - { - psize = -psize; - oldscreen_copy_seg(&(flic->screen),(long) x,(long) y, (unsigned char *)cpt, (long)psize); - cpt += psize; - } - } - y++; - } -} - -//************************************************************************** -// -// decode_delta_fli -// -// Fli style delta decompression. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_delta_fli(Uchar *data, Flic *flic) -{ - int xorg = flic->xoff; - int yorg = flic->yoff; - Short *wpt = (Short *)data; - Uchar *cpt = (Uchar *)(wpt + 2); - int x,y; - Short lines; - Uchar opcount; - Char psize; - - y = yorg + *wpt++; - lines = *wpt; - while (--lines >= 0) - { - x = xorg; - opcount = *cpt++; - while (opcount > 0) - { - x += *cpt++; - psize = *cpt++; - if (psize < 0) - { - psize = -psize; - screen_repeat_one(&flic->screen, x, y, *cpt++, psize); - x += psize; - opcount-=1; - } - else - { - oldscreen_copy_seg(&(flic->screen), (long)x, (long)y, (unsigned char *)cpt,(long) psize); - cpt += psize; - x += psize; - opcount -= 1; - } - } - y++; - } -} - -//************************************************************************** -// -// decode_delta_flc -// -// Flc-style delta decompression. The data is word oriented though -// a lot of the control info (how to skip, how many words to -// copy) are byte oriented still to save space. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_delta_flc(Uchar *data, Flic *flic) -{ - int xorg = flic->xoff; - int yorg = flic->yoff; - int width = flic->head.width; - int x,y; - Short lp_count; - Short opcount; - int psize; - union {Short *w; Uchar *ub; Char *b; Pixels2 *p2;} wpt; - int lastx; - - - lastx = xorg + width - 1; - wpt.ub = data; - lp_count = *wpt.w++; - y = yorg; - goto LPACK; - -SKIPLINES: /* Advance over some lines. */ - y -= opcount; - -LPACK: /* do next line */ - if ((opcount = *wpt.w++) >= 0) - goto DO_SS2OPS; - if( ((Ushort)opcount) & 0x4000) /* skip lines */ - goto SKIPLINES; - screen_put_dot(&flic->screen,(Uchar)opcount,lastx,(Pixel)y); /* put dot at eol with low byte */ - if((opcount = *wpt.w++) == 0) - { - ++y; - if (--lp_count > 0) - goto LPACK; - goto OUTT; - } -DO_SS2OPS: - x = xorg; - -PPACK: /* do next packet */ - x += *wpt.ub++; - psize = *wpt.b++; - if ((psize += psize) >= 0) - { - oldscreen_copy_seg(&(flic->screen), (long)x, (long)y, (unsigned char *)wpt.ub,(long) psize); - x += psize; - wpt.ub += psize; - if (--opcount != 0) - goto PPACK; - ++y; - if (--lp_count > 0) - goto LPACK; - } - else - { - psize = -psize; - screen_repeat_two(&flic->screen, x, y, *wpt.p2++, psize>>1); - x += psize; - if (--opcount != 0) - goto PPACK; - ++y; - if (--lp_count > 0) - goto LPACK; - } -OUTT: - return; -} - -//************************************************************************** -// -// decode_black -// -// Decode a BLACK chunk. Set frame to solid color 0 one -// line at a time. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_black(Uchar *data, Flic *flic) -{ - Pixels2 black; - int i; - int height = flic->head.height; - int width = flic->head.width; - int x = flic->xoff; - int y = flic->yoff; - - black.pixels[0] = black.pixels[1] = 0; - for (i=0; iscreen, x, y+i, black, width/2); - if (width & 1) /* if odd set last pixel */ - screen_put_dot(&flic->screen, x+width-1, y+i, 0); - } -} - -//************************************************************************** -// -// decode_literal -// -// Decode a LITERAL chunk. Just copy data to screen one line at -// a time. -// -// Parameter List : -// -// Uchar *data -> data to be decoded -// Flic *flic -> flic data containing where to decode to -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_literal(Uchar *data, Flic *flic) -{ - int i; - int height = flic->head.height; - int width = flic->head.width; - int x = flic->xoff; - int y = flic->yoff; - - for (i=0; iscreen),(long) x,(long)(y+i), (unsigned char *)data,(long) width); - data += width; - } -} - - -typedef void ColorOut(FlicScreen *s, int start, Colour *colors, int count); - /* This is the type of output parameter to our decode_color below. - * Not coincedently screen_put_color is of this type. */ - - -//************************************************************************** -// -// decode_color -// -// Decode color map. Put results into output. The two color -// compressions are identical except for whether the RGB values -// are 0-63 or 0-255. Passing in an output that does the appropriate -// shifting on the way to the real pallete lets us use the same -// code for both COLOR_64 and COLOR_256 compression. -// -// Parameter List : -// -// Uchar *data -> data to decode -// Flic *flic -> the flic -// ColorOut *output -> place to put decoded data -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_color(Uchar *data, Flic *flic, ColorOut *output) -{ - int start = 0; - Uchar *cbuf = (Uchar *)data; - Short *wp = (Short *)cbuf; - Short ops; - int count; - - ops = *wp; - cbuf += sizeof(*wp); - while (--ops >= 0) - { - start += *cbuf++; - if ((count = *cbuf++) == 0) - count = 256; - (*output)(&flic->screen, start, (Colour *)cbuf, count); - cbuf += 3*count; - start += count; - } -} - -//************************************************************************** -// -// decode_color_256 -// -// Decode COLOR_256 chunk. -// -// Parameter List : -// -// Uchar *data -> data to decode -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_color_256(Uchar *data, Flic *flic) -{ - decode_color(data, flic, screen_put_colors); -} - -//************************************************************************** -// -// decode_color_64 -// -// Decode COLOR_64 chunk. -// -// Parameter List : -// -// Uchar *data -> data to decode -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static void decode_color_64(Uchar *data, Flic *flic) -{ - decode_color(data, flic, screen_put_colors_64); -} - -//************************************************************************** -// -// decode_frame -// -// Decode a frame that is in memory already into screen. -// Here we just loop through each chunk calling appropriate -// chunk decoder. -// -// Parameter List : -// -// Flic *flic -> the flic -// FrameHead *frame -> info about the frame -// Uchar *data -> data to decode -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static ErrCode decode_frame(Flic *flic, FrameHead *frame, Uchar *data) -{ - int i; - ChunkHead *chunk; - - for (i=0; ichunks; ++i) - { - chunk = (ChunkHead *)data; - data += chunk->size; - switch (chunk->type) - { - case COLOR_256: - if (flic->screen.change_palette) - //decode_color_256((Uchar *)(chunk+1), flic); - decode_color_256( (((Uchar *)chunk) + 4 ), flic); - break; - case DELTA_FLC: - decode_delta_flc((Uchar *)(chunk+1), flic); - break; - case COLOR_64: - if (flic->screen.change_palette) - decode_color_64((Uchar *)(chunk+1), flic); - break; - case DELTA_FLI: - decode_delta_fli((Uchar *)(chunk+1), flic); - break; - case BLACK_FRAME: - decode_black((Uchar *)(chunk+1), flic); - break; - case BYTE_RUN: - decode_byte_run((Uchar *)(chunk+1), flic); - break; - case LITERAL: - decode_literal((Uchar *)(chunk+1), flic); - break; - default: - break; - } - } - return 0; -} - -static ErrCode file_read_big_block(FILE *file, char *block, Ulong size) - /* Read in a big block. Could be bigger than 64K. */ -{ - char *pt = block; - unsigned size1; - - while (size != 0) - { - size1 = ((size > 0xFFF0) ? 0xFFF0 : size); - if ( fread(pt, size1, 1, file) != 1 ) - return ErrFlicRead; - pt += size1; // Advance pointer to next batch. - size -= size1; // Subtract current batch from size to go. - } - return 0; -} - -//************************************************************************** -// -// fill_in_frame2 -// -// This figures out where the second frame of the flic is -// (useful for playing in a loop). -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static ErrCode fill_in_frame2(Flic *flic) -{ - FrameHead head; - //ErrCode err; - - (*flic->seek)(flic, flic->head.oframe1); - if ( fread(&head, sizeof(head), 1, flic->file) != 1 ) - return ErrFlicRead; - - if ( fread(&head, sizeof(head), 1, flic->file) != 1 ) - return ErrFlicRead; - - flic->head.oframe2 = flic->head.oframe1 + head.size; - - return 0; -} - -//************************************************************************** -// -// flic_next_frame -// -// Advance to next frame of flic. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static ErrCode flic_next_frame(Flic *flic, BOOL fDecode) -{ - FrameHead head; - ErrCode err = 0; - long size; - - if ( fread(&head, sizeof(head), 1, flic->file) != 1 ) - err = ErrFlicRead; - else - { - if (head.type == FRAME_TYPE) - { - size = head.size - sizeof(head); /* Don't include head. */ - if (size > 0) - { - if (size > 500000) - { - //TRACE("FLC chunk too big: %d\n",size); - //Assert(0); - FastDebugMsg(String("flic_next_frame: FLC chunk too big: %d", size)); - size = 64000; - } - if (!(err = file_read_big_block(flic->file, pcxbuf, size))) - { - if ( fDecode ) - err = decode_frame(flic, &head, (unsigned char *)pcxbuf); - } - } - } - else - err = ErrFlicBadFrame; - } - return err; -} - -//************************************************************************** -// -// flic_check_frame -// -// A dummy routine to be called for each frame. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -static Boolean flic_check_frame(Flic *flic) -{ - return TRUE; -} - -//************************************************************************** -// -// File io -// -//************************************************************************** - -static ErrCode flic_open(Flic *flic, const char *filename) -{ - return (flic->file = fopen(filename, "rb")) ? 0 : ErrFlicAccess; -} - -static ErrCode flic_seek(Flic *flic, long offset) -{ - return fseek(flic->file, offset, SEEK_SET) ? ErrFlicSeek : 0; -} - -//************************************************************************** -// -// FlicInit -// -// Initializes a flic object. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -void FlicInit(Flic *flic, unsigned screen_width, unsigned screen_height, char change_palette, char *Buff) -{ - flic->file = NULL; - //flic->lib.names = NULL; - - flic->open = flic_open; /* Set routines for single flick file access */ - flic->seek = flic_seek; - - flic->check_frame = flic_check_frame; /* Select a dummy routine */ - - /** Info used by low level routines */ - - flic->screen.pixels = (unsigned char *)Buff; // (char *) 0xa0000; - flic->screen.width = screen_width; - flic->screen.height = screen_height; - flic->screen.change_palette = change_palette; -} - -//************************************************************************** -// -// FlicOpen -// -// Opens a flic file or locates a flic file in a library. -// -// Parameter List : -// -// Flic *flic -> the flic -// const char *filename -> filename of flic to open -// -// Return Value : -// Modification history : -// -//************************************************************************** - -ErrCode FlicOpen(Flic *flic, const char *filename) -{ - ErrCode err; - - flic->xoff = flic->yoff = 0; - - if ( !(err = (*flic->open)(flic, filename)) ) - { - if (fread(&flic->head, sizeof(flic->head), 1, flic->file) != 1) - err = ErrFlicRead; - else - { - flic->name = filename; - - if (flic->head.type == FLC_TYPE) - { - /* Seek frame 1. */ - (*flic->seek)(flic, flic->head.oframe1); - return 0; - } - if (flic->head.type == FLI_TYPE) - { - long i; - /* Do some conversion work here. */ - flic->head.oframe1 = sizeof(flic->head); - i=flic->head.speed * 1000L; - flic->head.speed = i / 70; - return 0; - } - else - { - err = ErrFlicBad; - printf("flic was bad! \n"); - _getch(); - exit(0); - } - } - } - - FlicClose(flic); /* Close down and scrub partially opened flic. */ - return err; -} - -//************************************************************************** -// -// FlicSetOrigin -// -// Sets the location of the top left corner of the flic in terms of screen -// coordinates. -// -// Parameter List : -// -// Flic *flic -> the flic -// unsigned x -> x-coord of origin -// unsigned y -> y-coord of origin -// -// Return Value : -// Modification history : -// -//************************************************************************** - -void FlicSetOrigin(Flic *flic, unsigned x, unsigned y) -{ - flic->xoff = x; - flic->yoff = y; -} - -//************************************************************************** -// -// FlicClose -// -// Closes a flic file if one is open. If a library is open, this function has -// no effect. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -void FlicClose(Flic *flic) -{ - if ( flic->file ) - { - fclose(flic->file); - flic->file = NULL; - } -} - -//************************************************************************** -// -// flic_play_loop_timer -// -// This routine is called at the end of each timer period. The timer is used -// by the FlicPlay routine. The global variable timer_flag indicates that -// a time interval has elapsed. FlicPlay resets timer_flag for the next -// interval. -// -// Stack checking must be disabled. -// -// Parameter List : -// Return Value : -// Modification history : -// -//************************************************************************** - -#ifdef DEBUG -#pragma off (check_stack) -#endif - -static volatile int timer_flag=1; - -static void flic_play_loop_timer() -{ - timer_flag = 1; -} - -#ifdef DEBUG -#pragma on (check_stack) -#endif - -//************************************************************************** -// -// FlicPlay -// -// This is the engine for the flic display system. Call this function to -// display a flic. -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -ErrCode FlicPlay(Flic *flic, Ulong max_loop) -{ -/* - ErrCode err; - HTIMER timer; - - flic->status.max_loop_count = max_loop; - flic->status.max_frame_index = flic->head.frames; - - if (flic->head.oframe2 == 0) - { - fill_in_frame2(flic); - // FastBlitRegionSVGA((char *)(0xa0000),(char *)(flic->screen.pixels),(long)0,(long)640,(long)480,(long)0,(long)640); - // BlitSVGAPage((char *)(flic->screen.pixels)); - // BlitRegionSVGATst((void *)0xa0000,(void *)(flic->screen.pixels),(long)640,(long)480,(long)640); - //BlitRegionSVGA((char *)0xa0000,(char *)flic->screen.pixels,(long)0,(long)640,(long)480,(long)0,(long)640); - } - - // Seek to first frame. - (*flic->seek)(flic, flic->head.oframe1); - // Save time to move on. - - //videoSetMode(3); - //printf("speed is %d\n",flic->head.speed); - //_getch(); - //exit(0); - - //timer = AIL_register_timer(flic_play_loop_timer); - //AIL_set_timer_period(timer, flic->head.speed* 1000); - //timer_flag = 0; - //AIL_start_timer(timer); - - // Display first frame. - if (err = flic_next_frame(flic, TRUE)) - { - //AIL_release_timer_handle(timer); - return err; - } - - for (flic->status.loop_count = 0; !max_loop || flic->status.loop_count < max_loop; - ++flic->status.loop_count) - { - // Seek to second frame - (*flic->seek)(flic, flic->head.oframe2); - // Loop from 2nd frame thru ring frame - for (flic->status.frame_index=0; - (flic->status.frame_index < (flic->head.frames-1)) || - ( (flic->status.frame_index < flic->head.frames) && - ( !max_loop || (flic->status.loop_count < (max_loop - 1)))); - ++flic->status.frame_index) - { - while (!timer_flag); - - if (err = flic_next_frame(flic, TRUE)) - return err; - //else - // FastBlitRegionSVGA((char *)(0xa0000),(char *)(flic->screen.pixels),(long)0,(long)640,(long)480,(long)0,(long)640); - // BlitSVGAPage((char *)(flic->screen.pixels)); - // BlitRegionSVGATst((void *)0xa0000,(void *)(flic->screen.pixels),(long)640,(long)480,(long)640); - // BlitRegionSVGA((char *)0xa0000,(char *)flic->screen.pixels,(long)0,(long)640,(long)480,(long)0,(long)640); - - timer_flag = 0; - } - } - - //AIL_release_timer_handle(timer); -*/ - return 0; -} - -void FlicSeekFirst(Flic *flic) -{ -// if (flic->head.oframe2 == 0) -// fill_in_frame2(flic); - - // Seek to first frame. - flic_seek(flic, flic->head.oframe1); - - // Display first frame. - //flic_next_frame(flic, TRUE); HJH - flic->status.frame_index=0;//1; HJH -} - -int FlicAdvance(Flic *flic, BOOL fDecode) -{ - // Seek to second frame - //(*flic->seek)(flic, flic->head.oframe2); - // Loop from 2nd frame thru ring frame - - // for (flic->status.frame_index=0; - // (flic->status.frame_index < (flic->head.frames-1)) || - // ( (flic->status.frame_index < flic->head.frames) && - // ( !max_loop || (flic->status.loop_count < (max_loop - 1)))); - // ++flic->status.frame_index) - // { - - if(flic->status.frame_index < flic->head.frames) - { - flic_next_frame(flic, fDecode); - flic->status.frame_index++; - //memcpy(buffer, buffer2, (HSIZE*VSIZE)); - return(1); - } - else - return(0); - - // if (flic->check_frame && !(*flic->check_frame)(flic)) - // return 0; -} - -static void center_flic(Flic *flic) - /* Set flic.xoff and flic.yoff so flic plays centered rather - * than in upper left corner of display. */ -{ - flic->xoff = (flic->screen.width - (signed)flic->head.width)/2; - flic->yoff = (flic->screen.height - (signed)flic->head.height)/2; -} - -void set_flic_origin(Flic *flic, int x, int y) -{ - flic->xoff = x; - flic->yoff = y; -} - -int frame_check(Flic *flic) -{ -/* - char key; - - if (Esc()) - { - //AbortScript = TRUE; - return 0; - } - - if (flic->status.frame_index == FlcSoundFrames[FlcSoundIndex][0]) - { - // if the "sound" number is less than 100, then it's a VOC buffer - if (FlcSoundFrames[FlcSoundIndex][1] < 100) - { - PlayVoc(FlcSoundFrames[FlcSoundIndex][1],-1); - } - else // otherwise a raw sound data file to be streamed off of disk - { - if (FlcSoundNameList[FlcSoundNameIndex][0]!='\0') - { - retcode = lmLibSeek(SNDLIBINFO,FlcSoundNameList[FlcSoundNameIndex++],&SNDoffset,&SNDlength); - if (retcode == 0) - StPlay(glbPlayRate,IGNORE_AUDIO_GAPS); - } - } - - // now that the sound has been triggered, ready the next frame number - FlcSoundIndex++; - } - else - if (FlcSoundFrames[FlcSoundIndex][0] == 9998) // start music? - { - PlayXmi(FlcSoundFrames[FlcSoundIndex++][1],FALSE); - XmiVolume(1,127,0); - } - RefreshSound(); -*/ - return 1; -} - -//************************************************************************** -// -// FlicStart -// -// Parameter List : -// -// char *filename -> filename of flic to start processing -// char *buffer -> screen buffer to put data into -// Flic *flic -> the flic -// int usepal -> flag - should we use the palette? (I think) -// -// Return Value : -// Modification history : -// -//************************************************************************** - -int FlicStart(char *filename, int width, int height, char *buffer, Flic *flic, char usepal) -{ - FlicInit(flic, width, height, usepal, buffer); - - if(FlicOpen(flic, filename)) - return(-1); - - FlicSetOrigin(flic, 0, 0); - FlicSeekFirst(flic); - FlicAdvance(flic, TRUE); // HJH - we go to 1st, then go process it - - //memcpy(buffer, buffer2, (HSIZE*VSIZE)); - - return(0); -} - -//************************************************************************** -// -// FlicStop -// -// Parameter List : -// -// Flic *flic -> the flic -// -// Return Value : -// Modification history : -// -//************************************************************************** - -void FlicStop(Flic *flic) -{ - FlicClose(flic); -} - -//************************************************************************** -// -// FlicGetStats -// -// Gets statistics for the given file. -// -// Parameter List : -// -// char *filename -> the flic filename -// Flic *flic -> the flic -// int *piBufferSize -> this function will fill in how large a -// buffer is needed to store a screen of -// this flick -// int *piColourPalSize->this function will fill in how large -// the colour palette is -// -// Return Value : -// -// ErrCode -> 0 if successfull, non-zero otherwise -// -// Modification history : -// -// 05jun96:HJH -> creation -// -//************************************************************************** - -ErrCode FlicGetStats(char *filename, int width, int height, Flic *flic, int *piBufferSize, int *piColourPalSize) -{ - ErrCode err=0; - FlicInit(flic, width, height, 1, NULL); - - flic->xoff = flic->yoff = 0; - - if ( !(err = (*flic->open)(flic, filename)) ) - { - if (fread(&flic->head, sizeof(flic->head), 1, flic->file) != 1) - err = ErrFlicRead; - } - - if ( !err && piBufferSize ) - *piBufferSize = flic->head.width * flic->head.height; - - FlicSeekChunk( flic, 0, COLOR_256, piColourPalSize ); - FlicClose(flic); /* Close down and scrub partially opened flic. */ - - return err; -} - -//************************************************************************** -// -// FlicGetColourPalette -// -// To get the colour palette from the given flic file. -// -// Parameter List : -// -// char *filename -> the flic file to extract the palette from -// char **ppBuffer -> the place to put the palette -// -// Return Value : -// -// ErrCode -> 0 if successful, non-zero otherwise -// -// Modification history : -// -// 10jun96:HJH -> creation -// 19jun96:HJH -> removed <<2 after colors->r/g/b -// -//************************************************************************** - -ErrCode FlicGetColourPalette(CHAR *filename, int width, int height, CHAR **ppBuffer, INT *piNumColours) -{ - Flic flic; - INT iBufferSize; - INT iColourPaletteSize=0; - ErrCode err = 0; - ChunkHead *chunk = NULL; - CHAR *pcPosition; - - if ( FlicGetStats( filename, width, height, &flic, &iBufferSize, &iColourPaletteSize ) ) - err = -1; - - if ( piNumColours ) - *piNumColours = iColourPaletteSize; - - if ( !err && iColourPaletteSize ) - { - FlicInit(&flic, flic.head.width, flic.head.height, 1, NULL); - - if(FlicOpen(&flic, filename)) - return(-1); - - FlicSetOrigin(&flic, 0, 0); - - *ppBuffer = (CHAR *)MemAlloc( iColourPaletteSize ); - chunk = (ChunkHead *)FlicSeekChunk( &flic, 0, COLOR_256, NULL ); - pcPosition = (CHAR *)(((BYTE *)chunk)+6); - - if ( chunk ) - { - INT ix, end, count, start = 0; - Uchar *cbuf = (Uchar *)pcPosition; - Short *wp = (Short *)cbuf; - Short ops; - Colour *colors; - - ops = *wp; - cbuf += sizeof(*wp); - while (--ops >= 0) - { - start += *cbuf++; - if ((count = *cbuf++) == 0) - count = 256; - { - colors = (Colour *)cbuf; - end = start + count; - - for (ix = start; ix < end; ++ix) - { - (*ppBuffer)[ix*3] =colors->r; - (*ppBuffer)[ix*3+1]=colors->g; - (*ppBuffer)[ix*3+2]=colors->b; - ++colors; - } - } - cbuf += 3*count; - start += count; - } - } - } - else - { - err = -1; - } - - return(err); -} - -//************************************************************************** -// -// FlicSeekChunk -// -// To seek to a particular chunk in the flic file. -// -// Parameter List : -// -// Flic *flic -> the flic to search -// INT iFrame -> frame in which to search -// ChunkTypes eType -> type of chunk to search for -// INT *piChunkSize-> the function puts the size of the chunk here -// -// Return Value : -// -// char * -> the returned chunk -// -// Modification history : -// -// 05jun96:HJH -> creation -// -//************************************************************************** - -CHAR *FlicSeekChunk(Flic *flic, INT iFrame, ChunkTypes eType, INT *piChunkSize) -{ - FrameHead head; - LONG lSize; - ErrCode err=0; - INT i; - - FlicSeekFirst(flic); - - for ( i=0 ; i