Git Product home page Git Product logo

sc2replay-csharp's Introduction

sc2replay-csharp

C# library for extracting player and game information from .sc2replay files.

This is an easy-to-use library to quickly parse and extract information from the undocumented .sc2replay format. The project has a side goal of creating an in-depth wiki with replay file documentation.

Requirements: Visual C++ 2010 Runtime Redistributable as a requirement to MpqLib.dll

Current Version: 1.4.3 (4/3/2013)
Supports Replays Up To: 1.2.0.7
Latest Compiled: http://willeddins.com/apps/sc2-replayparser/Starcraft2.ReplayParser-1.4.3.zip

Current Abilities

  • Parses basic player and matchup information.
  • Parses entire chat log.
  • Parses all game events.
  • Can insert lines of text into the chat log for any player.
  • Can clear the in-game chat for a "clean" replay.

Replay Parsers for other languages

Example

    // Parse the replay.
    Replay replay = Replay.Parse(filename);

    // Basic information
    string map = replay.Map;
    TimeSpan length = replay.GameLength;

    // Print out players and mark winners with a *
    foreach (var player in replay.Players)
    {
      Console.Out.Write(string.Format("{0}{1} ", player.Name, player.IsWinner ? "*" : string.Empty));
    }

    // Write out chat messages to console
    Console.Out.WriteLine("Chat Messages:");
    foreach (var chatMessage in replay.ChatMessages)
    {
        Console.Out.WriteLine("[{0}]{1}: {2}",
            chatMessage.MessageTarget.ToString(),
            replay.Players[chatMessage.PlayerId - 1], 
            chatMessage.Message);
    }

You can find and contribute information in deconstructing the file format in the wiki: https://github.com/ascendedguard/sc2replay-csharp/wiki

Events parser

The events parser parses all of the events that the replay contains. This includes selection, hotkey, camera, and ability events. More technical information about the events can be found at replay.game.events.

The behavior of this events parser is dependent on a database which provides version-specific information on ability and unit ids and version-independent information on abilities, units, and events. More information about the format and generation of this database can be found at Event Information Database. A default database is compiled with the DLL, but it can be overridden by placing the .dat files into the application path, as needed.

Starcraft2.ReplayParser.DataCompiler is provided to translate an SQLite database to a set of .dat files. For editing the database, I recommend using SQLite Manager with a beta version of Firefox (for SQLite 3.7.11). Using the data compiler requires the System.Data.SQLite library, which is available at system.data.sqlite.org -- look for the x86 .NET 4.0 installer, and during setup, add the assemblies to the Global Assembly Cache.

sc2replay-csharp's People

Contributors

ascend-zz avatar ascendedguard avatar jamiepenney avatar notr1ch avatar robert-nix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sc2replay-csharp's Issues

Map fails to parse

On all versions of replays, the latest version fails to parse the map name, it's always a blank string.

Adding PlayerType.Observer

It'd be really cool if there would be an new PlayerType for Observer, so we can easily filter them out while parsing the replays.

League?

Since realease of SC2 2.0.5 the league of your own and your opponent will be saved in the replay.

Is it possible to implement that to the parser?

Missing replay info

Is there anyway you can populate the 2 pieces of info from the replay?

  1. Match Length
  2. Player APM(Action per minute)

Thank you

AbilityType.CancelTrain isnt parsed correctly. Returns Unknown

Linked below is a simple example that contains a replay with just a few events. Event 5 is a TrainSCV event, and Event 6 should be a CancelTrain or Cancel event (the SCV was cancelled in the replay. However, the EventType is Unknown.

string filename = @"test.SC2Replay";

Replay replay = Replay.Parse(filename);

List<IGameEvent> events = replay.PlayerEvents;

foreach (var e in events)
{
    if (e.Player.Name == "mesh") {
        if (e.EventType == GameEventType.Macro) {

            if (((AbilityEvent)e).AbilityType == AbilityType.Unknown)
            {
                System.Diagnostics.Debug.WriteLine(@"unknown");
            }

            if (((AbilityEvent)e).AbilityType == AbilityType.TrainSCV)
            {
                System.Diagnostics.Debug.WriteLine(@"trainscv");
            }
        }
    }
}

You can download the replay from:
http://dl.dropbox.com/u/361009/test.zip

Debugging into AbilityData.cs, the Unknown is coming from the final return, and not the check for index being greater than Data.Length.

Just adding some more info. GameEventType is also Unknown

Here is the Locals panel output for the Event should should be TrainCancel or Cancel.

-       [Starcraft2.ReplayParser.AbilityEvent]  {Starcraft2.ReplayParser.AbilityEvent}  Starcraft2.ReplayParser.AbilityEvent
-       base    {Starcraft2.ReplayParser.AbilityEvent}  Starcraft2.ReplayParser.GameEventBase {Starcraft2.ReplayParser.AbilityEvent}
        EventType   Unknown Starcraft2.ReplayParser.GameEventType
+       Player  {mesh}  Starcraft2.ReplayParser.Player
+       Time    {Starcraft2.ReplayParser.Timestamp} Starcraft2.ReplayParser.Timestamp
        AbilityFailed   false   bool
        AbilityType Unknown Starcraft2.ReplayParser.AbilityType
        AbilityUsed true    bool
+       Actors  Count = 1   System.Collections.Generic.List<Starcraft2.ReplayParser.Unit>
        DefaultAbility  false   bool
        DefaultActor    true    bool
        DefaultTarget   false   bool
        EnableAutoCast  false   bool
        MinimapClick    false   bool
        Queued  false   bool
        RightClick  false   bool
        TargetFlags 0   int
        TargetId    0   uint
        TargetLocation  null    Starcraft2.ReplayParser.Location
        TargetPlayer    0   int
        TargetTeam  0   int
        TargetUnit  null    Starcraft2.ReplayParser.Unit
        ToggleAbility   false   bool
        WireframeCancel false   bool
        WireframeClick  false   bool
        WireframeIndex  0   int
        WireframeUnload false   bool
        EventType   Unknown Starcraft2.ReplayParser.GameEventType
+       Player  {mesh}  Starcraft2.ReplayParser.Player
+       Time    {Starcraft2.ReplayParser.Timestamp} Starcraft2.ReplayParser.Timestamp

Assembly not found when deployed to Microsoft Server 2008

Running the project locally works, however - when deployed to the server it says "assembly or dependency" not found.

We are running MS Server 2008
.NET 4
Microsoft MCV3

Server Error in '/' Application.
Could not load file or assembly 'MpqLib.dll' or one of its dependencies. The specified module could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'MpqLib.dll' or one of its dependencies. The specified module could not be found.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[FileNotFoundException: Could not load file or assembly 'MpqLib.dll' or one of its dependencies. The specified module could not be found.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46

[ConfigurationErrorsException: Could not load file or assembly 'MpqLib.dll' or one of its dependencies. The specified module could not be found.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677

[HttpException (0x80004005): Could not load file or assembly 'MpqLib.dll' or one of its dependencies. The specified module could not be found.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9079228
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237

Behavior of Replay.Players property changed

Old Behavior

Replay.Players was a List that only contained players that actually participated in the game.

New Behavior

Replay.Players is a Player[16], which contains null entries for players that don't exist in the game. Players are inserted to the array using a 1-based index (instead of 0-based), which means that Players[0] is always null.

Anybody know why this was changed? This unexpectedly broke my app.

Foreign text causes a crash when parsing the chat

I figured this out when I used your dll on my SC2 ChatCloud project. It seems that most foreign text will cause an exception. The problem seems to be related to the PeekChar of the bytereader. See also here: http://www.johnsoer.com/blog/?p=493

I tried to fix it myself, but failed. Exception attached below.

************** Exception Text **************
System.ArgumentException: The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'System.Text.DecoderReplacementFallback'.
Parameter name: chars
at System.Text.Encoding.ThrowCharsOverflow()
at System.Text.Encoding.ThrowCharsOverflow(DecoderNLS decoder, Boolean nothingDecoded)
at System.Text.UTF8Encoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder)
at System.Text.DecoderNLS.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, Boolean flush)
at System.IO.BinaryReader.InternalReadChars(Char[] buffer, Int32 index, Int32 count)
at System.IO.BinaryReader.ReadChars(Int32 count)
at Starcraft2.ReplayParser.PlayerDetails.Parse(BinaryReader reader) in C:\Users\2\Desktop\ascendedguard-sc2replay-csharp-d4e9069\Starcraft2.ReplayParser\PlayerDetails.cs:line 44
at Starcraft2.ReplayParser.Replay.ParseReplayDetails(Replay replay, Stream stream) in C:\Users\2\Desktop\ascendedguard-sc2replay-csharp-d4e9069\Starcraft2.ReplayParser\Replay.cs:line 184
at Starcraft2.ReplayParser.Replay.ParseReplayDetails(Replay replay, Byte[] buffer) in C:\Users\2\Desktop\ascendedguard-sc2replay-csharp-d4e9069\Starcraft2.ReplayParser\Replay.cs:line 165
at Starcraft2.ReplayParser.Replay.Parse(String fileName) in C:\Users\2\Desktop\ascendedguard-sc2replay-csharp-d4e9069\Starcraft2.ReplayParser\Replay.cs:line 110
at SC2ChatCloud.Form1.Button3_Click(Object sender, EventArgs e) in C:\code\replay\WhatTheReplay\WhatTheReplay\Form1.vb:line 48
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Double namespace "replay" in the latest version

Since the latest version, the DLL contains the namespace "replay" twice. Once with a capital R and once without. This is not a problem when using the DLL in C#, but causes issues in VB.NET, which is not case sensitive.

HotS replays need event parsing updated

There are changes needed to get HotS event parsing to work again, then the ability and unit files need to be compiled for each HotS version as well.

A lot of work involved here. I know the Python project has updated abil and unit codes, and Mischanix seems to have updated his gist for retrieving event codes for HotS here: https://gist.github.com/Mischanix/4164860

These need to be added to the sqlite database and recompiled accordingly.

Also reference Mischanix's documentation on the SQLite DB here: https://github.com/Mischanix/sc2replay-csharp/wiki/Event-Information-Database

AddChatMessage should support longer strings

This requires adding a proper opcode when inserting the string and padding the proper string length. Shouldn't require much work, and will allow longer strings to be inserted.

Foreign filenames cause crash

Pretty much the same as with the previous issue where foreign text caused a crash it seems foreign filenames also cause trouble.

Example: 탈다림 제단 - 래더 (17).SC2Replay - Unable to parse

The same file parses fine after renaming. This also seems to happen under a proper foreign system. I ran it on a VM running Korean Windows XP and the issue still remains, so it is probably not related to English OS trying to parse foreign files.

Version number needs to be detected

Current the version number is unknown, wiki says it may be the first value in the replay file. Value needs to be read in order to properly parse newer replay files in the future without breaking existing support.

teams/players incorrectly parsed

This seems to be the case with some random replays. At first I was under the impression that its related to the new patch, but it seems to happen also with 1.3.3 replays. Players are wrongly reported to all being on Team 0 in some cases. I attached a replay where this happens:

http://replayfu.com/r/Pz9Zvf

The replay and teams are parsed correctly by the other parsers out there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.