Skip to content

Commit

Permalink
gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverGreen93 committed Mar 2, 2017
1 parent 16f1bf0 commit 4212350
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 272 deletions.
Binary file removed .vs/Kuid2Hash/v14/.suo
Binary file not shown.
3 changes: 0 additions & 3 deletions Kuid2Hash.vbproj.user

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Features:
- Translates hexadecimal KUIDs to decimal
- Calculates the hash for a specific KUID -> Used to identify the directory in which a particular Trainz asset is stored

[Download latest release here](bin/Debug/Kuid2Hash.exe)
[Download latest release here](bin/Release/Kuid2Hash.exe)

Screenshot:

Expand Down
Binary file removed bin/Debug/Kuid2Hash.exe
Binary file not shown.
6 changes: 0 additions & 6 deletions bin/Debug/Kuid2Hash.exe.config

This file was deleted.

Binary file removed bin/Debug/Kuid2Hash.pdb
Binary file not shown.
Binary file removed bin/Debug/Kuid2Hash.vshost.exe
Binary file not shown.
6 changes: 0 additions & 6 deletions bin/Debug/Kuid2Hash.vshost.exe.config

This file was deleted.

42 changes: 0 additions & 42 deletions bin/Debug/Kuid2Hash.xml

This file was deleted.

302 changes: 151 additions & 151 deletions frmKuid.vb
Original file line number Diff line number Diff line change
@@ -1,151 +1,151 @@
Imports System.Globalization

Public Class frmKuid

Function HexToKuid(ByVal kuid As Byte()) As String
Dim rstring As String = "<kuid"
Dim ubytes(3), cbytes(3) As Byte
Dim version As Integer
Dim uInt As Integer

Array.Copy(kuid, 0, ubytes, 0, 4)
Array.Copy(kuid, 4, cbytes, 0, 4)

If (ubytes(3) And (1 << 0)) <> 0 Then
'negative user id, ignore version
version = 0
Else
version = Convert.ToInt32(ubytes(3) >> 1)
ubytes(3) = ubytes(3) And &H1
End If

uInt = BitConverter.ToInt32(ubytes, 0)

If version <> 0 Then
rstring = rstring & "2:"
Else
rstring = rstring & ":"
End If

rstring = rstring & uInt
rstring = rstring & ":"
rstring = rstring & BitConverter.ToInt32(cbytes, 0)

If version <> 0 Then
rstring = rstring & ":" & version
End If

rstring = rstring & ">"
Return rstring
End Function

''' <summary>
''' Transforms string kuid to 8 byte kuid (for routes/sessions)
''' </summary>
''' <param name="kuid">The kuid as string</param>
''' <returns>The kuid as 8 bytes</returns>
''' <remarks></remarks>
Function KuidToHex(ByVal kuid As String) As Byte()
Dim num(2) As Integer 'variable to store kuid parts
Dim ubytes(3), cbytes(3) As Byte 'user bytes and content bytes
Dim str() As String 'split kuid to tokens
Dim rbytes(7) As Byte 'returned bytes

If kuid = "" Then
'MessageBox.Show("NULL kuid encountered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'err = True
Return {0, 0, 0, 0, 0, 0, 0, 0}
End If

str = System.Text.RegularExpressions.Regex.Split(kuid, ":")

If str.Length < 3 Then
'MessageBox.Show("Invalid kuid encountered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return {0, 0, 0, 0, 0, 0, 0, 0}
End If

Try
'parse the kuid parts (skip first) and convert to integers
For i As Integer = 1 To IIf(str.Length > 4, 4, str.Length) - 1
num(i - 1) = Val(str(i))
Next

'get the bytes from integers
ubytes = BitConverter.GetBytes(num(0))
cbytes = BitConverter.GetBytes(num(1))
If (num(2) > 0 AndAlso num(2) < 128 AndAlso num(0) >= 0) Then 'check if uid is negative
ubytes(3) = ubytes(3) Xor (CByte(num(2)) << 1) 'add the version number to byte 4 of uid
End If

'merge bytes
For i As Integer = 0 To 3
rbytes(i) = ubytes(i)
rbytes(i + 4) = cbytes(i)
Next
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Return rbytes

End Function

''' <summary>
''' Computes the hash of a kuid
''' </summary>
''' <param name="kuid">Kuid to be hashed</param>
''' <returns>One byte - hash code</returns>
''' <remarks></remarks>
Function computeHash(ByVal kuid As Byte()) As Byte()

Dim hash As Byte() = {&H0}

Try
'calculate hash using xor
For i As Integer = 0 To 7
hash(0) = hash(0) Xor kuid(i)
Next
'version needs to be ignored, so xor that out, only if uid is positive
If (kuid(3) And (1 << 0)) = 0 Then
hash(0) = hash(0) Xor kuid(3)
End If

Catch ex As Exception
MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Return hash

End Function

Function ConvertHex(ByVal t As String) As Byte()
Dim data(7) As Byte
Dim s() As String = t.Split({" "c, "-"c, ":"c, ","c})
'data = New Byte(s.Length - 1) {}
For i As Integer = 0 To s.Length - 1
If Not Byte.TryParse(s(i), NumberStyles.HexNumber, CultureInfo.CurrentCulture, data(i)) Then
data(i) = 0
'MsgBox("error converting!", MsgBoxStyle.Information)
End If
Next
Return data
End Function

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If TextBox1.Focused = True Then
TextBox2.Text = "hash-" & BitConverter.ToString(computeHash(KuidToHex(TextBox1.Text)))
TextBox3.Text = BitConverter.ToString(KuidToHex(TextBox1.Text)).Replace("-"c, " "c)
End If
End Sub

Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Process.Start("http://vvmm.freeforums.org/")
End Sub

Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
If TextBox3.Focused = True Then
TextBox1.Text = HexToKuid(ConvertHex(TextBox3.Text))
TextBox2.Text = "hash-" & BitConverter.ToString(computeHash(KuidToHex(TextBox1.Text)))
End If
End Sub
End Class
Imports System.Globalization

Public Class frmKuid

Function HexToKuid(ByVal kuid As Byte()) As String
Dim rstring As String = "<kuid"
Dim ubytes(3), cbytes(3) As Byte
Dim version As Integer
Dim uInt As Integer

Array.Copy(kuid, 0, ubytes, 0, 4)
Array.Copy(kuid, 4, cbytes, 0, 4)

If (ubytes(3) And (1 << 0)) <> 0 Then
'negative user id, ignore version
version = 0
Else
version = Convert.ToInt32(ubytes(3) >> 1)
ubytes(3) = ubytes(3) And &H1
End If

uInt = BitConverter.ToInt32(ubytes, 0)

If version <> 0 Then
rstring = rstring & "2:"
Else
rstring = rstring & ":"
End If

rstring = rstring & uInt
rstring = rstring & ":"
rstring = rstring & BitConverter.ToInt32(cbytes, 0)

If version <> 0 Then
rstring = rstring & ":" & version
End If

rstring = rstring & ">"
Return rstring
End Function

''' <summary>
''' Transforms string kuid to 8 byte kuid (for routes/sessions)
''' </summary>
''' <param name="kuid">The kuid as string</param>
''' <returns>The kuid as 8 bytes</returns>
''' <remarks></remarks>
Function KuidToHex(ByVal kuid As String) As Byte()
Dim num(2) As Integer 'variable to store kuid parts
Dim ubytes(3), cbytes(3) As Byte 'user bytes and content bytes
Dim str() As String 'split kuid to tokens
Dim rbytes(7) As Byte 'returned bytes

If kuid = "" Then
'MessageBox.Show("NULL kuid encountered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'err = True
Return {0, 0, 0, 0, 0, 0, 0, 0}
End If

str = System.Text.RegularExpressions.Regex.Split(kuid, ":")

If str.Length < 3 Then
'MessageBox.Show("Invalid kuid encountered!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return {0, 0, 0, 0, 0, 0, 0, 0}
End If

Try
'parse the kuid parts (skip first) and convert to integers
For i As Integer = 1 To IIf(str.Length > 4, 4, str.Length) - 1
num(i - 1) = Val(str(i))
Next

'get the bytes from integers
ubytes = BitConverter.GetBytes(num(0))
cbytes = BitConverter.GetBytes(num(1))
If (num(2) > 0 AndAlso num(2) < 128 AndAlso num(0) >= 0) Then 'check if uid is negative
ubytes(3) = ubytes(3) Xor (CByte(num(2)) << 1) 'add the version number to byte 4 of uid
End If

'merge bytes
For i As Integer = 0 To 3
rbytes(i) = ubytes(i)
rbytes(i + 4) = cbytes(i)
Next
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Return rbytes

End Function

''' <summary>
''' Computes the hash of a kuid
''' </summary>
''' <param name="kuid">Kuid to be hashed</param>
''' <returns>One byte - hash code</returns>
''' <remarks></remarks>
Function computeHash(ByVal kuid As Byte()) As Byte()

Dim hash As Byte() = {&H0}

Try
'calculate hash using xor
For i As Integer = 0 To 7
hash(0) = hash(0) Xor kuid(i)
Next
'version needs to be ignored, so xor that out, only if uid is positive
If (kuid(3) And (1 << 0)) = 0 Then
hash(0) = hash(0) Xor kuid(3)
End If

Catch ex As Exception
MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Return hash

End Function

Function ConvertHex(ByVal t As String) As Byte()
Dim data(7) As Byte
Dim s() As String = t.Split({" "c, "-"c, ":"c, ","c})
'data = New Byte(s.Length - 1) {}
For i As Integer = 0 To s.Length - 1
If Not Byte.TryParse(s(i), NumberStyles.HexNumber, CultureInfo.CurrentCulture, data(i)) Then
data(i) = 0
'MsgBox("error converting!", MsgBoxStyle.Information)
End If
Next
Return data
End Function

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If TextBox1.Focused = True Then
TextBox2.Text = "hash-" & BitConverter.ToString(computeHash(KuidToHex(TextBox1.Text)))
TextBox3.Text = BitConverter.ToString(KuidToHex(TextBox1.Text)).Replace("-"c, " "c)
End If
End Sub

Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Process.Start("http://vvmm.freeforums.org/")
End Sub

Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
If TextBox3.Focused = True Then
TextBox1.Text = HexToKuid(ConvertHex(TextBox3.Text))
TextBox2.Text = "hash-" & BitConverter.ToString(computeHash(KuidToHex(TextBox1.Text)))
End If
End Sub
End Class
Binary file removed obj/Debug/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.
Binary file not shown.
Binary file removed obj/Debug/Kuid2Hash.Resources.resources
Binary file not shown.
Binary file removed obj/Debug/Kuid2Hash.exe
Binary file not shown.
Binary file removed obj/Debug/Kuid2Hash.frmKuid.resources
Binary file not shown.
Binary file removed obj/Debug/Kuid2Hash.pdb
Binary file not shown.
21 changes: 0 additions & 21 deletions obj/Debug/Kuid2Hash.vbproj.FileListAbsolute.txt

This file was deleted.

Binary file removed obj/Debug/Kuid2Hash.vbproj.GenerateResource.Cache
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 4212350

Please sign in to comment.