Esempio n. 1
0
        public static int Open(ref lua_State state)
        {
            ClientConsole.RerouteConsole();
            ClientConsole.Color = new Color(0, 150, 255);
            Lua = GLua.Get(state);

            Lua.CreateTable();

            Lua.Push <Action <string> >(Dump);
            Lua.SetField(-2, "Dump");

            Lua.SetField(GLua.LUA_GLOBALSINDEX, "csluaview");

            var container = NativeInterface.Load <INetworkStringTableContainer>("engine", StringTableInterfaceName.CLIENT);
            var tablePtr  = container.FindTable("client_lua_files");
            var table     = JIT.ConvertInstance <INetworkStringTable>(tablePtr);

            Console.WriteLine($"dotnet table ptr: {tablePtr.ToString("X8")}");
            //var path0 = table.GetString(0); //hangs here

            //for (int i = 0; i < table.GetNumStrings(); i++)
            //{
            //}

            //var stringTable = StringTable.FindTable<int>("client_lua_files");
            //var luaFiles = stringTable.Select(s => new LuaFile { Path = s.String, CRC = s.UserData }).ToList();

            Console.WriteLine("DotNet Clientside Lua Viewer Loaded!");
            return(0);
        }
Esempio n. 2
0
        public static int Open(ref lua_State state)
        {
            GLua = GLua.Get(state);

            GLua.CreateTable();

            GLua.Push("woop was here");
            GLua.SetField(-2, "var");

            GLua.Push <Func <string, int, string> >(DoAThing);
            GLua.SetField(-2, "wrapped");

            GLua.SetField(GLua.LUA_GLOBALSINDEX, "dotnet");

            Console.WriteLine("DotNet loaded");
            return(0);
        }
Esempio n. 3
0
        public static int Open(ref lua_State state)
        {
            GLua = GLua.Get(state);

            GLua.CreateTable();

            GLua.Push(new Func <string, object>((string str) => {
                GLua.Push <string>("hello there");
                GLua.Call(1, 2);
                Console.WriteLine(GLua.Get <string>(5));
                GLua.Pop();
                GLua.Push <string>("hello there");
                GLua.Call(1, 2);
                Console.WriteLine(GLua.Get <string>(5));
                return(0);
            }));
            GLua.SetField(-2, "test");

            GLua.Push(new Func <string, string, int, object>((string path, string name, int boundObjectAmout) => {
                int res = instances.Count;
                try {
                    instances.Add(NodeInstance.InstantiateSync(path, name, boundObjectAmout));
                    return(res);
                }
                catch (Exception e) {
                    return(e.ToString());
                }
            }));
            GLua.SetField(-2, "instantiateSync");

            GLua.Push(new Func <string, string, int, object>((string path, string name, int boundObjectAmout) => {
                int res = instances.Count;
                NodeInstance.InstantiateAsync(path, name, boundObjectAmout).ContinueWith(taskResult => {
                    if (taskResult.IsFaulted)
                    {
                        newInstancesExceptionsAsync.Add(res, string.Join(",", taskResult.Exception.InnerExceptions.Select(x => x.ToString()).ToArray()));
                    }
                    else
                    {
                        newInstancesAsync.Add(res, taskResult.Result);
                    }
                });
                return(res);
            }));
            GLua.SetField(-2, "instantiateAsync");

            GLua.Push(new Func <int, bool>((int ptr) => {
                if (newInstancesAsync.ContainsKey(ptr))
                {
                    newInstancesAsync.Remove(ptr);
                    return(true);
                }
                return(false);
            }));
            GLua.SetField(-2, "checkForNewAsyncInstances");

            GLua.Push(new Func <int, object>((int ptr) => {
                if (newInstancesExceptionsAsync.ContainsKey(ptr))
                {
                    string str = newInstancesExceptionsAsync[ptr];
                    newInstancesExceptionsAsync.Remove(ptr);
                    return(str);
                }
                return(false);
            }));
            GLua.SetField(-2, "checkForNewAsyncInstancesExceptions");

            GLua.Push(new Func <int, string>((int instance) => {
                return(JsonConvert.SerializeObject(instances[instance].Methods));
            }));
            GLua.SetField(-2, "getInstanceMethods");

            GLua.Push(new Func <int, string, string, string>((int instance, string funcName, string args) => {
                Func <object> getHandler = new Func <object>(() => {
                    GLua.Push <string>("hello there");
                    GLua.Call(1, 2);
                    Console.WriteLine(GLua.Get <string>(5));
                    GLua.Pop();
                    return(0);
                });
                try {
                    object result = instances[instance].Call(funcName, JsonConvert.DeserializeObject <object[]>(args));
                    if (result == null)
                    {
                        return(null);
                    }

                    return(JsonConvert.SerializeObject(result));
                }
                catch (Exception e) {
                    Console.WriteLine(e);
                    return("Error: " + e.Message);
                }
            }));
            GLua.SetField(-2, "callInstanceMethod");

            GLua.Push(new Func <int, object>((int instance) => {
                instances[instance] = null;
                return(null);
            }));
            GLua.SetField(-2, "removeInstance");

            GLua.Push(new Func <int, object>((int instance) => {
                instances[instance] = null;
                return(null);
            }));
            GLua.SetField(-2, "getInstanceObject");

            GLua.Push(new Func <int, object>((int instance) => {
                instances[instance] = null;
                return(null);
            }));
            GLua.SetField(-2, "removeInstance");

            GLua.Push(new Func <double>(() => {
                return(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds);
            }));
            GLua.SetField(-2, "getUnixTime");

            GLua.SetField(GLua.LUA_GLOBALSINDEX, WRAPPER_OBJECT_NAME);
            return(0);
        }