Making editors for cricket games

There won't be anything new from me until another tutorial is released. Whatever you do, don't expect me to make an editor!
 
Nice stuff there,especially from Lee.Actually its all in your head,that making editors is a hell tough thing or anything.Its as easy as some of the applications made by Lee in the last couple of pages.
 
OK, I'll repost my first tutorial for the 3RD time, hope some people have a go:

Right, briefly from the beginning:
Create a form like this, naming the controls (objects) like this:
btnOpen, btnSave and txtFile.

030420061827318sf.png





Then drag an OpenFileDialog onto the form and name it dlgOpen:

030420061829321qp.png




Next double click the Open button, which should take you to a screen like this:


030420061831290az.png



Between the lines Private Sub... and End Sub, type the following:

Code:

Dim AllText As String Dim LineOfText As String dlgOpen.ShowDialog()



Now run it, click on the Open button and this should be what you get:


030420061836443vn.png



Post a screenie of your effort and I'll rep you. Tomorrow I will continue, so that we actually open a file.

Also, as a side note, it would be nice to see more people taking interest in this, maybe we could get more publicity?


Will post a followup in a minute..

Next step, after you write dlgOpen.ShowDialog(), write the following lines of code (copy and paste):

Code:
        'If user pressed cancel, the filename will be empty. This will cause errors, so:
        If dlgOpen.FileName <> "" Then
            'Open the file
            FileOpen(1, dlgOpen.FileName, OpenMode.Input)

            'Loop through these instructions until we reach the End Of File
            Do Until EOF(1)
                'Get the next line from the file
                LineOfText = LineInput(1)

                'Add this line on to the end of the Alltext variable (with a new line- vbCrLf)
                AllText = AllText & LineOfText & vbCrLf
            Loop

            'Display the file in the textbox

            txtFile.Text = AllText
            'Extra bonus bit. select the file
            txtFile.Select(1, 0)
            'Close the file. One of the most important steps, otherwise errors will happen
            FileClose(1)
        End If

I have commented the code so that if you want to you can learn what it is doing.
Run the program and choose a file to open. Warning: Make sure you pick a small file, otherwise you will crash your program!

Here I picked my squad from the first week of Battrick:


030620060736599up.png



Let us know how it goes! Tomorrow we shall move on to making the Save button do something...
 
Last edited:
I've been asked to make a small tool for c2k5 which can be used to change all the speeds to the same rather than editing each player.
I'll do it as a very basic tutorial and make it so people can add bits on. I'll post the first one next week when my essays are done.

Basically it will involve a combobox where you can select speed to start with but I'll add in more abilities later and a textbox where you can edit the number you want.
Obviously save and open buttons.
Long term I'd like to integrate it into the player editor so that you can highlight a number of players in a list box and change all their abilities in one field at a click but this small tool will do for the present and I'll be able to write a, reasonably easy to follow, tutorial for it.
Stay tuned.
 
Embi I Am Trying Your Tutorial
Plzz Tell Me Which Vb Software You Use , Also Specify The Version
 
Right I made a very simple version of the multiple abilities changer so I'm going to try and explain what I'm doing. I realise it'll be hard to follow but I'll do my best:

First of all the easy part. Design your form like this:

ac1.jpg


and label stuff like this: (openfiledialogue1 is found in the dialogues section)

ac1a.jpg


Your combobox should have none, speed and catching at present in the dropdown list.

Then you can start coding. Firstly we are going to inherit system.io so type it just above your class:

ac2.jpg


We also need some global variables which go just below the start of the class. They are FS As FileStream, BR As BinaryReader, BW As BinaryWriter.

The open sub is the same for most cricket editors so I'm not going to go into detail as to why you put what you put. Hopefully you can work most of it out:

ac3.jpg


Here's the code:

Code:
Windows.Forms.Cursor.Current = Cursors.WaitCursor
        Dim strFileName As String
        With OpenFileDialog1
            .Filter = "Cricket 2005 roster file|*.ros"
            .ShowDialog()
            strFileName = .FileName
        End With
        If strFileName = vbNullString Then Exit Sub
        FS = New FileStream(strFileName, FileMode.Open, FileAccess.ReadWrite)
        BR = New BinaryReader(FS)
        BW = New BinaryWriter(FS)
        'make sure the combobox is set to index 0 (none)
        cboattribute.SelectedIndex = 0

That's the easy stuff. I'll start trying to explain the hard stuff next...
 
We're ready to start coding the save sub: (remember that you don't need to type the commented bits)

First we're going to define some variables and add a Select Case statement.

ac5.jpg


If Case = 0 meaning the combobox is set to "none" then we exit the save sub. If it's set to 1 meaning "speed" we code the speed section.
The commented out parts explain how speed is calculated. Basically if you look at the two bytes in a hex editor we are using the first half of the first byte and all of the second byte. So that we don't lose the second half of the first byte (which is used to calculate something else) we have to set it to a variable.

ac6.jpg


For and Next:
This is a device by which we can make the code keep executing with a different value for x as many times as we like. In this case each cycle represents another player. So one save will edit 1000 players.

FS.Seek:
This is how we tell the program to arrive at a certain point in the open file and read what it finds. So on the first cycle it will read the byte at offset (176932 + 0*368 + 134) which is the first speed byte of Zulfiqur Ahmed.

BR.Readbyte:
The byte is read in decimal form and stored in a variable: a

a = a mod 16:
This redefines "a" as the variable that needs to stay the same whatever the speed happens to be.

speed = scaledown(updvalue.value)
scaledown is a function. You're going to have to trust me on this one and just paste it into your code. Basically there is scaling involved in calculating the values but it's not proportional.
Copy and paste this into your code as a public function:

Code:
Public Function scaledown(ByVal currentnumber As Integer) As Integer
        Dim b As Integer
        Select Case currentnumber
            Case 0
                b = 0
            Case 1
                b = 0
            Case 2
                b = 1
            Case 3
                b = 1
            Case 4
                b = 2
            Case 5
                b = 2
            Case 6
                b = 3
            Case 7
                b = 4
            Case 8
                b = 5
            Case 9
                b = 5
            Case 10
                b = 6
            Case 11
                b = 7
            Case 12
                b = 8
            Case 13
                b = 8
            Case 14
                b = 9
            Case 15
                b = 9
            Case 16
                b = 10
            Case 17
                b = 11
            Case 18
                b = 11
            Case 19
                b = 12
            Case 20
                b = 12
            Case 21
                b = 13
            Case 22
                b = 13
            Case 23
                b = 14
            Case 24
                b = 15
            Case 25
                b = 16
            Case 26
                b = 17
            Case 27
                b = 17
            Case 28
                b = 18
            Case 29
                b = 19
            Case 30
                b = 19
            Case 31
                b = 20
            Case 32
                b = 21
            Case 33
                b = 21
            Case 34
                b = 22
            Case 35
                b = 23
            Case 36
                b = 23
            Case 37
                b = 24
            Case 38
                b = 25
            Case 39
                b = 25
            Case 40
                b = 26
            Case 41
                b = 27
            Case 42
                b = 27
            Case 43
                b = 28
            Case 44
                b = 29
            Case 45
                b = 29
            Case 46
                b = 30
            Case 47
                b = 31
            Case 48
                b = 31
            Case 49
                b = 32
            Case 50
                b = 33
            Case 51
                b = 33
            Case 52
                b = 34
            Case 53
                b = 34
            Case 54
                b = 35
            Case 55
                b = 36
            Case 56
                b = 36
            Case 57
                b = 37
            Case 58
                b = 37
            Case 59
                b = 38
            Case 60
                b = 39
            Case 61
                b = 39
            Case 62
                b = 40
            Case 63
                b = 40
            Case 64
                b = 41
            Case 65
                b = 42
            Case 66
                b = 42
            Case 67
                b = 43
            Case 68
                b = 43
            Case 69
                b = 44
            Case 70
                b = 45
            Case 71
                b = 45
            Case 72
                b = 46
            Case 73
                b = 46
            Case 74
                b = 47
            Case 75
                b = 48
            Case 76
                b = 48
            Case 77
                b = 49
            Case 78
                b = 49
            Case 79
                b = 50
            Case 80
                b = 51
            Case 81
                b = 51
            Case 82
                b = 52
            Case 83
                b = 52
            Case 84
                b = 53
            Case 85
                b = 53
            Case 86
                b = 54
            Case 87
                b = 54
            Case 88
                b = 55
            Case 89
                b = 55
            Case 90
                b = 56
            Case 91
                b = 56
            Case 92
                b = 57
            Case 93
                b = 57
            Case 94
                b = 58
            Case 95
                b = 58
            Case 96
                b = 59
            Case 97
                b = 59
            Case 98
                b = 60
            Case 99
                b = 61
            Case 100
                b = 62
        End Select
        Return b
    End Function

updvalue.value obviously refers to what is in the number box. Our speed variable can then be calculated.

b = Int (speed / 16)
Speed variable divided by 16 and rounded down gives us the value of byte 135

a1 = speed mod 16
The remainder when speed is divided by 16. Gives us the first half of byte 134

a = a1*16 + a
Redefining the variable again by changing the two hex values into a decimal one so we can write it

FS.Seek
Same as before. What we have to do before we write

BW.Write
Writes the variable. Datatype is crucial. Byte will write 1 byte.

Next
Goes back to For and does all this again for x = 1 Z De Bruyn

More in a minute
 
Case 2 (catching) is much easier to code:

ac7.jpg


Code:
For x = 0 To 1000
                    'Catching is calculated by taking the decimal value of the byte
                    'and scaling it up and is dead easy to code
                    catching = scaledown(updvalue.Value)
                    FS.Seek((176932 + x * 368 + 136), SeekOrigin.Begin)
                    BW.Write(catching)
                Next

Obviously we can add lots more.
Last couple of things:

ac4.jpg


I like to make the open dialogue come up when I start the program. Double click on the frame to open this sub and type the following:

Code:
MsgBox("This is a beta. Use at your own risk and backup first", MsgBoxStyle.Critical)
        cmdopen.PerformClick()

You can also do an about box very easily. Hopefully some people will try this and, more importantly, will add other stuff to it as I've just made a very basic outline to try and keep things simple for the tutorial.
Hope people will give this a go and ask if you get stuck.
 
Embi, i'll your tutorial soon as i'm just downloading Visual Basic now, it looks good :).

Btw, Colin, where is the start of the tutorial your doing now?
 

Users who are viewing this thread

Top