Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] C++ Save&Load setting and text from file

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Sharel972
Newbie cheater
Reputation: 0

Joined: 02 Nov 2009
Posts: 24
Location: israel

PostPosted: Wed Apr 06, 2011 2:02 pm    Post subject: [C++] C++ Save&Load setting and text from file Reply with quote

---->System.Windows .Forms <----
looking for code that saves the value on txt file or all kind of files and then load them .

same for text i want to make the program that load text from file ...

Thanks for help.
Back to top
View user's profile Send private message MSN Messenger
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed Apr 06, 2011 2:49 pm    Post subject: Reply with quote

For loading you want StreamReader

http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx

For saving you want StreamWriter

http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx

If it's a binary you want BinaryReader

http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx

or BinaryWriter

http://msdn.microsoft.com/en-us/library/system.io.binarywriter.aspx

System.IO NameSpace

http://msdn.microsoft.com/en-us/library/29kt2zfk.aspx

An example of FileStream for saving files or opening them.

http://www.csharp-examples.net/filestream-open-file/

An example I did that creates a binary from predefined hex strings.

Code:
public void CreateFile()
        {
            GenKey(textBox1.Text, textBox1.Text.Length);
            padArray(textBox1.Text);
            shiftInt = Convert.ToUInt32(outPut);
            prevInt = shiftInt;
            for (int n = 0; n < newarrStr.Length; n++)
            {
                Gen(n, textBox1.Text.Length);
            }
            middleBit += myOut;
            string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            using (FileStream stream = new FileStream(path + "\\key-test-alpha.exe", FileMode.Create))
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                { 
                    writer.Write(StringToByteArray(headerBit1));
                    writer.Write(StringToByteArray(headerBit2));
                    writer.Write(StringToByteArray(headerBit3));
                    writer.Write(StringToByteArray(middleBit));
                    writer.Write(StringToByteArray(footerBit1));
                    writer.Write(StringToByteArray(footerBit2));
                    writer.Write(StringToByteArray(footerBit3));
                    writer.Write(StringToByteArray(footerBit4));
                    writer.Write(StringToByteArray(footerBit5));
                    writer.Write(StringToByteArray(footerBit6));
                    writer.Write(5);
                    writer.Close();
                }
            }
            MessageBox.Show("File has been written to your Desktop", "Thank You For Playing", MessageBoxButtons.OK);
        }


Project was abandoned due to the binary being digitally signed thats why there are so many different headers and footers written to the file. It was only after I had gotten this far that I realized it was a signature. Still though you get the idea.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Apr 06, 2011 5:21 pm    Post subject: Reply with quote

Look into serialization if you need to handle a large amount of data. It will be in your best interest to serialize a class into a file rather then writing/reading line by line and so on.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Sharel972
Newbie cheater
Reputation: 0

Joined: 02 Nov 2009
Posts: 24
Location: israel

PostPosted: Thu Apr 07, 2011 11:41 am    Post subject: Reply with quote

thanks
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites