Esempio n. 1
0
 internal void addUserHook(UserHook userHook)
 {
     lock (this) {
         userHooks.Add(userHook);
         isDirty = true;
     }
 }
Esempio n. 2
0
 internal bool removeUserHook(UserHook userHook)
 {
     lock (this) {
         bool ok = userHooks.Remove(userHook);
         if (ok)
         {
             isDirty = true;
         }
     }
     return(isDirty);
 }
    void Awake()
    {
        this.gameObject.name = "UserHook";

        if (!instance)
        {
            instance = this;
            instance.Init();
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(this.gameObject);
        }
    }
Esempio n. 4
0
 private void tryLoad()
 {
     lock (this) {
         try {
             if (File.Exists(fileName))
             {
                 string      json       = File.ReadAllText(fileName);
                 var         serializer = Utils.getJsonSerializer();
                 IDictionary data       = serializer.DeserializeObject(json) as IDictionary;
                 userNames.Clear();
                 IList namesJson = data["names"] as IList;
                 foreach (IDictionary nameData in namesJson.Cast <IDictionary>())
                 {
                     string key      = nameData["key"] as string;
                     string sense    = nameData["sense"] as string;
                     string nameType = nameData["type"] as string;
                     addUserName(key, sense, nameType);
                 }
                 contextsEnabled.Clear();
                 IDictionary contextsJson = data["contexts"] as IDictionary;
                 foreach (DictionaryEntry kv in contextsJson)
                 {
                     contextsEnabled[long.Parse((string)kv.Key)] = (bool)kv.Value;
                 }
                 _newContextsBehavior = (MyContextFactory.NewContextsBehavior)Enum.Parse(typeof(MyContextFactory.NewContextsBehavior), (string)data["newContexts"]);
                 userHooks.Clear();
                 IList hooksJson = data["hooks"] as IList;
                 foreach (string code in hooksJson.Cast <string>())
                 {
                     UserHook hook = UserHook.fromCode(code);
                     if (hook != null)
                     {
                         userHooks.Add(hook);
                     }
                 }
                 _po = data["po"] as string;
                 if (data["sentenceDelay"] != null)
                 {
                     int sd = (int)data["sentenceDelay"];
                     _sentenceDelay = TimeSpan.FromMilliseconds(sd);
                 }
             }
         } catch (Exception e) {
             Logger.logException(e);
         }
         isDirty = false;
     }
 }
Esempio n. 5
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string code = textBox1.Text;

            code = code.Trim().ToUpper();
            if (code == "")
            {
                return;
            }
            UserHook userHook = UserHook.fromCode(code);

            if (userHook == null)
            {
                Utils.error("Cannot parse hook code. Please verify code syntax and try again.");
                return;
            }
            if (!TextHook.instance.addUserHook(userHook))
            {
                Utils.error("Failed to install hook.");
                return;
            }
            listBox1.Items.Add(userHook);
            textBox1.Text = "";
        }
Esempio n. 6
0
 internal bool isHookAlreadyInstalled(UserHook userHook)
 {
     return(userHooks.Any((h) => h.addr == userHook.addr));
 }