--------------------------------------------------------------------------------
/lua_reference/luajs.md:
--------------------------------------------------------------------------------
1 | # luajs
2 |
3 | ### luajs.Register(tab, name)
4 |
5 | Registers a new luajs class.
6 |
7 | Arguments:
8 |
9 | - table tab: The class table.
10 | - string name: The class name.
11 |
12 | IMPORTANT: It is highly recommended to refrain from using this function to create luajs classes unless there is a specific reason for doing so.
13 |
14 | ### luajs.Create(class)
15 |
16 | Creates a new luajs object of the specified class name.
17 |
18 | Arguments:
19 |
20 | - string class: The class name of the new object.
21 |
22 | ### luajs.GetClasses()
23 |
24 | Returns the original table of all luajs classes.
25 |
26 | Returns:
27 |
28 | - table tab: The table of classes.
29 |
30 | ### luajs.GetClassTable(class)
31 |
32 | Returns the original table for the specified luajs class name.
33 |
34 | Arguments:
35 |
36 | - string class: The class name.
37 |
38 | Returns:
39 |
40 | - table tab: The table of the found class. Is nil if the class does not exist.
41 |
42 | ### luajs.GetClassTableCopy(class)
43 |
44 | Returns a copy of the table for the specified luajs class name.
45 |
46 | Arguments:
47 |
48 | - string class: The class name.
49 |
50 | Returns:
51 |
52 | - table tab: The table of the found class. Is nil if the class does not exist.
53 |
54 | ### luajs.GetByIndex(index)
55 |
56 | Returns the luajs object with the specified index.
57 |
58 | Arguments:
59 |
60 | - number index: The object's index.
61 |
62 | Returns:
63 |
64 | - luajs object: The object with the specified index. Returns an invalid object if no such index is occupied.
65 |
66 | ### luajs.GetAll()
67 |
68 | Returns a table of all created luajs objects.
69 |
70 | Returns:
71 |
72 | table tab: The table of objects.
73 |
74 | ### luajs.GetCount(includeRemoved)
75 |
76 | Returns the number of created luajs objects.
77 |
78 | Arguments:
79 |
80 | - boolean includeRemoved: If true, will include the luajs objects that are just about to be removed in the resulting number.
81 |
82 | Returns:
83 |
84 | - number count: The number of objects.
85 |
86 | ### luajs.FindByClass(class)
87 |
88 | Returns a table of luajs objects with the specified class. Wildcards (`*`) are supported.
89 |
90 | Arguments:
91 |
92 | - string class: The class name to search for.
93 |
94 | Returns:
95 |
96 | - table tab: The found objects.
97 |
--------------------------------------------------------------------------------
/tutorials/panel_customization.md:
--------------------------------------------------------------------------------
1 | Follow the tutorial below (from [this](http://wiki.garrysmod.com/page/Panel_Customization "Garry's Mod Wiki") Garry's Mod Wiki page), but instead of placing the source code in the usual folder ("lua/vgui"), place it in the folder "lua/vgui_menu".
2 |
3 | # Panel Customization
4 |
5 | Sometimes you may wish to create a custom VGUI Panel for an addon or gamemode.
6 | ## Create a Table
7 |
8 | The first step in creating a custom VGUI Panel is to create a table.
9 | ```
10 | local PANEL = {}
11 | ```
12 | ## Then Add Functions
13 |
14 | We can give our table a function so Garry's Mod knows what to do to it when it's initialized.
15 | ```
16 | function PANEL:Init()
17 | self:SetSize( 100, 100 )
18 | self:Center()
19 | end
20 | ```
21 | We use `self:SetSize( 100, 100 )` to set the size of our panel to 100 pixels wide and 100 pixels tall. `self:Center()` centers our panel in the middle of our parent (if no parent is given it will center the panel in the middle of the screen).
22 |
23 | We can also give our table a function to tell Garry's Mod what we should do when we want to paint the panel on the screen.
24 | ```
25 | function PANEL:Paint( w, h )
26 | draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 255 ) )
27 | end
28 | ```
29 | In this function we call `draw.RoundedBox(..)` to draw our panel with the dimensions defined in `self:SetSize()`. We start at 0,0 because this is the top-most-left-most point in our panel.
30 | Finally We Register
31 |
32 | The final step in creating a custom VGUI Panel is to register the table.
33 |
34 | vgui.Register( "MyFirstPanel", PANEL, "Panel" )
35 |
36 | Where; _"MyFirstPanel"_ is the desired name of your panel to be used when you wish to create it. _PANEL_ is the table we have created and _"Panel"_ is the type of element you wish to use as a base.
37 | ## Result
38 |
39 | You can now create your custom panel by using
40 | ```
41 | local pnl = vgui.Create( "MyFirstPanel", parentpanel )
42 | ```
43 | or
44 | ```
45 | local pnl = parentpanel:Add( "MyFirstPanel" )
46 | ```
47 | ## Complete Code
48 | ```
49 | local PANEL = {}
50 |
51 | function PANEL:Init()
52 | self:SetSize( 100, 100 )
53 | self:Center()
54 | end
55 |
56 | function PANEL:Paint( w, h )
57 | draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 255 ) )
58 | end
59 |
60 | vgui.Register( "MyFirstPanel", PANEL, "Panel" )
61 | ```
62 |
--------------------------------------------------------------------------------
/lua_reference/luahtml.md:
--------------------------------------------------------------------------------
1 | # luahtml
2 |
3 | ### luahtml.Register(tab, name)
4 |
5 | Registers a new luahtml class.
6 |
7 | Arguments:
8 |
9 | - table tab: The class table.
10 | - string name: The class name.
11 |
12 | IMPORTANT: It is highly recommended to refrain from using this function to create luahtml classes unless there is a specific reason for doing so.
13 |
14 | ### luahtml.Create(class)
15 |
16 | Creates a new luahtml object of the specified class name.
17 |
18 | Arguments:
19 |
20 | - string class: The class name of the new object.
21 |
22 | ### luahtml.GetClasses()
23 |
24 | Returns the original table of all luahtml classes.
25 |
26 | Returns:
27 |
28 | - table tab: The table of classes.
29 |
30 | ### luahtml.GetClassTable(class)
31 |
32 | Returns the original table for the specified luahtml class name.
33 |
34 | Arguments:
35 |
36 | - string class: The class name.
37 |
38 | Returns:
39 |
40 | - table tab: The table of the found class. Is nil if the class does not exist.
41 |
42 | ### luahtml.GetClassTableCopy(class)
43 |
44 | Returns a copy of the table for the specified luahtml class name.
45 |
46 | Arguments:
47 |
48 | - string class: The class name.
49 |
50 | Returns:
51 |
52 | - table tab: The table of the found class. Is nil if the class does not exist.
53 |
54 | ### luahtml.GetByIndex(index)
55 |
56 | Returns the luahtml object with the specified index.
57 |
58 | Arguments:
59 |
60 | - number index: The object's index.
61 |
62 | Returns:
63 |
64 | - luahtml object: The object with the specified index. Returns an invalid object if no such index is occupied.
65 |
66 | ### luahtml.GetAll()
67 |
68 | Returns a table of all created luahtml objects.
69 |
70 | Returns:
71 |
72 | table tab: The table of objects.
73 |
74 | ### luahtml.GetCount(includeRemoved)
75 |
76 | Returns the number of created luahtml objects.
77 |
78 | Arguments:
79 |
80 | - boolean includeRemoved: If true, will include the luahtml objects that are just about to be removed in the resulting number.
81 |
82 | Returns:
83 |
84 | - number count: The number of objects.
85 |
86 | ### luahtml.FindByClass(class)
87 |
88 | Returns a table of luahtml objects with the specified class. Wildcards (`*`) are supported.
89 |
90 | Arguments:
91 |
92 | - string class: The class name to search for.
93 |
94 | Returns:
95 |
96 | - table tab: The found objects.
97 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # About
4 |
5 | Menu Mods is a framework for Garry's Mod that allows the user to modify the main and pause menus. The user can add Lua code that is executed in the menu state of the game, and even add options to the menu.
6 |
7 | # Getting Started
8 |
9 | ## Steam Workshop Installation
10 |
11 | First, download the "Menu Mods" addon from the Garry's Mod workshop (found [here](https://steamcommunity.com/sharedfiles/filedetails/?id=1432846093 "Garry's Mod Workshop")). Then, download this repository and place the folder named "menu_mods_ws" inside the "addons" folder in your "garrysmod" directory (usually "C:/Program Files (x86)/Steam/steamapps/common/GarrysMod/garrysmod").
12 |
13 | ## Legacy Installation
14 |
15 | Download this repository and place the folder named "menu_mods" inside the "addons" folder in your "garrysmod" directory (usually "C:/Program Files (x86)/Steam/steamapps/common/GarrysMod/garrysmod").
16 |
17 | ## ConVars
18 |
19 | Name | Default | Description
20 | ---- | ------- | -----------
21 | menumods_enabled | 1 | Enables the mounting of Lua files in the menu state. Will disable the files only after restarting Garry's Mod.
22 | menumods_debugMode | 0 | Enables printing extra debug info to the console.
23 | menumods_enableLuaErrorLogging | 0 | Enables saving logs of Lua errors into the folder "data/menu_mods/logs".
24 | menumods_enableJavaScriptLogging | 0 | Enables saving logs of JavaScript code being executed into the folder "data/menu_mods/logs".
25 | menumods_net_enabled | 1 | Enables the Menu Mods net library which sends data between the menu and client states.
26 | menumods_net_tickRate | 30 | Sets the number of times per second at which net messages are sent between the menu and client states. Set to 0 for one tick every frame.
27 |
28 | ## Tutorials
29 |
30 | - [Your First Menu Option](/tutorials/your_first_menu_option.md "Your First Menu Option")
31 | - [Creating Lua-Based HTML Documents](/tutorials/creating_lua-based_html_documents.md "Creating Lua-Based HTML Documents")
32 | - [Creating Lua-Based JavaScript Documents](/tutorials/creating_lua-based_javascript_documents.md "Creating Lua-Based JavaScript Documents")
33 | - [Panel Customization](/tutorials/panel_customization.md "Panel Customization")
34 |
35 | ## References
36 |
37 | - [Lua Reference](/lua_reference/ROOT.md "Lua Reference")
38 |
--------------------------------------------------------------------------------
/menu_mods/html/js/menu/menumods.js:
--------------------------------------------------------------------------------
1 |
2 | var menumods =
3 | {
4 | string: {
5 | escChars: [["\b", "b"], ["\f", "f"], ["\n", "n"], ["\r", "r"], ["\t", "t"], ["\v", "v"], ["\"", "\""], ["\'", "\'"]],
6 | regExpChars: [[/\-/g, "\\-"], [/\[/g, "\\["], [/\]/g, "\\]"], [/\//g, "\\/"], [/\{/g, "\\{"], [/\}/g, "\\}"], [/\(/g, "\\("], [/\)/g, "\\)"], [/\*/g, "\\*"], [/\+/g, "\\+"], [/\?/g, "\\?"], [/\./g, "\\."], [/\^/g, "\\^"], [/\$/g, "\\$"], [/\|/g, "\\|"]],
7 | patternSafe: function(str)
8 | {
9 | var newString = ("" + str);
10 |
11 | newString = newString.replace(/\\/g, "\\\\");
12 |
13 | var k;
14 | var regExpChars = menumods.string.regExpChars;
15 |
16 | for (k in regExpChars) {
17 | newString = newString.replace(regExpChars[k][0], regExpChars[k][1]);
18 | }
19 |
20 | return newString;
21 | },
22 | levelPush: function(str, numLevels, noOuterQuotes)
23 | {
24 | var numLevels_new = numLevels;
25 |
26 | if (numLevels_new == undefined) {
27 | numLevels_new = 1;
28 | }
29 |
30 | var newString = ("" + str);
31 | var i;
32 |
33 | for (i = 0; i < numLevels_new; i++) {
34 | newString = newString.replace(/\\/g, "\\\\");
35 |
36 | var k;
37 | var escChars = menumods.string.escChars;
38 |
39 | for (k in escChars) {
40 | var pattern1 = new RegExp(menumods.string.patternSafe(escChars[k][0]), "g");
41 | var pattern2 = "\\" + menumods.string.patternSafe(escChars[k][1]);
42 |
43 | newString = newString.replace(pattern1, pattern2);
44 | }
45 |
46 | if (!noOuterQuotes) {
47 | newString = ("\"" + newString + "\"");
48 | }
49 | }
50 |
51 | return newString;
52 | },
53 | levelPop: function(str, numLevels)
54 | {
55 | var numLevels_new = numLevels;
56 |
57 | if (numLevels_new == undefined) {
58 | numLevels_new = 1;
59 | }
60 |
61 | var newString = ("" + str);
62 | var i;
63 |
64 | for (i = 0; i < numLevels_new; i++) {
65 | var k;
66 | var escChars = menumods.string.escChars;
67 |
68 | for (k in escChars) {
69 | var currStr1 = menumods.string.patternSafe(escChars[k][0]);
70 | var currStr2 = menumods.string.patternSafe(escChars[k][1]);
71 |
72 | var pattern1 = new RegExp(currStr1, "g");
73 | var pattern2 = new RegExp(("^\\\\" + currStr2), "g");
74 | var pattern3 = new RegExp(("([^\\\\])\\\\" + currStr2), "g");
75 |
76 | newString = newString.replace(pattern1, "");
77 | newString = newString.replace(pattern2, currStr1)
78 | newString = newString.replace(pattern3, ("$1" + currStr1));
79 | }
80 |
81 | newString = newString.replace(/\\\\/g, "\\");
82 | }
83 |
84 | return newString;
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/menu_mods_ws/html/js/menu/menumods.js:
--------------------------------------------------------------------------------
1 |
2 | var menumods =
3 | {
4 | string: {
5 | escChars: [["\b", "b"], ["\f", "f"], ["\n", "n"], ["\r", "r"], ["\t", "t"], ["\v", "v"], ["\"", "\""], ["\'", "\'"]],
6 | regExpChars: [[/\-/g, "\\-"], [/\[/g, "\\["], [/\]/g, "\\]"], [/\//g, "\\/"], [/\{/g, "\\{"], [/\}/g, "\\}"], [/\(/g, "\\("], [/\)/g, "\\)"], [/\*/g, "\\*"], [/\+/g, "\\+"], [/\?/g, "\\?"], [/\./g, "\\."], [/\^/g, "\\^"], [/\$/g, "\\$"], [/\|/g, "\\|"]],
7 | patternSafe: function(str)
8 | {
9 | var newString = ("" + str);
10 |
11 | newString = newString.replace(/\\/g, "\\\\");
12 |
13 | var k;
14 | var regExpChars = menumods.string.regExpChars;
15 |
16 | for (k in regExpChars) {
17 | newString = newString.replace(regExpChars[k][0], regExpChars[k][1]);
18 | }
19 |
20 | return newString;
21 | },
22 | levelPush: function(str, numLevels, noOuterQuotes)
23 | {
24 | var numLevels_new = numLevels;
25 |
26 | if (numLevels_new == undefined) {
27 | numLevels_new = 1;
28 | }
29 |
30 | var newString = ("" + str);
31 | var i;
32 |
33 | for (i = 0; i < numLevels_new; i++) {
34 | newString = newString.replace(/\\/g, "\\\\");
35 |
36 | var k;
37 | var escChars = menumods.string.escChars;
38 |
39 | for (k in escChars) {
40 | var pattern1 = new RegExp(menumods.string.patternSafe(escChars[k][0]), "g");
41 | var pattern2 = "\\" + menumods.string.patternSafe(escChars[k][1]);
42 |
43 | newString = newString.replace(pattern1, pattern2);
44 | }
45 |
46 | if (!noOuterQuotes) {
47 | newString = ("\"" + newString + "\"");
48 | }
49 | }
50 |
51 | return newString;
52 | },
53 | levelPop: function(str, numLevels)
54 | {
55 | var numLevels_new = numLevels;
56 |
57 | if (numLevels_new == undefined) {
58 | numLevels_new = 1;
59 | }
60 |
61 | var newString = ("" + str);
62 | var i;
63 |
64 | for (i = 0; i < numLevels_new; i++) {
65 | var k;
66 | var escChars = menumods.string.escChars;
67 |
68 | for (k in escChars) {
69 | var currStr1 = menumods.string.patternSafe(escChars[k][0]);
70 | var currStr2 = menumods.string.patternSafe(escChars[k][1]);
71 |
72 | var pattern1 = new RegExp(currStr1, "g");
73 | var pattern2 = new RegExp(("^\\\\" + currStr2), "g");
74 | var pattern3 = new RegExp(("([^\\\\])\\\\" + currStr2), "g");
75 |
76 | newString = newString.replace(pattern1, "");
77 | newString = newString.replace(pattern2, currStr1)
78 | newString = newString.replace(pattern3, ("$1" + currStr1));
79 | }
80 |
81 | newString = newString.replace(/\\\\/g, "\\");
82 | }
83 |
84 | return newString;
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/lua_reference/hooks_reference.md:
--------------------------------------------------------------------------------
1 | # Menu Mods Hooks
2 |
3 | These are the event hooks that can be created with the function "menumods.hook.Add".
4 |
5 | ### ElementCreated(currURL, urls, tag, class, parentClass, parentNum, content, attributes)
6 |
7 | Called when an HTML element has been created.
8 |
9 | Arguments:
10 |
11 | - string currURL: The URL the element is being created on.
12 | - table urls: The table of URLs the element exists on.
13 | - string tag: The type of HTML tag.
14 | - string class: The class name.
15 | - string parentClass: The class name of the parent element.
16 | - number parentNum: The ranking of the search results for the parent.
17 | - string content: The inner HTML content of the element.
18 | - vararg attributes: The attributes of the element.
19 |
20 | ### ElementModified(currURL, urls, class, num, content, attributes)
21 |
22 | Called when an HTML element is modified.
23 |
24 | Arguments:
25 |
26 | - string currURL: The URL the element is being modified on.
27 | - table urls: The table of URLs the element exists on.
28 | - string class: The class name.
29 | - number num: The ranking of the search results for the element.
30 | - string content: The inner HTML content of the element.
31 | - vararg attributes: The attributes of the element.
32 |
33 | ### ElementRemoved(attributeName, attributeValue)
34 |
35 | Called when an HTML element is removed.
36 |
37 | Arguments:
38 |
39 | - string attributeName: The name of the attribute that was used to find the element.
40 | - any attributeValue: The value of the attribute that was used to find the element.
41 |
42 | ### PrePageChange(oldURL, newURL)
43 |
44 | Called just before the URL changes.
45 |
46 | Arguments:
47 |
48 | - string oldURL: The old URL.
49 | - string newURL: The new URL.
50 |
51 | ### PostPageChange(oldURL, newURL)
52 |
53 | Called just after the URL changes.
54 |
55 | Arguments:
56 |
57 | - string oldURL: The old URL.
58 | - string newURL: The new URL.
59 |
60 | ### PageThink()
61 |
62 | Called when the page thinks.
63 |
64 | NOTE: When in game, this hook will only be called when the pause menu is open.
65 |
66 | ### Think()
67 |
68 | Called when the main panel thinks.
69 |
70 | NOTE: When in game, this hook will only be called when the pause menu is open.
71 |
72 | IMPORTANT: When running JavaScript inside a thinking hook, use "PageThink" instead. Otherwise, the JavaScript code will be added to the queue faster than it is run, resulting in gradually increasing lag.
73 |
74 | ### Initialize()
75 |
76 | Called when the main panel initializes. This can happen more than once.
77 |
78 | ### OnLuaError(text, realm, name, id)
79 |
80 | Called when a Lua error occurs. Functionally equivalent to the regular "OnLuaError" gamemode hook. Additionally works with errors that occur in the menu state.
81 |
82 | Arguments:
83 |
84 | - string text: The error message.
85 | - number realm: The realm (state) in which the error occurred. Does not seem to work currently.
86 | - string name: The name of the addon that caused the error. Will be an empty string if the addon is a legacy addon (not a .gma file).
87 | - string id: The Steam ID of the addon. Will be nil if the addon is a legacy addon (not a .gma file).
88 |
--------------------------------------------------------------------------------
/tutorials/creating_lua-based_javascript_documents.md:
--------------------------------------------------------------------------------
1 | # Tutorial: Creating Lua-Based JavaScript Documents
2 |
3 | In this tutorial, we will be learning how to create Lua-Based JavaScript Documents that can be opened in any lua browser.
4 |
5 | ## Preparing your File
6 |
7 | Place a blank .lua file with a unique name into the "lua/jsdocs" directory of your addon. This will be the file containing the code for your JavaScript document.
8 |
9 | ## Setting the Base Class
10 |
11 | If you would not like to start from scratch, type `LUA_JS.Base = "BASE CLASS NAME HERE"` in your file to set the desired base class for your script.
12 |
13 | ## Creating the Content
14 |
15 | Type `LUA_JS.Content = [[JAVASCRIPT CONTENT HERE]]` to set the content of your script.
16 |
17 | ## Object Functions
18 |
19 | The following are functions that can be used to do certain things with the script.
20 |
21 | ### LUA_JS:IsValid()
22 |
23 | Checks to see if the object is valid.
24 |
25 | Returns:
26 |
27 | - bool isvalid: Whether or not the object is valid.
28 |
29 | ### LUA_JS:Index()
30 |
31 | Returns the unique index of the object.
32 |
33 | Returns:
34 |
35 | - number index: The unique index of the object.
36 |
37 | ### LUA_JS:Remove()
38 |
39 | Removes the object, making it no longer valid or useable.
40 |
41 | ### LUA_JS:GetClass()
42 |
43 | Returns the class name of the object.
44 |
45 | Returns:
46 |
47 | - string classname: The class name of the object.
48 |
49 | ### LUA_JS:GetContent()
50 |
51 | Returns the content of the object.
52 |
53 | Returns:
54 |
55 | - string content: The content of the object.
56 |
57 | ### LUA_JS:SetContent(content)
58 |
59 | Sets the content of the object.
60 |
61 | Arguments:
62 |
63 | - string content: The new content for the object.
64 |
65 | ### LUA_JS:RunInPanel(HTML)
66 |
67 | Runs the script in a DHTML panel.
68 |
69 | Arguments:
70 |
71 | - Panel HTML: The DHTML panel to run the script in.
72 |
73 | ### LUA_JS:RunNewInCurrentPanel(class, doNotRemove)
74 |
75 | Runs a new script in this script's current panel.
76 |
77 | Arguments:
78 |
79 | - string class: The class name of the new script.
80 | - boolean doNotRemove: Set to true to not remove this script when opening the other one.
81 |
82 | ### LUA_JS:GetCurrentPanel()
83 |
84 | Returns the current panel of the script.
85 |
86 | Returns:
87 |
88 | - panel currentpanel: The current panel the script was opened in.
89 |
90 | ## Optional Custom Object Functions
91 |
92 | The following are customizable functions that are called whenever certain events happen.
93 |
94 | ### LUA_JS:Initialize()
95 |
96 | Called when the script is first created.
97 |
98 | ### LUA_JS:OnRemove()
99 |
100 | Called when the script is removed with its `LUA_JS:Remove()` function.
101 |
102 | ### LUA_JS:OnRunInPanel(HTML)
103 |
104 | Called when the script is ran in a DHTML panel.
105 |
106 | Arguments:
107 |
108 | - panel HTML: The DHTML panel the script was run in.
109 |
110 | ## Finishing Up
111 |
112 | After writing your code, save the file, copy your addon into your addons directory, and test it. If there are any errors, they will show up in the console.
113 |
--------------------------------------------------------------------------------
/menu_mods/html/blank.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/menu_mods_ws/html/blank.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/tutorials/creating_lua-based_html_documents.md:
--------------------------------------------------------------------------------
1 | # Tutorial: Creating Lua-Based HTML Documents
2 |
3 | In this tutorial, we will be learning how to create Lua-Based HTML Documents that can be opened in any lua browser.
4 |
5 | ## Preparing your File
6 |
7 | Place a blank .lua file with a unique name into the "lua/htmldocs" directory of your addon. This will be the file containing the code for your HTML document.
8 |
9 | ## Setting the Base Class
10 |
11 | If you would not like to start from scratch, type `LUA_HTML.Base = "BASE CLASS NAME HERE"` in your file to set the desired base class for your document.
12 |
13 | ## Creating the Head and Body
14 |
15 | For the head of your document, type `LUA_HTML.Head = [[HTML HEAD HERE]]`.
16 | Next, type `LUA_HTML.Body = [[HTML BODY HERE]]` to set the body of your document.
17 |
18 | ## Object Functions
19 |
20 | The following are functions that can be used to do certain things with the document.
21 |
22 | ### LUA_HTML:IsValid()
23 |
24 | Checks to see if the object is valid.
25 |
26 | Returns:
27 |
28 | - bool isvalid: Whether or not the object is valid.
29 |
30 | ### LUA_HTML:Index()
31 |
32 | Returns the unique index of the object.
33 |
34 | Returns:
35 |
36 | - number index: The unique index of the object.
37 |
38 | ### LUA_HTML:Remove()
39 |
40 | Removes the object, making it no longer valid or useable.
41 |
42 | ### LUA_HTML:GetClass()
43 |
44 | Returns the class name of the object.
45 |
46 | Returns:
47 |
48 | - string classname: The class name of the object.
49 |
50 | ### LUA_HTML:GetHead()
51 |
52 | Returns the HTML head of the object.
53 |
54 | Returns:
55 |
56 | - string head: The HTML head of the object.
57 |
58 | ### LUA_HTML:SetHead(head)
59 |
60 | Sets the HTML head of the object.
61 |
62 | Arguments:
63 |
64 | - string head: The new HTML head for the object.
65 |
66 | ### LUA_HTML:GetBody()
67 |
68 | Returns the HTML body of the object.
69 |
70 | Returns:
71 |
72 | - string body: The HTML body of the object.
73 |
74 | ### LUA_HTML:SetBody(body)
75 |
76 | Sets the HTML body of the object.
77 |
78 | Arguments:
79 |
80 | - string body: The new HTML body for the object.
81 |
82 | ### LUA_HTML:OpenInPanel(HTML)
83 |
84 | Opens the document in a DHTML panel.
85 |
86 | Arguments:
87 |
88 | - Panel HTML: The DHTML panel to open the document in.
89 |
90 | ### LUA_HTML:OpenNewInCurrentPanel(class, doNotRemove)
91 |
92 | Opens a new document in this document's current panel.
93 |
94 | Arguments:
95 |
96 | - string class: The class name of the new document.
97 | - boolean doNotRemove: Set to true to not remove this document when opening the other one.
98 |
99 | ### LUA_HTML:RunScript(class, doNotRemove)
100 |
101 | Runs a Lua-based script in this document's current panel.
102 |
103 | Arguments:
104 |
105 | - string class: The class name of the new script.
106 | - boolean doNotRemove: Set to true to not remove the script just after running it.
107 |
108 | ### LUA_HTML:GetCurrentPanel()
109 |
110 | Returns the current panel of the document.
111 |
112 | Returns:
113 |
114 | - panel currentpanel: The current panel the document was opened in.
115 |
116 | ## Optional Custom Object Functions
117 |
118 | The following are customizable functions that are called whenever certain events happen.
119 |
120 | ### LUA_HTML:Initialize()
121 |
122 | Called when the document is first created.
123 |
124 | ### LUA_HTML:OnRemove()
125 |
126 | Called when the document is removed with its `LUA_HTML:Remove()` function.
127 |
128 | ### LUA_HTML:OnOpenInPanel(HTML)
129 |
130 | Called when the document is opened in a DHTML panel.
131 |
132 | Arguments:
133 |
134 | - panel HTML: The DHTML panel the document was opened in.
135 |
136 | ### LUA_HTML:OnRunScript(script)
137 |
138 | Called when a Lua-based script (written in JavaScript) is executed on the document.
139 |
140 | Arguments:
141 |
142 | - LuaJS script: The Lua-based script that was executed on the document.
143 |
144 | ## Finishing Up
145 |
146 | After writing your code, save the file, copy your addon into your addons directory, and test it. If there are any errors, they will show up in the console.
147 |
--------------------------------------------------------------------------------
/tutorials/your_first_menu_option.md:
--------------------------------------------------------------------------------
1 | # Tutorial: Your First Menu Option
2 |
3 | One of the main features this addon offers is the ability to run user-created Lua files in the main menu. In this tutorial, we will be
4 | learning how to add custom menu options to the main menu and pause menu.
5 |
6 | ## Preparing Your Autorun File
7 |
8 | Place a blank .lua file with a unique name into the "lua/autorun/menu" directory of your addon. This will be the file containing the code for your menu option.
9 |
10 | IMPORTANT: If you would like to include the contents of an outside file, use the "menumods.include" function in place of the regular "include" function. (The "include" function will crash the game, saying the file is not found.) The "menumods.include" function also does not support local file paths, so replace any local file paths with the full Lua file path. Example: If you are including the .lua file "lua/autorun/stuff/test.lua" from another file, type `menumods.include("autorun/stuff/test.lua")` in the desired location.
11 |
12 | ## Choosing a Location for Your Menu Option
13 |
14 | For adding an option to the Garry's Mod menu, Menu Mods offers almost every location on the screen.
15 | The class names of these locations can be seen in the diagram below.
16 |
17 | 
18 |
19 | Refer to this diagram for further instruction.
20 |
21 | ## Different Methods
22 |
23 | There are three main functions used to add HTML tags to different parts of the page, the last two of which are specific to `` tags.
24 |
25 | ### menumods.AddElement(identifier, data)
26 |
27 | This function can be used to add any HTML tag to the menu.
28 |
29 | Arguments:
30 |
31 | - any identifier: Used as a unique name for the element (like gamemode hooks).
32 | - table data: The data table for the element.
33 |
34 | ### menumods.AddOption(identifier, data, onClick)
35 |
36 | This function is used to add options to the menu that execute code when clicked.
37 |
38 | Arguments:
39 |
40 | - any identifier: Used as a unique name for the element (like gamemode hooks).
41 | - table data: The data table for the element.
42 | - string onClick: The JavaScript code to be executed when the option is clicked.
43 |
44 | ### menumods.AddLuaOption(identifier, data, callback)
45 |
46 | This function is used to add options to the menu that execute code when clicked.
47 |
48 | Arguments:
49 |
50 | - any identifier: Used as a unique name for the element (like gamemode hooks).
51 | - table data: The data table for the element.
52 | - function callback: The Lua function to be executed when the option is clicked. It has no arguments.
53 |
54 | ## Data Structure
55 |
56 | The functions used to add HTML elements to the page use the data structure shown below as the "data" argument.
57 |
58 | Key | Value Type | Description
59 | --- | ---------- | -----------
60 | urls | table | Determines which pages this element should be added to. It is a table of strings.
61 | tag | string | Determines the type of HTML tag the element is. Unlike html, the tag name should be in all caps. (Ex. "A" for a `` tag, "P" for a `
153 |
154 |
155 |
156 |
--------------------------------------------------------------------------------
/menu_mods/lua/includes/modules/luahtml.lua:
--------------------------------------------------------------------------------
1 |
2 | local NullLuaHTML = {}
3 |
4 | function NullLuaHTML:IsValid()
5 | return false
6 | end
7 |
8 | NULL_HTML = {}
9 |
10 | function NULL_HTML:IsValid()
11 | return false
12 | end
13 |
14 | local AllHTMLDocs = AllHTMLDocs or {}
15 | local AllHTMLDocsCount = AllHTMLDocsCount or 0
16 | local AllValidHTMLDocsCount = AllValidHTMLDocsCount or 0
17 |
18 | local HTMLDocs = HTMLDocs or {}
19 |
20 | HTMLDocs.base_html = {}
21 |
22 | HTMLDocs.base_html.BaseClass = {}
23 | HTMLDocs.base_html.ClassName = "base_html"
24 | HTMLDocs.base_html.Head = ""
25 | HTMLDocs.base_html.Body = ""
26 | HTMLDocs.base_html.UniqueID = -1
27 | HTMLDocs.base_html.Removing = false
28 |
29 | function HTMLDocs.base_html:Index()
30 | return self.UniqueID
31 | end
32 |
33 | function HTMLDocs.base_html:Initialize()
34 |
35 | end
36 |
37 | function HTMLDocs.base_html:OnRemove()
38 |
39 | end
40 |
41 | function HTMLDocs.base_html:Remove()
42 | AllValidHTMLDocsCount = AllValidHTMLDocsCount - 1
43 |
44 | if (AllValidHTMLDocsCount < 0) then
45 | AllValidHTMLDocsCount = 0
46 | end
47 |
48 | self.Removing = true
49 | AllHTMLDocs[self.UniqueID] = nil
50 | self:OnRemove()
51 |
52 | AllHTMLDocsCount = AllHTMLDocsCount - 1
53 |
54 | if (AllHTMLDocsCount < 0) then
55 | AllHTMLDocsCount = 0
56 | end
57 | end
58 |
59 | function HTMLDocs.base_html:IsValid()
60 | return (not self.Removing) and (AllHTMLDocs[self.UniqueID] == self)
61 | end
62 |
63 | function HTMLDocs.base_html:GetClass()
64 | return self.ClassName
65 | end
66 |
67 | function HTMLDocs.base_html:GetHead()
68 | return self.Head
69 | end
70 |
71 | function HTMLDocs.base_html:SetHead(head)
72 | if (not isstring(head)) then return end
73 |
74 | self.Head = head
75 | end
76 |
77 | function HTMLDocs.base_html:GetBody()
78 | return self.Body
79 | end
80 |
81 | function HTMLDocs.base_html:SetBody(body)
82 | if (not isstring(body)) then return end
83 |
84 | self.Body = body
85 | end
86 |
87 | function HTMLDocs.base_html:OnOpenInPanel(HTML)
88 |
89 | end
90 |
91 | function HTMLDocs.base_html:OnRunScript(script)
92 |
93 | end
94 |
95 | function HTMLDocs.base_html:OpenInPanel(HTML)
96 | if (self.CurrentPanel and self.CurrentPanel:IsValid()) then
97 | local newDoc = luahtml.Create(self.ClassName)
98 |
99 | newDoc:SetHead(self.Head)
100 | newDoc:SetBody(self.Body)
101 |
102 | newDoc:OpenInPanel(HTML)
103 |
104 | return
105 | end
106 |
107 | self.CurrentPanel = HTML
108 |
109 | if (not self:IsValid()) then return end
110 |
111 | HTML:SetAllowLua(true)
112 |
113 | HTML:OpenURL("asset://garrysmod/html/blank.html")
114 |
115 | local exec = "document.head.innerHTML = document.head.innerHTML + \"" .. menumods.string.LevelPush(self.Head, 1, true) .. "\";\ndocument.body.innerHTML = document.body.innerHTML + \"" .. menumods.string.LevelPush(self.Body, 1, true) .. "\";\nvar allElements = document.getElementsByTagName(\"*\");\nvar currIndex;\nfor (currIndex in allElements) {\nvar currElement = allElements[currIndex];\nif ((currElement.hasAttribute != undefined) && (currElement.getAttribute != undefined)) {\nif (currElement.hasAttribute(\"lua-href\")) {\ncurrElement.setAttribute(\"href\", \"asset://garrysmod/html/blank.html\");\ncurrElement.addEventListener(\"click\", function(){\nlua.Run(\"local document = luahtml.GetByIndex(" .. self.UniqueID .. ")\\nif document:IsValid() then\\ndocument:OpenNewInCurrentPanel(\\\"\" + menumods.string.levelPush(this.getAttribute(\"lua-href\"), 1, true) + \"\\\")\\nend\");\n});\n}\nif ((currElement.tagName === \"SCRIPT\") && (currElement.hasAttribute(\"lua-src\"))) {\nlua.Run(\"local document = luahtml.GetByIndex(" .. self.UniqueID .. ")\\nif document:IsValid() then\\ndocument:RunScript(\\\"\" + menumods.string.levelPush(currElement.getAttribute(\"lua-src\"), 1, true) + \"\\\")\\nend\");\n}\n}\n}\n"
116 |
117 | HTML:Call(exec)
118 |
119 | self:OnOpenInPanel(HTML)
120 | end
121 |
122 | function HTMLDocs.base_html:OpenNewInCurrentPanel(class, doNotRemove)
123 | if (not self.CurrentPanel) then return end
124 | if (not self.CurrentPanel:IsValid()) then return end
125 |
126 | local newPanel = self.CurrentPanel
127 |
128 | if (not doNotRemove) then
129 | self:Remove()
130 | end
131 |
132 | local newDoc = luahtml.Create(class)
133 |
134 | newDoc:OpenInPanel(newPanel)
135 | end
136 |
137 | function HTMLDocs.base_html:RunScript(class, doNotRemove)
138 | if (not self.CurrentPanel) then return end
139 | if (not self.CurrentPanel:IsValid()) then return end
140 |
141 | local newPanel = self.CurrentPanel
142 |
143 | local script = luajs.Create(class)
144 |
145 | script:RunInPanel(newPanel)
146 |
147 | self:OnRunScript(script)
148 |
149 | if (not doNotRemove) then
150 | script:Remove()
151 | end
152 | end
153 |
154 | function HTMLDocs.base_html:GetCurrentPanel()
155 | if (not self.CurrentPanel) then
156 | return NULL
157 | end
158 |
159 | return self.CurrentPanel
160 | end
161 |
162 | baseclass.Set("base_html", HTMLDocs.base_html)
163 |
164 | luahtml = {}
165 |
166 | function luahtml.Register(tab, name)
167 | local newName = string.lower(name)
168 |
169 | tab.ClassName = name
170 |
171 | baseclass.Set(newName, tab)
172 |
173 | tab.BaseClass = baseclass.Get(tab.Base)
174 |
175 | HTMLDocs[name] = tab
176 | end
177 |
178 | local function FindUniqueID(luahtml)
179 | local currID = 1
180 | local foundID = false
181 |
182 | while (not foundID) do
183 | if (not AllHTMLDocs[currID]) then
184 | foundID = true
185 | else
186 | currID = currID + 1
187 | end
188 | end
189 |
190 | AllHTMLDocs[currID] = luahtml
191 | luahtml.UniqueID = currID
192 | end
193 |
194 | function luahtml.Create(class)
195 | if (not HTMLDocs[class]) then
196 | local errInfo = debug.getinfo(0, "S")
197 |
198 | error("[ERROR] " .. errInfo.short_src .. ": Attempted to create a new HTML document object from a non-existent class.")
199 |
200 | return
201 | end
202 |
203 | local newObject = table.Copy(HTMLDocs[class])
204 |
205 | AllHTMLDocsCount = AllHTMLDocsCount + 1
206 |
207 | FindUniqueID(newObject)
208 |
209 | AllValidHTMLDocsCount = AllValidHTMLDocsCount + 1
210 |
211 | newObject:Initialize()
212 |
213 | return newObject
214 | end
215 |
216 | function luahtml.GetClasses()
217 | return HTMLDocs
218 | end
219 |
220 | function luahtml.GetClassTable(class)
221 | return HTMLDocs[class]
222 | end
223 |
224 | function luahtml.GetClassTableCopy(class)
225 | if (not HTMLDocs[class]) then
226 | return nil
227 | end
228 |
229 | return table.Copy(HTMLDocs[class])
230 | end
231 |
232 | function luahtml.GetByIndex(index)
233 | if (not AllHTMLDocs[index]) then return NullLuaHTML end
234 |
235 | return AllHTMLDocs[index]
236 | end
237 |
238 | function luahtml.GetAll()
239 | local tab = {}
240 |
241 | for k, v in pairs(AllHTMLDocs) do
242 | table.insert(tab, v)
243 | end
244 |
245 | return tab
246 | end
247 |
248 | function luahtml.GetCount(includeRemoved)
249 | if includeRemoved then
250 | return (AllHTMLDocsCount + 0)
251 | end
252 |
253 | return (AllValidHTMLDocsCount + 0)
254 | end
255 |
256 | local function string_CompareToSearch(str, search, caseSensitive)
257 | local newStr
258 | local searchTab
259 |
260 | if caseSensitive then
261 | newStr = ("" .. str)
262 | searchTab = string.Explode("*", search, false)
263 | else
264 | newStr = string.lower(str)
265 | searchTab = string.Explode("*", string.lower(search), false)
266 | end
267 |
268 | local currPos = 1
269 | local doesMatch = true
270 |
271 | for k, v in ipairs(searchTab) do
272 | if (v != "") then
273 | if (k > 1) then
274 | local start, endpos = string.find(str, v, currPos, true)
275 |
276 | if start then
277 | currPos = endpos
278 | else
279 | doesMatch = false
280 |
281 | break
282 | end
283 | else
284 | local start, endpos = string.find(str, v, currPos, true)
285 |
286 | if start then
287 | currPos = endpos
288 |
289 | if (start != 1) then
290 | doesMatch = false
291 |
292 | break
293 | end
294 | else
295 | doesMatch = false
296 |
297 | break
298 | end
299 | end
300 | end
301 | end
302 |
303 | return doesMatch
304 | end
305 |
306 | function luahtml.FindByClass(class)
307 | local tab = {}
308 |
309 | for k, v in pairs(AllHTMLDocs) do
310 | if string_CompareToSearch(v.ClassName, class, false) then
311 | table.insert(tab, v)
312 | end
313 | end
314 |
315 | return tab
316 | end
317 |
--------------------------------------------------------------------------------
/menu_mods/lua/includes/modules/netdata.lua:
--------------------------------------------------------------------------------
1 |
2 | netdata = {}
3 |
4 | local NullNetData = {}
5 |
6 | function NullNetData:IsValid()
7 | return false
8 | end
9 |
10 | NULL_NET = {}
11 |
12 | function NULL_NET:IsValid()
13 | return false
14 | end
15 |
16 | local AllNetDatas = AllNetDatas or {}
17 | local AllNetDatasCount = AllNetDatasCount or 0
18 | local AllValidNetDatasCount = AllValidNetDatasCount or 0
19 |
20 | local NetDatas = NetDatas or {}
21 |
22 | NetDatas.base_netdata = {}
23 |
24 | NetDatas.base_netdata.BaseClass = {}
25 | NetDatas.base_netdata.ClassName = "base_netdata"
26 | NetDatas.base_netdata.Data = ""
27 | NetDatas.base_netdata.UniqueID = -1
28 | NetDatas.base_netdata.Removing = false
29 |
30 | function NetDatas.base_netdata:Index()
31 | return self.UniqueID
32 | end
33 |
34 | function NetDatas.base_netdata:Initialize()
35 |
36 | end
37 |
38 | function NetDatas.base_netdata:OnRemove()
39 |
40 | end
41 |
42 | function NetDatas.base_netdata:Remove()
43 | AllValidNetDatasCount = AllValidNetDatasCount - 1
44 |
45 | if (AllValidNetDatasCount < 0) then
46 | AllValidNetDatasCount = 0
47 | end
48 |
49 | self.Removing = true
50 | AllNetDatas[self.UniqueID] = nil
51 | self:OnRemove()
52 |
53 | AllNetDatasCount = AllNetDatasCount - 1
54 |
55 | if (AllNetDatasCount < 0) then
56 | AllNetDatasCount = 0
57 | end
58 | end
59 |
60 | function NetDatas.base_netdata:IsValid()
61 | return (not self.Removing) and (AllNetDatas[self.UniqueID] == self)
62 | end
63 |
64 | function NetDatas.base_netdata:GetClass()
65 | return self.ClassName
66 | end
67 |
68 | function NetDatas.base_netdata:OnWriteToFile(filename)
69 |
70 | end
71 |
72 | function NetDatas.base_netdata:OnReadFromFile(filename, dir, oldData)
73 |
74 | end
75 |
76 | function NetDatas.base_netdata:GetData()
77 | return self.Data
78 | end
79 |
80 | function NetDatas.base_netdata:SetData(data)
81 | if (not isstring(data)) then return end
82 |
83 | self.Data = data
84 | end
85 |
86 | function NetDatas.base_netdata:WriteDataToFile(filename)
87 | local filenameTab = string.Explode("/", filename, false)
88 | local currFolder
89 |
90 | for k, v in ipairs(filenameTab) do
91 | if (k < #filenameTab) then
92 | local dir
93 |
94 | if isstring(currFolder) then
95 | dir = currFolder .. "/" .. v
96 | else
97 | dir = v
98 | end
99 |
100 | if (not file.IsDir(dir, "DATA")) then
101 | file.CreateDir(dir)
102 | end
103 |
104 | currFolder = dir
105 | end
106 | end
107 |
108 | local data = self.Data
109 |
110 | if (not data) then
111 | data = ""
112 | end
113 |
114 | file.Write(filename, data)
115 |
116 | self:OnWriteToFile(filename)
117 | end
118 |
119 | function NetDatas.base_netdata:ReadDataFromFile(filename, dir)
120 | if (not file.Exists(filename, dir)) then return end
121 |
122 | local data = file.Read(filename, dir)
123 |
124 | if (not data) then
125 | data = ""
126 | end
127 |
128 | local oldData = "" .. self.Data
129 |
130 | self.Data = data
131 |
132 | self:OnReadFromFile(filename, dir, oldData)
133 | end
134 |
135 | function NetDatas.base_netdata:WriteAngle(...)
136 | self.Data = menumods.string.WriteAngle(self.Data, ...)
137 | end
138 |
139 | function NetDatas.base_netdata:WriteBool(...)
140 | self.Data = menumods.string.WriteBool(self.Data, ...)
141 | end
142 |
143 | function NetDatas.base_netdata:WriteNumber(...)
144 | self.Data = menumods.string.WriteNumber(self.Data, ...)
145 | end
146 |
147 | function NetDatas.base_netdata:WriteString(...)
148 | self.Data = menumods.string.WriteString(self.Data, ...)
149 | end
150 |
151 | function NetDatas.base_netdata:WriteTable(...)
152 | self.Data = menumods.string.WriteTable(self.Data, ...)
153 | end
154 |
155 | function NetDatas.base_netdata:WriteEntity(...)
156 | self.Data = menumods.string.WriteEntity(self.Data, ...)
157 | end
158 |
159 | function NetDatas.base_netdata:WritePanel(...)
160 | self.Data = menumods.string.WritePanel(self.Data, ...)
161 | end
162 |
163 | function NetDatas.base_netdata:WriteVector(...)
164 | self.Data = menumods.string.WriteVector(self.Data, ...)
165 | end
166 |
167 | function NetDatas.base_netdata:WriteType(...)
168 | self.Data = menumods.string.WriteType(self.Data, ...)
169 | end
170 |
171 | function NetDatas.base_netdata:ReadAngle(...)
172 | local newVal, newData = menumods.string.ReadAngle(self.Data, ...)
173 |
174 | self.Data = newData
175 |
176 | return newVal
177 | end
178 |
179 | function NetDatas.base_netdata:ReadBool(...)
180 | local newVal, newData = menumods.string.ReadBool(self.Data, ...)
181 |
182 | self.Data = newData
183 |
184 | return newVal
185 | end
186 |
187 | function NetDatas.base_netdata:ReadNumber(...)
188 | local newVal, newData = menumods.string.ReadNumber(self.Data, ...)
189 |
190 | self.Data = newData
191 |
192 | return newVal
193 | end
194 |
195 | function NetDatas.base_netdata:ReadString(...)
196 | local newVal, newData = menumods.string.ReadString(self.Data, ...)
197 |
198 | self.Data = newData
199 |
200 | return newVal
201 | end
202 |
203 | function NetDatas.base_netdata:ReadTable(...)
204 | local newVal, newData = menumods.string.ReadTable(self.Data, ...)
205 |
206 | self.Data = newData
207 |
208 | return newVal
209 | end
210 |
211 | function NetDatas.base_netdata:ReadEntity(...)
212 | local newVal, newData = menumods.string.ReadEntity(self.Data, ...)
213 |
214 | self.Data = newData
215 |
216 | return newVal
217 | end
218 |
219 | function NetDatas.base_netdata:ReadPanel(...)
220 | local newVal, newData = menumods.string.ReadTable(self.Data, ...)
221 |
222 | self.Data = newData
223 |
224 | return newVal
225 | end
226 |
227 | function NetDatas.base_netdata:ReadVector(...)
228 | local newVal, newData = menumods.string.ReadVector(self.Data, ...)
229 |
230 | self.Data = newData
231 |
232 | return newVal
233 | end
234 |
235 | function NetDatas.base_netdata:ReadType(...)
236 | local newVal, newData = menumods.string.ReadType(self.Data, ...)
237 |
238 | self.Data = newData
239 |
240 | return newVal
241 | end
242 |
243 | baseclass.Set("base_netdata", NetDatas.base_netdata)
244 |
245 | function netdata.Register(tab, name)
246 | local newName = string.lower(name)
247 |
248 | tab.ClassName = name
249 |
250 | baseclass.Set(newName, tab)
251 |
252 | tab.BaseClass = baseclass.Get(tab.Base)
253 |
254 | NetDatas[name] = tab
255 | end
256 |
257 | local function FindUniqueID(savDat)
258 | local currID = 1
259 | local foundID = false
260 |
261 | while (not foundID) do
262 | if (not AllNetDatas[currID]) then
263 | foundID = true
264 | else
265 | currID = currID + 1
266 | end
267 | end
268 |
269 | AllNetDatas[currID] = savDat
270 | savDat.UniqueID = currID
271 | end
272 |
273 | function netdata.Create(class)
274 | if (not NetDatas[class]) then
275 | local errInfo = debug.getinfo(0, "S")
276 |
277 | error("[ERROR] " .. errInfo.short_src .. ": Attempted to create a new NetData object from a non-existent class.")
278 |
279 | return
280 | end
281 |
282 | local newObject = table.Copy(NetDatas[class])
283 |
284 | AllNetDatasCount = AllNetDatasCount + 1
285 |
286 | FindUniqueID(newObject)
287 |
288 | AllValidNetDatasCount = AllValidNetDatasCount + 1
289 |
290 | newObject:Initialize()
291 |
292 | return newObject
293 | end
294 |
295 | function netdata.GetClasses()
296 | return NetDatas
297 | end
298 |
299 | function netdata.GetClassTable(class)
300 | return NetDatas[class]
301 | end
302 |
303 | function netdata.GetClassTableCopy(class)
304 | if (not NetDatas[class]) then
305 | return nil
306 | end
307 |
308 | return table.Copy(NetDatas[class])
309 | end
310 |
311 | function netdata.GetByIndex(index)
312 | if (not AllNetDatas[index]) then return NullNetData end
313 |
314 | return AllNetDatas[index]
315 | end
316 |
317 | function netdata.GetAll()
318 | local tab = {}
319 |
320 | for k, v in pairs(AllNetDatas) do
321 | table.insert(tab, v)
322 | end
323 |
324 | return tab
325 | end
326 |
327 | function netdata.GetCount(includeRemoved)
328 | if includeRemoved then
329 | return (AllNetDatasCount + 0)
330 | end
331 |
332 | return (AllValidNetDatasCount + 0)
333 | end
334 |
335 | local function string_CompareToSearch(str, search, caseSensitive)
336 | local newStr
337 | local searchTab
338 |
339 | if caseSensitive then
340 | newStr = ("" .. str)
341 | searchTab = string.Explode("*", search, false)
342 | else
343 | newStr = string.lower(str)
344 | searchTab = string.Explode("*", string.lower(search), false)
345 | end
346 |
347 | local currPos = 1
348 | local doesMatch = true
349 |
350 | for k, v in ipairs(searchTab) do
351 | if (v != "") then
352 | if (k > 1) then
353 | local start, endpos = string.find(str, v, currPos, true)
354 |
355 | if start then
356 | currPos = endpos
357 | else
358 | doesMatch = false
359 |
360 | break
361 | end
362 | else
363 | local start, endpos = string.find(str, v, currPos, true)
364 |
365 | if start then
366 | currPos = endpos
367 |
368 | if (start != 1) then
369 | doesMatch = false
370 |
371 | break
372 | end
373 | else
374 | doesMatch = false
375 |
376 | break
377 | end
378 | end
379 | end
380 | end
381 |
382 | return doesMatch
383 | end
384 |
385 | function netdata.FindByClass(class)
386 | local tab = {}
387 |
388 | for k, v in pairs(AllNetDatas) do
389 | if string_CompareToSearch(v.ClassName, class, false) then
390 | table.insert(tab, v)
391 | end
392 | end
393 |
394 | return tab
395 | end
396 |
--------------------------------------------------------------------------------
/lua_reference/menumods.md:
--------------------------------------------------------------------------------
1 | # menumods
2 |
3 | ### menumods.include(filename)
4 |
5 | Includes an outside file. Works like the normal "include" function.
6 |
7 | Arguments:
8 |
9 | - string filename: The name of the .lua file to include.
10 |
11 | IMPORTANT: This function must be used in place of the "include" function when in the menu state due to a fatal Lua error in which the file is not found.
12 |
13 | NOTE: This function will include the first file of the specified name, regardless of which addon it comes from. Ensure to give your .lua files unique names.
14 |
15 | ### menumods.GetFullLuaFileName(filename)
16 |
17 | Returns the full path of a .lua file relative to the "lua/" folder (as if you were including the file using "menumods.include").
18 |
19 | Arguments:
20 |
21 | - string filename: The name of the file. Can be relative to the current file or relative to the "lua/" folder.
22 |
23 | Returns:
24 |
25 | - string fullFilename: The full path of the file.
26 |
27 | ### menumods.LogLuaError(content)
28 |
29 | Logs a Lua error in the directory "garrysmod/data/menu_mods/logs" with the given content.
30 |
31 | Arguments:
32 |
33 | - string content: The content of the log.
34 |
35 | ### menumods.NewLuaErrorLogFile(filename, extension)
36 |
37 | Changes the destination of logs created with "menumods.LogLuaError" to a new file.
38 |
39 | Arguments:
40 |
41 | - string filename: The prefix name of the file. (Do not include a file extension.)
42 | - string extension: The file extension of the new file. (Ex: `".txt"`, `".dat"`, etc.)
43 |
44 | ### menumods.ChangeLuaErrorLogFile(filename, extension, index)
45 |
46 | Changes the destination of logs created with "menumods.LogLuaError" to an already existing file. Will create a new file if the file doesn't exist.
47 |
48 | Arguments:
49 |
50 | - string filename: The prefix name of the file. (Do not include a file extension.)
51 | - string extension: The file extension of the new file. (Ex: `".txt"`, `".dat"`, etc.)
52 | - number index: The index of the file. Will choose the file with the last index if none is provided.
53 |
54 | ### menumods.LogJavaScript(content)
55 |
56 | Logs JavaScript code in the directory "garrysmod/data/menu_mods/logs" with the given content.
57 |
58 | Arguments:
59 |
60 | - string content: The content of the log.
61 |
62 | ### menumods.CreateLog(content) DEPRECIATED
63 |
64 | Logs JavaScript code in the directory "garrysmod/data/menu_mods/logs" with the given content. Alias of "menumods.LogJavaScript".
65 |
66 | Arguments:
67 |
68 | - string content: The content of the log.
69 |
70 | ### menumods.NewJavaScriptLogFile(filename, extension)
71 |
72 | Changes the destination of logs created with "menumods.LogJavaScript" to a new file.
73 |
74 | Arguments:
75 |
76 | - string filename: The prefix name of the file. (Do not include a file extension.)
77 | - string extension: The file extension of the new file. (Ex: `".txt"`, `".dat"`, etc.)
78 |
79 | ### menumods.ChangeJavaScriptLogFile(filename, extension, index)
80 |
81 | Changes the destination of logs created with "menumods.LogJavaScript" to an already existing file. Will create a new file if the file doesn't exist.
82 |
83 | Arguments:
84 |
85 | - string filename: The prefix name of the file. (Do not include a file extension.)
86 | - string extension: The file extension of the new file. (Ex: `".txt"`, `".dat"`, etc.)
87 | - number index: The index of the file. Will choose the file with the last index if none is provided.
88 |
89 | ### menumods.FindID(identifier) INTERNAL
90 |
91 | A function that is internally used to find unoccupied indices for custom HTML elements.
92 |
93 | Arguments:
94 |
95 | - string identifier: The identifier to assign to the index.
96 |
97 | Returns:
98 |
99 | - number index: The found index.
100 |
101 | IMPORTANT: This is an internal function. It is highly recommended to refrain from using it unless there is a specific reason for doing so.
102 |
103 | ### menumods.RemoveID(id) INTERNAL
104 |
105 | A function that is internally called to remove assigned identifiers from indices after custom HTML elements have been removed from the page.
106 |
107 | Arguments:
108 |
109 | - number id: The index to remove the identifier from.
110 |
111 | IMPORTANT: This is an internal function. It is highly recommended to refrain from using it unless there is a specific reason for doing so.
112 |
113 | ### menumods.AddElement(identifier, data)
114 |
115 | This function can be used to add any HTML tag to the menu.
116 |
117 | Arguments:
118 |
119 | - any identifier: Used as a unique name for the element (like gamemode hooks).
120 | - table data: The data table for the element.
121 |
122 | ### menumods.AddOption(identifier, data, onClick)
123 |
124 | This function is used to add options to the menu that execute code when clicked.
125 |
126 | Arguments:
127 |
128 | - any identifier: Used as a unique name for the element (like gamemode hooks).
129 | - table data: The data table for the element.
130 | - string onClick: The JavaScript code to be executed when the option is clicked.
131 |
132 | ### menumods.AddLuaOption(identifier, data, callback)
133 |
134 | This function is used to add options to the menu that execute code when clicked.
135 |
136 | Arguments:
137 |
138 | - any identifier: Used as a unique name for the element (like gamemode hooks).
139 | - table data: The data table for the element.
140 | - function callback: The Lua function to be executed when the option is clicked. It has no arguments.
141 |
142 | ### menumods.ExecuteElementCallback(identifier) INTERNAL
143 |
144 | A function that is used internally to execute the callbacks of custom HTML elements when they are clicked.
145 |
146 | Arguments:
147 |
148 | - string identifier: The identifier of the HTML element.
149 |
150 | IMPORTANT: This is an internal function. It is highly recommended to refrain from using it unless there is a specific reason for doing so.
151 |
152 | ### menumods.RemoveElementFromPage(identifier)
153 |
154 | Removes the custom HTML element with the specified identifier from the menu by disabling it.
155 |
156 | Arguments:
157 |
158 | - string identifier: The identifier of the HTML element.
159 |
160 | ### menumods.RemoveElement(identifier)
161 |
162 | Permenantly removes a custom HTML element from the global table, requiring the user to restart Garry's Mod for it to be added again.
163 |
164 | Arguments:
165 |
166 | - string identifier: The identifier of the HTML element.
167 |
168 | ### menumods.RemoveHTMLElement(searchType, search)
169 |
170 | Removes the first found HTML element that matches the search.
171 |
172 | Arguments:
173 |
174 | - string searchType: Determines which property is being searched with the parentClass value (or class value for modifying existing elements). All possible values are "classname", "id", "menumodsid" (searches for an id specific to Menu Mods), "name", and "tagname".
175 | - string search: The search entry to match the property to. Can also be a number when using "id" or "menumodsid" as searchType.
176 |
177 | ### menumods.ReAddExistingElement(identifier)
178 |
179 | Re-adds a disabled custom HTML element by re-enabling it.
180 |
181 | Arguments:
182 |
183 | - string identifier: The identifier of the HTML element.
184 |
185 | ### menumods.ElementExists(identifier)
186 |
187 | Returns if the specified element exists, disabled or not.
188 |
189 | Arguments:
190 |
191 | - string identifier: The identifier of the HTML element.
192 |
193 | Returns:
194 |
195 | - boolean exists: Whether or not the element exists.
196 |
197 | ### menumods.GetElement(identifier)
198 |
199 | Returns the original table of the custom HTML element with the specified identifier.
200 |
201 | Arguments:
202 |
203 | - string identifier: The identifier of the HTML element.
204 |
205 | Returns:
206 |
207 | - table tab: The table of the element.
208 |
209 | ### menumods.GetElementNameByID(id)
210 |
211 | Returns the identifier of the custom HTML element with the specified index.
212 |
213 | Arguments:
214 |
215 | - number index: The index of the HTML element.
216 |
217 | Returns:
218 |
219 | - string identifier: The identifier of the HTML element.
220 |
221 | ### menumods.GetActiveElementTable()
222 |
223 | Returns a table of all enabled custom HTML elements.
224 |
225 | Returns:
226 |
227 | - table tab: The table of elements.
228 |
229 | ### menumods.GetElementTable()
230 |
231 | Returns a table of all custom HTML elements, enabled or not.
232 |
233 | Returns:
234 |
235 | - table tab: The table of elements.
236 |
237 | ### menumods.RunJavaScript(str)
238 |
239 | Runs JavaScript code on the main DHTML panel.
240 |
241 | ## menumods.string
242 |
243 | ### menumods.string.LevelPush(str, numLevels, noOuterQuotes)
244 |
245 | Escapes a string a certain number of times.
246 |
247 | Arguments:
248 |
249 | - string str: The string to escape.
250 | - number numLevels: The number of times to escape the string. Default is 1.
251 | - boolean noOuterQuotes: When set to false or nil, the function will add outer quotes to the string every time it is escaped.
252 |
253 | Returns:
254 |
255 | - string str: The escaped string.
256 |
257 | ### menumods.string.LevelPop(str, numLevels)
258 |
259 | De-escapes a string a certain number of times.
260 |
261 | Arguments:
262 |
263 | - string str: The string to de-escape.
264 | - number numLevels: The number of times to de-escape the string. Default is 1.
265 |
266 | Returns:
267 |
268 | - string str: The de-escaped string.
269 |
270 | ## menumods.hook
271 |
272 | ### menumods.hook.Add(eventName, identifier, func)
273 |
274 | Adds a hook exclusive to Menu Mods. The hook is like a regular gamemode hook.
275 |
276 | Arguments:
277 |
278 | - string eventName: The event name.
279 | - any identifier: The unique identifier.
280 | - function func: The function to run.
281 |
282 | ### menumods.hook.Remove(eventName, identifier)
283 |
284 | Removes a hook exclusive to Menu Mods. The hook is like a regular gamemode hook.
285 |
286 | Arguments:
287 |
288 | - string eventName: The event name.
289 | - any identifier: The unique identifier.
290 |
291 | ### menumods.hook.Run(eventName)
292 |
293 | Runs an event exclusive to Menu Mods. The event is like a regular gamemode event.
294 |
295 | Arguments:
296 |
297 | - string eventName: The event name.
298 |
299 | ### menumods.hook.GetTable()
300 |
301 | Returns a table of all Menu Mods hooks.
302 |
303 | Returns:
304 |
305 | - table tab: The table of hooks.
306 |
307 | ## menumods.net
308 |
309 | The menumods net library is similar to the regular net library, only instead of sending data between the client and server states, this library sends data between the menu and client states.
310 |
311 | ### menumods.net.IsConnected()
312 |
313 | Returns if the client state is active and currently using the net library.
314 |
315 | Returns:
316 |
317 | - boolean isConnected: Whether or not the client state is connected.
318 |
319 | ### menumods.net.Start(identifier)
320 |
321 | Starts a new net message to send to either the client or menu state.
322 |
323 | Arguments:
324 |
325 | - string identifier: The unique identifier used to name the net message.
326 |
327 | ### menumods.net.Send()
328 |
329 | Sends the current net message to either the client or menu state.
330 |
331 | ### menumods.net.Receive(identifier, func)
332 |
333 | Adds a function that is run when a net message with the specified identifier is received.
334 |
335 | Arguments:
336 |
337 | - string identifier: The unique identifier of the net message.
338 | - function func: The function to run when the message is received. It has no arguments.
339 |
340 | ### menumods.net.IsValidType(val)
341 |
342 | Returns if the value is of a valid type that can be used with the function "menumods.net.WriteType".
343 |
344 | Arguments:
345 |
346 | - any val: The value to check.
347 |
348 | Returns:
349 |
350 | - boolean isValid: Whether or not the type is valid.
351 |
352 | ### menumods.net.WriteAngle(val)
353 |
354 | Writes an angle to the current net message.
355 |
356 | Arguments:
357 |
358 | - angle val: The angle to write.
359 |
360 | ### menumods.net.WriteBool(val)
361 |
362 | Writes a boolean to the current net message.
363 |
364 | Arguments:
365 |
366 | - boolean val: The boolean to write.
367 |
368 | ### menumods.net.WriteEntity(val)
369 |
370 | Writes an entity to the current net message.
371 |
372 | Arguments:
373 |
374 | - Entity val: The entity to write.
375 |
376 | ### menumods.net.WriteNumber(val)
377 |
378 | Writes a number to the current net message.
379 |
380 | Arguments:
381 |
382 | - number val: The number to write.
383 |
384 | ### menumods.net.WritePanel(val)
385 |
386 | Writes a panel to the current net message. Alias of "menumods.net.WriteEntity".
387 |
388 | Arguments:
389 |
390 | - Panel val: The panel to write.
391 |
392 | ### menumods.net.WriteString(val)
393 |
394 | Writes a string to the current net message.
395 |
396 | Arguments:
397 |
398 | - string val: The string to write.
399 |
400 | ### menumods.net.WriteTable(val)
401 |
402 | Writes a table to the current net message.
403 |
404 | Arguments:
405 |
406 | - table val: The table to write.
407 |
408 | ### menumods.net.WriteVector(val)
409 |
410 | Writes a vector to the current net message.
411 |
412 | Arguments:
413 |
414 | - vector val: The vector to write.
415 |
416 | ### menumods.net.WriteType(val)
417 |
418 | Writes a value with a valid type to the current net message.
419 |
420 | Arguments:
421 |
422 | - any val: The value to write.
423 |
424 | ### menumods.net.ReadAngle()
425 |
426 | Reads an angle from the current net message.
427 |
428 | Returns:
429 |
430 | - angle val: The angle read.
431 |
432 | ### menumods.net.ReadBool()
433 |
434 | Reads a boolean from the current net message.
435 |
436 | Returns:
437 |
438 | - boolean val: The boolean read.
439 |
440 | ### menumods.net.ReadEntity()
441 |
442 | Reads an entity from the current net message.
443 |
444 | Returns:
445 |
446 | - Entity val: The entity read.
447 |
448 | ### menumods.net.ReadNumber()
449 |
450 | Reads a number from the current net message.
451 |
452 | Returns:
453 |
454 | - number val: The number read.
455 |
456 | ### menumods.net.ReadPanel()
457 |
458 | Reads a panel from the current net message. Alias of "menumods.net.ReadEntity".
459 |
460 | Returns:
461 |
462 | - Panel val: The panel read.
463 |
464 | ### menumods.net.ReadString()
465 |
466 | Reads a string from the current net message.
467 |
468 | Returns:
469 |
470 | - string val: The string read.
471 |
472 | ### menumods.net.ReadTable(newTab)
473 |
474 | Reads a table from the current net message.
475 |
476 | Arguments:
477 |
478 | - table newTab: If specified, fills this table with the values from the read table.
479 |
480 | Returns:
481 |
482 | - table val: The table read.
483 |
484 | ### menumods.net.ReadVector()
485 |
486 | Reads a vector from the current net message.
487 |
488 | Returns:
489 |
490 | - vector val: The vector read.
491 |
492 | ### menumods.net.ReadType()
493 |
494 | Reads a value with a valid type from the current net message.
495 |
496 | Returns:
497 |
498 | - any val: The value read.
499 |
--------------------------------------------------------------------------------
/menu_mods/lua/includes/menumods_init.lua:
--------------------------------------------------------------------------------
1 |
2 | if MenuMods_Initialized then return end
3 |
4 | local LuaDirs = {}
5 |
6 | local function UpdateLuaDirs()
7 | LuaDirs = {}
8 |
9 | local _, dirs = file.Find("lua/*", "GAME")
10 |
11 | for k, v in pairs(dirs) do
12 | local currDir = "" .. v
13 |
14 | currDir = string.gsub(currDir, "^lua%/([^%/]*).*", "%1")
15 |
16 | LuaDirs[currDir] = true
17 | end
18 | end
19 |
20 | UpdateLuaDirs()
21 |
22 | menumods = {}
23 | menumods.hook = {}
24 |
25 | function menumods.hook.GetTable()
26 | return {}
27 | end
28 |
29 | local CurrDir = "includes"
30 |
31 | function menumods.GetFullLuaFileName(filename)
32 | local newFileName = "" .. filename
33 | local prevDir = "" .. CurrDir
34 |
35 | local start, endPos = string.find(newFileName, "^[^%/]*")
36 |
37 | if endPos then
38 | if (endPos >= #newFileName) then
39 | newFileName = prevDir .. "/" .. newFileName
40 | else
41 | local folderDir = string.sub(newFileName, start, endPos)
42 | local currStr = "" .. newFileName
43 | local currFolderDir = ""
44 | local start, endPos = string.find(currStr, "^[^%/]*")
45 |
46 | while (start and endPos and (endPos < #currStr)) do
47 | if (#currFolderDir > 0) then
48 | currFolderDir = currFolderDir .. "/" .. string.sub(currStr, start, endPos)
49 | else
50 | currFolderDir = string.sub(currStr, start, endPos)
51 | end
52 |
53 | currStr = string.sub(currStr, (endPos + 2), #currStr)
54 |
55 | start, endPos = string.find(currStr, "^[^%/]*")
56 | end
57 |
58 | if (not LuaDirs[folderDir]) then
59 | newFileName = prevDir .. "/" .. newFileName
60 | prevDir = prevDir .. "/" .. currFolderDir
61 | else
62 | prevDir = currFolderDir
63 | end
64 | end
65 | end
66 |
67 | return newFileName, prevDir
68 | end
69 |
70 | local LogFilePrefix = ""
71 | local LogFileID = ""
72 | local LogFileExtension = ""
73 |
74 | function menumods.NewLuaErrorLogFile(filename, extension)
75 | if (not isstring(filename)) then
76 | filename = LogFilePrefix
77 | end
78 |
79 | if ((not isstring(extension)) or (not string.find(extension, "^%."))) then
80 | extension = ".txt"
81 | end
82 |
83 | local currID = 1
84 | local newFileID
85 |
86 | local found = false
87 |
88 | while (not found) do
89 | newFileID = tostring(currID)
90 |
91 | local newFileName = (filename .. newFileID .. extension)
92 |
93 | if (not file.Exists(newFileName, "DATA")) then
94 | found = true
95 | end
96 |
97 | currID = currID + 1
98 | end
99 |
100 | if newFileID then
101 | LogFilePrefix = filename
102 | LogFileID = newFileID
103 | LogFileExtension = extension
104 |
105 | return true
106 | end
107 |
108 | return false
109 | end
110 |
111 | function menumods.ChangeLuaErrorLogFile(filename, extension, index)
112 | if (not isstring(filename)) then
113 | filename = LogFilePrefix
114 | end
115 |
116 | if ((not isstring(extension)) or (not string.find(extension, "^%."))) then
117 | extension = ".txt"
118 | end
119 |
120 | local newFileID
121 |
122 | if ((not isnumber(index)) and (not isstring(index))) then
123 | local currID = 1
124 |
125 | local found = false
126 |
127 | while (not found) do
128 | local currFileID = tostring(currID)
129 | local newFileName = (filename .. newFileID .. extension)
130 |
131 | if file.Exists(newFileName, "DATA") then
132 | newFileID = currFileID
133 | else
134 | found = true
135 | end
136 |
137 | currID = currID + 1
138 | end
139 |
140 | if (not newFileID) then
141 | newFileID = "1"
142 | end
143 | else
144 | newFileID = tostring(index)
145 | end
146 |
147 | LogFilePrefix = filename
148 | LogFileID = newFileID
149 | LogFileExtension = extension
150 | end
151 |
152 | function menumods.LogLuaError(content)
153 | local logFileName = LogFilePrefix .. LogFileID .. LogFileExtension
154 | local CurrDir = ""
155 | local dirTab = string.Explode("/", logFileName, false)
156 | local dirTabCount = #dirTab
157 |
158 | for k, v in ipairs(dirTab) do
159 | if (k < dirTabCount) then
160 | if (k > 1) then
161 | CurrDir = CurrDir .. "/" .. v
162 | else
163 | CurrDir = v
164 | end
165 |
166 | if (not file.IsDir(CurrDir, "DATA")) then
167 | file.CreateDir(CurrDir)
168 | end
169 | else
170 | break
171 | end
172 | end
173 |
174 | if file.Exists(logFileName, "DATA") then
175 | local newContent = "\n" .. content
176 |
177 | file.Append(logFileName, newContent)
178 | else
179 | file.Write(logFileName, content)
180 | end
181 | end
182 |
183 | menumods.NewLuaErrorLogFile("menumods/logs/lua_error_log_")
184 |
185 | local ConVarTable = {}
186 | local PrevConVarValues = {}
187 |
188 | local CreateConVar_Old = CreateConVar
189 | local CreateConVar_New = CreateConVar_Old
190 |
191 | CreateConVar = function(name, default, flags, ...)
192 | local shouldSave = false
193 |
194 | if isnumber(flags) then
195 | shouldSave = (bit.band(flags, FCVAR_ARCHIVE) > 0)
196 | elseif istable(flags) then
197 | for k, v in ipairs(flags) do
198 | if (not shouldSave) then
199 | shouldSave = (bit.band(v, FCVAR_ARCHIVE) > 0)
200 | else
201 | break
202 | end
203 | end
204 | end
205 |
206 | local newName = tostring(name)
207 |
208 | if shouldSave then
209 | ConVarTable[newName] = true
210 | end
211 |
212 | local result = CreateConVar_New(name, default, ...)
213 |
214 | local prevValue = PrevConVarValues[newName]
215 |
216 | if prevValue then
217 | RunConsoleCommand(newName, prevValue)
218 | end
219 |
220 | return result
221 | end
222 |
223 | local CreateClientConVar_Old = CreateClientConVar
224 | local CreateClientConVar_New = CreateClientConVar_Old
225 |
226 | CreateClientConVar = function(name, default, shouldSave, ...)
227 | if ((not shouldSave) and (not isbool(shouldSave))) then
228 | shouldSave = true
229 | end
230 |
231 | local newName = tostring(name)
232 |
233 | if shouldSave then
234 | ConVarTable[newName] = true
235 | end
236 |
237 | local result = CreateClientConVar_New(name, default, shouldSave, ...)
238 |
239 | local prevValue = PrevConVarValues[newName]
240 |
241 | if prevValue then
242 | RunConsoleCommand(newName, prevValue)
243 | end
244 |
245 | return result
246 | end
247 |
248 | CreateConVar("menumods_enableLuaErrorLogging", 0, FCVAR_ARCHIVE)
249 |
250 | local hookName = "MenuErrorHandler"
251 |
252 | --[[
253 | local States = {
254 | [false] = "Unknown",
255 | [1] = "Server",
256 | [2] = "Menu",
257 | [3] = "Client"
258 | }
259 | ]]
260 |
261 | local AllHooks = hook.GetTable()
262 | local LuaErrorHooks = AllHooks["OnLuaError"]
263 |
264 | local MenuErrorHandler
265 |
266 | if istable(LuaErrorHooks) then
267 | local MenuErrorHandler_Old = LuaErrorHooks[hookName]
268 |
269 | if isfunction(MenuErrorHandler_Old) then
270 | MenuErrorHandler = MenuErrorHandler_Old
271 |
272 | hook.Remove("OnLuaError", hookName)
273 |
274 | LuaErrorHooks[hookName] = nil
275 | else
276 | MenuErrorHandler = function() end
277 | end
278 | else
279 | MenuErrorHandler = function() end
280 | end
281 |
282 | local function SafeEquals(a, b)
283 | if (type(a) != type(b)) then
284 | return false
285 | end
286 |
287 | return (a == b)
288 | end
289 |
290 | local function HandleErrorFunctionError(err)
291 | local text = "[ERROR] " .. err
292 |
293 | print(text)
294 | end
295 |
296 | local function OnLuaError(text, realm, addonName, addonID, ...)
297 | if (not isnumber(realm)) then
298 | realm = 0
299 | end
300 |
301 | if (not isstring(addonName)) then
302 | addonName = "N/A"
303 | end
304 |
305 | if (not isstring(addonID)) then
306 | addonID = nil
307 | end
308 |
309 | MenuErrorHandler(text, realm, addonName, addonID, ...)
310 |
311 | local allHooks = menumods.hook.GetTable()
312 | local luaErrorHooks = allHooks["OnLuaError"]
313 |
314 | if istable(luaErrorHooks) then
315 | for k, v in pairs(luaErrorHooks) do
316 | if ((not SafeEquals(k, hookName)) and isfunction(v)) then
317 | xpcall(v, HandleErrorFunctionError, text, realm, addonName, addonID, ...)
318 | end
319 | end
320 | end
321 |
322 | if (GetConVarNumber("menumods_enableLuaErrorLogging") != 0) then
323 | local errorString = "Addon: " .. addonName .. "\nRealm: " .. tostring(realm) .. "\n" .. text .. "\n"
324 |
325 | menumods.LogLuaError(errorString)
326 | end
327 | end
328 |
329 | function menumods.GetTraceString(level, shouldStop)
330 | local shouldStop = shouldStop
331 |
332 | if (not isfunction(shouldStop)) then
333 | shouldStop = function()
334 | return false
335 | end
336 | end
337 |
338 | local level = level
339 |
340 | if (not isnumber(level)) then
341 | level = 1
342 | end
343 |
344 | local finished = false
345 |
346 | local str = ""
347 |
348 | while (not finished) do
349 | local info = debug.getinfo(level, "flnSu")
350 |
351 | if info then
352 | local result = shouldStop(info, level)
353 |
354 | if (not result) then
355 | local stringToAdd = string.format("\t%i. %s - %s:%i", level, info.name, info.short_src, info.currentline)
356 |
357 | if (str != "") then
358 | str = str .. "\n" .. stringToAdd
359 | else
360 | str = stringToAdd
361 | end
362 |
363 | level = level + 1
364 | else
365 | finished = true
366 | end
367 | else
368 | finished = true
369 | end
370 | end
371 |
372 | return str
373 | end
374 |
375 | local function TraceShouldStop()
376 | local newInfo = debug.getinfo(6, "f")
377 |
378 | if (not isfunction(newInfo.func)) then
379 | return false
380 | end
381 |
382 | return (newInfo.func == menumods.include)
383 | end
384 |
385 | function menumods.error(err, realm, addonName, addonID, ...)
386 | if (not isnumber(realm)) then
387 | realm = 0
388 | end
389 |
390 | print(err)
391 |
392 | OnLuaError(err, realm, addonName, addonID, ...)
393 | end
394 |
395 | local function HandleError(err, realm, addonName, addonID, ...)
396 | if (not isnumber(realm)) then
397 | realm = 0
398 | end
399 |
400 | local traceString = menumods.GetTraceString(2, TraceShouldStop)
401 | local text = "[ERROR] " .. err .. "\n" .. traceString
402 |
403 | print(text)
404 |
405 | OnLuaError(text, realm, addonName, addonID, ...)
406 | end
407 |
408 | function menumods.include(filename)
409 | local start, endPos = string.find(filename, "%.lua$")
410 |
411 | if (not start) then
412 | print("[ERROR] Attempted to include a non-Lua file.")
413 |
414 | return
415 | end
416 |
417 | local newFileName, newDir = menumods.GetFullLuaFileName(filename)
418 |
419 | local fullFileName = "lua/" .. newFileName
420 |
421 | if file.Exists(fullFileName, "GAME") then
422 | local fileString = file.Read(fullFileName, "GAME")
423 |
424 | fileString = "local include = menumods.include; " .. fileString
425 |
426 | local exec = CompileString(fileString, newFileName, true)
427 |
428 | local result = {false}
429 |
430 | if isfunction(exec) then
431 | local prevDir = "" .. CurrDir
432 |
433 | CurrDir = newDir
434 |
435 | result = {xpcall(exec, HandleError)}
436 |
437 | CurrDir = prevDir
438 | end
439 |
440 | table.remove(result, 1)
441 |
442 | return unpack(result)
443 | end
444 | end
445 |
446 | local function SaveConVars()
447 | local conVarTab = {}
448 |
449 | for k, v in pairs(ConVarTable) do
450 | if ConVarExists(k) then
451 | conVarTab[k] = GetConVar(k):GetString()
452 | end
453 | end
454 |
455 | if (not file.IsDir("menumods", "DATA")) then
456 | file.CreateDir("menumods")
457 | end
458 |
459 | local JSON = util.TableToJSON(conVarTab, true)
460 |
461 | if JSON then
462 | file.Write("menumods/convars.txt", JSON)
463 | end
464 | end
465 |
466 | local function LoadConVars()
467 | if file.Exists("menumods/convars.txt", "DATA") then
468 | local JSON = file.Read("menumods/convars.txt", "DATA")
469 |
470 | local newConVarTab = util.JSONToTable(JSON)
471 |
472 | if newConVarTab then
473 | for k, v in pairs(newConVarTab) do
474 | local name = tostring(k)
475 | local value = tostring(v)
476 |
477 | if ConVarExists(name) then
478 | RunConsoleCommand(name, value)
479 | else
480 | PrevConVarValues[name] = value
481 | end
482 | end
483 | end
484 | end
485 | end
486 |
487 | hook.Add("OnLuaError", hookName, OnLuaError)
488 |
489 | hook.Add("CloseDermaMenus", "MenuMods_SaveConVars", SaveConVars)
490 |
491 | CreateConVar("menumods_enabled", 1, FCVAR_ARCHIVE)
492 |
493 | menumods.include("menumods_menu.lua")
494 |
495 | local FileBlacklist = {
496 | ["lua/vgui/spawnicon.lua"] = true
497 | }
498 |
499 | local files, dirs = file.Find("lua/vgui/*.lua", "MOD")
500 |
501 | for k, v in pairs(files) do
502 | if (not dirs[k]) then
503 | dirs[k] = "lua/vgui"
504 | end
505 |
506 | local filename = (dirs[k] .. "/" .. v)
507 |
508 | if ((not FileBlacklist[filename]) and file.Exists(filename, "MOD")) then
509 | filename = string.gsub(filename, "^lua%/", "")
510 |
511 | menumods.include(filename)
512 | end
513 | end
514 |
515 | local ContentChanged = false
516 |
517 | local FileTable = {}
518 | local HTMLFileTable = {}
519 | local JSFileTable = {}
520 |
521 | local function Mount()
522 | UpdateLuaDirs()
523 |
524 | LoadConVars()
525 |
526 | if (GetConVarNumber("menumods_enabled") == 0) then return end
527 |
528 | local files, dirs = file.Find("lua/vgui_menu/*.lua", "GAME")
529 |
530 | for k, v in pairs(files) do
531 | if (not dirs[k]) then
532 | dirs[k] = "lua/vgui_menu"
533 | end
534 |
535 | local filename = (dirs[k] .. "/" .. v)
536 |
537 | if ((not FileTable[filename]) and file.Exists(filename, "GAME")) then
538 | local newFileName = string.gsub(filename, "^lua%/", "")
539 |
540 | menumods.include(newFileName)
541 |
542 | FileTable[filename] = true
543 | end
544 | end
545 |
546 | files, dirs = file.Find("lua/autorun/menu/*.lua", "GAME")
547 |
548 | for k, v in pairs(files) do
549 | if (not dirs[k]) then
550 | dirs[k] = "lua/autorun/menu"
551 | end
552 |
553 | local filename = (dirs[k] .. "/" .. v)
554 |
555 | if ((not FileTable[filename]) and file.Exists(filename, "GAME")) then
556 | local newFileName = string.gsub(filename, "^lua%/", "")
557 |
558 | menumods.include(newFileName)
559 |
560 | FileTable[filename] = true
561 | end
562 | end
563 |
564 | files, dirs = file.Find("lua/htmldocs/*.lua", "GAME")
565 |
566 | for k, v in ipairs(files) do
567 | if (not dirs[k]) then
568 | dirs[k] = "lua/htmldocs"
569 | end
570 |
571 | local filename = (dirs[k] .. "/" .. v)
572 |
573 | if (not HTMLFileTable[filename]) then
574 | local startPos, endPos = string.find(v, "%.lua$")
575 |
576 | if startPos then
577 | local name = string.sub(v, 1, (startPos - 1))
578 |
579 | local shouldMount = true
580 |
581 | local dirTab = string.Explode("/", dirs[k], false)
582 |
583 | if ((#dirTab == 3) and (name == "init")) then
584 | name = string.lower(dirTab[#dirTab])
585 | elseif (#dirTab != 2) then
586 | shouldMount = false
587 | end
588 |
589 | if shouldMount then
590 | local fullPath = string.gsub((dirs[k] .. "/" .. v), "^lua/", "")
591 |
592 | LUA_HTML = {}
593 |
594 | LUA_HTML.ClassName = name
595 |
596 | if SERVER then
597 | AddCSLuaFile(fullPath)
598 | end
599 |
600 | menumods.include(fullPath)
601 |
602 | if (not LUA_HTML.Base) then
603 | LUA_HTML.Base = "base_html"
604 | end
605 |
606 | luahtml.Register(LUA_HTML, name)
607 | end
608 | end
609 |
610 | HTMLFileTable[filename] = true
611 | end
612 | end
613 |
614 | LUA_HTML = nil
615 |
616 | for k, v in pairs(luahtml.GetClasses()) do
617 | if istable(v.BaseClass) then
618 | for i, j in pairs(v.BaseClass) do
619 | if (v[i] == nil) then
620 | v[i] = j
621 | end
622 | end
623 | end
624 | end
625 |
626 | files, dirs = file.Find("lua/jsdocs/*.lua", "GAME")
627 |
628 | for k, v in ipairs(files) do
629 | if (not dirs[k]) then
630 | dirs[k] = "lua/jsdocs"
631 | end
632 |
633 | local filename = (dirs[k] .. "/" .. v)
634 |
635 | if (not JSFileTable[filename]) then
636 | local startPos, endPos = string.find(v, "%.lua$")
637 |
638 | if startPos then
639 | local name = string.sub(v, 1, (startPos - 1))
640 |
641 | local shouldMount = true
642 |
643 | local dirTab = string.Explode("/", dirs[k], false)
644 |
645 | if ((#dirTab == 3) and (name == "init")) then
646 | name = string.lower(dirTab[#dirTab])
647 | elseif (#dirTab != 2) then
648 | shouldMount = false
649 | end
650 |
651 | if shouldMount then
652 | local fullPath = string.gsub((dirs[k] .. "/" .. v), "^lua/")
653 |
654 | LUA_JS = {}
655 |
656 | LUA_JS.ClassName = name
657 |
658 | if SERVER then
659 | AddCSLuaFile(fullPath)
660 | end
661 |
662 | menumods.include(fullPath)
663 |
664 | if (not LUA_JS.Base) then
665 | LUA_JS.Base = "base_js"
666 | end
667 |
668 | luajs.Register(LUA_JS, name)
669 | end
670 | end
671 |
672 | JSFileTable[filename] = true
673 | end
674 | end
675 |
676 | LUA_JS = nil
677 |
678 | for k, v in pairs(luajs.GetClasses()) do
679 | if istable(v.BaseClass) then
680 | for i, j in pairs(v.BaseClass) do
681 | if (v[i] == nil) then
682 | v[i] = j
683 | end
684 | end
685 | end
686 | end
687 |
688 | if MenuMods_Initialized then
689 | menumods.hook.Run("Initialize")
690 | end
691 | end
692 |
693 | local function GameContentChanged()
694 | ContentChanged = true
695 | end
696 |
697 | local function Think()
698 | if (GetConVarNumber("menumods_enabled") == 0) then return end
699 |
700 | if ContentChanged then
701 | Mount()
702 | ContentChanged = false
703 | end
704 | end
705 |
706 | hook.Add("GameContentChanged", "MenuMods_GameContentChanged", GameContentChanged)
707 | hook.Add("Think", "MenuMods_Mount", Think)
708 |
709 | Mount()
710 |
711 | MenuMods_Initialized = true
712 |
--------------------------------------------------------------------------------
/menu_mods/lua/includes/menumods_menu.lua:
--------------------------------------------------------------------------------
1 |
2 | CreateConVar("menumods_debugMode", 0, FCVAR_ARCHIVE)
3 | CreateConVar("menumods_enableJavaScriptLogging", 0, FCVAR_ARCHIVE)
4 |
5 | menumods.string = {}
6 |
7 | local MenuMods_ElementTables = {}
8 | local MenuMods_Elements = {}
9 | local MenuMods_Hooks = {}
10 | local MenuMods_IDs = {}
11 |
12 | local LogFilePrefix = ""
13 | local LogFileID = ""
14 | local LogFileExtension = ""
15 |
16 | function menumods.NewJavaScriptLogFile(filename, extension)
17 | if (not isstring(filename)) then
18 | filename = LogFilePrefix
19 | end
20 |
21 | if ((not isstring(extension)) or (not string.find(extension, "^%."))) then
22 | extension = ".txt"
23 | end
24 |
25 | local currID = 1
26 | local newFileID
27 |
28 | local found = false
29 |
30 | while (not found) do
31 | newFileID = tostring(currID)
32 |
33 | local newFileName = (filename .. newFileID .. extension)
34 |
35 | if (not file.Exists(newFileName, "DATA")) then
36 | found = true
37 | end
38 |
39 | currID = currID + 1
40 | end
41 |
42 | if newFileID then
43 | LogFilePrefix = filename
44 | LogFileID = newFileID
45 | LogFileExtension = extension
46 |
47 | return true
48 | end
49 |
50 | return false
51 | end
52 |
53 | function menumods.ChangeJavaScriptLogFile(filename, extension, index)
54 | if (not isstring(filename)) then
55 | filename = LogFilePrefix
56 | end
57 |
58 | if ((not isstring(extension)) or (not string.find(extension, "^%."))) then
59 | extension = ".txt"
60 | end
61 |
62 | local newFileID
63 |
64 | if ((not isnumber(index)) and (not isstring(index))) then
65 | local currID = 1
66 |
67 | local found = false
68 |
69 | while (not found) do
70 | local currFileID = tostring(currID)
71 | local newFileName = (filename .. newFileID .. extension)
72 |
73 | if file.Exists(newFileName, "DATA") then
74 | newFileID = currFileID
75 | else
76 | found = true
77 | end
78 |
79 | currID = currID + 1
80 | end
81 |
82 | if (not newFileID) then
83 | newFileID = "1"
84 | end
85 | else
86 | newFileID = tostring(index)
87 | end
88 |
89 | LogFilePrefix = filename
90 | LogFileID = newFileID
91 | LogFileExtension = extension
92 | end
93 |
94 | function menumods.LogJavaScript(content)
95 | local logFileName = LogFilePrefix .. LogFileID .. LogFileExtension
96 | local currDir = ""
97 | local dirTab = string.Explode("/", logFileName, false)
98 | local dirTabCount = #dirTab
99 |
100 | for k, v in ipairs(dirTab) do
101 | if (k < dirTabCount) then
102 | if (k > 1) then
103 | currDir = currDir .. "/" .. v
104 | else
105 | currDir = v
106 | end
107 |
108 | if (not file.IsDir(currDir, "DATA")) then
109 | file.CreateDir(currDir)
110 | end
111 | else
112 | break
113 | end
114 | end
115 |
116 | if file.Exists(logFileName, "DATA") then
117 | local newContent = "\n" .. content
118 |
119 | file.Append(logFileName, newContent)
120 | else
121 | file.Write(logFileName, content)
122 | end
123 | end
124 |
125 | menumods.CreateLog = menumods.LogJavaScript
126 |
127 | menumods.NewJavaScriptLogFile("menumods/logs/javascript_log_")
128 |
129 | local escChars = {
130 | {"\a", "a"},
131 | {"\b", "b"},
132 | {"\f", "f"},
133 | {"\n", "n"},
134 | {"\r", "r"},
135 | {"\t", "t"},
136 | {"\v", "v"},
137 | {"\"", "\""},
138 | {"\'", "\'"},
139 | }
140 |
141 | function menumods.string.LevelPush(str, numLevels, noOuterQuotes)
142 | local numLevels_new = numLevels
143 |
144 | if (not numLevels_new) then
145 | numLevels_new = 1
146 | end
147 |
148 | local newString = ("" .. str)
149 |
150 | for i = 1, numLevels_new do
151 | newString = string.gsub(newString, "\\", "\\\\")
152 |
153 | for k, v in pairs(escChars) do
154 | local pattern1 = string.PatternSafe(v[1])
155 | local pattern2 = string.PatternSafe(v[2])
156 |
157 | newString = string.gsub(newString, pattern1, ("\\" .. pattern2))
158 | end
159 |
160 | if (not noOuterQuotes) then
161 | newString = ("\"" .. newString .. "\"")
162 | end
163 | end
164 |
165 | return newString
166 | end
167 |
168 | function menumods.string.LevelPop(str, numLevels)
169 | local numLevels_new = numLevels
170 |
171 | if (not numLevels_new) then
172 | numLevels_new = 1
173 | end
174 |
175 | local newString = ("" .. str)
176 |
177 | for i = 1, numLevels_new do
178 | for k, v in pairs(escChars) do
179 | local pattern1 = string.PatternSafe(v[1])
180 | local pattern2 = string.PatternSafe(v[2])
181 |
182 | newString = string.gsub(newString, pattern1, "")
183 | newString = string.gsub(newString, ("^\\" .. pattern2), pattern1)
184 | newString = string.gsub(newString, ("([^\\])\\" .. pattern2), ("%1" .. pattern1))
185 | end
186 |
187 | newString = string.gsub(newString, "\\\\", "\\")
188 | end
189 |
190 | return newString
191 | end
192 |
193 | function menumods.FindID(identifier)
194 | local found = false
195 | local currID = 0
196 |
197 | while (not found) do
198 | currID = currID + 1
199 |
200 | if (not MenuMods_IDs[currID]) then
201 | found = true
202 | end
203 | end
204 |
205 | MenuMods_IDs[currID] = identifier
206 |
207 | return currID
208 | end
209 |
210 | function menumods.RemoveID(id)
211 | MenuMods_IDs[id] = nil
212 | end
213 |
214 | function menumods.hook.Add(eventName, identifier, func)
215 | if (not isfunction(func)) then return end
216 |
217 | if (not MenuMods_Hooks[eventName]) then
218 | MenuMods_Hooks[eventName] = {}
219 | end
220 |
221 | if MenuMods_Hooks[eventName][identifier] then return end
222 |
223 | MenuMods_Hooks[eventName][identifier] = func
224 | end
225 |
226 | function menumods.hook.Remove(eventName, identifier)
227 | if (not MenuMods_Hooks[eventName]) then return end
228 |
229 | MenuMods_Hooks[eventName][identifier] = nil
230 |
231 | if (#MenuMods_Hooks[eventName] <= 0) then
232 | MenuMods_Hooks[eventName] = nil
233 | end
234 | end
235 |
236 | function menumods.hook.Run(eventName, ...)
237 | if (not MenuMods_Hooks[eventName]) then return true end
238 |
239 | local args = {...}
240 |
241 | local currOutput = true
242 |
243 | for k, v in pairs(MenuMods_Hooks[eventName]) do
244 | local result = v(unpack(args))
245 |
246 | if (result != nil) then
247 | if (not result) then
248 | currOutput = false
249 | end
250 | end
251 | end
252 |
253 | return currOutput
254 | end
255 |
256 | function menumods.hook.GetTable()
257 | --[[
258 | local currTable = {}
259 |
260 | for k, v in pairs(MenuMods_Hooks) do
261 | local currIndex = k
262 | local currEvent = v
263 |
264 | currTable[currIndex] = {}
265 |
266 | for i, j in pairs(currEvent) do
267 | currTable[currIndex][i] = j
268 | end
269 | end
270 | ]]
271 |
272 | return MenuMods_Hooks
273 | end
274 |
275 | function menumods.AddElement(identifier, data)
276 | if MenuMods_ElementTables["" .. identifier] then return end
277 | if (not istable(data)) then return end
278 |
279 | data.identifier = ("" .. identifier)
280 |
281 | local newData_Old = data
282 | local newData = newData_Old
283 |
284 | MenuMods_ElementTables["" .. identifier] = newData
285 |
286 | table.insert(MenuMods_Elements, (#MenuMods_Elements + 1), ("" .. identifier))
287 | end
288 |
289 | function menumods.AddOption(identifier, data, onClick)
290 | if MenuMods_ElementTables["" .. identifier] then return end
291 | if (not istable(data)) then return end
292 |
293 | data.identifier = ("" .. identifier)
294 |
295 | local newData_Old = data
296 | local newData = newData_Old
297 |
298 | newData.tag = "A"
299 |
300 | newData.onClick = onClick
301 |
302 | table.insert(newData.attributes, (#newData.attributes + 1), {"href", "#/"})
303 |
304 | MenuMods_ElementTables["" .. identifier] = newData
305 |
306 | table.insert(MenuMods_Elements, (#MenuMods_Elements + 1), ("" .. identifier))
307 | end
308 |
309 | function menumods.AddLuaOption(identifier, data, callback)
310 | if MenuMods_ElementTables["" .. identifier] then return end
311 | if (not istable(data)) then return end
312 |
313 | data.identifier = ("" .. identifier)
314 |
315 | local newData_Old = data
316 | local newData = newData_Old
317 |
318 | newData.tag = "A"
319 | newData.callback = callback
320 |
321 | newData.onClick = "lua.Run(\"menumods.ExecuteElementCallback(\\\"" .. menumods.string.LevelPush(("" .. identifier), 2, true) .. "\\\")\")"
322 |
323 | table.insert(newData.attributes, (#newData.attributes + 1), {"href", "#/"})
324 |
325 | MenuMods_ElementTables["" .. identifier] = newData
326 |
327 | table.insert(MenuMods_Elements, (#MenuMods_Elements + 1), ("" .. identifier))
328 | end
329 |
330 | function menumods.ExecuteElementCallback(identifier)
331 | if (not MenuMods_ElementTables["" .. identifier]) then return end
332 |
333 | return MenuMods_ElementTables["" .. identifier].callback()
334 | end
335 |
336 | function menumods.RemoveElementFromPage(identifier)
337 | if (not pnlMainMenu) then return end
338 | if (not pnlMainMenu.HTML) then return end
339 | if (not MenuMods_ElementTables["" .. identifier]) then return end
340 |
341 | local elementTable = MenuMods_ElementTables["" .. identifier]
342 |
343 | if (not elementTable.id) then return end
344 |
345 | pnlMainMenu.HTML:RemoveElement(elementTable.id)
346 |
347 | MenuMods_ElementTables["" .. identifier].disabled = true
348 | end
349 |
350 | function menumods.RemoveElement(identifier)
351 | menumods.RemoveElementFromPage(identifier)
352 |
353 | MenuMods_ElementTables["" .. identifier] = nil
354 | end
355 |
356 | function menumods.RemoveHTMLElement(searchType, ...)
357 | if (not pnlMainMenu) then return end
358 | if (not pnlMainMenu.HTML) then return end
359 | if (not isstring(searchType)) then return end
360 |
361 | if (searchType == "classname") then
362 | pnlMainMenu.HTML:RemoveElementByClassName(...)
363 | elseif (searchType == "id") then
364 | pnlMainMenu.HTML:RemoveElementByID(...)
365 | elseif (searchType == "menumodsid") then
366 | pnlMainMenu.HTML:RemoveElement(...)
367 | elseif (searchType == "name") then
368 | pnlMainMenu.HTML:RemoveElementByName(...)
369 | elseif (searchType == "tagname") then
370 | pnlMainMenu.HTML:RemoveElementByTagName(...)
371 | end
372 | end
373 |
374 | function menumods.ReAddExistingElement(identifier)
375 | if (not MenuMods_ElementTables["" .. identifier]) then return end
376 |
377 | MenuMods_ElementTables["" .. identifier].disabled = false
378 | end
379 |
380 | function menumods.ElementExists(identifier)
381 | if MenuMods_ElementTables["" .. identifier] then
382 | return true
383 | else
384 | return false
385 | end
386 | end
387 |
388 | function menumods.GetElement(identifier)
389 | return MenuMods_ElementTables["" .. identifier]
390 | end
391 |
392 | function menumods.GetElementNameByID(id)
393 | if (not MenuMods_IDs[id]) then return end
394 |
395 | return ("" .. MenuMods_IDs[id])
396 | end
397 |
398 | function menumods.GetActiveElementTable()
399 | local currTable = {}
400 |
401 | for k, v in pairs(MenuMods_Elements) do
402 | if MenuMods_ElementTables[v] then
403 | table.insert(currTable, (#currTable + 1), MenuMods_ElementTables[v])
404 | end
405 | end
406 |
407 | return currTable
408 | end
409 |
410 | function menumods.GetElementTable()
411 | local currTable = {}
412 |
413 | for k, v in pairs(MenuMods_ElementTables) do
414 | table.insert(currTable, (#currTable + 1), v)
415 | end
416 |
417 | return currTable
418 | end
419 |
420 | function menumods.RunJavaScript(str)
421 | if (not pnlMainMenu) then return end
422 | if (not pnlMainMenu.HTML) then return end
423 |
424 | pnlMainMenu.HTML:Call(str)
425 | end
426 |
427 | local function MenuMods_PanelInit(self)
428 | MenuMods_UpdatingURL = true
429 |
430 | self.HTML.ShouldRefresh = true
431 |
432 | function self.HTML:CreateElement(identifier, currURL, urls, tag, class, parentClass, searchType, parentNum, onClick, content, ...)
433 | local proceed = false
434 |
435 | if urls then
436 | if istable(urls) then
437 | for k, v in pairs(urls) do
438 | if (currURL == v) then
439 | proceed = true
440 | break
441 | end
442 | end
443 | elseif isstring(urls) then
444 | proceed = (currURL == urls)
445 | end
446 | else
447 | proceed = true
448 | end
449 |
450 | if proceed then
451 | local attributes = {...}
452 | local exec
453 |
454 | if (searchType == nil) then
455 | exec = "var elements = document.getElementsByClassName(" .. menumods.string.LevelPush(parentClass, 1) .. ");\n"
456 | elseif (searchType == "classname") then
457 | exec = "var elements = document.getElementsByClassName(" .. menumods.string.LevelPush(parentClass, 1) .. ");\n"
458 | elseif (searchType == "id") then
459 | exec = "var elements = [document.getElementById(" .. menumods.string.LevelPush(parentClass, 1) .. ")];\n"
460 | elseif (searchType == "menumodsid") then
461 | exec = "var elements = [document.getElementById(" .. menumods.string.LevelPush(("menumods_" .. parentClass), 1) .. ")];\n"
462 | elseif (searchType == "name") then
463 | exec = "var elements = document.getElementsByName(" .. menumods.string.LevelPush(parentClass, 1) .. ");\n"
464 | elseif (searchType == "tagname") then
465 | exec = "var elements = document.getElementsByTagName(" .. menumods.string.LevelPush(parentClass, 1) .. ");\n"
466 | else
467 | exec = "var elements = document.getElementsByClassName(" .. menumods.string.LevelPush(parentClass, 1) .. ");\n"
468 | end
469 |
470 | exec = exec .. "if (elements.length >= " .. parentNum .. ") {\nvar element = elements[" .. (parentNum - 1) .. "];\nif ((element != undefined) && (element != null)) {\nvar object = document.createElement(\"" .. tag .. "\");\nelement.appendChild(object);\n"
471 |
472 | local ID = menumods.FindID(identifier)
473 |
474 | if MenuMods_ElementTables[identifier] then
475 | MenuMods_ElementTables[identifier].id = ID
476 | end
477 |
478 | exec = exec .. "object.setAttribute(\"id\", \"menumods_" .. ID .. "\");\n"
479 |
480 | exec = exec .. "object.setAttribute(\"class\", " .. menumods.string.LevelPush(class, 1) .. ");\n"
481 |
482 | for k, v in pairs(attributes) do
483 | if isnumber(k) then
484 | if (isstring(v[1]) and isstring(v[2])) then
485 | if (v[1] != "id") and (v[1] != "class") then
486 | exec = exec .. "object.setAttribute(" .. menumods.string.LevelPush(v[1], 1) .. ", " .. menumods.string.LevelPush(v[2], 1) .. ");\n"
487 | end
488 | end
489 | end
490 | end
491 |
492 | if onClick then
493 | exec = exec .. "object.addEventListener(\"click\", function(){\n" .. onClick .. ";\n});\n"
494 | end
495 |
496 | exec = exec .. "object.innerHTML = " .. menumods.string.LevelPush(content, 1) .. ";\n} else {\nlua.Run(\"pnlMainMenu.HTML.MenuModsElements[\\\"" .. menumods.string.LevelPush(identifier, 2, true) .. "\\\"] = nil\");\n};\n} else {\nlua.Run(\"pnlMainMenu.HTML.MenuModsElements[\\\"" .. menumods.string.LevelPush(identifier, 2, true) .. "\\\"] = nil\");\n}\n"
497 |
498 | self:Call(exec)
499 |
500 | if (GetConVarNumber("menumods_enableJavaScriptLogging") != 0) then
501 | menumods.LogJavaScript(exec)
502 | end
503 |
504 | if (GetConVarNumber("menumods_debugMode") != 0) then
505 | print("Menu Mods: Created element of class " .. menumods.string.LevelPush(class, 1) .. " parented to element of class " .. menumods.string.LevelPush(parentClass, 1) .. ".")
506 | end
507 |
508 | menumods.hook.Run("ElementCreated", currURL, urls, tag, class, parentClass, parentNum, content, ...)
509 |
510 | return ID
511 | end
512 | end
513 |
514 | function self.HTML:ModifyElement(currURL, urls, class, searchType, num, onClick, content, ...)
515 | local proceed = false
516 |
517 | if urls then
518 | if istable(urls) then
519 | for k, v in pairs(urls) do
520 | if (currURL == v) then
521 | proceed = true
522 | break
523 | end
524 | end
525 | elseif isstring(urls) then
526 | proceed = (currURL == urls)
527 | end
528 | else
529 | proceed = true
530 | end
531 |
532 | if proceed then
533 | local attributes = {...}
534 | local exec
535 |
536 | if (searchType == nil) then
537 | exec = "var elements = document.getElementsByClassName(" .. menumods.string.LevelPush(class, 1) .. ");\n"
538 | elseif (searchType == "classname") then
539 | exec = "var elements = document.getElementsByClassName(" .. menumods.string.LevelPush(class, 1) .. ");\n"
540 | elseif (searchType == "id") then
541 | exec = "var elements = [document.getElementById(" .. menumods.string.LevelPush(class, 1) .. ")];\n"
542 | elseif (searchType == "menumodsid") then
543 | exec = "var elements = [document.getElementById(" .. menumods.string.LevelPush(("menumods_" .. class), 1) .. ")];\n"
544 | elseif (searchType == "name") then
545 | exec = "var elements = document.getElementsByName(" .. menumods.string.LevelPush(class, 1) .. ");\n"
546 | elseif (searchType == "tagname") then
547 | exec = "var elements = document.getElementsByTagName(" .. menumods.string.LevelPush(class, 1) .. ");\n"
548 | else
549 | exec = "var elements = document.getElementsByClassName(" .. menumods.string.LevelPush(class, 1) .. ");\n"
550 | end
551 |
552 | exec = exec .. "if (objects.length >= " .. num .. ") {\nvar object = objects[" .. (num - 1) .. "];\nif ((object != undefined) && (object != null)) {\n"
553 |
554 | for k, v in pairs(attributes) do
555 | if isnumber(k) then
556 | if (isstring(v[1]) and isstring(v[2])) then
557 | if (v[1] != "id") and (v[1] != "class") then
558 | exec = exec .. "object.setAttribute(" .. menumods.string.LevelPush(v[1], 1) .. ", " .. menumods.string.LevelPush(v[2], 1) .. ");\n"
559 | end
560 | end
561 | end
562 | end
563 |
564 | if onClick then
565 | exec = exec .. "object.addEventListener(\"click\", function(){\n" .. onClick .. ";\n});\n"
566 | end
567 |
568 | if content then
569 | exec = exec .. "object.innerHTML = " .. menumods.string.LevelPush(content, 1) .. ";\n"
570 | end
571 |
572 | exec = exec .. "};\n}\n"
573 |
574 | self:Call(exec)
575 |
576 | if (GetConVarNumber("menumods_enableJavaScriptLogging") != 0) then
577 | menumods.LogJavaScript(exec)
578 | end
579 |
580 | if (GetConVarNumber("menumods_debugMode") != 0) then
581 | print("Menu Mods: Modified element of class " .. menumods.string.LevelPush(class, 1) .. ".")
582 | end
583 |
584 | menumods.hook.Run("ElementModified", currURL, urls, class, num, content, ...)
585 | end
586 | end
587 |
588 | function self.HTML:RemoveElement(id)
589 | local exec = "var object = document.getElementById(\"menumods_" .. id .. "\");\nif (object != null) {\nif (object.parentNode != undefined) {\nobject.parentNode.removeChild(object);\n};\n};\n"
590 |
591 | self:Call(exec)
592 |
593 | if (GetConVarNumber("menumods_enableJavaScriptLogging") != 0) then
594 | menumods.LogJavaScript(exec)
595 | end
596 |
597 | menumods.hook.Run("ElementRemoved", "menumods_id", id)
598 |
599 | menumods.RemoveID(id)
600 |
601 | if (GetConVarNumber("menumods_debugMode") != 0) then
602 | print("Menu Mods: Removed element of Menu Mods ID " .. menumods.string.LevelPush(id, 1) .. ".")
603 | end
604 | end
605 |
606 | function self.HTML:RemoveElementByID(id)
607 | local exec = "var object = document.getElementById(" .. menumods.string.LevelPush(id, 1) .. ");\nif (object != null) {\nif ((object.parentNode != undefined) && (object.parentNode != null) && (object.id.indexOf(\"menumods_\") != 0)) {\nobject.parentNode.removeChild(object);\n};\n};\n"
608 |
609 | self:Call(exec)
610 |
611 | if (GetConVarNumber("menumods_enableJavaScriptLogging") != 0) then
612 | menumods.LogJavaScript(exec)
613 | end
614 |
615 | menumods.hook.Run("ElementRemoved", "id", id)
616 |
617 | if (GetConVarNumber("menumods_debugMode") != 0) then
618 | print("Menu Mods: Removed element of ID " .. menumods.string.LevelPush(id, 1) .. ".")
619 | end
620 | end
621 |
622 | function self.HTML:RemoveElementByClassName(className, num)
623 | local exec = "var objects = document.getElementsByClassName(" .. menumods.string.LevelPush(className, 1) .. ");\nvar object = objects[" .. (num - 1) .. "];\nif (object != undefined) {\nif ((object.parentNode != undefined) && (object.parentNode != null) && (object.id.indexOf(\"menumods_\") != 0)) {\nobject.parentNode.removeChild(object);\n};\n};\n"
624 |
625 | self:Call(exec)
626 |
627 | if (GetConVarNumber("menumods_enableJavaScriptLogging") != 0) then
628 | menumods.LogJavaScript(exec)
629 | end
630 |
631 | menumods.hook.Run("ElementRemoved", "classname", className, num)
632 |
633 | if (GetConVarNumber("menumods_debugMode") != 0) then
634 | print("Menu Mods: Removed element of class name " .. menumods.string.LevelPush(className, 1) .. ", occurrence " .. num .. ".")
635 | end
636 | end
637 |
638 | function self.HTML:RemoveElementByName(name, num)
639 | local exec = "var objects = document.getElementsByName(" .. menumods.string.LevelPush(name, 1) .. ");\nvar object = objects[" .. (num - 1) .. "];\nif (object != undefined) {\nif ((object.parentNode != undefined) && (object.parentNode != null) && (object.id.indexOf(\"menumods_\") != 0)) {\nobject.parentNode.removeChild(object);\n};\n};\n"
640 |
641 | self:Call(exec)
642 |
643 | if (GetConVarNumber("menumods_enableJavaScriptLogging") != 0) then
644 | menumods.LogJavaScript(exec)
645 | end
646 |
647 | menumods.hook.Run("ElementRemoved", "name", className, num)
648 |
649 | if (GetConVarNumber("menumods_debugMode") != 0) then
650 | print("Menu Mods: Removed element of name " .. menumods.string.LevelPush(name, 1) .. ", occurrence " .. num .. ".")
651 | end
652 | end
653 |
654 | function self.HTML:RemoveElementByTagName(tagName, num)
655 | local exec = "var objects = document.getElementsByTagName(" .. menumods.string.LevelPush(tagName, 1) .. ");\nvar object = objects[" .. (num - 1) .. "];\nif (object != undefined) {\nif ((object.parentNode != undefined) && (object.parentNode != null) && (object.id.indexOf(\"menumods_\") != 0)) {\nobject.parentNode.removeChild(object);\n};\n};\n"
656 |
657 | self:Call(exec)
658 |
659 | if (GetConVarNumber("menumods_enableJavaScriptLogging") != 0) then
660 | menumods.LogJavaScript(exec)
661 | end
662 |
663 | menumods.hook.Run("ElementRemoved", "tagname", className, num)
664 |
665 | if (GetConVarNumber("menumods_debugMode") != 0) then
666 | print("Menu Mods: Removed element of class name " .. menumods.string.LevelPush(tagName, 1) .. ", occurrence " .. num .. ".")
667 | end
668 | end
669 |
670 | function self.HTML:OnDocumentReady(url)
671 | self.ShouldRefresh = true
672 | end
673 |
674 | function self:UpdateHTML()
675 | if self.HTML then
676 | if ((not MenuMods_UpdatingURL) or self.HTML.ShouldRefresh) then
677 | menumods.hook.Run("PageThink")
678 |
679 | MenuMods_UpdatingURL = true
680 |
681 | self.HTML:Call("lua.Run(\"pnlMainMenu.HTML.MenuMods_URL = \\\"\" + document.URL + \"\\\"; MenuMods_UpdatingURL = false\")")
682 | end
683 |
684 | if (not self.HTML.MenuModsElements) then
685 | self.HTML.MenuModsElements = {}
686 | end
687 |
688 | if self.HTML.MenuMods_URL then
689 | if ((self.HTML.MenuMods_URL != self.HTML.MenuMods_PrevURL) or self.HTML.ShouldRefresh) then
690 | if file.Exists("html/js/menu/menumods.js", "GAME") then
691 | local fileString = file.Read("html/js/menu/menumods.js", "GAME")
692 |
693 | self.HTML:Call(fileString)
694 | end
695 |
696 | menumods.hook.Run("PrePageChange", self.HTML.MenuMods_PrevURL, self.HTML.MenuMods_URL)
697 |
698 | MenuMods_IDs = {}
699 | end
700 |
701 | local j = 1
702 | local tableLength = #MenuMods_Elements
703 |
704 | for i = 1, tableLength do
705 | local k = MenuMods_Elements[j]
706 | local v = MenuMods_ElementTables[k]
707 |
708 | if v then
709 | if (not isbool(v.prevDisabled)) then
710 | v.prevDisabled = false
711 | end
712 |
713 | if (not isbool(v.prevShow)) then
714 | v.prevShow = true
715 | end
716 |
717 | if (not v.disabled) then
718 | local show = true
719 |
720 | if (v.show != nil) then
721 | if isfunction(v.show) then
722 | if (not v.show()) then
723 | show = false
724 | end
725 | elseif (not v.show) then
726 | show = false
727 | end
728 | end
729 |
730 | if show then
731 | if ((not self.HTML.MenuModsElements[k]) or (self.HTML.MenuMods_URL != self.HTML.MenuMods_PrevURL) or self.HTML.ShouldRefresh or (not v.prevShow) or v.prevDisabled) then
732 | local function handleError( err )
733 | print("[ERROR] Menu Mods: Identifier \"" .. k .. "\": " .. err)
734 | end
735 |
736 | local exec
737 |
738 | if (not v.modifyExisting) then
739 | exec = function()
740 | self.HTML:CreateElement(k, self.HTML.MenuMods_URL, v.urls, v.tag, v.class, v.parentClass, v.searchType, v.parentNum, v.onClick, v.content, unpack(v.attributes))
741 | end
742 | else
743 | exec = function()
744 | self.HTML:ModifyElement(self.HTML.MenuMods_URL, v.urls, v.class, v.searchType, v.num, v.onClick, v.content, unpack(v.attributes))
745 | end
746 | end
747 |
748 | xpcall(exec, handleError)
749 |
750 | v = MenuMods_ElementTables[k]
751 |
752 | self.HTML.MenuModsElements[k] = true
753 | end
754 | elseif (v.id and (not v.modifyExisting)) then
755 | self.HTML:RemoveElement(v.id)
756 |
757 | self.HTML.MenuModsElements[k] = nil
758 | end
759 | elseif (v.id and (not v.modifyExisting)) then
760 | self.HTML:RemoveElement(v.id)
761 |
762 | self.HTML.MenuModsElements[k] = nil
763 | end
764 |
765 | v.prevDisabled = v.disabled
766 | v.prevShow = v.show
767 |
768 | j = j + 1
769 | else
770 | table.remove(MenuMods_Elements, j)
771 | end
772 | end
773 |
774 | if ((self.HTML.MenuMods_URL != self.HTML.MenuMods_PrevURL) or self.HTML.ShouldRefresh) then
775 | menumods.hook.Run("PostPageChange", self.HTML.MenuMods_PrevURL, self.HTML.MenuMods_URL)
776 | end
777 |
778 | self.HTML.MenuMods_PrevURL = self.HTML.MenuMods_URL
779 | end
780 |
781 | self.HTML.ShouldRefresh = false
782 | end
783 | end
784 |
785 | if self.HTML then
786 | menumods.hook.Run("Initialize")
787 |
788 | self.MenuMods_HasInitialized = true
789 |
790 | print("Menu Mods has been initialized.")
791 | end
792 | end
793 |
794 | local function Think()
795 | if (not (pnlMainMenu and pnlMainMenu:IsValid())) then return end
796 | if (not pnlMainMenu.HTML) then return end
797 | if pnlMainMenu.MenuMods_HasCreatedFuncs then return end
798 |
799 | local PanelInit_Old = pnlMainMenu.Init
800 | local PanelInit = PanelInit_Old
801 |
802 | MenuMods_UpdatingURL = false
803 |
804 | pnlMainMenu.Init = function(self)
805 | if PanelInit then
806 | PanelInit(self)
807 | end
808 |
809 | if (not self.MenuMods_HasInitialized) then
810 | MenuMods_PanelInit(self)
811 | end
812 |
813 | if self.UpdateHTML then
814 | self:UpdateHTML()
815 | end
816 | end
817 |
818 | local PanelThink_Old = pnlMainMenu.Think
819 | local PanelThink = PanelThink_Old
820 |
821 | pnlMainMenu.Think = function(self)
822 | if PanelThink then
823 | PanelThink(self)
824 | end
825 |
826 | if (not self.MenuMods_HasInitialized) then
827 | MenuMods_PanelInit(self)
828 | end
829 |
830 | if self.UpdateHTML then
831 | self:UpdateHTML()
832 | end
833 |
834 | menumods.hook.Run("Think")
835 | end
836 |
837 | pnlMainMenu.MenuMods_HasCreatedFuncs = true
838 | end
839 |
840 | hook.Add("Think", "MenuMods_CheckMainMenuPanel", Think)
841 |
842 | menumods.include("includes/extensions/menumods_net.lua")
843 | menumods.include("includes/modules/luahtml.lua")
844 | menumods.include("includes/modules/luajs.lua")
845 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------