Guest User

Untitled

a guest
May 16th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.83 KB | None | 0 0
  1. Public Class CChrFile
  2.    Public Characters() As Character
  3.    Public Bones() As String
  4.    Public Motions() As String
  5.    Public Effects() As String
  6.  
  7.    Structure Character
  8.       Public IsActive As Boolean
  9.       Public BoneID As Short
  10.       Public Name As String
  11.       Public Models() As Short
  12.       Public Motions() As Motion
  13.       Public Effects() As Effect
  14.       Structure Motion
  15.          Public ID As Short
  16.          Public MotionID As Short
  17.       End Structure
  18.       Structure Effect
  19.          Public ID As Short
  20.          Public EffectID As Short
  21.       End Structure
  22.    End Structure
  23.  
  24.    Public Function Load(ByVal Path As String) As Boolean
  25.  
  26.       Dim File As New FileStream(Path, FileMode.Open)
  27.       Dim FReader As New BinaryReader(File)
  28.  
  29.       Dim bone_count As Int16 = FReader.ReadInt16()
  30.       ReDim Bones(bone_count)
  31.       For i = 0 To bone_count - 1
  32.          Bones(i) = ReadZSTR(FReader)
  33.       Next
  34.  
  35.       Dim motion_count As Int16 = FReader.ReadInt16()
  36.       ReDim Motions(motion_count)
  37.       For i = 0 To motion_count - 1
  38.          Motions(i) = ReadZSTR(FReader)
  39.       Next
  40.  
  41.       Dim effect_count As Int16 = FReader.ReadInt16()
  42.       ReDim Effects(effect_count)
  43.       For i = 0 To effect_count - 1
  44.          Effects(i) = ReadZSTR(FReader)
  45.       Next
  46.  
  47.       Dim character_count As Int16 = FReader.ReadInt16()
  48.  
  49.       ReDim Characters(character_count)
  50.  
  51.       For i As Integer = 0 To character_count - 1
  52.          Characters(i) = New Character
  53.  
  54.          With Characters(i)
  55.             .IsActive = FReader.ReadByte()
  56.  
  57.             If .IsActive = 0 Then
  58.                Continue For
  59.             End If
  60.  
  61.             .BoneID = FReader.ReadInt16()
  62.             .Name = ReadZSTR(FReader)
  63.  
  64.             Dim meshCount As Short = FReader.ReadInt16()
  65.             ReDim .Models(meshCount)
  66.             For a = 0 To meshCount - 1
  67.                .Models(a) = FReader.ReadInt16()
  68.             Next
  69.  
  70.             motion_count = FReader.ReadInt16()
  71.             ReDim .Motions(motion_count)
  72.             For a = 0 To motion_count - 1
  73.                .Motions(a).ID = FReader.ReadInt16()
  74.                .Motions(a).MotionID = FReader.ReadInt16()
  75.             Next
  76.  
  77.             effect_count = FReader.ReadInt16()
  78.             ReDim .Effects(effect_count)
  79.             For a = 0 To effect_count - 1
  80.                .Effects(a).ID = FReader.ReadInt16()
  81.                .Effects(a).EffectID = FReader.ReadInt16()
  82.             Next
  83.  
  84.          End With
  85.       Next
  86.  
  87.       FReader.Close()
  88.  
  89.       Return True
  90.    End Function
  91.  
  92.    Public Function ReadZSTR(ByRef Br As BinaryReader) As String
  93.       Dim Str As String = ""
  94.       Do
  95.          Dim Tmp As Byte = Br.ReadByte()
  96.          If Tmp = &H0 Then
  97.             Return Str
  98.          Else
  99.             Str &= ChrW(Tmp)
  100.          End If
  101.       Loop
  102.    End Function
  103. End Class
Add Comment
Please, Sign In to add comment