Skip to content

Commit

Permalink
Support for BA2 archives
Browse files Browse the repository at this point in the history
Updated Assets Browser and Worldspace Browser to work with Fallout 4
  • Loading branch information
zilav committed Nov 27, 2015
1 parent 0d3c686 commit cdf15ae
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 66 deletions.
4 changes: 3 additions & 1 deletion Edit Scripts/Assets browser.pas
Expand Up @@ -185,7 +185,9 @@ procedure lvAssetsSelectItem(Sender: TObject; Item: TListItem;
f := Item.Caption;
ext := ExtractFileExt(f);
if SameText(ext, '.nif') then begin
NifTextureList(ResourceOpenData('', f), sl);
try
NifTextureList(ResourceOpenData('', f), sl);
except end;
slTextures.AddStrings(sl); // remove duplicates
mInfo.Lines.BeginUpdate;
mInfo.Clear;
Expand Down
17 changes: 15 additions & 2 deletions Edit Scripts/Worldspace browser.pas
Expand Up @@ -95,11 +95,17 @@ function LODTextureFileName(aGame, aFormID: integer; aEditorID: string;
else texname := 'textures\landscape\lod\%s\normals\%s.n.level%d.x%d.y%d.dds';
Result := Format(texname, [aEditorID, aEditorID, aLODLevel, x, y]);
end
// Skyrim (and probably later games)
else begin
// Skyrim
else if aGame = gmTES5 then begin
if not aNormals then texname := 'textures\terrain\%s\%s.%d.%d.%d.dds'
else texname := 'textures\terrain\%s\%s.%d.%d.%d_n.dds';
Result := Format(texname, [aEditorID, aEditorID, aLODLevel, x, y]);
end
// FO4
else if aGame = gmFO4 then begin
if not aNormals then texname := 'textures\terrain\%s\%s.%d.%d.%d.dds'
else texname := 'textures\terrain\%s\%s.%d.%d.%d_msn.dds';
Result := Format(texname, [aEditorID, aEditorID, aLODLevel, x, y]);
end;
end;

Expand All @@ -110,6 +116,9 @@ function HasLOD(wrld: IInterface): boolean;
// for Oblivion it is a presence of 0,0 quad lod texture
if wbGameMode = gmTES4 then
Result := ResourceExists(LODTextureFileName(wbGameMode, FormID(wrld), EditorID(wrld), 0, 0, 32, False))
// for FO4 unknown yet
else if wbGameMode = gmFO4 then
Result := True
// for other games a presence of lod settings file
else
Result := ResourceExists(LODSettingsFileName(wrld));
Expand All @@ -129,6 +138,10 @@ procedure LODCellSW(wrld: IInterface; var SWCellX, SWCellY: integer);
if not HasLOD(wrld) then
Exit;

// not sure for FO4, use MapSize
if wbGameMode = gmFO4 then
Exit;

// read from lod settings file
if wbGameMode <> gmTES4 then begin
BytesStream := TBytesStream.Create(ResourceOpenData('', LODSettingsFileName(wrld)));
Expand Down
4 changes: 2 additions & 2 deletions Imaging/ImagingDds.pas
Expand Up @@ -105,8 +105,6 @@ TDDSFileFormat = class(TImageFileFormat)
{ Texture array size stored in DDS file (DX10 extension).}
SMetaDdsArraySize = 'DdsArraySize';

implementation

const
SDDSFormatName = 'DirectDraw Surface';
SDDSMasks = '*.dds';
Expand Down Expand Up @@ -357,6 +355,8 @@ implementation
Reserved: LongWord;
end;

implementation

{ TDDSFileFormat class implementation }

procedure TDDSFileFormat.Define;
Expand Down
63 changes: 8 additions & 55 deletions frmViewMain.pas
Expand Up @@ -15466,7 +15466,10 @@ procedure TLoaderThread.Execute;
for i := 0 to Pred(n.Count) do
if wbLoadBSAs then begin
LoaderProgress('[' + n[i] + '] Loading Resources.');
wbContainerHandler.AddBSA(MakeDataFileName(n[i], ltDataPath));
if wbArchiveExtension = '.bsa' then
wbContainerHandler.AddBSA(MakeDataFileName(n[i], ltDataPath))
else if wbArchiveExtension = '.ba2' then
wbContainerHandler.AddBA2(MakeDataFileName(n[i], ltDataPath))
end else
LoaderProgress('[' + n[i] + '] Skipped.');
for i := 0 to Pred(m.Count) do
Expand All @@ -15479,42 +15482,6 @@ procedure TLoaderThread.Execute;
FreeAndNil(n);
end;

// with TMemIniFile.Create(wbTheGameIniFileName) do try
// with TStringList.Create do try
// if wbGameMode in [gmTES4, gmFO3, gmFNV] then
// Text := StringReplace(ReadString('Archive', 'sArchiveList', ''), ',' ,#10, [rfReplaceAll])
// else
// Text := StringReplace(
// ReadString('Archive', 'sResourceArchiveList', '') + ',' + ReadString('Archive', 'sResourceArchiveList2', ''),
// ',', #10, [rfReplaceAll]
// );
// for i := 0 to Pred(Count) do begin
// s := Trim(Strings[i]);
// if Length(s) < 5 then
// Continue;
// if not ((s[1] = '\') or (s[2] = ':')) then
// t := ltDataPath + s
// else
// t := s;
// if not FileExists(t) then
// LoaderProgress('Warning: <Can''t find ' + t + '>')
// else begin
// if wbContainerHandler.ContainerExists(t) then
// Continue;
// if wbLoadBSAs then begin
// LoaderProgress('[' + s + '] Loading Resources.');
// wbContainerHandler.AddBSA(t);
// end else
// LoaderProgress('[' + s + '] Skipped.');
// end;
// end;
// finally
// Free;
// end;
// finally
// Free;
// end;

for i := 0 to Pred(ltLoadList.Count) do begin
n := TStringList.Create;
try
Expand All @@ -15527,7 +15494,10 @@ procedure TLoaderThread.Execute;
for j := 0 to Pred(n.Count) do
if wbLoadBSAs then begin
LoaderProgress('[' + n[j] + '] Loading Resources.');
wbContainerHandler.AddBSA(MakeDataFileName(n[j], ltDataPath));
if wbArchiveExtension = '.bsa' then
wbContainerHandler.AddBSA(MakeDataFileName(n[j], ltDataPath))
else if wbArchiveExtension = '.ba2' then
wbContainerHandler.AddBA2(MakeDataFileName(n[j], ltDataPath))
end else
LoaderProgress('[' + n[j] + '] Skipped.');
for j := 0 to Pred(m.Count) do
Expand All @@ -15540,23 +15510,6 @@ procedure TLoaderThread.Execute;
FreeAndNil(n);
end;

// s := ChangeFileExt(ltLoadList[i], '');
// // all games prior to Skyrim load BSA files with partial matching, Skyrim requires exact names match
// if wbGameMode in [gmTES4, gmFO3, gmFNV] then
// s := s + '*';
// if FindFirst(ltDataPath + s + '.bsa', faAnyFile, F) = 0 then try
// repeat
// if wbContainerHandler.ContainerExists(ltDataPath + F.Name) then
// Continue;
// if wbLoadBSAs then begin
// LoaderProgress('[' + F.Name + '] Loading Resources.');
// wbContainerHandler.AddBSA(ltDataPath + F.Name);
// end else
// LoaderProgress('[' + F.Name + '] Skipped.');
// until FindNext(F) <> 0;
// finally
// FindClose(F);
// end;
end;
LoaderProgress('[' + ltDataPath + '] Setting Resource Path.');
wbContainerHandler.AddFolder(ltDataPath);
Expand Down

0 comments on commit cdf15ae

Please sign in to comment.