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; }
public static bool CutDemosByPattern(ArgumentResources resources, ref udtParseArg parseArg, List<string> filePaths, udtPatternInfo[] patterns, CutByPatternOptions options) { var timer = new Stopwatch(); timer.Start(); var fileCount = filePaths.Count; if(fileCount <= MaxBatchSizeCutting) { var result = CutDemosByPatternImpl(resources, ref parseArg, filePaths, patterns, options); PrintExecutionTime(timer); return result; } var oldProgressCb = parseArg.ProgressCb; var progressBase = 0.0f; var progressRange = 0.0f; var fileIndex = 0; var newParseArg = parseArg; newParseArg.ProgressCb = delegate(float progress, IntPtr userData) { var realProgress = progressBase + progressRange * progress; oldProgressCb(realProgress, userData); }; var demos = new List<DemoInfo>(); var batchCount = (fileCount + MaxBatchSizeCutting - 1) / MaxBatchSizeCutting; var filesPerBatch = fileCount / batchCount; var success = true; for(int i = 0; i < batchCount; ++i) { progressBase = (float)fileIndex / (float)fileCount; var currentFileCount = (i == batchCount - 1) ? (fileCount - fileIndex) : filesPerBatch; var currentFiles = filePaths.GetRange(fileIndex, currentFileCount); progressRange = (float)currentFileCount / (float)fileCount; var newResources = new ArgumentResources(); CutDemosByPatternImpl(newResources, ref newParseArg, currentFiles, patterns, options); fileIndex += currentFileCount; if(Marshal.ReadInt32(parseArg.CancelOperation) != 0) { success = false; break; } } resources.Free(); PrintExecutionTime(timer); return success; }
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; }
public static bool CutDemosByMultiRail(ref udtParseArg parseArg, List<string> filePaths, udtCutByMultiRailArg rules, CutByPatternOptions options) { var resources = new ArgumentResources(); var patterns = new udtPatternInfo[1]; if(!CreateMultiRailPatternInfo(ref patterns[0], resources, rules)) { return false; } return CutDemosByPattern(resources, ref parseArg, filePaths, patterns, options); }
public static bool CreateMultiRailPatternInfo(ref udtPatternInfo pattern, ArgumentResources resources, udtCutByMultiRailArg rules) { var pinnedRules = new PinnedObject(rules); resources.PinnedObjects.Add(pinnedRules); pattern.Type = (UInt32)udtPatternType.MultiFragRails; pattern.TypeSpecificInfo = pinnedRules.Address; return true; }
public static bool CreateFlagCapturePatternInfo(ref udtPatternInfo pattern, ArgumentResources resources, udtCutByFlagCaptureArg rules) { var pinnedRules = new PinnedObject(rules); resources.PinnedObjects.Add(pinnedRules); pattern.Type = (UInt32)udtPatternType.FlagCaptures; pattern.TypeSpecificInfo = pinnedRules.Address; return true; }
public static bool CreateChatPatternInfo(ref udtPatternInfo pattern, ArgumentResources resources, List<ChatRule> rules) { if(rules.Count == 0) { return false; } var rulesArray = new UDT_DLL.udtCutByChatRule[rules.Count]; for(var i = 0; i < rules.Count; ++i) { rulesArray[i].CaseSensitive = (UInt32)(rules[i].CaseSensitive ? 1 : 0); rulesArray[i].ChatOperator = GetOperatorFromString(rules[i].Operator); rulesArray[i].IgnoreColorCodes = (UInt32)(rules[i].IgnoreColors ? 1 : 0); rulesArray[i].Pattern = Marshal.StringToHGlobalAnsi(rules[i].Value); resources.GlobalAllocationHandles.Add(rulesArray[i].Pattern); } var pinnedRulesArray = new PinnedObject(rulesArray); var cutByChatArg = new udtCutByChatArg(); cutByChatArg.Rules = pinnedRulesArray.Address; cutByChatArg.RuleCount = (UInt32)rulesArray.Length; var pinnedRules = new PinnedObject(cutByChatArg); resources.PinnedObjects.Add(pinnedRulesArray); resources.PinnedObjects.Add(pinnedRules); pattern.Type = (UInt32)udtPatternType.GlobalChat; pattern.TypeSpecificInfo = pinnedRules.Address; return true; }
static private void DoAction(PatternAction action, uint selectedPatterns, bool saveConfigs) { var app = App.Instance; var demos = app.SelectedWriteDemos; if (demos == null) { return; } if (selectedPatterns == 0) { app.LogError("You didn't check any pattern. Please check at least one to proceed."); return; } if (saveConfigs) { app.SaveBothConfigs(); } var privateConfig = app.PrivateConfig; if (privateConfig.PatternCutPlayerIndex == int.MinValue && string.IsNullOrEmpty(privateConfig.PatternCutPlayerName)) { app.LogError("The selected player name is empty. Please specify a player name or select a different matching method to proceed."); return; } var filePaths = new List <string>(); foreach (var demo in demos) { filePaths.Add(demo.FilePath); } var config = app.Config; var patterns = new List <UDT_DLL.udtPatternInfo>(); var resources = new ArgumentResources(); if (IsPatternActive(selectedPatterns, UDT_DLL.udtPatternType.Chat)) { if (config.ChatRules.Count == 0) { app.LogError("[chat] No chat matching rule defined. Please add at least one to proceed."); return; } var pattern = new UDT_DLL.udtPatternInfo(); UDT_DLL.CreateChatPatternInfo(ref pattern, resources, config.ChatRules); patterns.Add(pattern); } if (IsPatternActive(selectedPatterns, UDT_DLL.udtPatternType.FragSequences)) { if (privateConfig.FragCutAllowedMeansOfDeaths == 0) { app.LogError("[frag sequence] You didn't check any Mean of Death. Please check at least one to proceed."); return; } if (config.FragCutMinFragCount < 2) { app.LogError("[frag sequence] 'Min. Frag Count' must be 2 or higher."); return; } if (config.FragCutTimeBetweenFrags < 1) { app.LogError("[frag sequence] 'Time Between Frags' must be strictly positive."); return; } var pattern = new UDT_DLL.udtPatternInfo(); var rules = UDT_DLL.CreateCutByFragArg(config, app.PrivateConfig); UDT_DLL.CreateFragPatternInfo(ref pattern, resources, rules); patterns.Add(pattern); } if (IsPatternActive(selectedPatterns, UDT_DLL.udtPatternType.MidAirFrags)) { if (!config.MidAirCutAllowRocket && !config.MidAirCutAllowBFG) { app.LogError("[mid-air frags] You didn't check any weapon. Please check at least one to proceed."); return; } var pattern = new UDT_DLL.udtPatternInfo(); var rules = UDT_DLL.CreateCutByMidAirArg(config); UDT_DLL.CreateMidAirPatternInfo(ref pattern, resources, rules); patterns.Add(pattern); } if (IsPatternActive(selectedPatterns, UDT_DLL.udtPatternType.MultiFragRails)) { var pattern = new UDT_DLL.udtPatternInfo(); var rules = UDT_DLL.CreateCutByMultiRailArg(config); UDT_DLL.CreateMultiRailPatternInfo(ref pattern, resources, rules); patterns.Add(pattern); } if (IsPatternActive(selectedPatterns, UDT_DLL.udtPatternType.FlagCaptures)) { if (!config.FlagCaptureAllowBaseToBase && !config.FlagCaptureAllowMissingToBase) { app.LogError("[flag captures] You disabled both base and non-base pick-ups. Please enable at least one of them to proceed."); return; } var pattern = new UDT_DLL.udtPatternInfo(); var rules = UDT_DLL.CreateCutByFlagCaptureArg(config); UDT_DLL.CreateFlagCapturePatternInfo(ref pattern, resources, rules); patterns.Add(pattern); } if (IsPatternActive(selectedPatterns, UDT_DLL.udtPatternType.FlickRails)) { if (config.FlickRailMinSpeed <= 0.0f && config.FlickRailMinAngleDelta <= 0.0f) { app.LogError("[flick rails] Both thresholds are negative or zero, which will match all railgun frags."); return; } var pattern = new UDT_DLL.udtPatternInfo(); var rules = UDT_DLL.CreateCutByFlickRailArg(config); UDT_DLL.CreateFlickRailPatternInfo(ref pattern, resources, rules); patterns.Add(pattern); } if (IsPatternActive(selectedPatterns, UDT_DLL.udtPatternType.Matches)) { var pattern = new UDT_DLL.udtPatternInfo(); var rules = UDT_DLL.CreateCutByMatchArg(config); UDT_DLL.CreateMatchPatternInfo(ref pattern, resources, rules); patterns.Add(pattern); } var threadArg = new ThreadArg(); threadArg.Demos = demos; threadArg.FilePaths = filePaths; threadArg.Patterns = patterns.ToArray(); threadArg.Resources = resources; app.DisableUiNonThreadSafe(); app.JoinJobThread(); switch (action) { case PatternAction.Cut: app.StartJobThread(DemoCutThread, threadArg); break; case PatternAction.Search: app.StartJobThread(DemoSearchThread, threadArg); break; default: break; } }