Skip to content

Commit 6772ca7

Browse files
author
CSDotNET
committedJul 23, 2023
added all files
1 parent 2a04d51 commit 6772ca7

36 files changed

+1351
-0
lines changed
 

‎.idea/.idea.TetrLoader/.idea/.gitignore

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/.idea.TetrLoader/.idea/encodings.xml

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/.idea.TetrLoader/.idea/indexLayout.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/.idea.TetrLoader/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ConsoleApp/ConsoleApp.csproj

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\TetrLoader\TetrLoader.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

‎ConsoleApp/Program.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Security.Cryptography.X509Certificates;
2+
using System.Text;
3+
using TetrLoader;
4+
5+
string jsonData = string.Empty;
6+
using (StreamReader reader = new StreamReader(@"C:\Users\CSDotNET\Downloads\zero-replay3.ttrm", Encoding.UTF8))
7+
{
8+
jsonData = reader.ReadToEnd();
9+
}
10+
11+
var IReplayData = ReplayLoader.ParseReplay(jsonData, ReplayKind.TTRM);
12+
13+
Console.WriteLine("a");
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Diagnostics;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
using TetrLoader.Enum;
5+
6+
namespace TetrLoader.Converter;
7+
8+
public class EventTypeConverter : JsonConverter<EventType>
9+
{
10+
public override EventType Read(ref Utf8JsonReader reader, Type typeToConvert,
11+
JsonSerializerOptions options)
12+
{
13+
switch (reader.GetString())
14+
{
15+
case "start":
16+
return EventType.Start;
17+
case "end":
18+
return EventType.End;
19+
case "full":
20+
return EventType.Full;
21+
case "keydown":
22+
return EventType.Keydown;
23+
case "keyup":
24+
return EventType.Keydown;
25+
case "targets":
26+
return EventType.Targets;
27+
case "ige":
28+
return EventType.Ige;
29+
default:
30+
throw new JsonException("Unknown event type.");
31+
}
32+
}
33+
34+
public override void Write(Utf8JsonWriter writer, EventType value, JsonSerializerOptions options)
35+
{
36+
switch (value)
37+
{
38+
case EventType.End:
39+
writer.WriteStringValue("end");
40+
return;
41+
case EventType.Full:
42+
writer.WriteStringValue("full");
43+
return;
44+
case EventType.Ige:
45+
writer.WriteStringValue("ige");
46+
return;
47+
case EventType.Keydown:
48+
writer.WriteStringValue("keydown");
49+
return;
50+
case EventType.Keyup:
51+
writer.WriteStringValue("keyup");
52+
return;
53+
case EventType.Start:
54+
writer.WriteStringValue("start");
55+
return;
56+
case EventType.Targets:
57+
writer.WriteStringValue("targets");
58+
return;
59+
default:
60+
throw new JsonException("Unknown event type.");
61+
}
62+
}
63+
}

‎TetrLoader/Enum/EventType.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Text.Json.Serialization;
2+
using TetrLoader.Converter;
3+
4+
namespace TetrLoader.Enum;
5+
6+
[JsonConverter(typeof(EventTypeConverter))]
7+
public enum EventType
8+
{
9+
Start,
10+
End,
11+
Full,
12+
Keydown,
13+
Keyup,
14+
Targets,
15+
Ige
16+
}

‎TetrLoader/IReplayData.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using TetrLoader.JsonClass.Event;
2+
3+
namespace TetrLoader
4+
{
5+
public interface IReplayData
6+
{
7+
List<Event>? GetReplayEvents(int playerIndex, int replayIndex);
8+
int GetPlayerCount();
9+
Stats GetReplayStats(int playerIndex, int replayIndex);
10+
int GetGameTotalFrames(int replayIndex);
11+
string GetUsername(int playerIndex);
12+
int GetReplayCount();
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
}
23+
24+
25+
}

‎TetrLoader/JsonClass/ConfigData.cs

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
namespace TetrLoader.JsonClass
2+
{
3+
public class ConfigData
4+
{
5+
6+
}
7+
8+
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
9+
public class Bgmtweak
10+
{
11+
}
12+
13+
public class Controls
14+
{
15+
public string? style { get; set; }
16+
public Custom? custom { get; set; }
17+
public double? sensitivity { get; set; }
18+
public string? vibration { get; set; }
19+
}
20+
21+
public class Custom
22+
{
23+
public List<string>? moveLeft { get; set; }
24+
public List<string>? moveRight { get; set; }
25+
public List<string>? softDrop { get; set; }
26+
public List<string>? hardDrop { get; set; }
27+
public List<string>? rotateCCW { get; set; }
28+
public List<string>? rotateCW { get; set; }
29+
public List<string>? rotate180 { get; set; }
30+
public List<string>? hold { get; set; }
31+
public List<string>? exit { get; set; }
32+
public List<string>? retry { get; set; }
33+
public List<string>? chat { get; set; }
34+
public List<object>? target1 { get; set; }
35+
public List<object>? target2 { get; set; }
36+
public List<object>? target3 { get; set; }
37+
public List<object>? target4 { get; set; }
38+
public List<string>? menuUp { get; set; }
39+
public List<string>? menuDown { get; set; }
40+
public List<string>? menuLeft { get; set; }
41+
public List<string>? menuRight { get; set; }
42+
public List<string>? menuBack { get; set; }
43+
public List<string>? menuConfirm { get; set; }
44+
public List<object>? openSocial { get; set; }
45+
}
46+
47+
public class Electron
48+
{
49+
public string? loginskip { get; set; }
50+
public string? frameratelimit { get; set; }
51+
public bool? presence { get; set; }
52+
public bool? taskbarflash { get; set; }
53+
public bool? anglecompat { get; set; }
54+
public bool? adblock { get; set; }
55+
}
56+
57+
public class Gameoptions
58+
{
59+
public bool? pro_40l { get; set; }
60+
public bool? pro_40l_alert { get; set; }
61+
public bool? pro_40l_retry { get; set; }
62+
public bool? stride_40l { get; set; }
63+
public bool? pro_blitz { get; set; }
64+
public bool? pro_blitz_alert { get; set; }
65+
public bool? pro_blitz_retry { get; set; }
66+
public bool? stride_blitz { get; set; }
67+
}
68+
69+
70+
71+
public class Notifications
72+
{
73+
public bool? suppress { get; set; }
74+
public bool? forcesound { get; set; }
75+
public string? online { get; set; }
76+
public string? offline { get; set; }
77+
public string? dm { get; set; }
78+
public string? dm_pending { get; set; }
79+
public string? invite { get; set; }
80+
public string? other { get; set; }
81+
}
82+
83+
public class Root
84+
{
85+
public Controls? controls { get; set; }
86+
public Handling? handling { get; set; }
87+
public Volume? volume { get; set; }
88+
public Video? video { get; set; }
89+
public Gameoptions? gameoptions { get; set; }
90+
public Electron? electron { get; set; }
91+
public Notifications? notifications { get; set; }
92+
}
93+
94+
public class Video
95+
{
96+
public string? graphics { get; set; }
97+
public string? caching { get; set; }
98+
public string? actiontext { get; set; }
99+
public double? particles { get; set; }
100+
public double? background { get; set; }
101+
public string? bounciness { get; set; }
102+
public string? shakiness { get; set; }
103+
public double? gridopacity { get; set; }
104+
public double? boardopacity { get; set; }
105+
public double? shadowopacity { get; set; }
106+
public string? zoom { get; set; }
107+
public bool? alwaystiny { get; set; }
108+
public bool? nosuperlobbyanim { get; set; }
109+
public bool? colorshadow { get; set; }
110+
public bool? sidebyside { get; set; }
111+
public bool? spin { get; set; }
112+
public bool? chatfilter { get; set; }
113+
public object? background_url { get; set; }
114+
public object? background_usecustom { get; set; }
115+
public bool? nochat { get; set; }
116+
public bool? hideroomids { get; set; }
117+
public bool? emotes { get; set; }
118+
public bool? emotes_anim { get; set; }
119+
public bool? siren { get; set; }
120+
public bool? powersave { get; set; }
121+
public bool? invert { get; set; }
122+
public bool? nobg { get; set; }
123+
public bool? chatbg { get; set; }
124+
public bool? replaytoolsnocollapse { get; set; }
125+
public bool? kos { get; set; }
126+
public bool? fire { get; set; }
127+
public bool? focuswarning { get; set; }
128+
public bool? hidenetwork { get; set; }
129+
public bool? guide { get; set; }
130+
public bool? lowrescounters { get; set; }
131+
public bool? desktopnotifications { get; set; }
132+
public bool? lowres { get; set; }
133+
public string? webgl { get; set; }
134+
public int? bloom { get; set; }
135+
public double? chroma { get; set; }
136+
public int? flashwave { get; set; }
137+
}
138+
139+
public class Volume
140+
{
141+
public bool? disable { get; set; }
142+
public double? music { get; set; }
143+
public double? sfx { get; set; }
144+
public double? stereo { get; set; }
145+
public bool? others { get; set; }
146+
public bool? attacks { get; set; }
147+
public bool? next { get; set; }
148+
public bool? noreset { get; set; }
149+
public bool? oof { get; set; }
150+
public bool? scrollable { get; set; }
151+
public Bgmtweak? bgmtweak { get; set; }
152+
}
153+
154+
155+
}

‎TetrLoader/JsonClass/EndContext.cs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TetrLoader.JsonClass
8+
{
9+
public class EndContext
10+
{
11+
//TTRM
12+
public int? naturalorder { get; set; } = null;
13+
public User? user { get; set; } = null;
14+
public bool? active { get; set; } = null;
15+
public int? wins { get; set; } = null;
16+
// public int? inputs { get; set; } = null;
17+
public int? piecesplaced { get; set; } = null;
18+
public Points? points { get; set; }
19+
20+
21+
//TTR
22+
public double? seed { get; set; } = null;
23+
public int? lines { get; set; } = null;
24+
public int? level_lines { get; set; } = null;
25+
public int? level_lines_needed { get; set; } = null;
26+
public int? holds { get; set; } = null;
27+
public int? score { get; set; } = null;
28+
public int? zenlevel { get; set; } = null;
29+
public int? zenprogress { get; set; } = null;
30+
public int? level { get; set; } = null;
31+
public int? combo { get; set; } = null;
32+
public int? currentcombopower { get; set; } = null;
33+
public int? topcombo { get; set; } = null;
34+
public int? btb { get; set; } = null;
35+
public int? topbtb { get; set; } = null;
36+
public int? tspins { get; set; } = null;
37+
public int? pieceplaced { get; set; } = null;
38+
public int? kills { get; set; } = null;
39+
40+
//BOTH
41+
public int? inputs { get; set; } = null;
42+
43+
}
44+
45+
}

‎TetrLoader/JsonClass/Event/Event.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using TetrLoader.Enum;
2+
3+
namespace TetrLoader.JsonClass.Event
4+
{
5+
public class Event
6+
{
7+
public Event(int? id, int? frame, EventType? type)
8+
{
9+
this.id = id;
10+
this.frame = frame;
11+
this.type = type;
12+
this.data = null;
13+
}
14+
15+
public int? id { get; set; }
16+
public int? frame { get; set; }
17+
public EventType? type { get; set; }
18+
public object? data { get; set; }
19+
}
20+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using TetrLoader.Enum;
2+
3+
namespace TetrLoader.JsonClass.Event
4+
{
5+
public class EventEnd : Event
6+
{
7+
public EventEnd(int? id, int frame, EventType? type, EventEndData data) : base(id, frame, type)
8+
{
9+
this.data = data;
10+
}
11+
12+
public new EventEndData data { get; set; }
13+
}
14+
15+
public class EventEndData
16+
{
17+
public string? reason { get; set; } = null;
18+
public Export? export { get; set; } = null;
19+
}
20+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using TetrLoader.Enum;
2+
using TetrLoader.JsonClass.Event;
3+
4+
namespace TetrLoader.JsonClass.Event
5+
{
6+
public class EventFull : Event
7+
{
8+
public EventFull(int? id,int frame,EventType? type, EventFullData data) : base(id,frame,type)
9+
{
10+
this.data = data;
11+
}
12+
13+
public new EventFullData data { get; set; }
14+
}
15+
16+
public class EventFullData
17+
{
18+
19+
public bool? successful { get; set; } = null;
20+
public object? gameoverreason { get; set; } = null;
21+
public int? fire { get; set; } = null;
22+
23+
public EventFullReplayData? replay { get; set; } = null;
24+
public EventFullSourceData? source { get; set; } = null;
25+
public EventFullOptionsData? options { get; set; } = null;
26+
public EventFullStatsData? stats { get; set; } = null;
27+
public EventFullGameData? game { get; set; } = null;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace TetrLoader.JsonClass.Event
2+
{
3+
public class EventFullGame : Event
4+
{
5+
public EventFullGame(EventFullGame data) : base(null, null, null)
6+
{
7+
this.data = data;
8+
}
9+
10+
public new EventFullGame data { get; set; }
11+
}
12+
public class EventFullGameData
13+
{
14+
public TetrLoader.JsonClass.Handling? handling { get; set; } = null;
15+
16+
17+
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+

2+
namespace TetrLoader.JsonClass.Event
3+
{
4+
public class EventFullOptions : Event
5+
{
6+
public EventFullOptions(EventFullGameData data) : base(null, null, null)
7+
{
8+
this.data = data;
9+
}
10+
11+
public new EventFullGameData data { get; set; }
12+
}
13+
14+
public class EventFullOptionsData
15+
{
16+
public int version { get; set; }
17+
public bool? seed_random { get; set; } = null;
18+
19+
public double seed { get; set; }
20+
public bool? allow180 { get; set; } = null;
21+
public double? g { get; set; } = null;
22+
public Handling? handling { get; set; } = null;
23+
24+
public bool? no_szo { get; set; } = null;
25+
public int? garbagespeed { get; set; } = null;
26+
public int? garbagecap { get; set; } = null;
27+
public string? kickset { get; set; } = null;
28+
public int? boardwidth { get; set; } = null;
29+
public int? boardheight { get; set; } = null;
30+
public int? boardbuffer { get; set; } = null;
31+
public bool? physical { get; set; } = null;
32+
public bool? display_username { get; set; } = null;
33+
public string? username { get; set; } = null;
34+
public int? nextcount { get; set; } = null;
35+
public int? stock { get; set; } = null;
36+
public bool? hasgarbage { get; set; } = null;
37+
public bool? display_next { get; set; } = null;
38+
public bool? display_hold { get; set; } = null;
39+
public int? gmargin { get; set; } = null;
40+
public int? garbagemargin { get; set; } = null;
41+
public double? gincrease { get; set; } = null;
42+
public double? garbagecapincrease { get; set; } = null;
43+
public int? garbagecapmax { get; set; } = null;
44+
public double? garbageincrease { get; set; } = null;
45+
public string? bagtype { get; set; } = null;
46+
public string? spinbonuses { get; set; } = null;
47+
public bool? allow_harddrop { get; set; } = null;
48+
public bool? display_shadow { get; set; } = null;
49+
public int? locktime { get; set; } = null;
50+
public int? are { get; set; } = null;
51+
public int? lieclear_are { get; set; } = null;
52+
public bool? infinitemovement { get; set; } = null;
53+
public int? lockresets { get; set; } = null;
54+
public bool? b2bchaining { get; set; } = null;
55+
public bool? clutch { get; set; } = null;
56+
public object? passthrough { get; set; } = null;
57+
public bool? nolockout { get; set; } = null;
58+
public string? garbageblocking { get; set; } = null;
59+
public double? garbagemultiplier { get; set; } = null;
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace TetrLoader.JsonClass.Event;
2+
3+
public class EventFullReplay : Event
4+
{
5+
public EventFullReplay(EventFullReplayData data) : base(null, null, null)
6+
{
7+
this.data = data;
8+
}
9+
10+
public new EventFullReplayData data { get; set; }
11+
}
12+
public class EventFullReplayData
13+
{
14+
public object? advanceFrame { get; set; } = null;
15+
public object? getFrame { get; set; } = null;
16+
public object? getEventCount { get; set; } = null;
17+
public object? getStarter { get; set; } = null;
18+
public object? getStartEvent { get; set; } = null;
19+
public object? getEndEvent { get; set; } = null;
20+
public object? pushEvent { get; set; } = null;
21+
public object? getEventsAtFrame { get; set; } = null;
22+
public object? export { get; set; } = null;
23+
public object? import { get; set; } = null;
24+
public object? seek { get; set; } = null;
25+
public object? bindRolling { get; set; } = null;
26+
public object? setListenID { get; set; } = null;
27+
public object? flush { get; set; } = null;
28+
public object? amendTargets { get; set; } = null;
29+
public object? setLatencyPrefence { get; set; } = null;
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+

2+
namespace TetrLoader.JsonClass.Event
3+
{
4+
public class EventFullSource : Event
5+
{
6+
public EventFullSource(EventFullSourceData data) : base(null, null, null)
7+
{
8+
this.data = data;
9+
}
10+
11+
public new EventFullSourceData data { get; set; }
12+
13+
}
14+
15+
public class EventFullSourceData
16+
{
17+
public object? advanceFrame { get; set; }
18+
public object? getFrame { get; set; }
19+
public object? readyEventQueue { get; set; }
20+
public object? pull { get; set; }
21+
public object? nextFrameReady { get; set; }
22+
public object? fallingBehind { get; set; }
23+
public object? amountToCatchUp { get; set; }
24+
public object? behindness { get; set; }
25+
public object? bind { get; set; }
26+
public object? unbind { get; set; }
27+
public object? seek { get; set; }
28+
public object? finished { get; set; }
29+
public object? type { get; set; }
30+
public object? pushIGE { get; set; }
31+
public object? pushTargets { get; set; }
32+
public object? unhook { get; set; }
33+
public object? destroy { get; set; }
34+
public object? socket { get; set; }
35+
public object? bindHyperRetry { get; set; }
36+
public object? bindHyperForfeit { get; set; }
37+
38+
}
39+
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace TetrLoader.JsonClass.Event
2+
{
3+
public class EventFullStats : Event
4+
{
5+
public EventFullStats(EventFullStatsData data) : base(null, null, null)
6+
{
7+
this.data = data;
8+
}
9+
10+
public new EventFullStatsData data { get; set; }
11+
12+
}
13+
14+
public class EventFullStatsData
15+
{
16+
public double? seed { get; set; }
17+
public int? lines { get; set; }
18+
public int? level_lines { get; set; }
19+
public int? level_lines_needed { get; set; }
20+
public int? inputs { get; set; }
21+
public int? holds { get; set; }
22+
public int? score { get; set; }
23+
public int? zenlevel { get; set; }
24+
public int? zenprogress { get; set; }
25+
public int? level { get; set; }
26+
public int? combo { get; set; }
27+
public int? currentcombopower { get; set; }
28+
public int? topcombo { get; set; }
29+
public int? btb { get; set; }
30+
public int? topbtb { get; set; }
31+
public int? tspins { get; set; }
32+
public int? piecesplaced { get; set; }
33+
public int? kills { get; set; }
34+
}
35+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Transactions;
8+
using TetrLoader;
9+
using TetrLoader.Enum;
10+
11+
namespace TetrLoader.JsonClass.Event
12+
{
13+
public class EventIge : Event
14+
{
15+
public EventIge(int? id, int frame, EventType? type, EventIgeData data) : base(id, frame, type)
16+
{
17+
this.data = data;
18+
}
19+
20+
public new EventIgeData data { get; set; }
21+
22+
}
23+
public class EventIgeData
24+
{
25+
public int? id { get; set; }
26+
public int frame { get; set; }
27+
public string? type { get; set; }
28+
public IgeData? data { get; set; }
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using TetrLoader;
7+
using TetrLoader.Enum;
8+
9+
namespace TetrLoader.JsonClass.Event
10+
{
11+
public class EventKeyInput : TetrLoader.JsonClass.Event.Event
12+
{
13+
public EventKeyInput(int? id, int frame, EventType? type, EventKeyInputData data) : base(id, frame, type)
14+
{
15+
this.data = data;
16+
}
17+
18+
public new EventKeyInputData data { get; set; }
19+
20+
}
21+
22+
public class EventKeyInputData
23+
{
24+
public string key { get; set; }
25+
public double subframe { get; set; }
26+
public bool hoisted { get; set; }
27+
}
28+
29+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+

2+
namespace TetrLoader.JsonClass.Event
3+
{
4+
public class EventKiller : Event
5+
{
6+
public EventKiller(Event? type, EventKillerData data) : base(null, null, type.type)
7+
{
8+
this.data = data;
9+
}
10+
11+
public new EventKillerData data { get; set; }
12+
13+
}
14+
15+
public class EventKillerData
16+
{
17+
public string? name { get; set; }
18+
public string? type { get; set; }
19+
}
20+
21+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+

2+
using TetrLoader;
3+
using TetrLoader.Enum;
4+
5+
namespace TetrLoader.JsonClass.Event
6+
{
7+
public class EventTargets : TetrLoader.JsonClass.Event.Event
8+
{
9+
public EventTargets(int? id, int frame, EventType? type, EventTargetsData data) : base(id, frame, type)
10+
{
11+
this.data = data;
12+
}
13+
14+
public new EventTargetsData? data { get; set; }
15+
16+
}
17+
18+
public class EventTargetsData
19+
{
20+
public string? id { get; set; } = null;
21+
public int? frame { get; set; } = null;
22+
public string? type { get; set; } = null;
23+
public List<string>? data { get; set; } = null;
24+
}
25+
}

‎TetrLoader/JsonClass/Extra.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TetrLoader.JsonClass
8+
{
9+
public class Extra
10+
{
11+
public float? vs { get; set; } = null;
12+
}
13+
14+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TetrLoader.JsonClass
8+
{
9+
public class ExtraAvgTracking
10+
{
11+
public double[]? aggregatestats___vsscore { get; set; } = null;
12+
}
13+
}

‎TetrLoader/JsonClass/GarbageData.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TetrLoader.JsonClass
8+
{
9+
public class GarbageData
10+
{
11+
public GarbageData Clone()
12+
{
13+
GarbageData newdata = new GarbageData()
14+
{
15+
iid = iid,
16+
type = type,
17+
amt = amt,
18+
ackiid = ackiid,
19+
x = x,
20+
y = y,
21+
column = column
22+
};
23+
24+
return newdata;
25+
}
26+
public int iid { get; set; }
27+
public string type { get; set; }
28+
public int amt { get; set; }
29+
public int ackiid { get; set; }
30+
public int x { get; set; }
31+
public int y { get; set; }
32+
public int column { get; set; }
33+
34+
}
35+
36+
}

‎TetrLoader/JsonClass/Handling.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TetrLoader.JsonClass
8+
{
9+
public class Handling
10+
{
11+
public double? arr { get; set; } = null;
12+
public double? das { get; set; } = null;
13+
public double? dcd { get; set; } = null;
14+
public double? sdf { get; set; } = null;
15+
public bool? safelock { get; set; } = null;
16+
public bool? cancel { get; set; } = false;
17+
}
18+
}

‎TetrLoader/JsonClass/IgeData.cs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using TetrLoader.JsonClass;
2+
3+
namespace TetrLoader.JsonClass;
4+
5+
public class IgeData:ICloneable
6+
{
7+
8+
9+
public IgeData Clone()
10+
{
11+
IgeData newdata = new IgeData();
12+
newdata.id = id;
13+
newdata.frame = frame;
14+
newdata.type = type;
15+
newdata.data = data.Clone();
16+
newdata.sender = sender;
17+
newdata.sender_id = sender_id;
18+
newdata.sent_frame = sent_frame;
19+
newdata.cid = cid;
20+
newdata.lines = lines;
21+
newdata.column = column;
22+
newdata.active = active;
23+
24+
25+
26+
27+
return newdata;
28+
29+
30+
}
31+
32+
object ICloneable.Clone()
33+
{
34+
return Clone();
35+
}
36+
37+
public int? id { get; set; }
38+
public int frame { get; set; }
39+
public string type { get; set; }
40+
public GarbageData data { get; set; }
41+
public string sender { get; set; }
42+
public string? sender_id { get; set; }
43+
public int sent_frame { get; set; }
44+
public int? cid { get; set; }
45+
public int lines { get; set; }
46+
public int column { get; set; }
47+
public bool active { get; set; }
48+
49+
}

‎TetrLoader/JsonClass/IsMulti.cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TetrLoader.JsonClass
8+
{
9+
public class IsMulti
10+
{
11+
public bool? ismulti { get; set; } = null;
12+
}
13+
}

‎TetrLoader/JsonClass/Points.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TetrLoader.JsonClass
8+
{
9+
public class Points
10+
{
11+
public int? primary { get; set; } = null;
12+
public double? secondary { get; set; } = null;
13+
public double? tertiary { get; set; } = null;
14+
public Extra? extra { get; set; } = null;
15+
public double[]? secondaryAvgTracking { get; set; } = null;
16+
public double[]? tertiaryAvgTracking { get; set; } = null;
17+
public ExtraAvgTracking? extraAvgTracking { get; set; } = null;
18+
19+
}
20+
21+
}

‎TetrLoader/JsonClass/ReplayDataTTR.cs

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
using System.Text.Json;
2+
using TetrLoader.Enum;
3+
using TetrLoader.JsonClass.Event;
4+
using TetrLoader;
5+
using TetrLoader.JsonClass;
6+
7+
namespace TetrLoader.JsonClass;
8+
9+
/// <summary>
10+
/// リプレイファイルのデータ
11+
/// </summary>
12+
public class ReplayDataTTR : IReplayData
13+
{
14+
public User? user { get; set; } = null;
15+
//TTR
16+
public string? _id { get; set; } = null;
17+
public string? shortid { get; set; } = null;
18+
public bool ismulti { get; set; } = false;
19+
public EndContext? endcontext { get; set; } = null;
20+
21+
public string? ts { get; set; } = null;
22+
public string? gametype { get; set; } = null;
23+
public bool? verified { get; set; } = null;
24+
/// <summary>
25+
/// 試合ごとのデータ群
26+
/// </summary>
27+
public ReplayEvent? data { get; set; } = null;
28+
public string? back { get; set; } = null;
29+
30+
public int GetGameTotalFrames(int replayIndex)
31+
=> -1;
32+
33+
public int GetPlayerCount()
34+
=> 1;
35+
36+
public int GetReplayCount()
37+
=> 1;
38+
39+
public List<Event.Event>? GetReplayEvents(int playerIndex, int replayIndex)
40+
{
41+
42+
var rawEvent = data.events;
43+
List<Event.Event> events = new List<Event.Event>();
44+
45+
foreach (var @event in rawEvent)
46+
{
47+
if (@event == null)
48+
throw new Exception();
49+
50+
switch (@event.type)
51+
{
52+
case EventType.Start:
53+
events.Add(@event);
54+
break;
55+
56+
case EventType.End:
57+
events.Add(new EventEnd
58+
(
59+
@event.id,
60+
(int)@event.frame,
61+
@event.type,
62+
JsonSerializer.Deserialize<EventEndData>(@event.data.ToString())
63+
));
64+
break;
65+
66+
case EventType.Full:
67+
events.Add(new EventFull
68+
(
69+
@event.id,
70+
(int)@event.frame,
71+
@event.type,
72+
JsonSerializer.Deserialize<EventFullData>(@event.data.ToString())
73+
));
74+
break;
75+
76+
case EventType.Keyup:
77+
case EventType.Keydown:
78+
events.Add(new EventKeyInput
79+
(
80+
@event.id,
81+
(int)@event.frame,
82+
@event.type,
83+
JsonSerializer.Deserialize<EventKeyInputData>(@event.data.ToString())
84+
));
85+
break;
86+
87+
case EventType.Targets:
88+
events.Add(new EventTargets(
89+
@event.id,
90+
(int)@event.frame,
91+
@event.type,
92+
JsonSerializer.Deserialize<EventTargetsData>(@event.data.ToString())
93+
));
94+
break;
95+
96+
case EventType.Ige:
97+
events.Add(new EventIge(
98+
@event.id,
99+
(int)@event.frame,
100+
@event.type,
101+
JsonSerializer.Deserialize<EventIgeData?>(@event.data.ToString())
102+
));
103+
break;
104+
105+
default:
106+
events.Add(@event);
107+
break;
108+
109+
}
110+
}
111+
112+
return events;
113+
114+
}
115+
116+
public Stats GetReplayStats(int playerIndex, int replayIndex)
117+
=> new Stats()
118+
{
119+
PPS = -1,
120+
APM = -1,
121+
VS = -1,
122+
Winner = false
123+
};
124+
125+
public string GetUsername(int playerIndex)
126+
=> user.username;
127+
128+
}
+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
using System.Text.Json;
2+
using TetrLoader.Enum;
3+
using TetrLoader.JsonClass.Event;
4+
using TetrLoader;
5+
using TetrLoader.JsonClass;
6+
7+
namespace TetrLoader.JsonClass;
8+
9+
/// <summary>
10+
/// リプレイファイルのデータ
11+
/// </summary>
12+
public class ReplayDataTTRM : IReplayData
13+
{
14+
public string? _id { get; set; } = null;
15+
public string? shortid { get; set; } = null;
16+
public bool ismulti { get; set; } = false;
17+
public List<EndContext>? endcontext { get; set; } = null;
18+
19+
public string? ts { get; set; } = null;
20+
public string? gametype { get; set; } = null;
21+
public bool? verified { get; set; } = null;
22+
/// <summary>
23+
/// 試合ごとのデータ群
24+
/// </summary>
25+
public List<PlayDataTTRM> data { get; set; }
26+
public string? back { get; set; } = null;
27+
28+
public int GetGameTotalFrames(int replayIndex)
29+
{
30+
int maxFrame = -1;
31+
32+
foreach (var game in data[replayIndex].replays)
33+
{
34+
if (maxFrame < game.frames)
35+
maxFrame = (int)game.frames;
36+
}
37+
38+
return maxFrame;
39+
}
40+
41+
42+
public int GetPlayerCount()
43+
=> data[0].replays.Count;
44+
45+
46+
public int GetReplayCount()
47+
=> data.Count;
48+
49+
50+
public List<TetrLoader.JsonClass.Event.Event>? GetReplayEvents(int playerIndex, int replayIndex)
51+
{
52+
var rawEvent = data?[replayIndex].replays?[playerIndex].events;
53+
List<TetrLoader.JsonClass.Event.Event> events = new List<TetrLoader.JsonClass.Event.Event>();
54+
55+
56+
foreach (var @event in rawEvent)
57+
{
58+
if (@event == null)
59+
throw new Exception();
60+
61+
switch (@event.type)
62+
{
63+
case EventType.Start:
64+
events.Add(@event);
65+
break;
66+
67+
case EventType.End:
68+
events.Add(new EventEnd
69+
(
70+
@event.id,
71+
(int)@event.frame,
72+
@event.type,
73+
JsonSerializer.Deserialize<EventEndData>(@event.data.ToString())
74+
));
75+
break;
76+
77+
case EventType.Full:
78+
events.Add(new EventFull
79+
(
80+
@event.id,
81+
(int)@event.frame,
82+
@event.type,
83+
JsonSerializer.Deserialize<EventFullData>(@event.data.ToString())
84+
));
85+
break;
86+
87+
case EventType.Keydown:
88+
case EventType.Keyup:
89+
events.Add(new EventKeyInput
90+
(
91+
@event.id,
92+
(int)@event.frame,
93+
@event.type,
94+
JsonSerializer.Deserialize<EventKeyInputData>(@event.data.ToString())
95+
));
96+
break;
97+
98+
case EventType.Targets:
99+
events.Add(new EventTargets(
100+
@event.id,
101+
(int)@event.frame,
102+
@event.type,
103+
JsonSerializer.Deserialize<EventTargetsData>(@event.data.ToString())
104+
));
105+
break;
106+
107+
case EventType.Ige:
108+
events.Add(new EventIge(
109+
@event.id,
110+
(int)@event.frame,
111+
@event.type,
112+
JsonSerializer.Deserialize<EventIgeData?>(@event.data.ToString())
113+
));
114+
break;
115+
116+
default:
117+
events.Add(@event);
118+
break;
119+
120+
}
121+
}
122+
123+
return events;
124+
125+
}
126+
127+
public Stats GetReplayStats(int playerIndex, int replayIndex)
128+
{
129+
var result = new Stats();
130+
var events = GetReplayEvents(playerIndex, replayIndex);
131+
EventEnd eventEnd = null;
132+
for (int i = events.Count - 1; i >= 0; i--)
133+
{
134+
if (events[i].type == EventType.End)
135+
{
136+
eventEnd = events[i] as EventEnd;
137+
break;
138+
}
139+
}
140+
141+
result.VS = eventEnd.data.export.aggregatestats.vsscore ?? -1;
142+
result.APM = eventEnd.data.export.aggregatestats.apm ?? -1;
143+
result.PPS = eventEnd.data.export.aggregatestats.pps ?? -1;
144+
145+
var frames = GetGameTotalFrames(replayIndex);
146+
int time = frames / 60;
147+
result.Time = (time / 60).ToString() + ":" + (time % 60).ToString("00");
148+
149+
if (data[replayIndex].board[playerIndex].success == null)
150+
{
151+
result.Winner = false;
152+
}
153+
else
154+
{
155+
if (GetUsername(playerIndex) == data[replayIndex].board[playerIndex].user.username)
156+
result.Winner = (bool)data[replayIndex].board[playerIndex].success;
157+
else
158+
result.Winner = !(bool)data[replayIndex].board[playerIndex].success;
159+
160+
}
161+
162+
return result;
163+
}
164+
165+
public string GetUsername(int playerIndex)
166+
=> endcontext[0].naturalorder == playerIndex ?
167+
endcontext[0].user.username :
168+
endcontext[1].user.username;
169+
}
170+
171+
public class ReplayDataTTRMData
172+
{
173+
174+
175+
}

‎TetrLoader/JsonClass/User.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TetrLoader.JsonClass
8+
{
9+
public class User
10+
{
11+
public string? _id { get; set; } = null;
12+
public string? username { get; set; } = null;
13+
}
14+
15+
}

‎TetrLoader/ReplayKind.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace TetrLoader
2+
{
3+
public enum ReplayKind
4+
{
5+
TTR,
6+
TTRM
7+
}
8+
9+
10+
}

‎TetrLoader/ReplayLoader.cs

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using System.Text.Json;
2+
using TetrLoader.JsonClass;
3+
using TetrLoader.JsonClass.Event;
4+
5+
namespace TetrLoader
6+
{
7+
public abstract class ReplayLoader
8+
{
9+
/// <summary>
10+
///
11+
/// </summary>
12+
/// <param name="jsonString">raw json replay string</param>
13+
/// <returns></returns>
14+
public static bool IsMulti(string jsonString)
15+
{
16+
IsMulti? replay = JsonSerializer.Deserialize<IsMulti>(jsonString);
17+
18+
if (replay?.ismulti == null || replay.ismulti == false)
19+
return false;
20+
else
21+
return true;
22+
}
23+
24+
25+
/// <summary>
26+
/// Parse json replay data
27+
/// </summary>
28+
/// <param name="jsonString"></param>
29+
/// <param name="replayKind"></param>
30+
/// <returns>Parsed replay object. Cast ReplayDataTTR or ReplayDataTTRM to use</returns>
31+
/// <exception cref="Exception"></exception>
32+
public static IReplayData ParseReplay(string jsonString, ReplayKind replayKind)
33+
{
34+
IReplayData replay;
35+
if (replayKind == ReplayKind.TTR)
36+
replay = JsonSerializer.Deserialize<ReplayDataTTR>(jsonString);
37+
else
38+
replay = JsonSerializer.Deserialize<ReplayDataTTRM>(jsonString);
39+
40+
if (replay == null)
41+
throw new Exception("Failed to Convert Json File.\r\n" +
42+
"Supported Json File is TETR.IO Replay(.ttr | .ttrm) Only.");
43+
44+
return replay;
45+
}
46+
}
47+
48+
49+
/// <summary>
50+
/// 試合中のデータ、プレイヤーの数分だけリストの個数がある
51+
/// </summary>
52+
public class PlayDataTTRM
53+
{
54+
/// <summary>
55+
/// プレイヤーの情報に関するデータ
56+
/// </summary>
57+
public List<Board> board { get; set; }
58+
59+
/// <summary>
60+
/// リプレイの操作に関するデータ
61+
/// </summary>
62+
public List<ReplayEvent> replays { get; set; }
63+
}
64+
65+
66+
public class Board
67+
{
68+
public User? user { get; set; } = null;
69+
public bool? active { get; set; } = null;
70+
public bool? success { get; set; } = null;
71+
public int? winning { get; set; } = null;
72+
}
73+
74+
/// <summary>
75+
/// 試合の入力データ
76+
/// </summary>
77+
public class ReplayEvent
78+
{
79+
/// <summary>
80+
/// 総フレーム数
81+
/// </summary>
82+
public int? frames { get; set; } = null;
83+
84+
public List<Event>? events { get; set; } = null;
85+
}
86+
87+
88+
public class Export
89+
{
90+
public bool? successful { get; set; } = null;
91+
public string? gameoverreason { get; set; } = null;
92+
public EventFullReplayData? replay { get; set; } = null;
93+
public EventFullSourceData? source { get; set; } = null;
94+
public EventFullOptionsData? options { get; set; } = null;
95+
96+
public EventFullStatsData? stats { get; set; } = null;
97+
98+
// public EventTargets? targets { get; set; } = null;
99+
public int? fire { get; set; } = null;
100+
public EventFullGameData? game { get; set; } = null;
101+
public EventKillerData? killer { get; set; } = null;
102+
public AggregateStats? aggregatestats { get; set; } = null;
103+
}
104+
105+
public class AggregateStats
106+
{
107+
public double? apm { get; set; } = null;
108+
public double? pps { get; set; } = null;
109+
public double? vsscore { get; set; } = null;
110+
}
111+
}

‎TetrLoader/Stats.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace TetrLoader
8+
{
9+
public struct Stats
10+
{
11+
public Stats(double pps, double apm, double vs, string time, bool winner)
12+
{
13+
PPS = pps;
14+
APM = apm;
15+
VS = vs;
16+
Time = time;
17+
Winner = winner;
18+
}
19+
20+
public double PPS { get; set; }
21+
public double APM { get; set; }
22+
public double VS { get; set; }
23+
public string Time { get; set; }
24+
public bool Winner { get; set; }
25+
}
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.