Jump to content

save var


Wiebrendh

Recommended Posts

you mean a data into .ini file or something like that?

 

Hmm no, just like money. It is stored somewhere, but the player can't edit it, only by using code

Link to comment
Share on other sites

LordOfTheBongs

use encryption

namespace EncryptionExample{    using System;    using System.Text;    using System.Security.Cryptography;     internal class Security    {        private static byte[] entropy = Encoding.Unicode.GetBytes("LordOfTheBongs");//this is used in the algorithm for encryption and you can make any random string value u like... u should read about entropy online for what this is for         internal static string EncryptString(string input)        {            byte[] encryptedData = ProtectedData.Protect(                Encoding.Unicode.GetBytes(input),                entropy,                DataProtectionScope.CurrentUser);            return Convert.ToBase64String(encryptedData);        }         internal static string DecryptString(string encryptedData)        {            try            {                byte[] decryptedData = ProtectedData.Unprotect(                    Convert.FromBase64String(encryptedData),                    entropy,                    DataProtectionScope.CurrentUser);                return Encoding.Unicode.GetString(decryptedData);            }            catch            {                return string.Empty;            }        }    }}

example of use...

int someNumber = 12;//u wanna save this but not let player edit the dat file //first convert to stringstring saveValue = someNumber.ToString(); //i'll assume u use streamwriter class to write to your dat file and u put a setting on it's own linestreamWriter.WriteLine(Security.EncryptString(saveValue)); //then to load ill assume u use streamreader class and the reader is in position to read the line with encrypted stringint someNumber = int.Parse(Security.DecryptString(reader.ReadLine()));

you could also write the byte value of the string and would look crazy in a text file but that is easier to "hack" i guess

Edited by LordOfTheBongs
Link to comment
Share on other sites

use encryption

namespace EncryptionExample{    using System;    using System.Text;    using System.Security.Cryptography;     internal class Security    {        private static byte[] entropy = Encoding.Unicode.GetBytes("LordOfTheBongs");//this is used in the algorithm for encryption and you can make any random string value u like... u should read about entropy online for what this is for         internal static string EncryptString(string input)        {            byte[] encryptedData = ProtectedData.Protect(                Encoding.Unicode.GetBytes(input),                entropy,                DataProtectionScope.CurrentUser);            return Convert.ToBase64String(encryptedData);        }         internal static string DecryptString(string encryptedData)        {            try            {                byte[] decryptedData = ProtectedData.Unprotect(                    Convert.FromBase64String(encryptedData),                    entropy,                    DataProtectionScope.CurrentUser);                return Encoding.Unicode.GetString(decryptedData);            }            catch            {                return string.Empty;            }        }    }}

example of use...

int someNumber = 12;//u wanna save this but not let player edit the dat file //first convert to stringstring saveValue = someNumber.ToString(); //i'll assume u use streamwriter class to write to your dat file and u put a setting on it's own linestreamWriter.WriteLine(Security.EncryptString(saveValue)); //then to load ill assume u use streamreader class and the reader is in position to read the line with encrypted stringint someNumber = int.Parse(Security.DecryptString(reader.ReadLine()));

you could also write the byte value of the string and would look crazy in a text file but that is easier to "hack" i guess

 

That looks pretty difficult for a beginner, but gonna figure it out

 

And i have to idea what streamwriter is..

Edited by Wiebrendh
Link to comment
Share on other sites

LordOfTheBongs

the Security class can be copied and pasted as is into your script's namespace. If you use visual studio add a class yo your project and paste all my code over the new class u added, make sure u change my example namespace name to your project's namespace then u can change any string to an encrypted value and u can read any value your script previously encrypted...

 

then it is simple to use as u can see in the 2nd code box. to encrypt and write to a dat file is 1 line of code... it looks like a lot on first glance but it really isnt ;)

 

just ask for help if u need

Edited by LordOfTheBongs
Link to comment
Share on other sites

the Security class can be copied and pasted as is into your script's namespace. If you use visual studio add a class yo your project and paste all my code over the new class u added, make sure u change my example namespace name to your project's namespace then u can change any string to an encrypted value and u can read any value your script previously encrypted...

 

then it is simple to use as u can see in the 2nd code box. to encrypt and write to a dat file is 1 line of code... it looks like a lot on first glance but it really isnt ;)

 

just ask for help if u need

 

I made a new .cs file, added that script to it, edited the namespace, and what do i have to place in the "LordOfTheBongs" thing, and how do i get the encrypted data in the first class?

Link to comment
Share on other sites

Here is a serialization example, I think it's a much more out of the box solution.

 

Here is a wrapper of the msdn example:

    static void Serialize(string fullFilePath, object data)    {        FileStream fs = new FileStream(fullFilePath, FileMode.Create);        try        {            new BinaryFormatter().Serialize(fs, data);        }        catch (SerializationException e)        {            // Serialization failed        }        finally        {            fs.Close();        }    }    static object Deserialize(string fullFilePath)    {        object result;        FileStream fs = new FileStream(fullFilePath, FileMode.Open);        try        {            result = new BinaryFormatter().Deserialize(fs);        }        catch (SerializationException e)        {            // Deserialization failed        }        finally        {            fs.Close();        }        return result;    }    // Usage    string data = "4410d99cefe57ec2c2cdbd3f1d5cf862bb4fb6f8";    // Save data    Serialize(@"C:\data.dat", data);    // Load data    string dataBack = (string)Deserialize(@"C:\data.dat");
Edited by pedro2555
Link to comment
Share on other sites

LordOfTheBongs

 

the Security class can be copied and pasted as is into your script's namespace. If you use visual studio add a class yo your project and paste all my code over the new class u added, make sure u change my example namespace name to your project's namespace then u can change any string to an encrypted value and u can read any value your script previously encrypted...

 

then it is simple to use as u can see in the 2nd code box. to encrypt and write to a dat file is 1 line of code... it looks like a lot on first glance but it really isnt ;)

 

just ask for help if u need

 

I made a new .cs file, added that script to it, edited the namespace, and what do i have to place in the "LordOfTheBongs" thing, and how do i get the encrypted data in the first class?

 

u can change to anything... it simply needs to always be the same string value... this entropy object is used in the math formula that calculates the encrypted string... along with your user credentials, it makes the common encryption algorithm that everyone uses from .net unique

 

u should read about what entropy is, google it ;)

 

the first code box is copy pasted onto your new class file and u changed the namespace to your project's namespace... so good. Then depending how u write to the file just know u need to use the encrypt method on the string that u write and then use decrypt on the encrypted string u read (2nd code box)

Link to comment
Share on other sites

 

Here is a serialization example, I think it's a much more out of the box solution.

 

Here is a wrapper of the msdn example:

    static void Serialize(string fullFilePath, object data)    {        FileStream fs = new FileStream(fullFilePath, FileMode.Create);        try        {            new BinaryFormatter().Serialize(fs, data);        }        catch (SerializationException e)        {            // Serialization failed        }        finally        {            fs.Close();        }    }    static object Deserialize(string fullFilePath)    {        object result;        FileStream fs = new FileStream(fullFilePath, FileMode.Open);        try        {            result = new BinaryFormatter().Deserialize(fs);        }        catch (SerializationException e)        {            // Deserialization failed        }        finally        {            fs.Close();        }        return result;    }    // Usage    string data = "4410d99cefe57ec2c2cdbd3f1d5cf862bb4fb6f8";    // Save data    Serialize(@"C:\data.dat", data);    // Load data    string dataBack = (string)Deserialize(@"C:\data.dat");

nothing gives error, expect for the one of the last lines of code..

Serialize(@"C:\data.dat", data); 

this line gives 2 errors..

error one:

Invalid token ')' in class, struct, or interface member declaration

error two:

Method must have a return type

Link to comment
Share on other sites

Man, do you know anything about C# at all ?

 

Off course it trows those errors, that is just an example sample. You should place the lines bellow // Usage somewhere in your code flow, eg: where you need to save/load your data.

 

The rest is just a ready made methods.

Link to comment
Share on other sites

Man, do you know anything about C# at all ?

 

Off course it trows those errors, that is just an example sample. You should place the lines bellow // Usage somewhere in your code flow, eg: where you need to save/load your data.

 

The rest is just a ready made methods.

 

Yeah, i know a little bit about C# and that it :(

Link to comment
Share on other sites

 

Man, do you know anything about C# at all ?

 

Off course it trows those errors, that is just an example sample. You should place the lines bellow // Usage somewhere in your code flow, eg: where you need to save/load your data.

 

The rest is just a ready made methods.

 

Yeah, i know a little bit about C# and that it :(

 

 

Well then, you should know what code flow is.

 

What I and LorfOfTheBongs provided was just 2 functions, and instructions on how to use them on your code flow. It isn't just copy and paste everything into a .cs file and everything will automagically work.

 

I suggest you to learn a bit more about the language:

 

http://msdn.microsoft.com/en-us/vstudio/hh341490 -> For complete begginers

http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx -> Nice set of simple tutorials

 

http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners -> If you are American (no offense intended)

http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx -> To get your head around some more stuff

 

http://gtaxscripting.blogspot.com/p/tutorials.html -> Alternatively, you can wrap up C#, learn VB.NET and then (and only then) follow JulioNIB's tutorials on GTA Scripting with VB.NET

 

With that done, I will assure you that you can come here, ask questions and understand the replies.

Edited by pedro2555
Link to comment
Share on other sites

 

 

Man, do you know anything about C# at all ?

 

Off course it trows those errors, that is just an example sample. You should place the lines bellow // Usage somewhere in your code flow, eg: where you need to save/load your data.

 

The rest is just a ready made methods.

 

Yeah, i know a little bit about C# and that it :(

 

 

Well then, you should know what code flow is.

 

What I and LorfOfTheBongs provided was just 2 functions, and instructions on how to use them on your code flow. It isn't just copy and paste everything into a .cs file and everything will automagically work.

 

I suggest you to learn a bit more about the language:

 

http://msdn.microsoft.com/en-us/vstudio/hh341490 -> For complete begginers

http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx -> Nice set of simple tutorials

 

http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners -> If you are American (no offense intended)

http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx -> To get your head around some more stuff

 

http://gtaxscripting.blogspot.com/p/tutorials.html -> Alternatively, you can wrap up C#, learn VB.NET and then (and only then) follow JulioNIB's tutorials on GTA Scripting with VB.NET

 

With that done, I will assure you that you can come here, ask questions and understand the replies.

 

Oke, thanks, gonna watch it all, is this http://thenewboston.org/list.php?cat=15 also usefull to understand this?

Edited by Wiebrendh
Link to comment
Share on other sites

 

 

 

Man, do you know anything about C# at all ?

 

Off course it trows those errors, that is just an example sample. You should place the lines bellow // Usage somewhere in your code flow, eg: where you need to save/load your data.

 

The rest is just a ready made methods.

 

Yeah, i know a little bit about C# and that it :(

 

 

Well then, you should know what code flow is.

 

What I and LorfOfTheBongs provided was just 2 functions, and instructions on how to use them on your code flow. It isn't just copy and paste everything into a .cs file and everything will automagically work.

 

I suggest you to learn a bit more about the language:

 

http://msdn.microsoft.com/en-us/vstudio/hh341490 -> For complete begginers

http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx -> Nice set of simple tutorials

 

http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners -> If you are American (no offense intended)

http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx -> To get your head around some more stuff

 

http://gtaxscripting.blogspot.com/p/tutorials.html -> Alternatively, you can wrap up C#, learn VB.NET and then (and only then) follow JulioNIB's tutorials on GTA Scripting with VB.NET

 

With that done, I will assure you that you can come here, ask questions and understand the replies.

 

Oke, thanks, gonna watch it all, is this http://thenewboston.org/list.php?cat=15 also usefull to understand this?

 

Quite comprehensive at first glance, so yes, useful. But be sure to understand the concepts used in the videos.

Link to comment
Share on other sites

 

 

 

 

Man, do you know anything about C# at all ?

 

Off course it trows those errors, that is just an example sample. You should place the lines bellow // Usage somewhere in your code flow, eg: where you need to save/load your data.

 

The rest is just a ready made methods.

 

Yeah, i know a little bit about C# and that it :(

 

 

Well then, you should know what code flow is.

 

What I and LorfOfTheBongs provided was just 2 functions, and instructions on how to use them on your code flow. It isn't just copy and paste everything into a .cs file and everything will automagically work.

 

I suggest you to learn a bit more about the language:

 

http://msdn.microsoft.com/en-us/vstudio/hh341490 -> For complete begginers

http://msdn.microsoft.com/en-us/library/67ef8sbd.aspx -> Nice set of simple tutorials

 

http://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners -> If you are American (no offense intended)

http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx -> To get your head around some more stuff

 

http://gtaxscripting.blogspot.com/p/tutorials.html -> Alternatively, you can wrap up C#, learn VB.NET and then (and only then) follow JulioNIB's tutorials on GTA Scripting with VB.NET

 

With that done, I will assure you that you can come here, ask questions and understand the replies.

 

Oke, thanks, gonna watch it all, is this http://thenewboston.org/list.php?cat=15 also usefull to understand this?

 

Quite comprehensive at first glance, so yes, useful. But be sure to understand the concepts used in the videos.

 

Oke, nice that is a very good teacher

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.