internal static void Init() { #if ML MelonLoader.MelonCoroutines.Start(Update()); #else ExplorerCore.LogError("Execute in main not supported yet."); return; #endif }
public static void Start() { if (Running) { throw new Exception("Already Running"); } Running = true; ProtocolManager.Listen(Server); #if ML MelonLoader.MelonCoroutines.Start(Reader()); #else ExplorerCore.LogError("TCP Web Server not supported yet."); return; #endif Server.Start(); ExplorerCore.Log("Server Started"); }
static ProtocolMap() { ProtocolKlasses = Assembly.GetAssembly(typeof(IMessage)).GetTypes().Where(type => { if (!type.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMessage <>))) { return(false); } var descriptor = GetDescriptor(type); if (descriptor == null) { return(false); } var options = descriptor.GetOptions(); if ((options) == null) { return(false); } return(options.HasExtension(CommandExtensions.DataId)); } ).ToList(); foreach (var protocolKlass in ProtocolKlasses) { var descriptor = GetDescriptor(protocolKlass); var ID = descriptor.GetOptions().GetExtension(CommandExtensions.DataId); if (ProtocolCache.Forward.HasEntry(ID)) { ExplorerCore.LogError($"{protocolKlass.FullName} (data_id) is a duplicate of {ProtocolCache.Forward[ID].FullName}. skipping"); continue; } ProtocolCache.Add(ID, protocolKlass); AddProtocolMessage(protocolKlass); } }
private static void ProcessNextOfCoroutine(IEnumerator enumerator) { try { if (!enumerator.MoveNext()) // Run the next step of the coroutine. If it's done, restore the parent routine { var indices = ourCoroutinesStore.Select((it, idx) => (idx, it)).Where(it => it.it.WaitCondition == enumerator).Select(it => it.idx).ToList(); for (var i = indices.Count - 1; i >= 0; i--) { var index = indices[i]; ourNextFrameCoroutines.Add(ourCoroutinesStore[index].Coroutine); ourCoroutinesStore.RemoveAt(index); } return; } } catch (Exception e) { ExplorerCore.LogError(e.ToString()); Stop(FindOriginalCoro(enumerator)); // We want the entire coroutine hierachy to stop when an error happen } var next = enumerator.Current; switch (next) { case null: ourNextFrameCoroutines.Add(enumerator); return; case WaitForFixedUpdate _: ourWaitForFixedUpdateCoroutines.Add(enumerator); return; case WaitForEndOfFrame _: ourWaitForEndOfFrameCoroutines.Add(enumerator); return; case WaitForSeconds _: break; // do nothing, this one is supported in Process case Il2CppObjectBase il2CppObjectBase: var nextAsEnumerator = il2CppObjectBase.TryCast <Il2CppSystem.Collections.IEnumerator>(); if (nextAsEnumerator != null) // il2cpp IEnumerator also handles CustomYieldInstruction { next = new Il2CppEnumeratorWrapper(nextAsEnumerator); } else { ExplorerCore.LogWarning($"Unknown coroutine yield object of type {il2CppObjectBase} for coroutine {enumerator}"); } break; } ourCoroutinesStore.Add(new CoroTuple { WaitCondition = next, Coroutine = enumerator }); if (next is IEnumerator nextCoro) { ProcessNextOfCoroutine(nextCoro); } }
public override void DrawWindow() { GUILayout.Label("<b><size=15><color=cyan>C# Console</color></size></b>", new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.UpperLeft; // SCRIPT INPUT GUILayout.Label("Enter code here as though it is a method body:", new GUILayoutOption[0]); inputAreaScroll = GUIHelper.BeginScrollView( inputAreaScroll, new GUILayoutOption[] { GUILayout.Height(250), GUIHelper.ExpandHeight(true) } ); GUI.SetNextControlName(INPUT_CONTROL_NAME); m_input = GUIHelper.TextArea(m_input, new GUILayoutOption[] { GUIHelper.ExpandHeight(true) }); GUIHelper.EndScrollView(); // EXECUTE BUTTON if (GUILayout.Button("<color=cyan><b>Execute</b></color>", new GUILayoutOption[0])) { try { m_input = m_input.Trim(); if (!string.IsNullOrEmpty(m_input)) { Evaluate(m_input); //var result = Evaluate(m_input); //if (result != null && !Equals(result, VoidType.Value)) //{ // ExplorerCore.Log("[Console Output]\r\n" + result.ToString()); //} } } catch (Exception e) { ExplorerCore.LogError("Exception compiling!\r\nMessage: " + e.Message + "\r\nStack: " + e.StackTrace); } } // SUGGESTIONS if (AutoCompletes.Count > 0) { autocompleteScroll = GUIHelper.BeginScrollView(autocompleteScroll, new GUILayoutOption[] { GUILayout.Height(150) }); var origSkin = GUI.skin.button; GUI.skin.button = AutocompleteStyle; foreach (var autocomplete in AutoCompletes) { AutocompleteStyle.normal.textColor = autocomplete.TextColor; if (GUILayout.Button(autocomplete.Full, new GUILayoutOption[] { GUILayout.Width(MainMenu.MainRect.width - 50) })) { UseAutocomplete(autocomplete.Addition); break; } } GUI.skin.button = origSkin; GUIHelper.EndScrollView(); } if (shouldRefocus) { GUI.FocusControl(INPUT_CONTROL_NAME); shouldRefocus = false; } // USING DIRECTIVES GUILayout.Label("<b>Using directives:</b>", new GUILayoutOption[0]); GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Add namespace:", new GUILayoutOption[] { GUILayout.Width(105) }); m_usingInput = GUIHelper.TextField(m_usingInput, new GUILayoutOption[] { GUILayout.Width(150) }); if (GUILayout.Button("<b><color=lime>Add</color></b>", new GUILayoutOption[] { GUILayout.Width(120) })) { AddUsing(m_usingInput); } if (GUILayout.Button("<b><color=red>Clear All</color></b>", new GUILayoutOption[] { GUILayout.Width(120) })) { ResetConsole(); } GUILayout.EndHorizontal(); foreach (var asm in UsingDirectives) { GUILayout.Label(AsmToUsing(asm, true), new GUILayoutOption[0]); } CheckAutocomplete(); }