From af3c404e11867c6794975f1d45dd98932d804ede Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Fri, 22 Apr 2016 17:00:15 +0300 Subject: [PATCH] no more path splitting in wad reading, it's useless --- src/game/g_game.pas | 32 ++++---- src/game/g_gui.pas | 7 +- src/game/g_map.pas | 67 ++++++++-------- src/game/g_menu.pas | 8 +- src/game/g_netmaster.pas | 4 +- src/game/g_netmsg.pas | 2 +- src/game/g_playermodel.pas | 6 +- src/game/g_saveload.pas | 2 +- src/game/g_sound.pas | 14 ++-- src/game/g_textures.pas | 24 +++--- src/game/g_triggers.pas | 12 +-- src/shared/wadreader.pas | 153 +++++++++++++++++++++++++++---------- 12 files changed, 194 insertions(+), 137 deletions(-) diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 6379821..e17175b 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -483,7 +483,7 @@ begin w := TWADFile.Create(); w.ReadFile(WAD); - if not w.GetResource('', 'INTERSCRIPT', p, len) then + if not w.GetResource('INTERSCRIPT', p, len) then begin w.Free(); Exit; @@ -542,7 +542,7 @@ begin w := TWADFile.Create(); w.ReadFile(MapsDir + WAD); - if not w.GetResource('', 'INTERSCRIPT', p, len) then + if not w.GetResource('INTERSCRIPT', p, len) then begin w.Free(); Exit; @@ -579,14 +579,14 @@ begin MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', ''); if MegaWAD.endpic <> '' then begin - g_ProcessResourceStr(MegaWAD.endpic, @s, nil, nil); + s := g_ExtractWadName(MegaWAD.endpic); if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/'; g_Texture_CreateWADEx('TEXTURE_endpic', s+MegaWAD.endpic); end; MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ'); if MegaWAD.endmus <> '' then begin - g_ProcessResourceStr(MegaWAD.endmus, @s, nil, nil); + s := g_ExtractWadName(MegaWAD.endmus); if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/'; g_Sound_CreateWADEx('MUSIC_endmus', s+MegaWAD.endmus, True); end; @@ -664,7 +664,7 @@ end; procedure EndGame(); var a: Integer; - FileName, SectionName, ResName: string; + FileName: string; begin if g_Game_IsNet and g_Game_IsServer then MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed)); @@ -726,10 +726,10 @@ begin EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå begin // Ñòàòèñòèêà Ñâîåé èãðû: - g_ProcessResourceStr(gMapInfo.Map, FileName, SectionName, ResName); + FileName := g_ExtractWadName(gMapInfo.Map); CustomStat.GameTime := gTime; - CustomStat.Map := ExtractFileName(FileName)+':'+ResName; + CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName; CustomStat.MapName := gMapInfo.Name; CustomStat.GameMode := gGameSettings.GameMode; if gGameSettings.GameMode in [GM_TDM, GM_CTF] then @@ -841,8 +841,8 @@ begin e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32); e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0); - g_ProcessResourceStr(gMapInfo.Map, @wad, nil, @map); - wad := ExtractFileName(wad); + wad := g_ExtractWadNameNoPath(gMapInfo.Map); + map := g_ExtractFileName(gMapInfo.Map); mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name; case gGameSettings.GameMode of @@ -3662,7 +3662,7 @@ var begin if g_Game_IsClient then Exit; - g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map); + map := g_ExtractFileName(gMapInfo.Map); MessageTime := 0; gGameOn := False; @@ -3693,7 +3693,8 @@ begin if Pos(':\', Map) > 0 then begin - g_ProcessResourceStr(Map, @NewWAD, nil, @ResName); + NewWAD := g_ExtractWadName(Map); + ResName := g_ExtractFileName(Map); if g_Game_IsServer then begin gWADHash := MD5File(MapsDir + NewWAD); @@ -3871,7 +3872,7 @@ begin Exit; end; gExit := EXIT_ENDLEVELCUSTOM; - g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map); + Map := g_ExtractFileName(gMapInfo.Map); gNextMap := Map; end; @@ -4019,7 +4020,7 @@ begin if MapList = nil then Exit; - g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map); + Map := g_ExtractFileName(gMapInfo.Map); SortSArray(MapList); MapIndex := -255; @@ -4058,11 +4059,8 @@ begin end; function g_Game_IsTestMap(): Boolean; -var - FName, Sect, Res: String; begin - g_ProcessResourceStr(gMapInfo.Map, FName, Sect, Res); - Result := UpperCase(Res) = TEST_MAP_NAME; + result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map)); end; procedure g_Game_DeleteTestMap(); diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas index 973def6..9319e45 100644 --- a/src/game/g_gui.pas +++ b/src/game/g_gui.pas @@ -2469,12 +2469,12 @@ var panels: TPanelsRec1Array; header: TMapHeaderRec_1; a: Integer; - FileName, SectionName, ResName: string; + FileName: string; Data: Pointer; Len: Integer; rX, rY: Single; begin - g_ProcessResourceStr(Res, FileName, SectionName, ResName); + FileName := g_ExtractWadName(Res); WAD := TWADFile.Create(); if not WAD.ReadFile(FileName) then @@ -2483,7 +2483,8 @@ begin Exit; end; - if not WAD.GetResource('', ResName, Data, Len) then + //k8: ignores path again + if not WAD.GetResource(g_ExtractFileName(Res), Data, Len) then begin WAD.Free(); Exit; diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 8445e78..6c156ca 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -367,8 +367,6 @@ var WAD: TWADFile; TextureData: Pointer; WADName: String; - SectionName: String; - TextureName: String; a, ResLength: Integer; begin Result := -1; @@ -409,7 +407,7 @@ begin end; // Çàãðóæàåì ðåñóðñ òåêñòóðû â ïàìÿòü èç WAD'à: - g_ProcessResourceStr(RecName, WADName, SectionName, TextureName); + WADName := g_ExtractWadName(RecName); WAD := TWADFile.Create(); @@ -420,7 +418,7 @@ begin WAD.ReadFile(WADName); - if WAD.GetResource(SectionName, TextureName, TextureData, ResLength) then + if WAD.GetResource(g_ExtractFilePathName(RecName), TextureData, ResLength) then begin SetLength(Textures, Length(Textures)+1); if not e_CreateTextureMem(TextureData, ResLength, Textures[High(Textures)].TextureID) then @@ -452,8 +450,6 @@ var TextureData: Pointer; cfg: TConfig; WADName: String; - SectionName: String; - TextureName: String; ResLength: Integer; TextureResource: String; _width, _height, _framecount, _speed: Integer; @@ -462,7 +458,7 @@ begin Result := -1; // ×èòàåì WAD-ðåñóðñ àíèì.òåêñòóðû èç WAD'à â ïàìÿòü: - g_ProcessResourceStr(RecName, WADName, SectionName, TextureName); + WADName := g_ExtractWadName(RecName); WAD := TWADFile.Create(); @@ -473,7 +469,7 @@ begin WAD.ReadFile(WADName); - if not WAD.GetResource(SectionName, TextureName, TextureWAD, ResLength) then + if not WAD.GetResource(g_ExtractFilePathName(RecName), TextureWAD, ResLength) then begin if log then begin @@ -494,7 +490,7 @@ begin end; // ×èòàåì INI-ðåñóðñ àíèì. òåêñòóðû è çàïîìèíàåì åãî óñòàíîâêè: - if not WAD.GetResource('TEXT', 'ANIM', TextData, ResLength) then + if not WAD.GetResource('TEXT/ANIM', TextData, ResLength) then begin FreeMem(TextureWAD); WAD.Free(); @@ -523,7 +519,7 @@ begin cfg.Free(); // ×èòàåì ðåñóðñ òåêñòóð (êàäðîâ) àíèì. òåêñòóðû â ïàìÿòü: - if not WAD.GetResource('TEXTURES', TextureResource, TextureData, ResLength) then + if not WAD.GetResource('TEXTURES/'+TextureResource, TextureData, ResLength) then begin FreeMem(TextureWAD); FreeMem(TextData); @@ -776,8 +772,7 @@ var DoorPanel: Integer; ShotPanel: Integer; end; - FileName, SectionName, ResName, - FileName2, s, TexName: String; + FileName, mapResName, s, TexName: String; Data: Pointer; Len: Integer; ok, isAnim, trigRef: Boolean; @@ -791,8 +786,8 @@ begin sfsGCDisable(); // temporary disable removing of temporary volumes try // Çàãðóçêà WAD: - g_ProcessResourceStr(Res, FileName, SectionName, ResName); - e_WriteLog('Loading map WAD: ' + FileName, MSG_NOTIFY); + FileName := g_ExtractWadName(Res); + e_WriteLog('Loading map WAD: '+FileName, MSG_NOTIFY); g_Game_SetLoadingText(_lc[I_LOAD_WAD_FILE], 0, False); WAD := TWADFile.Create(); @@ -802,16 +797,18 @@ begin WAD.Free(); Exit; end; - if not WAD.GetResource('', ResName, Data, Len) then + //k8: why loader ignores path here? + mapResName := g_ExtractFileName(Res); + if not WAD.GetResource(mapResName, Data, Len) then begin - g_FatalError(Format(_lc[I_GAME_ERROR_MAP_RES], [ResName])); + g_FatalError(Format(_lc[I_GAME_ERROR_MAP_RES], [mapResName])); WAD.Free(); Exit; end; WAD.Free(); // Çàãðóçêà êàðòû: - e_WriteLog('Loading map: ' + ResName, MSG_NOTIFY); + e_WriteLog('Loading map: '+mapResName, MSG_NOTIFY); g_Game_SetLoadingText(_lc[I_LOAD_MAP], 0, False); MapReader := TMapReader_1.Create(); @@ -1173,17 +1170,16 @@ begin begin e_WriteLog(' Loading sky: ' + gMapInfo.SkyName, MSG_NOTIFY); g_Game_SetLoadingText(_lc[I_LOAD_SKY], 0, False); - g_ProcessResourceStr(gMapInfo.SkyName, FileName, SectionName, ResName); + FileName := g_ExtractWadName(gMapInfo.SkyName); if FileName <> '' then FileName := GameDir+'/wads/'+FileName else begin - g_ProcessResourceStr(Res, @FileName2, nil, nil); - FileName := FileName2; + FileName := g_ExtractWadName(Res); end; - s := FileName+':'+SectionName+'/'+ResName; + s := FileName+':'+g_ExtractFilePathName(gMapInfo.SkyName); if g_Texture_CreateWAD(BackID, s) then begin g_Game_SetupScreenSize(); @@ -1198,17 +1194,16 @@ begin begin e_WriteLog(' Loading music: ' + gMapInfo.MusicName, MSG_NOTIFY); g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False); - g_ProcessResourceStr(gMapInfo.MusicName, FileName, SectionName, ResName); + FileName := g_ExtractWadName(gMapInfo.MusicName); if FileName <> '' then FileName := GameDir+'/wads/'+FileName else begin - g_ProcessResourceStr(Res, @FileName2, nil, nil); - FileName := FileName2; + FileName := g_ExtractWadName(Res); end; - s := FileName+':'+SectionName+'/'+ResName; + s := FileName+':'+g_ExtractFilePathName(gMapInfo.MusicName); if g_Sound_CreateWADEx(gMapInfo.MusicName, s, True) then ok := True else @@ -1257,12 +1252,12 @@ var WAD: TWADFile; MapReader: TMapReader_1; Header: TMapHeaderRec_1; - FileName, SectionName, ResName: String; + FileName: String; Data: Pointer; Len: Integer; begin FillChar(Result, SizeOf(Result), 0); - g_ProcessResourceStr(Res, FileName, SectionName, ResName); + FileName := g_ExtractWadName(Res); WAD := TWADFile.Create(); if not WAD.ReadFile(FileName) then @@ -1271,7 +1266,8 @@ begin Exit; end; - if not WAD.GetResource('', ResName, Data, Len) then + //k8: it ignores path again + if not WAD.GetResource(g_ExtractFileName(Res), Data, Len) then begin WAD.Free(); Exit; @@ -1322,12 +1318,12 @@ begin Exit; end; - ResList := WAD.GetResourcesList(''); + ResList := WAD.GetRootResources(); if ResList <> nil then for a := 0 to High(ResList) do begin - if not WAD.GetResource('', ResList[a], Data, Len) then Continue; + if not WAD.GetResource(ResList[a], Data, Len) then Continue; CopyMemory(@Sign[0], Data, 3); FreeMem(Data); @@ -1346,15 +1342,13 @@ end; function g_Map_Exist(Res: string): Boolean; var WAD: TWADFile; - FileName, SectionName, ResName: string; + FileName, mnn: string; ResList: SArray; a: Integer; begin Result := False; - g_ProcessResourceStr(Res, FileName, SectionName, ResName); - - FileName := addWadExtension(FileName); + FileName := addWadExtension(g_ExtractWadName(Res)); WAD := TWADFile.Create; if not WAD.ReadFile(FileName) then @@ -1363,11 +1357,12 @@ begin Exit; end; - ResList := WAD.GetResourcesList(''); + ResList := WAD.GetRootResources(); WAD.Free(); + mnn := g_ExtractFileName(Res); if ResList <> nil then - for a := 0 to High(ResList) do if ResList[a] = ResName then + for a := 0 to High(ResList) do if StrEquCI1251(ResList[a], mnn) then begin Result := True; Exit; diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index 8b3dc31..eeb6f4a 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -726,7 +726,7 @@ begin if a.pic <> '' then begin - g_ProcessResourceStr(a.pic, @fn, nil, nil); + fn := g_ExtractWadName(a.pic); if fn = '' then TGUIImage(win.GetControl('mpWADImage')).SetImage(wad+a.pic) else @@ -784,7 +784,7 @@ begin wad := TWADFile.Create; if wad.ReadFile(GameWAD) then - wad.GetResource('FONTS', cfgres, cfgdata, cfglen); + wad.GetResource('FONTS/'+cfgres, cfgdata, cfglen); wad.Free(); if cfglen <> 0 then @@ -823,8 +823,8 @@ begin wad := TWADFile.Create; if wad.ReadFile(GameWAD) then begin - wad.GetResource('FONTS', txtres, cfgdata, cfglen); - wad.GetResource('FONTS', fntres, fntdata, fntlen); + wad.GetResource('FONTS/'+txtres, cfgdata, cfglen); + wad.GetResource('FONTS/'+fntres, fntdata, fntlen); end; wad.Free(); diff --git a/src/game/g_netmaster.pas b/src/game/g_netmaster.pas index 916f7cd..afc88a7 100644 --- a/src/game/g_netmaster.pas +++ b/src/game/g_netmaster.pas @@ -223,8 +223,8 @@ var Wad, Map: string; Cli: Byte; begin - g_ProcessResourceStr(gMapInfo.Map, @Wad, nil, @Map); - Wad := ExtractFileName(Wad); + Wad := g_ExtractWadNameNoPath(gMapInfo.Map); + Map := g_ExtractFileName(gMapInfo.Map); e_Buffer_Write(@NetOut, NetServerName); diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index 0dab350..9b0614d 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -714,7 +714,7 @@ procedure MH_SEND_Info(ID: Byte); var Map: string; begin - g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map); + Map := g_ExtractFileName(gMapInfo.Map); e_Buffer_Clear(@NetOut); diff --git a/src/game/g_playermodel.pas b/src/game/g_playermodel.pas index 8345e78..7f939fb 100644 --- a/src/game/g_playermodel.pas +++ b/src/game/g_playermodel.pas @@ -253,7 +253,7 @@ begin Exit; end; - if not WAD.GetResource('TEXT', 'MODEL', pData, len) then + if not WAD.GetResource('TEXT/MODEL', pData, len) then begin WAD.Free(); Exit; @@ -358,8 +358,8 @@ begin SetLength(Gibs, ReadInt('Gibs', 'count', 0)); if (Gibs <> nil) and - (WAD.GetResource('TEXTURES', config.ReadStr('Gibs', 'resource', 'GIBS'), pData, lenpd)) and - (WAD.GetResource('TEXTURES', config.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2, lenpd2)) then + (WAD.GetResource('TEXTURES/'+config.ReadStr('Gibs', 'resource', 'GIBS'), pData, lenpd)) and + (WAD.GetResource('TEXTURES/'+config.ReadStr('Gibs', 'mask', 'GIBSMASK'), pData2, lenpd2)) then begin for a := 0 to High(Gibs) do if e_CreateTextureMemEx(pData, lenpd, Gibs[a].ID, a*32, 0, 32, 32) and diff --git a/src/game/g_saveload.pas b/src/game/g_saveload.pas index 3a1cecd..3d8c14c 100644 --- a/src/game/g_saveload.pas +++ b/src/game/g_saveload.pas @@ -152,7 +152,7 @@ begin str := gGameSettings.WAD; bMem.WriteString(str, 128); // Èìÿ êàðòû: - g_ProcessResourceStr(gMapInfo.Map, nil, nil, @str); + str := g_ExtractFileName(gMapInfo.Map); bMem.WriteString(str, 32); // Êîëè÷åñòâî èãðîêîâ: nPlayers := g_Player_GetCount(); diff --git a/src/game/g_sound.pas b/src/game/g_sound.pas index 0632efd..5c2882d 100644 --- a/src/game/g_sound.pas +++ b/src/game/g_sound.pas @@ -281,9 +281,7 @@ end; function g_Sound_CreateWAD(var ID: DWORD; Resource: string; isMusic: Boolean = False): Boolean; var WAD: TWADFile; - FileName, - SectionName, - ResourceName: string; + FileName: string; SoundData: Pointer; ResLength: Integer; ok: Boolean; @@ -292,12 +290,12 @@ begin ok := False; // e_WriteLog('Loading sound: ' + Resource, MSG_NOTIFY); - g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName); + FileName := g_ExtractWadName(Resource); WAD := TWADFile.Create(); WAD.ReadFile(FileName); - if WAD.GetResource(SectionName, ResourceName, SoundData, ResLength) then + if WAD.GetResource(g_ExtractFilePathName(Resource), SoundData, ResLength) then begin if e_LoadSoundMem(SoundData, ResLength, ID, isMusic) then ok := True @@ -326,7 +324,7 @@ end; function g_Sound_CreateWADEx(SoundName: ShortString; Resource: string; isMusic: Boolean = False): Boolean; var WAD: TWADFile; - FileName, SectionName, ResourceName: string; + FileName: string; SoundData: Pointer; ResLength: Integer; find_id: DWORD; @@ -336,14 +334,14 @@ begin ok := False; // e_WriteLog('Loading sound: ' + Resource, MSG_NOTIFY); - g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName); + FileName := g_ExtractWadName(Resource); find_id := FindSound(); WAD := TWADFile.Create(); WAD.ReadFile(FileName); - if WAD.GetResource(SectionName, ResourceName, SoundData, ResLength) then + if WAD.GetResource(g_ExtractFilePathName(Resource), SoundData, ResLength) then begin if e_LoadSoundMem(SoundData, ResLength, SoundArray[find_id].ID, isMusic) then begin diff --git a/src/game/g_textures.pas b/src/game/g_textures.pas index bdf6605..4e1cffa 100644 --- a/src/game/g_textures.pas +++ b/src/game/g_textures.pas @@ -145,19 +145,17 @@ end; function g_Texture_CreateWAD(var ID: DWORD; Resource: String): Boolean; var WAD: TWADFile; - FileName, - SectionName, - ResourceName: String; + FileName: String; TextureData: Pointer; ResourceLength: Integer; begin Result := False; - g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName); + FileName := g_ExtractWadName(Resource); WAD := TWADFile.Create; WAD.ReadFile(FileName); - if WAD.GetResource(SectionName, ResourceName, TextureData, ResourceLength) then + if WAD.GetResource(g_ExtractFilePathName(Resource), TextureData, ResourceLength) then begin if e_CreateTextureMem(TextureData, ResourceLength, ID) then Result := True @@ -185,21 +183,19 @@ end; function g_Texture_CreateWADEx(TextureName: ShortString; Resource: String): Boolean; var WAD: TWADFile; - FileName, - SectionName, - ResourceName: String; + FileName: String; TextureData: Pointer; find_id: DWORD; ResourceLength: Integer; begin - g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName); + FileName := g_ExtractWadName(Resource); find_id := FindTexture(); WAD := TWADFile.Create; WAD.ReadFile(FileName); - if WAD.GetResource(SectionName, ResourceName, TextureData, ResourceLength) then + if WAD.GetResource(g_ExtractFilePathName(Resource), TextureData, ResourceLength) then begin Result := e_CreateTextureMem(TextureData, ResourceLength, TexturesArray[find_id].ID); if Result then @@ -393,20 +389,18 @@ function g_Frames_CreateWAD(ID: PDWORD; Name: ShortString; Resource: string; FWidth, FHeight, FCount: Word; BackAnimation: Boolean = False): Boolean; var WAD: TWADFile; - FileName, - SectionName, - ResourceName: string; + FileName: string; TextureData: Pointer; ResourceLength: Integer; begin Result := False; - g_ProcessResourceStr(Resource, FileName, SectionName, ResourceName); + FileName := g_ExtractWadName(Resource); WAD := TWADFile.Create(); WAD.ReadFile(FileName); - if not WAD.GetResource(SectionName, ResourceName, TextureData, ResourceLength) then + if not WAD.GetResource(g_ExtractFilePathName(Resource), TextureData, ResourceLength) then begin WAD.Free(); e_WriteLog(Format('Error loading texture %s', [Resource]), MSG_WARNING); diff --git a/src/game/g_triggers.pas b/src/game/g_triggers.pas index 89adae4..609c309 100644 --- a/src/game/g_triggers.pas +++ b/src/game/g_triggers.pas @@ -1993,12 +1993,12 @@ begin // Åùå íåò òàêîãî çâóêà: if not g_Sound_Exists(Trigger.Data.SoundName) then begin - g_ProcessResourceStr(Trigger.Data.SoundName, @fn, nil, nil); + fn := g_ExtractWadName(Trigger.Data.SoundName); if fn = '' then begin // Çâóê â ôàéëå ñ êàðòîé - g_ProcessResourceStr(gMapInfo.Map, @mapw, nil, nil); - fn := mapw + Trigger.Data.SoundName; + mapw := g_ExtractWadName(gMapInfo.Map); + fn := mapw+':'+g_ExtractFilePathName(Trigger.Data.SoundName); end else // Çâóê â îòäåëüíîì ôàéëå fn := GameDir + '/wads/' + Trigger.Data.SoundName; @@ -2026,12 +2026,12 @@ begin // Åùå íåò òàêîé ìóçûêè: if not g_Sound_Exists(Trigger.Data.MusicName) then begin - g_ProcessResourceStr(Trigger.Data.MusicName, @fn, nil, nil); + fn := g_ExtractWadName(Trigger.Data.MusicName); if fn = '' then begin // Ìóçûêà â ôàéëå ñ êàðòîé - g_ProcessResourceStr(gMapInfo.Map, @mapw, nil, nil); - fn := mapw + Trigger.Data.MusicName; + mapw := g_ExtractWadName(gMapInfo.Map); + fn := mapw+':'+g_ExtractFilePathName(Trigger.Data.MusicName); end else // Ìóçûêà â ôàéëå ñ êàðòîé fn := GameDir+'/wads/'+Trigger.Data.MusicName; diff --git a/src/shared/wadreader.pas b/src/shared/wadreader.pas index aee12f4..ade53ad 100644 --- a/src/shared/wadreader.pas +++ b/src/shared/wadreader.pas @@ -27,15 +27,19 @@ type function ReadFile (FileName: AnsiString): Boolean; function ReadMemory (Data: Pointer; Len: LongWord): Boolean; - function GetResource (Section, Resource: AnsiString; var pData: Pointer; var Len: Integer): Boolean; - function GetResourcesList (Section: AnsiString): SArray; + + function GetResource (name: AnsiString; var pData: Pointer; var Len: Integer): Boolean; + function GetRootResources (): SArray; property isOpen: Boolean read getIsOpen; end; -procedure g_ProcessResourceStr (ResourceStr: AnsiString; var FileName, SectionName, ResourceName: AnsiString); overload; -procedure g_ProcessResourceStr (ResourceStr: AnsiString; FileName, SectionName, ResourceName: PString); overload; +function g_ExtractWadName (resourceStr: AnsiString): AnsiString; +function g_ExtractWadNameNoPath (resourceStr: AnsiString): AnsiString; +function g_ExtractFilePath (resourceStr: AnsiString): AnsiString; +function g_ExtractFileName (resourceStr: AnsiString): AnsiString; // without path +function g_ExtractFilePathName (resourceStr: AnsiString): AnsiString; // return fixed AnsiString or empty AnsiString function findDiskWad (fname: AnsiString): AnsiString; @@ -74,48 +78,100 @@ begin end; -procedure g_ProcessResourceStr (ResourceStr: AnsiString; var FileName, SectionName, ResourceName: AnsiString); +function normSlashes (s: AnsiString): AnsiString; var - a, i: Integer; + f: Integer; begin - //e_WriteLog(Format('g_ProcessResourceStr0: [%s]', [ResourceStr]), MSG_NOTIFY); - for i := Length(ResourceStr) downto 1 do if ResourceStr[i] = ':' then break; - FileName := Copy(ResourceStr, 1, i-1); - for a := i+1 to Length(ResourceStr) do if (ResourceStr[a] = '\') or (ResourceStr[a] = '/') then Break; - ResourceName := Copy(ResourceStr, a+1, Length(ResourceStr)-Abs(a)); - SectionName := Copy(ResourceStr, i+1, Length(ResourceStr)-Length(ResourceName)-Length(FileName)-2); + for f := 1 to length(s) do if s[f] = '\' then s[f] := '/'; + result := s; end; +function g_ExtractWadNameNoPath (resourceStr: AnsiString): AnsiString; +var + f, c: Integer; +begin + for f := length(resourceStr) downto 1 do + begin + if resourceStr[f] = ':' then + begin + result := normSlashes(Copy(resourceStr, 1, f-1)); + c := length(result); + while (c > 0) and (result[c] <> '/') do Dec(c); + if c > 0 then result := Copy(result, c+1, length(result)); + exit; + end; + end; + result := ''; +end; -procedure g_ProcessResourceStr (ResourceStr: AnsiString; FileName, SectionName, ResourceName: PAnsiString); +function g_ExtractWadName (resourceStr: AnsiString): AnsiString; var - a, i, l1, l2: Integer; + f: Integer; begin - //e_WriteLog(Format('g_ProcessResourceStr1: [%s]', [ResourceStr]), MSG_NOTIFY); - for i := Length(ResourceStr) downto 1 do if ResourceStr[i] = ':' then break; - if FileName <> nil then + for f := length(resourceStr) downto 1 do begin - FileName^ := Copy(ResourceStr, 1, i-1); - l1 := Length(FileName^); - end - else + if resourceStr[f] = ':' then + begin + result := normSlashes(Copy(resourceStr, 1, f-1)); + exit; + end; + end; + result := ''; +end; + +function g_ExtractFilePath (resourceStr: AnsiString): AnsiString; +var + f, lastSlash: Integer; +begin + result := ''; + lastSlash := -1; + for f := length(resourceStr) downto 1 do begin - l1 := 0; + if (lastSlash < 0) and (resourceStr[f] = '\') or (resourceStr[f] = '/') then lastSlash := f; + if resourceStr[f] = ':' then + begin + if lastSlash > 0 then result := normSlashes(Copy(resourceStr, f, lastSlash-f)); + exit; + end; end; - for a := i+1 to Length(ResourceStr) do if (ResourceStr[a] = '\') or (ResourceStr[a] = '/') then break; - if ResourceName <> nil then + if lastSlash > 0 then result := normSlashes(Copy(resourceStr, 1, lastSlash-1)); +end; + +function g_ExtractFileName (resourceStr: AnsiString): AnsiString; // without path +var + f, lastSlash: Integer; +begin + result := ''; + lastSlash := -1; + for f := length(resourceStr) downto 1 do begin - ResourceName^ := Copy(ResourceStr, a+1, Length(ResourceStr)-Abs(a)); - l2 := Length(ResourceName^); - end - else + if (lastSlash < 0) and (resourceStr[f] = '\') or (resourceStr[f] = '/') then lastSlash := f; + if resourceStr[f] = ':' then + begin + if lastSlash > 0 then result := Copy(resourceStr, lastSlash+1, length(resourceStr)); + exit; + end; + end; + if lastSlash > 0 then result := Copy(resourceStr, lastSlash+1, length(resourceStr)); +end; + +function g_ExtractFilePathName (resourceStr: AnsiString): AnsiString; +var + f: Integer; +begin + result := ''; + for f := length(resourceStr) downto 1 do begin - l2 := 0; + if resourceStr[f] = ':' then + begin + result := normSlashes(Copy(resourceStr, f+1, length(resourceStr))); + exit; + end; end; - if SectionName <> nil then SectionName^ := Copy(ResourceStr, i+1, Length(ResourceStr)-l2-l1-2); end; + { TWADFile } constructor TWADFile.Create(); begin @@ -158,25 +214,41 @@ begin result := s; end; -function TWADFile.GetResource (Section, Resource: AnsiString; var pData: Pointer; var Len: Integer): Boolean; +function TWADFile.GetResource (name: AnsiString; var pData: Pointer; var Len: Integer): Boolean; var - f: Integer; + f, lastSlash: Integer; fi: TSFSFileInfo; fs: TStream; fpp: Pointer; + rpath, rname: AnsiString; //fn: AnsiString; begin Result := False; if not isOpen or (fIter = nil) then Exit; - if length(Resource) = 0 then Exit; // just in case - if (length(Section) <> 0) and (Section[length(Section)] <> '/') then Section := Section+'/'; + rname := removeExt(name); + if length(rname) = 0 then Exit; // just in case + lastSlash := -1; + for f := 1 to length(rname) do + begin + if rname[f] = '\' then rname[f] := '/'; + if rname[f] = '/' then lastSlash := f; + end; + if lastSlash > 0 then + begin + rpath := Copy(rname, 1, lastSlash); + Delete(rname, 1, lastSlash); + end + else + begin + rpath := ''; + end; // backwards, due to possible similar names and such for f := fIter.Count-1 downto 0 do begin fi := fIter.Files[f]; if fi = nil then continue; //e_WriteLog(Format('DFWAD: searching for [%s : %s] in [%s]; current is [%s : %s]', [Section, Resource, fFileName, fi.path, fi.name]), MSG_NOTIFY); - if StrEquCI1251(fi.path, Section) and StrEquCI1251(removeExt(fi.name), Resource) then + if StrEquCI1251(fi.path, rpath) and StrEquCI1251(removeExt(fi.name), rname) then begin // i found her! //fn := fFileName+'::'+fi.path+fi.name; @@ -188,7 +260,7 @@ begin end; if fs = nil then begin - e_WriteLog(Format('DFWAD: can''t open file [%s%s] in [%s]', [Section, Resource, fFileName]), MSG_WARNING); + e_WriteLog(Format('DFWAD: can''t open file [%s] in [%s]', [name, fFileName]), MSG_WARNING); break; end; Len := Integer(fs.size); @@ -209,29 +281,28 @@ begin result := true; {$IFDEF SFS_DWFAD_DEBUG} if gSFSDebug then - e_WriteLog(Format('DFWAD: file [%s%s] FOUND in [%s]; size is %d bytes', [Section, Resource, fFileName, Len]), MSG_NOTIFY); + e_WriteLog(Format('DFWAD: file [%s] FOUND in [%s]; size is %d bytes', [name, fFileName, Len]), MSG_NOTIFY); {$ENDIF} exit; end; end; - e_WriteLog(Format('DFWAD: file [%s%s] not found in [%s]', [Section, Resource, fFileName]), MSG_WARNING); + e_WriteLog(Format('DFWAD: file [%s] not found in [%s]', [name, fFileName]), MSG_WARNING); end; -function TWADFile.GetResourcesList (Section: AnsiString): SArray; +function TWADFile.GetRootResources (): SArray; var f: Integer; fi: TSFSFileInfo; begin Result := nil; if not isOpen or (fIter = nil) then Exit; - if (length(Section) <> 0) and (Section[length(Section)] <> '/') then Section := Section+'/'; for f := 0 to fIter.Count-1 do begin fi := fIter.Files[f]; if fi = nil then continue; if length(fi.name) = 0 then continue; - if StrEquCI1251(fi.path, Section) then + if length(fi.path) = 0 then begin SetLength(result, Length(result)+1); result[high(result)] := removeExt(fi.name); -- 2.29.2