Skip to content

Commit 183054e

Browse files
committed
Alpha 5
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
1 parent 608ea01 commit 183054e

File tree

16 files changed

+2133
-6413
lines changed

16 files changed

+2133
-6413
lines changed

.vs/SkyReader-GUI/v16/.suo

3.5 KB
Binary file not shown.

SkyReader-GUI/CRC16CCITT.vb

Lines changed: 88 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Public Class CRC16CCITT
2929
'Type 3 Checksum is Like Type 2, but add 14 BLOCKS of Zero at the end of the Array.
3030
'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.
3131

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

3435
Public Shared Function GetCrc() As String
@@ -80,50 +81,69 @@ Public Class CRC16CCITT
8081
Dim NewChecksumArea1Type4(1) As Byte
8182

8283

83-
'Since we are getting back a String value, I use the Function to convert that String back to a Byte Array.
84-
'Type 0
85-
86-
CalculateSerialXOR()
84+
'Since we are getting back a String value, I use the Function to convert that String back to a Byte Array.
85+
'Type 0
86+
CalculateSerialXOR()
8787
NewChecksumType0 = AES.StringToByteArray(CalculateType0)
8888

89-
'Type 3
90-
NewChecksumArea0Type3 = AES.StringToByteArray(CalculateArea0Type3)
91-
NewChecksumArea1Type3 = AES.StringToByteArray(CalculateArea1Type3)
89+
If blnTrap = False Then
90+
'Type 3
91+
NewChecksumArea0Type3 = AES.StringToByteArray(CalculateArea0Type3)
92+
NewChecksumArea1Type3 = AES.StringToByteArray(CalculateArea1Type3)
93+
94+
'Type 3
95+
WholeFile(&H8A) = NewChecksumArea0Type3(0)
96+
WholeFile(&H8B) = NewChecksumArea0Type3(1)
97+
98+
WholeFile(&H24A) = NewChecksumArea1Type3(0)
99+
WholeFile(&H24B) = NewChecksumArea1Type3(1)
100+
Else
101+
NewChecksumArea0Type3 = AES.StringToByteArray(CalculateArea0TypeTrap)
102+
NewChecksumArea1Type3 = AES.StringToByteArray(CalculateArea1TypeTrap)
103+
104+
WholeFile(&H8A) = NewChecksumArea0Type3(0)
105+
WholeFile(&H8B) = NewChecksumArea0Type3(1)
106+
107+
WholeFile(&H24A) = NewChecksumArea1Type3(0)
108+
WholeFile(&H24B) = NewChecksumArea1Type3(1)
109+
End If
110+
92111

93112
'Type 2
94113
NewChecksumArea0Type2 = AES.StringToByteArray(CalculateArea0Type2)
95114
NewChecksumArea1Type2 = AES.StringToByteArray(CalculateArea1Type2)
96115

97-
'Type 4
98-
NewChecksumArea0Type4 = AES.StringToByteArray(CalculateArea0Type4)
99-
NewChecksumArea1Type4 = AES.StringToByteArray(CalculateArea1Type4)
116+
If blnTrap = False Then
117+
'Type 4
118+
NewChecksumArea0Type4 = AES.StringToByteArray(CalculateArea0Type4)
119+
NewChecksumArea1Type4 = AES.StringToByteArray(CalculateArea1Type4)
120+
'Type 4
121+
WholeFile(&H110) = NewChecksumArea0Type4(0)
122+
WholeFile(&H111) = NewChecksumArea0Type4(1)
123+
124+
125+
WholeFile(&H2D0) = NewChecksumArea1Type4(0)
126+
WholeFile(&H2D1) = NewChecksumArea1Type4(1)
127+
Else
128+
'Don't do anything related to Type 4 if we are working with a Trap.
129+
'It will mangle/break the Third Villian in the Trap.
130+
End If
131+
100132
'We Seek after we Generate the Checksum to set our position
101133
'We do this because we have been ALL over this file.
102134

103135
'Type 0
104136
WholeFile(&H1E) = NewChecksumType0(0)
105137
WholeFile(&H1F) = NewChecksumType0(1)
106138

107-
'Type 3
108-
WholeFile(&H8A) = NewChecksumArea0Type3(0)
109-
WholeFile(&H8B) = NewChecksumArea0Type3(1)
110-
111-
WholeFile(&H24A) = NewChecksumArea1Type3(0)
112-
WholeFile(&H24B) = NewChecksumArea1Type3(1)
113-
114139
'Type 2
115140
WholeFile(&H8C) = NewChecksumArea0Type2(0)
116141
WholeFile(&H8D) = NewChecksumArea0Type2(1)
117142

118143
WholeFile(&H24C) = NewChecksumArea1Type2(0)
119144
WholeFile(&H24D) = NewChecksumArea1Type2(1)
120145

121-
'Type 4
122-
WholeFile(&H110) = NewChecksumArea0Type4(0)
123-
WholeFile(&H111) = NewChecksumArea0Type4(1)
124146

125-
WholeFile(&H2D0) = NewChecksumArea1Type4(0)
126-
WholeFile(&H2D1) = NewChecksumArea1Type4(1)
127147

128148
'We calculate Type 1 last because of it's reliance on the other checksums
129149
'Type 1
@@ -160,11 +180,57 @@ Public Class CRC16CCITT
160180
VerifyArea1Type4()
161181
End Sub
162182
#Region " Traps "
183+
'These may be wrong.
163184
Public Shared Function CalculateArea0TypeTrap() As String
185+
'Trap CRC is Special
186+
Counter = 0
187+
Dim LoopCounter As Integer = 0
188+
'We ReDim to Resize the Byte Array
189+
'Is this offsize?
190+
ReDim Bytes(33)
191+
192+
Do Until LoopCounter = 32 'Gets 32 Bytes.
193+
Bytes(Counter) = Buffer.GetByte(WholeFile, &H8D + LoopCounter)
194+
'Save As
195+
Counter += 1
196+
LoopCounter += 1
197+
Loop
198+
'Skipping the MiFare Block and getting the last two Bytes
199+
Dim TwoByte As Integer = 0
200+
Do Until LoopCounter = 34
201+
Bytes(Counter) = Buffer.GetByte(WholeFile, &HC0 + TwoByte)
202+
Counter += 1
203+
LoopCounter += 1
204+
TwoByte += 1
205+
Loop
206+
Area0TypeTrapCRC = GetCrc().ToUpper
164207

208+
Return Area0TypeTrapCRC
165209
End Function
166210
Public Shared Function CalculateArea1TypeTrap() As String
211+
'Trap CRC is Special
212+
Counter = 0
213+
Dim LoopCounter As Integer = 0
214+
'We ReDim to Resize the Byte Array
215+
'Is this offsize?
216+
ReDim Bytes(33)
167217

218+
Do Until LoopCounter = 32 'Gets 32 Bytes.
219+
Bytes(Counter) = Buffer.GetByte(WholeFile, &H24D + LoopCounter)
220+
'Save As
221+
Counter += 1
222+
LoopCounter += 1
223+
Loop
224+
'Skipping the MiFare Block and getting the last two Bytes
225+
Dim TwoByte As Integer = 0
226+
Do Until LoopCounter = 34
227+
Bytes(Counter) = Buffer.GetByte(WholeFile, &H280 + TwoByte)
228+
Counter += 1
229+
LoopCounter += 1
230+
TwoByte += 1
231+
Loop
232+
Area1TypeTrapCRC = GetCrc().ToUpper
233+
Return Area1TypeTrapCRC
168234
End Function
169235
#End Region
170236
#Region " Type 4 "

SkyReader-GUI/Figures.vb

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -179,32 +179,6 @@ Public Class Figures
179179
'Read/Write Bytes
180180
'7F0F0869
181181

182-
'Imaginators requires these bytes to be 0x00.
183-
'This will not cause problems for non-Imaginator figures.
184-
Do Until Counter = 16
185-
'NameBytes(Counter) = WholeFile(&HA0 + Counter)
186-
WholeFile(&H20 + Counter) = &H0
187-
Counter += 1
188-
Loop
189-
Counter = 0
190-
Do Until Counter = 16
191-
'NameBytes(Counter) = WholeFile(&HA0 + Counter)
192-
WholeFile(&H40 + Counter) = &H0
193-
Counter += 1
194-
Loop
195-
Counter = 0
196-
Do Until Counter = 16
197-
'NameBytes(Counter) = WholeFile(&HA0 + Counter)
198-
WholeFile(&H220 + Counter) = &H0
199-
Counter += 1
200-
Loop
201-
Counter = 0
202-
Do Until Counter = 16
203-
'NameBytes(Counter) = WholeFile(&HA0 + Counter)
204-
WholeFile(&H3E0 + Counter) = &H0
205-
Counter += 1
206-
Loop
207-
'WholeFile(&H20) = &H0
208182

209183

210184

SkyReader-GUI/FileIODeclarations.vb

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,93 +3,92 @@ Option Explicit On
33

44
Imports Microsoft.Win32.SafeHandles
55
Imports System.Runtime.InteropServices
6-
Imports System.Threading
76

87
''' <summary>
98
''' API declarations relating to file I/O.
109
''' </summary>
1110

1211
Friend NotInheritable Class FileIO
1312

14-
Friend Const FILE_FLAG_OVERLAPPED As Int32 = &H40000000
15-
Friend Const FILE_SHARE_READ As Int32 = 1
16-
Friend Const FILE_SHARE_WRITE As Int32 = 2
17-
Friend Const GENERIC_READ As UInt32 = &H80000000UL
18-
Friend Const GENERIC_WRITE As UInt32 = &H40000000
19-
Friend Const INVALID_HANDLE_VALUE As Int32 = -1
20-
Friend Const OPEN_EXISTING As Int32 = 3
21-
Friend Const WAIT_TIMEOUT As Int32 = &H102
22-
Friend Const WAIT_OBJECT_0 As Int32 = 0
13+
Friend Const FILE_FLAG_OVERLAPPED As Int32 = &H40000000
14+
Friend Const FILE_SHARE_READ As Int32 = 1
15+
Friend Const FILE_SHARE_WRITE As Int32 = 2
16+
Friend Const GENERIC_READ As UInt32 = &H80000000UL
17+
Friend Const GENERIC_WRITE As UInt32 = &H40000000
18+
Friend Const INVALID_HANDLE_VALUE As Int32 = -1
19+
Friend Const OPEN_EXISTING As Int32 = 3
20+
Friend Const WAIT_TIMEOUT As Int32 = &H102
21+
Friend Const WAIT_OBJECT_0 As Int32 = 0
2322

24-
<StructLayout(LayoutKind.Sequential)> _
25-
Friend Class SECURITY_ATTRIBUTES
26-
Friend nLength As Int32
27-
Friend lpSecurityDescriptor As Int32
28-
Friend bInheritHandle As Int32
29-
End Class
23+
<StructLayout(LayoutKind.Sequential)> _
24+
Friend Class SECURITY_ATTRIBUTES
25+
Friend nLength As Int32
26+
Friend lpSecurityDescriptor As Int32
27+
Friend bInheritHandle As Int32
28+
End Class
3029

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

37-
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
38-
Shared Function CreateEvent _
39-
(ByVal SecurityAttributes As IntPtr, _
40-
ByVal bManualReset As Boolean, _
41-
ByVal bInitialState As Boolean, _
42-
ByVal lpName As String) _
43-
As IntPtr
44-
End Function
36+
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
37+
Shared Function CreateEvent _
38+
(ByVal SecurityAttributes As IntPtr, _
39+
ByVal bManualReset As Boolean, _
40+
ByVal bInitialState As Boolean, _
41+
ByVal lpName As String) _
42+
As IntPtr
43+
End Function
4544

46-
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
47-
Shared Function CreateFile _
48-
(ByVal lpFileName As String, _
49-
ByVal dwDesiredAccess As UInt32, _
50-
ByVal dwShareMode As Int32, _
51-
ByVal lpSecurityAttributes As IntPtr, _
52-
ByVal dwCreationDisposition As Int32, _
53-
ByVal dwFlagsAndAttributes As Int32, _
54-
ByVal hTemplateFile As Int32) _
55-
As SafeFileHandle
56-
End Function
45+
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
46+
Shared Function CreateFile _
47+
(ByVal lpFileName As String, _
48+
ByVal dwDesiredAccess As UInt32, _
49+
ByVal dwShareMode As Int32, _
50+
ByVal lpSecurityAttributes As IntPtr, _
51+
ByVal dwCreationDisposition As Int32, _
52+
ByVal dwFlagsAndAttributes As Int32, _
53+
ByVal hTemplateFile As Int32) _
54+
As SafeFileHandle
55+
End Function
5756

58-
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
59-
Shared Function GetOverlappedResult _
60-
(ByVal hFile As SafeFileHandle, _
61-
ByVal lpOverlapped As IntPtr, _
62-
ByRef lpNumberOfBytesTransferred As Int32, _
63-
ByVal bWait As Boolean) _
64-
As Boolean
65-
End Function
57+
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
58+
Shared Function GetOverlappedResult _
59+
(ByVal hFile As SafeFileHandle, _
60+
ByVal lpOverlapped As IntPtr, _
61+
ByRef lpNumberOfBytesTransferred As Int32, _
62+
ByVal bWait As Boolean) _
63+
As Boolean
64+
End Function
6665

67-
<DllImport("kernel32.dll", SetLastError:=True)> _
68-
Shared Function ReadFile _
69-
(ByVal hFile As SafeFileHandle, _
70-
ByVal lpBuffer As IntPtr, _
71-
ByVal nNumberOfBytesToRead As Int32, _
72-
ByRef lpNumberOfBytesRead As Int32, _
73-
ByVal lpOverlapped As IntPtr) _
74-
As Boolean
75-
End Function
66+
<DllImport("kernel32.dll", SetLastError:=True)> _
67+
Shared Function ReadFile _
68+
(ByVal hFile As SafeFileHandle, _
69+
ByVal lpBuffer As IntPtr, _
70+
ByVal nNumberOfBytesToRead As Int32, _
71+
ByRef lpNumberOfBytesRead As Int32, _
72+
ByVal lpOverlapped As IntPtr) _
73+
As Boolean
74+
End Function
7675

77-
<DllImport("kernel32.dll", SetLastError:=True)> _
78-
Shared Function WaitForSingleObject _
79-
(ByVal hHandle As IntPtr, _
80-
ByVal dwMilliseconds As Int32) _
81-
As Int32
82-
End Function
76+
<DllImport("kernel32.dll", SetLastError:=True)> _
77+
Shared Function WaitForSingleObject _
78+
(ByVal hHandle As IntPtr, _
79+
ByVal dwMilliseconds As Int32) _
80+
As Int32
81+
End Function
8382

84-
<DllImport("kernel32.dll", SetLastError:=True)> _
85-
Shared Function WriteFile _
86-
(ByVal hFile As SafeFileHandle, _
87-
ByVal lpBuffer() As Byte, _
88-
ByVal nNumberOfBytesToWrite As Int32, _
89-
ByRef lpNumberOfBytesWritten As Int32, _
90-
ByVal lpOverlapped As IntPtr) _
91-
As Boolean
92-
End Function
83+
<DllImport("kernel32.dll", SetLastError:=True)> _
84+
Shared Function WriteFile _
85+
(ByVal hFile As SafeFileHandle, _
86+
ByVal lpBuffer() As Byte, _
87+
ByVal nNumberOfBytesToWrite As Int32, _
88+
ByRef lpNumberOfBytesWritten As Int32, _
89+
ByVal lpOverlapped As IntPtr) _
90+
As Boolean
91+
End Function
9392

9493
End Class
9594

0 commit comments

Comments
 (0)