Question editing hex for a save game editor. "Arithmetic operation resulted in an overflow."

Super_hoops1967

New member
Joined
Jun 18, 2012
Messages
4
Programming Experience
Beginner
editing hex for a save game editor. "Arithmetic operation resulted in an overflow."

Hi.

I'm making a program that will remove the pain of hex editing an old DOS game (sensible world of soccer).

the program removes the limit of the number of players you can purchase (5), removes the maximum number of seasons you can compete for (20)

i'm trying to make it so you can edit your transfer budget too but i'm getting a "Arithmetic operation resulted in an overflow." error when i run the code.

here is the full code for my program. (the transfer limit & maximum season limit both work)

---------------------------------
VB.NET:
'#########################################
'#Sensible World of Soccer Career editor #
'#Created By: Gary Mckeown               #
'#Start Date: 05/02/2012                 #
'#Version: 2.00                          #
'#########################################


Imports System.IO


Public Class Swos_Editor_2013


    Dim transferbudget As String




    Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
        '#########
        '#WARNING#
        '#########
        'Dim answer As DialogResult
        'answer = MessageBox.Show("Make a Backup of your career file then click OK to proceed.  I take no responsibility for damaged career files",
        '                             "*PLEASE READ BEFORE PROCEEDING*", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)


        '##########################
        '#Progress bar set options#
        '##########################
        ProgressBar1.Minimum = 0
        ProgressBar1.Maximum = 2
        ProgressBar1.Value = 0


        '##################
        '#tool tip options#
        '##################
        Dim toolTip1 As New ToolTip


        toolTip1.AutoPopDelay = 5000
        toolTip1.InitialDelay = 1000
        toolTip1.ReshowDelay = 500
        ToolTip1.ShowAlways = True


        '###################################
        '#Open Swos career file for editing#
        '###################################
        Me.OpenFileDialog1.InitialDirectory = "c:\"
        Me.OpenFileDialog1.Title = "Select Career File for editing"
        Me.OpenFileDialog1.DefaultExt = "*.car"
        Me.OpenFileDialog1.FileName = ""
        Me.OpenFileDialog1.Filter = "Career File(*.car)|*.car"
        Me.OpenFileDialog1.Multiselect = False


        '###################
        '#OK button pressed#
        '###################
        If Me.OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then


            '##############################
            '#increase progress bar to 50%#
            '##############################


            If ProgressBar1.Value < ProgressBar1.Maximum Then
                ProgressBar1.Value += 1
            End If


            '################
            '#Enable buttons#
            '################


            btn_save.Enabled = True
            btn_trans_limit.Enabled = True
            btn_career_limit.Enabled = True
            cb_combo.Enabled = True
        End If
    End Sub
    '#######################
    '#Enable combo box drop#
    '#######################
    Private Sub cb_combo_CheckedChanged(ByVal sender As Object, e As EventArgs) Handles cb_combo.CheckedChanged
        ComboBox1.Enabled = True
    End Sub
    '########################
    '#Select Transfer Budget#
    '########################
    Private Sub ComboBox1_DropDownClosed(ByVal sender As Object, e As EventArgs) Handles ComboBox1.DropDownClosed


        Select Case ComboBox1.SelectedItem
            Case Is = "-£10 million (are you crazy CHALLENGE)"
                transferbudget = "100"
            Case Is = "-£2 million (mid level CHALLENGE)"
                transferbudget = "200"
            Case Is = "-£500k (lower league CHALLENGE)"
                transferbudget = "500"
            Case Is = "£500k (tough)"
                transferbudget = "05"
            Case Is = "£5 million"
                transferbudget = "5"
            Case Is = "£10 million"
                transferbudget = "10"
            Case Is = "£25 million"
                transferbudget = "25"
            Case Is = "£50 million"
                transferbudget = "50000000"
            Case Is = "£99 million"
                transferbudget = "999"                        
        End Select
    End Sub
    '#######################################
    '#exit if EXIT is clicked from dropdown#
    '#######################################
    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub
    '#######################
    '#Not got a bloody clue#
    '#######################
    Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T
        target = value
        Return value
    End Function
    '##################################################################
    '#Apply changes made to drop down box AND radio button IF selected#
    '##################################################################
    Public Sub SaveChanges()
        Dim amount As Integer
        Dim fpath As String = OpenFileDialog1.FileName


        Using stream = New FileStream(fpath, FileMode.Open, FileAccess.ReadWrite)
            Dim result As Integer = 0
            Dim buffer As Byte() = New Byte(3) {}


            stream.Position = 54748
            If (stream.Read(buffer, 0, 4) <> 4) Then
                Throw New Exception(("Didn't read 4 bytes when it should have: " _
                                + (result + "bytes read")))
            End If


            stream.Position = &HD5DC


            buffer = BitConverter.GetBytes(amount)


            stream.Write(buffer, 0, 4)
            stream.Position = &HD880
            If btn_career_limit.Checked Then
                stream.WriteByte(0)
            Else
                stream.WriteByte(1)
            End If


            stream.Position = &HD5C4
            If btn_trans_limit.Checked Then
                stream.WriteByte(&HFF)
            Else
                stream.WriteByte(0)
            End If


            'stream.Write(buffer, 0, 4)
            'stream.Position = &HD5DC
            'If testbutton.Checked Then
            '    stream.WriteByte("3B9AC9FF")
            'End If


            If cb_combo.Checked = True Then
                stream.Position = &HD5DC
                stream.WriteByte(transferbudget)  ######this is where i get the overflow error#####
            End If
        End Using
    End Sub
    '###############################################
    '#Save above changes & set progress bar to 100%#
    '###############################################


    Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
        SaveChanges()


        If ProgressBar1.Value < ProgressBar1.Maximum Then
            ProgressBar1.Value += 1
        End If
    End Sub
    '#########################################################################################################################################
    '#                                                              TOOL TIP (MOUSE HOVER)                                                   #
    '#                                                                                                                                       #
    Private Sub btn_trans_limit_CheckedChanged(sender As Object, e As EventArgs) Handles btn_trans_limit.MouseHover
        '#
        ToolTip1.SetToolTip(btn_trans_limit, "Removes 5 player transfer limit")                                                             '#
    End Sub
    Private Sub btn_career_limit_CheckedChanged(sender As Object, e As EventArgs) Handles btn_career_limit.MouseHover                       '#
        '#                                                                                                                                  '#
        ToolTip1.SetToolTip(btn_career_limit, "Removes 20 season limit")                                                                    '#
    End Sub
    Private Sub ComboBox1_MouseHover(sender As Object, e As EventArgs) Handles ComboBox1.MouseHover                                         '#
        '#                                                                                                                                  '#
        ToolTip1.SetToolTip(ComboBox1, "Select Transfer Budget")                                                                            '#
    End Sub
    Private Sub btn_save_MouseHover(sender As Object, e As EventArgs) Handles btn_save.MouseHover                                           '#
        '#                                                                                                                                  '#
        ToolTip1.SetToolTip(btn_save, "Save changes to your career file")
    End Sub
    Private Sub cb_combo_MouseHover(sender As Object, e As EventArgs) Handles cb_combo.MouseHover                                           '#
        '#                                                                                                                                  '#
        ToolTip1.SetToolTip(cb_combo, "tick if you want to edit transfer budget")                                                           '#
    End Sub
    '#########################################################################################################################################
End Class

any help would be greatly appreciated. i'm a complete noob at this so please accept my apology for the poor code lol :)

Cheers

Gaz
 
Top Bottom