| 1 |
Imports System.IO |
| 2 |
Imports System.IO.Compression |
| 3 |
Imports System.Xml |
| 4 |
|
| 5 |
Imports FrankenDrift.Glue |
| 6 |
|
| 7 |
Imports DashStyles = FrankenDrift.Glue.ConceptualDashStyle |
| 8 |
|
| 9 |
Module FileIO |
| 10 |
|
| 11 |
Private br As BinaryReader |
| 12 |
Private bw As BinaryWriter |
| 13 |
Private sLoadString As String |
| 14 |
Private bAdventure() As Byte |
| 15 |
Private salWithStates As New StringArrayList |
| 16 |
Private iStartPriority As Integer |
| 17 |
Private dFileVersion As Double |
| 18 |
Friend Enum LoadWhatEnum |
| 19 |
All |
| 20 |
Properies |
| 21 |
AllExceptProperties |
| 22 |
End Enum |
| 23 |
|
| 24 |
|
| 25 |
Private Function LoadDescription(ByVal nodContainerXML As XmlElement, ByVal sNode As String) As Description |
| 26 |
|
| 27 |
Dim Description As New Description |
| 28 |
|
| 29 |
If nodContainerXML.Item(sNode) Is Nothing OrElse nodContainerXML.GetElementsByTagName(sNode).Count = 0 Then Return Description |
| 30 |
|
| 31 |
Dim nodDescription As XmlElement = CType(nodContainerXML.GetElementsByTagName(sNode)(0), XmlElement) |
| 32 |
|
| 33 |
For Each nodDesc As XmlElement In nodDescription.SelectNodes("Description") '. nodDescription.GetElementsByTagName("Description") |
| 34 |
Dim sd As New SingleDescription |
| 35 |
sd.Restrictions = LoadRestrictions(nodDesc) |
| 36 |
sd.eDisplayWhen = CType([Enum].Parse(GetType(SingleDescription.DisplayWhenEnum), nodDesc.Item("DisplayWhen").InnerText), SingleDescription.DisplayWhenEnum) |
| 37 |
If nodDesc.Item("Text") IsNot Nothing Then sd.Description = nodDesc.Item("Text").InnerText |
| 38 |
If nodDesc.Item("DisplayOnce") IsNot Nothing Then sd.DisplayOnce = GetBool(nodDesc.Item("DisplayOnce").InnerText) |
| 39 |
If nodDesc.Item("ReturnToDefault") IsNot Nothing Then sd.ReturnToDefault = GetBool(nodDesc.Item("ReturnToDefault").InnerText) |
| 40 |
If nodDesc.Item("TabLabel") IsNot Nothing Then sd.sTabLabel = SafeString(nodDesc.Item("TabLabel").InnerText) |
| 41 |
Description.Add(sd) |
| 42 |
Next |
| 43 |
|
| 44 |
If Description.Count > 1 Then Description.RemoveAt(0) |
| 45 |
Return Description |
| 46 |
|
| 47 |
End Function |
| 48 |
|
| 49 |
|
| 50 |
' Write a state to file |
| 51 |
Friend Function SaveState(ByVal state As clsGameState, ByVal sFilePath As String) As Boolean |
| 52 |
|
| 53 |
Try |
| 54 |
Dim stmMemory As New MemoryStream |
| 55 |
Dim xmlWriter As New System.Xml.XmlTextWriter(stmMemory, System.Text.Encoding.UTF8) |
| 56 |
Dim bData() As Byte |
| 57 |
|
| 58 |
With xmlWriter |
| 59 |
.Indentation = 4 ' Change later |
| 60 |
|
| 61 |
.WriteStartDocument() |
| 62 |
.WriteStartElement("Game") |
| 63 |
|
| 64 |
' TODO: Ideally this should only save values that are different from the initial TAF state |
| 65 |
|
| 66 |
For Each sKey As String In state.htblLocationStates.Keys |
| 67 |
Dim locs As clsGameState.clsLocationState = CType(state.htblLocationStates(sKey), clsGameState.clsLocationState) |
| 68 |
.WriteStartElement("Location") |
| 69 |
.WriteElementString("Key", sKey) |
| 70 |
For Each sPropKey As String In locs.htblProperties.Keys |
| 71 |
Dim props As clsGameState.clsLocationState.clsStateProperty = CType(locs.htblProperties(sPropKey), clsGameState.clsLocationState.clsStateProperty) |
| 72 |
.WriteStartElement("Property") |
| 73 |
.WriteElementString("Key", sPropKey) |
| 74 |
.WriteElementString("Value", props.Value) |
| 75 |
.WriteEndElement() |
| 76 |
Next |
| 77 |
For Each sDisplayedKey As String In locs.htblDisplayedDescriptions.Keys |
| 78 |
.WriteElementString("Displayed", sDisplayedKey) |
| 79 |
Next |
| 80 |
.WriteEndElement() |
| 81 |
Next |
| 82 |
|
| 83 |
For Each sKey As String In state.htblObjectStates.Keys |
| 84 |
Dim obs As clsGameState.clsObjectState = CType(state.htblObjectStates(sKey), clsGameState.clsObjectState) |
| 85 |
.WriteStartElement("Object") |
| 86 |
.WriteElementString("Key", sKey) |
| 87 |
If obs.Location.DynamicExistWhere <> clsObjectLocation.DynamicExistsWhereEnum.Hidden Then |
| 88 |
.WriteElementString("DynamicExistWhere", obs.Location.DynamicExistWhere.ToString) |
| 89 |
End If |
| 90 |
If obs.Location.StaticExistWhere <> clsObjectLocation.StaticExistsWhereEnum.NoRooms Then |
| 91 |
.WriteElementString("StaticExistWhere", obs.Location.StaticExistWhere.ToString) |
| 92 |
End If |
| 93 |
.WriteElementString("LocationKey", obs.Location.Key) |
| 94 |
For Each sPropKey As String In obs.htblProperties.Keys |
| 95 |
Dim props As clsGameState.clsObjectState.clsStateProperty = CType(obs.htblProperties(sPropKey), clsGameState.clsObjectState.clsStateProperty) |
| 96 |
.WriteStartElement("Property") |
| 97 |
.WriteElementString("Key", sPropKey) |
| 98 |
.WriteElementString("Value", props.Value) |
| 99 |
.WriteEndElement() |
| 100 |
Next |
| 101 |
For Each sDisplayedKey As String In obs.htblDisplayedDescriptions.Keys |
| 102 |
.WriteElementString("Displayed", sDisplayedKey) |
| 103 |
Next |
| 104 |
.WriteEndElement() |
| 105 |
Next |
| 106 |
|
| 107 |
For Each sKey As String In state.htblTaskStates.Keys |
| 108 |
Dim tas As clsGameState.clsTaskState = CType(state.htblTaskStates(sKey), clsGameState.clsTaskState) |
| 109 |
.WriteStartElement("Task") |
| 110 |
.WriteElementString("Key", sKey) |
| 111 |
.WriteElementString("Completed", tas.Completed.ToString) |
| 112 |
.WriteElementString("Scored", tas.Scored.ToString) |
| 113 |
For Each sDisplayedKey As String In tas.htblDisplayedDescriptions.Keys |
| 114 |
.WriteElementString("Displayed", sDisplayedKey) |
| 115 |
Next |
| 116 |
.WriteEndElement() |
| 117 |
Next |
| 118 |
|
| 119 |
For Each sKey As String In state.htblEventStates.Keys |
| 120 |
Dim evs As clsGameState.clsEventState = CType(state.htblEventStates(sKey), clsGameState.clsEventState) |
| 121 |
.WriteStartElement("Event") |
| 122 |
.WriteElementString("Key", sKey) |
| 123 |
.WriteElementString("Status", evs.Status.ToString) |
| 124 |
.WriteElementString("Timer", evs.TimerToEndOfEvent.ToString) |
| 125 |
.WriteElementString("SubEventTime", evs.iLastSubEventTime.ToString) |
| 126 |
.WriteElementString("SubEventIndex", evs.iLastSubEventIndex.ToString) |
| 127 |
For Each sDisplayedKey As String In evs.htblDisplayedDescriptions.Keys |
| 128 |
.WriteElementString("Displayed", sDisplayedKey) |
| 129 |
Next |
| 130 |
.WriteEndElement() |
| 131 |
Next |
| 132 |
|
| 133 |
For Each sKey As String In state.htblCharacterStates.Keys |
| 134 |
Dim chs As clsGameState.clsCharacterState = CType(state.htblCharacterStates(sKey), clsGameState.clsCharacterState) |
| 135 |
.WriteStartElement("Character") |
| 136 |
.WriteElementString("Key", sKey) |
| 137 |
If chs.Location.ExistWhere <> clsCharacterLocation.ExistsWhereEnum.Hidden Then |
| 138 |
.WriteElementString("ExistWhere", chs.Location.ExistWhere.ToString) |
| 139 |
End If |
| 140 |
If chs.Location.Position <> clsCharacterLocation.PositionEnum.Standing Then |
| 141 |
.WriteElementString("Position", chs.Location.Position.ToString) |
| 142 |
End If |
| 143 |
If chs.Location.Key <> "" Then .WriteElementString("LocationKey", chs.Location.Key) |
| 144 |
For Each ws As clsGameState.clsCharacterState.clsWalkState In chs.lWalks |
| 145 |
.WriteStartElement("Walk") |
| 146 |
.WriteElementString("Status", ws.Status.ToString) |
| 147 |
.WriteElementString("Timer", ws.TimerToEndOfWalk.ToString) |
| 148 |
.WriteEndElement() |
| 149 |
Next |
| 150 |
For Each sSeen As String In chs.lSeenKeys |
| 151 |
.WriteElementString("Seen", sSeen) |
| 152 |
Next |
| 153 |
For Each sPropKey As String In chs.htblProperties.Keys |
| 154 |
Dim props As clsGameState.clsCharacterState.clsStateProperty = CType(chs.htblProperties(sPropKey), clsGameState.clsCharacterState.clsStateProperty) |
| 155 |
.WriteStartElement("Property") |
| 156 |
.WriteElementString("Key", sPropKey) |
| 157 |
.WriteElementString("Value", props.Value) |
| 158 |
.WriteEndElement() |
| 159 |
Next |
| 160 |
For Each sDisplayedKey As String In chs.htblDisplayedDescriptions.Keys |
| 161 |
.WriteElementString("Displayed", sDisplayedKey) |
| 162 |
Next |
| 163 |
.WriteEndElement() |
| 164 |
Next |
| 165 |
|
| 166 |
For Each sKey As String In state.htblVariableStates.Keys |
| 167 |
Dim vars As clsGameState.clsVariableState = CType(state.htblVariableStates(sKey), clsGameState.clsVariableState) |
| 168 |
.WriteStartElement("Variable") |
| 169 |
.WriteElementString("Key", sKey) |
| 170 |
|
| 171 |
Dim v As clsVariable = Adventure.htblVariables(sKey) |
| 172 |
For i As Integer = 0 To vars.Value.Length - 1 |
| 173 |
If v.Type = clsVariable.VariableTypeEnum.Numeric Then |
| 174 |
If vars.Value(i) <> "0" Then .WriteElementString("Value_" & i, vars.Value(i)) |
| 175 |
Else |
| 176 |
If vars.Value(i) <> "" Then .WriteElementString("Value_" & i, vars.Value(i)) |
| 177 |
End If |
| 178 |
Next |
| 179 |
For Each sDisplayedKey As String In vars.htblDisplayedDescriptions.Keys |
| 180 |
.WriteElementString("Displayed", sDisplayedKey) |
| 181 |
Next |
| 182 |
.WriteEndElement() |
| 183 |
Next |
| 184 |
|
| 185 |
For Each sKey As String In state.htblGroupStates.Keys |
| 186 |
Dim grps As clsGameState.clsGroupState = CType(state.htblGroupStates(sKey), clsGameState.clsGroupState) |
| 187 |
.WriteStartElement("Group") |
| 188 |
.WriteElementString("Key", sKey) |
| 189 |
For Each sMember As String In grps.lstMembers |
| 190 |
.WriteElementString("Member", sMember) |
| 191 |
Next |
| 192 |
.WriteEndElement() |
| 193 |
Next |
| 194 |
|
| 195 |
.WriteElementString("Turns", Adventure.Turns.ToString) |
| 196 |
|
| 197 |
.WriteEndElement() ' Game |
| 198 |
.WriteEndDocument() |
| 199 |
.Flush() |
| 200 |
|
| 201 |
Dim stmFile As New IO.FileStream(sFilePath, FileMode.Create) |
| 202 |
Using zStream As New ZLibStream(stmFile, CompressionLevel.Optimal) |
| 203 |
stmMemory.Position = 0 |
| 204 |
stmMemory.CopyTo(zStream) |
| 205 |
End Using |
| 206 |
End With |
| 207 |
|
| 208 |
Return True |
| 209 |
|
| 210 |
Catch ex As Exception |
| 211 |
ErrMsg("Error saving game state", ex) |
| 212 |
Return False |
| 213 |
End Try |
| 214 |
|
| 215 |
End Function |
| 216 |
|
| 217 |
|
| 218 |
Friend Function LoadActions(ByVal nodContainerXML As XmlElement) As ActionArrayList |
| 219 |
|
| 220 |
Dim Actions As New ActionArrayList |
| 221 |
|
| 222 |
If nodContainerXML.Item("Actions") Is Nothing Then Return Actions |
| 223 |
|
| 224 |
For Each nod As XmlNode In nodContainerXML.Item("Actions").ChildNodes |
| 225 |
If TypeOf nod Is XmlElement Then |
| 226 |
Dim nodAct As XmlElement = CType(nod, XmlElement) |
| 227 |
Dim act As New clsAction |
| 228 |
Dim sAct As String |
| 229 |
Dim sType As String = Nothing |
| 230 |
sType = nodAct.Name |
| 231 |
|
| 232 |
If sType Is Nothing Then Return Actions |
| 233 |
|
| 234 |
sAct = nodAct.InnerText |
| 235 |
Dim sElements() As String = Split(sAct, " ") |
| 236 |
Select Case sType |
| 237 |
Case "EndGame" |
| 238 |
act.eItem = clsAction.ItemEnum.EndGame |
| 239 |
act.eEndgame = EnumParseEndGame(sElements(0)) |
| 240 |
|
| 241 |
Case "MoveObject", "AddObjectToGroup", "RemoveObjectFromGroup" |
| 242 |
Select Case sType |
| 243 |
Case "MoveObject" |
| 244 |
act.eItem = clsAction.ItemEnum.MoveObject |
| 245 |
Case "AddObjectToGroup" |
| 246 |
act.eItem = clsAction.ItemEnum.AddObjectToGroup |
| 247 |
Case "RemoveObjectFromGroup" |
| 248 |
act.eItem = clsAction.ItemEnum.RemoveObjectFromGroup |
| 249 |
End Select |
| 250 |
|
| 251 |
If dFileVersion <= 5.000016 Then ' Upgrade previous file format |
| 252 |
act.sKey1 = sElements(0) |
| 253 |
act.eMoveObjectWhat = clsAction.MoveObjectWhatEnum.Object |
| 254 |
Select Case act.sKey1 |
| 255 |
Case "AllHeldObjects" |
| 256 |
act.eMoveObjectWhat = clsAction.MoveObjectWhatEnum.EverythingHeldBy |
| 257 |
act.sKey1 = THEPLAYER |
| 258 |
Case "AllWornObjects" |
| 259 |
act.eMoveObjectWhat = clsAction.MoveObjectWhatEnum.EverythingWornBy |
| 260 |
act.sKey1 = THEPLAYER |
| 261 |
Case Else |
| 262 |
' Leave as is |
| 263 |
End Select |
| 264 |
act.eMoveObjectTo = EnumParseMoveObject(sElements(1)) |
| 265 |
act.sKey2 = sElements(2) |
| 266 |
Else |
| 267 |
act.eMoveObjectWhat = CType([Enum].Parse(GetType(clsAction.MoveObjectWhatEnum), sElements(0)), clsAction.MoveObjectWhatEnum) |
| 268 |
act.sKey1 = sElements(1) |
| 269 |
If sElements.Length > 4 Then |
| 270 |
For iEl As Integer = 2 To sElements.Length - 3 |
| 271 |
act.sPropertyValue &= sElements(iEl) |
| 272 |
If iEl < sElements.Length - 3 Then act.sPropertyValue &= " " |
| 273 |
Next |
| 274 |
End If |
| 275 |
Select Case act.eItem |
| 276 |
Case clsAction.ItemEnum.AddObjectToGroup |
| 277 |
act.eMoveObjectTo = clsAction.MoveObjectToEnum.ToGroup |
| 278 |
Case clsAction.ItemEnum.RemoveObjectFromGroup |
| 279 |
act.eMoveObjectTo = clsAction.MoveObjectToEnum.FromGroup |
| 280 |
Case clsAction.ItemEnum.MoveObject |
| 281 |
act.eMoveObjectTo = CType([Enum].Parse(GetType(clsAction.MoveObjectToEnum), sElements(sElements.Length - 2)), clsAction.MoveObjectToEnum) |
| 282 |
End Select |
| 283 |
act.sKey2 = sElements(sElements.Length - 1) |
| 284 |
End If |
| 285 |
|
| 286 |
Case "MoveCharacter", "AddCharacterToGroup", "RemoveCharacterFromGroup" |
| 287 |
Select Case sType |
| 288 |
Case "MoveCharacter" |
| 289 |
act.eItem = clsAction.ItemEnum.MoveCharacter |
| 290 |
Case "AddCharacterToGroup" |
| 291 |
act.eItem = clsAction.ItemEnum.AddCharacterToGroup |
| 292 |
Case "RemoveCharacterFromGroup" |
| 293 |
act.eItem = clsAction.ItemEnum.RemoveCharacterFromGroup |
| 294 |
End Select |
| 295 |
|
| 296 |
If dFileVersion <= 5.000016 Then ' Upgrade previous file format |
| 297 |
act.eItem = clsAction.ItemEnum.MoveCharacter |
| 298 |
act.sKey1 = sElements(0) |
| 299 |
act.eMoveCharacterTo = EnumParseMoveCharacter(sElements(1)) |
| 300 |
act.sKey2 = sElements(2) |
| 301 |
If act.eMoveCharacterTo = clsAction.MoveCharacterToEnum.InDirection AndAlso IsNumeric(act.sKey2) Then |
| 302 |
act.sKey2 = WriteEnum(CType(SafeInt(act.sKey2), DirectionsEnum)) |
| 303 |
End If |
| 304 |
Else |
| 305 |
act.eMoveCharacterWho = CType([Enum].Parse(GetType(clsAction.MoveCharacterWhoEnum), sElements(0)), clsAction.MoveCharacterWhoEnum) |
| 306 |
act.sKey1 = sElements(1) |
| 307 |
If sElements.Length > 4 Then |
| 308 |
For iEl As Integer = 2 To sElements.Length - 3 |
| 309 |
act.sPropertyValue &= sElements(iEl) |
| 310 |
If iEl < sElements.Length - 3 Then act.sPropertyValue &= " " |
| 311 |
Next |
| 312 |
End If |
| 313 |
Select Case act.eItem |
| 314 |
Case clsAction.ItemEnum.AddCharacterToGroup |
| 315 |
act.eMoveCharacterTo = clsAction.MoveCharacterToEnum.ToGroup |
| 316 |
Case clsAction.ItemEnum.RemoveCharacterFromGroup |
| 317 |
act.eMoveCharacterTo = clsAction.MoveCharacterToEnum.FromGroup |
| 318 |
Case clsAction.ItemEnum.MoveCharacter |
| 319 |
act.eMoveCharacterTo = CType([Enum].Parse(GetType(clsAction.MoveCharacterToEnum), sElements(sElements.Length - 2)), clsAction.MoveCharacterToEnum) |
| 320 |
End Select |
| 321 |
act.sKey2 = sElements(sElements.Length - 1) |
| 322 |
End If |
| 323 |
|
| 324 |
Case "AddLocationToGroup", "RemoveLocationFromGroup" |
| 325 |
Select Case sType |
| 326 |
Case "AddLocationToGroup" |
| 327 |
act.eItem = clsAction.ItemEnum.AddLocationToGroup |
| 328 |
Case "RemoveLocationFromGroup" |
| 329 |
act.eItem = clsAction.ItemEnum.RemoveLocationFromGroup |
| 330 |
End Select |
| 331 |
|
| 332 |
act.eMoveLocationWhat = CType([Enum].Parse(GetType(clsAction.MoveLocationWhatEnum), sElements(0)), clsAction.MoveLocationWhatEnum) |
| 333 |
act.sKey1 = sElements(1) |
| 334 |
If sElements.Length > 4 Then |
| 335 |
For iEl As Integer = 2 To sElements.Length - 3 |
| 336 |
act.sPropertyValue &= sElements(iEl) |
| 337 |
If iEl < sElements.Length - 3 Then act.sPropertyValue &= " " |
| 338 |
Next |
| 339 |
End If |
| 340 |
Select Case act.eItem |
| 341 |
Case clsAction.ItemEnum.AddLocationToGroup |
| 342 |
act.eMoveLocationTo = clsAction.MoveLocationToEnum.ToGroup |
| 343 |
Case clsAction.ItemEnum.RemoveLocationFromGroup |
| 344 |
act.eMoveLocationTo = clsAction.MoveLocationToEnum.FromGroup |
| 345 |
End Select |
| 346 |
act.sKey2 = sElements(sElements.Length - 1) |
| 347 |
|
| 348 |
Case "SetProperty" |
| 349 |
act.eItem = clsAction.ItemEnum.SetProperties |
| 350 |
act.sKey1 = sElements(0) |
| 351 |
act.sKey2 = sElements(1) |
| 352 |
'act.StringValue = sElements(2) |
| 353 |
Dim sValue As String = "" |
| 354 |
For i As Integer = 2 To sElements.Length - 1 |
| 355 |
sValue &= sElements(i) |
| 356 |
If i < sElements.Length - 1 Then sValue &= " " |
| 357 |
Next |
| 358 |
act.StringValue = sValue |
| 359 |
act.sPropertyValue = sValue |
| 360 |
Case "Score" |
| 361 |
Case "SetTasks" |
| 362 |
act.eItem = clsAction.ItemEnum.SetTasks |
| 363 |
Dim iStartIndex As Integer = 0 |
| 364 |
Dim iEndIndex As Integer = 1 |
| 365 |
If sElements(0) = "FOR" Then |
| 366 |
' sElements(1) = %Loop% |
| 367 |
' sElements(2) = '=' |
| 368 |
act.IntValue = CInt(sElements(3)) |
| 369 |
' sElements(4) = TO |
| 370 |
act.sPropertyValue = sElements(5) |
| 371 |
' sElements(6) = : |
| 372 |
iStartIndex = 7 |
| 373 |
iEndIndex = 4 |
| 374 |
End If |
| 375 |
act.eSetTasks = EnumParseSetTask(sElements(iStartIndex)) |
| 376 |
act.sKey1 = sElements(iStartIndex + 1) |
| 377 |
For iElement As Integer = iStartIndex + 2 To sElements.Length - iEndIndex |
| 378 |
act.StringValue &= sElements(iElement) |
| 379 |
Next |
| 380 |
If act.StringValue IsNot Nothing Then |
| 381 |
' Simplify Runner so it only has to deal with multiple, or specific refs |
| 382 |
act.StringValue = FixInitialRefs(act.StringValue) |
| 383 |
If act.StringValue.StartsWith("(") Then act.StringValue = sRight(act.StringValue, act.StringValue.Length - 1) |
| 384 |
If act.StringValue.EndsWith(")") Then act.StringValue = sLeft(act.StringValue, act.StringValue.Length - 1) |
| 385 |
End If |
| 386 |
|
| 387 |
Case "SetVariable", "IncVariable", "DecVariable", "ExecuteTask" |
| 388 |
Select Case sType |
| 389 |
Case "SetVariable" |
| 390 |
act.eItem = clsAction.ItemEnum.SetVariable |
| 391 |
Case "IncVariable" |
| 392 |
act.eItem = clsAction.ItemEnum.IncreaseVariable |
| 393 |
Case "DecVariable" |
| 394 |
act.eItem = clsAction.ItemEnum.DecreaseVariable |
| 395 |
End Select |
| 396 |
|
| 397 |
If sElements(0) = "FOR" Then |
| 398 |
act.eVariables = clsAction.VariablesEnum.Loop |
| 399 |
' sElements(1) = %Loop% |
| 400 |
' sElements(2) = '=' |
| 401 |
act.IntValue = CInt(sElements(3)) |
| 402 |
' sElements(4) = TO |
| 403 |
act.sKey2 = sElements(5) |
| 404 |
' sElements(6) = : |
| 405 |
' sElements(7) = SET |
| 406 |
act.sKey1 = sElements(8).Split("["c)(0) |
| 407 |
' sElements(9) = '=' |
| 408 |
For iElement As Integer = 10 To sElements.Length - 4 |
| 409 |
act.StringValue &= sElements(iElement) |
| 410 |
If iElement < sElements.Length - 4 Then act.StringValue &= " " |
| 411 |
Next |
| 412 |
Else |
| 413 |
act.eVariables = clsAction.VariablesEnum.Assignment |
| 414 |
If sInstr(sElements(0), "[") > 0 Then |
| 415 |
act.sKey1 = sElements(0).Split("["c)(0) |
| 416 |
act.sKey2 = sElements(0).Split("["c)(1).Replace("]", "") |
| 417 |
Else |
| 418 |
act.sKey1 = sElements(0) |
| 419 |
End If |
| 420 |
' sElements(1) = '=' |
| 421 |
'act.StringValue = sElements(2) |
| 422 |
For iElement As Integer = 2 To sElements.Length - 1 |
| 423 |
act.StringValue &= sElements(iElement) |
| 424 |
If iElement < sElements.Length - 1 Then act.StringValue &= " " |
| 425 |
Next |
| 426 |
If dFileVersion > 5.0000321 Then |
| 427 |
If act.StringValue.StartsWith("""") AndAlso act.StringValue.EndsWith("""") Then |
| 428 |
act.StringValue = act.StringValue.Substring(1, act.StringValue.Length - 2) |
| 429 |
End If |
| 430 |
End If |
| 431 |
End If |
| 432 |
|
| 433 |
Case "Time" |
| 434 |
act.eItem = clsAction.ItemEnum.Time |
| 435 |
For i As Integer = 1 To sElements.Length - 2 |
| 436 |
If i > 1 Then act.StringValue &= " " |
| 437 |
act.StringValue &= sElements(i) |
| 438 |
Next |
| 439 |
act.StringValue = act.StringValue.Substring(1, act.StringValue.Length - 2) |
| 440 |
|
| 441 |
Case "Conversation" |
| 442 |
act.eItem = clsAction.ItemEnum.Conversation |
| 443 |
Select Case sElements(0).ToUpper |
| 444 |
Case "GREET", "FAREWELL" |
| 445 |
If sElements(0).ToUpper = "GREET" Then |
| 446 |
act.eConversation = clsAction.ConversationEnum.Greet |
| 447 |
Else |
| 448 |
act.eConversation = clsAction.ConversationEnum.Farewell |
| 449 |
End If |
| 450 |
act.sKey1 = sElements(1) |
| 451 |
If sElements.Length > 2 Then |
| 452 |
' sElements(2) = "with" |
| 453 |
For iElement As Integer = 3 To sElements.Length - 1 |
| 454 |
act.StringValue &= sElements(iElement) |
| 455 |
If iElement < sElements.Length - 1 Then act.StringValue &= " " |
| 456 |
Next |
| 457 |
If act.StringValue.StartsWith("'") Then act.StringValue = act.StringValue.Substring(1) |
| 458 |
If act.StringValue.EndsWith("'") Then act.StringValue = sLeft(act.StringValue, act.StringValue.Length - 1) |
| 459 |
End If |
| 460 |
|
| 461 |
Case "ASK", "TELL" |
| 462 |
If sElements(0).ToUpper = "ASK" Then |
| 463 |
act.eConversation = clsAction.ConversationEnum.Ask |
| 464 |
Else |
| 465 |
act.eConversation = clsAction.ConversationEnum.Tell |
| 466 |
End If |
| 467 |
act.sKey1 = sElements(1) |
| 468 |
' sElements(2) = "About" |
| 469 |
For iElement As Integer = 3 To sElements.Length - 1 |
| 470 |
act.StringValue &= sElements(iElement) |
| 471 |
If iElement < sElements.Length - 1 Then act.StringValue &= " " |
| 472 |
Next |
| 473 |
If act.StringValue.StartsWith("'") Then act.StringValue = act.StringValue.Substring(1) |
| 474 |
If act.StringValue.EndsWith("'") Then act.StringValue = sLeft(act.StringValue, act.StringValue.Length - 1) |
| 475 |
|
| 476 |
Case "SAY" |
| 477 |
act.eConversation = clsAction.ConversationEnum.Command |
| 478 |
' sElements(0) = "Say" |
| 479 |
For iElement As Integer = 1 To sElements.Length - 3 |
| 480 |
act.StringValue &= sElements(iElement) |
| 481 |
If iElement < sElements.Length - 3 Then act.StringValue &= " " |
| 482 |
Next |
| 483 |
If act.StringValue.StartsWith("'") Then act.StringValue = act.StringValue.Substring(1) |
| 484 |
If act.StringValue.EndsWith("'") Then act.StringValue = sLeft(act.StringValue, act.StringValue.Length - 1) |
| 485 |
' sElements(len - 2) = "to" |
| 486 |
act.sKey1 = sElements(sElements.Length - 1) |
| 487 |
|
| 488 |
Case "ENTERWITH", "LEAVEWITH" |
| 489 |
If sElements(0).ToUpper = "ENTERWITH" Then |
| 490 |
act.eConversation = clsAction.ConversationEnum.EnterConversation |
| 491 |
Else |
| 492 |
act.eConversation = clsAction.ConversationEnum.LeaveConversation |
| 493 |
End If |
| 494 |
act.sKey1 = sElements(1) |
| 495 |
End Select |
| 496 |
End Select |
| 497 |
|
| 498 |
Actions.Add(act) |
| 499 |
|
| 500 |
End If |
| 501 |
Next |
| 502 |
|
| 503 |
Return Actions |
| 504 |
|
| 505 |
End Function |
| 506 |
|
| 507 |
Friend Function LoadRestrictions(ByVal nodContainerXML As XmlElement) As RestrictionArrayList |
| 508 |
|
| 509 |
Dim Restrictions As New RestrictionArrayList |
| 510 |
|
| 511 |
If nodContainerXML.SelectNodes("Restrictions").Count = 0 Then Return Restrictions |
| 512 |
|
| 513 |
Dim nodRestrictions As XmlElement = CType(nodContainerXML.SelectNodes("Restrictions")(0), XmlElement) |
| 514 |
|
| 515 |
For Each nodRest As XmlElement In nodRestrictions.SelectNodes("Restriction") |
| 516 |
Dim rest As New clsRestriction |
| 517 |
Dim sRest As String |
| 518 |
Dim sType As String = Nothing |
| 519 |
If Not nodRest.Item("Location") Is Nothing Then sType = "Location" |
| 520 |
If Not nodRest.Item("Object") Is Nothing Then sType = "Object" |
| 521 |
If Not nodRest.Item("Task") Is Nothing Then sType = "Task" |
| 522 |
If Not nodRest.Item("Character") Is Nothing Then sType = "Character" |
| 523 |
If Not nodRest.Item("Variable") Is Nothing Then sType = "Variable" |
| 524 |
If Not nodRest.Item("Property") Is Nothing Then sType = "Property" |
| 525 |
If nodRest.Item("Direction") IsNot Nothing Then sType = "Direction" |
| 526 |
If nodRest.Item("Expression") IsNot Nothing Then sType = "Expression" |
| 527 |
If nodRest.Item("Item") IsNot Nothing Then sType = "Item" |
| 528 |
|
| 529 |
If nodRest.Item(sType) Is Nothing Then Exit For |
| 530 |
|
| 531 |
sRest = nodRest.Item(sType).InnerText |
| 532 |
Dim sElements() As String = Split(sRest, " ") |
| 533 |
Select Case sType |
| 534 |
Case "Location" |
| 535 |
rest.eType = clsRestriction.RestrictionTypeEnum.Location |
| 536 |
rest.sKey1 = sElements(0) |
| 537 |
rest.eMust = EnumParseMust(sElements(1)) |
| 538 |
|
| 539 |
rest.eLocation = EnumParseLocation(sElements(2)) |
| 540 |
rest.sKey2 = sElements(3) |
| 541 |
Case "Object" |
| 542 |
rest.eType = clsRestriction.RestrictionTypeEnum.Object |
| 543 |
rest.sKey1 = sElements(0) |
| 544 |
rest.eMust = EnumParseMust(sElements(1)) |
| 545 |
rest.eObject = EnumParseObject(sElements(2)) |
| 546 |
rest.sKey2 = sElements(3) |
| 547 |
Case "Task" |
| 548 |
rest.eType = clsRestriction.RestrictionTypeEnum.Task |
| 549 |
rest.sKey1 = sElements(0) |
| 550 |
rest.eMust = EnumParseMust(sElements(1)) |
| 551 |
rest.eTask = clsRestriction.TaskEnum.Complete |
| 552 |
Case "Character" |
| 553 |
rest.eType = clsRestriction.RestrictionTypeEnum.Character |
| 554 |
rest.sKey1 = sElements(0) |
| 555 |
rest.eMust = EnumParseMust(sElements(1)) |
| 556 |
rest.eCharacter = EnumParseCharacter(sElements(2)) |
| 557 |
rest.sKey2 = sElements(3) |
| 558 |
Case "Item" |
| 559 |
rest.eType = clsRestriction.RestrictionTypeEnum.Item |
| 560 |
rest.sKey1 = sElements(0) |
| 561 |
rest.eMust = EnumParseMust(sElements(1)) |
| 562 |
rest.eItem = EnumParseItem(sElements(2)) |
| 563 |
rest.sKey2 = sElements(3) |
| 564 |
Case "Variable" |
| 565 |
rest.eType = clsRestriction.RestrictionTypeEnum.Variable |
| 566 |
rest.sKey1 = sElements(0) |
| 567 |
If rest.sKey1.Contains("[") AndAlso rest.sKey1.Contains("]") Then |
| 568 |
rest.sKey2 = rest.sKey1.Substring(rest.sKey1.IndexOf("[") + 1, rest.sKey1.LastIndexOf("]") - rest.sKey1.IndexOf("[") - 1) |
| 569 |
rest.sKey1 = rest.sKey1.Substring(0, rest.sKey1.IndexOf("[")) |
| 570 |
End If |
| 571 |
rest.eMust = EnumParseMust(sElements(1)) |
| 572 |
rest.eVariable = CType([Enum].Parse(GetType(clsRestriction.VariableEnum), sElements(2).Substring(2)), clsRestriction.VariableEnum) |
| 573 |
|
| 574 |
Dim sValue As String = "" |
| 575 |
For i As Integer = 3 To sElements.Length - 1 |
| 576 |
sValue &= sElements(i) |
| 577 |
If i < sElements.Length - 1 Then sValue &= " " |
| 578 |
Next |
| 579 |
If sElements.Length = 4 AndAlso IsNumeric(sElements(3)) Then |
| 580 |
rest.IntValue = CInt(sElements(3)) ' Integer value |
| 581 |
rest.StringValue = rest.IntValue.ToString |
| 582 |
Else |
| 583 |
If sValue.StartsWith("""") AndAlso sValue.EndsWith("""") Then |
| 584 |
rest.StringValue = sValue.Substring(1, sValue.Length - 2) ' String constant |
| 585 |
ElseIf sValue.StartsWith("'") AndAlso sValue.EndsWith("'") Then |
| 586 |
rest.StringValue = sValue.Substring(1, sValue.Length - 2) ' Expression |
| 587 |
Else |
| 588 |
rest.StringValue = sElements(3) |
| 589 |
rest.IntValue = Integer.MinValue ' A key to a variable |
| 590 |
End If |
| 591 |
End If |
| 592 |
|
| 593 |
Case "Property" |
| 594 |
rest.eType = clsRestriction.RestrictionTypeEnum.Property |
| 595 |
rest.sKey1 = sElements(0) |
| 596 |
rest.sKey2 = sElements(1) |
| 597 |
rest.eMust = EnumParseMust(sElements(2)) |
| 598 |
Dim iStartExpression As Integer = 3 |
| 599 |
rest.IntValue = -1 |
| 600 |
For Each eEquals As clsRestriction.VariableEnum In [Enum].GetValues(GetType(clsRestriction.VariableEnum)) |
| 601 |
If sElements(3) = eEquals.ToString Then rest.IntValue = CInt(eEquals) |
| 602 |
Next |
| 603 |
If rest.IntValue > -1 Then iStartExpression = 4 Else rest.IntValue = CInt(clsRestriction.VariableEnum.EqualTo) |
| 604 |
Dim sValue As String = "" |
| 605 |
For i As Integer = iStartExpression To sElements.Length - 1 |
| 606 |
sValue &= sElements(i) |
| 607 |
If i < sElements.Length - 1 Then sValue &= " " |
| 608 |
Next |
| 609 |
rest.StringValue = sValue |
| 610 |
|
| 611 |
Case "Direction" |
| 612 |
rest.eType = clsRestriction.RestrictionTypeEnum.Direction |
| 613 |
rest.eMust = EnumParseMust(sElements(0)) |
| 614 |
rest.sKey1 = sElements(1) |
| 615 |
rest.sKey1 = sRight(rest.sKey1, rest.sKey1.Length - 2) ' Trim off the Be |
| 616 |
|
| 617 |
Case "Expression" |
| 618 |
rest.eType = clsRestriction.RestrictionTypeEnum.Expression |
| 619 |
rest.eMust = clsRestriction.MustEnum.Must |
| 620 |
Dim sValue As String = "" |
| 621 |
For i As Integer = 0 To sElements.Length - 1 |
| 622 |
sValue &= sElements(i) |
| 623 |
If i < sElements.Length - 1 Then sValue &= " " |
| 624 |
Next |
| 625 |
rest.StringValue = sValue |
| 626 |
|
| 627 |
End Select |
| 628 |
rest.oMessage = LoadDescription(nodRest, "Message") |
| 629 |
Restrictions.Add(rest) |
| 630 |
|
| 631 |
Next |
| 632 |
Restrictions.BracketSequence = nodRestrictions.SelectNodes("BracketSequence")(0).InnerText ' GetElementsByTagName("BracketSequence")(0).InnerText |
| 633 |
|
| 634 |
If Not bAskedAboutBrackets AndAlso dFileVersion < 5.000026 AndAlso Restrictions.BracketSequence.Contains("#A#O#") Then |
| 635 |
bCorrectBracketSequences = Glue.AskYesNoQuestion("There was a logic correction in version 5.0.26 which means OR restrictions after AND restrictions were not evaluated. Would you like to auto-correct these tasks?" & vbCrLf & vbCrLf & "You may not wish to do so if you have already used brackets around any OR restrictions following AND restrictions.", "Adventure Upgrade") |
| 636 |
bAskedAboutBrackets = True |
| 637 |
End If |
| 638 |
If bCorrectBracketSequences Then Restrictions.BracketSequence = CorrectBracketSequence(Restrictions.BracketSequence) |
| 639 |
|
| 640 |
Restrictions.BracketSequence = Restrictions.BracketSequence.Replace("[", "((").Replace("]", "))") |
| 641 |
Return Restrictions |
| 642 |
|
| 643 |
End Function |
| 644 |
|
| 645 |
Private Function FixInitialRefs(ByVal sCommand As String) As String |
| 646 |
If sCommand Is Nothing Then Return "" |
| 647 |
Return sCommand.Replace("%object%", "%object1%").Replace("%character%", "%character1%").Replace("%location%", "%location1%").Replace("%number%", "%number1%").Replace("%text%", "%text1%").Replace("%item%", "%item1%").Replace("%direction%", "%direction1%") |
| 648 |
End Function |
| 649 |
|
| 650 |
Private Function IsEqual(ByRef mb1 As Byte(), ByRef mb2 As Byte()) As Boolean |
| 651 |
|
| 652 |
If (mb1.Length <> mb2.Length) Then ' make sure arrays same length |
| 653 |
Return False |
| 654 |
Else |
| 655 |
For i As Integer = 0 To mb1.Length - 1 ' run array length looking for miscompare |
| 656 |
If mb1(i) <> mb2(i) Then Return False |
| 657 |
Next |
| 658 |
End If |
| 659 |
|
| 660 |
Return True |
| 661 |
End Function |
| 662 |
|
| 663 |
|
| 664 |
' This loads from file into our data structure |
| 665 |
' Assumes file exists |
| 666 |
' |
| 667 |
Public Enum FileTypeEnum |
| 668 |
TextAdventure_TAF |
| 669 |
XMLModule_AMF |
| 670 |
v4Module_AMF |
| 671 |
GameState_TAS |
| 672 |
Blorb |
| 673 |
Exe |
| 674 |
End Enum |
| 675 |
|
| 676 |
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 |
| 677 |
|
| 678 |
Dim stmOriginalFile As IO.FileStream = Nothing |
| 679 |
|
| 680 |
Try |
| 681 |
If Not IO.File.Exists(sFilename) Then |
| 682 |
ErrMsg("File '" & sFilename & "' not found.") |
| 683 |
Return False |
| 684 |
End If |
| 685 |
|
| 686 |
stmOriginalFile = New IO.FileStream(sFilename, IO.FileMode.Open, FileAccess.Read) |
| 687 |
|
| 688 |
If eFileType = FileTypeEnum.TextAdventure_TAF Then |
| 689 |
|
| 690 |
stmOriginalFile.Seek(FileLen(sFilename) - 14, SeekOrigin.Begin) |
| 691 |
br = New BinaryReader(stmOriginalFile) |
| 692 |
Dim bPass As Byte() = Dencode(br.ReadBytes(12), FileLen(sFilename) - 13) |
| 693 |
Dim sPassString As String = System.Text.Encoding.UTF8.GetString(bPass) |
| 694 |
Adventure.Password = (sLeft(sPassString, 4) & sRight(sPassString, 4)).Trim |
| 695 |
|
| 696 |
End If |
| 697 |
|
| 698 |
If lOffset > 0 Then |
| 699 |
stmOriginalFile.Seek(lOffset, SeekOrigin.Begin) |
| 700 |
lOffset += 7 ' for the footer |
| 701 |
Else |
| 702 |
stmOriginalFile.Seek(0, SeekOrigin.Begin) |
| 703 |
End If |
| 704 |
|
| 705 |
br = New BinaryReader(stmOriginalFile) |
| 706 |
|
| 707 |
iLoading += 1 |
| 708 |
|
| 709 |
Select Case eFileType |
| 710 |
Case FileTypeEnum.Exe |
| 711 |
If clsBlorb.ExecResource IsNot Nothing AndAlso clsBlorb.ExecResource.Length > 0 Then |
| 712 |
If Not Load500(Decompress(clsBlorb.ExecResource, dVersion >= 5.00002 AndAlso clsBlorb.bObfuscated, 16, clsBlorb.ExecResource.Length - 30), False) Then Return False |
| 713 |
clsBlorb.bObfuscated = False |
| 714 |
If clsBlorb.MetaData IsNot Nothing Then Adventure.BabelTreatyInfo.FromString(clsBlorb.MetaData.OuterXml) |
| 715 |
Adventure.FullPath = SafeString(Application.ExecutablePath) |
| 716 |
Else |
| 717 |
Return False |
| 718 |
End If |
| 719 |
|
| 720 |
Case FileTypeEnum.Blorb |
| 721 |
Blorb = New clsBlorb |
| 722 |
If Blorb.LoadBlorb(stmOriginalFile, sFilename) Then |
| 723 |
|
| 724 |
Dim bVersion As Byte() = New Byte(11) {} |
| 725 |
Array.Copy(clsBlorb.ExecResource, bVersion, 12) |
| 726 |
|
| 727 |
Dim sVersion As String |
| 728 |
If IsEqual(bVersion, New Byte() {60, 66, 63, 201, 106, 135, 194, 207, 146, 69, 62, 97}) Then |
| 729 |
sVersion = "Version 5.00" |
| 730 |
ElseIf IsEqual(bVersion, New Byte() {60, 66, 63, 201, 106, 135, 194, 207, 147, 69, 62, 97}) Then |
| 731 |
sVersion = "Version 4.00" |
| 732 |
ElseIf IsEqual(bVersion, New Byte() {60, 66, 63, 201, 106, 135, 194, 207, 148, 69, 55, 97}) Then |
| 733 |
sVersion = "Version 3.90" |
| 734 |
Else |
| 735 |
sVersion = System.Text.Encoding.UTF8.GetString(Dencode(bVersion, 1)) |
| 736 |
End If |
| 737 |
|
| 738 |
If Left(sVersion, 8) <> "Version " Then |
| 739 |
ErrMsg("Not an ADRIFT Blorb file") |
| 740 |
Return False |
| 741 |
End If |
| 742 |
|
| 743 |
UserSession.ShowUserSplash() |
| 744 |
|
| 745 |
With Adventure |
| 746 |
.dVersion = Double.Parse(sVersion.Replace("Version ", ""), Globalization.CultureInfo.InvariantCulture.NumberFormat) 'CDbl(sVersion.Replace("Version ", "")) |
| 747 |
.Filename = Path.GetFileName(sFilename) |
| 748 |
.FullPath = sFilename |
| 749 |
End With |
| 750 |
|
| 751 |
Dim bDeObfuscate As Boolean = clsBlorb.MetaData Is Nothing OrElse clsBlorb.MetaData.OuterXml.Contains("compilerversion") ' Nasty, but works |
| 752 |
' Was this a pre-obfuscated size blorb? |
| 753 |
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 |
| 754 |
If Not Load500(Decompress(clsBlorb.ExecResource, bDeObfuscate, 16, clsBlorb.ExecResource.Length - 30), False) Then Return False |
| 755 |
Else |
| 756 |
If Not Load500(Decompress(clsBlorb.ExecResource, bDeObfuscate, 12, clsBlorb.ExecResource.Length - 26), False) Then Return False |
| 757 |
End If |
| 758 |
|
| 759 |
If clsBlorb.MetaData IsNot Nothing Then Adventure.BabelTreatyInfo.FromString(clsBlorb.MetaData.OuterXml) |
| 760 |
Else |
| 761 |
Return False |
| 762 |
End If |
| 763 |
|
| 764 |
Case FileTypeEnum.TextAdventure_TAF |
| 765 |
Dim bVersion As Byte() = br.ReadBytes(12) |
| 766 |
Dim sVersion As String |
| 767 |
If IsEqual(bVersion, New Byte() {60, 66, 63, 201, 106, 135, 194, 207, 146, 69, 62, 97}) Then |
| 768 |
sVersion = "Version 5.00" |
| 769 |
ElseIf IsEqual(bVersion, New Byte() {60, 66, 63, 201, 106, 135, 194, 207, 147, 69, 62, 97}) Then |
| 770 |
sVersion = "Version 4.00" |
| 771 |
ElseIf IsEqual(bVersion, New Byte() {60, 66, 63, 201, 106, 135, 194, 207, 148, 69, 55, 97}) Then |
| 772 |
sVersion = "Version 3.90" |
| 773 |
Else |
| 774 |
sVersion = System.Text.Encoding.UTF8.GetString(Dencode(bVersion, 1)) |
| 775 |
End If |
| 776 |
|
| 777 |
|
| 778 |
If Left(sVersion, 8) <> "Version " Then |
| 779 |
ErrMsg("Not an ADRIFT Text Adventure file") |
| 780 |
Return False |
| 781 |
End If |
| 782 |
|
| 783 |
With Adventure |
| 784 |
.dVersion = Double.Parse(sVersion.Replace("Version ", ""), Globalization.CultureInfo.InvariantCulture.NumberFormat) |
| 785 |
.Filename = Path.GetFileName(sFilename) |
| 786 |
.FullPath = sFilename |
| 787 |
End With |
| 788 |
|
| 789 |
Debug.WriteLine("Start Load: " & Now) |
| 790 |
Select Case sVersion |
| 791 |
Case "Version 3.90", "Version 4.00" |
| 792 |
ErrMsg("ADRIFT v3.9 and v4 adventures are not supported in FrankenDrift.") |
| 793 |
Return False |
| 794 |
Case "Version 5.00" |
| 795 |
Dim sSize As String = System.Text.Encoding.UTF8.GetString(br.ReadBytes(4)) |
| 796 |
Dim sCheck As String = System.Text.Encoding.UTF8.GetString(br.ReadBytes(8)) |
| 797 |
Dim iBabelLength As Integer = 0 |
| 798 |
Dim sBabel As String = Nothing |
| 799 |
Dim bObfuscate As Boolean = True |
| 800 |
If sSize = "0000" OrElse sCheck = "<ifindex" Then |
| 801 |
stmOriginalFile.Seek(16, 0) ' Set to just after the size chunk |
| 802 |
' 5.0.20 format onwards |
| 803 |
iBabelLength = CInt("&H" & sSize) |
| 804 |
If iBabelLength > 0 Then |
| 805 |
Dim bBabel() As Byte = br.ReadBytes(iBabelLength) |
| 806 |
sBabel = System.Text.Encoding.UTF8.GetString(bBabel) |
| 807 |
End If |
| 808 |
iBabelLength += 4 ' For size header |
| 809 |
Else |
| 810 |
' Pre 5.0.20 |
| 811 |
' THIS COULD BE AN EXTRACTED TAF, THEREFORE NO METADATA!!! |
| 812 |
' Ok, we have no uncompressed Babel info at the start. Start over... |
| 813 |
stmOriginalFile.Seek(0, SeekOrigin.Begin) |
| 814 |
br = New BinaryReader(stmOriginalFile) |
| 815 |
br.ReadBytes(12) |
| 816 |
bObfuscate = False |
| 817 |
End If |
| 818 |
Dim stmFile As MemoryStream = FileToMemoryStream(True, CInt(FileLen(sFilename) - 26 - lOffset - iBabelLength), bObfuscate) |
| 819 |
If stmFile Is Nothing Then Return False |
| 820 |
If Not Load500(stmFile, False, False, eLoadWhat, dtAdvDate) Then Return False ' - 12))) |
| 821 |
If sBabel <> "" Then |
| 822 |
Adventure.BabelTreatyInfo.FromString(sBabel) |
| 823 |
Dim sTemp As String = Adventure.CoverFilename |
| 824 |
Adventure.CoverFilename = Nothing |
| 825 |
Adventure.CoverFilename = sTemp ' Just to re-set the image in the Babel structure |
| 826 |
End If |
| 827 |
|
| 828 |
Case Else |
| 829 |
ErrMsg("ADRIFT " & sVersion & " Adventures are not currently supported in ADRIFT v" & dVersion.ToString("0.0")) |
| 830 |
Return False |
| 831 |
End Select |
| 832 |
Debug.WriteLine("End Load: " & Now) |
| 833 |
|
| 834 |
Case FileTypeEnum.v4Module_AMF |
| 835 |
TODO("Version 4.0 Modules") |
| 836 |
|
| 837 |
Case FileTypeEnum.XMLModule_AMF |
| 838 |
If Not Load500(FileToMemoryStream(False, CInt(FileLen(sFilename)), False), bLibrary, True, eLoadWhat, dtAdvDate, sFilename) Then Return False |
| 839 |
|
| 840 |
Case FileTypeEnum.GameState_TAS |
| 841 |
state = LoadState(FileToMemoryStream(True, CInt(FileLen(sFilename)), False)) |
| 842 |
|
| 843 |
End Select |
| 844 |
|
| 845 |
If br IsNot Nothing Then br.Close() |
| 846 |
br = Nothing |
| 847 |
stmOriginalFile.Close() |
| 848 |
stmOriginalFile = Nothing |
| 849 |
|
| 850 |
If Adventure.NotUnderstood = "" Then Adventure.NotUnderstood = "Sorry, I didn't understand that command." |
| 851 |
If Adventure.Player IsNot Nothing AndAlso (Adventure.Player.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.Hidden OrElse Adventure.Player.Location.Key = "") Then |
| 852 |
If Adventure.htblLocations.Count > 0 Then |
| 853 |
Dim locFirst As clsCharacterLocation = Adventure.Player.Location |
| 854 |
locFirst.ExistWhere = clsCharacterLocation.ExistsWhereEnum.AtLocation |
| 855 |
For Each sKey As String In Adventure.htblLocations.Keys |
| 856 |
locFirst.Key = sKey |
| 857 |
Exit For |
| 858 |
Next |
| 859 |
Adventure.Player.Move(locFirst) |
| 860 |
End If |
| 861 |
End If |
| 862 |
|
| 863 |
iLoading -= 1 |
| 864 |
|
| 865 |
Return True |
| 866 |
Catch ex As Exception |
| 867 |
If Not br Is Nothing Then br.Close() |
| 868 |
If Not stmOriginalFile Is Nothing Then stmOriginalFile.Close() |
| 869 |
ErrMsg("Error loading " & sFilename, ex) |
| 870 |
Return False |
| 871 |
Finally |
| 872 |
End Try |
| 873 |
|
| 874 |
End Function |
| 875 |
|
| 876 |
Private Function LoadState(ByVal stmMemory As MemoryStream) As clsGameState |
| 877 |
Try |
| 878 |
Dim NewState As New clsGameState |
| 879 |
Dim xmlDoc As New XmlDocument |
| 880 |
xmlDoc.Load(stmMemory) |
| 881 |
|
| 882 |
With xmlDoc.Item("Game") |
| 883 |
For Each nodLoc As XmlElement In xmlDoc.SelectNodes("/Game/Location") |
| 884 |
With nodLoc |
| 885 |
Dim locs As New clsGameState.clsLocationState |
| 886 |
Dim sKey As String = .Item("Key").InnerText |
| 887 |
For Each nodProp As XmlElement In nodLoc.SelectNodes("Property") |
| 888 |
Dim props As New clsGameState.clsLocationState.clsStateProperty |
| 889 |
Dim sPropKey As String = nodProp.Item("Key").InnerText |
| 890 |
props.Value = nodProp.Item("Value").InnerText |
| 891 |
locs.htblProperties.Add(sPropKey, props) |
| 892 |
Next |
| 893 |
For Each nodDisplayed As XmlElement In nodLoc.SelectNodes("Displayed") |
| 894 |
locs.htblDisplayedDescriptions.Add(nodDisplayed.InnerText, True) |
| 895 |
Next |
| 896 |
NewState.htblLocationStates.Add(sKey, locs) |
| 897 |
End With |
| 898 |
Next |
| 899 |
|
| 900 |
For Each nodOb As XmlElement In xmlDoc.SelectNodes("/Game/Object") |
| 901 |
With nodOb |
| 902 |
Dim obs As New clsGameState.clsObjectState |
| 903 |
obs.Location = New clsObjectLocation |
| 904 |
Dim sKey As String = .Item("Key").InnerText |
| 905 |
If .Item("DynamicExistWhere") IsNot Nothing Then |
| 906 |
obs.Location.DynamicExistWhere = CType([Enum].Parse(GetType(clsObjectLocation.DynamicExistsWhereEnum), .Item("DynamicExistWhere").InnerText), clsObjectLocation.DynamicExistsWhereEnum) |
| 907 |
Else |
| 908 |
obs.Location.DynamicExistWhere = clsObjectLocation.DynamicExistsWhereEnum.Hidden |
| 909 |
End If |
| 910 |
If .Item("StaticExistWhere") IsNot Nothing Then |
| 911 |
obs.Location.StaticExistWhere = CType([Enum].Parse(GetType(clsObjectLocation.StaticExistsWhereEnum), .Item("StaticExistWhere").InnerText), clsObjectLocation.StaticExistsWhereEnum) |
| 912 |
Else |
| 913 |
obs.Location.StaticExistWhere = clsObjectLocation.StaticExistsWhereEnum.NoRooms |
| 914 |
End If |
| 915 |
If .Item("LocationKey") IsNot Nothing Then obs.Location.Key = .Item("LocationKey").InnerText |
| 916 |
For Each nodProp As XmlElement In nodOb.SelectNodes("Property") |
| 917 |
Dim props As New clsGameState.clsObjectState.clsStateProperty |
| 918 |
Dim sPropKey As String = nodProp.Item("Key").InnerText |
| 919 |
props.Value = nodProp.Item("Value").InnerText |
| 920 |
obs.htblProperties.Add(sPropKey, props) |
| 921 |
Next |
| 922 |
For Each nodDisplayed As XmlElement In nodOb.SelectNodes("Displayed") |
| 923 |
obs.htblDisplayedDescriptions.Add(nodDisplayed.InnerText, True) |
| 924 |
Next |
| 925 |
|
| 926 |
NewState.htblObjectStates.Add(sKey, obs) |
| 927 |
End With |
| 928 |
Next |
| 929 |
|
| 930 |
For Each nodTas As XmlElement In xmlDoc.SelectNodes("/Game/Task") |
| 931 |
With nodTas |
| 932 |
Dim tas As New clsGameState.clsTaskState |
| 933 |
Dim sKey As String = .Item("Key").InnerText |
| 934 |
tas.Completed = CBool(.Item("Completed").InnerText) |
| 935 |
If .Item("Scored") IsNot Nothing Then tas.Scored = CBool(.Item("Scored").InnerText) |
| 936 |
For Each nodDisplayed As XmlElement In nodTas.SelectNodes("Displayed") |
| 937 |
tas.htblDisplayedDescriptions.Add(nodDisplayed.InnerText, True) |
| 938 |
Next |
| 939 |
|
| 940 |
NewState.htblTaskStates.Add(sKey, tas) |
| 941 |
End With |
| 942 |
Next |
| 943 |
|
| 944 |
For Each nodEv As XmlElement In xmlDoc.SelectNodes("/Game/Event") |
| 945 |
With nodEv |
| 946 |
Dim evs As New clsGameState.clsEventState |
| 947 |
Dim sKey As String = .Item("Key").InnerText |
| 948 |
evs.Status = CType([Enum].Parse(GetType(clsEvent.StatusEnum), .Item("Status").InnerText), clsEvent.StatusEnum) |
| 949 |
evs.TimerToEndOfEvent = SafeInt(.Item("Timer").InnerText) |
| 950 |
If .Item("SubEventTime") IsNot Nothing Then evs.iLastSubEventTime = SafeInt(.Item("SubEventTime").InnerText) |
| 951 |
If .Item("SubEventIndex") IsNot Nothing Then evs.iLastSubEventIndex = SafeInt(.Item("SubEventIndex").InnerText) |
| 952 |
For Each nodDisplayed As XmlElement In nodEv.SelectNodes("Displayed") |
| 953 |
evs.htblDisplayedDescriptions.Add(nodDisplayed.InnerText, True) |
| 954 |
Next |
| 955 |
NewState.htblEventStates.Add(sKey, evs) |
| 956 |
End With |
| 957 |
Next |
| 958 |
|
| 959 |
For Each nodCh As XmlElement In xmlDoc.SelectNodes("/Game/Character") |
| 960 |
With nodCh |
| 961 |
Dim chs As New clsGameState.clsCharacterState |
| 962 |
Dim sKey As String = .Item("Key").InnerText |
| 963 |
If Adventure.htblCharacters.ContainsKey(sKey) Then |
| 964 |
chs.Location = New clsCharacterLocation(Adventure.htblCharacters(sKey)) |
| 965 |
If .Item("ExistWhere") IsNot Nothing Then |
| 966 |
chs.Location.ExistWhere = CType([Enum].Parse(GetType(clsCharacterLocation.ExistsWhereEnum), .Item("ExistWhere").InnerText), clsCharacterLocation.ExistsWhereEnum) |
| 967 |
Else |
| 968 |
chs.Location.ExistWhere = clsCharacterLocation.ExistsWhereEnum.Hidden |
| 969 |
End If |
| 970 |
If .Item("Position") IsNot Nothing Then |
| 971 |
chs.Location.Position = CType([Enum].Parse(GetType(clsCharacterLocation.PositionEnum), .Item("Position").InnerText), clsCharacterLocation.PositionEnum) |
| 972 |
Else |
| 973 |
chs.Location.Position = clsCharacterLocation.PositionEnum.Standing |
| 974 |
End If |
| 975 |
If .Item("LocationKey") IsNot Nothing Then |
| 976 |
chs.Location.Key = .Item("LocationKey").InnerText |
| 977 |
Else |
| 978 |
chs.Location.Key = "" |
| 979 |
End If |
| 980 |
For Each nodW As XmlElement In nodCh.SelectNodes("Walk") |
| 981 |
With nodW |
| 982 |
Dim ws As New clsGameState.clsCharacterState.clsWalkState |
| 983 |
ws.Status = CType([Enum].Parse(GetType(clsWalk.StatusEnum), .Item("Status").InnerText), clsWalk.StatusEnum) |
| 984 |
ws.TimerToEndOfWalk = SafeInt(.Item("Timer").InnerText) |
| 985 |
chs.lWalks.Add(ws) |
| 986 |
End With |
| 987 |
Next |
| 988 |
For Each nodProp As XmlElement In nodCh.SelectNodes("Property") |
| 989 |
Dim props As New clsGameState.clsCharacterState.clsStateProperty |
| 990 |
Dim sPropKey As String = nodProp.Item("Key").InnerText |
| 991 |
props.Value = nodProp.Item("Value").InnerText |
| 992 |
chs.htblProperties.Add(sPropKey, props) |
| 993 |
Next |
| 994 |
For Each nodSeen As XmlElement In nodCh.SelectNodes("Seen") |
| 995 |
chs.lSeenKeys.Add(nodSeen.InnerText) |
| 996 |
Next |
| 997 |
For Each nodDisplayed As XmlElement In nodCh.SelectNodes("Displayed") |
| 998 |
chs.htblDisplayedDescriptions.Add(nodDisplayed.InnerText, True) |
| 999 |
Next |
| 1000 |
NewState.htblCharacterStates.Add(sKey, chs) |
| 1001 |
Else |
| 1002 |
DisplayError("Character key " & sKey & " not found in adventure!") |
| 1003 |
End If |
| 1004 |
End With |
| 1005 |
Next |
| 1006 |
|
| 1007 |
For Each nodVar As XmlElement In xmlDoc.SelectNodes("/Game/Variable") |
| 1008 |
With nodVar |
| 1009 |
Dim vars As New clsGameState.clsVariableState |
| 1010 |
Dim sKey As String = .Item("Key").InnerText |
| 1011 |
If Adventure.htblVariables.ContainsKey(sKey) Then |
| 1012 |
Dim v As clsVariable = Adventure.htblVariables(sKey) |
| 1013 |
|
| 1014 |
ReDim vars.Value(v.Length - 1) |
| 1015 |
For i As Integer = 0 To v.Length - 1 |
| 1016 |
If .Item("Value_" & i) IsNot Nothing Then |
| 1017 |
vars.Value(i) = SafeString(.Item("Value_" & i).InnerText) |
| 1018 |
Else |
| 1019 |
If v.Type = clsVariable.VariableTypeEnum.Numeric Then |
| 1020 |
vars.Value(i) = "0" |
| 1021 |
Else |
| 1022 |
vars.Value(i) = "" |
| 1023 |
End If |
| 1024 |
End If |
| 1025 |
Next |
| 1026 |
If .Item("Value") IsNot Nothing Then ' Old style |
| 1027 |
vars.Value(0) = SafeString(.Item("Value").InnerText) |
| 1028 |
End If |
| 1029 |
|
| 1030 |
For Each nodDisplayed As XmlElement In nodVar.SelectNodes("Displayed") |
| 1031 |
vars.htblDisplayedDescriptions.Add(nodDisplayed.InnerText, True) |
| 1032 |
Next |
| 1033 |
NewState.htblVariableStates.Add(sKey, vars) |
| 1034 |
Else |
| 1035 |
DisplayError("Variable key " & sKey & " not found in adventure!") |
| 1036 |
End If |
| 1037 |
|
| 1038 |
End With |
| 1039 |
Next |
| 1040 |
|
| 1041 |
For Each nodGrp As XmlElement In xmlDoc.SelectNodes("/Game/Group") |
| 1042 |
With nodGrp |
| 1043 |
Dim grps As New clsGameState.clsGroupState |
| 1044 |
Dim sKey As String = .Item("Key").InnerText |
| 1045 |
For Each nodMember As XmlElement In nodGrp.SelectNodes("Member") |
| 1046 |
grps.lstMembers.Add(nodMember.InnerText) |
| 1047 |
Next |
| 1048 |
NewState.htblGroupStates.Add(sKey, grps) |
| 1049 |
End With |
| 1050 |
Next |
| 1051 |
|
| 1052 |
If .Item("Turns") IsNot Nothing Then Adventure.Turns = SafeInt(.Item("Turns").InnerText) |
| 1053 |
|
| 1054 |
End With |
| 1055 |
|
| 1056 |
Return NewState |
| 1057 |
|
| 1058 |
Catch ex As Exception |
| 1059 |
ErrMsg("Error loading game state", ex) |
| 1060 |
End Try |
| 1061 |
|
| 1062 |
Return Nothing |
| 1063 |
|
| 1064 |
End Function |
| 1065 |
|
| 1066 |
Private Sub ObfuscateByteArray(ByRef bytData As Byte(), Optional ByVal iOffset As Integer = 0, Optional ByVal iLength As Integer = 0) |
| 1067 |
|
| 1068 |
Dim iRandomKey As Integer() = {41, 236, 221, 117, 23, 189, 44, 187, 161, 96, 4, 147, 90, 91, 172, 159, 244, 50, 249, 140, 190, 244, 82, 111, 170, 217, 13, 207, 25, 177, 18, 4, 3, 221, 160, 209, 253, 69, 131, 37, 132, 244, 21, 4, 39, 87, 56, 203, 119, 139, 231, 180, 190, 13, 213, 53, 153, 109, 202, 62, 175, 93, 161, 239, 77, 0, 143, 124, 186, 219, 161, 175, 175, 212, 7, 202, 223, 77, 72, 83, 160, 66, 88, 142, 202, 93, 70, 246, 8, 107, 55, 144, 122, 68, 117, 39, 83, 37, 183, 39, 199, 188, 16, 155, 233, 55, 5, 234, 6, 11, 86, 76, 36, 118, 158, 109, 5, 19, 36, 239, 185, 153, 115, 79, 164, 17, 52, 106, 94, 224, 118, 185, 150, 33, 139, 228, 49, 188, 164, 146, 88, 91, 240, 253, 21, 234, 107, 3, 166, 7, 33, 63, 0, 199, 109, 46, 72, 193, 246, 216, 3, 154, 139, 37, 148, 156, 182, 3, 235, 185, 60, 73, 111, 145, 151, 94, 169, 118, 57, 186, 165, 48, 195, 86, 190, 55, 184, 206, 180, 93, 155, 111, 197, 203, 143, 189, 208, 202, 105, 121, 51, 104, 24, 237, 203, 216, 208, 111, 48, 15, 132, 210, 136, 60, 51, 211, 215, 52, 102, 92, 227, 232, 79, 142, 29, 204, 131, 163, 2, 217, 141, 223, 12, 192, 134, 61, 23, 214, 139, 230, 102, 73, 158, 165, 216, 201, 231, 137, 152, 187, 230, 155, 99, 12, 149, 75, 25, 138, 207, 254, 85, 44, 108, 86, 129, 165, 197, 200, 182, 245, 187, 1, 169, 128, 245, 153, 74, 170, 181, 83, 229, 250, 11, 70, 243, 242, 123, 0, 42, 58, 35, 141, 6, 140, 145, 58, 221, 71, 35, 51, 4, 30, 210, 162, 0, 229, 241, 227, 22, 252, 1, 110, 212, 123, 24, 90, 32, 37, 99, 142, 42, 196, 158, 123, 209, 45, 250, 28, 238, 187, 188, 3, 134, 130, 79, 199, 39, 105, 70, 14, 0, 151, 234, 46, 56, 181, 185, 138, 115, 54, 25, 183, 227, 149, 9, 63, 128, 87, 208, 210, 234, 213, 244, 91, 63, 254, 232, 81, 44, 81, 51, 183, 222, 85, 142, 146, 218, 112, 66, 28, 116, 111, 168, 184, 161, 4, 31, 241, 121, 15, 70, 208, 152, 116, 35, 43, 163, 142, 238, 58, 204, 103, 94, 34, 2, 97, 217, 142, 6, 119, 100, 16, 20, 179, 94, 122, 44, 59, 185, 58, 223, 247, 216, 28, 11, 99, 31, 105, 49, 98, 238, 75, 129, 8, 80, 12, 17, 134, 181, 63, 43, 145, 234, 2, 170, 54, 188, 228, 22, 168, 255, 103, 213, 180, 91, 213, 143, 65, 23, 159, 66, 111, 92, 164, 136, 25, 143, 11, 99, 81, 105, 165, 133, 121, 14, 77, 12, 213, 114, 213, 166, 58, 83, 136, 99, 135, 118, 205, 173, 123, 124, 207, 111, 22, 253, 188, 52, 70, 122, 145, 167, 176, 129, 196, 63, 89, 225, 91, 165, 13, 200, 185, 207, 65, 248, 8, 27, 211, 64, 1, 162, 193, 94, 231, 213, 153, 53, 111, 124, 81, 25, 198, 91, 224, 45, 246, 184, 142, 73, 9, 165, 26, 39, 159, 178, 194, 0, 45, 29, 245, 161, 97, 5, 120, 238, 229, 81, 153, 239, 165, 35, 114, 223, 83, 244, 1, 94, 238, 20, 2, 79, 140, 137, 54, 91, 136, 153, 190, 53, 18, 153, 8, 81, 135, 176, 184, 193, 226, 242, 72, 164, 30, 159, 164, 230, 51, 58, 212, 171, 176, 100, 17, 25, 27, 165, 20, 215, 206, 29, 102, 75, 147, 100, 221, 11, 27, 32, 88, 162, 59, 64, 123, 252, 203, 93, 48, 237, 229, 80, 40, 77, 197, 18, 132, 173, 136, 238, 54, 225, 156, 225, 242, 197, 140, 252, 17, 185, 193, 153, 202, 19, 226, 49, 112, 111, 232, 20, 78, 190, 117, 38, 242, 125, 244, 24, 134, 128, 224, 47, 130, 45, 234, 119, 6, 90, 78, 182, 112, 206, 76, 118, 43, 75, 134, 20, 107, 147, 162, 20, 197, 116, 160, 119, 107, 117, 238, 116, 208, 115, 118, 144, 217, 146, 22, 156, 41, 107, 43, 21, 33, 50, 163, 127, 114, 254, 251, 166, 247, 223, 173, 242, 222, 203, 106, 14, 141, 114, 11, 145, 107, 217, 229, 253, 88, 187, 156, 153, 53, 233, 235, 255, 104, 141, 243, 146, 209, 33, 5, 109, 122, 72, 125, 240, 198, 131, 178, 14, 40, 8, 15, 182, 95, 153, 169, 71, 77, 166, 38, 182, 97, 97, 113, 13, 244, 173, 138, 80, 215, 215, 61, 107, 108, 157, 22, 35, 91, 244, 55, 213, 8, 142, 113, 44, 217, 52, 159, 206, 228, 171, 68, 42, 250, 78, 11, 24, 215, 112, 252, 24, 249, 97, 54, 80, 202, 164, 74, 194, 131, 133, 235, 88, 110, 81, 173, 211, 240, 68, 51, 191, 13, 187, 108, 44, 147, 18, 113, 30, 146, 253, 76, 235, 247, 30, 219, 167, 88, 32, 97, 53, 234, 221, 75, 94, 192, 236, 188, 169, 160, 56, 40, 146, 60, 61, 10, 62, 245, 10, 189, 184, 50, 43, 47, 133, 57, 0, 97, 80, 117, 6, 122, 207, 226, 253, 212, 48, 112, 14, 108, 166, 86, 199, 125, 89, 213, 185, 174, 186, 20, 157, 178, 78, 99, 169, 2, 191, 173, 197, 36, 191, 139, 107, 52, 154, 190, 88, 175, 63, 105, 218, 206, 230, 157, 22, 98, 107, 174, 214, 175, 127, 81, 166, 60, 215, 84, 44, 107, 57, 251, 21, 130, 170, 233, 172, 27, 234, 147, 227, 155, 125, 10, 111, 80, 57, 207, 203, 176, 77, 71, 151, 16, 215, 22, 165, 110, 228, 47, 92, 69, 145, 236, 118, 68, 84, 88, 35, 252, 241, 250, 119, 215, 203, 59, 50, 117, 225, 86, 2, 8, 137, 124, 30, 242, 99, 4, 171, 148, 68, 61, 55, 186, 55, 157, 9, 144, 147, 43, 252, 225, 171, 206, 190, 83, 207, 191, 68, 155, 227, 47, 140, 142, 45, 84, 188, 20} |
| 1069 |
|
| 1070 |
For i As Integer = 0 To bytData.Length - 1 |
| 1071 |
If i >= iOffset AndAlso (iLength = 0 OrElse i < iLength + iOffset) Then bytData(i) = CByte(bytData(i) Xor iRandomKey((i - iOffset) Mod 1024)) |
| 1072 |
Next |
| 1073 |
|
| 1074 |
End Sub |
| 1075 |
|
| 1076 |
|
| 1077 |
Private Function Decompress(ByVal bZLib As Byte(), ByVal bObfuscate As Boolean, Optional ByVal iOffset As Integer = 0, Optional ByVal iLength As Integer = 0) As MemoryStream |
| 1078 |
|
| 1079 |
If bObfuscate Then ObfuscateByteArray(bZLib, iOffset, iLength) |
| 1080 |
Dim outStream As New System.IO.MemoryStream |
| 1081 |
If iLength = 0 Then iLength = bZLib.Length - iOffset |
| 1082 |
Dim inStream As New System.IO.MemoryStream(bZLib, iOffset, iLength) |
| 1083 |
Using zStream As New ZLibStream(inStream, CompressionMode.Decompress) |
| 1084 |
zStream.CopyTo(outStream) |
| 1085 |
End Using |
| 1086 |
outStream.Position = 0 |
| 1087 |
Return outStream |
| 1088 |
End Function |
| 1089 |
|
| 1090 |
Private Function FileToMemoryStream(ByVal bCompressed As Boolean, ByVal iLength As Integer, ByVal bObfuscate As Boolean) As MemoryStream |
| 1091 |
|
| 1092 |
'ReDim bAdventure(-1) ' if this needs to be done, why here? |
| 1093 |
|
| 1094 |
If bCompressed Then |
| 1095 |
Dim bAdvZLib() As Byte = br.ReadBytes(iLength) |
| 1096 |
Return Decompress(bAdvZLib, bObfuscate) |
| 1097 |
Else |
| 1098 |
Return New MemoryStream(br.ReadBytes(iLength)) |
| 1099 |
End If |
| 1100 |
|
| 1101 |
End Function |
| 1102 |
|
| 1103 |
|
| 1104 |
' Grab the numeric part of the key (if any) and increment it |
| 1105 |
Private Function IncrementKey(ByVal sKey As String) As String |
| 1106 |
|
| 1107 |
Dim re As New System.Text.RegularExpressions.Regex("") |
| 1108 |
|
| 1109 |
Dim sJustKey As String = System.Text.RegularExpressions.Regex.Replace(sKey, "\d*$", "") |
| 1110 |
Dim sNumber As String = sKey.Replace(sJustKey, "") |
| 1111 |
If sNumber = "" Then sNumber = "0" |
| 1112 |
Dim iNumber As Integer = CInt(sNumber) |
| 1113 |
Return sJustKey & iNumber + 1 |
| 1114 |
|
| 1115 |
End Function |
| 1116 |
|
| 1117 |
Private Class LoadAbortException |
| 1118 |
Inherits Exception |
| 1119 |
End Class |
| 1120 |
|
| 1121 |
Private Enum LoadItemEum As Integer |
| 1122 |
No = 0 |
| 1123 |
Yes = 1 |
| 1124 |
Both = 2 |
| 1125 |
End Enum |
| 1126 |
Private Function ShouldWeLoadLibraryItem(ByVal sItemKey As String) As LoadItemEum |
| 1127 |
If Adventure.listExcludedItems.Contains(sItemKey) Then Return LoadItemEum.No |
| 1128 |
Return LoadItemEum.Yes |
| 1129 |
End Function |
| 1130 |
|
| 1131 |
|
| 1132 |
Private Sub SetChar(ByRef sText As String, ByVal iPos As Integer, ByVal Character As Char) |
| 1133 |
If iPos > sText.Length - 1 Then Exit Sub |
| 1134 |
sText = sLeft(sText, iPos) & Character & sRight(sText, sText.Length - iPos - 1) |
| 1135 |
End Sub |
| 1136 |
|
| 1137 |
|
| 1138 |
Private Function GetDate(ByVal sDate As String) As Date |
| 1139 |
|
| 1140 |
' Non UK locals save "yyyy-MM-dd HH:mm:ss" in their own format. Convert these for pre-5.0.22 saves |
| 1141 |
If dFileVersion < 5.000022 Then |
| 1142 |
If sDate.Length = 19 Then |
| 1143 |
SetChar(sDate, 13, ":"c) |
| 1144 |
SetChar(sDate, 16, ":"c) |
| 1145 |
End If |
| 1146 |
End If |
| 1147 |
|
| 1148 |
Dim dtReturn As Date |
| 1149 |
If Date.TryParse(sDate, dtReturn) Then Return dtReturn |
| 1150 |
|
| 1151 |
Return Date.MinValue |
| 1152 |
|
| 1153 |
End Function |
| 1154 |
|
| 1155 |
|
| 1156 |
' Corrects the bracket sequences for ORs after ANDs |
| 1157 |
Private Function CorrectBracketSequence(ByVal sSequence As String) As String |
| 1158 |
|
| 1159 |
If sSequence.Contains("#A#O#") Then |
| 1160 |
For i As Integer = 10 To 0 Step -1 |
| 1161 |
Dim sSearch As String = "#A#" |
| 1162 |
For j As Integer = 0 To i |
| 1163 |
sSearch &= "O#" |
| 1164 |
Next |
| 1165 |
While sSequence.Contains(sSearch) |
| 1166 |
Dim sReplace As String = "#A(#" |
| 1167 |
For j As Integer = 0 To i |
| 1168 |
sReplace &= "O#" |
| 1169 |
Next |
| 1170 |
sReplace &= ")" |
| 1171 |
sSequence = sSequence.Replace(sSearch, sReplace) |
| 1172 |
iCorrectedTasks += 1 |
| 1173 |
End While |
| 1174 |
Next |
| 1175 |
End If |
| 1176 |
|
| 1177 |
Return sSequence |
| 1178 |
|
| 1179 |
End Function |
| 1180 |
|
| 1181 |
|
| 1182 |
Private Function GetBool(ByVal sBool As String) As Boolean |
| 1183 |
|
| 1184 |
Select Case sBool.ToUpper |
| 1185 |
Case "0", "FALSE" |
| 1186 |
Return False |
| 1187 |
Case "-1", "1", "TRUE", "VRAI" |
| 1188 |
Return True |
| 1189 |
Case Else |
| 1190 |
Return False |
| 1191 |
End Select |
| 1192 |
|
| 1193 |
End Function |
| 1194 |
|
| 1195 |
|
| 1196 |
Dim bCorrectBracketSequences As Boolean = False |
| 1197 |
Dim bAskedAboutBrackets As Boolean = False |
| 1198 |
Dim iCorrectedTasks As Integer = 0 |
| 1199 |
|
| 1200 |
Private Function Load500(ByVal stmMemory As MemoryStream, ByVal bLibrary As Boolean, Optional ByVal bAppend As Boolean = False, Optional ByVal eLoadWhat As LoadWhatEnum = LoadWhatEnum.All, Optional ByVal dtAdvDate As Date = #1/1/1900#, Optional ByVal sFilename As String = "") As Boolean |
| 1201 |
Try |
| 1202 |
If stmMemory Is Nothing Then Return False |
| 1203 |
|
| 1204 |
Dim xmlDoc As New XmlDocument |
| 1205 |
xmlDoc.PreserveWhitespace = True |
| 1206 |
xmlDoc.Load(stmMemory) |
| 1207 |
Dim a As clsAdventure = Adventure |
| 1208 |
Dim bAddDuplicateKeys As Boolean = True |
| 1209 |
Dim htblDuplicateKeyMapping As New StringHashTable |
| 1210 |
Dim arlNewTasks As New StringArrayList |
| 1211 |
|
| 1212 |
With xmlDoc.Item("Adventure") |
| 1213 |
If .Item("Version") IsNot Nothing Then |
| 1214 |
dFileVersion = SafeDbl(.Item("Version").InnerText) |
| 1215 |
If dFileVersion > dVersion Then |
| 1216 |
Glue.MakeNote("This file is newer than what this software might understand.") |
| 1217 |
End If |
| 1218 |
If Not bLibrary Then a.dVersion = dFileVersion |
| 1219 |
Else |
| 1220 |
Throw New Exception("Version tag not specified") |
| 1221 |
End If |
| 1222 |
|
| 1223 |
If eLoadWhat = LoadWhatEnum.All Then |
| 1224 |
bAskedAboutBrackets = False |
| 1225 |
iCorrectedTasks = 0 |
| 1226 |
|
| 1227 |
If Not bLibrary AndAlso .Item("Title") IsNot Nothing Then a.Title = .Item("Title").InnerText |
| 1228 |
If Not bLibrary AndAlso .Item("Author") IsNot Nothing Then a.Author = .Item("Author").InnerText |
| 1229 |
If .Item("LastUpdated") IsNot Nothing Then a.LastUpdated = GetDate(.Item("LastUpdated").InnerText) |
| 1230 |
If Not .Item("Introduction") Is Nothing Then a.Introduction = LoadDescription(xmlDoc.Item("Adventure"), "Introduction") ' New Description(.Item("Introduction").InnerText) |
| 1231 |
If .Item("FontName") IsNot Nothing Then a.DefaultFontName = .Item("FontName").InnerText |
| 1232 |
If .Item("FontSize") IsNot Nothing Then a.DefaultFontSize = SafeInt(.Item("FontSize").InnerText) |
| 1233 |
If .Item("BackgroundColour") IsNot Nothing Then a.DeveloperDefaultBackgroundColour = CInt(.Item("BackgroundColour").InnerText) |
| 1234 |
If .Item("InputColour") IsNot Nothing Then a.DeveloperDefaultInputColour = CInt(.Item("InputColour").InnerText) |
| 1235 |
If .Item("OutputColour") IsNot Nothing Then a.DeveloperDefaultOutputColour = CInt(.Item("OutputColour").InnerText) |
| 1236 |
If .Item("LinkColour") IsNot Nothing Then a.DeveloperDefaultLinkColour = CInt(.Item("LinkColour").InnerText) |
| 1237 |
If .Item("ShowFirstLocation") IsNot Nothing Then a.ShowFirstRoom = GetBool(.Item("ShowFirstLocation").InnerText) |
| 1238 |
If .Item("UserStatus") IsNot Nothing Then a.sUserStatus = .Item("UserStatus").InnerText |
| 1239 |
If .Item("ifindex") IsNot Nothing Then Adventure.BabelTreatyInfo.FromString(.Item("ifindex").OuterXml) ' Pre 5.0.20 |
| 1240 |
If .Item("Cover") IsNot Nothing Then |
| 1241 |
Adventure.CoverFilename = .Item("Cover").InnerText |
| 1242 |
End If |
| 1243 |
If .Item("ShowExits") IsNot Nothing Then a.ShowExits = GetBool(.Item("ShowExits").InnerText) |
| 1244 |
If .Item("EnableMenu") IsNot Nothing Then a.EnableMenu = GetBool(.Item("EnableMenu").InnerText) |
| 1245 |
If .Item("EnableDebugger") IsNot Nothing Then a.EnableDebugger = GetBool(.Item("EnableDebugger").InnerText) |
| 1246 |
If .Item("EndGameText") IsNot Nothing Then a.WinningText = LoadDescription(xmlDoc.Item("Adventure"), "EndGameText") |
| 1247 |
If .Item("Elapsed") IsNot Nothing Then a.iElapsed = SafeInt(.Item("Elapsed").InnerText) |
| 1248 |
If .Item("TaskExecution") IsNot Nothing Then a.TaskExecution = CType([Enum].Parse(GetType(clsAdventure.TaskExecutionEnum), .Item("TaskExecution").InnerText), clsAdventure.TaskExecutionEnum) |
| 1249 |
If .Item("WaitTurns") IsNot Nothing Then a.WaitTurns = SafeInt(.Item("WaitTurns").InnerText) |
| 1250 |
If .Item("KeyPrefix") IsNot Nothing Then |
| 1251 |
a.KeyPrefix = .Item("KeyPrefix").InnerText |
| 1252 |
End If |
| 1253 |
|
| 1254 |
If .Item("DirectionNorth") IsNot Nothing AndAlso .Item("DirectionNorth").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.North) = .Item("DirectionNorth").InnerText |
| 1255 |
If .Item("DirectionNorthEast") IsNot Nothing AndAlso .Item("DirectionNorthEast").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.NorthEast) = .Item("DirectionNorthEast").InnerText |
| 1256 |
If .Item("DirectionEast") IsNot Nothing AndAlso .Item("DirectionEast").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.East) = .Item("DirectionEast").InnerText |
| 1257 |
If .Item("DirectionSouthEast") IsNot Nothing AndAlso .Item("DirectionSouthEast").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.SouthEast) = .Item("DirectionSouthEast").InnerText |
| 1258 |
If .Item("DirectionSouth") IsNot Nothing AndAlso .Item("DirectionSouth").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.South) = .Item("DirectionSouth").InnerText |
| 1259 |
If .Item("DirectionSouthWest") IsNot Nothing AndAlso .Item("DirectionSouthWest").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.SouthWest) = .Item("DirectionSouthWest").InnerText |
| 1260 |
If .Item("DirectionWest") IsNot Nothing AndAlso .Item("DirectionWest").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.West) = .Item("DirectionWest").InnerText |
| 1261 |
If .Item("DirectionNorthWest") IsNot Nothing AndAlso .Item("DirectionNorthWest").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.NorthWest) = .Item("DirectionNorthWest").InnerText |
| 1262 |
If .Item("DirectionIn") IsNot Nothing AndAlso .Item("DirectionIn").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.In) = .Item("DirectionIn").InnerText |
| 1263 |
If .Item("DirectionOut") IsNot Nothing AndAlso .Item("DirectionOut").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.Out) = .Item("DirectionOut").InnerText |
| 1264 |
If .Item("DirectionUp") IsNot Nothing AndAlso .Item("DirectionUp").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.Up) = .Item("DirectionUp").InnerText |
| 1265 |
If .Item("DirectionDown") IsNot Nothing AndAlso .Item("DirectionDown").InnerText <> "" Then a.sDirectionsRE(DirectionsEnum.Down) = .Item("DirectionDown").InnerText |
| 1266 |
|
| 1267 |
End If |
| 1268 |
|
| 1269 |
If eLoadWhat = LoadWhatEnum.All OrElse eLoadWhat = LoadWhatEnum.AllExceptProperties Then |
| 1270 |
Debug.WriteLine("End Intro: " & Now) |
| 1271 |
End If |
| 1272 |
|
| 1273 |
|
| 1274 |
If eLoadWhat = LoadWhatEnum.All OrElse eLoadWhat = LoadWhatEnum.Properies Then |
| 1275 |
' Properties |
| 1276 |
For Each nodProp As XmlElement In xmlDoc.SelectNodes("/Adventure/Property") |
| 1277 |
Dim prop As New clsProperty |
| 1278 |
With nodProp |
| 1279 |
Dim sKey As String = .Item("Key").InnerText |
| 1280 |
If .Item("Library") IsNot Nothing Then prop.IsLibrary = GetBool(.Item("Library").InnerText) |
| 1281 |
If a.htblAllProperties.ContainsKey(sKey) Then |
| 1282 |
If a.htblAllProperties.ContainsKey(sKey) Then |
| 1283 |
If prop.IsLibrary OrElse bLibrary Then |
| 1284 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblAllProperties(sKey).LastUpdated Then GoTo NextProp |
| 1285 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 1286 |
Case LoadItemEum.Yes |
| 1287 |
a.htblAllProperties.Remove(sKey) |
| 1288 |
Case LoadItemEum.No |
| 1289 |
GoTo NextProp |
| 1290 |
Case LoadItemEum.Both |
| 1291 |
' Keep key, but still add this new one |
| 1292 |
End Select |
| 1293 |
End If |
| 1294 |
End If |
| 1295 |
If bAddDuplicateKeys Then |
| 1296 |
While a.htblAllProperties.ContainsKey(sKey) |
| 1297 |
sKey = IncrementKey(sKey) |
| 1298 |
End While |
| 1299 |
Else |
| 1300 |
GoTo NextProp |
| 1301 |
End If |
| 1302 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 1303 |
GoTo NextProp |
| 1304 |
End If |
| 1305 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 1306 |
prop.Key = sKey |
| 1307 |
If bLibrary Then |
| 1308 |
prop.IsLibrary = True |
| 1309 |
prop.LoadedFromLibrary = True |
| 1310 |
End If |
| 1311 |
If Not .Item("LastUpdated") Is Nothing Then prop.LastUpdated = GetDate(.Item("LastUpdated").InnerText) |
| 1312 |
prop.Description = .Item("Description").InnerText |
| 1313 |
If Not .Item("Mandatory") Is Nothing Then |
| 1314 |
prop.Mandatory = GetBool(.Item("Mandatory").InnerText) |
| 1315 |
End If |
| 1316 |
If .Item("PropertyOf") IsNot Nothing Then prop.PropertyOf = EnumParsePropertyPropertyOf(.Item("PropertyOf").InnerText) |
| 1317 |
If .Item("AppendTo") IsNot Nothing Then prop.AppendToProperty = .Item("AppendTo").InnerText |
| 1318 |
prop.Type = EnumParsePropertyType(.Item("Type").InnerText) |
| 1319 |
Select Case prop.Type |
| 1320 |
Case clsProperty.PropertyTypeEnum.StateList |
| 1321 |
For Each nodState As XmlElement In nodProp.SelectNodes("State") |
| 1322 |
prop.arlStates.Add(nodState.InnerText) |
| 1323 |
Next |
| 1324 |
If prop.arlStates.Count > 0 Then prop.Value = prop.arlStates(0) |
| 1325 |
Case clsProperty.PropertyTypeEnum.ValueList |
| 1326 |
For Each nodValueList As XmlElement In nodProp.SelectNodes("ValueList") |
| 1327 |
If nodValueList.Item("Label") IsNot Nothing Then |
| 1328 |
Dim sLabel As String = nodValueList("Label").InnerText |
| 1329 |
Dim iValue As Integer = 0 |
| 1330 |
If nodValueList.Item("Value") IsNot Nothing Then iValue = SafeInt(nodValueList("Value").InnerText) |
| 1331 |
prop.ValueList.Add(sLabel, iValue) |
| 1332 |
End If |
| 1333 |
Next |
| 1334 |
End Select |
| 1335 |
If .Item("PrivateTo") IsNot Nothing Then prop.PrivateTo = .Item("PrivateTo").InnerText |
| 1336 |
If .Item("Tooltip") IsNot Nothing Then prop.PopupDescription = .Item("Tooltip").InnerText |
| 1337 |
|
| 1338 |
If Not .Item("DependentKey") Is Nothing Then |
| 1339 |
If .Item("DependentKey").InnerText <> sKey Then |
| 1340 |
prop.DependentKey = .Item("DependentKey").InnerText |
| 1341 |
If Not .Item("DependentValue") Is Nothing Then |
| 1342 |
prop.DependentValue = .Item("DependentValue").InnerText |
| 1343 |
End If |
| 1344 |
End If |
| 1345 |
End If |
| 1346 |
If Not .Item("RestrictProperty") Is Nothing Then |
| 1347 |
prop.RestrictProperty = .Item("RestrictProperty").InnerText |
| 1348 |
If Not .Item("RestrictValue") Is Nothing Then |
| 1349 |
prop.RestrictValue = .Item("RestrictValue").InnerText |
| 1350 |
End If |
| 1351 |
End If |
| 1352 |
End With |
| 1353 |
a.htblAllProperties.Add(prop) |
| 1354 |
NextProp: |
| 1355 |
Next |
| 1356 |
a.htblAllProperties.SetSelected() |
| 1357 |
Debug.WriteLine("End Properties: " & Now) |
| 1358 |
|
| 1359 |
CreateMandatoryProperties() |
| 1360 |
End If |
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
If eLoadWhat = LoadWhatEnum.All OrElse eLoadWhat = LoadWhatEnum.AllExceptProperties Then |
| 1365 |
' Locations |
| 1366 |
For Each nodLoc As XmlElement In xmlDoc.SelectNodes("/Adventure/Location") |
| 1367 |
Dim loc As New clsLocation |
| 1368 |
With nodLoc |
| 1369 |
Dim sKey As String = .Item("Key").InnerText |
| 1370 |
If Not .Item("Library") Is Nothing Then loc.IsLibrary = GetBool(.Item("Library").InnerText) |
| 1371 |
If a.htblLocations.ContainsKey(sKey) Then |
| 1372 |
If a.htblLocations.ContainsKey(sKey) Then |
| 1373 |
If loc.IsLibrary OrElse bLibrary Then |
| 1374 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblLocations(sKey).LastUpdated Then GoTo NextLoc |
| 1375 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 1376 |
Case LoadItemEum.Yes |
| 1377 |
a.htblLocations.Remove(sKey) |
| 1378 |
Case LoadItemEum.No |
| 1379 |
GoTo NextLoc |
| 1380 |
Case LoadItemEum.Both |
| 1381 |
' Keep key, but still add this new one |
| 1382 |
End Select |
| 1383 |
End If |
| 1384 |
End If |
| 1385 |
If bAddDuplicateKeys Then |
| 1386 |
While a.htblLocations.ContainsKey(sKey) |
| 1387 |
sKey = IncrementKey(sKey) |
| 1388 |
End While |
| 1389 |
Else |
| 1390 |
GoTo NextLoc |
| 1391 |
End If |
| 1392 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 1393 |
GoTo NextLoc |
| 1394 |
End If |
| 1395 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 1396 |
loc.Key = sKey |
| 1397 |
If bLibrary Then |
| 1398 |
loc.IsLibrary = True |
| 1399 |
loc.LoadedFromLibrary = True |
| 1400 |
End If |
| 1401 |
If Not .Item("LastUpdated") Is Nothing Then loc.LastUpdated = CDate(.Item("LastUpdated").InnerText) |
| 1402 |
If dFileVersion < 5.000015 Then |
| 1403 |
loc.ShortDescription = New Description(.Item("ShortDescription").InnerText) |
| 1404 |
Else |
| 1405 |
loc.ShortDescription = LoadDescription(nodLoc, "ShortDescription") |
| 1406 |
End If |
| 1407 |
loc.LongDescription = LoadDescription(nodLoc, "LongDescription") |
| 1408 |
|
| 1409 |
For Each nodDir As XmlElement In nodLoc.SelectNodes("Movement") |
| 1410 |
Dim xdir As DirectionsEnum = EnumParseDirections(nodDir.Item("Direction").InnerText) |
| 1411 |
|
| 1412 |
With loc.arlDirections(xdir) |
| 1413 |
.LocationKey = nodDir.Item("Destination").InnerText |
| 1414 |
.Restrictions = LoadRestrictions(nodDir) |
| 1415 |
End With |
| 1416 |
Next |
| 1417 |
For Each nodProp As XmlElement In .SelectNodes("Property") |
| 1418 |
Dim prop As New clsProperty |
| 1419 |
Dim sPropKey As String = nodProp.Item("Key").InnerText |
| 1420 |
If Adventure.htblAllProperties.ContainsKey(sPropKey) Then |
| 1421 |
prop = Adventure.htblAllProperties(sPropKey).Copy |
| 1422 |
If prop.Type = clsProperty.PropertyTypeEnum.Text Then |
| 1423 |
prop.StringData = LoadDescription(nodProp, "Value") |
| 1424 |
ElseIf prop.Type <> clsProperty.PropertyTypeEnum.SelectionOnly Then |
| 1425 |
prop.Value = nodProp.Item("Value").InnerText |
| 1426 |
End If |
| 1427 |
prop.Selected = True |
| 1428 |
loc.AddProperty(prop) |
| 1429 |
End If |
| 1430 |
Next |
| 1431 |
If .Item("Hide") IsNot Nothing Then loc.HideOnMap = GetBool(.Item("Hide").InnerText) |
| 1432 |
End With |
| 1433 |
a.htblLocations.Add(loc, loc.Key) |
| 1434 |
NextLoc: |
| 1435 |
Next nodLoc |
| 1436 |
Debug.WriteLine("End Locations: " & Now) |
| 1437 |
End If |
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
If eLoadWhat = LoadWhatEnum.All OrElse eLoadWhat = LoadWhatEnum.AllExceptProperties Then |
| 1442 |
' Objects |
| 1443 |
For Each nodOb As XmlElement In .SelectNodes("/Adventure/Object") |
| 1444 |
Dim ob As New clsObject |
| 1445 |
With nodOb |
| 1446 |
Dim sKey As String = .Item("Key").InnerText |
| 1447 |
If Not .Item("Library") Is Nothing Then ob.IsLibrary = GetBool(.Item("Library").InnerText) |
| 1448 |
If a.htblObjects.ContainsKey(sKey) Then |
| 1449 |
If a.htblObjects.ContainsKey(sKey) Then |
| 1450 |
If ob.IsLibrary OrElse bLibrary Then |
| 1451 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblObjects(sKey).LastUpdated Then GoTo NextOb |
| 1452 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 1453 |
Case LoadItemEum.Yes |
| 1454 |
a.htblObjects.Remove(sKey) |
| 1455 |
Case LoadItemEum.No |
| 1456 |
GoTo NextOb |
| 1457 |
Case LoadItemEum.Both |
| 1458 |
' Keep key, but still add this new one |
| 1459 |
End Select |
| 1460 |
End If |
| 1461 |
End If |
| 1462 |
If bAddDuplicateKeys Then |
| 1463 |
While a.htblObjects.ContainsKey(sKey) |
| 1464 |
sKey = IncrementKey(sKey) |
| 1465 |
End While |
| 1466 |
Else |
| 1467 |
GoTo NextOb |
| 1468 |
End If |
| 1469 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 1470 |
GoTo NextOb |
| 1471 |
End If |
| 1472 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 1473 |
ob.Key = sKey |
| 1474 |
If bLibrary Then |
| 1475 |
ob.IsLibrary = True |
| 1476 |
ob.LoadedFromLibrary = True |
| 1477 |
End If |
| 1478 |
If Not .Item("LastUpdated") Is Nothing Then ob.LastUpdated = CDate(.Item("LastUpdated").InnerText) |
| 1479 |
If .Item("Article") IsNot Nothing Then ob.Article = .Item("Article").InnerText |
| 1480 |
If .Item("Prefix") IsNot Nothing Then ob.Prefix = .Item("Prefix").InnerText |
| 1481 |
For Each nodName As XmlElement In .GetElementsByTagName("Name") |
| 1482 |
ob.arlNames.Add(nodName.InnerText) |
| 1483 |
Next |
| 1484 |
ob.Description = LoadDescription(nodOb, "Description") |
| 1485 |
|
| 1486 |
For Each nodProp As XmlElement In .SelectNodes("Property") |
| 1487 |
Dim prop As New clsProperty |
| 1488 |
Dim sPropKey As String = nodProp.Item("Key").InnerText |
| 1489 |
If Adventure.htblAllProperties.ContainsKey(sPropKey) Then |
| 1490 |
prop = Adventure.htblAllProperties(sPropKey).Copy |
| 1491 |
If prop.Type = clsProperty.PropertyTypeEnum.Text Then |
| 1492 |
prop.StringData = LoadDescription(nodProp, "Value") |
| 1493 |
ElseIf prop.Type <> clsProperty.PropertyTypeEnum.SelectionOnly Then |
| 1494 |
prop.Value = nodProp.Item("Value").InnerText |
| 1495 |
End If |
| 1496 |
prop.Selected = True |
| 1497 |
ob.AddProperty(prop) |
| 1498 |
End If |
| 1499 |
Next |
| 1500 |
ob.Location = ob.Location ' Assigns the location object from the object properties |
| 1501 |
End With |
| 1502 |
a.htblObjects.Add(ob, ob.Key) |
| 1503 |
NextOb: |
| 1504 |
Next |
| 1505 |
Debug.WriteLine("End Objects: " & Now) |
| 1506 |
|
| 1507 |
' Tasks |
| 1508 |
For Each nodTask As XmlElement In .SelectNodes("/Adventure/Task") |
| 1509 |
Dim tas As New clsTask |
| 1510 |
With nodTask |
| 1511 |
Dim sKey As String = .Item("Key").InnerText |
| 1512 |
If .Item("Library") IsNot Nothing Then tas.IsLibrary = GetBool(.Item("Library").InnerText) |
| 1513 |
If .Item("ReplaceTask") IsNot Nothing Then tas.ReplaceDuplicateKey = GetBool(.Item("ReplaceTask").InnerText) |
| 1514 |
If a.htblTasks.ContainsKey(sKey) Then |
| 1515 |
If tas.IsLibrary OrElse bLibrary Then |
| 1516 |
' We skip loading the task if it is not newer than the one we currently have loaded |
| 1517 |
' If there's no timestamp, we have to assume it is newer |
| 1518 |
If .Item("LastUpdated") IsNot Nothing AndAlso CDate(.Item("LastUpdated").InnerText) <= a.htblTasks(sKey).LastUpdated Then GoTo NextTask |
| 1519 |
' If a library item is newer than the library in your game, prompt |
| 1520 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 1521 |
Case LoadItemEum.Yes |
| 1522 |
a.htblTasks.Remove(sKey) |
| 1523 |
Case LoadItemEum.No |
| 1524 |
' Set the timestamp of the custom version to now, so it's more recent than the "newer" library. That way we won't be prompted next time |
| 1525 |
a.htblTasks(sKey).LastUpdated = Now |
| 1526 |
GoTo NextTask |
| 1527 |
Case LoadItemEum.Both |
| 1528 |
' Keep key, but still add this new one |
| 1529 |
End Select |
| 1530 |
End If |
| 1531 |
If tas.ReplaceDuplicateKey Then |
| 1532 |
If a.htblTasks.ContainsKey(sKey) Then a.htblTasks.Remove(sKey) |
| 1533 |
Else |
| 1534 |
If bAddDuplicateKeys Then |
| 1535 |
Dim sOldKey As String = sKey |
| 1536 |
While a.htblTasks.ContainsKey(sKey) |
| 1537 |
sKey = IncrementKey(sKey) |
| 1538 |
End While |
| 1539 |
htblDuplicateKeyMapping.Add(sOldKey, sKey) |
| 1540 |
Else |
| 1541 |
GoTo NextTask |
| 1542 |
End If |
| 1543 |
End If |
| 1544 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 1545 |
GoTo NextTask |
| 1546 |
End If |
| 1547 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 1548 |
tas.Key = sKey |
| 1549 |
tas.Priority = CInt(.Item("Priority").InnerText) |
| 1550 |
If bLibrary AndAlso Not tas.IsLibrary Then tas.Priority += 50000 |
| 1551 |
If bLibrary Then |
| 1552 |
tas.IsLibrary = True |
| 1553 |
tas.LoadedFromLibrary = True |
| 1554 |
End If |
| 1555 |
If Not .Item("LastUpdated") Is Nothing Then tas.LastUpdated = GetDate(.Item("LastUpdated").InnerText) |
| 1556 |
tas.Priority = CInt(.Item("Priority").InnerText) |
| 1557 |
If Not .Item("AutoFillPriority") Is Nothing Then tas.AutoFillPriority = CInt(.Item("AutoFillPriority").InnerText) |
| 1558 |
tas.TaskType = EnumParseTaskType(.Item("Type").InnerText) |
| 1559 |
tas.CompletionMessage = LoadDescription(nodTask, "CompletionMessage") |
| 1560 |
Select Case tas.TaskType |
| 1561 |
Case clsTask.TaskTypeEnum.General |
| 1562 |
For Each nodCommand As XmlElement In .GetElementsByTagName("Command") |
| 1563 |
' Simplify Runner so it only has to deal with multiple, or specific refs |
| 1564 |
tas.arlCommands.Add(FixInitialRefs(nodCommand.InnerText)) |
| 1565 |
Next |
| 1566 |
Case clsTask.TaskTypeEnum.Specific |
| 1567 |
tas.GeneralKey = .Item("GeneralTask").InnerText |
| 1568 |
Dim iSpecCount As Integer = 0 |
| 1569 |
ReDim tas.Specifics(-1) |
| 1570 |
For Each nodSpec As XmlElement In .GetElementsByTagName("Specific") |
| 1571 |
Dim spec As New clsTask.Specific |
| 1572 |
iSpecCount += 1 |
| 1573 |
spec.Type = EnumParseSpecificType(nodSpec.Item("Type").InnerText) |
| 1574 |
spec.Multiple = GetBool(nodSpec.Item("Multiple").InnerText) |
| 1575 |
For Each nodKey As XmlElement In nodSpec.GetElementsByTagName("Key") |
| 1576 |
spec.Keys.Add(nodKey.InnerText) |
| 1577 |
Next |
| 1578 |
ReDim Preserve tas.Specifics(iSpecCount - 1) |
| 1579 |
tas.Specifics(iSpecCount - 1) = spec |
| 1580 |
Next |
| 1581 |
If .Item("ExecuteParentActions") IsNot Nothing Then ' Old checkbox method |
| 1582 |
If GetBool(.Item("ExecuteParentActions").InnerText) Then |
| 1583 |
If tas.CompletionMessage.ToString(True) = "" Then |
| 1584 |
tas.SpecificOverrideType = clsTask.SpecificOverrideTypeEnum.BeforeTextAndActions |
| 1585 |
Else |
| 1586 |
tas.SpecificOverrideType = clsTask.SpecificOverrideTypeEnum.BeforeActionsOnly |
| 1587 |
End If |
| 1588 |
Else |
| 1589 |
If tas.CompletionMessage.ToString(True) = "" Then |
| 1590 |
tas.SpecificOverrideType = clsTask.SpecificOverrideTypeEnum.BeforeTextOnly |
| 1591 |
Else |
| 1592 |
tas.SpecificOverrideType = clsTask.SpecificOverrideTypeEnum.Override |
| 1593 |
End If |
| 1594 |
End If |
| 1595 |
End If |
| 1596 |
If .Item("SpecificOverrideType") IsNot Nothing Then |
| 1597 |
tas.SpecificOverrideType = CType([Enum].Parse(GetType(clsTask.SpecificOverrideTypeEnum), .Item("SpecificOverrideType").InnerText), clsTask.SpecificOverrideTypeEnum) |
| 1598 |
End If |
| 1599 |
Case clsTask.TaskTypeEnum.System |
| 1600 |
If .Item("RunImmediately") IsNot Nothing Then tas.RunImmediately = GetBool(.Item("RunImmediately").InnerText) |
| 1601 |
If .Item("LocationTrigger") IsNot Nothing Then tas.LocationTrigger = .Item("LocationTrigger").InnerText |
| 1602 |
End Select |
| 1603 |
tas.Description = .Item("Description").InnerText |
| 1604 |
tas.Repeatable = GetBool(.Item("Repeatable").InnerText) |
| 1605 |
If .Item("Aggregate") IsNot Nothing Then tas.AggregateOutput = GetBool(.Item("Aggregate").InnerText) |
| 1606 |
If .Item("Continue") IsNot Nothing Then |
| 1607 |
Select Case .Item("Continue").InnerText |
| 1608 |
Case "ContinueNever", "ContinueOnFail", "ContinueOnNoOutput" |
| 1609 |
tas.ContinueToExecuteLowerPriority = False |
| 1610 |
Case "ContinueAlways" |
| 1611 |
tas.ContinueToExecuteLowerPriority = True |
| 1612 |
End Select |
| 1613 |
End If |
| 1614 |
If .Item("LowPriority") IsNot Nothing Then tas.LowPriority = GetBool(.Item("LowPriority").InnerText) |
| 1615 |
tas.arlRestrictions = LoadRestrictions(nodTask) |
| 1616 |
tas.arlActions = LoadActions(nodTask) |
| 1617 |
tas.FailOverride = LoadDescription(nodTask, "FailOverride") |
| 1618 |
If Not .Item("MessageBeforeOrAfter") Is Nothing Then tas.eDisplayCompletion = EnumParseBeforeAfter(.Item("MessageBeforeOrAfter").InnerText) Else tas.eDisplayCompletion = clsTask.BeforeAfterEnum.Before |
| 1619 |
If .Item("PreventOverriding") IsNot Nothing Then tas.PreventOverriding = GetBool(.Item("PreventOverriding").InnerText) |
| 1620 |
End With |
| 1621 |
a.htblTasks.Add(tas, tas.Key) |
| 1622 |
arlNewTasks.Add(tas.Key) |
| 1623 |
NextTask: |
| 1624 |
Next |
| 1625 |
Debug.WriteLine("End Tasks: " & Now) |
| 1626 |
|
| 1627 |
|
| 1628 |
For Each nodEvent As XmlElement In .SelectNodes("/Adventure/Event") |
| 1629 |
Dim ev As New clsEvent |
| 1630 |
With nodEvent |
| 1631 |
Dim sKey As String = .Item("Key").InnerText |
| 1632 |
If .Item("Library") IsNot Nothing Then ev.IsLibrary = GetBool(.Item("Library").InnerText) |
| 1633 |
If a.htblEvents.ContainsKey(sKey) Then |
| 1634 |
If a.htblEvents.ContainsKey(sKey) Then |
| 1635 |
If ev.IsLibrary OrElse bLibrary Then |
| 1636 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblEvents(sKey).LastUpdated Then GoTo NextEvent |
| 1637 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 1638 |
Case LoadItemEum.Yes |
| 1639 |
a.htblEvents.Remove(sKey) |
| 1640 |
Case LoadItemEum.No |
| 1641 |
GoTo NextEvent |
| 1642 |
Case LoadItemEum.Both |
| 1643 |
' Keep key, but still add this new one |
| 1644 |
End Select |
| 1645 |
End If |
| 1646 |
End If |
| 1647 |
If bAddDuplicateKeys Then |
| 1648 |
While a.htblEvents.ContainsKey(sKey) |
| 1649 |
sKey = IncrementKey(sKey) |
| 1650 |
End While |
| 1651 |
Else |
| 1652 |
GoTo NextEvent |
| 1653 |
End If |
| 1654 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 1655 |
GoTo NextEvent |
| 1656 |
End If |
| 1657 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 1658 |
ev.Key = sKey |
| 1659 |
If bLibrary Then |
| 1660 |
ev.IsLibrary = True |
| 1661 |
ev.LoadedFromLibrary = True |
| 1662 |
End If |
| 1663 |
If Not .Item("LastUpdated") Is Nothing Then ev.LastUpdated = CDate(.Item("LastUpdated").InnerText) |
| 1664 |
If .Item("Type") IsNot Nothing Then ev.EventType = CType([Enum].Parse(GetType(clsEvent.EventTypeEnum), .Item("Type").InnerText), clsEvent.EventTypeEnum) |
| 1665 |
ev.Description = .Item("Description").InnerText |
| 1666 |
ev.WhenStart = CType([Enum].Parse(GetType(clsEvent.WhenStartEnum), .Item("WhenStart").InnerText), clsEvent.WhenStartEnum) |
| 1667 |
If .Item("Repeating") IsNot Nothing Then ev.Repeating = GetBool(.Item("Repeating").InnerText) |
| 1668 |
If .Item("RepeatCountdown") IsNot Nothing Then ev.RepeatCountdown = GetBool(.Item("RepeatCountdown").InnerText) |
| 1669 |
|
| 1670 |
Dim sData() As String |
| 1671 |
If .Item("StartDelay") IsNot Nothing Then |
| 1672 |
sData = .Item("StartDelay").InnerText.Split(" "c) |
| 1673 |
ev.StartDelay.iFrom = CInt(sData(0)) |
| 1674 |
If sData.Length = 1 Then |
| 1675 |
ev.StartDelay.iTo = CInt(sData(0)) |
| 1676 |
Else |
| 1677 |
ev.StartDelay.iTo = CInt(sData(2)) |
| 1678 |
End If |
| 1679 |
End If |
| 1680 |
sData = .Item("Length").InnerText.Split(" "c) |
| 1681 |
ev.Length.iFrom = CInt(sData(0)) |
| 1682 |
If sData.Length = 1 Then |
| 1683 |
ev.Length.iTo = CInt(sData(0)) |
| 1684 |
Else |
| 1685 |
ev.Length.iTo = CInt(sData(2)) |
| 1686 |
End If |
| 1687 |
|
| 1688 |
For Each nodCtrl As XmlElement In nodEvent.GetElementsByTagName("Control") |
| 1689 |
Dim ctrl As New EventOrWalkControl |
| 1690 |
sData = nodCtrl.InnerText.Split(" "c) |
| 1691 |
ctrl.eControl = CType([Enum].Parse(GetType(EventOrWalkControl.ControlEnum), sData(0)), EventOrWalkControl.ControlEnum) |
| 1692 |
ctrl.eCompleteOrNot = CType([Enum].Parse(GetType(EventOrWalkControl.CompleteOrNotEnum), sData(1)), EventOrWalkControl.CompleteOrNotEnum) |
| 1693 |
ctrl.sTaskKey = sData(2) |
| 1694 |
ReDim Preserve ev.EventControls(ev.EventControls.Length) |
| 1695 |
ev.EventControls(ev.EventControls.Length - 1) = ctrl |
| 1696 |
Next |
| 1697 |
|
| 1698 |
For Each nodSubEvent As XmlElement In nodEvent.GetElementsByTagName("SubEvent") |
| 1699 |
Dim se As New clsEvent.SubEvent(ev.Key) |
| 1700 |
sData = nodSubEvent.Item("When").InnerText.Split(" "c) |
| 1701 |
|
| 1702 |
se.ftTurns.iFrom = CInt(sData(0)) |
| 1703 |
If sData.Length = 4 Then |
| 1704 |
se.ftTurns.iTo = CInt(sData(2)) |
| 1705 |
se.eWhen = CType([Enum].Parse(GetType(clsEvent.SubEvent.WhenEnum), sData(3).ToString), clsEvent.SubEvent.WhenEnum) |
| 1706 |
Else |
| 1707 |
se.ftTurns.iTo = CInt(sData(0)) |
| 1708 |
se.eWhen = CType([Enum].Parse(GetType(clsEvent.SubEvent.WhenEnum), sData(1).ToString), clsEvent.SubEvent.WhenEnum) |
| 1709 |
End If |
| 1710 |
|
| 1711 |
If nodSubEvent.Item("Action") IsNot Nothing Then |
| 1712 |
If nodSubEvent.Item("Action").InnerXml.Contains("<Description>") Then |
| 1713 |
se.oDescription = LoadDescription(nodSubEvent, "Action") |
| 1714 |
Else |
| 1715 |
sData = nodSubEvent.Item("Action").InnerText.Split(" "c) |
| 1716 |
se.eWhat = CType([Enum].Parse(GetType(clsEvent.SubEvent.WhatEnum), sData(0).ToString), clsEvent.SubEvent.WhatEnum) |
| 1717 |
se.sKey = sData(1) |
| 1718 |
End If |
| 1719 |
End If |
| 1720 |
|
| 1721 |
If nodSubEvent.Item("Measure") IsNot Nothing Then se.eMeasure = EnumParseSubEventMeasure(nodSubEvent("Measure").InnerText) |
| 1722 |
If nodSubEvent.Item("What") IsNot Nothing Then se.eWhat = EnumParseSubEventWhat(nodSubEvent("What").InnerText) |
| 1723 |
If nodSubEvent.Item("OnlyApplyAt") IsNot Nothing Then se.sKey = nodSubEvent.Item("OnlyApplyAt").InnerText |
| 1724 |
|
| 1725 |
ReDim Preserve ev.SubEvents(ev.SubEvents.Length) |
| 1726 |
ev.SubEvents(ev.SubEvents.Length - 1) = se |
| 1727 |
Next |
| 1728 |
|
| 1729 |
End With |
| 1730 |
|
| 1731 |
a.htblEvents.Add(ev, ev.Key) |
| 1732 |
NextEvent: |
| 1733 |
Next |
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
For Each nodChar As XmlElement In .SelectNodes("/Adventure/Character") |
| 1738 |
Dim chr As New clsCharacter |
| 1739 |
With nodChar |
| 1740 |
Dim sKey As String = .Item("Key").InnerText |
| 1741 |
If Not .Item("Library") Is Nothing Then chr.IsLibrary = GetBool(.Item("Library").InnerText) |
| 1742 |
If a.htblCharacters.ContainsKey(sKey) Then |
| 1743 |
If a.htblCharacters.ContainsKey(sKey) Then |
| 1744 |
If chr.IsLibrary OrElse bLibrary Then |
| 1745 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblCharacters(sKey).LastUpdated Then GoTo NextChar |
| 1746 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 1747 |
Case LoadItemEum.Yes |
| 1748 |
a.htblCharacters.Remove(sKey) |
| 1749 |
Case LoadItemEum.No |
| 1750 |
GoTo NextChar |
| 1751 |
Case LoadItemEum.Both |
| 1752 |
' Keep key, but still add this new one |
| 1753 |
End Select |
| 1754 |
End If |
| 1755 |
End If |
| 1756 |
If bAddDuplicateKeys Then |
| 1757 |
While a.htblCharacters.ContainsKey(sKey) |
| 1758 |
sKey = IncrementKey(sKey) |
| 1759 |
End While |
| 1760 |
Else |
| 1761 |
GoTo NextChar |
| 1762 |
End If |
| 1763 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 1764 |
GoTo NextChar |
| 1765 |
End If |
| 1766 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 1767 |
chr.Key = sKey |
| 1768 |
If bLibrary Then |
| 1769 |
chr.IsLibrary = True |
| 1770 |
chr.LoadedFromLibrary = True |
| 1771 |
End If |
| 1772 |
If Not .Item("LastUpdated") Is Nothing Then chr.LastUpdated = GetDate(.Item("LastUpdated").InnerText) |
| 1773 |
If Not .Item("Name") Is Nothing Then chr.ProperName = .Item("Name").InnerText |
| 1774 |
If Not .Item("Article") Is Nothing Then chr.Article = .Item("Article").InnerText |
| 1775 |
If Not .Item("Prefix") Is Nothing Then chr.Prefix = .Item("Prefix").InnerText |
| 1776 |
If .Item("Perspective") IsNot Nothing Then chr.Perspective = CType([Enum].Parse(GetType(PerspectiveEnum), .Item("Perspective").InnerText), PerspectiveEnum) Else chr.Perspective = PerspectiveEnum.ThirdPerson |
| 1777 |
If dFileVersion < 5.00002 Then chr.Perspective = PerspectiveEnum.SecondPerson |
| 1778 |
For Each nodName As XmlElement In .GetElementsByTagName("Descriptor") |
| 1779 |
If nodName.InnerText <> "" Then chr.arlDescriptors.Add(nodName.InnerText) |
| 1780 |
Next |
| 1781 |
chr.Description = LoadDescription(nodChar, "Description") |
| 1782 |
For Each nodProp As XmlElement In .SelectNodes("Property") |
| 1783 |
Dim prop As New clsProperty |
| 1784 |
Dim sPropKey As String = nodProp.Item("Key").InnerText |
| 1785 |
If Adventure.htblAllProperties.ContainsKey(sPropKey) Then |
| 1786 |
prop = Adventure.htblAllProperties(sPropKey).Copy |
| 1787 |
If prop.Type = clsProperty.PropertyTypeEnum.Text Then |
| 1788 |
prop.StringData = LoadDescription(nodProp, "Value") |
| 1789 |
ElseIf prop.Type <> clsProperty.PropertyTypeEnum.SelectionOnly Then |
| 1790 |
prop.Value = nodProp.Item("Value").InnerText |
| 1791 |
End If |
| 1792 |
prop.Selected = True |
| 1793 |
chr.AddProperty(prop) |
| 1794 |
Else |
| 1795 |
ErrMsg("Error loading character " & chr.Name & ": Property " & sPropKey & " not found.") |
| 1796 |
End If |
| 1797 |
Next |
| 1798 |
|
| 1799 |
For Each nodWalk As XmlElement In .GetElementsByTagName("Walk") |
| 1800 |
Dim walk As New clsWalk |
| 1801 |
walk.sKey = sKey |
| 1802 |
walk.Description = nodWalk.Item("Description").InnerText |
| 1803 |
walk.Loops = GetBool(nodWalk.Item("Loops").InnerText) |
| 1804 |
walk.StartActive = GetBool(nodWalk.Item("StartActive").InnerText) |
| 1805 |
For Each nodStep As XmlElement In nodWalk.GetElementsByTagName("Step") |
| 1806 |
Dim [step] As New clsWalk.clsStep |
| 1807 |
Dim sData() As String = nodStep.InnerText.Split(" "c) |
| 1808 |
[step].sLocation = sData(0) |
| 1809 |
[step].ftTurns.iFrom = CInt(sData(1)) |
| 1810 |
If sData.Length = 2 Then |
| 1811 |
[step].ftTurns.iTo = CInt(sData(1)) |
| 1812 |
Else |
| 1813 |
[step].ftTurns.iTo = CInt(sData(3)) |
| 1814 |
End If |
| 1815 |
If dFileVersion < 5.000029 Then |
| 1816 |
If [step].sLocation = "%Player%" Then |
| 1817 |
If [step].ftTurns.iFrom < 1 Then [step].ftTurns.iFrom = 1 |
| 1818 |
If [step].ftTurns.iTo < 1 Then [step].ftTurns.iTo = 1 |
| 1819 |
End If |
| 1820 |
End If |
| 1821 |
walk.arlSteps.Add([step]) |
| 1822 |
Next |
| 1823 |
For Each nodCtrl As XmlElement In nodWalk.GetElementsByTagName("Control") |
| 1824 |
Dim ctrl As New EventOrWalkControl |
| 1825 |
Dim sData() As String = nodCtrl.InnerText.Split(" "c) |
| 1826 |
ctrl.eControl = CType([Enum].Parse(GetType(EventOrWalkControl.ControlEnum), sData(0)), EventOrWalkControl.ControlEnum) |
| 1827 |
ctrl.eCompleteOrNot = CType([Enum].Parse(GetType(EventOrWalkControl.CompleteOrNotEnum), sData(1)), EventOrWalkControl.CompleteOrNotEnum) |
| 1828 |
ctrl.sTaskKey = sData(2) |
| 1829 |
ReDim Preserve walk.WalkControls(walk.WalkControls.Length) |
| 1830 |
walk.WalkControls(walk.WalkControls.Length - 1) = ctrl |
| 1831 |
Next |
| 1832 |
For Each nodSubWalk As XmlElement In nodWalk.GetElementsByTagName("Activity") |
| 1833 |
Dim sw As New clsWalk.SubWalk |
| 1834 |
Dim sData() As String = nodSubWalk.Item("When").InnerText.Split(" "c) |
| 1835 |
If sData(0) = clsWalk.SubWalk.WhenEnum.ComesAcross.ToString Then |
| 1836 |
sw.eWhen = clsWalk.SubWalk.WhenEnum.ComesAcross |
| 1837 |
sw.sKey = sData(1) |
| 1838 |
Else |
| 1839 |
sw.ftTurns.iFrom = CInt(sData(0)) |
| 1840 |
If sData.Length = 4 Then |
| 1841 |
sw.ftTurns.iTo = CInt(sData(2)) |
| 1842 |
sw.eWhen = CType([Enum].Parse(GetType(clsWalk.SubWalk.WhenEnum), sData(3).ToString), clsWalk.SubWalk.WhenEnum) |
| 1843 |
Else |
| 1844 |
sw.ftTurns.iTo = CInt(sData(0)) |
| 1845 |
sw.eWhen = CType([Enum].Parse(GetType(clsWalk.SubWalk.WhenEnum), sData(1).ToString), clsWalk.SubWalk.WhenEnum) |
| 1846 |
End If |
| 1847 |
End If |
| 1848 |
|
| 1849 |
If nodSubWalk.Item("Action") IsNot Nothing Then |
| 1850 |
If nodSubWalk.Item("Action").InnerXml.Contains("<Description>") Then |
| 1851 |
sw.oDescription = LoadDescription(nodSubWalk, "Action") |
| 1852 |
Else |
| 1853 |
sData = nodSubWalk.Item("Action").InnerText.Split(" "c) |
| 1854 |
sw.eWhat = CType([Enum].Parse(GetType(clsWalk.SubWalk.WhatEnum), sData(0).ToString), clsWalk.SubWalk.WhatEnum) |
| 1855 |
sw.sKey2 = sData(1) |
| 1856 |
End If |
| 1857 |
End If |
| 1858 |
|
| 1859 |
If nodSubWalk.Item("OnlyApplyAt") IsNot Nothing Then sw.sKey3 = nodSubWalk.Item("OnlyApplyAt").InnerText |
| 1860 |
|
| 1861 |
ReDim Preserve walk.SubWalks(walk.SubWalks.Length) |
| 1862 |
walk.SubWalks(walk.SubWalks.Length - 1) = sw |
| 1863 |
Next |
| 1864 |
|
| 1865 |
chr.arlWalks.Add(walk) |
| 1866 |
Next |
| 1867 |
|
| 1868 |
For Each nodTopic As XmlElement In .GetElementsByTagName("Topic") |
| 1869 |
Dim topic As New clsTopic |
| 1870 |
topic.Key = nodTopic.Item("Key").InnerText |
| 1871 |
If nodTopic.Item("ParentKey") IsNot Nothing Then topic.ParentKey = nodTopic.Item("ParentKey").InnerText |
| 1872 |
topic.Summary = nodTopic.Item("Summary").InnerText |
| 1873 |
' Simplify Runner so it only has to deal with multiple, or specific refs |
| 1874 |
topic.Keywords = FixInitialRefs(nodTopic.Item("Keywords").InnerText) |
| 1875 |
|
| 1876 |
topic.oConversation = LoadDescription(nodTopic, "Description") |
| 1877 |
If nodTopic.Item("IsAsk") IsNot Nothing Then topic.bAsk = GetBool(nodTopic.Item("IsAsk").InnerText) |
| 1878 |
If nodTopic.Item("IsCommand") IsNot Nothing Then topic.bCommand = GetBool(nodTopic.Item("IsCommand").InnerText) |
| 1879 |
If nodTopic.Item("IsFarewell") IsNot Nothing Then topic.bFarewell = GetBool(nodTopic.Item("IsFarewell").InnerText) |
| 1880 |
If nodTopic.Item("IsIntro") IsNot Nothing Then topic.bIntroduction = GetBool(nodTopic.Item("IsIntro").InnerText) |
| 1881 |
If nodTopic.Item("IsTell") IsNot Nothing Then topic.bTell = GetBool(nodTopic.Item("IsTell").InnerText) |
| 1882 |
If nodTopic.Item("StayInNode") IsNot Nothing Then topic.bStayInNode = GetBool(nodTopic.Item("StayInNode").InnerText) |
| 1883 |
topic.arlRestrictions = LoadRestrictions(nodTopic) |
| 1884 |
topic.arlActions = LoadActions(nodTopic) |
| 1885 |
chr.htblTopics.Add(topic) |
| 1886 |
Next |
| 1887 |
|
| 1888 |
chr.Location = chr.Location ' Assigns the location object from the character properties |
| 1889 |
chr.CharacterType = EnumParseCharacterType(.Item("Type").InnerText) |
| 1890 |
End With |
| 1891 |
If eLoadWhat = LoadWhatEnum.All Then |
| 1892 |
a.htblCharacters.Add(chr, chr.Key) |
| 1893 |
Else |
| 1894 |
' Only add the Player character if we don't already have one |
| 1895 |
If chr.CharacterType = clsCharacter.CharacterTypeEnum.NonPlayer OrElse a.Player Is Nothing Then a.htblCharacters.Add(chr, chr.Key) |
| 1896 |
End If |
| 1897 |
For Each sCharFunction As String In New String() {"CharacterName", "DisplayCharacter", "ListHeld", "ListExits", "ListWorn", "LocationOf", "ParentOf", "ProperName"} |
| 1898 |
chr.SearchAndReplace("%" & sCharFunction & "%", "%" & sCharFunction & "[" & chr.Key & "]%") |
| 1899 |
Next |
| 1900 |
NextChar: |
| 1901 |
Next |
| 1902 |
Debug.WriteLine("End Chars: " & Now) |
| 1903 |
|
| 1904 |
End If |
| 1905 |
|
| 1906 |
If eLoadWhat = LoadWhatEnum.All OrElse eLoadWhat = LoadWhatEnum.Properies Then |
| 1907 |
For Each nodVar As XmlElement In .SelectNodes("/Adventure/Variable") |
| 1908 |
Dim var As New clsVariable |
| 1909 |
With nodVar |
| 1910 |
Dim sKey As String = .Item("Key").InnerText |
| 1911 |
If Not .Item("Library") Is Nothing Then var.IsLibrary = GetBool(.Item("Library").InnerText) |
| 1912 |
If a.htblVariables.ContainsKey(sKey) Then |
| 1913 |
If var.IsLibrary OrElse bLibrary Then |
| 1914 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblVariables(sKey).LastUpdated Then GoTo NextVar |
| 1915 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 1916 |
Case LoadItemEum.Yes |
| 1917 |
a.htblVariables.Remove(sKey) |
| 1918 |
Case LoadItemEum.No |
| 1919 |
GoTo NextVar |
| 1920 |
Case LoadItemEum.Both |
| 1921 |
' Keep key, but still add this new one |
| 1922 |
End Select |
| 1923 |
End If |
| 1924 |
If bAddDuplicateKeys Then |
| 1925 |
While a.htblVariables.ContainsKey(sKey) |
| 1926 |
sKey = IncrementKey(sKey) |
| 1927 |
End While |
| 1928 |
Else |
| 1929 |
GoTo NextVar |
| 1930 |
End If |
| 1931 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 1932 |
GoTo NextVar |
| 1933 |
End If |
| 1934 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 1935 |
var.Key = sKey |
| 1936 |
If bLibrary Then |
| 1937 |
var.IsLibrary = True |
| 1938 |
var.LoadedFromLibrary = True |
| 1939 |
End If |
| 1940 |
If Not .Item("LastUpdated") Is Nothing Then var.LastUpdated = GetDate(.Item("LastUpdated").InnerText) |
| 1941 |
var.Name = .Item("Name").InnerText |
| 1942 |
var.Type = EnumParseVariableType(.Item("Type").InnerText) |
| 1943 |
Dim sValue As String = .Item("InitialValue").InnerText |
| 1944 |
If Not .Item("ArrayLength") Is Nothing Then var.Length = CInt(Val(.Item("ArrayLength").InnerText)) |
| 1945 |
If var.Type = clsVariable.VariableTypeEnum.Text OrElse (var.Length > 1 AndAlso sValue.Contains(",")) Then |
| 1946 |
If var.Type = clsVariable.VariableTypeEnum.Numeric Then |
| 1947 |
Dim iValues() As String = Split(sValue, ",") |
| 1948 |
For iIndex As Integer = 1 To iValues.Length |
| 1949 |
var.IntValue(iIndex) = SafeInt(iValues(iIndex - 1)) |
| 1950 |
Next |
| 1951 |
var.StringValue = sValue |
| 1952 |
Else |
| 1953 |
For iIndex As Integer = 1 To var.Length |
| 1954 |
var.StringValue(iIndex) = sValue |
| 1955 |
Next |
| 1956 |
End If |
| 1957 |
|
| 1958 |
Else |
| 1959 |
For i As Integer = 1 To var.Length |
| 1960 |
var.IntValue(i) = CInt(Val(sValue)) |
| 1961 |
Next i |
| 1962 |
End If |
| 1963 |
End With |
| 1964 |
a.htblVariables.Add(var, var.Key) |
| 1965 |
NextVar: |
| 1966 |
Next |
| 1967 |
End If |
| 1968 |
|
| 1969 |
If eLoadWhat = LoadWhatEnum.All OrElse eLoadWhat = LoadWhatEnum.AllExceptProperties Then |
| 1970 |
For Each nodGroup As XmlElement In .SelectNodes("/Adventure/Group") |
| 1971 |
Dim grp As New clsGroup |
| 1972 |
With nodGroup |
| 1973 |
Dim sKey As String = .Item("Key").InnerText |
| 1974 |
If Not .Item("Library") Is Nothing Then grp.IsLibrary = GetBool(.Item("Library").InnerText) |
| 1975 |
If a.htblGroups.ContainsKey(sKey) Then |
| 1976 |
If grp.IsLibrary OrElse bLibrary Then |
| 1977 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblGroups(sKey).LastUpdated Then GoTo NextGroup |
| 1978 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 1979 |
Case LoadItemEum.Yes |
| 1980 |
a.htblGroups.Remove(sKey) |
| 1981 |
Case LoadItemEum.No |
| 1982 |
GoTo NextGroup |
| 1983 |
Case LoadItemEum.Both |
| 1984 |
' Keep key, but still add this new one |
| 1985 |
End Select |
| 1986 |
End If |
| 1987 |
If bAddDuplicateKeys Then |
| 1988 |
While a.htblGroups.ContainsKey(sKey) |
| 1989 |
sKey = IncrementKey(sKey) |
| 1990 |
End While |
| 1991 |
Else |
| 1992 |
GoTo NextGroup |
| 1993 |
End If |
| 1994 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 1995 |
GoTo NextGroup |
| 1996 |
End If |
| 1997 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 1998 |
grp.Key = sKey |
| 1999 |
If bLibrary Then |
| 2000 |
grp.IsLibrary = True |
| 2001 |
grp.LoadedFromLibrary = True |
| 2002 |
End If |
| 2003 |
If Not .Item("LastUpdated") Is Nothing Then grp.LastUpdated = GetDate(.Item("LastUpdated").InnerText) |
| 2004 |
grp.Name = .Item("Name").InnerText |
| 2005 |
grp.GroupType = EnumParseGroupType(.Item("Type").InnerText) |
| 2006 |
For Each nodMember As XmlElement In .GetElementsByTagName("Member") |
| 2007 |
grp.arlMembers.Add(nodMember.InnerText) |
| 2008 |
Next |
| 2009 |
For Each nodProp As XmlElement In .GetElementsByTagName("Property") |
| 2010 |
Dim prop As New clsProperty |
| 2011 |
Dim sPropKey As String = nodProp.Item("Key").InnerText |
| 2012 |
If Adventure.htblAllProperties.ContainsKey(sPropKey) Then |
| 2013 |
prop = Adventure.htblAllProperties(sPropKey).Copy |
| 2014 |
If nodProp.Item("Value") IsNot Nothing Then |
| 2015 |
If prop.Type = clsProperty.PropertyTypeEnum.Text Then |
| 2016 |
prop.StringData = LoadDescription(nodProp, "Value") |
| 2017 |
ElseIf prop.Type <> clsProperty.PropertyTypeEnum.SelectionOnly Then |
| 2018 |
prop.Value = nodProp.Item("Value").InnerText |
| 2019 |
End If |
| 2020 |
End If |
| 2021 |
prop.Selected = True |
| 2022 |
If prop.PropertyOf = grp.GroupType Then |
| 2023 |
grp.htblProperties.Add(prop) |
| 2024 |
End If |
| 2025 |
Else |
| 2026 |
ErrMsg("Error loading group " & grp.Name & ": Property " & sPropKey & " not found.") |
| 2027 |
End If |
| 2028 |
Next |
| 2029 |
End With |
| 2030 |
a.htblGroups.Add(grp, grp.Key) |
| 2031 |
|
| 2032 |
For Each sMember As String In grp.arlMembers |
| 2033 |
Dim itm As clsItemWithProperties = CType(Adventure.GetItemFromKey(sMember), clsItemWithProperties) |
| 2034 |
If itm IsNot Nothing Then itm.ResetInherited() ' In case we've accessed properties, and built inherited before the group existed |
| 2035 |
Next |
| 2036 |
NextGroup: |
| 2037 |
Next |
| 2038 |
|
| 2039 |
|
| 2040 |
For Each nodALR As XmlElement In .SelectNodes("/Adventure/TextOverride") |
| 2041 |
Dim alr As New clsALR |
| 2042 |
With nodALR |
| 2043 |
Dim sKey As String = .Item("Key").InnerText |
| 2044 |
If .Item("Library") IsNot Nothing Then alr.IsLibrary = GetBool(.Item("Library").InnerText) |
| 2045 |
If a.htblALRs.ContainsKey(sKey) Then |
| 2046 |
If alr.IsLibrary OrElse bLibrary Then |
| 2047 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblALRs(sKey).LastUpdated Then GoTo NextALR |
| 2048 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 2049 |
Case LoadItemEum.Yes |
| 2050 |
a.htblALRs.Remove(sKey) |
| 2051 |
Case LoadItemEum.No |
| 2052 |
GoTo NextALR |
| 2053 |
Case LoadItemEum.Both |
| 2054 |
' Keep key, but still add this new one |
| 2055 |
End Select |
| 2056 |
End If |
| 2057 |
If bAddDuplicateKeys Then |
| 2058 |
While a.htblALRs.ContainsKey(sKey) |
| 2059 |
sKey = IncrementKey(sKey) |
| 2060 |
End While |
| 2061 |
Else |
| 2062 |
GoTo NextALR |
| 2063 |
End If |
| 2064 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 2065 |
GoTo NextALR |
| 2066 |
End If |
| 2067 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 2068 |
alr.Key = sKey |
| 2069 |
If bLibrary Then |
| 2070 |
alr.IsLibrary = True |
| 2071 |
alr.LoadedFromLibrary = True |
| 2072 |
End If |
| 2073 |
If Not .Item("LastUpdated") Is Nothing Then alr.LastUpdated = CDate(.Item("LastUpdated").InnerText) |
| 2074 |
alr.OldText = CStr(.Item("OldText").InnerText) |
| 2075 |
alr.NewText = LoadDescription(nodALR, "NewText") |
| 2076 |
End With |
| 2077 |
a.htblALRs.Add(alr, alr.Key) |
| 2078 |
NextALR: |
| 2079 |
Next |
| 2080 |
|
| 2081 |
For Each nodHint As XmlElement In .SelectNodes("/Adventure/Hint") |
| 2082 |
Dim hint As New clsHint |
| 2083 |
With nodHint |
| 2084 |
Dim sKey As String = .Item("Key").InnerText |
| 2085 |
If .Item("Library") IsNot Nothing Then hint.IsLibrary = GetBool(.Item("Library").InnerText) |
| 2086 |
If a.htblHints.ContainsKey(sKey) Then |
| 2087 |
If hint.IsLibrary OrElse bLibrary Then |
| 2088 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblHints(sKey).LastUpdated Then GoTo NextHint |
| 2089 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 2090 |
Case LoadItemEum.Yes |
| 2091 |
a.htblHints.Remove(sKey) |
| 2092 |
Case LoadItemEum.No |
| 2093 |
GoTo NextHint |
| 2094 |
Case LoadItemEum.Both |
| 2095 |
' Keep key, but still add this new one |
| 2096 |
End Select |
| 2097 |
End If |
| 2098 |
If bAddDuplicateKeys Then |
| 2099 |
While a.htblHints.ContainsKey(sKey) |
| 2100 |
sKey = IncrementKey(sKey) |
| 2101 |
End While |
| 2102 |
Else |
| 2103 |
GoTo NextHint |
| 2104 |
End If |
| 2105 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 2106 |
GoTo NextHint |
| 2107 |
End If |
| 2108 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 2109 |
hint.Key = sKey |
| 2110 |
If bLibrary Then |
| 2111 |
hint.IsLibrary = True |
| 2112 |
hint.LoadedFromLibrary = True |
| 2113 |
End If |
| 2114 |
If Not .Item("LastUpdated") Is Nothing Then hint.LastUpdated = CDate(.Item("LastUpdated").InnerText) |
| 2115 |
hint.Question = CStr(.Item("Question").InnerText) |
| 2116 |
hint.SubtleHint = LoadDescription(nodHint, "Subtle") |
| 2117 |
hint.SledgeHammerHint = LoadDescription(nodHint, "Sledgehammer") |
| 2118 |
hint.arlRestrictions = LoadRestrictions(nodHint) |
| 2119 |
End With |
| 2120 |
a.htblHints.Add(hint, hint.Key) |
| 2121 |
NextHint: |
| 2122 |
Next |
| 2123 |
|
| 2124 |
For Each nodSynonym As XmlElement In .SelectNodes("/Adventure/Synonym") |
| 2125 |
Dim synonym As New clsSynonym |
| 2126 |
With nodSynonym |
| 2127 |
Dim sKey As String = .Item("Key").InnerText |
| 2128 |
If .Item("Library") IsNot Nothing Then synonym.IsLibrary = GetBool(.Item("Library").InnerText) |
| 2129 |
If a.htblSynonyms.ContainsKey(sKey) Then |
| 2130 |
If synonym.IsLibrary OrElse bLibrary Then |
| 2131 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblSynonyms(sKey).LastUpdated Then GoTo NextSynonym |
| 2132 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 2133 |
Case LoadItemEum.Yes |
| 2134 |
a.htblSynonyms.Remove(sKey) |
| 2135 |
Case LoadItemEum.No |
| 2136 |
GoTo NextSynonym |
| 2137 |
Case LoadItemEum.Both |
| 2138 |
' Keep key, but still add this new one |
| 2139 |
End Select |
| 2140 |
End If |
| 2141 |
|
| 2142 |
If bAddDuplicateKeys Then |
| 2143 |
While a.htblSynonyms.ContainsKey(sKey) |
| 2144 |
sKey = IncrementKey(sKey) |
| 2145 |
End While |
| 2146 |
Else |
| 2147 |
GoTo NextSynonym |
| 2148 |
End If |
| 2149 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 2150 |
GoTo NextSynonym |
| 2151 |
End If |
| 2152 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 2153 |
synonym.Key = sKey |
| 2154 |
If bLibrary Then |
| 2155 |
synonym.IsLibrary = True |
| 2156 |
synonym.LoadedFromLibrary = True |
| 2157 |
End If |
| 2158 |
If Not .Item("LastUpdated") Is Nothing Then synonym.LastUpdated = CDate(.Item("LastUpdated").InnerText) |
| 2159 |
|
| 2160 |
For Each nodFrom As XmlElement In .GetElementsByTagName("From") |
| 2161 |
synonym.ChangeFrom.Add(nodFrom.InnerText) |
| 2162 |
Next |
| 2163 |
synonym.ChangeTo = .Item("To").InnerText |
| 2164 |
End With |
| 2165 |
a.htblSynonyms.Add(synonym) |
| 2166 |
NextSynonym: |
| 2167 |
Next |
| 2168 |
|
| 2169 |
|
| 2170 |
For Each nodUDF As XmlElement In .SelectNodes("/Adventure/Function") |
| 2171 |
Dim udf As New clsUserFunction |
| 2172 |
With nodUDF |
| 2173 |
Dim sKey As String = .Item("Key").InnerText |
| 2174 |
If .Item("Library") IsNot Nothing Then udf.IsLibrary = GetBool(.Item("Library").InnerText) |
| 2175 |
If a.htblUDFs.ContainsKey(sKey) Then |
| 2176 |
If udf.IsLibrary OrElse bLibrary Then |
| 2177 |
If .Item("LastUpdated") Is Nothing OrElse CDate(.Item("LastUpdated").InnerText) <= a.htblUDFs(sKey).LastUpdated Then GoTo NextUDF |
| 2178 |
Select Case ShouldWeLoadLibraryItem(sKey) |
| 2179 |
Case LoadItemEum.Yes |
| 2180 |
a.htblUDFs.Remove(sKey) |
| 2181 |
Case LoadItemEum.No |
| 2182 |
GoTo NextUDF |
| 2183 |
Case LoadItemEum.Both |
| 2184 |
' Keep key, but still add this new one |
| 2185 |
End Select |
| 2186 |
End If |
| 2187 |
If bAddDuplicateKeys Then |
| 2188 |
While a.htblUDFs.ContainsKey(sKey) |
| 2189 |
sKey = IncrementKey(sKey) |
| 2190 |
End While |
| 2191 |
Else |
| 2192 |
GoTo NextUDF |
| 2193 |
End If |
| 2194 |
ElseIf bLibrary AndAlso ShouldWeLoadLibraryItem(sKey) = LoadItemEum.No Then |
| 2195 |
GoTo NextUDF |
| 2196 |
End If |
| 2197 |
If a.listExcludedItems.Contains(sKey) Then a.listExcludedItems.Remove(sKey) |
| 2198 |
udf.Key = sKey |
| 2199 |
If bLibrary Then |
| 2200 |
udf.IsLibrary = True |
| 2201 |
udf.LoadedFromLibrary = True |
| 2202 |
End If |
| 2203 |
If Not .Item("LastUpdated") Is Nothing Then udf.LastUpdated = CDate(.Item("LastUpdated").InnerText) |
| 2204 |
|
| 2205 |
udf.Name = CStr(.Item("Name").InnerText) |
| 2206 |
udf.Output = LoadDescription(nodUDF, "Output") |
| 2207 |
For Each nodArgument As XmlElement In .GetElementsByTagName("Argument") |
| 2208 |
With nodArgument |
| 2209 |
Dim arg As New clsUserFunction.Argument |
| 2210 |
arg.Name = .Item("Name").InnerText |
| 2211 |
arg.Type = CType([Enum].Parse(GetType(clsUserFunction.ArgumentType), .Item("Type").InnerText), clsUserFunction.ArgumentType) |
| 2212 |
udf.Arguments.Add(arg) |
| 2213 |
End With |
| 2214 |
Next |
| 2215 |
|
| 2216 |
End With |
| 2217 |
a.htblUDFs.Add(udf, udf.Key) |
| 2218 |
NextUDF: |
| 2219 |
Next |
| 2220 |
|
| 2221 |
If Not bLibrary Then |
| 2222 |
For Each nodExclude As XmlElement In .SelectNodes("/Adventure/Exclude") |
| 2223 |
a.listExcludedItems.Add(nodExclude.InnerText) |
| 2224 |
Next |
| 2225 |
End If |
| 2226 |
|
| 2227 |
If Not bLibrary Then |
| 2228 |
If .Item("Map") IsNot Nothing Then |
| 2229 |
Adventure.Map.Pages.Clear() |
| 2230 |
For Each nodPage As XmlElement In .SelectNodes("/Adventure/Map/Page") |
| 2231 |
With nodPage |
| 2232 |
Dim sPageKey As String = .Item("Key").InnerText |
| 2233 |
If IsNumeric(sPageKey) Then |
| 2234 |
Dim page As New MapPage(SafeInt(sPageKey)) |
| 2235 |
If .Item("Label") IsNot Nothing Then page.Label = .Item("Label").InnerText |
| 2236 |
If .Item("Selected") IsNot Nothing AndAlso GetBool(.Item("Selected").InnerText) Then Adventure.Map.SelectedPage = sPageKey |
| 2237 |
For Each nodNode As XmlElement In .GetElementsByTagName("Node") |
| 2238 |
With nodNode |
| 2239 |
Dim node As New MapNode |
| 2240 |
If .Item("Key") IsNot Nothing Then node.Key = .Item("Key").InnerText |
| 2241 |
Dim loc As clsLocation = Adventure.htblLocations(node.Key) |
| 2242 |
If loc IsNot Nothing Then |
| 2243 |
node.Text = loc.ShortDescriptionSafe ' StripCarats(ReplaceALRs(loc.ShortDescription.ToString)) |
| 2244 |
If .Item("X") IsNot Nothing Then node.Location.X = SafeInt(.Item("X").InnerText) |
| 2245 |
If .Item("Y") IsNot Nothing Then node.Location.Y = SafeInt(.Item("Y").InnerText) |
| 2246 |
If .Item("Z") IsNot Nothing Then node.Location.Z = SafeInt(.Item("Z").InnerText) |
| 2247 |
If .Item("Height") IsNot Nothing Then node.Height = SafeInt(.Item("Height").InnerText) Else node.Height = 4 |
| 2248 |
If .Item("Width") IsNot Nothing Then node.Width = SafeInt(.Item("Width").InnerText) Else node.Width = 6 |
| 2249 |
|
| 2250 |
If loc.arlDirections(DirectionsEnum.Up).LocationKey IsNot Nothing Then node.bHasUp = True |
| 2251 |
If loc.arlDirections(DirectionsEnum.Down).LocationKey IsNot Nothing Then node.bHasDown = True |
| 2252 |
If loc.arlDirections(DirectionsEnum.In).LocationKey IsNot Nothing Then node.bHasIn = True |
| 2253 |
If loc.arlDirections(DirectionsEnum.Out).LocationKey IsNot Nothing Then node.bHasOut = True |
| 2254 |
|
| 2255 |
For Each nodLink As XmlElement In .GetElementsByTagName("Link") |
| 2256 |
With nodLink |
| 2257 |
Dim link As New MapLink |
| 2258 |
link.sSource = node.Key |
| 2259 |
If .Item("SourceAnchor") IsNot Nothing Then link.eSourceLinkPoint = CType([Enum].Parse(GetType(DirectionsEnum), .Item("SourceAnchor").InnerText), DirectionsEnum) |
| 2260 |
link.sDestination = loc.arlDirections(link.eSourceLinkPoint).LocationKey |
| 2261 |
If Adventure.Map.DottedLink(loc.arlDirections(link.eSourceLinkPoint)) Then |
| 2262 |
link.Style = DashStyles.Dot |
| 2263 |
Else |
| 2264 |
link.Style = DashStyles.Solid |
| 2265 |
End If |
| 2266 |
If .Item("DestinationAnchor") IsNot Nothing Then link.eDestinationLinkPoint = CType([Enum].Parse(GetType(DirectionsEnum), .Item("DestinationAnchor").InnerText), DirectionsEnum) |
| 2267 |
Dim sDest As String = loc.arlDirections(link.eSourceLinkPoint).LocationKey |
| 2268 |
If sDest IsNot Nothing AndAlso Adventure.htblLocations.ContainsKey(sDest) Then |
| 2269 |
Dim locDest As clsLocation = Adventure.htblLocations(sDest) |
| 2270 |
If locDest IsNot Nothing Then |
| 2271 |
If locDest.arlDirections(link.eDestinationLinkPoint).LocationKey = loc.Key Then |
| 2272 |
link.Duplex = True |
| 2273 |
If Adventure.Map.DottedLink(locDest.arlDirections(link.eDestinationLinkPoint)) Then link.Style = DashStyles.Dot |
| 2274 |
End If |
| 2275 |
End If |
| 2276 |
End If |
| 2277 |
For Each nodAnchor As XmlElement In .GetElementsByTagName("Anchor") |
| 2278 |
Dim p As New Point3D |
| 2279 |
With nodAnchor |
| 2280 |
If .Item("X") IsNot Nothing Then p.X = SafeInt(.Item("X").InnerText) |
| 2281 |
If .Item("Y") IsNot Nothing Then p.Y = SafeInt(.Item("Y").InnerText) |
| 2282 |
If .Item("Z") IsNot Nothing Then p.Z = SafeInt(.Item("Z").InnerText) |
| 2283 |
End With |
| 2284 |
ReDim Preserve link.OrigMidPoints(link.OrigMidPoints.Length) |
| 2285 |
link.OrigMidPoints(link.OrigMidPoints.Length - 1) = p |
| 2286 |
Dim ar As New Anchor |
| 2287 |
ar.Visible = True |
| 2288 |
ar.Parent = link |
| 2289 |
link.Anchors.Add(ar) |
| 2290 |
Next |
| 2291 |
node.Links.Add(link.eSourceLinkPoint, link) |
| 2292 |
End With |
| 2293 |
Next |
| 2294 |
|
| 2295 |
node.Page = page.iKey |
| 2296 |
page.AddNode(node) |
| 2297 |
End If |
| 2298 |
End With |
| 2299 |
Next |
| 2300 |
Adventure.Map.Pages.Add(page.iKey, page) |
| 2301 |
Adventure.Map.Pages(page.iKey).SortNodes() |
| 2302 |
End If |
| 2303 |
End With |
| 2304 |
Next |
| 2305 |
End If |
| 2306 |
End If |
| 2307 |
|
| 2308 |
' Now fix any remapped keys |
| 2309 |
' This must only remap our newly imported tasks, not all the original ones! |
| 2310 |
' |
| 2311 |
For Each sOldKey As String In htblDuplicateKeyMapping.Keys |
| 2312 |
For Each sTask As String In arlNewTasks |
| 2313 |
Dim tas As clsTask = a.htblTasks(sTask) |
| 2314 |
If tas.GeneralKey = sOldKey Then tas.GeneralKey = htblDuplicateKeyMapping(sOldKey) |
| 2315 |
For Each act As clsAction In tas.arlActions |
| 2316 |
If act.sKey1 = sOldKey Then act.sKey1 = htblDuplicateKeyMapping(sOldKey) |
| 2317 |
If act.sKey2 = sOldKey Then act.sKey2 = htblDuplicateKeyMapping(sOldKey) |
| 2318 |
Next |
| 2319 |
Next |
| 2320 |
Next |
| 2321 |
|
| 2322 |
Adventure.BlorbMappings.Clear() |
| 2323 |
If .Item("FileMappings") IsNot Nothing Then |
| 2324 |
For Each nodMapping As XmlElement In .SelectNodes("/Adventure/FileMappings/Mapping") |
| 2325 |
With nodMapping |
| 2326 |
Dim iResource As Integer = SafeInt(.Item("Resource").InnerText) |
| 2327 |
Dim sFile As String = .Item("File").InnerText |
| 2328 |
Adventure.BlorbMappings.Add(sFile, iResource) |
| 2329 |
End With |
| 2330 |
Next |
| 2331 |
End If |
| 2332 |
|
| 2333 |
End If |
| 2334 |
|
| 2335 |
End With |
| 2336 |
|
| 2337 |
' Correct any old style functions |
| 2338 |
' Player.Held.Weight > Player.Held.Weight.Sum |
| 2339 |
If Not bLibrary AndAlso dFileVersion < 5.0000311 Then |
| 2340 |
For Each sd As SingleDescription In Adventure.AllDescriptions |
| 2341 |
For Each p As clsProperty In Adventure.htblAllProperties.Values |
| 2342 |
If p.Type = clsProperty.PropertyTypeEnum.Integer OrElse p.Type = clsProperty.PropertyTypeEnum.ValueList Then |
| 2343 |
If sd.Description.Contains("." & p.Key) Then |
| 2344 |
sd.Description = sd.Description.Replace("." & p.Key, "." & p.Key & ".Sum") |
| 2345 |
End If |
| 2346 |
End If |
| 2347 |
Next |
| 2348 |
Next |
| 2349 |
End If |
| 2350 |
|
| 2351 |
|
| 2352 |
If eLoadWhat = LoadWhatEnum.All AndAlso iCorrectedTasks > 0 Then |
| 2353 |
Glue.ShowInfo(iCorrectedTasks & " tasks have been updated.", "Adventure Upgrade") |
| 2354 |
End If |
| 2355 |
|
| 2356 |
With Adventure |
| 2357 |
If .Map.Pages.Count = 1 AndAlso .Map.Pages.ContainsKey(0) AndAlso .Map.Pages(0).Nodes.Count = 0 Then |
| 2358 |
.Map = New clsMap |
| 2359 |
.Map.RecalculateLayout() |
| 2360 |
End If |
| 2361 |
End With |
| 2362 |
dFileVersion = dVersion ' Set back to current version so copy/paste etc has correct versions |
| 2363 |
|
| 2364 |
Return True |
| 2365 |
|
| 2366 |
Catch exLAE As LoadAbortException |
| 2367 |
' Ignore |
| 2368 |
Return False |
| 2369 |
Catch exXML As XmlException |
| 2370 |
If bLibrary Then |
| 2371 |
ErrMsg("The file '" & sFilename & "' you are trying to load is not a valid ADRIFT Module.", exXML) |
| 2372 |
Else |
| 2373 |
ErrMsg("Error loading Adventure", exXML) |
| 2374 |
End If |
| 2375 |
Catch ex As Exception |
| 2376 |
If ex.Message.Contains("Root element is missing") Then |
| 2377 |
ErrMsg("The file you are trying to load is not a valid ADRIFT v5.0 file.") |
| 2378 |
Else |
| 2379 |
ErrMsg("Error loading Adventure", ex) |
| 2380 |
End If |
| 2381 |
Return False |
| 2382 |
End Try |
| 2383 |
|
| 2384 |
End Function |
| 2385 |
|
| 2386 |
Friend Sub CreateMandatoryProperties() |
| 2387 |
For Each sKey As String In New String() {OBJECTARTICLE, OBJECTPREFIX, OBJECTNOUN} |
| 2388 |
If Not Adventure.htblObjectProperties.ContainsKey(sKey) Then |
| 2389 |
Dim prop As New clsProperty |
| 2390 |
With prop |
| 2391 |
.Key = sKey |
| 2392 |
Select Case .Key |
| 2393 |
Case OBJECTARTICLE |
| 2394 |
.Description = "Object Article" |
| 2395 |
Case OBJECTPREFIX |
| 2396 |
.Description = "Object Prefix" |
| 2397 |
Case OBJECTNOUN |
| 2398 |
.Description = "Object Name" |
| 2399 |
End Select |
| 2400 |
.PropertyOf = clsProperty.PropertyOfEnum.Objects |
| 2401 |
.Type = clsProperty.PropertyTypeEnum.Text |
| 2402 |
End With |
| 2403 |
Adventure.htblAllProperties.Add(prop) |
| 2404 |
End If |
| 2405 |
Adventure.htblObjectProperties(sKey).GroupOnly = True |
| 2406 |
Next |
| 2407 |
|
| 2408 |
If Not Adventure.htblLocationProperties.ContainsKey(SHORTLOCATIONDESCRIPTION) Then |
| 2409 |
Dim prop As New clsProperty |
| 2410 |
With prop |
| 2411 |
.Key = SHORTLOCATIONDESCRIPTION |
| 2412 |
.Description = "Short Location Description" |
| 2413 |
.PropertyOf = clsProperty.PropertyOfEnum.Locations |
| 2414 |
.Type = clsProperty.PropertyTypeEnum.Text |
| 2415 |
End With |
| 2416 |
Adventure.htblAllProperties.Add(prop) |
| 2417 |
End If |
| 2418 |
Adventure.htblLocationProperties(SHORTLOCATIONDESCRIPTION).GroupOnly = True |
| 2419 |
|
| 2420 |
If Not Adventure.htblLocationProperties.ContainsKey(LONGLOCATIONDESCRIPTION) Then |
| 2421 |
Dim prop As New clsProperty |
| 2422 |
With prop |
| 2423 |
.Key = LONGLOCATIONDESCRIPTION |
| 2424 |
.Description = "Long Location Description" |
| 2425 |
.PropertyOf = clsProperty.PropertyOfEnum.Locations |
| 2426 |
.Type = clsProperty.PropertyTypeEnum.Text |
| 2427 |
End With |
| 2428 |
Adventure.htblAllProperties.Add(prop) |
| 2429 |
End If |
| 2430 |
Adventure.htblLocationProperties(LONGLOCATIONDESCRIPTION).GroupOnly = True |
| 2431 |
|
| 2432 |
If Not Adventure.htblCharacterProperties.ContainsKey(CHARACTERPROPERNAME) Then |
| 2433 |
Dim prop As New clsProperty |
| 2434 |
With prop |
| 2435 |
.Key = CHARACTERPROPERNAME |
| 2436 |
.Description = "Character Proper Name" |
| 2437 |
.PropertyOf = clsProperty.PropertyOfEnum.Characters |
| 2438 |
.Type = clsProperty.PropertyTypeEnum.Text |
| 2439 |
End With |
| 2440 |
Adventure.htblAllProperties.Add(prop) |
| 2441 |
End If |
| 2442 |
Adventure.htblCharacterProperties(CHARACTERPROPERNAME).GroupOnly = True |
| 2443 |
|
| 2444 |
If Not Adventure.htblObjectProperties.ContainsKey("StaticOrDynamic") Then |
| 2445 |
Dim prop As New clsProperty |
| 2446 |
With prop |
| 2447 |
.Key = "StaticOrDynamic" |
| 2448 |
.Description = "Object type" |
| 2449 |
.Mandatory = True |
| 2450 |
.PropertyOf = clsProperty.PropertyOfEnum.Objects |
| 2451 |
.Type = clsProperty.PropertyTypeEnum.StateList |
| 2452 |
.arlStates.Add("Static") |
| 2453 |
.arlStates.Add("Dynamic") |
| 2454 |
End With |
| 2455 |
Adventure.htblAllProperties.Add(prop) |
| 2456 |
End If |
| 2457 |
Adventure.htblObjectProperties("StaticOrDynamic").GroupOnly = True |
| 2458 |
|
| 2459 |
If Not Adventure.htblObjectProperties.ContainsKey("StaticLocation") Then |
| 2460 |
Dim prop As New clsProperty |
| 2461 |
With prop |
| 2462 |
.Key = "StaticLocation" |
| 2463 |
.Description = "Location of the object" |
| 2464 |
.Mandatory = True |
| 2465 |
.PropertyOf = clsProperty.PropertyOfEnum.Objects |
| 2466 |
.Type = clsProperty.PropertyTypeEnum.StateList |
| 2467 |
.arlStates.Add("Hidden") |
| 2468 |
.arlStates.Add("Single Location") |
| 2469 |
.arlStates.Add("Location Group") |
| 2470 |
.arlStates.Add("Everywhere") |
| 2471 |
.arlStates.Add("Part of Character") |
| 2472 |
.arlStates.Add("Part of Object") |
| 2473 |
.DependentKey = "StaticOrDynamic" |
| 2474 |
.DependentValue = "Static" |
| 2475 |
End With |
| 2476 |
Adventure.htblAllProperties.Add(prop) |
| 2477 |
End If |
| 2478 |
Adventure.htblObjectProperties("StaticLocation").GroupOnly = True |
| 2479 |
|
| 2480 |
If Not Adventure.htblObjectProperties.ContainsKey("DynamicLocation") Then |
| 2481 |
Dim prop As New clsProperty |
| 2482 |
With prop |
| 2483 |
.Key = "DynamicLocation" |
| 2484 |
.Description = "Location of the object" |
| 2485 |
.Mandatory = True |
| 2486 |
.PropertyOf = clsProperty.PropertyOfEnum.Objects |
| 2487 |
.Type = clsProperty.PropertyTypeEnum.StateList |
| 2488 |
.arlStates.Add("Hidden") |
| 2489 |
.arlStates.Add("Held by Character") |
| 2490 |
.arlStates.Add("Worn by Character") |
| 2491 |
.arlStates.Add("In Location") |
| 2492 |
.arlStates.Add("Inside Object") |
| 2493 |
.arlStates.Add("On Object") |
| 2494 |
.DependentKey = "StaticOrDynamic" |
| 2495 |
.DependentValue = "Dynamic" |
| 2496 |
End With |
| 2497 |
Adventure.htblAllProperties.Add(prop) |
| 2498 |
End If |
| 2499 |
Adventure.htblObjectProperties("DynamicLocation").GroupOnly = True |
| 2500 |
|
| 2501 |
For Each sProp As String In New String() {"AtLocation", "AtLocationGroup", "PartOfWhat", "PartOfWho", "HeldByWho", "WornByWho", "InLocation", "InsideWhat", "OnWhat"} |
| 2502 |
If Adventure.htblObjectProperties.ContainsKey(sProp) Then Adventure.htblObjectProperties(sProp).GroupOnly = True |
| 2503 |
Next |
| 2504 |
|
| 2505 |
End Sub |
| 2506 |
|
| 2507 |
' Simple encryption |
| 2508 |
Function Dencode(ByVal sText As String) As String |
| 2509 |
|
| 2510 |
Rnd(-1) |
| 2511 |
Randomize(1976) |
| 2512 |
|
| 2513 |
Dencode = "" |
| 2514 |
For n As Integer = 1 To sText.Length |
| 2515 |
Dencode = Dencode & Chr((Asc(Mid(sText, n, 1)) Xor Int(CInt(Rnd() * 255 - 0.5))) Mod 256) |
| 2516 |
Next n |
| 2517 |
|
| 2518 |
End Function |
| 2519 |
|
| 2520 |
Friend Function Dencode(ByVal sText As String, ByVal lOffset As Long) As Byte() ' String |
| 2521 |
Rnd(-1) |
| 2522 |
Randomize(1976) |
| 2523 |
|
| 2524 |
For n As Long = 1 To lOffset - 1 |
| 2525 |
Rnd() |
| 2526 |
Next |
| 2527 |
|
| 2528 |
Dim result(sText.Length - 1) As Byte |
| 2529 |
For n As Integer = 1 To sText.Length |
| 2530 |
result(n - 1) = CByte((Asc(Mid(sText, n, 1)) Xor Int(CInt(Rnd() * 255 - 0.5))) Mod 256) |
| 2531 |
Next |
| 2532 |
|
| 2533 |
Return result |
| 2534 |
End Function |
| 2535 |
|
| 2536 |
Friend Function Dencode(ByVal bData As Byte(), ByVal lOffset As Long) As Byte() ' String |
| 2537 |
Rnd(-1) |
| 2538 |
Randomize(1976) |
| 2539 |
|
| 2540 |
For n As Long = 1 To lOffset - 1 |
| 2541 |
Rnd() |
| 2542 |
Next |
| 2543 |
|
| 2544 |
Dim result(bData.Length - 1) As Byte |
| 2545 |
For n As Integer = 1 To bData.Length |
| 2546 |
'result(n - 1) = CByte((Asc(CChar(sMid(sText, n, 1))) Xor Int(CInt(Rnd() * 255 - 0.5))) Mod 256) |
| 2547 |
result(n - 1) = CByte((bData(n - 1) Xor Int(CInt(Rnd() * 255 - 0.5))) Mod 256) |
| 2548 |
Next |
| 2549 |
|
| 2550 |
Return result |
| 2551 |
End Function |
| 2552 |
|
| 2553 |
End Module |