How to read Slither IO websocket binary data with c# - c#

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

Related

Splitting and Saving Mp4 In Unity/C#

So I want to make an application that will be able to split an mp4 into various segments and save them as separate videos, but I am having trouble with the approach to something like this. I can convert the mp4 into a byte array, but I am unable to properly trim or cut the bytes without the saved video being either corrupted or just not working. Is there a way to achieve this, either by using a byte array or by using another solution?
I know C# is not the best way to go about doing something like this, but it's my preferred coding language and I am trying to make an app only for myself, so I don't mind if the code is a bit messy or slow.
If you are trying to make an audio editor, it might be just better to use one like audacity (it is open source) or any other.

How to encode and decode a text file to binary in c#?

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.

How to convert stored MP3 file data (byte[]) into a float[] Unity can use as AudioSource-Data?

I did tons of research during the last days and nothing helped me out for my special problem. I am writing my own music engine for a Unity3d game and for this I created custom files containing the mp3 data and other information.
What I'm trying to do now is to take these split up mp3-byte-arrays (which can be played when I store them individually, I tested it - so the audio data seems to be fine) and convert them to Unity's AudioSource(s) somehow. I think converting the byte[] into a float[] containing the needed sample data of my audio would be enough, because audioClip.setData( ... ); should do the trick then (I hope).
But I continuously fail at decompressing and/or converting my raw mp3 buffer[] to anything like float[] - and even if I somehow succeed, the only thing I hear is nasty whitenoise-like nonsense.
Any ideas? I would love to hear from you and solve this problem!
Implementation of a decompression algorithm that will take a compressed MP3 stream and output it as uncompressed data is not a trivial task. You can either find a library that does this (I am not aware of any), or work around the issue in some way.
You can use untiy engine to decompress (aka play back) through an AudioSource, and sample it then, or execute some FFMPEG command line to get the wav. Most ways of doing it are cumbersome and ideally you should find a way of not doing it at all.
byte[] or float[] is not really a signifficant difference here - the difference is encoded vs raw

Edit VSAM file using C#

We are looking at different ways to update a VSAM file.
One of the things that we would like to do is to stop writing any new cobol code.
We were wondering is it possible to download a VSAM file from the Main Frame to a Windows Server, then use a C# program to edit it, then transfer it back to the Main frame?
Has anyone tried this?
And yes we are moving away from the use of VSAM, but it takes time.
There are plenty of other options for updating a VSAM file other than a COBOL program.
Transferring the file and and back again seems a perverse and error prone way to update a simple VSAM file. Most VSAM files contain a mix of character, integer and packed decimal data, C# plain cannot handle mainframe packed decimal and any attempt to translate EBDCIC to ASCII during file transfer will corrupt the packed decimal and binary values, so, you will need to manipulate raw EBCDIC characters.
Obviously you can write a COBOL program! (seems perverse not to!)
You could also write a C, C++, Java or PL/1 program all of which run on the mainframe, all of which have VSAM support.
You could extract to a sequential file update with a script (zsh, Rexx, PERL etc. etc.) and reload. (Your site may have an add-in that allows direct update from Rexx).
Most largish mainframe sites have an add on utility like File-Aid, Startool or Ditto which allow direct editing of VSAM files.
The MS way would be to use Biztalk Microsoft Host Integration Server to access VSAM.
There might be other non-MS drivers, which I am not aware of - maybe via DB2 Windows drivers.

opening a file format

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.

Categories