Esempio n. 1
0
        static void LoadCurrentReplayFormat(BinaryReader reader, ref ShavitReplay replay)
        {
            if (replay.Version >= 0x03)
            {
                reader.ReadString(out string map);
                replay.Map   = map;
                replay.Style = reader.ReadByte();
                replay.Track = reader.ReadByte();
            }

            replay.PreFrames       = reader.ReadInt32();
            replay.PreFrames       = Math.Max(0, replay.PreFrames);
            replay.FrameCount      = reader.ReadInt32();
            replay.Frames.Capacity = replay.FrameCount;
            replay.Time            = reader.ReadSingle();

            if (replay.Version >= 0x04)
            {
                replay.SteamID = reader.ReadInt32();
            }
            else
            {
                reader.ReadString(out string auth);
                auth           = auth.Replace("[U:1:", "");
                auth           = auth.Substring(0, auth.Length - 1);
                replay.SteamID = Int32.Parse(auth);
            }

            int size    = Marshal.SizeOf <ReplayFrame>();
            int sizeold = Marshal.SizeOf <ReplayFrameOld>();

            for (int i = 0; i < replay.FrameCount; i++)
            {
                if (replay.Version >= 0x02)
                {
                    var bytes = new byte[size];

                    reader.Read(bytes);

                    var frame = GetStructure <ReplayFrame>(bytes);
                    replay.Frames.Add(frame);
                }
                else
                {
                    var bytes = new byte[sizeold];

                    reader.Read(bytes);

                    var frame = (ReplayFrame)GetStructure <ReplayFrameOld>(bytes);
                    replay.Frames.Add(frame);
                }
            }
        }
Esempio n. 2
0
        static void WriteToJSON(ref ShavitReplay replay, string path)
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            using FileStream stream = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None);
            using var writer        = new StreamWriter(stream, Encoding.UTF8);
            writer.Write("{");
            writer.Write($"\"Version\": {replay.Version},");

            writer.Write($"\"Style\": {replay.Style},");
            writer.Write($"\"Track\": {replay.Track},");
            writer.Write($"\"PreFrames\": {replay.PreFrames},");
            writer.Write($"\"FrameCount\": {replay.FrameCount},");
            writer.Write($"\"SteamID\": {replay.SteamID},");
            writer.Write($"\"Time\": {replay.Time},");
            writer.Write($"\"Map\": \"{replay.Map}\",");
            writer.Write($"\"Format\": \"{replay.Format}\",");
            writer.Write($"\"Frames\": [");

            int i      = 0;
            var buffer = new StringBuilder();

            foreach (ReplayFrame frame in replay.Frames)
            {
                frame.ToJSONObject(buffer);
                if (i++ != replay.FrameCount - 1)
                {
                    buffer.Append(",");
                }
                writer.Write(buffer.ToString());
                buffer.Clear();
            }


            writer.Write("]}");
        }