1 Attachment(s)
I am very new to Visual Studio and need some guidance.
Currently there are 2 files in the client that control parts of the resolution.
1st is the HTStartup.cfg located in Main\system folder for the client.
It controls whether it is Windowed or Full screen.
It is easy enough to configure with ease to make a selection in visual studio.
2nd is HTUserSetting.sys located in the Main folder for the client.
The only way it can be altered is by hexing it.
The question is for me as follows.
Is there anyway to make a group box with both the windowed option and also being able to edit the hex in Visual Studio 2010 so that I can create a new launcher that does both? I know how to design it easily but, I do NOT know the actual code that would be required to do such a thing.
The pictures are as follows and if anyone has any ideas it would be greatly appreciated. Thank you for your time.
Attachment 137821
Re: I am very new to Visual Studio and need some guidance.
HTStartup.cfg is an INI setting file parser. To read it's settings you can use my IniFile class:
PHP Code:
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
/// <summary>
/// Create a New INI file to store or load data
/// </summary>
public class IniFile
{
private string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
/// <summary>
/// INI file Constructor.
/// </summary>
/// <PARAM name="INIPath"></PARAM>
public IniFile(string iniPath)
{
this.path = iniPath;
}
/// <summary>
/// Write Data to the INI File
/// </summary>
/// <param name="section"></param>
/// Section name
/// <param name="key"></param>
/// Key Name
/// <param name="value"></param>
/// Value Name
public void Write(string section, string key, string value)
{
WritePrivateProfileString(section, key, value, this.path);
}
/// <summary>
/// Write all data to INI file.
/// </summary>
/// <param name="data">Selection-Key-Value - Collection.</param>
public void WriteAll(Dictionary<string, Dictionary<string, string>> data)
{
foreach (string selection in data.Keys)
{
foreach (string key in data[selection].Keys)
{
this.Write(selection, key, data[selection][key]);
}
}
}
/// <summary>
/// Read Data Value From the Ini File
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <returns></returns>
public string Read(string section, string key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(section, key, "", temp, 255, this.path);
return temp.ToString();
}
/// <summary>
/// Read all data from INI file.
/// </summary>
/// <returns>Selection-Key-Value - Collection.</returns>
public Dictionary<string, Dictionary<string, string>> ReadAll()
{
Dictionary<string, Dictionary<string, string>> result = new Dictionary<string, Dictionary<string, string>>();
/*
* Try to read the content of a simle INI file
*/
List<string> selections = this.getSelections();
foreach (string selection in selections)
{
/*
* Get the keys
*/
List<string> keys = this.getKeys(selection);
foreach (string key in keys)
{
/*
* Now store the content
*/
if (!result[selection].ContainsKey(key))
{
result[selection].Add(key, "");
}
result[selection][key] = this.Read(selection, key);
}
}
return result;
}
/// <summary>
/// Shows the Path.
/// </summary>
/// <returns>Path to INI file.</returns>
public override string ToString()
{
return this.path;
}
private List<string> getKeys(string selection)
{
StringBuilder temp = new StringBuilder(32768);
GetPrivateProfileString(selection, null, null, temp, 32768, this.path);
List<string> result = new List<string>(temp.ToString().Split('\0'));
result.RemoveRange(result.Count - 2, 2);
return result;
}
private List<string> getSelections()
{
StringBuilder temp = new StringBuilder(65536);
GetPrivateProfileString(null, null, null, temp, 65536, this.path);
List<string> result = new List<string>(temp.ToString().Split('\0'));
result.RemoveRange(result.Count - 2, 2);
return result;
}
}
Use ReadAll and WriteAll to load and save the settings.
To read the HTUserSetting.sys use a byte array and stream read and stream write it. Google for it.
Design your options in the designer and set the values of the controls on load by reading such files. Then use a save button event or the form close event to overwrite the data again.
Re: I am very new to Visual Studio and need some guidance.
i figured out the cfg file since it is no different than a text file. thank you for your time and experience. i will google byte array now.
Re: I am very new to Visual Studio and need some guidance.
I am having some difficulty trying to figure out how to implement this into my launcher. Here is my code so far for the cfg file. But, I still don't know how to get the string to byte array setup. Like I said I am an amateur at this coding and I apologize to everyone. I know there are better things to do.
Quote:
Imports Launcher.GameLauncher
Public Class SettingsForm
Private Sub Settings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
EnableWindowed.Checked = My.Settings.Enablewindowed
End Sub
Private Sub SaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveBtn.Click
GetINI(Application.StartupPath & "\system\HTStartup.cfg")
SaveToINI("RENDERER", "windowed", EnableWindowed.Checked)
My.Settings.Enablewindowed = EnableWindowed.Checked
My.Settings.Save()
Me.Close()
End Sub
Private Sub CloseBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseBtn.Click
Me.Close()
End Sub
End Class
Here is the ultimate design that I am attempting to do in visual basic 2010 express.
http://img401.imageshack.us/img401/6475/3hsi.png
Using Cff Explorer this is what I have extracted from the hex so far in. I am not sure if this even looks right since I am very new to this.
Quote:
unsigned char data[23] = {
0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
Thank you for your time..[/QUOTE]
Re: I am very new to Visual Studio and need some guidance.
Compare your unsigned char data array with your content:
0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, ...
http://forum.ragezone.com/attachment...n-settings.png
It's the same you see?
Now Idk what hex value is what option exactly, thats your turn.
You can either work with any char array or prefer byte array I would prefer. byte is unsigned automatically, 8 bit number (0-255). You will work with the left numbers, your hex editor will display the right when viewing the file:
Code:
DEC BIN HEX
00 0000 0000 00
01 0000 0001 01
02 0000 0010 02
03 0000 0011 03
04 0000 0100 04
05 0000 0101 05
06 0000 0110 06
07 0000 0111 07
08 0000 1000 08
09 0000 1001 09
10 0000 1010 0A
11 0000 1011 0B
12 0000 1100 0C
13 0000 1101 0D
14 0000 1110 0E
15 0000 1111 0F
16 0001 0000 10
17 0001 0001 11
18 0001 0010 12
19 0001 0011 13
....
Use File.ReadAllBytes to receive your byte array. And use File.WriteAllBytes to send your byte array to file again.
Once you read it, you can scan the positions for X resolution in index 1 and 2 of your byte array, etc.
PHP Code:
byte[] test = File.ReadAllBytes("anyfile.sys");
if (test.length > 10)
{
byte x1 = test[1];
byte x2 = test[2];
byte y1 = test[5];
byte y2 = test[6];
byte cpu = test[9];
}
Now you just need to know what value stands for what to preset options in your form.
On save create a new byte array after reading the states of your form (the user changed) and changing your byte variables:
PHP Code:
byte[] test = new byte[] {
1, x1, x2, 0, 0, y1, y2, 0, 0, cpu, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
File.WriteAllBytes("anyfile.sys", test);
Alternatively you can even write:
PHP Code:
byte[] test = new byte[] {
0x01, x1, x2, 0x00, 0x00, y1, y2, 0x00, 0x00, cpu, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
};
File.WriteAllBytes("anyfile.sys", test);
So you can still work with hex values instead of decimal values.
Re: I am very new to Visual Studio and need some guidance.
The following site is how I obtained the information from the .sys file in hex. It is an awesome site for trying to figure out the hex code and what is stands for. Also I manually altered the hex code with CFF Explorer to verify what it does within the file and also to make sure that I could alter the graphics in the game with success.
Decimal to Hex Converter
So essentially 0x00 0x04 = 1024 and 0x00 0x03 = 768 and 0x10 = 16 which can be changed to 0x20 for 32 as demonstrated in the website even though it is backwards from the .sys file. Changing these values in the hex manually can be done with ease but, what I am attempting to do is to have a selection with dropdownlist do this automatically in the "Settings" window and change the hex automatically as well as adding the check boxes to change it from 16 bit graphics to 32 bit graphics. With the code provided I have already given the option to change it to a Windowed setup with ease but, I have absolutely no idea on the byte array to add it to the above code for the options. Anyhow I will research it more and once again Thank You.
Re: I am very new to Visual Studio and need some guidance.
Quote:
Originally Posted by
jbeitz107
Who needs that for single values? Learn to count binary numbers and hexadecimals while sleeping. At least the 2 number system is quite easier than our ten number system.
Quote:
Originally Posted by
jbeitz107
So essentially 0x00 0x04 = 1024 and 0x00 0x03 = 768 and 0x10 = 16 which can be changed to 0x20 for 32 as demonstrated in the website even though it is backwards from the .sys file.
As first, find out what values you can get at all. so 800x600, 1024x768, etc. Find out all options that are possible, set its values, test your game took the desired resolution and note it down. If you do not know what options you have, why creating options at all?
Quote:
Originally Posted by
jbeitz107
Changing these values in the hex manually can be done with ease but, what I am attempting to do is to have a selection with dropdownlist do this automatically in the "Settings" window and change the hex automatically as well as adding the check boxes to change it from 16 bit graphics to 32 bit graphics. With the code provided I have already given the option to change it to a Windowed setup with ease but, I have absolutely no idea on the byte array to add it to the above code for the options. Anyhow I will research it more and once again Thank You.
The above example explains you how to do it already.
In the save event after saving the ini, do the following:
PHP Code:
byte x, y;
string[] resolution = this.ddlResolution.SelectedText.Split('x'); // this is your drop down list
switch(resolution[0])
{
case "1024": x = 0x04; break;
// case "800": // ADD MORE HERE
}
switch(resolution[1])
{
case "768": y = 0x03; break;
// MORE HERE TOO
}
Then use two radio buttons for the bit. Do not use check boxes as you can select all of them, not just one.
PHP Code:
byte cpu = this.rb32bit.Checked ? 0x20 : 0x10;
Then save it like I posted:
PHP Code:
byte[] test = new byte[] {
0x01, 0x00, x, 0x00, 0x00, 0x00, y, 0x00, 0x00, cpu, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
};
File.WriteAllBytes("anyfile.sys", test);
It's impossible to explain it easier, I already gave you the full example now. If you still cannot handle it, I will not help you. This is a little bit ridiculously easy. You should either get a book and learn the basics. For this time it's fine, but doing more with C# you should learn the basics first.
Do not forget to like and rep my helpful posts.
Re: I am very new to Visual Studio and need some guidance.
Ok. This is what I have achieved so far. I can set it to 800x600x16 but, I am having problems with it doing the 2nd selection. I don't know what is wrong here but, can you help with that?
Quote:
If ResolutionSelector.SelectedIndex = 0 Then
Dim fs As New IO.FileStream("HTUserSetting.sys", FileMode.Open, FileAccess.ReadWrite)
Dim strHex As String = "012003000058020000100000000302020202020202000001"
fs.Position = &H0
For j As Integer = 0 To strHex.Length - 1 Step 2
fs.WriteByte(CByte(Conversion.Val("&H" & strHex.Substring(j, 2))))
Next
fs.Close()
fs.Dispose()
ElseIf ResolutionSelector.SelectedIndex = 2 Then
Dim fs As New IO.FileStream("HTUserSetting.sys", FileMode.Open, FileAccess.ReadWrite)
Dim strHex As String = "010004000000030000100000000302020202020202000001"
fs.Position = &H0
For j As Integer = 0 To strHex.Length - 1 Step 2
fs.WriteByte(CByte(Conversion.Val("&H" & strHex.Substring(j, 2))))
Next
fs.Close()
fs.Dispose()
I just want it to continue to 1024x768x16 in the dropdownlist. Thanks
Nevermind. I removed the dropdownlist and made it button options instead. So much simpler. Thanks