Skip to content

Commit 23a7f35

Browse files
committed
Further code tidying
1 parent fa74b21 commit 23a7f35

File tree

2 files changed

+66
-90
lines changed

2 files changed

+66
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ Temporary Items
6767
.vs/GoWSaveEdit/FileContentIndex/403481d9-e36b-4504-9c12-6330af10fdbd.vsidx
6868
.vs/GoWSaveEdit/FileContentIndex/read.lock
6969
.vs/GoWSaveEdit/FileContentIndex/e26802e6-2a58-47ee-9039-82e6d37d379b.vsidx
70+
.vs/GoWSaveEdit/FileContentIndex/b1ecb1b2-ff5d-42be-8751-55d32bba0666.vsidx

GoWSaveEdit/GoW1.vb

Lines changed: 65 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,36 @@ Public Class GoW1
3535

3636
End Sub
3737

38-
Private Function RSingle(ByRef bytes, start) As Single
38+
Private Function RSingle(ByRef bytes() As Byte, start As Int32) As Single
3939
Dim ba(4) As Byte
4040
Array.Copy(bytes, start, ba, 0, 4)
4141
If bigendian Then Array.Reverse(ba)
4242

4343
REM TODO: ...Why is this not acting like it's zero-indexed?
4444
Return BitConverter.ToSingle(ba, 1)
4545
End Function
46+
Private Sub WSingle(ByRef bytes() As Byte, start As Int32, val As Single)
47+
Dim ba(4) As Byte
48+
ba = BitConverter.GetBytes(val)
49+
If bigendian Then Array.Reverse(ba)
4650

47-
Private Function SingleToHex(text As String, part As Integer)
48-
Return (Byte.Parse(Mid(BitConverter.ToString(BitConverter.GetBytes(System.Convert.ToSingle(text))), (13 - part * 3), 2), Globalization.NumberStyles.HexNumber))
49-
End Function
50-
51-
52-
Private Function HexToSingle(ByVal hexValue As String) As Single
53-
Dim iInputIndex As Integer = 0
54-
Dim iOutputIndex As Integer = 0
55-
Dim bArray(3) As Byte
51+
Array.Copy(ba, 0, bytes, start, 4)
52+
End Sub
53+
Private Sub WUInt16(ByRef bytes() As Byte, start As Int32, val As UInt16)
54+
Dim ba(2) As Byte
55+
ba = BitConverter.GetBytes(val)
56+
If bigendian Then Array.Reverse(ba)
5657

57-
For iInputIndex = 0 To hexValue.Length - 1 Step 2
58-
bArray(iOutputIndex) = Byte.Parse(hexValue.Chars(iInputIndex) & hexValue.Chars(iInputIndex + 1), Globalization.NumberStyles.HexNumber)
59-
iOutputIndex += 1
60-
Next
58+
Array.Copy(ba, 0, bytes, start, 2)
59+
End Sub
60+
Private Sub WUInt32(ByRef bytes() As Byte, start As Int32, val As UInt32)
61+
Dim ba(4) As Byte
62+
ba = BitConverter.GetBytes(val)
63+
If bigendian Then Array.Reverse(ba)
6164

62-
Array.Reverse(bArray)
63-
Return BitConverter.ToSingle(bArray, 0)
65+
Array.Copy(ba, 0, bytes, start, 4)
66+
End Sub
6467

65-
End Function
6668

6769
Private Function FileToBytes(name As String) As Byte()
6870
If encrypted Then
@@ -190,7 +192,7 @@ Public Class GoW1
190192

191193
txtG1SecsPlayed.Text = RSingle(bytes, &H6A)
192194

193-
txtG1Health.Text = RSingle(bytes, 118)
195+
txtG1Health.Text = RSingle(bytes, &H76)
194196
txtG1Magic.Text = RSingle(bytes, 122)
195197
txtG1Rage.Text = RSingle(bytes, 126)
196198
txtG1MagicRegen.Text = RSingle(bytes, 130)
@@ -200,7 +202,7 @@ Public Class GoW1
200202
txtG1HealthExt.Text = bytes(148)
201203
txtG1MagicExt.Text = bytes(149)
202204

203-
txtG1PR.Text = bytes(150) + 1
205+
txtG1PR.Text = bytes(&H96) + 1
204206
txtG1MG.Text = bytes(151) + 1
205207
txtG1ZF.Text = bytes(152) + 1
206208
txtG1AoH.Text = bytes(153) + 1
@@ -231,7 +233,7 @@ Public Class GoW1
231233
txtG1Camera.Text = ""
232234
txtG1CamWad.Text = ""
233235

234-
For i = 174 To 197
236+
For i = &HAE To &HC5
235237
If bytes(i) > 0 Then
236238
txtG1Camera.Text = txtG1Camera.Text + Chr(bytes(i))
237239
Else
@@ -455,70 +457,41 @@ Public Class GoW1
455457

456458
REM TODO: What the hell, pastWulf? This was what you did?
457459
REM For shame....
458-
bytes(78) = SingleToHex(txtG1Xpos.Text, 1)
459-
bytes(79) = SingleToHex(txtG1Xpos.Text, 2)
460-
bytes(80) = SingleToHex(txtG1Xpos.Text, 3)
461-
bytes(81) = SingleToHex(txtG1Xpos.Text, 4)
462-
463-
bytes(82) = SingleToHex(txtG1Height.Text, 1)
464-
bytes(83) = SingleToHex(txtG1Height.Text, 2)
465-
bytes(84) = SingleToHex(txtG1Height.Text, 3)
466-
bytes(85) = SingleToHex(txtG1Height.Text, 4)
467460

468-
bytes(86) = SingleToHex(txtG1YPos.Text, 1)
469-
bytes(87) = SingleToHex(txtG1YPos.Text, 2)
470-
bytes(88) = SingleToHex(txtG1YPos.Text, 3)
471-
bytes(89) = SingleToHex(txtG1YPos.Text, 4)
461+
WSingle(bytes, &H4E, Convert.ToSingle(txtG1Xpos.Text))
462+
WSingle(bytes, &H52, Convert.ToSingle(txtG1Height.Text))
463+
WSingle(bytes, &H56, Convert.ToSingle(txtG1YPos.Text))
472464

473465
If chkG1Swim.Checked = True Then bytes(96) = 2 Else bytes(96) = 0
474466

475-
bytes(106) = SingleToHex(txtG1SecsPlayed.Text, 1)
476-
bytes(107) = SingleToHex(txtG1SecsPlayed.Text, 2)
477-
bytes(108) = SingleToHex(txtG1SecsPlayed.Text, 3)
478-
bytes(109) = SingleToHex(txtG1SecsPlayed.Text, 4)
467+
WSingle(bytes, &H6A, Convert.ToSingle(txtG1SecsPlayed.Text))
468+
WSingle(bytes, &H76, Convert.ToSingle(txtG1Health.Text))
469+
WSingle(bytes, &H7A, Convert.ToSingle(txtG1Magic.Text))
470+
WSingle(bytes, &H7E, Convert.ToSingle(txtG1Rage.Text))
471+
WSingle(bytes, &H82, Convert.ToSingle(txtG1MagicRegen.Text))
472+
WUInt16(bytes, &H86, Convert.ToUInt16(txtG1RedOrbs.Text))
479473

480-
bytes(118) = SingleToHex(txtG1Health.Text, 1)
481-
bytes(119) = SingleToHex(txtG1Health.Text, 2)
482-
bytes(120) = SingleToHex(txtG1Health.Text, 3)
483-
bytes(121) = SingleToHex(txtG1Health.Text, 4)
484474

485-
bytes(122) = SingleToHex(txtG1Magic.Text, 1)
486-
bytes(123) = SingleToHex(txtG1Magic.Text, 2)
487-
bytes(124) = SingleToHex(txtG1Magic.Text, 3)
488-
bytes(125) = SingleToHex(txtG1Magic.Text, 4)
489475

490-
bytes(126) = SingleToHex(txtG1Rage.Text, 1)
491-
bytes(127) = SingleToHex(txtG1Rage.Text, 2)
492-
bytes(128) = SingleToHex(txtG1Rage.Text, 3)
493-
bytes(129) = SingleToHex(txtG1Rage.Text, 4)
494476

495-
bytes(130) = SingleToHex(txtG1MagicRegen.Text, 1)
496-
bytes(131) = SingleToHex(txtG1MagicRegen.Text, 2)
497-
bytes(132) = SingleToHex(txtG1MagicRegen.Text, 3)
498-
bytes(133) = SingleToHex(txtG1MagicRegen.Text, 4)
477+
bytes(&H94) = txtG1HealthExt.Text
478+
bytes(&H95) = txtG1MagicExt.Text
499479

500-
bytes(134) = Math.Floor(Val(txtG1RedOrbs.Text / (256)))
501-
bytes(135) = txtG1RedOrbs.Text Mod 256
502-
503-
504-
bytes(148) = txtG1HealthExt.Text
505-
bytes(149) = txtG1MagicExt.Text
506-
507-
bytes(150) = txtG1PR.Text - 1
508-
bytes(151) = txtG1MG.Text - 1
509-
bytes(152) = txtG1ZF.Text - 1
480+
bytes(&H96) = txtG1PR.Text - 1
481+
bytes(&H97) = txtG1MG.Text - 1
482+
bytes(&H98) = txtG1ZF.Text - 1
510483
bytes(153) = txtG1AoH.Text - 1
511484
bytes(154) = txtG1BoA.Text - 1
512485
bytes(155) = txtG1BoC.Text - 1
513486

514-
bytes(156) = 0
487+
bytes(&H9C) = 0
515488
If chkG1PRSel.Checked = True Then bytes(156) = 3
516489
If chkG1MGSel.Checked = True Then bytes(156) = 4
517490
If chkG1AoHSel.Checked = True Then bytes(156) = 5
518491
If chkG1ZFSel.Checked = True Then bytes(156) = 6
519492

520493

521-
bytes(157) = txtG1GorgonEyes.Text
494+
bytes(&H9D) = txtG1GorgonEyes.Text
522495
bytes(158) = txtG1PhoenixFeathers.Text
523496
bytes(159) = txtG1MuseKeys.Text
524497

@@ -528,55 +501,55 @@ Public Class GoW1
528501
bytes(160) = 0
529502
End If
530503

531-
bytes(161) = System.Math.Abs((chkG1PR.Checked * 64) + (chkG1MG.Checked * 32) + (chkG1ZF.Checked * 16) + (chkG1AoH.Checked * 8) + (chkG1BoA.Checked * 4))
504+
bytes(&HA1) = System.Math.Abs((chkG1PR.Checked * 64) + (chkG1MG.Checked * 32) + (chkG1ZF.Checked * 16) + (chkG1AoH.Checked * 8) + (chkG1BoA.Checked * 4))
532505

533506

534507
For i = 0 To 23
535508
If (i < txtG1Camera.TextLength) Then
536-
bytes(i + 174) = Asc(txtG1Camera.Text(i))
509+
bytes(i + &HAE) = Asc(txtG1Camera.Text(i))
537510
Else
538-
bytes(i + 174) = 0
511+
bytes(i + &HAE) = 0
539512
End If
540513
Next
541514

542515
For i = 0 To 23
543516
If (i < txtG1CamWad.TextLength) Then
544-
bytes(i + 198) = Asc(txtG1CamWad.Text(i))
517+
bytes(i + &HC6) = Asc(txtG1CamWad.Text(i))
545518
Else
546-
bytes(i + 198) = 0
519+
bytes(i + &HC6) = 0
547520
End If
548521
Next
549522

550523

551524
If rdbG1Kratos.Checked = True Then
552-
bytes(1062) = 0
525+
bytes(&H426) = 0
553526
bytes(7) = 0
554527
End If
555528
If rdbG1Chef.Checked = True Then
556-
bytes(1062) = 1
529+
bytes(&H426) = 1
557530
bytes(7) = 1
558531
End If
559532
If rdbG1Bubbles.Checked = True Then
560-
bytes(1062) = 2
533+
bytes(&H426) = 2
561534
bytes(7) = 2
562535
End If
563536
If rdbG1Tycoonius.Checked = True Then
564-
bytes(1062) = 3
537+
bytes(&H426) = 3
565538
bytes(7) = 3
566539
End If
567540
If rdbG1Dairy.Checked = True Then
568-
bytes(1062) = 4
541+
bytes(&H426) = 4
569542
bytes(7) = 4
570543
End If
571544
If rdbG1Ares.Checked = True Then
572-
bytes(1062) = 5
545+
bytes(&H426) = 5
573546
bytes(7) = 5
574547
End If
575548

576-
If rdbG1Easy.Checked = True Then bytes(1063) = 0
577-
If rdbG1Normal.Checked = True Then bytes(1063) = 1
578-
If rdbG1Hard.Checked = True Then bytes(1063) = 2
579-
If rdbG1VeryHard.Checked = True Then bytes(1063) = 3
549+
If rdbG1Easy.Checked = True Then bytes(&H427) = 0
550+
If rdbG1Normal.Checked = True Then bytes(&H427) = 1
551+
If rdbG1Hard.Checked = True Then bytes(&H427) = 2
552+
If rdbG1VeryHard.Checked = True Then bytes(&H427) = 3
580553

581554

582555
Dim checksum As ULong
@@ -600,26 +573,28 @@ Public Class GoW1
600573

601574
Dim bytesmast = FileToBytes("MASTER.BIN")
602575

603-
bytesmast(4 + 16 * Val(slotnum)) = 202
604-
bytesmast(5 + 16 * Val(slotnum)) = 254
605-
bytesmast(6 + 16 * Val(slotnum)) = 186
606-
bytesmast(7 + 16 * Val(slotnum)) = 209
576+
bytesmast(4 + 16 * Val(slotnum)) = &HCA
577+
bytesmast(5 + 16 * Val(slotnum)) = &HFE
578+
bytesmast(6 + 16 * Val(slotnum)) = &HBA
579+
bytesmast(7 + 16 * Val(slotnum)) = &HD1
607580

608-
bytesmast(8 + 16 * Val(slotnum)) = bytes(106)
609-
bytesmast(9 + 16 * Val(slotnum)) = bytes(107)
610-
bytesmast(10 + 16 * Val(slotnum)) = bytes(108)
611-
bytesmast(11 + 16 * Val(slotnum)) = bytes(109)
581+
bytesmast(8 + 16 * Val(slotnum)) = bytes(&H6A)
582+
bytesmast(9 + 16 * Val(slotnum)) = bytes(&H6B)
583+
bytesmast(10 + 16 * Val(slotnum)) = bytes(&H6C)
584+
bytesmast(11 + 16 * Val(slotnum)) = bytes(&H6D)
612585

613586
If bytesmast(13 + 16 * Val(slotnum)) = 0 Then bytesmast(13 + 16 * Val(slotnum)) = 1
614-
bytesmast(14 + 16 * Val(slotnum)) = bytes(1063)
587+
bytesmast(14 + 16 * Val(slotnum)) = bytes(&H427)
588+
589+
BytesToFile("MASTER.BIN", bytesmast)
615590
End If
616591

617592
BytesToFile(filename, bytes)
618593

619594

620595
MsgBox("Save Completed")
621596
Catch ex As Exception
622-
MsgBox("Save failed, no specific reason. Either you or I did something dumb.")
597+
MsgBox("Save failed, no specific reason. Either you or I did something dumb. " & ex.Message)
623598
End Try
624599
End Sub
625600

0 commit comments

Comments
 (0)