Compare commits

...

2 Commits

Author SHA1 Message Date
Tarik Hijstek 5946d075d0 Header parsing 2 years ago
Tarik Hijstek 909c0f02ff csharp init 2 years ago

@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/bin/Debug/net7.0/src.dll",
"args": [],
"cwd": "${workspaceFolder}/src",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

41
.vscode/tasks.json vendored

@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/src.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/src.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/src/src.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

@ -22,3 +22,8 @@ Analysis of TF2 Demo files. To help me get more _data driven_ approaches to get
Parsing the demo files. Hopefully once, maybe multiple times.
Only intrested after the start of the official match. Warmup should not count.
Big up for (DemoInfo)[https://github.com/StatsHelix/demoinfo/tree/master/DemoInfo] for providing some inspiration
And thanks to the lads at (demostf)[https://github.com/demostf/parser] for TF2 specific code

@ -0,0 +1,112 @@
// See https://aka.ms/new-console-template for more information
using System.Text;
using DemoParser;
Console.WriteLine("Hello, World!");
//TODO: Config
const string _DemoPath = "/home/sherwood/projects/tf2DemoAnalysis/demos/";
var demoFilePaths = Directory.GetFiles(_DemoPath, "*.dem");
foreach(var currentDemoPath in demoFilePaths){
var demo = File.OpenRead(Path.Combine(_DemoPath, currentDemoPath));
var info = DemoParsing.ReadDemoHeader(demo);
Console.WriteLine($"{currentDemoPath}: Header parsed ");
}
namespace DemoParser{
public record demoHeader(
int demoProtocol,
int networkProtocol,
string ServerName,
string ClientName,
string MapName,
string GameDirectory,
float playbackTime,
int Ticks,
int Frames,
int SignOnLength
);
public class DemoParsing{
public static demoHeader ReadDemoHeader(FileStream stream){
// 8 chars
// int
// int
// 260 chars
// 260 chars
// 260 chars
// 260 chars
//float
//int
//int
//int
//Read the header.
// If the first 8 chars are not "HL2DEMO" then it is not valid.
var buffer = new Byte[8];
stream.Read(buffer, 0, 8);
if(Encoding.ASCII.GetString(buffer) != "HL2DEMO\0"){
throw new Exception($"DemoFile not valid! Filestamp: {Encoding.ASCII.GetString(buffer)}");
}
return new demoHeader(
readInt(stream),
readInt(stream),
readString(stream, 260, Encoding.ASCII),
readString(stream, 260, Encoding.ASCII),
readString(stream, 260, Encoding.ASCII),
readString(stream, 260, Encoding.ASCII),
readFloat(stream),
readInt(stream),
readInt(stream),
readInt(stream)
);
}
public static int readInt(FileStream stream, int offset = 0){
var buffer = new Byte[4];
stream.Read(buffer, offset, 4);
return BitConverter.ToInt32(buffer,0);
}
public static float readFloat(FileStream stream, int offset = 0){
var buffer = new Byte[4];
stream.Read(buffer, offset, 4);
return BitConverter.ToSingle(buffer,0);
}
//Reads until end of string
public static string readString(FileStream stream, int maxLength, Encoding encoding,int offset = 0){
var buffer = new Byte[maxLength];
var readBytes = stream.Read(buffer, offset, maxLength);
var readString = encoding.GetString(buffer).Split('\0')[0];
return readString;
}
}
// static class helper{
// public static string ReadCString(this BinaryReader reader, int length, Encoding encoding)
// {
// return encoding.GetString(reader.ReadBytes(length)).Split(new char[] { '\0' }, 2)[0];
// }
// }
}

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Loading…
Cancel
Save