For my Unity Game, I want to save player data by using text files. Text files can be easily modified and so can the data in them be modified. So, I would like to convert the text files to 0's and 1's. So that when you open it you should see 0101011 instead of readable and editable data. I know that I can use Read Bytes of File and replace the text in the file with this data, but how in the world do I make it data again? I need help with that.
Text files can be easily modified and so can the data in them be modified.
Is this a problem? games are made to have fun, so why do you want to stop the user from gaming how he wants? If it is a competitive multiplayer game, or any type of game involving actual money, you should not rely on any data on the client.
So, I would like to convert the text files to 0's and 1's. So that when you open it you should see 0101011 instead of readable and editable data
Please do not do this, it will just reduce performance for no benefit. If you do not want trivial modification of data, just use a binary serialization format. Or use the Unity provided storage options. Using binary serialization will likely be faster and produce smaller files, at the cost of making modifications more difficult. But you do not seem concerned about the last point.
Converting objects to serialized data and back again is a common operation, and there are great libraries for it. Json is common for textual data, I have used Protobuf .net for binary data, and find it quite fast and easy to use.
Related
I'm trying to build a custom client for a game called slither.io with csharp, but I've run into a small problem: I need to be able to read the binary data sent and received through their websocket.
I should add that you might also need to explain it like I'm dumb.
Here's a screenshot of the binary data I need to decode in C#:
Probably no need to reverse engineer it by yourself, there is a github project with some details. You can learn it and try to incrementally write your own code to parse it, probably in some sandbox you construct with technology you feel most familiar with, like winapi, unity or anything else. Later you will be able to move the code you created in proper modules and environment you need to use
https://github.com/ClitherProject/Slither.io-Protocol/blob/master/Protocol.md#type_l_detail
To parse binary data you will have to learn some additional stuff, writing your own hex viewer will be a relatively simple but suffficient way to learn how to deal with binary. I think this tutorial is good https://www.taniarascia.com/bits-bytes-bases-and-a-hex-dump-javascript/ although it is javascript. You can write some simple console output of parsed data and compare it to some existing hex viewer like HxD
If you want to master it even better you can quickly inspect some Chip8 or other emulators code to see how they parse commands. But in two words you can mae some parsing with logical ors, ands, binary shifts. For example if you are interested in third and forth byte of int (0x1243 (11A3) 12_12_AF) variable named "a" you can write following:
(a >> 3) & 0xFFFF will have 0x11A3 in a result, so in case of these commands you can check the type of it and values of its arguments with similar approach. By basically shifting bytes and covering them with mask of needed size. If you receive this data in byte array it will be even easier, you will just access the byte you want to check.
But in case you reverse engineer some browser game, you can look into some browser js code, make some source owerrides with logs, sometimes put breakpoints if it is possible from game dynamics side and check received ws data in some hex editor like HxD. In case of the snake it can be useful to see how its segments are placed, mouse position and angle is calculated etc
I've been researching about this. Haven't find an answer about it.
Is it possible to insert/delete data to a file without overwriting it? I know there's File.AppendAllText(Path, "Content"); but what about deleting it?
For example.
We got a "Things.CB" File. The content of this file is:
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
I want to delete 7 and 4.
I open the File with my program and then proceed to read this numbers into a List<String>.
When this happens, after doing a RemoveAt() to the list, I got to serialize the file and then save it with a BinaryWriter or a streamWriter.
In this process, we did 2 things, read the whole file, deserializate and then serializate it so we can write it again.
I want to know if it's possible to only open the file, check position of the text then delete/insert and just save it without serializate or reading into list/arrays/etc...
Depending on your OS, if you are on FAT/NTFS you could use Microsoft API functions to play with the FAT/NTFS structure for a certain file.
Consider that you have three parts to your file...1,2,3. You want to delete Part 2. So you would manipulate the FAT so that the end of Part 1 now points to the start of Part 3 - effectively dropping Part 2 from the FAT and making it appear deleted. Then you have not moved any data, simply changed the various clusters and position markers for the file in the FAT.
You would use the same technique for inserting data... Simply adjust the 'pointers' stored in the FAT (file index) so that your new data is in the position you want in the file. Without moving any of your file contents.
These API functions are commonly used by defragmenting programs (Use this term for google searches) and have full access to the file structures (Although I'm not entirely sure that they have enough dynamics for you to skirt around data you want to delete, without moving the other file contents. They should though). To go to a lower level would require C / C++, and could become extremely dangerous (backup everything) and hardware specific. You can access APIs with C#/VB.NET although it is a bit tedious, something like VB6 would be surprisingly quicker to develop around the API functions, although its clunky for general coding.
This will not work over networks, so will only work on drives physically managed by your OS. This may also not work if you want to delete very tiny bits of data, as the granularity of the FAT management functions may not go that small.
I'm working on a program that I want to have some audio output. I would use System.Media.SoundPlayer, except that the data is generated dynamically and in real time. I really just want to set the speaker to a single byte value, and change that value when needed. Any buffers or streams would make this overly complicated.
You can't. System.Media.SoundPlayer works on streams, either dynamically generated like you want or generated from a file.
Learn to work with streams. They're not complicated. Certainly less complicated then dynamically generating audio.
I have the following textual binary representation: "0x255044462D312E340D0A25FFFFFFF..."
I know it's a pdf.
I know it's the textual represantation from a sql server column (image data type).
But im lost to find out how to save this binary to a pdf file on my disk and view the content.
Maybe someone can hint me in the right direction.
Best Regards and Thanks in Advance
You're correct that it is a PDF file (at least it masquerades like on. You have hexadecimally encoded bytes; the first read:
255044462D312E340D0A
%PDF-1.4<CR><LF>
So you appear to have a PDF 1.4 string.
Just take two characters from the string, treat them as hex, convert them to the correct byte and write them to a file. Write binary, not textually (you don't want to add additional line-breaks in there, PDF is too binary to let that work.
(I did the conversion using this site: http://www.dolcevie.com/js/converter.html)
I'm not sure what database you are working with or how you are getting your string that you have above.
Many databases allow you to save binary data as a blob or some other byte array type. I believe in MSSQL this is called an "image" but I am not 100% on that. I would start by looking into the two following links in order. The first link talks about how to pull byte array data from a database. The example is in Visual Basic but should be easily changed to C# if that is what you are using.
The second link contains an example of how to save that byte array data to the file system.
I would also suggest posting some of the code you have tried as well so that the community may comment and point out areas you possibly had misunderstandings on.
1.) http://support.microsoft.com/kb/308042
2.) Save and load MemoryStream to/from a file
http://www.pdfsharp.com/PDFsharp/ can read in binary data and you can call .Save() and it will make the PDF file to disk for you.
I've been looking on certain sites for some time now, but I cant seem to find anything usable about file formats.
There is a certain file format on my computer, which I want to re-create to make add-ons for a program. Unfortunatly I would be the first to do so for that certain format, which makes it all the more hard. There are programs to ádd information to the file, but those programs are not open-source unfortunatly. But that does mean it's possible to figure out the file format somehow.
The closest I came to finding usable information about re-creating a file format was, "open it in notepad or a hex editor, and see if you can find anything usable"..
This certain file format contains information, so nothing like music files or images in case you'r wondering.
I'm just wondering if there is any guide on how to create a file format, or figuring out how an existing file format works. I believe this sort of format is called a Tabulated data format?
It really does depend on the file format.
Ideally, you find some documentation on how the file works, and use that. This is easy if the file uses a public format, so for HTML files or PNG files you can easily find that information. Proprietary formats often have published spec's too, or at least a publicly available API for manipulating them, depending on the company's policy on actively encouraging this sort of extension.
Next best is using examples of working code (whether published source or reverse engineered in itself) that deal with the file as a reference implementation.
Otherwise, reverse engineering is as good as you can do. Opening it in notepad and a hex editor (even with a binary format, looking at it parsed as text can tell you something; even with a text-based format, looking at it in a hex editor can tell you if they are making use of non-printable characters) is indeed the way to go. It's a detective job and while sometimes easy, often very hard, esp. since you may miss ways they deal with edge-cases that aren't hit in the samples you use.
The difficulty with obscure formats distributed with games is that they are often compiled from either a declarative definition language, a scripting language or directly from a set of resources like textures and meshes.
In some games, one compiled file will contain bits and pieces of all of the above, with no available documentation on the tools and formats used to piece it together. Some people call that "fun".
If you can't get anything from the hex, can't find any documentation and can't find a tool to read the file, you're probably best off asking the community to see if anyone is familiar with the technology.