Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Redid the most of the file loading/saving. Now uses $HOME/.avp/ and

$AVP_DIR to look for files.
  • Loading branch information...
commit 6a01356438dd660b06cc74c8952be435d2007b33 1 parent fdec628
Steven Fuller authored
Showing with 1,399 additions and 1,578 deletions.
  1. +1 −1  Makefile
  2. +27 −14 README
  3. +9 −6 src/avp/cdtrackselection.cpp
  4. +15 −8 src/avp/psnd.c
  5. +5 −7 src/avp/psndproj.c
  6. +18 −34 src/avp/savegame.c
  7. +9 −97 src/avp/scream.cpp
  8. +5 −16 src/avp/support/consbind.cpp
  9. +1 −1  src/avp/support/consbtch.cpp
  10. +14 −16 src/avp/win95/ffread.cpp
  11. +7 −5 src/avp/win95/ffstdio.cpp
  12. +23 −24 src/avp/win95/frontend/avp_envinfo.c
  13. +50 −45 src/avp/win95/frontend/avp_menus.c
  14. +93 −144 src/avp/win95/frontend/avp_mp_config.cpp
  15. +39 −61 src/avp/win95/frontend/avp_userprofile.cpp
  16. +1 −1  src/avp/win95/frontend/avp_userprofile.h
  17. +4 −3 src/avp/win95/objsetup.cpp
  18. +2 −2 src/avp/win95/platsup.c
  19. +8 −23 src/avp/win95/projload.cpp
  20. +8 −4 src/avp/win95/scrshot.cpp
  21. +2 −8 src/avp/win95/system.c
  22. +2 −2 src/avp/win95/usr_io.c
  23. +0 −682 src/avp/win95/win_proj.cpp
  24. +575 −0 src/files.c
  25. +34 −0 src/files.h
  26. +1 −1  src/fixer.h
  27. +118 −32 src/main.c
  28. +189 −100 src/openal.c
  29. +4 −50 src/stubs.c
  30. +20 −20 src/win95/awtexld.cpp
  31. +2 −2 src/win95/awtexld.hpp
  32. +4 −6 src/win95/bmpnames.cpp
  33. +14 −22 src/win95/chnkload.cpp
  34. +6 −5 src/win95/chnktexi.cpp
  35. +6 −5 src/win95/db.c
  36. +3 −17 src/win95/iff_ilbm.cpp
  37. +7 −2 src/win95/media.hpp
  38. +40 −57 src/win95/mishchnk.cpp
  39. +19 −24 src/win95/sprchunk.cpp
  40. +14 −31 src/winapi.c
View
2  Makefile
@@ -20,7 +20,7 @@ LDLIBS = -L/usr/X11R6/lib -lX11 -lXext -lGL `sdl-config --libs` -lopenal
AFLAGS = -g -w+macro-params -w+orphan-labels -w+number-overflow
-ROOT = main.c mathline.c math.asm opengl.c net.c menus.c openal.c cdplayer.c winapi.c stubs.c frustum.c kshape.c map.c maths.c md5.c mem3dc.c mem3dcpp.cpp module.c morph.c object.c shpanim.c sphere.c tables.c vdb.c version.c
+ROOT = main.c files.c winapi.c stubs.c version.c mathline.c math.asm opengl.c openal.c cdplayer.c menus.c net.c frustum.c kshape.c map.c maths.c md5.c mem3dc.c mem3dcpp.cpp module.c morph.c object.c shpanim.c sphere.c tables.c vdb.c
AVP = ai_sight.c avpview.c bh_agun.c bh_ais.c bh_alien.c bh_binsw.c bh_cable.c bh_corpse.c bh_deathvol.c bh_debri.c bh_dummy.c bh_fan.c bh_far.c bh_fhug.c bh_gener.c bh_ldoor.c bh_lift.c bh_light.c bh_lnksw.c bh_ltfx.c bh_marin.c bh_mission.c bh_near.c bh_pargen.c bh_plachier.c bh_plift.c bh_pred.c bh_queen.c bh_rubberduck.c bh_selfdest.c bh_snds.c bh_spcl.c bh_swdor.c bh_track.c bh_types.c bh_videoscreen.c bh_waypt.c bh_weap.c bh_xeno.c bonusabilities.c cconvars.cpp cdtrackselection.cpp cheatmodes.c comp_map.c comp_shp.c consolelog.cpp davehook.cpp deaths.c decal.c detaillevels.c dynamics.c dynblock.c equipmnt.c equiputl.cpp extents.c game.c game_statistics.c gamecmds.cpp gamevars.cpp hmodel.c hud.c inventry.c language.c lighting.c load_shp.c los.c maps.c mempool.c messagehistory.c missions.cpp movement.c paintball.c particle.c pfarlocs.c pheromon.c player.c pmove.c psnd.c psndproj.c pvisible.c savegame.c scream.cpp secstats.c sfx.c stratdef.c targeting.c track.c triggers.c weapons.c
SHAPES = cube.c
SUPPORT = consbind.cpp consbtch.cpp coordstr.cpp daemon.cpp indexfnt.cpp r2base.cpp r2pos666.cpp reflist.cpp refobj.cpp rentrntq.cpp scstring.cpp strtab.cpp strutil.c trig666.cpp wrapstr.cpp
View
41 README
@@ -11,8 +11,7 @@ end users." Hopefully this status will change in the not-so-distant future.
-
-
+(Please see note below regarding installation/running.)
Obviously this README is totally incomplete, and will probably remain so for
@@ -42,12 +41,29 @@ If you are wanting to run the Alien demo (the installer is an .exe but you
can just use unzip to extract the files from the .exe), add -DALIEN_DEMO to
the CFLAGS line (the one that's uncommented) in the Makefile. Rename all game
files lowercase. Be sure to install SDL 1.2 (http://www.libsdl.org) with
-OpenGL support, nasm 0.98, PhysicsFS 0.1.4 (http://icculus.org/physfs/),
-and the latest OpenAL CVS (http://www.openal.org). AvP requires a 3D card
-with OpenGL support.
-
-Create the MPConfig and User_Profiles directories if they do not exist.
-(Note: Windows profiles probably do not work in Linux and vice versa)
+OpenGL support, nasm 0.98, and the latest OpenAL CVS (http://www.openal.org).
+AvP requires a 3D card with OpenGL support.
+
+***
+IMPORTANT:
+AvP now uses $HOME/.avp/ to load/store configs, logs, etc.
+NOTE: Windows profiles probably do not work in Linux and vice versa.
+
+AvP will no longer use the current working directory to look for files. You
+must either copy or symlink the AvP binary to the game data directory and run
+that, or set AVP_DATA to the data directory.
+
+Currently:
+If you want to install the mappacks from
+http://www.avpnews.com/files/avpfiles.html, install them with the rest of
+the game data, not in ~/.avp/. Make sure everything is lowercase (although,
+the maps in avp_rifs/Custom do not have to be totally lowercase, just the .rif
+extension). Maybe in the future users will be able to install the files in
+~/.avp/ also.
+
+Hopefully all the necessary file loading changes were made. Please let me
+know if something goes wrong.
+***
If you have the regular edition, add -DREGULAR_EDITION to CFLAGS.
@@ -64,14 +80,11 @@ have to uncomment a LDLIBS line in the Makefile.
relnev:~/avp/AvP Demo 3 - Alien$ ls
-aenglish.txt alienavp_huds/ alienfastfile/ avp_rifs/ MPConfig/
-User_Profiles/
+aenglish.txt alienavp_huds/ alienfastfile/ avp_rifs/
relnev:~/avp/Gold Edition$ ls
-avp_huds/ avp_rifs/ cd tracks.txt default.cfg fastfile/ language.txt
-MPConfig/ User_Profiles/
+avp_huds/ avp_rifs/ cd tracks.txt fastfile/ language.txt
-Support for the demo is not quite complete (some sounds are missing and some
-text is incorrect/missing).
+Support for the demo is not quite complete (some sounds are missing).
Linux Port-specific commands:
View
15 src/avp/cdtrackselection.cpp
@@ -112,8 +112,9 @@ void LoadCDTrackList()
//clear out the old list first
EmptyCDTrackList();
- HANDLE file=CreateFile(CDTrackFileName,GENERIC_READ, 0, 0, OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS, 0);
- if(file==INVALID_HANDLE_VALUE)
+ FILE *file = OpenGameFile(CDTrackFileName, FILEMODE_READONLY, FILETYPE_OPTIONAL);
+
+ if(file==NULL)
{
LOGDXFMT(("Failed to open %s",CDTrackFileName));
return;
@@ -121,13 +122,15 @@ void LoadCDTrackList()
char* buffer;
int file_size;
- unsigned long bytes_read;
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ rewind(file);
+
//copy the file contents into a buffer
- file_size= GetFileSize(file,0);
buffer=new char[file_size+1];
- ReadFile(file,buffer,file_size,&bytes_read,0);
- CloseHandle(file);
+ fread(buffer, 1, file_size, file);
+ fclose(file);
char* bufferptr=buffer;
View
23 src/avp/psnd.c
@@ -511,10 +511,10 @@ void Sound_Play(SOUNDINDEX soundNumber, char *format, ...)
if(loop) ActiveSounds[newIndex].loop = 1;
else ActiveSounds[newIndex].loop = 0;
-/*
-printf("Play: new = %d. num = %d, p = %d, v = %d, pi = %d, l = %d, mi = %d, rev = %d\n", newIndex, soundNumber, priority, volume, pitch, loop, marine_ignore, reverb_off);
-printf("Play: %d %d %s l:%d\n", newIndex, soundNumber, GameSounds[soundNumber].wavName, loop);
-*/
+#if 0
+fprintf(stderr, "PSND: Play: new = %d. num = %d, p = %d, v = %d, pi = %d, l = %d, mi = %d, rev = %d\n", newIndex, soundNumber, priority, volume, pitch, loop, marine_ignore, reverb_off);
+fprintf(stderr, "PSND: Play: %d %d %s l:%d\n", newIndex, soundNumber, GameSounds[soundNumber].wavName, loop);
+#endif
if(worldPosn)
{
@@ -562,8 +562,10 @@ printf("Play: %d %d %s l:%d\n", newIndex, soundNumber, GameSounds[soundNumber].w
// //sound starts part of the way in
// IDirectSoundBuffer_SetCurrentPosition(ActiveSounds[newIndex].dsBufferP,soundStartPosition);
// }
+#if 0 /* TODO */
if (soundStartPosition)
fprintf(stderr, "Sound_Play: sound starts part of the way in (%d)\n", soundStartPosition);
+#endif
}
void Sound_Stop(int activeSoundNumber)
@@ -590,9 +592,11 @@ void Sound_Stop(int activeSoundNumber)
/* stop the sound: it may have already stopped, of course, but never mind */
PlatStopSound(activeSoundNumber);
-/*
-printf("Stop: %d %d %s\n", activeSoundNumber, soundNo, GameSounds[soundNo].wavName);
-*/
+
+#if 0
+fprintf(stderr, "PSND: Stop: %d %d %s\n", activeSoundNumber, soundNo, GameSounds[soundNo].wavName);
+#endif
+
/* release the active sound slot */
buf = ActiveSounds[activeSoundNumber].ds3DBufferP;
ActiveSounds[activeSoundNumber] = BlankActiveSound;
@@ -853,8 +857,9 @@ void Save_SoundState(int* soundHandle)
// IDirectSoundBuffer_GetCurrentPosition(sound->dsBufferP,(LPDWORD)&block->position,NULL);
// else
block->position = 0;
+#if 0 /* TODO */
fprintf(stderr, "Save_SoundState: GetCurrentPosition!\n");
-
+#endif
strcpy((char*)(block+1),name);
}
@@ -944,7 +949,9 @@ void Save_SoundsWithNoReference()
// IDirectSoundBuffer_GetCurrentPosition(sound->dsBufferP,(LPDWORD)&block->position,NULL);
// else
block->position = 0;
+#if 0 /* TODO */
fprintf(stderr, "Save_SoundsWithNoReference: GetCurrentPosition!\n");
+#endif
strcpy((char*)(block+1),name);
}
View
12 src/avp/psndproj.c
@@ -867,16 +867,14 @@ int FindAndLoadWavFile(int soundNum,char* wavFileName)
{
//check to see if file exists locally first
- FILE* wavFile=fopen(sound_name,"rb");
-
+ FILE* wavFile = OpenGameFile(sound_name, FILEMODE_READONLY, FILETYPE_PERM);
if(!wavFile && SecondSoundDir)
{
//look for sound over network
sprintf (sound_name, "%s%s", SecondSoundDir,wavFileName);
-
- wavFile=fopen(sound_name,"rb");
- if(!wavFile)
- {
+
+ wavFile = OpenGameFile(sound_name, FILEMODE_READONLY, FILETYPE_PERM);
+ if(!wavFile) {
LOGDXFMT(("Failed to find %s\n",wavFileName));
return 0;
}
@@ -905,7 +903,7 @@ void *LoadRebSndFile(char *filename)
void *bufferPtr;
long int save_pos, size_of_file;
FILE *fp;
- fp = fopen(filename,"rb");
+ fp = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_PERM);
if (!fp) goto error;
View
52 src/avp/savegame.c
@@ -397,8 +397,7 @@ static BOOL SaveGameAllowed()
void SaveGame()
{
char filename[100];
- HANDLE file;
- DWORD bytes_written;
+ FILE *file;
int headerLength;
HuffmanPackage *packagePtr;
@@ -456,34 +455,27 @@ void SaveGame()
SaveGameRequest = SAVELOAD_REQUEST_NONE;
//write the file
- file = CreateFile(filename,GENERIC_WRITE, 0, 0, CREATE_ALWAYS,FILE_FLAG_RANDOM_ACCESS, 0);
+ file = OpenGameFile(filename, FILEMODE_WRITEONLY, FILETYPE_CONFIG);
- if (file == INVALID_HANDLE_VALUE)
+ if (file == NULL)
{
GLOBALASSERT("Error saving file"==0);
return;
}
- WriteFile(file,SaveInfo.BufferStart,headerLength,&bytes_written,0);
+ fwrite(SaveInfo.BufferStart, headerLength, 1, file);
packagePtr = HuffmanCompression(SaveInfo.BufferStart+headerLength,SaveInfo.BufferSpaceUsed-headerLength);
- WriteFile(file,packagePtr,packagePtr->CompressedDataSize+sizeof(HuffmanPackage),&bytes_written,0);
-
- CloseHandle(file);
-
+ fwrite(packagePtr, packagePtr->CompressedDataSize+sizeof(HuffmanPackage), 1, file);
+
+ fclose(file);
NewOnScreenMessage(GetTextString(TEXTSTRING_SAVEGAME_GAMESAVED));
DisplaySavesLeft();
-
}
-
-
-
-
-
static void EndLoadGame()
{
@@ -495,7 +487,6 @@ static void EndLoadGame()
LoadInfo.BufferPos = NULL;
LoadInfo.BufferSize = 0;
LoadInfo.BufferSpaceLeft = 0;
-
}
extern SAVE_SLOT_HEADER SaveGameSlot[];
@@ -535,9 +526,8 @@ void LoadSavedGame()
{
SAVE_SLOT_HEADER* save_slot;
char filename[100];
- HANDLE file;
+ FILE *file;
BOOL terminal_error = FALSE;
- unsigned int bytes_read;
if(LoadGameRequest == SAVELOAD_REQUEST_NONE) return;
@@ -576,31 +566,32 @@ void LoadSavedGame()
LoadGameRequest = SAVELOAD_REQUEST_NONE;
//load the file
- file = CreateFile(filename,GENERIC_READ, 0, 0, OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS, 0);
+ file = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_CONFIG);
-
- if(file==INVALID_HANDLE_VALUE)
+ if(file==NULL)
{
//failed to load
EndLoadGame();
return;
}
- LoadInfo.BufferSize = GetFileSize(file,0);
+ fseek(file, 0, SEEK_END);
+ LoadInfo.BufferSize = ftell(file);
+ rewind(file);
+
if(!LoadInfo.BufferSize)
{
- CloseHandle(file);
+ fclose(file);
EndLoadGame();
return;
}
//allocate buffer , and read file into memory
LoadInfo.BufferStart = (char*) AllocateMem(LoadInfo.BufferSize);
- ReadFile(file,LoadInfo.BufferStart,LoadInfo.BufferSize,(LPDWORD)&bytes_read,0);
- CloseHandle(file);
+ fread(LoadInfo.BufferStart, LoadInfo.BufferSize, 1, file);
+ fclose(file);
-
LoadInfo.BufferPos = LoadInfo.BufferStart;
LoadInfo.BufferSpaceLeft = LoadInfo.BufferSize;
@@ -1340,10 +1331,6 @@ static void SaveMiscGlobalStuff()
GetFMVInformation(&block->FMV_MessageNumber,&block->FMV_FrameNumber);
}
-
-
-
-
extern void DisplaySavesLeft()
{
char text [100];
@@ -1353,9 +1340,6 @@ extern void DisplaySavesLeft()
NewOnScreenMessage(text);
}
-
-
-
extern void ResetNumberOfSaves()
{
switch(AvP.Difficulty)
@@ -1370,7 +1354,7 @@ extern void ResetNumberOfSaves()
case I_Impossible :
NumberOfSavesLeft = NUM_SAVES_FOR_HARD_MODE;
break;
-
default:
+ break;
}
}
View
106 src/avp/scream.cpp
@@ -56,7 +56,6 @@ static CharacterSoundEffects QueenSounds={0,0,0,SID_NOSOUND};
//static SOUNDINDEX global_last_sound;
-/* TODO: dir separator */
#if ALIEN_DEMO
#define ScreamFilePath "alienfastfile/"
#elif LOAD_SCREAMS_FROM_FASTFILES
@@ -65,95 +64,6 @@ static CharacterSoundEffects QueenSounds={0,0,0,SID_NOSOUND};
#define ScreamFilePath "sound/"
#endif
-#if 0
-void LoadScreamSounds()
-{
- if(voice_types) return;
-
- HANDLE file=CreateFile(ScreamFileName,GENERIC_READ, 0, 0, OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS, 0);
- if(file==INVALID_HANDLE_VALUE)
- {
- LOGDXFMT(("Failed to open %s",ScreamFileName));
- return;
- }
-
- char* buffer;
- int file_size;
- unsigned long bytes_read;
-
- file_size= GetFileSize(file,0);
- buffer=new char[file_size+1];
- ReadFile(file,buffer,file_size,&bytes_read,0);
- CloseHandle(file);
-
- if(strncmp("MARSOUND",buffer,8))
- {
- return;
- }
-
- char* bufpos=buffer+8;
-
- num_voice_types=*(int*)bufpos;
- bufpos+=4;
- num_voice_cats=*(int*)bufpos;
- bufpos+=4;
-
- voice_types=(ScreamVoiceType*) PoolAllocateMem(num_voice_types * sizeof(ScreamVoiceType));
-
- /* TODO: dir separator */
- char wavpath[200]="npc/marinevoice/";
- char* wavname=&wavpath[strlen(wavpath)];
- for(int i=0;i<num_voice_types;i++)
- {
- voice_types[i].category=(ScreamSoundCategory*) PoolAllocateMem( num_voice_cats * sizeof(ScreamSoundCategory));
- for(int j=0;j<num_voice_cats;j++)
- {
- ScreamSoundCategory* cat=&voice_types[i].category[j];
- cat->last_sound=SID_NOSOUND;
- cat->num_sounds=*(int*)bufpos;
- bufpos+=4;
-
- if(cat->num_sounds)
- {
- cat->sounds=(ScreamSound*) PoolAllocateMem(cat->num_sounds * sizeof(ScreamSound));
- }
- else
- {
- cat->sounds=0;
- }
-
- for(int k=0;k<cat->num_sounds;)
- {
- ScreamSound * sound=&cat->sounds[k];
-
- strcpy(wavname,bufpos);
- bufpos+=strlen(bufpos)+1;
-
- sound->pitch=*(int*)bufpos;
- bufpos+=4;
- sound->volume=*(int*)bufpos;
- bufpos+=4;
-
- sound->sound_loaded=GetSound(wavpath);
- if(sound->sound_loaded)
- {
- k++;
- }
- else
- {
- cat->num_sounds--;
- }
-
- }
-
- }
- }
-
- delete [] buffer;
-
-}
-#endif
-
void CharacterSoundEffects::LoadSounds(const char* filename,const char* directory)
{
@@ -162,8 +72,8 @@ void CharacterSoundEffects::LoadSounds(const char* filename,const char* director
char path[100]=ScreamFilePath;
strcat(path,filename);
- HANDLE file=CreateFile(path,GENERIC_READ, 0, 0, OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS, 0);
- if(file==INVALID_HANDLE_VALUE)
+ FILE *file = OpenGameFile(path, FILEMODE_READONLY, FILETYPE_PERM);
+ if(file==NULL)
{
LOGDXFMT(("Failed to open %s",path));
return;
@@ -171,12 +81,15 @@ void CharacterSoundEffects::LoadSounds(const char* filename,const char* director
char* buffer;
int file_size;
- unsigned long bytes_read;
- file_size= GetFileSize(file,0);
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ rewind(file);
+
buffer=new char[file_size+1];
- ReadFile(file,buffer,file_size,&bytes_read,0);
- CloseHandle(file);
+
+ fread(buffer, file_size, 1, file);
+ fclose(file);
if(strncmp("MARSOUND",buffer,8))
{
@@ -347,7 +260,6 @@ void UnloadScreamSounds()
}
-/* TODO: dir separator */
void LoadMarineScreamSounds()
{
MarineSounds.LoadSounds("marsound.dat","npc\\marinevoice\\");
View
21 src/avp/support/consbind.cpp
@@ -53,19 +53,7 @@
#endif
extern unsigned char KeyboardInput[];
extern unsigned char DebouncedKeyboardInput[];
-
- #if 0
- extern OurBool DaveDebugOn;
- extern FDIEXTENSIONTAG FDIET_Dummy;
- extern IFEXTENSIONTAG IFET_Dummy;
- extern FDIQUAD FDIQuad_WholeScreen;
- extern FDIPOS FDIPos_Origin;
- extern FDIPOS FDIPos_ScreenCentre;
- extern IFOBJECTLOCATION IFObjLoc_Origin;
- extern UncompressedGlobalPlotAtomID UGPAID_StandardNull;
- extern IFCOLOUR IFColour_Dummy;
- extern IFVECTOR IFVec_Zero;
- #endif
+
#ifdef __cplusplus
};
#endif
@@ -111,7 +99,8 @@ KeyBinding :: ParseBindCommand
SCString* pSCString_ToBind = new SCString(pProjCh_FollowingTheKey);
// Create the KeyBinding object:
- KeyBinding* pNewBinding = new KeyBinding
+ KeyBinding* pNewBinding;
+ pNewBinding = new KeyBinding
(
theKey,
pSCString_ToBind
@@ -185,7 +174,7 @@ KeyBinding :: ParseUnbindCommand
{
OurBool bGotMatch = No;
unsigned int LongestMatch = 0;
- BindableKey theKey_ToUnbind;
+ BindableKey theKey_ToUnbind = (BindableKey)0;
for (int i=0;i<MAX_VALUE_BINDABLE_KEY; i++)
{
@@ -384,7 +373,7 @@ void KeyBinding :: WriteToConfigFile(char* Filename)
GLOBALASSERT(Filename);
- FILE* pFile = fopen(Filename,"w");
+ FILE* pFile = OpenGameFile(Filename, FILEMODE_WRITEONLY, FILETYPE_CONFIG);
if (!pFile)
{
View
2  src/avp/support/consbtch.cpp
@@ -83,7 +83,7 @@ BatchFileProcessing :: Run(char* Filename)
RefList<SCString> PendingList;
{
- FILE* pFile = fopen(Filename,"r");
+ FILE* pFile = OpenGameFile(Filename, FILEMODE_READONLY, FILETYPE_CONFIG);
if (NULL==pFile)
{
View
30 src/avp/win95/ffread.cpp
@@ -69,7 +69,7 @@ void ReportError(char const * mesg1, char const * mesg2)
/***************/
#define READ_FILE(fname,post_proc,on_return,h,data,n_bytes,n_bytes_read,p5) \
- if (!ReadFile(h,data,n_bytes,&n_bytes_read,p5)) \
+ if ((n_bytes_read = fread(data, 1, n_bytes, h)) == 0) \
{ \
ReportError(fname); \
post_proc; \
@@ -181,8 +181,6 @@ FFHeaderI::FFHeaderI(char const *_filename,BOOL _should_be_kept)
{
filename = new char [strlen(_filename) + 1];
strcpy(filename,_filename);
-
- FixFilename(filename);
Read();
}
@@ -280,9 +278,9 @@ FFError FFHeaderI::Read(char const *_filename)
strcpy(filename,_filename);
}
- HANDLE h = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
+ FILE *h = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_PERM);
- if (INVALID_HANDLE_VALUE==h)
+ if (h == NULL)
{
ReportError(filename);
return FF_COULDNOTOPENFILE;
@@ -298,40 +296,40 @@ FFError FFHeaderI::Read(char const *_filename)
DWORD bytes_read;
- READ_FILE(filename,(void)0,CloseHandle(h),h,magic,4,bytes_read,0)
- READ_FILE(filename,(void)0,CloseHandle(h),h,&rffl_version,4,bytes_read,0)
- READ_FILE(filename,(void)0,CloseHandle(h),h,&num_files,4,bytes_read,0)
- READ_FILE(filename,(void)0,CloseHandle(h),h,&total_headsize,4,bytes_read,0)
- READ_FILE(filename,(void)0,CloseHandle(h),h,&length,4,bytes_read,0)
+ READ_FILE(filename,(void)0,fclose(h),h,magic,4,bytes_read,0)
+ READ_FILE(filename,(void)0,fclose(h),h,&rffl_version,4,bytes_read,0)
+ READ_FILE(filename,(void)0,fclose(h),h,&num_files,4,bytes_read,0)
+ READ_FILE(filename,(void)0,fclose(h),h,&total_headsize,4,bytes_read,0)
+ READ_FILE(filename,(void)0,fclose(h),h,&length,4,bytes_read,0)
if (strncmp(magic,"RFFL",4))
{
ReportError(filename,"Incorrect file type");
- CloseHandle(h);
+ fclose(h);
return FF_COULDNOTREADFILE;
}
if (rffl_version>0)
{
ReportError(filename,"Version not supported");
- CloseHandle(h);
+ fclose(h);
return FF_COULDNOTREADFILE;
}
void * header = malloc(total_headsize);
- READ_FILE(filename,(void)0,CloseHandle(h),h,header,total_headsize,bytes_read,0)
+ READ_FILE(filename,(void)0,fclose(h),h,header,total_headsize,bytes_read,0)
data = malloc(length);
- READ_FILE(filename,(void)0,CloseHandle(h),h,data,length,bytes_read,0)
+ READ_FILE(filename,(void)0,fclose(h),h,data,length,bytes_read,0)
- CloseHandle(h);
+ fclose(h);
// now parse the header
void * headerP = header;
- for (int i=0; i<num_files; ++i)
+ for (unsigned int i=0; i<num_files; ++i)
{
char const * fnameP = (char *)((size_t)headerP + 8);
size_t leng = *(size_t *)((size_t)headerP + 4);
View
12 src/avp/win95/ffstdio.cpp
@@ -54,7 +54,7 @@ FFileDesc::FFileDesc(char const * infoline, char const * path)
do
{
c2 = c1 = *infoline++;
- if (';'==c1||'\n'==c1)
+ if (';'==c1||'\n'==c1||'\r'==c1)
c1 = 0;
*dbufP++ = (char)c1;
}
@@ -65,7 +65,7 @@ FFileDesc::FFileDesc(char const * infoline, char const * path)
do
{
c1 = *infoline++;
- if ('\n'==c1)
+ if ('\n'==c1||'\r'==c1)
c1 = 0;
*fbufP++ = (char)c1;
}
@@ -158,7 +158,7 @@ static List<FFILE *> openlist;
int ffInit(char const * infofilename, char const * ffpath)
{
- FILE * fp = fopen(infofilename,"r");
+ FILE * fp = OpenGameFile(infofilename, FILEMODE_READONLY, FILETYPE_PERM);
if (!fp) return 0;
while (fdesclist.size())
@@ -370,7 +370,9 @@ FFILE * ffopen(char const * filename, char const * mode)
#if debug && 0 // dont do this, caller should handle this situation
LOGDXFMT(("%s not in any fastfile",filename));
- FILE * sfp = fopen(filename,mode);
+ /* mode is always "rb" */
+ FILE *sfp = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_PERM);
+
if (!sfp) return 0;
fseek(sfp,0,SEEK_END);
@@ -442,7 +444,7 @@ int ffseek(FFILE * fp, long offset, int whence)
switch (whence)
{
case SEEK_SET:
- if (offset > fp->length || offset < 0)
+ if ((unsigned long)offset > fp->length || offset < 0)
{
fp->flag |= FFF_ERR;
errno = EDOM;
View
47 src/avp/win95/frontend/avp_envinfo.c
@@ -182,26 +182,25 @@ static char *RifNamesForEnvironments[] =
"Not a Level",//AVP_ENVIRONMENT_END_OF_LIST
//multipack multiplayer levels
- "Leadworks",//AVP_ENVIRONMENT_LEADWORKS_MP,
- "HadleysHope",//AVP_ENVIRONMENT_HADLEYSHOPE_MP,
- "Meat_Factory",//AVP_ENVIRONMENT_MEATFACTORY_MP,
- "Nostromo",//AVP_ENVIRONMENT_NOSTROMO_MP,
- "Subway",//AVP_ENVIRONMENT_SUBWAY_MP,
- "Elevator",//AVP_ENVIRONMENT_ELEVATOR_MP,
- "Lab14",//AVP_ENVIRONMENT_LAB14_MP,
- "Compound",//AVP_ENVIRONMENT_COMPOUND_MP,
- "Office",//AVP_ENVIRONMENT_OFFICE_MP,
+ "leadworks",//AVP_ENVIRONMENT_LEADWORKS_MP,
+ "hadleyshope",//AVP_ENVIRONMENT_HADLEYSHOPE_MP,
+ "meat_factory",//AVP_ENVIRONMENT_MEATFACTORY_MP,
+ "nostromo",//AVP_ENVIRONMENT_NOSTROMO_MP,
+ "subway",//AVP_ENVIRONMENT_SUBWAY_MP,
+ "elevator",//AVP_ENVIRONMENT_ELEVATOR_MP,
+ "lab14",//AVP_ENVIRONMENT_LAB14_MP,
+ "compound",//AVP_ENVIRONMENT_COMPOUND_MP,
+ "office",//AVP_ENVIRONMENT_OFFICE_MP,
//multipack multiplayer cooperative levels
- "Leadworks_coop",//AVP_ENVIRONMENT_LEADWORKS_COOP,
+ "leadworks_coop",//AVP_ENVIRONMENT_LEADWORKS_COOP,
"hadleyshope_coop",//AVP_ENVIRONMENT_HADLEYSHOPE_COOP,
- "Co-op_Meat_Factory",//AVP_ENVIRONMENT_MEATFACTORY_COOP,
- "Nostromo_Coop",//AVP_ENVIRONMENT_NOSTROMO_COOP,
- "SubwayCoop",//AVP_ENVIRONMENT_SUBWAY_COOP,
- "Elevator_co-op",//AVP_ENVIRONMENT_ELEVATOR_COOP,
- "Lab14coop",//AVP_ENVIRONMENT_LAB14_COOP,
- "CompoundCoop",//AVP_ENVIRONMENT_COMPOUND_COOP,
-
+ "co-op_meat_factory",//AVP_ENVIRONMENT_MEATFACTORY_COOP,
+ "nostromo_coop",//AVP_ENVIRONMENT_NOSTROMO_COOP,
+ "subwaycoop",//AVP_ENVIRONMENT_SUBWAY_COOP,
+ "elevator_co-op",//AVP_ENVIRONMENT_ELEVATOR_COOP,
+ "lab14coop",//AVP_ENVIRONMENT_LAB14_COOP,
+ "compoundcoop",//AVP_ENVIRONMENT_COMPOUND_COOP,
};
extern char LevelName[];
@@ -5142,7 +5141,7 @@ void SetLevelToLoadForMultiplayer(int episode)
{
//it certainly is
//(the game type sent passed to the function doesn't really matter , as long as it isn't NGT_COOP)
- sprintf(LevelName,"Custom\\%s",GetCustomMultiplayerLevelName(episode,NGT_Individual));
+ sprintf(LevelName,"Custom/%s",GetCustomMultiplayerLevelName(episode,NGT_Individual));
}
else
{
@@ -5155,7 +5154,7 @@ void SetLevelToLoadForCooperative(int episode)
if(episode>=MAX_NO_OF_COOPERATIVE_EPISODES)
{
//it certainly is
- sprintf(LevelName,"Custom\\%s",GetCustomMultiplayerLevelName(episode,NGT_Coop));
+ sprintf(LevelName,"Custom/%s",GetCustomMultiplayerLevelName(episode,NGT_Coop));
}
else
{
@@ -5200,14 +5199,14 @@ int NumberForCurrentLevel(void) {
static BOOL DoesNamedLevelExist(const char* level_name)
{
- HANDLE file_handle;
+ FILE *file_handle;
char filename[200];
- sprintf(filename,"avp_rifs\\%s.rif",level_name);
+ sprintf(filename, "avp_rifs/%s.rif", level_name);
- file_handle = CreateFile(filename,GENERIC_READ,0,0,OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS, 0);
- if(file_handle == INVALID_HANDLE_VALUE) return FALSE;
- CloseHandle(file_handle);
+ file_handle = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_PERM);
+ if(file_handle == NULL) return FALSE;
+ fclose(file_handle);
return TRUE;
}
View
95 src/avp/win95/frontend/avp_menus.c
@@ -110,7 +110,6 @@ static void KeyboardEntryQueue_Clear(void);
static void KeyboardEntryQueue_StartProcessing(void);
void ScanSaveSlots(void);
extern void GetFilenameForSaveSlot(int i, unsigned char *filenamePtr);
-static void GetHeaderInfoForSaveSlot(SAVE_SLOT_HEADER* save_slot,const char* filename);
static void PasteFromClipboard(char* Text,int MaxTextLength);
/* KJL 11:23:03 23/06/98 - Requirements
@@ -4451,7 +4450,7 @@ void DisplayVideoModeUnavailableScreen(void)
void CheckForCredits(void)
{
#if 0
- FILE *fp = fopen("credits.txt","rb");
+ FILE *fp = OpenGameFile("credits.txt", FILEMODE_READONLY, FILETYPE_PERM);
if (!fp)
{
@@ -5437,28 +5436,6 @@ static char KeyboardEntryQueue_ProcessCharacter(void)
-
-void ScanSaveSlots(void)
-{
- unsigned char filename[100];
- int i;
- SAVE_SLOT_HEADER *slotPtr = SaveGameSlot;
-
- for (i=0; i<NUMBER_OF_SAVE_SLOTS; i++, slotPtr++)
- {
- GetFilenameForSaveSlot(i,filename);
-
- GetHeaderInfoForSaveSlot(slotPtr,filename);
- }
-}
-
-extern void GetFilenameForSaveSlot(int i, unsigned char *filenamePtr)
-{
- sprintf(filenamePtr,"%s%s_%d.sav",USER_PROFILES_PATH,UserProfilePtr->Name,i+1);
-}
-
-
-
/*------------------------------------**
** Loading and saving main level info **
**------------------------------------*/
@@ -5502,7 +5479,6 @@ void SaveLevelHeader()
block->Difficulty = AvP.Difficulty;
block->NumberOfSavesLeft = (unsigned char) NumberOfSavesLeft;
-
}
void LoadLevelHeader(SAVE_BLOCK_HEADER* header)
@@ -5514,48 +5490,43 @@ void LoadLevelHeader(SAVE_BLOCK_HEADER* header)
AvP.ElapsedHours = block->ElapsedTime_Hours;
AvP.ElapsedMinutes = block->ElapsedTime_Minutes;
AvP.ElapsedSeconds = block->ElapsedTime_Seconds;
-
}
-static void GetHeaderInfoForSaveSlot(SAVE_SLOT_HEADER* save_slot,const char* filename)
+static void GetHeaderInfoForSaveSlot(SAVE_SLOT_HEADER* save_slot, const GameDirectoryFile *gdf)
{
LEVEL_SAVE_BLOCK block;
unsigned int file_size;
- unsigned int bytes_read;
- HANDLE file;
+ unsigned char filename[100];
+ FILE *file;
save_slot->SlotUsed = 0;
- file = CreateFile(filename,GENERIC_READ, 0, 0, OPEN_EXISTING,FILE_FLAG_RANDOM_ACCESS, 0);
+ sprintf(filename, "%s%s", USER_PROFILES_PATH, gdf->filename);
+ file = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_CONFIG);
- if(file==INVALID_HANDLE_VALUE)
+ if (file==NULL)
{
//failed to load (probably doesn't exist)
return;
}
-
-
- file_size = GetFileSize(file,0);
-
+
+ fseek(file, 0, SEEK_END);
+ file_size = ftell(file);
+ rewind(file);
+
if(file_size < sizeof(LEVEL_SAVE_BLOCK))
{
//obviously not much of a save file then...
- CloseHandle(file);
+ fclose(file);
return;
}
-{
- struct stat buf;
-
- if (stat(filename, &buf) != -1) {
- save_slot->TimeStamp = buf.st_mtime;
- }
-}
+ save_slot->TimeStamp = gdf->timestamp;
//load the level header
- ReadFile(file,&block,sizeof(block),(LPDWORD)&bytes_read,0);
- CloseHandle(file);
+ fread(&block, sizeof(block), 1, file);
+ fclose(file);
//a few checks
if(block.header.type != SaveBlock_MainHeader ||
@@ -5580,6 +5551,40 @@ static void GetHeaderInfoForSaveSlot(SAVE_SLOT_HEADER* save_slot,const char* fil
save_slot->SavesLeft = block.NumberOfSavesLeft;
}
+void ScanSaveSlots(void)
+{
+ unsigned char pattern[100], *ptr;
+ int i;
+ void *gd;
+ GameDirectoryFile *gdf;
+
+ sprintf(pattern, "%s_?.sav", UserProfilePtr->Name);
+ gd = OpenGameDirectory(USER_PROFILES_PATH, pattern, FILETYPE_CONFIG);
+ if (gd == NULL)
+ return;
+
+ while ((gdf = ScanGameDirectory(gd)) != NULL) {
+ if ((gdf->attr & FILEATTR_DIRECTORY) != 0)
+ continue;
+ if ((gdf->attr & FILEATTR_READABLE) == 0)
+ continue;
+
+ ptr = strrchr(gdf->filename, '.');
+ if (ptr == NULL)
+ continue;
+ ptr--;
+
+ i = *ptr - '1';
+ if (i >= 0 && (i < NUMBER_OF_SAVE_SLOTS)) {
+ GetHeaderInfoForSaveSlot(&SaveGameSlot[i], gdf);
+ }
+ }
+}
+
+extern void GetFilenameForSaveSlot(int i, unsigned char *filenamePtr)
+{
+ sprintf(filenamePtr,"%s%s_%d.sav",USER_PROFILES_PATH,UserProfilePtr->Name,i+1);
+}
static void CheckForLoadGame()
{
View
237 src/avp/win95/frontend/avp_mp_config.cpp
@@ -15,22 +15,16 @@
#define UseLocalAssert Yes
#include "ourasert.h"
-#include <glob.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-
extern "C"
{
extern void SetDefaultMultiplayerConfig();
extern char MP_SessionName[];
extern char MP_Config_Description[];
-#define MP_CONFIG_DIR "MPConfig"
-#define MP_CONFIG_WILDCARD "MPConfig/*.cfg"
+#define MP_CONFIG_DIR "MPConfig/"
+#define MP_CONFIG_WILDCARD "*.cfg"
-#define SKIRMISH_CONFIG_WILDCARD "MPConfig/*.skirmish_cfg"
+#define SKIRMISH_CONFIG_WILDCARD "*.skirmish_cfg"
static List<char*> ConfigurationFilenameList;
static List<char*> ConfigurationLocalisedFilenameList;
@@ -63,68 +57,48 @@ BOOL BuildLoadMPConfigMenu()
load_name=SKIRMISH_CONFIG_WILDCARD;
}
- glob_t globbuf;
- if (glob(load_name, 0, NULL, &globbuf))
- return FALSE;
+ void *gd;
+ GameDirectoryFile *gdf;
- // get any path in the load_name
- int nPathLen = 0;
- char * pColon = strrchr(load_name,':');
- if (pColon) nPathLen = pColon - load_name + 1;
- char * pBackSlash = strrchr(load_name,'\\');
- if (pBackSlash)
- {
- int nLen = pBackSlash - load_name + 1;
- if (nLen > nPathLen) nPathLen = nLen;
- }
- char * pSlash = strrchr(load_name,'/');
- if (pSlash)
- {
- int nLen = pSlash - load_name + 1;
- if (nLen > nPathLen) nPathLen = nLen;
+ gd = OpenGameDirectory(MP_CONFIG_DIR, load_name, FILETYPE_CONFIG);
+ if (gd == NULL) {
+ CreateGameDirectory(MP_CONFIG_DIR); /* maybe it didn't exist.. */
+ return FALSE;
}
- for (unsigned int i = 0; i < globbuf.gl_pathc; i++) {
- struct stat buf;
-
- if (stat(globbuf.gl_pathv[i], &buf) == -1)
+ while ((gdf = ScanGameDirectory(gd)) != NULL) {
+ if ((gdf->attr & FILEATTR_DIRECTORY) != 0)
+ continue;
+ if ((gdf->attr & FILEATTR_READABLE) == 0)
continue;
-
- if (S_ISREG(buf.st_mode) && (access(globbuf.gl_pathv[i], R_OK) == 0)) {
- char *filename = strrchr(globbuf.gl_pathv[i], '/');
- if (filename)
- filename++;
- else
- filename = globbuf.gl_pathv[i];
- char* name=new char[strlen(filename)+1];
- strcpy(name,filename);
- char* dotpos=strrchr(name,'.');
- if(dotpos) *dotpos=0;
-
- ConfigurationFilenameList.add_entry(name);
+ char* name=new char[strlen(gdf->filename)+1];
+ strcpy(name,gdf->filename);
+ char* dotpos=strrchr(name,'.');
+ if(dotpos) *dotpos=0;
+
+ ConfigurationFilenameList.add_entry(name);
- BOOL localisedFilename=FALSE;
+ BOOL localisedFilename=FALSE;
- //seeif this is one of the default language localised configurations
- if(!strncmp(name,"Config",6))
- {
- if(name[6]>='1' && name[6]<='7' && name[7]=='\0')
- {
- TEXTSTRING_ID string_index=(TEXTSTRING_ID)(TEXTSTRING_MPCONFIG1_FILENAME+(name[6]-'1'));
- ConfigurationLocalisedFilenameList.add_entry(GetTextString(string_index));
- localisedFilename=TRUE;
- }
- }
- if(!localisedFilename)
+ //seeif this is one of the default language localised configurations
+ if(!strncmp(name,"Config",6))
+ {
+ if(name[6]>='1' && name[6]<='7' && name[7]=='\0')
{
- ConfigurationLocalisedFilenameList.add_entry(name);
+ TEXTSTRING_ID string_index=(TEXTSTRING_ID)(TEXTSTRING_MPCONFIG1_FILENAME+(name[6]-'1'));
+ ConfigurationLocalisedFilenameList.add_entry(GetTextString(string_index));
+ localisedFilename=TRUE;
}
}
+ if(!localisedFilename)
+ {
+ ConfigurationLocalisedFilenameList.add_entry(name);
+ }
}
- globfree(&globbuf);
-
+ CloseGameDirectory(gd);
+
//delete the old menu
if(AvPMenu_Multiplayer_LoadConfig) delete AvPMenu_Multiplayer_LoadConfig;
@@ -195,7 +169,7 @@ const char* GetMultiplayerConfigDescription(int index)
else
sprintf(filename,"%s/%s.cfg",MP_CONFIG_DIR,name);
- file=fopen(filename,"rb");
+ file= OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_CONFIG);
if(!file)
{
return 0;
@@ -233,7 +207,7 @@ void LoadMultiplayerConfiguration(const char* name)
else
sprintf(filename,"%s/%s.cfg",MP_CONFIG_DIR,name);
- file=fopen(filename,"rb");
+ file= OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_CONFIG);
if(!file) return;
@@ -330,7 +304,6 @@ void LoadMultiplayerConfiguration(const char* name)
netGameData.customLevelName[0] = 0;
}
}
-
}
void SaveMultiplayerConfiguration(const char* name)
@@ -342,10 +315,15 @@ void SaveMultiplayerConfiguration(const char* name)
else
sprintf(filename,"%s/%s.cfg",MP_CONFIG_DIR,name);
- CreateDirectory(MP_CONFIG_DIR,0);
- file=fopen(filename,"wb");
- if(!file) return;
-
+
+ file = OpenGameFile(filename, FILEMODE_WRITEONLY, FILETYPE_CONFIG);
+ if (file == NULL) {
+ CreateGameDirectory(MP_CONFIG_DIR); /* try again */
+ file = OpenGameFile(filename, FILEMODE_WRITEONLY, FILETYPE_CONFIG);
+ if (file == NULL)
+ return;
+ }
+
fwrite(&netGameData.gameType,sizeof(int),1,file);
fwrite(&netGameData.levelNumber,sizeof(int),1,file);
fwrite(&netGameData.scoreLimit,sizeof(int),1,file);
@@ -427,7 +405,6 @@ void SaveMultiplayerConfiguration(const char* name)
delete [] LastDescriptionText;
LastDescriptionFile=0;
LastDescriptionText=0;
-
}
@@ -441,12 +418,12 @@ void DeleteMultiplayerConfigurationByIndex(int index)
else
sprintf(filename,"%s/%s.cfg",MP_CONFIG_DIR,ConfigurationFilenameList[index]);
- DeleteFile(filename);
+ DeleteGameFile(filename);
}
-#define IP_ADDRESS_DIR "IP_Address"
-#define IP_ADDRESS_WILDCARD "IP_Address/*.IP Address"
+#define IP_ADDRESS_DIR "IP_Address/"
+#define IP_ADDRESS_WILDCARD "*.IP Address"
static List<char*> IPAddFilenameList;
@@ -465,52 +442,29 @@ BOOL BuildLoadIPAddressMenu()
//do a search for all the addresses in the address directory
- glob_t globbuf;
- const char* load_name=IP_ADDRESS_WILDCARD;
-
- if (glob(load_name, 0, NULL, &globbuf))
+ void *gd;
+ GameDirectoryFile *gdf;
+ gd = OpenGameDirectory(IP_ADDRESS_DIR, IP_ADDRESS_WILDCARD, FILETYPE_CONFIG);
+ if (gd == NULL) {
+ CreateGameDirectory(IP_ADDRESS_DIR); /* maybe it didn't exist.. */
return FALSE;
-
- // get any path in the load_name
- int nPathLen = 0;
- char * pColon = strrchr(load_name,':');
- if (pColon) nPathLen = pColon - load_name + 1;
- char * pBackSlash = strrchr(load_name,'\\');
- if (pBackSlash)
- {
- int nLen = pBackSlash - load_name + 1;
- if (nLen > nPathLen) nPathLen = nLen;
}
- char * pSlash = strrchr(load_name,'/');
- if (pSlash)
- {
- int nLen = pSlash - load_name + 1;
- if (nLen > nPathLen) nPathLen = nLen;
- }
-
- for (unsigned int i = 0; i < globbuf.gl_pathc; i++) {
- struct stat buf;
-
- if (stat(globbuf.gl_pathv[i], &buf) == -1)
+
+ while ((gdf = ScanGameDirectory(gd)) != NULL) {
+ if ((gdf->attr & FILEATTR_DIRECTORY) != 0)
+ continue;
+ if ((gdf->attr & FILEATTR_READABLE) == 0)
continue;
- if (S_ISREG(buf.st_mode) && (access(globbuf.gl_pathv[i], R_OK) == 0)) {
- char *filename = strrchr(globbuf.gl_pathv[i], '/');
- if (filename)
- filename++;
- else
- filename = globbuf.gl_pathv[i];
-
- char* name=new char[strlen(filename)+1];
- strcpy(name,filename);
- char* dotpos=strchr(name,'.');
- if(dotpos) *dotpos=0;
- IPAddFilenameList.add_entry(name);
- }
+ char* name=new char[strlen(gdf->filename)+1];
+ strcpy(name,gdf->filename);
+ char* dotpos=strchr(name,'.');
+ if(dotpos) *dotpos=0;
+ IPAddFilenameList.add_entry(name);
}
- globfree(&globbuf);
-
+ CloseGameDirectory(gd);
+
//delete the old menu
if(AvPMenu_Multiplayer_LoadIPAddress) delete [] AvPMenu_Multiplayer_LoadIPAddress;
@@ -544,9 +498,13 @@ void SaveIPAddress(const char* name,const char* address)
char filename[200];
sprintf(filename,"%s/%s.IP Address",IP_ADDRESS_DIR,name);
- CreateDirectory(IP_ADDRESS_DIR,0);
- file=fopen(filename,"wb");
- if(!file) return;
+ file = OpenGameFile(filename, FILEMODE_WRITEONLY, FILETYPE_CONFIG);
+ if (file == NULL) {
+ CreateGameDirectory(IP_ADDRESS_DIR); /* try again */
+ file = OpenGameFile(filename, FILEMODE_WRITEONLY, FILETYPE_CONFIG);
+ if (file == NULL)
+ return;
+ }
fwrite(address,1,strlen(address)+1,file);
@@ -556,15 +514,14 @@ void SaveIPAddress(const char* name,const char* address)
void LoadIPAddress(const char* name)
{
extern char IPAddressString[];
-
-
+
if(!name) return;
FILE* file;
char filename[200];
sprintf(filename,"%s/%s.IP Address",IP_ADDRESS_DIR,name);
- file=fopen(filename,"rb");
+ file=OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_CONFIG);
if(!file) return;
fread(IPAddressString,1,16,file);
@@ -598,41 +555,33 @@ void BuildMultiplayerLevelNameArray()
//first do a search for custom level rifs
// allow a wildcard search
-
- const char* load_name="avp_rifs/custom/*.rif";
-
- glob_t globbuf;
+ void *gd;
+ GameDirectoryFile *gdf;
- if (glob(load_name, 0, NULL, &globbuf) == 0) {
+ /* TODO: Have to use PERM until the load_rif code can handle CONFIG */
+ if ((gd = OpenGameDirectory("avp_rifs/Custom/", "*.rif", FILETYPE_PERM)) != NULL) {
char* custom_string = GetTextString(TEXTSTRING_CUSTOM_LEVEL);
int cs_len = strlen(custom_string);
- for (unsigned int i = 0; i < globbuf.gl_pathc; i++) {
- struct stat buf;
-
- if (stat(globbuf.gl_pathv[i], &buf) == -1)
+ while ((gdf = ScanGameDirectory(gd)) != NULL) {
+ if ((gdf->attr & FILEATTR_DIRECTORY) != 0)
continue;
-
- if (S_ISREG(buf.st_mode) && (access(globbuf.gl_pathv[i], R_OK) == 0)) {
- char *filename = strrchr(globbuf.gl_pathv[i], '/');
- if (filename)
- filename++;
- else
- filename = globbuf.gl_pathv[i];
-
- char* name=new char[strlen(filename)+cs_len+3+1];
+ if ((gdf->attr & FILEATTR_READABLE) == 0)
+ continue;
+
+ char* name=new char[strlen(gdf->filename)+cs_len+3+1];
- strcpy(name, filename);
- char* dotpos=strrchr(name,'.');
- if(dotpos) *dotpos=0;
- strcat(name," (");
- strcat(name,custom_string);
- strcat(name,")");
-
- CustomLevelNameList.add_entry(name);
- }
+ strcpy(name, gdf->filename);
+ char* dotpos=strrchr(name,'.');
+ if(dotpos) *dotpos=0;
+ strcat(name," (");
+ strcat(name,custom_string);
+ strcat(name,")");
+ CustomLevelNameList.add_entry(name);
}
- globfree(&globbuf);
+ CloseGameDirectory(gd);
+ } else {
+ CreateGameDirectory("Custom/"); /* maybe it didn't exist.. */
}
NumCustomLevels = CustomLevelNameList.size();
View
100 src/avp/win95/frontend/avp_userprofile.cpp
@@ -20,11 +20,6 @@ extern "C"
#include "pldnet.h"
#include <time.h>
-#include <glob.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
static int LoadUserProfiles(void);
static void EmptyUserProfilesList(void);
@@ -112,9 +107,9 @@ extern int SaveUserProfile(AVP_USER_PROFILE *profilePtr)
strcat(filename,profilePtr->Name);
strcat(filename,USER_PROFILES_SUFFIX);
- FILE* file=fopen(filename,"wb");
+ FILE* file=OpenGameFile(filename, FILEMODE_WRITEONLY, FILETYPE_CONFIG);
delete [] filename;
- if(!file) return 0;
+ if (!file) return 0;
SaveSettingsToUserProfile(profilePtr);
@@ -135,7 +130,7 @@ extern void DeleteUserProfile(int number)
strcat(filename,profilePtr->Name);
strcat(filename,USER_PROFILES_SUFFIX);
- DeleteFile(filename);
+ DeleteGameFile(filename);
delete [] filename;
{
@@ -145,7 +140,7 @@ extern void DeleteUserProfile(int number)
for (i=0; i<NUMBER_OF_SAVE_SLOTS; i++)
{
sprintf(filename,"%s%s_%d.sav",USER_PROFILES_PATH,profilePtr->Name,i+1);
- DeleteFile(filename);
+ DeleteGameFile(filename);
}
delete [] filename;
}
@@ -180,71 +175,54 @@ static int ProfileIsMoreRecent(AVP_USER_PROFILE *profilePtr, AVP_USER_PROFILE *p
static int LoadUserProfiles(void)
{
- glob_t globbuf;
- const char* load_name=USER_PROFILES_WILDCARD_NAME;
+ void *gd;
+ GameDirectoryFile *gdf;
- if (glob(load_name, 0, NULL, &globbuf))
+ gd = OpenGameDirectory(USER_PROFILES_PATH, USER_PROFILES_WILDCARD_NAME, FILETYPE_CONFIG);
+ if (gd == NULL) {
+ CreateGameDirectory(USER_PROFILES_PATH); /* maybe it didn't exist.. */
return 0;
-
- // get any path in the load_name
- int nPathLen = 0;
- char * pColon = strrchr(load_name,':');
- if (pColon) nPathLen = pColon - load_name + 1;
- char * pBackSlash = strrchr(load_name,'\\');
- if (pBackSlash)
- {
- int nLen = pBackSlash - load_name + 1;
- if (nLen > nPathLen) nPathLen = nLen;
- }
- char * pSlash = strrchr(load_name,'/');
- if (pSlash)
- {
- int nLen = pSlash - load_name + 1;
- if (nLen > nPathLen) nPathLen = nLen;
}
- for (unsigned int i = 0; i < globbuf.gl_pathc; i++) {
- struct stat buf;
-
- if (stat(globbuf.gl_pathv[i], &buf) == -1)
+ int nPathLen = strlen(USER_PROFILES_PATH);
+
+ while ((gdf = ScanGameDirectory(gd)) != NULL) {
+ if ((gdf->attr & FILEATTR_DIRECTORY) != 0)
+ continue;
+ if ((gdf->attr & FILEATTR_READABLE) == 0)
continue;
- if (S_ISREG(buf.st_mode) && (access(globbuf.gl_pathv[i], R_OK) == 0))
- {
- char * pszFullPath = new char [nPathLen+strlen(globbuf.gl_pathv[i])+1];
- // strncpy(pszFullPath,load_name,nPathLen);
- strcpy(pszFullPath /* +nPathLen */, globbuf.gl_pathv[i]);
-
- HANDLE rif_file;
- rif_file = CreateFile (pszFullPath, GENERIC_READ, 0, 0, OPEN_EXISTING,
- FILE_FLAG_RANDOM_ACCESS, 0);
- if(rif_file==INVALID_HANDLE_VALUE)
- {
- delete[] pszFullPath;
- continue;
- }
-
- AVP_USER_PROFILE *profilePtr = new AVP_USER_PROFILE;
- unsigned long bytes_read;
+ char * pszFullPath = new char [nPathLen+strlen(gdf->filename)+1];
+ strcpy(pszFullPath, USER_PROFILES_PATH);
+ strcat(pszFullPath, gdf->filename);
- if (!ReadFile(rif_file, profilePtr, sizeof(AVP_USER_PROFILE), &bytes_read, 0))
- {
- CloseHandle (rif_file);
- delete[] pszFullPath;
- delete profilePtr;
- continue;
- }
+ FILE *rif_file;
+ rif_file = OpenGameFile(pszFullPath, FILEMODE_READONLY, FILETYPE_CONFIG);
+ if(rif_file==NULL)
+ {
+ delete[] pszFullPath;
+ continue;
+ }
- profilePtr->FileTime = buf.st_mtime;
+ AVP_USER_PROFILE *profilePtr = new AVP_USER_PROFILE;
- InsertProfileIntoList(profilePtr);
- CloseHandle (rif_file);
+ if (fread(profilePtr, 1, sizeof(AVP_USER_PROFILE), rif_file) != sizeof(AVP_USER_PROFILE))
+ {
+ fclose(rif_file);
delete[] pszFullPath;
+ delete profilePtr;
+ continue;
}
+
+ profilePtr->FileTime = gdf->timestamp;
+
+ InsertProfileIntoList(profilePtr);
+ fclose(rif_file);
+ delete[] pszFullPath;
}
- globfree(&globbuf);
-
+ CloseGameDirectory(gd);
+
return 1;
}
View
2  src/avp/win95/frontend/avp_userprofile.h
@@ -145,7 +145,7 @@ typedef struct
#define USER_PROFILES_PATH "User_Profiles/"
-#define USER_PROFILES_WILDCARD_NAME "User_Profiles/*.prf"
+#define USER_PROFILES_WILDCARD_NAME "*.prf"
#define USER_PROFILES_SUFFIX ".prf"
View
7 src/avp/win95/objsetup.cpp
@@ -3719,6 +3719,9 @@ void setup_sounds (Environment_Data_Chunk * envd)
stt->outer_range = snd->outer_range * local_scale;
stt->max_volume = snd->max_volume;
stt->pitch = snd->pitch;
+
+ stt->playing = 0;
+ stt->loop = 0;
if(snd->flags & SoundObjectFlag_NotPlayingAtStart)
stt->playing=0;
@@ -3729,13 +3732,11 @@ void setup_sounds (Environment_Data_Chunk * envd)
stt->loop=0;
else
stt->loop=1;
-
stt->sound_name =(char*) PoolAllocateMem(strlen (snd->wav_name) + 1);
strcpy(stt->sound_name,snd->wav_name);
stt->sound_loaded=GetSoundForMainRif(snd->wav_name);
-
-
+
AddToBehaviourList(snd->snd_name,snd->CalculateID(), I_BehaviourPlacedSound, (void *) stt);
}
}
View
4 src/avp/win95/platsup.c
@@ -52,7 +52,7 @@ void catpathandextension(char* dst, char* src)
if ((len > 0 && (dst[len-1] != '\\' && dst[len-1] != '/')) && *src != '.')
{
- lstrcat(dst,"\\");
+ lstrcat(dst,"/");
}
lstrcat(dst,src);
@@ -367,7 +367,7 @@ char *LoadTextFile(char *filename)
char *bufferPtr;
long int save_pos, size_of_file;
FILE *fp;
- fp = fopen(filename,"rb");
+ fp = OpenGameFile(filename, FILEMODE_READONLY, FILETYPE_PERM);
if (!fp) goto error;
View
31 src/avp/win95/projload.cpp
@@ -84,12 +84,6 @@ const char * SubShps_Directory = "SubShps\\All\\";
// const char * GenTex_Directory = 0;
const char * FixTex_Directory = "\\\\Kate\\Kate Share\\avp\\Fix-Tex\\";
const char * GameTex_Directory = "\\\\Kate\\Kate Share\\avp\\game-tex\\";
-// these link with pcmenus.cpp
-const char * GenTex4bit_Directory = "\\\\Kate\\Kate Share\\avp\\G4bitTex\\";
-const char * GenTex8bit_Directory = "\\\\Kate\\Kate Share\\avp\\GenG-Tex\\";
-const char * GenTex75pc_Directory = "\\\\Kate\\Kate Share\\avp\\Gen34Tex\\";
-const char * GenTex50pc_Directory = "\\\\Kate\\Kate Share\\avp\\Gen12Tex\\";
-
// new directories for new-style graphics - to be determined properly
char const * FirstTex_Directory = "Graphics"; // currently relative to cwd
char const * SecondTex_Directory = 0; // will be the src safe shadow for development builds
@@ -357,9 +351,9 @@ struct LoadedPlacedHierarchy
#define NumPlacedHierarchy 3
LoadedPlacedHierarchy PlacedHierarchyArray[NumPlacedHierarchy]=
{
- "dropship","dropship",INVALID_RIFFHANDLE,
- "pred ship fury","pred ship fury",INVALID_RIFFHANDLE,
- "pred ship ob","pred ship ob",INVALID_RIFFHANDLE,
+ { "dropship","dropship",INVALID_RIFFHANDLE },
+ { "pred ship fury","pred ship fury",INVALID_RIFFHANDLE },
+ { "pred ship ob","pred ship ob",INVALID_RIFFHANDLE },
};
@@ -368,7 +362,6 @@ void LoadedPlacedHierarchy::load_rif()
if(placed_rif!=INVALID_RIFFHANDLE) return;
char file_path[100];
-/* TODO: dir seperator */
sprintf(file_path,"avp_huds/%s.rif",file_name);
placed_rif=avp_load_rif_non_env(file_path);
@@ -505,7 +498,6 @@ Global_Hierarchy_Store::Global_Hierarchy_Store (RIFFHANDLE h)
sound_array[index].volume=isc->max_volume;
if(dir_chunk)
{
- /* TODO: dir separator */
sprintf(wavname,"%s\\%s",dir_chunk->directory,isc->wav_name);
sound_array[index].sound_loaded=GetSound(wavname);
}
@@ -516,14 +508,9 @@ Global_Hierarchy_Store::Global_Hierarchy_Store (RIFFHANDLE h)
if(sound_array[index].sound_loaded)
{
sound_array[index].sound_index=(SOUNDINDEX)sound_array[index].sound_loaded->sound_num;
- }
-
-
+ }
}
}
-
-
-
}
@@ -1989,7 +1976,6 @@ BOOL copy_rif_data (RIFFHANDLE h, int flags,int progress_start,int progress_inte
int start_shape_no = rt_temp.start_list_pos;
int list_pos = rt_temp.main_list_pos;
db_logf3(("Shape copied to %d",list_pos));
- MORPHCTRL * mc = rt_temp.mc;
#else
int list_pos = copy_to_mainshapelist(h,shplif(),flags,&ob->object_data);
int start_shape_no = list_pos;
@@ -3010,10 +2996,9 @@ void DeallocateLoadedShapeheader(SHAPEHEADER * shp)
void DeallocateModules()
{
-
- MODULE ** m_arrayPtr = MainScene.sm_marray;
-
#if !USE_LEVEL_MEMORY_POOL
+ MODULE ** m_arrayPtr = MainScene.sm_marray;
+
while (*m_arrayPtr)
{
List<Light_Chunk *> lights_for_this_module;
@@ -3092,7 +3077,7 @@ void avp_undo_rif_load(RIFFHANDLE h)
RIFFHANDLE avp_load_rif (const char * fname)
{
//see if there is a local copy of the rif file
- FILE* rifFile = fopen(fname,"rb");
+ FILE* rifFile = OpenGameFile(fname, FILEMODE_READONLY, FILETYPE_PERM);
/* TODO: Let's find a better method */
if (!rifFile && AvpCDPath)
@@ -3111,7 +3096,7 @@ RIFFHANDLE avp_load_rif (const char * fname)
RIFFHANDLE avp_load_rif_non_env (const char * fname)
{
//see if there is a local copy of the rif file
- FILE* rifFile = fopen(fname, "rb");
+ FILE* rifFile = OpenGameFile(fname, FILEMODE_READONLY, FILETYPE_PERM);
/* TODO: Let's find a better method */
if (!rifFile && AvpCDPath)
View
12 src/avp/win95/scrshot.cpp
@@ -27,10 +27,13 @@ extern void LoadModuleData();
void LogCameraPosForModuleLinking()
{
+ fprintf(stderr, "STUB: LogCameraPosForModuleLinking()\n");
+
+#if 0 /* TODO: commented out because I want to know if its actually used */
if(!playerPherModule) return;
if(!playerPherModule->name) return;
- char Filename[100]={"avp_rifs\\"};
+ char Filename[100]={"avp_rifs/"};
strcat(Filename,Env_List[AvP.CurrentEnv]->main);
strcat(Filename,".mlf");
@@ -59,6 +62,7 @@ void LogCameraPosForModuleLinking()
fwrite(&output_buffer[0],4,length/4,file);
fclose(file);
textprint("Saving camera for module links");
+#endif
}
int SaveCameraPosKeyPressed=0;
static BOOL ModuleLinkAssist=FALSE;
@@ -115,7 +119,7 @@ void ScreenShot()
{
Name[length]=i/10+'0';
Name[length+1]=(i%10)+'0';
- FILE* tempfp=fopen(Name,"r");
+ FILE* tempfp = OpenGameFile(Name, FILEMODE_READONLY, FILETYPE_CONFIG);
if(!tempfp)break;
else
{
@@ -124,7 +128,7 @@ void ScreenShot()
}
if(i==100) return;
- FILE * fp = fopen(Name,"wb");
+ FILE *fp = OpenGameFile(Name, FILEMODE_WRITEONLY, FILETYPE_CONFIG);
if (!fp)
{
return;
@@ -190,7 +194,7 @@ void ScreenShot()
unsigned char *BufferPtr = &buf[0];
for (i=h.WinInfo.Height-1; i>=0; --i)
{
- int j;
+ unsigned int j;
for (j=0; j<h.WinInfo.Width; ++j)
{
PutByte((BYTE)BufferPtr[j*3+2],fp); //b
View
10 src/avp/win95/system.c
@@ -734,8 +734,8 @@ void IntegrateNewEnvironment()
}
-const char GameDataDirName[20] = {"AVP_RIFS"};
-const char FileNameExtension[5] = {".RIF"};
+const char GameDataDirName[20] = {"avp_rifs"};
+const char FileNameExtension[5] = {".rif"};
void LoadRifFile()
{
@@ -760,8 +760,6 @@ void LoadRifFile()
catpathandextension(&file_and_path[0], Env_List[AvP.CurrentEnv]->main); /* root of the file name,smae as dir*/
catpathandextension(&file_and_path[0], (char *)&FileNameExtension[0]); /* extension*/
- FixFilename(file_and_path);
-
env_rif = avp_load_rif((const char*)&file_and_path[0]);
Set_Progress_Bar_Position(PBAR_LEVEL_START+PBAR_LEVEL_INTERVAL*.4);
@@ -772,10 +770,6 @@ void LoadRifFile()
};
-// #ifdef __WATCOMC__
-// #pragma message("Note: use copy_chunks_from_envronment(CCF_ENVIRONMENT) iff a character rif is loaded")
-// #endif
-
#if MaxImageGroups>1
SetCurrentImageGroup(2); // FOR ENV
#endif
View
4 src/avp/win95/usr_io.c
@@ -1718,7 +1718,7 @@ void SaveAKeyConfiguration(char* Filename)
void SaveDefaultPrimaryConfigs(void)
{
- FILE* file=fopen("default.cfg","wb");
+ FILE *file = OpenGameFile("default.cfg", FILEMODE_WRITEONLY, FILETYPE_CONFIG);
if(!file) return;
fwrite(&DefaultMarineInputPrimaryConfig,sizeof(PLAYER_INPUT_CONFIGURATION),1,file);
@@ -1729,7 +1729,7 @@ void SaveDefaultPrimaryConfigs(void)
}
void LoadDefaultPrimaryConfigs(void)
{
- FILE* file=fopen("default.cfg","rb");
+ FILE *file = OpenGameFile("default.cfg", FILEMODE_READONLY, FILETYPE_CONFIG);
if(!file) return;
fread(&DefaultMarineInputPrimaryConfig,sizeof(PLAYER_INPUT_CONFIGURATION),1,file);
View
682 src/avp/win95/win_proj.cpp
@@ -1,682 +0,0 @@
-/****
-
-Project specific (or potentially
-project specific) windows functionality
-
-****/
-
-// To link code to main C functions
-
-extern "C" {
-
-#include "3dc.h"
-#include "inline.h"
-#include "cd_player.h"
-#include "psndplat.h"
-
-#include "rentrntq.h"
- // Added 21/11/97 by DHM: support for a queue of Windows
- // messages to avoid problems with re-entrancy due to WinProc()
-
-#include "alt_tab.h"
-
-#include "dxlog.h"
-#include "zmouse.h"
-
-void MakeToAsciiTable(void);
-
-// mousewheel msg id
-UINT const RWM_MOUSEWHEEL = RegisterWindowMessage(MSH_MOUSEWHEEL);
-signed int MouseWheelStatus;
-
-extern LPDIRECTDRAWSURFACE lpDDSBack;
-extern LPDIRECTDRAWSURFACE lpDDSPrimary;
-extern LPDIRECTDRAWSURFACE lpZBuffer;
-extern LPDIRECTDRAWSURFACE lpDDBackdrop;
-
-unsigned char ksarray[256];
-unsigned char ToAsciiTable[256][256];
-
-// Dubious
-#define grabmousecapture No
-
-/*
- Name of project window etc for Win95 interface
- Project specific (fairly obviously...).
- Determines the default menu in which the application
- appears (altho' other code will undoubtedly be needed
- as well...), so that a NULL here should ensure no menu.
-*/
-
-#define NAME "AvP"
-#define TITLE "AvP"
-
-// Necessary globals
-
-HWND hWndMain;
-BOOL bActive = TRUE; // is application active?
-
-// Parameters for main (assumed full screen) window
-int WinLeftX, WinRightX, WinTopY, WinBotY;
-int WinWidth, WinHeight;
-
-// Externs
-
-
-
-extern int VideoMode;
-extern int WindowMode;
-extern WINSCALEXY TopLeftSubWindow;
-extern WINSCALEXY ExtentXYSubWindow;
-
-// Window procedure (to run continuously while WinMain is active).
-// Only necessary functions are handling keyboard input (for the moment
-// at least - cf. DirectInput) and dealing with important system
-// messages, e.g. WM_PAINT.
-
-// Remember to support all the keys you need for your project
-// for both KEYUP and KEYDOWN messages!!!
-
-// IMPORTANT!!! The WindowProc is project specific
-// by default, since various nifty hacks can always
-// be implemented directly via the windows procedure
-
-#define RESTORE_SURFACE(lpDDS) { \
- if (lpDDS) { \
- if (DDERR_SURFACELOST == (lpDDS)->IsLost()) { \
- HRESULT hResult = (lpDDS)->Restore(); \
- LOGDXFMT(("%s surface was restored", #lpDDS )); \
- LOGDXERR(hResult); \
- } else { \
- LOGDXFMT(("%s surface wasn't lost", #lpDDS )); \
- } \
- } \
- else { \
- LOGDXFMT(("?&@#! no %s surface", #lpDDS )); \
- } \
-}
-
-extern void KeyboardEntryQueue_Add(char c);
-extern IngameKeyboardInput_KeyDown(unsigned char key);
-extern IngameKeyboardInput_KeyUp(unsigned char key);
-extern IngameKeyboardInput_ClearBuffer(void);
-
-
-long FAR PASCAL WindowProc(HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam)
-{
- PAINTSTRUCT ps;
- HDC hdc;
- RECT NewWindCoord;
-
- if (message==RWM_MOUSEWHEEL)
- {
- message = WM_MOUSEWHEEL;
- wParam <<= 16;
- }
-
-
- switch(message)
- {
-
- case WM_MOUSEWHEEL:
- {
- MouseWheelStatus = wParam;
- MouseWheelStatus>>=16;
- return 0;
- }
-
- // 21/11/97 DHM: Added porcessing of WM_CHAR messages:
- case WM_CHAR:
- RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_CHAR
- (
- (char) wParam
- );
- KeyboardEntryQueue_Add((char)wParam);
- return 0;
- case WM_KEYDOWN:
- RE_ENTRANT_QUEUE_WinProc_AddMessage_WM_KEYDOWN
- (
- wParam
- );
- // it's intentional for this case to fall through to WM_SYSKEYDOWN
- case WM_SYSKEYDOWN:
- {
- int scancode = (lParam>>16)&255;
- unsigned char vkcode = (wParam&255);
-
- // ignore the status of caps lock
- //ksarray[VK_CAPITAL] = 0;
- //ksarray[VK_CAPITAL] = GetKeyState(VK_CAPITAL);
- if (vkcode!=VK_CAPITAL && vkcode!=VK_SCROLL)
- {
- #if 0
- WORD output;
- if (ToAscii(vkcode,scancode,&ksarray[0],&output,0))
- {
- IngameKeyboardInput_KeyDown((unsigned char)(output));
- }
- #else
- if (ToAsciiTable[vkcode][scancode])
- {
- IngameKeyboardInput_KeyDown(ToAsciiTable[vkcode][scancode]);
- }
- #endif
- }
- // reset caps lock status
- //ksarray[VK_CAPITAL] = GetKeyState(VK_CAPITAL);
- //ToAscii(wParam&255,scancode,&ksarray[0],&output,0);
- }
- return 0;
-
- case WM_SYSKEYUP:
- case WM_KEYUP:
- {
- int scancode = (lParam>>16)&255;
- unsigned char vkcode = (wParam&255);
-
-
- // ignore the status of caps lock
- //ksarray[VK_CAPITAL] = 0;
-//MakeToAsciiTable();
- //ksarray[VK_CAPITAL] = GetKeyState(VK_CAPITAL);
- if (vkcode!=VK_CAPITAL && vkcode!=VK_SCROLL)
- {
- #if 0
- WORD output;
- unsigned char z = ToAscii(vkcode,scancode,&ksarray[0],&output,0);
- unsigned char a = (unsigned char)output;
- unsigned char b = ToAsciiTable[vkcode][scancode];
- #endif
- #if 0
- WORD output;
- if (ToAscii(vkcode,scancode,&ksarray[0],&output,0))
- {
- IngameKeyboardInput_KeyUp((unsigned char)(output));
- }
- #else
- if (ToAsciiTable[vkcode][scancode])
- {
- IngameKeyboardInput_KeyUp(ToAsciiTable[vkcode][scancode]);
- }
- #endif
- }
- // reset caps lock status
- //ksarray[VK_CAPITAL] = GetKeyState(VK_CAPITAL);
- //ToAscii(wParam&255,scancode,&ksarray[0],&output,0);
- }
- return 0;
-
- // This, in combination with code in win_func,
- // will hopefully disable Alt-Tabbing...
- case WM_ACTIVATEAPP:
- bActive = (BOOL) wParam;
-
- LOGDXFMT(("WM_ACTIVATEAPP msg: bActive = %d",(int)bActive));
-
- if (bActive)
- {
- // need to restore all surfaces - do the special ones first
- RESTORE_SURFACE(lpDDSPrimary)
- RESTORE_SURFACE(lpDDSBack)
- RESTORE_SURFACE(lpZBuffer)
- // dodgy, this is meant to be graphic, so it'll really need to be reloaded
- RESTORE_SURFACE(lpDDBackdrop)
- // now do all the graphics surfaces and textures, etc.
- ATOnAppReactivate();
- }
- IngameKeyboardInput_ClearBuffer();
-
- return 0;
-
- // Three below are for safety, to turn off
- // as much as possible of the more annoying
- // functionality of the default Windows
- // procedure handler
-
- case WM_ACTIVATE:
- return 0;
-#if 0
- case WM_SYSKEYUP:
- return 0;
-
- case WM_SYSKEYDOWN:
- return 0;
-#endif
- case WM_CREATE:
- break;
-
- case WM_MOVE:
- // Necessary to stop it crashing in 640x480
- // FullScreen modes on window initialisation
- if (WindowMode == WindowModeSubWindow)
- {
- GetWindowRect(hWndMain, &NewWindCoord);
- WinLeftX = NewWindCoord.left;
- WinTopY = NewWindCoord.top;
- WinRightX = NewWindCoord.right;
- WinBotY = NewWindCoord.bottom;
- }
- break;
-
- case WM_SIZE:
- // Necessary to stop it crashing in 640x480
- // FullScreen modes on window initialisation
- if (WindowMode == WindowModeSubWindow)
-
- {
- GetWindowRect(hWndMain, &NewWindCoord);
- WinLeftX = NewWindCoord.left;
- WinTopY = NewWindCoord.top;
- WinRightX = NewWindCoord.right;
- WinBotY = NewWindCoord.bottom;
- }
- break;
-
- case WM_SETCURSOR:
- SetCursor(NULL);
- return TRUE;
-
- case WM_ERASEBKGND:
- return TRUE;
-
- case WM_PAINT:
- hdc = BeginPaint(hWnd, &ps);
- EndPaint(hWnd, &ps);
- return TRUE;
-
- /* Patrick 11/6/97: this to detects the end of a cdda track */
- case MM_MCINOTIFY:
- PlatCDDAManagementCallBack(wParam, lParam);
- break;
-
- case WM_DESTROY:
- // Calls ReleaseDirect3D DIRECTLY,
- // so as to avoid calling ExitSystem and exiting the
- // Windows system inside the windows procedure
- // IMPORTANT!!! For this to work, release functions
- // must be re-entrant. Since this may be causing
- // problems under obscure cirumstances, I am removing
- // this now (25/7/96).
- // And putting it back... (20/9/96)
- ReleaseDirect3D();
- /* patrick 9/6/97: hmmmmm.... */
- PlatEndSoundSys();
-
- PostQuitMessage(0);
- break;
- }
-
- return DefWindowProc(hWnd, message, wParam, lParam);
-}
-
-/*
- Persuade Win95 to give us the window we want and, like,
- TOTAL CONTROL, and then shut up, stop whinging and
- go away.
- Or at least as much control as we can get.. safely...
- elegantly... ummm...
-*/
-
-// IMPORTANT!!! Windows initialisation is project specific,
-// because of the project name and title if nothing else
-
-// This function now takes a mode which is
-// set to full or change. Full should be
-// run ONLY when the system is starting.
-// Change is used to change the window
-// characteristics during a run, e.g. to
-// change from SubWindow to FullScreen
-// mode, and will not attempt to register
-// the windows class.
-
-BOOL InitialiseWindowsSystem(HANDLE hInstance, int nCmdShow,
- int WinInitMode)
-{
- WNDCLASS wc;
- BOOL rc;
-
- MakeToAsciiTable();
-/*
- Set up the width and height we want from
- the VideoMode, taking account of WindowMode.
-*/
-
-// This has now been modified to just set the
-// size to the current system metrics, which
-// may or may not be ideal. Surprisingly, it
-// seems not to make much difference.
-
- if (WindowMode == WindowModeSubWindow)
- {
-
- //force window to be 640x480 to avoid stretch blits.
- WinWidth=640;
- WinHeight=480;
-
- WinLeftX = (int) (TopLeftSubWindow.x *
- (float) GetSystemMetrics(SM_CXSCREEN));
- WinTopY = (int) (TopLeftSubWindow.y *
- (float) GetSystemMetrics(SM_CYSCREEN));
- WinRightX = (WinLeftX + WinWidth);
- WinBotY = (WinTopY + WinHeight);
- }
- else if (WindowMode == WindowModeFullScreen)
- {
- #if 1
- WinWidth = GetSystemMetrics(SM_CXSCREEN);
- WinHeight = GetSystemMetrics(SM_CYSCREEN);
- #else
- // This version of the code MUST be
- // kept up to date with new video modes!!!
- if ((VideoMode == VideoMode_DX_320x200x8) ||
- (VideoMode == VideoMode_DX_320x200x8T))
- {
- WinWidth = 320;
- WinHeight = 200;
- }
- else if (VideoMode == VideoMode_DX_320x240x8)
- {
- WinWidth = 320;
- WinHeight = 240;
- }
- else // Default to 640x480
- {
- WinWidth = 640;
- WinHeight = 480;
- }
- #endif
-
- // Set up globals for window corners
- WinLeftX = 0;
- WinTopY = 0;
- WinRightX = WinWidth;
- WinBotY = WinHeight;
- }
- else
- return FALSE;
-
-// We only want to register the class in
-// WinInitFull mode!!!
-
- if (WinInitMode == WinInitFull)
- {
-
-/*
- Set up and register window class
-*/
-// get double click messages from mouse if user double-clicks it
- wc.style = CS_DBLCLKS;
-// Name of window procedure (see above)
- wc.lpfnWndProc = WindowProc;
-/*
- Extra bytes for obscure purposes bearing a sordid relationship to
- dialog box conventions. Zero for us.
-*/
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
-// Instance which window is within
- wc.hInstance = (HINSTANCE) hInstance;
-/*
- System icon resource. This one is generic. For an actual
- game this icon will be project specific.
-*/
- #if 1
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- #else
- wc.hIcon = NULL;
- #endif
-// System cursor resource. This one is generic.
- #if 1
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- #else
- wc.hCursor = NULL;
- #endif
-/*
- NULL background forces application to redraw
- the background ITSELF when it receives a WM_ERASEBKGND
- message, leaving graphical control with the engine
-*/
- wc.hbrBackground = NULL;
-// Project name and class for windows menus etc.
- wc.lpszMenuName = NAME;
- wc.lpszClassName = NAME;
-/*
- Register the class we have constructed as a valid window that
- can then be created. Return code indicates success or