Ok now that we have our code working it's time to make it look pretty. Some people can use a console fairly well,some can barely click a button lol. We want our programs to be as user-friendly as possible, thus we need a GUI. This should actually be the easiest part of the project since we already have our code. As I said before the code should be in functions so it's just a matter of tying those functions into events. Whenever a user does anything and I mean anything it triggers an event, be it clicking or moving a mouse, pressing a key, or sometimes even just sneezing on the screen (or maybe that's just me lol). We only need to capture certain events such as a button being clicked or a slider being moved usually so that's what I'll focus in terms of controls.
Designing the GUI
First thing we do is open up our favorite form designer. There are designers for most languages so if you don't have one just google, you're bound to find one. Design your GUI in this (place buttons, sliders, text boxes, labels, etc) then get the code for it. Make sure when you're designing your GUI anything that needs to be interacted with (buttons, sliders, etc) have an event set off when they're clicked/changed. Most form designers have an option to import the code directly into your editor/compiler so just do that if you can.
Integrating Functions and Events
Ok now that we have our code and our GUI code we can put the two together. Since all our important stuff is in functions and we can call it whenever we need all we need to do is put our function calls inside our event triggers. Here's an example in autoit of code that calls our custom function, called "HexEdit" when a button named "$btnChange" is clicked. Now it's named $btnChange but it will show Change on the button itself, don't get those confused it'll screw you up.
Code:
$nMsg = GUIGetMsg()
Switch $nMsg
Case $btnChange
HexEdit($data)
EndSwitch
$data is just a variable passed as a parameter to the function. Ok whose head just exploded, be honest. Raise your hand. Ok now go get a towel then talk to me after it grows back. For those of you still able to think all this code does is say "when a user clicks a button named $btnChange call the function HexEdit and send $data to that function."
Our function "HexEdit" should take the data it gets from $data and use that to do whatever it needs to do. Say it edits our gold, $data should be the value we want our gold at. We send $data (which has a value of, say, 10k) and in turn HexEdit() automatically edits our save file to give us 10k gold. Simple in principle yeah?
The most time-consuming portion of the GUI phase is designing the GUI. We all want our programs to look good so we'll probably spend a fair amount of time designing. I've found that doing a rough draft in the form designer then editing values in the code is a good way to make things look neat. I like to do things in increments of 5. If something has a value of 173 I'll make it 175, if it's 289 I'll make it 290, etc. Things line up well and it seems more professional, plus it's easier than trying to get it perfect in the form designer. Try to have an idea of how you want it to look before you start designing, that way you're not making it up and it looks even better. Really integration of the code and GUI is simple, once both portions are done. If you plan on adding features later you might want to add the appropriate controls to the editor and just disable them until their functions are working. It gives users a bit of a teaser of what's to come.
Now most of these will be in AutoIt since it's my preferred language but I will post some code in other languages as well if I know the conversions off-hand. Most of these will be snippets (small pieces of code that do something specific).
For loop: *assuming you have an integer variable declared that's named iCount*
AutoIt
Code:
For $iCount = 1 to 6
*do something here*
Next
This loops the code 6 times, each time doing what's between "For" and Next. It also adds 1 to $iCount.
While loop: *assuming you have an integer variable declared that's named iCount
AutoIt
Code:
While $iCount < 12
*do something*
WEnd
Checks if $iCount is less than 12 and if so executes
C++
Code:
While(iCount < 12){
*do something*;
}
Same as above
Do loop: *assuming you have an integer variable declared that's named iCount
Code:
Do
*do something*
Until $iCount = 48
Executes until $iCount equals 48
Open a file:
AutoIt
Code:
$fSave = FileOpen("*savegame*")
Creates a filehandle to a file that can be used with other File* functions and opens in read-only mode
C++
Code:
FILE * fFile;
fFile = fopen ("*savegame*","r");
Same as above
Read a file: *uses the filehandle created earlier*
Code:
$sFileData = FileRead($fFile)
Reads the file's contents into a variable named sFileData
Write to a file: *uses the filehadle created earlier*
Code:
FileWrite($fFile,$sData)
Writes the string $sData to the file, either appending it (adding it to the end) or replacing the file's entire contents depending on the mode used to open the file.
Open a file in binary mode: *since we're modders we'll need the hex of the file so this will help a lot*
Code:
$fFile = FileOpen("*savegame*",16)
Opens the file in binary read-only mode. The binary is represented as hex. This will give us the hex data.
Read one byte from an offset: *uses filehandle created earlier*
Since I'm working on a project with another member here that requires me learning C# I thought I'd post some of my practice code. It's all functional.
C#
Common Functions:
Code:
using System.Windows.Forms;
using System;
using System.IO;
using System.Threading;
using System.Collections.Generic;
namespace Common
{
public class CommonFunctions{
public static void MsgBox(string sMessage, string sCaption = "Error", MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon Icon = MessageBoxIcon.Exclamation, IWin32Window owner = null)
{
MessageBox.Show(owner, sMessage, sCaption, buttons, Icon);
}
public static void Test(params string[] sInput)
{
for (int i = 0; i < sInput.Length; i++)
{
Console.WriteLine(sInput[i]);
}
}
public static void Sleep(int iMilliseconds)
{
Thread.Sleep(iMilliseconds);
}
public static string StringStripCR(string sInput)
{
string sNewString = sInput.Replace(Convert.ToString(Convert.ToChar(10)), "");
sNewString = sNewString.Replace(Convert.ToString(Convert.ToChar(13)), "");
return sNewString;
}
public static string[] DriveGetDrive(string sType){
DriveInfo[] ListDrives = DriveInfo.GetDrives();
List<string> lList = new List<string>();
DriveType dType = new DriveType();
int iDriveNum = 0;
lList.Add(Convert.ToString(iDriveNum));
if((sType == "removable") || (sType == "Removable")){
dType = DriveType.Removable;
}
else if((sType == "network") || (sType == "Network")){
dType = DriveType.Network;
}
else if ((sType == "Fixed") || (sType == "fixed"))
{
dType = DriveType.Fixed;
}
else if ((sType == "CDRom") || (sType == "cdrom") || (sType == "CDrom"))
{
dType = DriveType.CDRom;
}
foreach (DriveInfo sDrive in ListDrives)
{
if(sDrive.DriveType.Equals(dType))
{
string sDriveString = Convert.ToString(sDrive);
lList.Add(sDriveString.Remove(sDriveString.Length - 1,1));//Add to RemovableDrive list
}
}
lList[0] = Convert.ToString(lList.Count - 1);
string[] aDrives = lList.ToArray();
return aDrives;
}
}
}
CWCheat Database Fixer:
Code:
using Common;
using System.IO;
using System;
public class MainRun:CommonFunctions
{
static void Main()
{
string path = "";
string[] aDrives = DriveGetDrive("removable");
int iMax = Convert.ToInt16(aDrives[0]);
for(int i = 2;i <= iMax; i++){
if (Directory.Exists(aDrives[i] + "\\seplugins\\"))
{
path = aDrives[i] + "\\seplugins\\cwcheat\\cheat.db";
}
}
if((path==""))
{
MsgBox("No database detected\n\nExiting...");
Environment.Exit(0);
}
string sFileContents = File.ReadAllText(path);
string sCleared = StringStripCR(sFileContents);
sCleared = sCleared.Replace("_", "\r\n_");
sCleared = sCleared.Remove(0, 1);
File.WriteAllText(path, sCleared);
}
}
Autoit
CWCheat Database Fixer:
Code:
#include <File.au3>
$path = ""
$drives = DriveGetDrive("removable")
for $i = 2 to $drives[0]
if FileExists($drives[$i] & "\seplugins") Then
$path = $drives[$i] & "\seplugins\cwcheat\cheat.db"
EndIf
Next
if $path = "" Then
MsgBox(48,"Error","No database detected." & @CRLF & @CRLF & "Exiting...")
Exit
EndIf
$file = FileOpen($path,0)
$data = StringReplace(StringReplace(StringStripCR(FileRead($file)),"_", @CRLF & "_"),@cr,"",1)
$file = FileOpen($path,2)
FileWrite($file,$data)
Now the two DB fixers work exactly the same in exactly the same way with exactly the same result. Oddly enough the c# version was slower on my system than the autoit version, but considerably smaller. It may just be something quirky with my system but I thought I'd let you know. Since they work the same it's easy to look at the code and "translate" between the two.
switch (sType.ToLower())//use .ToLower() to handle the string as all lowercase
{
case "removable": dType = DriveType.Removeable; break;
case "network": dType = DriveTypeNetwork; break;
case "fixed": dType = DriveType.Fixed; break;
case "cdrom": dType = DriveType.CDRom; break;
default: throw new Exception("Invalid type!");
}
As you can see, it saves code space and looks tidier
In case you guys were afraid feel free to ask any questions or make requests for examples here the worst that'll happen is I'll say "I don't know how to do that :/" and it'll allow someone who does know how know they need to post an example
cant you read the OP? 10 poster. use search button for modding apk.
@OP
this is what i have always wanted. i tried learning hex-editing on .gba modifying sites for games but was never able to do it. will get back at this guide after exams. Thanks no thanks button in OT forum
XDA Developer TV Producer Kevin set up his phone to respond to … more
XDA Developers was founded by developers, for developers. It is now a valuable resource for people who want to make the most of their mobile devices, from customizing the look and feel to adding new functionality. Are you a developer?