forked from imkindaprogrammermyself/Replays-Unpack-CS
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from Nodsoft/feature/source-gen
Source Generators, lock issue and general Cleanup
- Loading branch information
Showing
338 changed files
with
27,152 additions
and
904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,4 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Nodsoft.WowsReplaysUnpack; | ||
using Nodsoft.WowsReplaysUnpack.Core.Models; | ||
using Nodsoft.WowsReplaysUnpack.EntitySerializer; | ||
using Nodsoft.WowsReplaysUnpack.ExtendedData; | ||
using Nodsoft.WowsReplaysUnpack.ExtendedData.Models; | ||
using Nodsoft.WowsReplaysUnpack.FileStore.Definitions; | ||
using Nodsoft.WowsReplaysUnpack.Services; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Threading.Tasks; | ||
using Nodsoft.WowsReplaysUnpack.Console.Samples.EntitySerializer; | ||
|
||
string samplePath = Path.Join(Directory.GetCurrentDirectory(), "../../../../Nodsoft.WowsReplaysUnpack.Tests", "Replay-Samples"); | ||
FileStream _GetReplayFile(string name) => File.OpenRead(Path.Join(samplePath, name)); | ||
|
||
ServiceProvider? services = new ServiceCollection() | ||
//.AddWowsReplayUnpacker(builder => | ||
//{ | ||
// //builder.AddReplayController<CVECheckOnlyController>(); | ||
// //builder.AddExtendedData(); | ||
//}) | ||
.AddWowsReplayUnpacker(builder => builder | ||
.WithDefinitionLoader<FileSystemDefinitionLoader>()) | ||
.Configure<FileSystemDefinitionLoaderOptions>(options => | ||
{ | ||
options.RootDirectory = options.RootDirectory = Path.Join(Directory.GetCurrentDirectory(), | ||
"..", "..", "..", "..", "Nodsoft.WowsReplaysUnpack.Core", "Definitions", "Versions"); | ||
}) | ||
.AddLogging(logging => | ||
{ | ||
logging.ClearProviders(); | ||
logging.AddConsole(); | ||
logging.SetMinimumLevel(LogLevel.Error); | ||
}) | ||
.BuildServiceProvider(); | ||
|
||
ReplayUnpackerFactory? replayUnpacker = services.GetRequiredService<ReplayUnpackerFactory>(); | ||
|
||
//var unpackedReplay = replayUnpacker.GetUnpacker().Unpack(GetReplayFile("payload.wowsreplay")); | ||
//var unpackedReplay = replayUnpacker.GetUnpacker<CVECheckOnlyController>().Unpack(GetReplayFile("payload.wowsreplay")); | ||
//ExtendedDataReplay? unpackedReplay = (ExtendedDataReplay)replayUnpacker.GetExtendedDataUnpacker().Unpack(_GetReplayFile("good.wowsreplay")); | ||
|
||
//foreach (ReplayMessage msg in replay.ChatMessages) | ||
//{ | ||
// Console.WriteLine($"[{GetGroupString(msg)}] {msg.EntityId} : {msg.MessageContent}"); | ||
//} | ||
|
||
const int CYCLE = 20; | ||
async Task<UnpackedReplay[]> syncTasks(bool sync) | ||
{ | ||
List<UnpackedReplay> unpackedReplays = new List<UnpackedReplay>(); | ||
if (sync) | ||
{ | ||
for (int i = 0; i < CYCLE; i++) | ||
{ | ||
replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay")); | ||
} | ||
} | ||
else | ||
{ | ||
Parallel.ForEach(Enumerable.Range(0, CYCLE), (i) => | ||
{ | ||
unpackedReplays.Add(replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay"))); | ||
}); | ||
} | ||
return unpackedReplays.ToArray(); | ||
} | ||
|
||
DateTime start = DateTime.Now; | ||
await syncTasks(false); | ||
Console.WriteLine(DateTime.Now - start); | ||
|
||
var goodReplay = replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay")); | ||
var alphaReplay = replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("press_account_alpha.wowsreplay")); | ||
var bravoReplay = replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("unfinished_replay.wowsreplay")); | ||
|
||
var alphaState = alphaReplay.Entities.Single(e => e.Value.Name == "BattleLogic").Value.ClientProperties | ||
.GetAsDict("state") | ||
.GetAsDict("missions") | ||
.GetAsArr("teamsScore"); | ||
|
||
var bravoState = bravoReplay.Entities.Single(e => e.Value.Name == "BattleLogic").Value.ClientProperties | ||
.GetAsDict("state") | ||
.GetAsDict("missions") | ||
.GetAsArr("teamsScore"); | ||
|
||
var scoreA = alphaState.GetAsDict(0).GetAsValue<ushort>("score"); | ||
var scoreB = alphaState.GetAsDict(1).GetAsValue<ushort>("score"); | ||
|
||
var _scoreA = bravoState.GetAsDict(0).GetAsValue<ushort>("score"); | ||
var _scoreB = bravoState.GetAsDict(1).GetAsValue<ushort>("score"); | ||
|
||
|
||
|
||
var test = alphaReplay.SerializeEntity<BattleLogic>("BattleLogic"); | ||
|
||
Console.WriteLine(); | ||
Console.ReadKey(); | ||
|
||
public class BattleLogic | ||
{ | ||
public Statee State { get; set; } | ||
public class Statee | ||
{ | ||
[DataMember(Name = "missions")] | ||
public Missions _missions { get; set; } | ||
public class Missions | ||
{ | ||
public List<TeamsScore> teamsScore { get; set; } | ||
public class TeamsScore | ||
{ | ||
public ushort score { get; set; } | ||
} | ||
} | ||
} | ||
} | ||
public static class ext | ||
{ | ||
public static FixedDictionary GetAsDict(this Dictionary<string, object?> dict, string key) => dict[key] as FixedDictionary; | ||
public static FixedList GetAsArr(this Dictionary<string, object?> dict, string key) => dict[key] as FixedList; | ||
public static FixedDictionary GetAsDict(this FixedList list, int index) => list[index] as FixedDictionary; | ||
public static T GetAsValue<T>(this FixedDictionary dict, string key) => (T)dict[key]; | ||
} | ||
|
||
//static string GetGroupString(ReplayMessage msg) => msg.MessageGroup switch | ||
//{ | ||
// "battle_team" => "Team", | ||
// "battle_common" => "All", | ||
// _ => "" | ||
//}; | ||
// await new SyncTest().ExecuteAsync(); | ||
await new EntitySerializerSample().ExecuteAsync(); |
30 changes: 30 additions & 0 deletions
30
Nodsoft.WowsReplaysUnpack.Console/Samples/EntitySerializer/BattleLogic.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Nodsoft.WowsReplaysUnpack.Generators; | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Nodsoft.WowsReplaysUnpack.Console.Samples.EntitySerializer; | ||
|
||
[SerializableEntity] | ||
public partial class BattleLogic | ||
{ | ||
[DataMember(Name = "state")] | ||
public State State { get; set; } = null!; | ||
} | ||
|
||
public class State | ||
{ | ||
[DataMember(Name = "missions")] | ||
public Missions Missions { get; set; } = null!; | ||
} | ||
|
||
public class Missions | ||
{ | ||
[DataMember(Name = "teamsScore")] | ||
public List<TeamsScore> TeamsScore { get; set; } = null!; | ||
} | ||
|
||
public class TeamsScore | ||
{ | ||
[DataMember(Name = "score")] | ||
public ushort Score { get; set; } | ||
} |
72 changes: 72 additions & 0 deletions
72
Nodsoft.WowsReplaysUnpack.Console/Samples/EntitySerializer/EntitySerializerSample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Nodsoft.WowsReplaysUnpack.Core.Models; | ||
using Nodsoft.WowsReplaysUnpack.EntitySerializer; | ||
using Nodsoft.WowsReplaysUnpack.ExtendedData; | ||
using Nodsoft.WowsReplaysUnpack.ExtendedData.Models; | ||
using Nodsoft.WowsReplaysUnpack.Services; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Nodsoft.WowsReplaysUnpack.Console.Samples.EntitySerializer; | ||
|
||
public class EntitySerializerSample : TaskBase | ||
{ | ||
protected override void ConfigureServices(IServiceCollection serviceCollection) | ||
{ | ||
serviceCollection.AddWowsReplayUnpacker(builder => | ||
{ | ||
builder.AddExtendedData(); | ||
}); | ||
} | ||
|
||
protected override Task ExecuteAsync(IServiceProvider services) | ||
{ | ||
using IReplayUnpackerService<ExtendedDataReplay> unpacker = | ||
services.GetRequiredService<IReplayUnpackerFactory>().GetExtendedDataUnpacker(); | ||
|
||
ExtendedDataReplay alphaReplay = unpacker.Unpack(GetReplayFile("press_account_alpha.wowsreplay")); | ||
ExtendedDataReplay bravoReplay = unpacker.Unpack(GetReplayFile("press_account_bravo.wowsreplay")); | ||
|
||
ManualExtensions(alphaReplay, bravoReplay); | ||
Serializer(alphaReplay, bravoReplay); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private void ManualExtensions(UnpackedReplay alphaReplay, UnpackedReplay bravoReplay) | ||
{ | ||
FixedList? alphaState = alphaReplay.Entities.Single(e => e.Value.Name == "BattleLogic").Value.ClientProperties | ||
.GetAsDict("state")? | ||
.GetAsDict("missions")? | ||
.GetAsArr("teamsScore"); | ||
|
||
FixedList? bravoState = bravoReplay.Entities.Single(e => e.Value.Name == "BattleLogic").Value.ClientProperties | ||
.GetAsDict("state")? | ||
.GetAsDict("missions")? | ||
.GetAsArr("teamsScore"); | ||
|
||
ushort? alphaScoreA = alphaState?.GetAsDict(0)?.GetAsValue<ushort>("score"); | ||
ushort? alphaScoreB = alphaState?.GetAsDict(1)?.GetAsValue<ushort>("score"); | ||
|
||
ushort? bravoScoreA = bravoState?.GetAsDict(0)?.GetAsValue<ushort>("score"); | ||
ushort? bravoScoreB = bravoState?.GetAsDict(1)?.GetAsValue<ushort>("score"); | ||
|
||
System.Console.WriteLine("Manuel Extensions:"); | ||
System.Console.WriteLine($"Alpha Replay: [{alphaScoreA}:{alphaScoreB}]"); | ||
System.Console.WriteLine($"Bravo Replay: [{bravoScoreA}:{bravoScoreB}]"); | ||
} | ||
|
||
private void Serializer(UnpackedReplay alphaReplay, UnpackedReplay bravoReplay) | ||
{ | ||
BattleLogic alphaBattleLogic = alphaReplay.DeserializeEntity<BattleLogic>("BattleLogic"); | ||
BattleLogic bravoBattleLogic = bravoReplay.DeserializeEntity<BattleLogic>("BattleLogic"); | ||
|
||
|
||
System.Console.WriteLine("Manuel Extensions:"); | ||
System.Console.WriteLine( | ||
$"Alpha Replay: [{alphaBattleLogic.State.Missions.TeamsScore[0].Score}:{alphaBattleLogic.State.Missions.TeamsScore[1].Score}]"); | ||
System.Console.WriteLine( | ||
$"Bravo Replay: [{bravoBattleLogic.State.Missions.TeamsScore[0].Score}:{bravoBattleLogic.State.Missions.TeamsScore[1].Score}]"); | ||
} | ||
} |
Oops, something went wrong.