Exemplo n.º 1
0
 private static void ProcessItemList(IList <Item> items, ProcessMethod method)
 {
     for (int index = items.Count - 1; index >= 0; --index)
     {
         items[index] = ProcessSingleItem(items[index], method);
     }
 }
Exemplo n.º 2
0
        private static Item ProcessSingleItem(Item item, ProcessMethod method)
        {
            if (item is Chest chest)
            {
                ProcessItemList(chest.items, method);
            }
            else if (item is StardewValley.Object @object &&
                     @object.heldObject.Value is Chest chest2)
            {
                ProcessItemList(chest2.items, method);
            }

            if (method == ProcessMethod.Remove && item is EasterEggItem easterEggItem)
            {
                return(new StardewValley.Object(EASTER_EGG_REPLACEMENT_ITEM, easterEggItem.Stack)
                {
                    name = UNIQUE_NAME_FOR_EASTER_EGG_ITEMS
                });
            }
            else if (method == ProcessMethod.Restore &&
                     item is StardewValley.Object @object &&
                     @object.parentSheetIndex == EASTER_EGG_REPLACEMENT_ITEM &&
                     @object.name == UNIQUE_NAME_FOR_EASTER_EGG_ITEMS)
            {
                return(new EasterEggItem()
                {
                    Stack = @object.Stack
                });
            }

            return(item);
        }
Exemplo n.º 3
0
    string ProcessLine(string line, string startSequence, string endSequence, ProcessMethod processMethod)
    {
        int  startIndex = 0;
        bool done       = false;

        while (!done)
        {
            int start = line.IndexOf(startSequence, startIndex);
            if (start != -1)
            {
                int end = line.IndexOf(endSequence);
                if (end != -1)
                {
                    int    startChunk = start + startSequence.Length;
                    int    endChunk   = end;
                    string chunk      = line.Substring(startChunk, endChunk - startChunk);

                    int    endEnd  = end + endSequence.Length;
                    string replace = processMethod(chunk);
                    line       = line.Substring(0, start) + replace + line.Substring(endEnd, line.Length - endEnd);
                    startIndex = start + replace.Length;
                }
                else
                {
                    done = true;
                }
            }
            else
            {
                done = true;
            }
        }
        return(line);
    }
Exemplo n.º 4
0
        public void Update_ProcessMethod()
        {
            ListBox processMethod_ListBox = ControlExtensions.FindControl <ListBox>(this, "processMethod_ListBox");

            if (processMethod_ListBox.SelectedItem == null)
            {
                ResourceManager.mainWindowVM.Tips = "需要选定要更新的ProcessMethod!";
                return;
            }
            ProcessMethod processMethod = (ProcessMethod)processMethod_ListBox.SelectedItem;

            ListBox process_ListBox = ControlExtensions.FindControl <ListBox>(this, "process_ListBox");

            if (process_ListBox.SelectedItem == null)
            {
                ResourceManager.mainWindowVM.Tips = "需要选定进程模板!";
                return;
            }
            Process process = (Process)process_ListBox.SelectedItem;

            ListBox method_ListBox = ControlExtensions.FindControl <ListBox>(this, "method_ListBox");

            if (method_ListBox.SelectedItem == null)
            {
                ResourceManager.mainWindowVM.Tips = "需要选定方法!";
                return;
            }
            Method method = (Method)method_ListBox.SelectedItem;

            processMethod.Process             = process;
            processMethod.Method              = method;
            ResourceManager.mainWindowVM.Tips = "更新了ProcessMethod:" + processMethod;
        }
Exemplo n.º 5
0
        public ArrayList RunningProcesses()
        {
            ArrayList alProcesses = new ArrayList();

            alProcesses = ProcessMethod.RunningProcesses(connectionScope);
            return(alProcesses);
        }
Exemplo n.º 6
0
 public static void ProcessEntries(object source, object checkData, ProcessMethod method)
 {
     foreach (XmlReader entry in ReadEntries(source, checkData))
     {
         method(entry);
     }
 }
Exemplo n.º 7
0
        public void Add_ProcessMethod()
        {
            ListBox process_ListBox = ControlExtensions.FindControl <ListBox>(this, "process_ListBox");

            if (process_ListBox.SelectedItem == null)
            {
                ResourceManager.mainWindowVM.Tips = "需要选定进程模板!";
                return;
            }
            Process process = (Process)process_ListBox.SelectedItem;

            ListBox method_ListBox = ControlExtensions.FindControl <ListBox>(this, "method_ListBox");

            if (method_ListBox.SelectedItem == null)
            {
                ResourceManager.mainWindowVM.Tips = "需要选定方法!";
                return;
            }
            Method method = (Method)method_ListBox.SelectedItem;

            ProcessMethod processMethod = new ProcessMethod(process, method);

            ((Axiom_EW_VM)DataContext).Axiom.ProcessMethods.Add(processMethod);
            ResourceManager.mainWindowVM.Tips = "添加了ProcessMethod:" + processMethod;
        }
Exemplo n.º 8
0
        public ArrayList ProcessProperties(string processName)
        {
            ArrayList alProperties = new ArrayList();

            alProperties = ProcessMethod.ProcessProperties(connectionScope,
                                                           processName);
            return(alProperties);
        }
Exemplo n.º 9
0
    protected override IEnumerator RespondToCommandInternal(string inputCommand)
    {
        if (ProcessMethod == null)
        {
            Debug.LogError("A declared TwitchPlays SimpleModComponentSolver process method is <null>, yet a component solver has been created; command invokation will not continue.");
            yield break;
        }

        KMSelectable[] selectableSequence = null;

        try
        {
            selectableSequence = (KMSelectable[])ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand });
            if (selectableSequence == null || selectableSequence.Length == 0)
            {
                yield break;
            }
        }
        catch (Exception ex)
        {
            Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", ProcessMethod.DeclaringType.FullName, ProcessMethod.Name);
            Debug.LogException(ex);
            yield break;
        }

        yield return("modsequence");

        int beforeInteractionStrikeCount = StrikeCount;

        for (int selectableIndex = 0; selectableIndex < selectableSequence.Length; ++selectableIndex)
        {
            if (Canceller.ShouldCancel)
            {
                Canceller.ResetCancel();
                yield break;
            }

            KMSelectable selectable = selectableSequence[selectableIndex];
            if (selectable == null)
            {
                yield return(new WaitForSeconds(0.1f));

                continue;
            }

            DoInteractionStart(selectable);
            yield return(new WaitForSeconds(0.1f));

            DoInteractionEnd(selectable);

            //Escape the sequence if a part of the given sequence is wrong, or if part of the sequence solved the module.
            //This means it is no longer possible to death warp a bomb in twitch plays. Kappa Keepo
            if (StrikeCount != beforeInteractionStrikeCount || Solved)
            {
                yield break;
            }
        }
    }
        public static void Process(ProcessMethod method, string baseFolderPath)
        {
            switch (method)
            {
            case ProcessMethod.ByDateTaken:
                ByDateTaken(baseFolderPath);
                break;

            case ProcessMethod.ByDateModified:
                ByDateModified(baseFolderPath);
                break;
            }
        }
Exemplo n.º 11
0
        private static void ProcessLocation(GameLocation location, ProcessMethod method)
        {
            if (location == null)
            {
                return;
            }

            ModEntry.Log("EasterEggFunctions.ProcessLocation(" + location.Name + ", " + method + ")", StardewModdingAPI.LogLevel.Trace);

            if (processedLocations.Contains(location))
            {
                ModEntry.Log("EasterEggFunctions.ProcessLocation(" + location.Name + ", " + method + "): Already processed this location (infinite recursion?), aborting!", StardewModdingAPI.LogLevel.Warn);
                return;
            }
            processedLocations.Add(location);

            if (location is BuildableGameLocation buildableGameLocation)
            {
                foreach (Building building in buildableGameLocation.buildings)
                {
                    ProcessLocation(building.indoors.Value, method);

                    if (building is Mill mill)
                    {
                        ProcessItemList(mill.output.Value.items, method);
                    }
                    else if (building is JunimoHut hut)
                    {
                        ProcessItemList(hut.output.Value.items, method);
                    }
                }
            }

            if (location is DecoratableLocation decoratableLocation)
            {
                foreach (Furniture furniture in decoratableLocation.furniture)
                {
                    furniture.heldObject.Value = (StardewValley.Object)ProcessSingleItem(furniture.heldObject.Value, method);
                }
            }

            if (location is FarmHouse farmHouse)
            {
                ProcessItemList(farmHouse.fridge.Value.items, method);
            }

            foreach (var key in new List <Vector2>(location.objects.Keys))
            {
                location.objects[key] = (StardewValley.Object)ProcessSingleItem(location.objects[key], method);
            }
        }
Exemplo n.º 12
0
        public void Delete_ProcessMethod()
        {
            ListBox processMethod_ListBox = ControlExtensions.FindControl <ListBox>(this, "processMethod_ListBox");

            if (processMethod_ListBox.SelectedItem == null)
            {
                ResourceManager.mainWindowVM.Tips = "需要选定要删除的ProcessMethod!";
                return;
            }
            ProcessMethod processMethod = (ProcessMethod)processMethod_ListBox.SelectedItem;

            ((Axiom_EW_VM)DataContext).Axiom.ProcessMethods.Remove(processMethod);
            ResourceManager.mainWindowVM.Tips = "删除了ProcessMethod:" + processMethod;
        }
    protected override IEnumerator RespondToCommandInternal(string inputCommand)
    {
        if (ProcessMethod == null)
        {
            Debug.LogError("A declared TwitchPlays SimpleModComponentSolver process method is <null>, yet a component solver has been created; command invokation will not continue.");
            yield break;
        }

        KMSelectable[] selectableSequence = null;

        try
        {
            selectableSequence = (KMSelectable[])ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand });
            if (selectableSequence == null || selectableSequence.Length == 0)
            {
                yield break;
            }
        }
        catch (Exception ex)
        {
            Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", ProcessMethod.DeclaringType.FullName, ProcessMethod.Name);
            Debug.LogException(ex);
            yield break;
        }
        
        yield return "modsequence";

        for(int selectableIndex = 0; selectableIndex < selectableSequence.Length; ++selectableIndex)
        {
            if (Canceller.ShouldCancel)
            {
                Canceller.ResetCancel();
                yield break;
            }

            KMSelectable selectable = selectableSequence[selectableIndex];
            if (selectable == null)
            {
                yield return new WaitForSeconds(0.1f);
                continue;
            }

            DoInteractionClick(selectable);
			yield return new WaitForSeconds(0.1f);
        }
    }
Exemplo n.º 14
0
        public void Update_ProcessMethod()
        {
            ListBox processMethod_ListBox = ControlExtensions.FindControl <ListBox>(this, "processMethod_ListBox");

            if (processMethod_ListBox.SelectedItem == null)
            {
                ResourceManager.mainWindowVM.Tips = "需要选定要更新的ProcessMethod!";
                return;
            }
            ProcessMethod processMethod = (ProcessMethod)processMethod_ListBox.SelectedItem;

            ListBox process_ListBox = ControlExtensions.FindControl <ListBox>(this, "process_ListBox");

            if (process_ListBox.SelectedItem == null)
            {
                ResourceManager.mainWindowVM.Tips = "需要选定进程模板!";
                return;
            }
            Process process = (Process)process_ListBox.SelectedItem;

            ListBox method_ListBox = ControlExtensions.FindControl <ListBox>(this, "method_ListBox");

            if (method_ListBox.SelectedItem == null)
            {
                ResourceManager.mainWindowVM.Tips = "需要选定方法!";
                return;
            }
            Method method = (Method)method_ListBox.SelectedItem;

            ObservableCollection <ProcessMethod> processMethods = ((Axiom_EW_VM)DataContext).Axiom.ProcessMethods;

            // 判重
            foreach (ProcessMethod pm in processMethods)
            {
                if (pm.Process == process && pm.Method == method)
                {
                    ResourceManager.mainWindowVM.Tips = "无效的操作。该进程方法已经添加过";
                    return;
                }
            }

            processMethod.Process             = process;
            processMethod.Method              = method;
            ResourceManager.mainWindowVM.Tips = "更新了ProcessMethod:" + processMethod;
        }
Exemplo n.º 15
0
        private static Item ProcessSingleItem(Item item, ProcessMethod method)
        {
            if (item == null)
            {
                return(item);
            }

            if (processedItems.Contains(item))
            {
                ModEntry.Log("EasterEggFunctions.ProcessSingleItem(" + item.Name + ", " + method + "): Already processed this item (infinite recursion?), aborting!", StardewModdingAPI.LogLevel.Warn);
                return(item);
            }
            processedItems.Add(item);

            if (item is Chest chest)
            {
                ProcessItemList(chest.items, method);
            }
            else if (item is StardewValley.Object @object &&
                     @object.heldObject.Value is Chest chest2)
            {
                ProcessItemList(chest2.items, method);
            }

            if (method == ProcessMethod.Remove && item is EasterEggItem easterEggItem)
            {
                return(new StardewValley.Object(EASTER_EGG_REPLACEMENT_ITEM, easterEggItem.Stack)
                {
                    name = UNIQUE_NAME_FOR_EASTER_EGG_ITEMS
                });
            }
            else if (method == ProcessMethod.Restore &&
                     item is StardewValley.Object @object &&
                     @object.ParentSheetIndex == EASTER_EGG_REPLACEMENT_ITEM &&
                     @object.name == UNIQUE_NAME_FOR_EASTER_EGG_ITEMS)
            {
                return(new EasterEggItem()
                {
                    Stack = @object.Stack
                });
            }

            return(item);
        }
Exemplo n.º 16
0
        private static void ProcessLocation(GameLocation location, ProcessMethod method)
        {
            if (location == null)
            {
                return;
            }

            if (location is BuildableGameLocation buildableGameLocation)
            {
                foreach (Building building in buildableGameLocation.buildings)
                {
                    ProcessLocation(building.indoors.Value, method);

                    if (building is Mill mill)
                    {
                        ProcessItemList(mill.output.Value.items, method);
                    }
                    else if (building is JunimoHut hut)
                    {
                        ProcessItemList(hut.output.Value.items, method);
                    }
                }
            }

            if (location is DecoratableLocation decoratableLocation)
            {
                foreach (Furniture furniture in decoratableLocation.furniture)
                {
                    furniture.heldObject.Value = (StardewValley.Object)ProcessSingleItem(furniture.heldObject.Value, method);
                }
            }

            if (location is FarmHouse farmHouse)
            {
                ProcessItemList(farmHouse.fridge.Value.items, method);
            }

            foreach (var key in new List <Vector2>(location.objects.Keys))
            {
                location.objects[key] = (StardewValley.Object)ProcessSingleItem(location.objects[key], method);
            }
        }
Exemplo n.º 17
0
 public void ReceiveMessage_Asyn(ProcessMethod callBack)
 {
     processMethod = new ProcessMethod(callBack);
     try
     {
         // m_recvBuf = new byte[SocketParserConstants.MAX_SIZE_READ_PACKET_BUFFER];
         buffer = new byte[1024];
         EndPoint newClientEP = new IPEndPoint(IPAddress.Any, 0);
         // receive data from client
         serverSocket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref newClientEP, DoReceiveFrom, serverSocket);
     }
     catch (SocketException ex)
     {
         Console.WriteLine("SocketException Start: {0}", ex.Message);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Exception Start: {0}", ex.Message);
     }
 }
Exemplo n.º 18
0
        private static void ProcessAllInLocation(GameLocation location, ProcessMethod method)
        {
            if (location == null)
            {
                return;
            }

            ModEntry.Log("WoodsObelisk.ProcessAllInLocation(" + location.Name + ", " + method + ")", StardewModdingAPI.LogLevel.Trace);

            if (processedLocations.Contains(location))
            {
                ModEntry.Log("WoodsObelisk.ProcessAllInLocation(" + location.Name + ", " + method + "): Already processed this location (infinite recursion?), aborting!", StardewModdingAPI.LogLevel.Warn);
                return;
            }
            processedLocations.Add(location);

            if (location is BuildableGameLocation buildableGameLocation)
            {
                foreach (Building building in buildableGameLocation.buildings)
                {
                    if (building != null)
                    {
                        ProcessAllInLocation(building.indoors.Value, method);
                        if (method == ProcessMethod.Remove && building.buildingType.Value == WOODS_OBELISK_BUILDING_NAME)
                        {
                            building.buildingType.Value = EARTH_OBELISK_BUILDING_NAME;
                            DeepWoodsState.WoodsObeliskLocations.Add(new XY(building.tileX.Value, building.tileY.Value));
                        }
                        else if (method == ProcessMethod.Restore && building.buildingType.Value == EARTH_OBELISK_BUILDING_NAME)
                        {
                            if (DeepWoodsState.WoodsObeliskLocations.Contains(new XY(building.tileX.Value, building.tileY.Value)))
                            {
                                building.buildingType.Value = WOODS_OBELISK_BUILDING_NAME;
                                building.resetTexture();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
 private static void ProcessAllInLocation(GameLocation location, ProcessMethod method)
 {
     if (location is BuildableGameLocation buildableGameLocation)
     {
         foreach (Building building in buildableGameLocation.buildings)
         {
             ProcessAllInLocation(building.indoors.Value, method);
             if (method == ProcessMethod.Remove && building.buildingType == WOODS_OBELISK_BUILDING_NAME)
             {
                 building.buildingType.Value = EARTH_OBELISK_BUILDING_NAME;
                 DeepWoodsState.WoodsObeliskLocations.Add(new XY(building.tileX, building.tileY));
             }
             else if (method == ProcessMethod.Restore && building.buildingType == EARTH_OBELISK_BUILDING_NAME)
             {
                 if (DeepWoodsState.WoodsObeliskLocations.Contains(new XY(building.tileX, building.tileY)))
                 {
                     building.buildingType.Value = WOODS_OBELISK_BUILDING_NAME;
                     building.resetTexture();
                 }
             }
         }
     }
 }
    protected internal override IEnumerator RespondToCommandInternal(string inputCommand)
    {
        if (ProcessMethod == null)
        {
            DebugHelper.LogError("A declared TwitchPlays CoroutineModComponentSolver process method is <null>, yet a component solver has been created; command invokation will not continue.");
            yield break;
        }

        IEnumerator responseCoroutine;

        bool regexValid = ModInfo.validCommands == null;

        if (!regexValid)
        {
            foreach (string regex in ModInfo.validCommands)
            {
                regexValid = Regex.IsMatch(inputCommand, regex, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                if (regexValid)
                {
                    break;
                }
            }
        }
        if (!regexValid)
        {
            yield break;
        }

        try
        {
            responseCoroutine = (IEnumerator)ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand });
            if (responseCoroutine == null)
            {
                yield break;
            }
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex,
                                     $"An exception occurred while trying to invoke {ProcessMethod?.DeclaringType?.FullName}.{ProcessMethod.Name}; the command invocation will not continue.");

            yield break;
        }

        //Previous change lists mentioned that people using the TPAPI were not following strict rules about how coroutine implementations should be done, w.r.t. required yield returning first before doing things.
        //From the TPAPI side of things, this was *never* an explicit requirement. This yield return is here to explicitly follow the internal design for how component solvers are structured, so that external
        //code would never be executed until absolutely necessary.
        //There is the side-effect though that invalid commands sent to the module will appear as if they were 'correctly' processed, by executing the focus.
        //I'd rather have interactions that are not broken by timing mismatches, even if the tradeoff is that it looks like it accepted invalid commands.
        if (!ModInfo.DoesTheRightThing)
        {
            yield return("modcoroutine");
        }
        bool   result    = true;
        string exception = null;

        while (result)
        {
            try
            {
                result = responseCoroutine.MoveNext();
            }
            catch (Exception ex)
            {
                result = false;
loop:
                switch (ex)
                {
                case FormatException fex:
                    exception = fex.Message;
                    break;

                default:
                    if (ex.InnerException == null)
                    {
                        throw;
                    }
                    ex = ex.InnerException;
                    goto loop;
                }
            }
            if (result)
            {
                yield return(responseCoroutine.Current);
            }
            else if (exception != null)
            {
                yield return($"sendtochaterror!f {exception}");
            }
        }
    }
    protected internal override IEnumerator RespondToCommandInternal(string inputCommand)
    {
        if (ProcessMethod == null)
        {
            DebugHelper.LogError("A declared TwitchPlays SimpleModComponentSolver process method is <null>, yet a component solver has been created; command invocation will not continue.");
            yield break;
        }

        IList <KMSelectable> selectableList = null;

        string exception = null;

        try
        {
            bool regexValid = ModInfo.validCommands == null;
            if (!regexValid)
            {
                foreach (string regex in ModInfo.validCommands)
                {
                    regexValid = Regex.IsMatch(inputCommand, regex, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                    if (regexValid)
                    {
                        break;
                    }
                }
            }
            if (!regexValid)
            {
                yield break;
            }

            IEnumerable <KMSelectable> selectableSequence = (IEnumerable <KMSelectable>)ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand });
            if (selectableSequence == null)
            {
                yield break;
            }
            selectableList = selectableSequence as IList <KMSelectable> ?? selectableSequence.ToArray();
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex,
                                     $"An exception occurred while trying to invoke {ProcessMethod?.DeclaringType?.FullName}.{ProcessMethod.Name}; the command invocation will not continue.");
loop:
            switch (ex)
            {
            case FormatException fex:
                exception = fex.Message;
                break;

            default:
                if (ex.InnerException == null)
                {
                    throw;
                }
                ex = ex.InnerException;
                goto loop;
            }
        }

        if (exception != null)
        {
            yield return($"sendtochaterror {exception}");

            yield break;
        }

        if (selectableList?.Count == 0)
        {
            yield return(null);
        }
        else
        {
            yield return("modsequence");

            yield return("trycancelsequence");

            yield return(selectableList);
        }
    }
Exemplo n.º 22
0
 public void SetMethod(ProcessMethod method)
 {
     Process = method;
 }
Exemplo n.º 23
0
 public OptionProcessor(string name, ProcessMethod process)
 {
     Name    = name;
     Process = process;
 }
Exemplo n.º 24
0
 public string CreateCMDProcess(string processPath, string processName, string arguments)
 {
     return(ProcessMethod.StartProcess(Environment.MachineName, processPath + processName + " " + arguments));
 }
    protected override IEnumerator RespondToCommandInternal(string inputCommand)
    {
        if (ProcessMethod == null)
        {
            DebugHelper.LogError("A declared TwitchPlays SimpleModComponentSolver process method is <null>, yet a component solver has been created; command invokation will not continue.");
            yield break;
        }

        KMSelectable[] selectableSequence = null;

        try
        {
            bool RegexValid = modInfo.validCommands == null;
            if (!RegexValid)
            {
                foreach (string regex in modInfo.validCommands)
                {
                    RegexValid = Regex.IsMatch(inputCommand, regex, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                    if (RegexValid)
                    {
                        break;
                    }
                }
            }
            if (!RegexValid)
            {
                yield break;
            }

            selectableSequence = (KMSelectable[])ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand });
            if (selectableSequence == null || selectableSequence.Length == 0)
            {
                yield break;
            }
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex, string.Format("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", ProcessMethod.DeclaringType.FullName, ProcessMethod.Name));
            yield break;
        }

        if (!modInfo.DoesTheRightThing)
        {
            yield return("modsequence");
        }

        for (int selectableIndex = 0; selectableIndex < selectableSequence.Length; ++selectableIndex)
        {
            if (Canceller.ShouldCancel)
            {
                Canceller.ResetCancel();
                yield break;
            }

            KMSelectable selectable = selectableSequence[selectableIndex];
            if (selectable == null)
            {
                yield return(new WaitForSeconds(0.1f));

                continue;
            }

            DoInteractionClick(selectable);
            yield return(new WaitForSeconds(0.1f));
        }
    }
Exemplo n.º 26
0
	string ProcessLine(string line, string startSequence, string endSequence, ProcessMethod processMethod)
	{
		int startIndex = 0;
		bool done = false;
		while (!done)
		{
			int start = line.IndexOf(startSequence, startIndex);
			if (start != -1)
			{
				int end = line.IndexOf(endSequence);
				if (end != -1)
				{
					int startChunk = start + startSequence.Length;
					int endChunk = end;
					string chunk = line.Substring(startChunk, endChunk - startChunk);

					int endEnd = end + endSequence.Length;
					string replace = processMethod(chunk);
					line = line.Substring(0, start) + replace + line.Substring(endEnd, line.Length - endEnd);
					startIndex = start + replace.Length;
				}
				else
				{
					done = true;
				}
			}
			else
			{
				done = true;
			}
		}
		return line;
	}
Exemplo n.º 27
0
 public void TerminateProcess(string processName)
 {
     ProcessMethod.KillProcess(connectionScope, processName);
 }
Exemplo n.º 28
0
 public void SetPriority(string processName, ProcessPriority.priority priority)
 {
     ProcessMethod.ChangePriority(connectionScope, processName, priority);
 }
Exemplo n.º 29
0
 public string GetProcessOwnerSID(string processName)
 {
     return(ProcessMethod.ProcessOwnerSID(connectionScope, processName));
 }
    protected override IEnumerator RespondToCommandInternal(string inputCommand)
    {
        if (ProcessMethod == null)
        {
            Debug.LogError("A declared TwitchPlays CoroutineModComponentSolver process method is <null>, yet a component solver has been created; command invokation will not continue.");
            yield break;
        }

        IEnumerator responseCoroutine = null;

        try
        {
            responseCoroutine = (IEnumerator)ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand });
            if (responseCoroutine == null)
            {
                yield break;
            }
        }
        catch (Exception ex)
        {
            Debug.LogErrorFormat("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", ProcessMethod.DeclaringType.FullName, ProcessMethod.Name);
            Debug.LogException(ex);
            yield break;
        }

        //Previous changelists mentioned that people using the TPAPI were not following strict rules about how coroutine implementations should be done, w.r.t. required yield returning first before doing things.
        //From the TPAPI side of things, this was *never* an explicit requirement. This yield return is here to explicitly follow the internal design for how component solvers are structured, so that external
        //code would never be executed until absolutely necessary.
        //There is the side-effect though that invalid commands sent to the module will appear as if they were 'correctly' processed, by executing the focus.
        //I'd rather have interactions that are not broken by timing mismatches, even if the tradeoff is that it looks like it accepted invalid commands.
        yield return("modcoroutine");

        while (true)
        {
            try
            {
                if (!responseCoroutine.MoveNext())
                {
                    yield break;
                }
            }
            catch (Exception ex)
            {
                Debug.LogErrorFormat(
                    "An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.",
                    ProcessMethod.DeclaringType.FullName, ProcessMethod.Name);
                Debug.LogException(ex);
                yield break;
            }

            object currentObject = responseCoroutine.Current;
            if (currentObject is KMSelectable)
            {
                KMSelectable selectable = (KMSelectable)currentObject;
                if (HeldSelectables.Contains(selectable))
                {
                    DoInteractionEnd(selectable);
                    HeldSelectables.Remove(selectable);
                }
                else
                {
                    DoInteractionStart(selectable);
                    HeldSelectables.Add(selectable);
                }
            }
            if (currentObject is KMSelectable[])
            {
                KMSelectable[] selectables = (KMSelectable[])currentObject;
                foreach (KMSelectable selectable in selectables)
                {
                    DoInteractionClick(selectable);
                    yield return(new WaitForSeconds(0.1f));
                }
            }
            if (currentObject is string)
            {
                string str = (string)currentObject;
                if (str.Equals("cancelled", StringComparison.InvariantCultureIgnoreCase))
                {
                    Canceller.ResetCancel();
                    TryCancel = false;
                }
            }
            yield return(currentObject);

            if (Canceller.ShouldCancel)
            {
                TryCancel = true;
            }
        }
    }
Exemplo n.º 31
0
        protected override IEnumerator RespondToCommandInternal(string inputCommand)
        {
            string exception = null;

            switch (ShimData.ModCommandType)
            {
            case ModCommandType.Simple:
                KMSelectable[] selectables = null;
                try
                {
                    selectables = (KMSelectable[])ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand });
                }
                catch (FormatException ex)
                {
                    DebugHelper.LogException(ex, string.Format("An exception occurred while trying to invoke {0}.{1}; the command invocation will not continue.", ProcessMethod?.DeclaringType?.FullName, ProcessMethod?.Name));
                    exception = ex.Message;
                }
                catch (Exception ex)
                {
                    DebugHelper.LogException(ex, string.Format("An exception occurred while trying to invoke {0}.{1}; the command invocation will not continue.", ProcessMethod?.DeclaringType?.FullName, ProcessMethod?.Name));
                    throw;
                }
                if (selectables != null && selectables.Length > 0)
                {
                    yield return("modsimple");

                    yield return("trycancelsequence");

                    yield return(selectables);
                }
                break;

            case ModCommandType.Coroutine:
                IEnumerator handler;
                bool        result;
                try
                {
                    handler = (IEnumerator)ProcessMethod.Invoke(CommandComponent, new object[] { inputCommand });
                    result  = handler != null;
                }
                catch (Exception ex)
                {
                    DebugHelper.LogException(ex, string.Format("An exception occurred while trying to invoke {0}.{1}; the command invokation will not continue.", ProcessMethod?.DeclaringType?.FullName, ProcessMethod?.Name));
                    yield break;
                }

                while (result)
                {
                    try
                    {
                        result = handler.MoveNext();
                    }
                    catch (FormatException ex)
                    {
                        DebugHelper.LogException(ex, string.Format("An exception occurred while trying to invoke {0}.{1}; the command invocation will not continue.", ProcessMethod?.DeclaringType?.FullName, ProcessMethod.Name));
                        result    = false;
                        exception = ex.Message;
                    }
                    catch (Exception ex)
                    {
                        DebugHelper.LogException(ex, string.Format("An exception occurred while trying to invoke {0}.{1}; the command invocation will not continue.", ProcessMethod?.DeclaringType?.FullName, ProcessMethod.Name));
                        throw;
                    }
                    if (result)
                    {
                        yield return(handler.Current);
                    }
                }
                break;
            }
            if (exception != null)
            {
                yield return($"sendtochaterror {exception}");
            }
        }