Skip to content

Commit

Permalink
Alpha 5
Browse files Browse the repository at this point in the history
Add Area A/B Form
Attempt to calculate CRC for Traps (Untested)
Do not write System Data to Traps
Edited CRC for Type 3 to not be set for Traps
Fixes Trap Data being read and written
Moved some Portal Functionality to new Module
Put all Portal Read/Write methods into Background worker
Refactored Trap Module to be more efficient
  • Loading branch information
hegyak committed May 19, 2020
1 parent 608ea01 commit 183054e
Show file tree
Hide file tree
Showing 16 changed files with 2,133 additions and 6,413 deletions.
Binary file modified .vs/SkyReader-GUI/v16/.suo
Binary file not shown.
110 changes: 88 additions & 22 deletions SkyReader-GUI/CRC16CCITT.vb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Public Class CRC16CCITT
'Type 3 Checksum is Like Type 2, but add 14 BLOCKS of Zero at the end of the Array.
'Type 4 Checksum is The NEXT Four Blocks, after Type 2's Block. It is like Type 2 except that the Inital Two bytes must be set to 06 and 01 respectively.

'Traps and Crystals use their own Unique things. Because of course they do.
'Yes, Type 3 and Type 2 must be done first before we can do Type 1

Public Shared Function GetCrc() As String
Expand Down Expand Up @@ -80,50 +81,69 @@ Public Class CRC16CCITT
Dim NewChecksumArea1Type4(1) As Byte


'Since we are getting back a String value, I use the Function to convert that String back to a Byte Array.
'Type 0

CalculateSerialXOR()
'Since we are getting back a String value, I use the Function to convert that String back to a Byte Array.
'Type 0
CalculateSerialXOR()
NewChecksumType0 = AES.StringToByteArray(CalculateType0)

'Type 3
NewChecksumArea0Type3 = AES.StringToByteArray(CalculateArea0Type3)
NewChecksumArea1Type3 = AES.StringToByteArray(CalculateArea1Type3)
If blnTrap = False Then
'Type 3
NewChecksumArea0Type3 = AES.StringToByteArray(CalculateArea0Type3)
NewChecksumArea1Type3 = AES.StringToByteArray(CalculateArea1Type3)

'Type 3
WholeFile(&H8A) = NewChecksumArea0Type3(0)
WholeFile(&H8B) = NewChecksumArea0Type3(1)

WholeFile(&H24A) = NewChecksumArea1Type3(0)
WholeFile(&H24B) = NewChecksumArea1Type3(1)
Else
NewChecksumArea0Type3 = AES.StringToByteArray(CalculateArea0TypeTrap)
NewChecksumArea1Type3 = AES.StringToByteArray(CalculateArea1TypeTrap)

WholeFile(&H8A) = NewChecksumArea0Type3(0)
WholeFile(&H8B) = NewChecksumArea0Type3(1)

WholeFile(&H24A) = NewChecksumArea1Type3(0)
WholeFile(&H24B) = NewChecksumArea1Type3(1)
End If


'Type 2
NewChecksumArea0Type2 = AES.StringToByteArray(CalculateArea0Type2)
NewChecksumArea1Type2 = AES.StringToByteArray(CalculateArea1Type2)

'Type 4
NewChecksumArea0Type4 = AES.StringToByteArray(CalculateArea0Type4)
NewChecksumArea1Type4 = AES.StringToByteArray(CalculateArea1Type4)
If blnTrap = False Then
'Type 4
NewChecksumArea0Type4 = AES.StringToByteArray(CalculateArea0Type4)
NewChecksumArea1Type4 = AES.StringToByteArray(CalculateArea1Type4)
'Type 4
WholeFile(&H110) = NewChecksumArea0Type4(0)
WholeFile(&H111) = NewChecksumArea0Type4(1)


WholeFile(&H2D0) = NewChecksumArea1Type4(0)
WholeFile(&H2D1) = NewChecksumArea1Type4(1)
Else
'Don't do anything related to Type 4 if we are working with a Trap.
'It will mangle/break the Third Villian in the Trap.
End If

'We Seek after we Generate the Checksum to set our position
'We do this because we have been ALL over this file.

'Type 0
WholeFile(&H1E) = NewChecksumType0(0)
WholeFile(&H1F) = NewChecksumType0(1)

'Type 3
WholeFile(&H8A) = NewChecksumArea0Type3(0)
WholeFile(&H8B) = NewChecksumArea0Type3(1)

WholeFile(&H24A) = NewChecksumArea1Type3(0)
WholeFile(&H24B) = NewChecksumArea1Type3(1)

'Type 2
WholeFile(&H8C) = NewChecksumArea0Type2(0)
WholeFile(&H8D) = NewChecksumArea0Type2(1)

WholeFile(&H24C) = NewChecksumArea1Type2(0)
WholeFile(&H24D) = NewChecksumArea1Type2(1)

'Type 4
WholeFile(&H110) = NewChecksumArea0Type4(0)
WholeFile(&H111) = NewChecksumArea0Type4(1)

WholeFile(&H2D0) = NewChecksumArea1Type4(0)
WholeFile(&H2D1) = NewChecksumArea1Type4(1)

'We calculate Type 1 last because of it's reliance on the other checksums
'Type 1
Expand Down Expand Up @@ -160,11 +180,57 @@ Public Class CRC16CCITT
VerifyArea1Type4()
End Sub
#Region " Traps "
'These may be wrong.
Public Shared Function CalculateArea0TypeTrap() As String
'Trap CRC is Special
Counter = 0
Dim LoopCounter As Integer = 0
'We ReDim to Resize the Byte Array
'Is this offsize?
ReDim Bytes(33)

Do Until LoopCounter = 32 'Gets 32 Bytes.
Bytes(Counter) = Buffer.GetByte(WholeFile, &H8D + LoopCounter)
'Save As
Counter += 1
LoopCounter += 1
Loop
'Skipping the MiFare Block and getting the last two Bytes
Dim TwoByte As Integer = 0
Do Until LoopCounter = 34
Bytes(Counter) = Buffer.GetByte(WholeFile, &HC0 + TwoByte)
Counter += 1
LoopCounter += 1
TwoByte += 1
Loop
Area0TypeTrapCRC = GetCrc().ToUpper

Return Area0TypeTrapCRC
End Function
Public Shared Function CalculateArea1TypeTrap() As String
'Trap CRC is Special
Counter = 0
Dim LoopCounter As Integer = 0
'We ReDim to Resize the Byte Array
'Is this offsize?
ReDim Bytes(33)

Do Until LoopCounter = 32 'Gets 32 Bytes.
Bytes(Counter) = Buffer.GetByte(WholeFile, &H24D + LoopCounter)
'Save As
Counter += 1
LoopCounter += 1
Loop
'Skipping the MiFare Block and getting the last two Bytes
Dim TwoByte As Integer = 0
Do Until LoopCounter = 34
Bytes(Counter) = Buffer.GetByte(WholeFile, &H280 + TwoByte)
Counter += 1
LoopCounter += 1
TwoByte += 1
Loop
Area1TypeTrapCRC = GetCrc().ToUpper
Return Area1TypeTrapCRC
End Function
#End Region
#Region " Type 4 "
Expand Down
26 changes: 0 additions & 26 deletions SkyReader-GUI/Figures.vb
Original file line number Diff line number Diff line change
Expand Up @@ -179,32 +179,6 @@ Public Class Figures
'Read/Write Bytes
'7F0F0869

'Imaginators requires these bytes to be 0x00.
'This will not cause problems for non-Imaginator figures.
Do Until Counter = 16
'NameBytes(Counter) = WholeFile(&HA0 + Counter)
WholeFile(&H20 + Counter) = &H0
Counter += 1
Loop
Counter = 0
Do Until Counter = 16
'NameBytes(Counter) = WholeFile(&HA0 + Counter)
WholeFile(&H40 + Counter) = &H0
Counter += 1
Loop
Counter = 0
Do Until Counter = 16
'NameBytes(Counter) = WholeFile(&HA0 + Counter)
WholeFile(&H220 + Counter) = &H0
Counter += 1
Loop
Counter = 0
Do Until Counter = 16
'NameBytes(Counter) = WholeFile(&HA0 + Counter)
WholeFile(&H3E0 + Counter) = &H0
Counter += 1
Loop
'WholeFile(&H20) = &H0



Expand Down
133 changes: 66 additions & 67 deletions SkyReader-GUI/FileIODeclarations.vb
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,92 @@ Option Explicit On

Imports Microsoft.Win32.SafeHandles
Imports System.Runtime.InteropServices
Imports System.Threading

''' <summary>
''' API declarations relating to file I/O.
''' </summary>

Friend NotInheritable Class FileIO

Friend Const FILE_FLAG_OVERLAPPED As Int32 = &H40000000
Friend Const FILE_SHARE_READ As Int32 = 1
Friend Const FILE_SHARE_WRITE As Int32 = 2
Friend Const GENERIC_READ As UInt32 = &H80000000UL
Friend Const GENERIC_WRITE As UInt32 = &H40000000
Friend Const INVALID_HANDLE_VALUE As Int32 = -1
Friend Const OPEN_EXISTING As Int32 = 3
Friend Const WAIT_TIMEOUT As Int32 = &H102
Friend Const WAIT_OBJECT_0 As Int32 = 0
Friend Const FILE_FLAG_OVERLAPPED As Int32 = &H40000000
Friend Const FILE_SHARE_READ As Int32 = 1
Friend Const FILE_SHARE_WRITE As Int32 = 2
Friend Const GENERIC_READ As UInt32 = &H80000000UL
Friend Const GENERIC_WRITE As UInt32 = &H40000000
Friend Const INVALID_HANDLE_VALUE As Int32 = -1
Friend Const OPEN_EXISTING As Int32 = 3
Friend Const WAIT_TIMEOUT As Int32 = &H102
Friend Const WAIT_OBJECT_0 As Int32 = 0

<StructLayout(LayoutKind.Sequential)> _
Friend Class SECURITY_ATTRIBUTES
Friend nLength As Int32
Friend lpSecurityDescriptor As Int32
Friend bInheritHandle As Int32
End Class
<StructLayout(LayoutKind.Sequential)> _
Friend Class SECURITY_ATTRIBUTES
Friend nLength As Int32
Friend lpSecurityDescriptor As Int32
Friend bInheritHandle As Int32
End Class

<DllImport("kernel32.dll", SetLastError:=True)> _
Shared Function CancelIo _
(ByVal hFile As SafeFileHandle) _
As Int32
End Function

<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Shared Function CreateEvent _
(ByVal SecurityAttributes As IntPtr, _
ByVal bManualReset As Boolean, _
ByVal bInitialState As Boolean, _
ByVal lpName As String) _
As IntPtr
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Shared Function CreateEvent _
(ByVal SecurityAttributes As IntPtr, _
ByVal bManualReset As Boolean, _
ByVal bInitialState As Boolean, _
ByVal lpName As String) _
As IntPtr
End Function

<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Shared Function CreateFile _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As UInt32, _
ByVal dwShareMode As Int32, _
ByVal lpSecurityAttributes As IntPtr, _
ByVal dwCreationDisposition As Int32, _
ByVal dwFlagsAndAttributes As Int32, _
ByVal hTemplateFile As Int32) _
As SafeFileHandle
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Shared Function CreateFile _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As UInt32, _
ByVal dwShareMode As Int32, _
ByVal lpSecurityAttributes As IntPtr, _
ByVal dwCreationDisposition As Int32, _
ByVal dwFlagsAndAttributes As Int32, _
ByVal hTemplateFile As Int32) _
As SafeFileHandle
End Function

<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Shared Function GetOverlappedResult _
(ByVal hFile As SafeFileHandle, _
ByVal lpOverlapped As IntPtr, _
ByRef lpNumberOfBytesTransferred As Int32, _
ByVal bWait As Boolean) _
As Boolean
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Shared Function GetOverlappedResult _
(ByVal hFile As SafeFileHandle, _
ByVal lpOverlapped As IntPtr, _
ByRef lpNumberOfBytesTransferred As Int32, _
ByVal bWait As Boolean) _
As Boolean
End Function

<DllImport("kernel32.dll", SetLastError:=True)> _
Shared Function ReadFile _
(ByVal hFile As SafeFileHandle, _
ByVal lpBuffer As IntPtr, _
ByVal nNumberOfBytesToRead As Int32, _
ByRef lpNumberOfBytesRead As Int32, _
ByVal lpOverlapped As IntPtr) _
As Boolean
End Function
<DllImport("kernel32.dll", SetLastError:=True)> _
Shared Function ReadFile _
(ByVal hFile As SafeFileHandle, _
ByVal lpBuffer As IntPtr, _
ByVal nNumberOfBytesToRead As Int32, _
ByRef lpNumberOfBytesRead As Int32, _
ByVal lpOverlapped As IntPtr) _
As Boolean
End Function

<DllImport("kernel32.dll", SetLastError:=True)> _
Shared Function WaitForSingleObject _
(ByVal hHandle As IntPtr, _
ByVal dwMilliseconds As Int32) _
As Int32
End Function
<DllImport("kernel32.dll", SetLastError:=True)> _
Shared Function WaitForSingleObject _
(ByVal hHandle As IntPtr, _
ByVal dwMilliseconds As Int32) _
As Int32
End Function

<DllImport("kernel32.dll", SetLastError:=True)> _
Shared Function WriteFile _
(ByVal hFile As SafeFileHandle, _
ByVal lpBuffer() As Byte, _
ByVal nNumberOfBytesToWrite As Int32, _
ByRef lpNumberOfBytesWritten As Int32, _
ByVal lpOverlapped As IntPtr) _
As Boolean
End Function
<DllImport("kernel32.dll", SetLastError:=True)> _
Shared Function WriteFile _
(ByVal hFile As SafeFileHandle, _
ByVal lpBuffer() As Byte, _
ByVal nNumberOfBytesToWrite As Int32, _
ByRef lpNumberOfBytesWritten As Int32, _
ByVal lpOverlapped As IntPtr) _
As Boolean
End Function

End Class

Loading

0 comments on commit 183054e

Please sign in to comment.