コード例 #1
0
ファイル: UDT.cs プロジェクト: Danmer/uberdemotools
        private static List<DemoInfo> ParseDemosImpl(ref udtParseArg parseArg, List<string> filePaths, int maxThreadCount, int inputIndexBase)
        {
            var errorCodeArray = new Int32[filePaths.Count];
            var filePathArray = new IntPtr[filePaths.Count];
            for(var i = 0; i < filePaths.Count; ++i)
            {
                filePathArray[i] = Marshal.StringToHGlobalAnsi(Path.GetFullPath(filePaths[i]));
            }

            var pinnedPlugIns = new PinnedObject(PlugInArray);
            parseArg.PlugInCount = (UInt32)PlugInArray.Length;
            parseArg.PlugIns = pinnedPlugIns.Address;

            var pinnedFilePaths = new PinnedObject(filePathArray);
            var pinnedErrorCodes = new PinnedObject(errorCodeArray);
            var multiParseArg = new udtMultiParseArg();
            multiParseArg.FileCount = (UInt32)filePathArray.Length;
            multiParseArg.FilePaths = pinnedFilePaths.Address;
            multiParseArg.OutputErrorCodes = pinnedErrorCodes.Address;
            multiParseArg.MaxThreadCount = (UInt32)maxThreadCount;

            udtParserContextGroupRef contextGroup = IntPtr.Zero;
            var result = udtParseDemoFiles(ref contextGroup, ref parseArg, ref multiParseArg);
            pinnedPlugIns.Free();
            pinnedFilePaths.Free();
            pinnedErrorCodes.Free();
            for(var i = 0; i < filePathArray.Length; ++i)
            {
                Marshal.FreeHGlobal(filePathArray[i]);
            }

            if(result != udtErrorCode.None && result != udtErrorCode.OperationCanceled)
            {
                udtDestroyContextGroup(contextGroup);
                App.GlobalLogError("Failed to parse demos: " + GetErrorCodeString(result));
                return null;
            }

            uint contextCount = 0;
            if(udtGetContextCountFromGroup(contextGroup, ref contextCount) != udtErrorCode.None)
            {
                udtDestroyContextGroup(contextGroup);
                return null;
            }

            var infoList = new List<DemoInfo>();
            for(uint i = 0; i < contextCount; ++i)
            {
                udtParserContextRef context = IntPtr.Zero;
                if(udtGetContextFromGroup(contextGroup, i, ref context) != udtErrorCode.None)
                {
                    udtDestroyContextGroup(contextGroup);
                    return null;
                }

                uint demoCount = 0;
                if(udtGetDemoCountFromContext(context, ref demoCount) != udtErrorCode.None)
                {
                    udtDestroyContextGroup(contextGroup);
                    return null;
                }

                for(uint j = 0; j < demoCount; ++j)
                {
                    uint inputIdx = 0;
                    if(udtGetDemoInputIndex(context, j, ref inputIdx) != udtErrorCode.None)
                    {
                        continue;
                    }

                    var errorCode = errorCodeArray[(int)inputIdx];
                    if(errorCode != (Int32)udtErrorCode.None)
                    {
                        if(errorCode != (Int32)udtErrorCode.Unprocessed && errorCode != (Int32)udtErrorCode.OperationCanceled)
                        {
                            var fileName = Path.GetFileName(filePaths[(int)inputIdx]);
                            var errorCodeString = GetErrorCodeString((udtErrorCode)errorCode);
                            App.GlobalLogError("Failed to parse demo file {0}: {1}", fileName, errorCodeString);
                        }
                        continue;
                    }

                    var filePath = filePaths[(int)inputIdx];
                    var protocol = udtGetProtocolByFilePath(filePath);
                    var info = new DemoInfo();
                    info.Analyzed = true;
                    info.InputIndex = inputIndexBase + (int)inputIdx;
                    info.FilePath = Path.GetFullPath(filePath);
                    info.Protocol = UDT_DLL.GetProtocolAsString(protocol);

                    ExtractDemoInfo(context, j, ref info);
                    infoList.Add(info);
                }
            }

            udtDestroyContextGroup(contextGroup);

            // Keep the original input order.
            infoList.Sort((a, b) => a.InputIndex - b.InputIndex);

            return infoList;
        }
コード例 #2
0
ファイル: UDT.cs プロジェクト: Danmer/uberdemotools
        private static bool CutDemosByPatternImpl(ArgumentResources resources, ref udtParseArg parseArg, List<string> filePaths, udtPatternInfo[] patterns, CutByPatternOptions options)
        {
            var errorCodeArray = new Int32[filePaths.Count];
            var filePathArray = new IntPtr[filePaths.Count];
            for(var i = 0; i < filePaths.Count; ++i)
            {
                filePathArray[i] = Marshal.StringToHGlobalAnsi(Path.GetFullPath(filePaths[i]));
                resources.GlobalAllocationHandles.Add(filePathArray[i]);
            }

            parseArg.PlugInCount = 0;
            parseArg.PlugIns = IntPtr.Zero;

            var pinnedFilePaths = new PinnedObject(filePathArray);
            var pinnedErrorCodes = new PinnedObject(errorCodeArray);
            var multiParseArg = new udtMultiParseArg();
            multiParseArg.FileCount = (UInt32)filePathArray.Length;
            multiParseArg.FilePaths = pinnedFilePaths.Address;
            multiParseArg.OutputErrorCodes = pinnedErrorCodes.Address;
            multiParseArg.MaxThreadCount = (UInt32)options.MaxThreadCount;

            var playerNameUnmanaged = IntPtr.Zero;
            if(!string.IsNullOrEmpty(options.PlayerName))
            {
                playerNameUnmanaged = Marshal.StringToHGlobalAnsi(options.PlayerName);
                resources.GlobalAllocationHandles.Add(playerNameUnmanaged);
            }

            var pinnedPatterns = new PinnedObject(patterns);
            var cutByPatternArg = new udtCutByPatternArg();
            cutByPatternArg.StartOffsetSec = (UInt32)options.StartOffset;
            cutByPatternArg.EndOffsetSec = (UInt32)options.EndOffset;
            cutByPatternArg.Patterns = pinnedPatterns.Address;
            cutByPatternArg.PatternCount = (UInt32)patterns.Length;
            cutByPatternArg.PlayerIndex = options.PlayerIndex;
            cutByPatternArg.PlayerName = playerNameUnmanaged;
            cutByPatternArg.Flags = 0;
            if(options.MergeCutSections)
            {
                cutByPatternArg.Flags |= (UInt32)udtCutByPatternArgFlags.MergeCutSections;
            }

            resources.PinnedObjects.Add(pinnedPatterns);
            resources.PinnedObjects.Add(pinnedFilePaths);
            resources.PinnedObjects.Add(pinnedErrorCodes);

            udtErrorCode result = udtErrorCode.OperationFailed;
            try
            {
                result = udtCutDemoFilesByPattern(ref parseArg, ref multiParseArg, ref cutByPatternArg);
            }
            finally
            {
                resources.Free();
            }

            return result == udtErrorCode.None;
        }
コード例 #3
0
ファイル: UDT.cs プロジェクト: Danmer/uberdemotools
        private static bool ConvertDemosImpl(ref udtParseArg parseArg, udtProtocol outProtocol, List<MapConversionRule> mapRules, List<string> filePaths, int maxThreadCount)
        {
            var resources = new ArgumentResources();
            var errorCodeArray = new Int32[filePaths.Count];
            var filePathArray = new IntPtr[filePaths.Count];
            for(var i = 0; i < filePaths.Count; ++i)
            {
                var filePath = Marshal.StringToHGlobalAnsi(Path.GetFullPath(filePaths[i]));
                filePathArray[i] = filePath;
                resources.GlobalAllocationHandles.Add(filePath);
            }

            var pinnedFilePaths = new PinnedObject(filePathArray);
            var pinnedErrorCodes = new PinnedObject(errorCodeArray);
            resources.PinnedObjects.Add(pinnedFilePaths);
            resources.PinnedObjects.Add(pinnedErrorCodes);
            var multiParseArg = new udtMultiParseArg();
            multiParseArg.FileCount = (UInt32)filePathArray.Length;
            multiParseArg.FilePaths = pinnedFilePaths.Address;
            multiParseArg.OutputErrorCodes = pinnedErrorCodes.Address;
            multiParseArg.MaxThreadCount = (UInt32)maxThreadCount;

            var conversionArg = new udtProtocolConversionArg();
            conversionArg.OutputProtocol = (UInt32)outProtocol;
            conversionArg.MapRules = IntPtr.Zero;
            conversionArg.MapRuleCount = 0;
            if(mapRules.Count > 0)
            {
                var mapRuleArray = new udtMapConversionRule[mapRules.Count];
                for(var i = 0; i < mapRules.Count; ++i)
                {
                    var inputName = Marshal.StringToHGlobalAnsi(mapRules[i].InputName);
                    var outputName = Marshal.StringToHGlobalAnsi(mapRules[i].OutputName);
                    mapRuleArray[i].InputName = inputName;
                    mapRuleArray[i].OutputName = outputName;
                    mapRuleArray[i].PositionOffsetX = mapRules[i].OffsetX;
                    mapRuleArray[i].PositionOffsetY = mapRules[i].OffsetY;
                    mapRuleArray[i].PositionOffsetZ = mapRules[i].OffsetZ;
                    resources.GlobalAllocationHandles.Add(inputName);
                    resources.GlobalAllocationHandles.Add(outputName);
                }
                var pinnedMapRules = new PinnedObject(mapRuleArray);
                resources.PinnedObjects.Add(pinnedMapRules);
                conversionArg.MapRules = pinnedMapRules.Address;
                conversionArg.MapRuleCount = (UInt32)mapRuleArray.Length;
            }

            var result = udtErrorCode.OperationFailed;
            try
            {
                result = udtConvertDemoFiles(ref parseArg, ref multiParseArg, ref conversionArg);
            }
            finally
            {
                resources.Free();
            }

            return result != udtErrorCode.None;
        }
コード例 #4
0
ファイル: UDT.cs プロジェクト: Danmer/uberdemotools
 private static extern udtErrorCode udtParseDemoFiles(ref udtParserContextGroupRef contextGroup, ref udtParseArg info, ref udtMultiParseArg extraInfo);
コード例 #5
0
ファイル: UDT.cs プロジェクト: Danmer/uberdemotools
 private static extern udtErrorCode udtCutDemoFilesByPattern(ref udtParseArg info, ref udtMultiParseArg extraInfo, ref udtCutByPatternArg patternInfo);
コード例 #6
0
ファイル: UDT.cs プロジェクト: Danmer/uberdemotools
 private static extern udtErrorCode udtConvertDemoFiles(ref udtParseArg info, ref udtMultiParseArg extraInfo, ref udtProtocolConversionArg conversionInfo);