Exemplo n.º 1
0
        private void Add_Function(string name, int line, ScriptFile filein, Var_State state)
        {
            ScriptLabel scr_lab = new ScriptLabel();

            scr_lab.Name = name.ToUpperInvariant();
            scr_lab.Line = line;
            scr_lab.File = filein.Name;
            scr_lab.State = state;

            filein._functionlist.Add(scr_lab.Name, scr_lab);
        }
Exemplo n.º 2
0
        public void ReadFile(ScriptFile filein)
        {
            File = filein.Name;

            //gotta find the varbeing and varend and read in the middle
            bool cstarted = false;
            bool vstarted = false;
            bool cended   = false;

            string p1, p2, p3;

            for (int i = 0; i < filein._ScriptLines.Count; i++)
            {
                ScriptLine cmd = (ScriptLine)filein._ScriptLines[i];

                string line = cmd.UnParsedParams;

                switch (cmd.Command)
                {
                case ScriptCommands.INCLUDE:
                    if (!cstarted)
                    {
                        Globals.scriptthread.Script_INCLUDE(line);
                    }
                    break;

                case ScriptCommands.PUBLIC:
                    if (cstarted && vstarted)
                    {
                        //defining a variable
                        p1 = ScriptEngine.Get_String(ref line);
                        p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                        p3 = ScriptEngine.Get_String(ref line);

                        ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.PUBLIC);

                        _Variables.Add(nv);
                    }
                    else if (cstarted)
                    {
                        //a function
                        p1 = ScriptEngine.Get_String(ref line);
                        Add_Function(p1, i, filein, Var_State.PUBLIC);
                    }
                    break;

                case ScriptCommands.PRIVATE:
                    if (cstarted && vstarted)
                    {
                        //defining a variable
                        p1 = ScriptEngine.Get_String(ref line);
                        p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                        p3 = ScriptEngine.Get_String(ref line);

                        ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.PRIVATE);

                        _Variables.Add(nv);
                    }
                    else if (cstarted)
                    {
                        //a function
                        p1 = ScriptEngine.Get_String(ref line);
                        Add_Function(p1, i, filein, Var_State.PRIVATE);
                    }
                    break;

                case ScriptCommands.PROTECTED:
                    if (cstarted && vstarted)
                    {
                        //defining a variable
                        p1 = ScriptEngine.Get_String(ref line);
                        p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                        p3 = ScriptEngine.Get_String(ref line);

                        ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.PROTECTED);

                        _Variables.Add(nv);
                    }
                    else if (cstarted)
                    {
                        //a function
                        p1 = ScriptEngine.Get_String(ref line);
                        Add_Function(p1, i, filein, Var_State.PROTECTED);
                    }
                    break;

                case ScriptCommands.STATIC:
                    if (cstarted && vstarted)
                    {
                        //defining a variable
                        p1 = ScriptEngine.Get_String(ref line);
                        p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                        p3 = ScriptEngine.Get_String(ref line);

                        ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.STATIC);

                        _Variables.Add(nv);
                    }
                    else if (cstarted)
                    {
                        //a function
                        p1 = ScriptEngine.Get_String(ref line);
                        Add_Function(p1, i, filein, Var_State.STATIC);
                    }
                    break;

                case ScriptCommands.CLASS:
                    cstarted = true;
                    Name     = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                    p1       = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                    if (p1 != "NULL" && p1.Length != 0)
                    {
                        //gotta find this class... and copy over it's stuff
                        if (ScriptEngine.Classes.ContainsKey(p1))
                        {
                            Script_Class sc = (Script_Class)ScriptEngine.Classes[p1];

                            foreach (ScriptVariable nv in sc._Variables)
                            {
                                _Variables.Add(nv.Clone());
                            }

                            ParentName = sc.Name;
                            ParentFile = sc.File;
                        }
                        else
                        {
                            ScriptEngine.Script_Error("CLASS [" + p1 + "] NOT LOADED PRIOR TO USAGE");
                        }
                    }
                    break;

                case ScriptCommands.END_CLASS:
                    cended   = true;
                    cstarted = false;
                    break;

                case ScriptCommands.VAR_START:
                    vstarted = true;
                    break;

                case ScriptCommands.VAR_END:
                    vstarted = false;
                    break;
                }

                if (cended)
                {
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public void ReadFile(ScriptFile filein)
        {
            File = filein.Name;

            //gotta find the varbeing and varend and read in the middle
            bool cstarted = false;
            bool vstarted = false;
            bool cended = false;

            string p1, p2, p3;

            for(int i = 0; i < filein._ScriptLines.Count; i++)
            {
                ScriptLine cmd = (ScriptLine)filein._ScriptLines[i];

                string line = cmd.UnParsedParams;

                switch(cmd.Command)
                {
                    case ScriptCommands.INCLUDE:
                        if (!cstarted)
                        {
                            Globals.scriptthread.Script_INCLUDE(line);
                        }
                        break;
                    case ScriptCommands.PUBLIC:
                        if (cstarted && vstarted)
                        {
                            //defining a variable
                            p1 = ScriptEngine.Get_String(ref line);
                            p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                            p3 = ScriptEngine.Get_String(ref line);

                            ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.PUBLIC);

                            _Variables.Add(nv);
                        }
                        else if(cstarted)
                        {
                            //a function
                            p1 = ScriptEngine.Get_String(ref line);
                            Add_Function(p1, i, filein, Var_State.PUBLIC);
                        }
                        break;
                    case ScriptCommands.PRIVATE:
                        if (cstarted && vstarted)
                        {
                            //defining a variable
                            p1 = ScriptEngine.Get_String(ref line);
                            p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                            p3 = ScriptEngine.Get_String(ref line);

                            ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.PRIVATE);

                            _Variables.Add(nv);
                        }
                        else if (cstarted)
                        {
                            //a function
                            p1 = ScriptEngine.Get_String(ref line);
                            Add_Function(p1, i, filein, Var_State.PRIVATE);
                        }
                        break;
                    case ScriptCommands.PROTECTED:
                        if (cstarted && vstarted)
                        {
                            //defining a variable
                            p1 = ScriptEngine.Get_String(ref line);
                            p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                            p3 = ScriptEngine.Get_String(ref line);

                            ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.PROTECTED);

                            _Variables.Add(nv);
                        }
                        else if (cstarted)
                        {
                            //a function
                            p1 = ScriptEngine.Get_String(ref line);
                            Add_Function(p1, i, filein, Var_State.PROTECTED);
                        }
                        break;
                    case ScriptCommands.STATIC:
                        if (cstarted && vstarted)
                        {
                            //defining a variable
                            p1 = ScriptEngine.Get_String(ref line);
                            p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                            p3 = ScriptEngine.Get_String(ref line);

                            ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.STATIC);

                            _Variables.Add(nv);
                        }
                        else if (cstarted)
                        {
                            //a function
                            p1 = ScriptEngine.Get_String(ref line);
                            Add_Function(p1, i, filein, Var_State.STATIC);
                        }
                        break;
                    case ScriptCommands.CLASS:
                        cstarted = true;
                        Name = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                        p1 = ScriptEngine.Get_String(ref line).ToUpperInvariant();
                        if (p1 != "NULL" && p1.Length != 0)
                        {
                            //gotta find this class... and copy over it's stuff
                            if (ScriptEngine.Classes.ContainsKey(p1))
                            {
                                Script_Class sc = (Script_Class)ScriptEngine.Classes[p1];

                                foreach (ScriptVariable nv in sc._Variables)
                                {
                                    _Variables.Add(nv.Clone());
                                }

                                ParentName = sc.Name;
                                ParentFile = sc.File;
                            }
                            else
                            {
                                ScriptEngine.Script_Error("CLASS [" + p1 + "] NOT LOADED PRIOR TO USAGE");
                            }
                        }
                        break;
                    case ScriptCommands.END_CLASS:
                        cended = true;
                        cstarted = false;
                        break;
                    case ScriptCommands.VAR_START:
                        vstarted = true;
                        break;
                    case ScriptCommands.VAR_END:
                        vstarted = false;
                        break;
                }

                if (cended)
                {
                    break;
                }
            }
        }
Exemplo n.º 4
0
        private void Call_Event(ScriptEventCaller evn_call, ScriptEvent pop_event)
        {
            if (evn_call == null)
            {
                return;
            }
            //is the file loaded?
            if (!Files.ContainsKey(evn_call.File))
            {
                System.IO.StreamReader filein = new System.IO.StreamReader(evn_call.File);
                ScriptFile sf = new ScriptFile();
                sf.Name = evn_call.File;
                sf.ReadScript(filein);
                filein.Close();

                Files.Add(sf.Name, sf);
            }
            //find the function
            int dest_line = Get_Function_Line(evn_call.Function, evn_call.File);
            if (dest_line == -1)
            {
                ScriptEngine.Script_Error("EVENT CALLER: FUNCTION DOES NOT EXIST : " + evn_call.File + " : " + evn_call.Function);
                Globals.gamedata.CurrentScriptState = ScriptState.Error;
                return;
            }

            //create a new thread at the function...
            ScriptThread scr_thread = new ScriptThread();
            scr_thread.Current_File = evn_call.File;
            scr_thread.Line_Pos = dest_line + 1;

            VariableList stack_bottom = new VariableList();
            //copy the variables over
            foreach (ScriptVariable svar in pop_event.Variables)
            {
                stack_bottom.Add_Variable(svar);
            }
            scr_thread._stack.Add(stack_bottom);
            scr_thread.ID = GetUniqueThreadID();
            Threads.Add(scr_thread.ID, scr_thread);
        }
Exemplo n.º 5
0
		private void RunScript()
		{
#if !DEBUG
			try
			{
#endif
            	ScriptLine line;
            	//int while_count = 0;

                if (System.String.Equals(Globals.Script_MainFile, ""))
            	{
                    Globals.gamedata.CurrentScriptState = ScriptState.Stopped;
                    ScriptEngine.Script_Error("Script Thread entry point not set... did you forget to load first?");
                    Globals.l2net_home.SetStartScript();
	                return;
            	}
                
                //clean up pathfinding stuff
                ScriptEngine.is_Moving = false;
                ScriptEngine.Moving_List.Clear();
                
	            System.IO.StreamReader filein = new System.IO.StreamReader(Globals.Script_MainFile);
				ScriptFile sf = new ScriptFile();
				sf.Name = Globals.Script_MainFile;
				sf.ReadScript(filein);
				filein.Close();

                Files.Add(sf.Name, sf);

	            ScriptThread scr_thread = new ScriptThread();
	            scr_thread.Current_File = Globals.Script_MainFile;
	            scr_thread.Line_Pos = 0;

	            VariableList stack_bottom = new VariableList();
	            scr_thread._stack.Add(stack_bottom);

                scr_thread.ID = GetUniqueThreadID();
                Threads.Add(scr_thread.ID, scr_thread);

	            ScriptEvent pop_event;
	            ScriptEventCaller evn_call;

                bool all_sleeping;
                bool time_passed;

                while (true)//Globals.gamedata.running)
                {
                    all_sleeping = true;

                    //need to check the state of the script thread
                    if (IsRunning())//if running
                    {
#if !TESTING
                        try
                        {
#endif
                            foreach (ScriptThread cthread in Threads.Values)
                            {
                                CurrentThread = cthread.ID;

                                System.DateTime finish = System.DateTime.Now.AddTicks(Globals.Script_Ticks_Per_Switch);
                                time_passed = false;
                                BumpThread = false;

                                while (IsRunning() && (cthread.Sleep_Until < System.DateTime.Now) && !time_passed)
                                {
                                    line = Get_Line(Line_Pos);

                                    if (Proccess_Line(line, true))
                                    {
                                        all_sleeping = false;
                                    }

                                    time_passed = (System.DateTime.Now > finish || BumpThread);
                                }
                            }
#if !TESTING
                        }
                        catch
                        {
                            //set was modified... no biggie
                        }
#endif

                        try
                        {
                            //lets pop off all our events
                            lock (eventqueueLock)
                            {
                                while (EventQueueCount() > 0)
                                {
                                    all_sleeping = false;
                                    pop_event = EventQueueDequeue();

                                    //time to handle the event... fun fun fun

                                    switch (pop_event.Type)
                                    {
                                        case EventType.ServerPacket:
                                            if (ServerPacketsContainsKey((int)pop_event.Type2))
                                            {
                                                //the event exists...
                                                evn_call = ServerPacketsGetCaller((int)pop_event.Type2);

                                                Call_Event(evn_call, pop_event);
                                            }
                                            break;
                                        case EventType.ServerPacketEX:
                                            if (ServerPacketsEXContainsKey((int)pop_event.Type2))
                                            {
                                                //the event exists...
                                                evn_call = ServerPacketsEXGetCaller((int)pop_event.Type2);

                                                Call_Event(evn_call, pop_event);
                                            }
                                            break;
                                        case EventType.ClientPacket:
                                            if (ClientPacketsContainsKey((int)pop_event.Type2))
                                            {
                                                //the event exists...
                                                evn_call = ClientPacketsGetCaller((int)pop_event.Type2);

                                                Call_Event(evn_call, pop_event);
                                            }
                                            break;
                                        case EventType.ClientPacketEX:
                                            if (ClientPacketsEXContainsKey((int)pop_event.Type2))
                                            {
                                                //the event exists...
                                                evn_call = ClientPacketsEXGetCaller((int)pop_event.Type2);

                                                Call_Event(evn_call, pop_event);
                                            }
                                            break;
                                        case EventType.SelfPacket:
                                            if (SelfPacketsContainsKey((int)pop_event.Type2))
                                            {
                                                //the event exists...
                                                evn_call = SelfPacketsGetCaller((int)pop_event.Type2);

                                                Call_Event(evn_call, pop_event);
                                            }
                                            break;
                                        case EventType.SelfPacketEX:
                                            if (SelfPacketsEXContainsKey((int)pop_event.Type2))
                                            {
                                                //the event exists...
                                                evn_call = SelfPacketsEXGetCaller((int)pop_event.Type2);

                                                Call_Event(evn_call, pop_event);
                                            }
                                            break;
                                        default:
                                            //need to check if the event exists in our list
                                            if (EventsContainsKey((int)pop_event.Type))
                                            {
                                                //the event exists...
                                                evn_call = EventsGetCaller((int)pop_event.Type);
                                                Call_Event(evn_call, pop_event);
                                            }
                                            break;
                                    }
                                }//end of while dequeque
                            }
                        }
                        catch//(Exception e)
                        {
                            ScriptEngine.Script_Error("Event Error... possible wrong file or function name?");
                        }
                    }//end of if

                    switch (Globals.gamedata.CurrentScriptState)
                    {
                        case ScriptState.Stopped:
                        case ScriptState.Running:
                            break;
                        case ScriptState.Paused:
                            System.Threading.Thread.Sleep(Globals.SLEEP_WhileScript);
                            break;
                        case ScriptState.DelayStart:
                            System.Threading.Thread.Sleep(Globals.SLEEP_Script_Reset);
                            Globals.gamedata.CurrentScriptState = ScriptState.Running;
                            break;
                        default:
                            return;
                    }

                    if (all_sleeping)
                    {
                        System.Threading.Thread.Sleep(Globals.SLEEP_WhileScript);
                    }
                }//end of while true
#if !DEBUG
			}
			catch (Exception e)
			{
                string broke_file = "";
                try
                {
                    broke_file = ((ScriptThread)Threads[CurrentThread]).Current_File;
                }
                catch
                {
                    broke_file = "no file loaded";
                }
                ScriptEngine.Script_Error("Script Thread Crashed File: " + broke_file);
                ScriptEngine.Script_Error(e.Message + " : " + e.InnerException);
			}
#endif
        }
Exemplo n.º 6
0
        private void Script_CALL_EXTERN(string line)
        {
            string s_file = Get_String(ref line);
            string s_name = Get_String(ref line);
            string s_var = Get_String(ref line);
            string s_values = line;

            //check if the file has been loaded yet...
            //if not... load the file into memory
            s_file = Globals.PATH + "\\Scripts\\" + s_file;

            if (!Files.ContainsKey(s_file))
            {
                System.IO.StreamReader filein = new System.IO.StreamReader(s_file);
                ScriptFile sf = new ScriptFile();
                sf.Name = s_file;
                sf.ReadScript(filein);
                filein.Close();

                Files.Add(sf.Name, sf);
            }

            Function_Call(s_file, s_name, s_var, s_values);
        }
Exemplo n.º 7
0
        public void Script_INCLUDE(string line)
        {
            string s_file = Get_String(ref line);
            s_file = Globals.PATH + "\\Scripts\\" + s_file;

            s_file = s_file.ToUpperInvariant().Replace('/','\\');

            try
            {
                Script_Class sc = new Script_Class();

                if (!Files.ContainsKey(s_file))
                {
                    System.IO.StreamReader filein = new System.IO.StreamReader(s_file);
                    ScriptFile sf = new ScriptFile();
                    sf.Name = s_file;
                    sf.ReadScript(filein);
                    filein.Close();

                    Files.Add(sf.Name, sf);

                    sc.ReadFile(sf);

                    if (!Classes.ContainsKey(sc.Name))
                    {
                        Classes.Add(sc.Name, sc);
                    }
                    else
                    {
                        //we already have a class of this name... from a different file
                        ScriptEngine.Script_Error("FAILED TO INCLUDE FILE : " + s_file + " : A class of this name [" + sc.Name + "] from a different file has already been loaded");
                        Globals.gamedata.CurrentScriptState = ScriptState.Error;
                    }
                }
                /*else
                {
                    //we already have this file loaded... why would we want to reload it?
                    //what was I thinking here?  maybe they would have a class in a non class file?  f**k that...
                    //sc.ReadFile((ScriptFile)Files[s_file]);
                }*/
            }
            catch
            {
                ScriptEngine.Script_Error("FAILED TO INCLUDE FILE : " + s_file);
                Globals.gamedata.CurrentScriptState = ScriptState.Error;
            }
        }