예제 #1
0
        void IModule.Unload(ILua lua)
        {
            surface        = null;
            materialSystem = null;

            if (sourcesdkc != IntPtr.Zero)
            {
                NativeLibrary.Free(sourcesdkc);
            }
        }
예제 #2
0
        void IModule.Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context)
        {
            if (is_serverside)
            {
                throw new Exception("Must be loaded from client");
            }

            string platformIdentifier = OperatingSystem.IsWindows() ? "win-x64" : "linux-x64";

            assembly_context.SetCustomNativeLibraryResolver((ctx, str) =>
            {
                if (str.Contains("sourcesdkc"))
                {
                    if (sourcesdkc == IntPtr.Zero)
                    {
                        Console.WriteLine("loading sourcesdkc");
                        sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/GetRenderTargetExample/runtimes/{platformIdentifier}/native/sourcesdkc");
                        Console.WriteLine($"loaded sourcesdkc: {sourcesdkc != IntPtr.Zero}");
                    }
                    return(sourcesdkc);
                }
                return(IntPtr.Zero);
            });

            if (interfaceh.Sys_LoadInterface("vguimatsurface", ISurface.VGUI_SURFACE_INTERFACE_VERSION, out _, out IntPtr isurfacePtr))
            {
                surface = new(isurfacePtr);
            }
            else
            {
                throw new Exception("failed loading vguimatsurface");
            }

            if (interfaceh.Sys_LoadInterface("materialsystem", IMaterialSystem.MATERIAL_SYSTEM_INTERFACE_VERSION, out _, out IntPtr materialSystemPtr))
            {
                materialSystem = new(materialSystemPtr);
            }
            else
            {
                Console.WriteLine("failed loading materialsystem");
            }

            lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
            lua.GetField(-1, "GetRenderTarget");
            lua.PushString("ExampleRTwithAlpha");
            lua.PushNumber(512);
            lua.PushNumber(512);
            lua.MCall(3, 1);
            rt = lua.GetUserType(-1, (int)TYPES.TEXTURE);
            lua.Pop();

            lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
            lua.GetField(-1, "CreateMaterial");
            lua.PushString("ExampleRTwithAlpha_Mat");
            lua.PushString("UnlitGeneric");
            lua.CreateTable();
            {
                lua.PushString("$basetexture");
                lua.PushString("ExampleRTwithAlpha");
                lua.SetTable(-3);

                lua.PushString("$translucent");
                lua.PushString("1");
                lua.SetTable(-3);
            }
            lua.MCall(3, 1);
            mat = lua.GetUserType(-1, (int)TYPES.MATERIAL);
            lua.Pop();

            lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
            lua.GetField(-1, "hook");
            lua.GetField(-1, "Add");
            lua.PushString("HUDPaint");
            lua.PushString("ExampleRTwithAlpha_Render");
            lua.PushManagedFunction(Render);
            lua.MCall(3, 0);
            lua.Pop();
        }