Skip to content

Commit

Permalink
Giving up here
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Apr 21, 2023
1 parent 73b47f7 commit b89b075
Show file tree
Hide file tree
Showing 9 changed files with 591 additions and 546 deletions.
53 changes: 27 additions & 26 deletions FrankenDrift.Adrift/FileIO.vb
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,15 @@ Module FileIO
Exe
End Enum

Friend Function LoadFile(ByVal sFilename As String, ByVal eFileType As FileTypeEnum, ByVal eLoadWhat As LoadWhatEnum, ByVal bLibrary As Boolean, Optional ByVal dtAdvDate As Date = #1/1/1900#, Optional ByRef state As clsGameState = Nothing, Optional ByVal lOffset As Long = 0, Optional ByVal bSilentError As Boolean = False) As Boolean
Friend Async Function LoadFile(ByVal sFilename As String, ByVal eFileType As FileTypeEnum, ByVal eLoadWhat As LoadWhatEnum, ByVal bLibrary As Boolean, Optional ByVal dtAdvDate As Date = #1/1/1900#, Optional ByVal state As clsGameState = Nothing, Optional ByVal lOffset As Long = 0, Optional ByVal bSilentError As Boolean = False) As Task(of (result as Boolean, state As clsGameState))

Dim stmOriginalFile As IO.FileStream = Nothing

Try
If Not IO.File.Exists(sFilename) Then
ErrMsg("File '" & sFilename & "' not found.")
RemoveFileFromList(sFilename)
Return False
Return (False, state)
End If

stmOriginalFile = New IO.FileStream(sFilename, IO.FileMode.Open, FileAccess.Read)
Expand Down Expand Up @@ -928,12 +928,12 @@ Module FileIO
Select Case eFileType
Case FileTypeEnum.Exe
If clsBlorb.ExecResource IsNot Nothing AndAlso clsBlorb.ExecResource.Length > 0 Then
If Not Load500(Decompress(clsBlorb.ExecResource, dVersion >= 5.00002 AndAlso clsBlorb.bObfuscated, 16, clsBlorb.ExecResource.Length - 30), False) Then Return False
If Not Load500(Decompress(clsBlorb.ExecResource, dVersion >= 5.00002 AndAlso clsBlorb.bObfuscated, 16, clsBlorb.ExecResource.Length - 30), False) Then Return (False, state)
clsBlorb.bObfuscated = False
If clsBlorb.MetaData IsNot Nothing Then Adventure.BabelTreatyInfo.FromString(clsBlorb.MetaData.OuterXml)
Adventure.FullPath = SafeString(Application.ExecutablePath)
Else
Return False
Return (False, state)
End If

Case FileTypeEnum.Blorb
Expand All @@ -956,7 +956,7 @@ Module FileIO

If Left(sVersion, 8) <> "Version " Then
ErrMsg("Not an ADRIFT Blorb file")
Return False
Return (False, state)
End If

UserSession.ShowUserSplash()
Expand All @@ -970,14 +970,14 @@ Module FileIO
Dim bDeObfuscate As Boolean = clsBlorb.MetaData Is Nothing OrElse clsBlorb.MetaData.OuterXml.Contains("compilerversion") ' Nasty, but works
' Was this a pre-obfuscated size blorb?
If clsBlorb.ExecResource.Length > 16 AndAlso clsBlorb.ExecResource(12) = 48 AndAlso clsBlorb.ExecResource(13) = 48 AndAlso clsBlorb.ExecResource(14) = 48 AndAlso clsBlorb.ExecResource(15) = 48 Then
If Not Load500(Decompress(clsBlorb.ExecResource, bDeObfuscate, 16, clsBlorb.ExecResource.Length - 30), False) Then Return False
If Not Load500(Decompress(clsBlorb.ExecResource, bDeObfuscate, 16, clsBlorb.ExecResource.Length - 30), False) Then Return (False, state)
Else
If Not Load500(Decompress(clsBlorb.ExecResource, bDeObfuscate, 12, clsBlorb.ExecResource.Length - 26), False) Then Return False
If Not Load500(Decompress(clsBlorb.ExecResource, bDeObfuscate, 12, clsBlorb.ExecResource.Length - 26), False) Then Return (False, state)
End If

If clsBlorb.MetaData IsNot Nothing Then Adventure.BabelTreatyInfo.FromString(clsBlorb.MetaData.OuterXml)
Else
Return False
Return (False, state)
End If

Case FileTypeEnum.TextAdventure_TAF
Expand All @@ -996,7 +996,7 @@ Module FileIO

If Left(sVersion, 8) <> "Version " Then
ErrMsg("Not an ADRIFT Text Adventure file")
Return False
Return (False, state)
End If

With Adventure
Expand All @@ -1010,20 +1010,20 @@ Module FileIO
Case "Version 3.90", "Version 4.00"
Dim br2 As BinaryReader = br
'LoadDefaults() ' If mandatory properties like StaticOrDynamic don't exist, create them
LoadLibraries(LoadWhatEnum.Properies)
Await LoadLibraries(LoadWhatEnum.Properies)
br = br2
iStartPriority = 0
If LoadOlder(CDbl(sVersion.Substring(8))) Then
iStartPriority = 50000
LoadLibraries(LoadWhatEnum.AllExceptProperties, "standardlibrary")
Await LoadLibraries(LoadWhatEnum.AllExceptProperties, "standardlibrary")
'CreateMandatoryProperties()
TweakTasksForv4()
br = br2
Set400SpecificTasks()
Adventure.dVersion = CDbl(sVersion.Substring(8))
If Adventure.dVersion = 4 Then Adventure.dVersion = 4.000052
Else
Return False
Return (False, state)
End If
Case "Version 5.00"
Dim sSize As String = System.Text.Encoding.UTF8.GetString(br.ReadBytes(4))
Expand All @@ -1050,8 +1050,8 @@ Module FileIO
bObfuscate = False
End If
Dim stmFile As MemoryStream = FileToMemoryStream(True, CInt(FileLen(sFilename) - 26 - lOffset - iBabelLength), bObfuscate)
If stmFile Is Nothing Then Return False
If Not Load500(stmFile, False, False, eLoadWhat, dtAdvDate) Then Return False ' - 12)))
If stmFile Is Nothing Then Return (False, state)
If Not Load500(stmFile, False, False, eLoadWhat, dtAdvDate) Then Return (False, state) ' - 12)))
If sBabel <> "" Then
Adventure.BabelTreatyInfo.FromString(sBabel)
Dim sTemp As String = Adventure.CoverFilename
Expand All @@ -1061,18 +1061,18 @@ Module FileIO

Case Else
ErrMsg("ADRIFT " & sVersion & " Adventures are not currently supported in ADRIFT v" & dVersion.ToString("0.0"))
Return False
Return (False, state)
End Select
Debug.WriteLine("End Load: " & Now)

Case FileTypeEnum.v4Module_AMF
TODO("Version 4.0 Modules")

Case FileTypeEnum.XMLModule_AMF
If Not Load500(FileToMemoryStream(False, CInt(FileLen(sFilename)), False), bLibrary, True, eLoadWhat, dtAdvDate, sFilename) Then Return False
If Not Load500(FileToMemoryStream(False, CInt(FileLen(sFilename)), False), bLibrary, True, eLoadWhat, dtAdvDate, sFilename) Then Return (False, state)

Case FileTypeEnum.GameState_TAS
state = LoadState(FileToMemoryStream(True, CInt(FileLen(sFilename)), False))
state = Await LoadState(FileToMemoryStream(True, CInt(FileLen(sFilename)), False))

End Select

Expand All @@ -1096,19 +1096,19 @@ Module FileIO

iLoading -= 1

Return True
Return (True, state)
Catch ex As Exception
If Not br Is Nothing Then br.Close()
If Not stmOriginalFile Is Nothing Then stmOriginalFile.Close()
ErrMsg("Error loading " & sFilename, ex)
Return False
Return (False, state)
Finally
End Try

End Function


Private Function LoadState(ByVal stmMemory As MemoryStream) As clsGameState
Private Async Function LoadState(ByVal stmMemory As MemoryStream) As Task(of clsGameState)

Try
Dim NewState As New clsGameState
Expand Down Expand Up @@ -5610,7 +5610,7 @@ NextGroup:
End Function


Friend Sub LoadLibraries(ByVal eLoadWhat As LoadWhatEnum, Optional ByVal sOnlyLoad As String = "")
Friend Async Function LoadLibraries(ByVal eLoadWhat As LoadWhatEnum, Optional ByVal sOnlyLoad As String = "") as Task
Dim sLibraries() As String = GetSetting("ADRIFT", "Generator", "Libraries").Split("|"c)
Dim sError As String = ""

Expand All @@ -5632,18 +5632,19 @@ NextGroup:
#If DEBUG Then
bLoadLibrary = True
#End If
If bLoadLibrary Then LoadFile(sLibrary, FileTypeEnum.XMLModule_AMF, eLoadWhat, True)
If bLoadLibrary Then Await LoadFile(sLibrary, FileTypeEnum.XMLModule_AMF, eLoadWhat, True)
End If
Next

If sError <> "" Then
ErrMsg("Sorry. The unregistered version of ADRIFT will only load the original library files. The following libraries were not loaded:" & vbCrLf & vbCrLf & sError)
End If

End Sub
End Function


Friend Sub OverwriteLibraries(ByVal eLoadWhat As LoadWhatEnum)
' Never called!
Friend Async Function OverwriteLibraries(ByVal eLoadWhat As LoadWhatEnum) As Task

Dim sLibraries() As String = GetSetting("ADRIFT", "Generator", "Libraries").Split("|"c)

Expand All @@ -5654,11 +5655,11 @@ NextGroup:
sLibrary = sLibrary.Split("#"c)(0)
End If
If bLoad AndAlso File.Exists(sLibrary) Then
LoadFile(sLibrary, FileTypeEnum.XMLModule_AMF, eLoadWhat, True, Adventure.LastUpdated)
Await LoadFile(sLibrary, FileTypeEnum.XMLModule_AMF, eLoadWhat, True, Adventure.LastUpdated)
End If
Next

End Sub
End Function


' v4 GetLine
Expand Down
Loading

0 comments on commit b89b075

Please sign in to comment.