Skip to content

Commit

Permalink
Added Flag &H2030200 Extract/Rebuild (DeS TPF)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wulf2k committed Mar 14, 2023
1 parent e52074b commit 51bebfe
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 130 deletions.
6 changes: 3 additions & 3 deletions DeS-BNDBuild/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
</configuration>
115 changes: 110 additions & 5 deletions DeS-BNDBuild/DeS_BNDBuild.vb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Imports System.Security.Cryptography


Public Class Des_BNDBuild
Public Const VERSION = "2018-11-08-15"

Public Shared bytes() As Byte
Public Shared filename As String
Expand Down Expand Up @@ -1233,7 +1232,35 @@ Public Class Des_BNDBuild
Next
ElseIf flags = &H2030200 Then
' Dark Souls/Demon's Souls (headerless DDS)
output(TimeOfDay & " - TPF format not implemented" & Environment.NewLine)
' output(TimeOfDay & " - TPF format not implemented" & Environment.NewLine)
BinderID = Microsoft.VisualBasic.Left(StrFromBytes(&H0), 3)
numFiles = UIntFromBytes(&H8)

fileList = BinderID & Environment.NewLine & flags & Environment.NewLine

For i As UInteger = 0 To numFiles - 1
currFileOffset = UIntFromBytes(&H10 + i * &H20)
currFileSize = UIntFromBytes(&H14 + i * &H20)
currFileFlags1 = UIntFromBytes(&H18 + i * &H20)
currFileFlags2 = UIntFromBytes(&H1C + i * &H20)
currFileNameOffset = UIntFromBytes(&H28 + i * &H20)

currFileName = DecodeFileName(currFileNameOffset) & ".dds"
fileList += currFileFlags1 & "," & currFileFlags2 & "," & currFileName & Environment.NewLine
currFileName = filepath & filename & ".extract\" & currFileName
currFilePath = Microsoft.VisualBasic.Left(currFileName, InStrRev(currFileName, "\"))
currFileName = Microsoft.VisualBasic.Right(currFileName, currFileName.Length - currFilePath.Length)

If (Not System.IO.Directory.Exists(currFilePath)) Then
System.IO.Directory.CreateDirectory(currFilePath)
End If

ReDim currFileBytes(currFileSize - 1)
Array.Copy(bytes, currFileOffset, currFileBytes, 0, currFileSize)
File.WriteAllBytes(currFilePath & currFileName, currFileBytes)
Next


ElseIf flags = &H10300 Then
' Dark Souls III

Expand Down Expand Up @@ -2436,6 +2463,86 @@ Public Class Des_BNDBuild
Next

UIntToBytes(totalFileSize, &H4)
ElseIf flags = &H2030200 Then
' Dark Souls/Demon's Souls (headerless DDS)

bigEndian = True

numFiles = fileList.Length - 2

namesEndLoc = &H10 + numFiles * &H20

For i = 2 To fileList.Length - 1
currFileName = fileList(i)
currFileName = currFileName.Substring(InStrRev(currFileName, ","))
currFileName = currFileName.Substring(0, currFileName.Length - ".dds".Length)
namesEndLoc += EncodeFileName(currFileName).Length + 1
Next

UIntToBytes(numFiles, &H8)
UIntToBytes(flags, &HC)

If namesEndLoc Mod &H100 > 0 Then
padding = &H100 - (namesEndLoc Mod &H100)
Else
padding = 0
End If

ReDim Preserve bytes(namesEndLoc + padding - 1)
currFileOffset = namesEndLoc + padding

UIntToBytes(currFileOffset, &H10)

currFileNameOffset = &H10 + &H20 * numFiles

For i = 0 To numFiles - 1
currFileName = filepath & filename & ".extract\" & Microsoft.VisualBasic.Right(fileList(i + 2), fileList(i + 2).Length - (InStrRev(fileList(i + 2), ",")))
tmpbytes = File.ReadAllBytes(currFileName)

currFileSize = tmpbytes.Length
If currFileSize Mod &H20 > 0 Then
padding = &H20 - (currFileSize Mod &H20)
Else
padding = 0
End If

currFileFlags1 = Microsoft.VisualBasic.Left(fileList(i + 2), InStr(fileList(i + 2), ",") - 1)
currFileFlags2 = Microsoft.VisualBasic.Right(Microsoft.VisualBasic.Left(fileList(i + 2), InStrRev(fileList(i + 2), ",") - 1), Microsoft.VisualBasic.Left(fileList(i + 2), InStrRev(fileList(i + 2), ",") - 1).Length - InStr(Microsoft.VisualBasic.Left(fileList(i + 2), InStrRev(fileList(i + 2), ",") - 1), ","))

UIntToBytes(currFileOffset, &H10 + i * &H20)
UIntToBytes(currFileSize, &H14 + i * &H20)
UIntToBytes(currFileFlags1, &H18 + i * &H20)
UIntToBytes(currFileFlags2, &H1C + i * &H20)
UIntToBytes(currFileNameOffset, &H28 + i * &H20)

ReDim Preserve bytes(bytes.Length + currFileSize + padding - 1)

InsBytes(tmpbytes, currFileOffset)

currFileOffset += currFileSize + padding
totalFileSize += currFileSize

currFileName = Microsoft.VisualBasic.Right(fileList(i + 2), fileList(i + 2).Length - (InStrRev(fileList(i + 2), ",")))
currFileName = currFileName.Substring(0, currFileName.Length - ".dds".Length)
EncodeFileName(currFileName, currFileNameOffset)
currFileNameOffset += EncodeFileName(currFileName).Length + 1
REM currFileNameOffset += EncodeFileName(Microsoft.VisualBasic.Right(fileList(i + 2), fileList(i + 2).Length - (InStrRev(fileList(i + 2), ",")))).Length + 1
Next

UIntToBytes(totalFileSize, &H4)













ElseIf flags = &H10300 Then
' Dark Souls III

Expand Down Expand Up @@ -2767,9 +2874,7 @@ Public Class Des_BNDBuild
End Sub

Private Sub Des_BNDBuild_Load(sender As Object, e As EventArgs) Handles MyBase.Load
updateUITimer.Interval = 200
updateUITimer.Start()
Text &= $" ({VERSION})"

End Sub

Private Sub updateUI() Handles updateUITimer.Tick
Expand Down
4 changes: 3 additions & 1 deletion DeS-BNDBuild/DeS_BNDBuild.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<AssemblyName>BND-Build</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>WindowsForms</MyType>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -84,6 +85,7 @@
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Application.myapp</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
Expand Down
Loading

0 comments on commit 51bebfe

Please sign in to comment.