A Simple Program That Makes a Dev/Cheat Menu

Hey,

I was fooling around today and made a pretty simple and crude program that will look through your startup.txt file and create a new file called ‘devmenu.txt’. It is just a big choice that allows you to edit every variable while you’re playing. I had it hooked up to my choicescript_stats.txt so I’d recommend linking it in there if you want to use it.

I don’t know if anyone would actually be interested in it but I’ll throw the github link out there if you want to mess around. It only works on Windows desktops as far as I am aware. Let me know if you’ve got any questions.

12 Likes

That’s a really cool idea.

Unfortunately I don’t use windows, I can’t try it. Can you post an example of how it looks when you use it?

Also, what did you use to develop it? Can you share the source?

1 Like

Yeah I’ll post some screenshots!

I wrote the program in Visual Studio in VB .NET and because of this, it only runs on Windows machines. I’ve been looking at remaking this either with Mono or in C# so that Macs can use it too. Regardless, I will put the code in here for you to copy if you’d like.

The startup.txt file

The program

The generated file

The VB .NET code
Imports Microsoft.VisualBasic.FileIO
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'resultWriter will be used to write to devmenu.txt
        Dim resultWriter As System.IO.StreamWriter
        'resultFilePath is where devmenu.txt is located
        Dim resultFilePath As String
        'startupFilePath is where the startup file is located, starts empty
        Dim startupFilePath As String = String.Empty
        'A list of all variables in the startup file that are string types
        Dim varListString As New List(Of String)()
        'A list of all variables in the startup file that are numeric types (most likely an integer)
        Dim varListNumeric As New List(Of String)()
        'An array of every word on the current line in the startup file when being read by the File Parser
        Dim currentLine As String()

        'Opens the file explorer that searches for .txt files initially in the C Drive
        Using FileDialogue As OpenFileDialog = New OpenFileDialog()
            FileDialogue.Title = "Select startup.txt"
            FileDialogue.InitialDirectory = "C:\"
            FileDialogue.Filter = "Text files (*.txt)|*.txt"
            FileDialogue.FilterIndex = 2
            FileDialogue.RestoreDirectory = True

            'Save the file path to startup.txt 
            If FileDialogue.ShowDialog() = DialogResult.OK Then
                startupFilePath = FileDialogue.FileName
                'If Cancel is selected the file selection is aborted
            ElseIf FileDialogue.ShowDialog() = DialogResult.Cancel Then
                Exit Sub
            End If
        End Using

        'Try to path devmenu.txt to the desktop
        Try
            resultFilePath = My.Computer.FileSystem.SpecialDirectories.Desktop + "\devmenu.txt"
        Catch ex As Exception
            MessageBox.Show("Sorry, the program could not find your desktop", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try

        'If devmenu.txt doesn't exist, make it
        'If it does, ask whether to overwrite it or not
        If Not System.IO.File.Exists(resultFilePath) Then
            System.IO.File.Create(resultFilePath).Dispose()
            MessageBox.Show("devmenu.txt created at " & resultFilePath, "Done", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            If MessageBox.Show("Do you want to overwrite your devmenu file?", "Overwrite?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then
                System.IO.File.Create(resultFilePath).Dispose()
                MessageBox.Show("devmenu.txt overwritten", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                resultFilePath = My.Computer.FileSystem.SpecialDirectories.Desktop + "\devmenuAlt.txt"
                System.IO.File.Create(resultFilePath).Dispose()
                MessageBox.Show("devmenuAlt.txt created on Desktop", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        End If

        'If the path to the startup file is not an empty string, open it and begin parsing
        'The startup file is closed when we are at "End Using"
        If Len(startupFilePath) <> 0 Then
            Try
                Using FileParser As New TextFieldParser(startupFilePath)
                    'Ignore any line starting with "*comment"
                    FileParser.CommentTokens = New String() {"*comment"}
                    'Tells the parser that each word is separated by a space
                    FileParser.SetDelimiters(" ")

                    'While Not FileParser.EndOfData means read the whole file
                    While Not FileParser.EndOfData
                        'Store each distinct word in the currentLine list
                        currentLine = FileParser.ReadFields()
                        'If the first word is *create and the 3rd is not a number, put the variable name in varListString
                        'If the first word is *create and the 3rd is a number, put in varListNumeric
                        If currentLine(0) = "*create" Then
                            If IsNumeric(currentLine(2)) = False Then
                                varListString.Add(currentLine(1))
                            ElseIf IsNumeric(currentLine(2)) = True Then
                                varListNumeric.Add(currentLine(1))
                            End If
                        End If
                    End While
                End Using

                'Open devmenu.txt in append mode
                resultWriter = My.Computer.FileSystem.OpenTextFileWriter(resultFilePath, True)
                'write two lines that begins the Choicescript code
                resultWriter.WriteLine("*label variableEditChoice" & vbCrLf)
                resultWriter.WriteLine("*choice" & vbCrLf)
                'A loop that creates Choicescript code for each string variable
                For Each stringVariable As String In varListString
                    resultWriter.WriteLine(vbTab & "#" & stringVariable & vbCrLf)
                    resultWriter.WriteLine(vbTab & vbTab & "Give a string for " & stringVariable & vbCrLf)
                    resultWriter.WriteLine(vbTab & vbTab & "*input_text " & stringVariable & vbCrLf)
                Next
                'A loop that creates code for each numeric variable
                For Each numericVariable As String In varListNumeric
                    resultWriter.WriteLine(vbTab & "#" & numericVariable & vbCrLf)
                    resultWriter.WriteLine(vbTab & vbTab & "Give a value for " & numericVariable & vbCrLf)
                    resultWriter.WriteLine(vbTab & vbTab & "*input_number " & numericVariable & " 0 100" & vbCrLf)
                Next
                'An option to go back to the stats screen
                resultWriter.WriteLine(vbTab & "#Go back to stats" & vbCrLf)
                resultWriter.WriteLine(vbTab & vbTab & "*goto choicescript_stats" & vbCrLf)
                'If you selected an option above you will be brought back to the variable choice
                resultWriter.WriteLine("*goto variableEditChoice")
                'Close the devmenu.txt file
                resultWriter.Close()
                'Tell the user that everything is finished
                MessageBox.Show("Dev menu complete", "Success", MessageBoxButtons.OK, MessageBoxIcon.None)

            Catch ex As Exception
                MessageBox.Show("Sorry, the file parser isn't working", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            End Try
        Else
            MessageBox.Show("Sorry, the startup file isn't found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If
    End Sub
End Class

3 Likes

Thanks so much. When you take the Window-specific UI out, it’s very compact and easy to read. I think I’ll start using your idea for tests and debugging.

1 Like