Skip to content

Commit 3209e10

Browse files
committed
Version 0.5.0
+ Initial Language API implementation * Fix some me memory leaks
1 parent 363792d commit 3209e10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+948
-475
lines changed

examples/RCE.lua/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Remote Code Execution example
22

3-
As soon as RCE loads, it starts the web server on [0.0.0.0:1337](https://127.0.0.1:1337/). When you open this page, you will see the code editor where you can execute Lua scripts in realtime.
3+
As soon as RCE loads, it starts the web server on [0.0.0.0:1337](https://127.0.0.1:1337/). When you open this page, you will see the code editor where you can execute Lua scripts in realtime. Note that the game **must not** be paused, otherwise the server will be unavailable!
44

55
## Editor hotkeys:
66
1. F5 - Execute code
@@ -10,4 +10,4 @@ As soon as RCE loads, it starts the web server on [0.0.0.0:1337](https://127.0.0
1010

1111
## Credits
1212

13-
This mod uses thirdparty libraries such as [luasocket](https://luarocks.org/modules/lunarmodules/luasocket) and [mimetypes](https://luarocks.org/modules/luarocks/mimetypes)
13+
This mod uses thirdparty libraries such as [luasocket](https://luarocks.org/modules/lunarmodules/luasocket), [mimetypes](https://luarocks.org/modules/luarocks/mimetypes), [Ace Editor](https://ace.c9.io/) and [Toastify](https://github.com/apvarun/toastify-js)

examples/RCE.lua/main.lua

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ local index_page = [[
4242
<script>
4343
window.onload = () => {
4444
let sessions = [];
45-
for(let i = 0; i < 10; i++) {
45+
for (let i = 0; i < 10; i++) {
4646
let name = 'sess' + i;
4747
let session = JSON.parse(localStorage.getItem(name));
48-
if(session == null) {
48+
if (session == null) {
4949
session = {
5050
annotations: [],
5151
breakpoints: [],
@@ -69,7 +69,7 @@ local index_page = [[
6969
}
7070
7171
let restoreSession = (current, id) => {
72-
if(id >= sessions.length) throw "wtf dude?";
72+
if (id >= sessions.length) throw "wtf dude?";
7373
let saved = sessions[id];
7474
7575
current.removeFolds(current.getAllFolds());
@@ -110,7 +110,7 @@ local index_page = [[
110110
}
111111
112112
let currentSession = parseInt(localStorage.getItem('sess'));
113-
if(isNaN(currentSession)) currentSession = 0;
113+
if (isNaN(currentSession)) currentSession = 0;
114114
115115
let editor = ace.edit('editor');
116116
editor.focus();
@@ -178,9 +178,9 @@ local index_page = [[
178178
179179
keyboardJS.watch(editor_el);
180180
181-
for(let i = 0; i < 10; i++) {
181+
for (let i = 0; i < 10; i++) {
182182
keyboardJS.bind('ctrl+num' + i, (e) => {
183-
if(currentSession != i) {
183+
if (currentSession != i) {
184184
let session = editor.getSession();
185185
saveSession(session, currentSession);
186186
restoreSession(session, i);
@@ -205,7 +205,7 @@ local index_page = [[
205205
206206
keyboardJS.bind('f5', (e) => {
207207
let code = editor.getSession().getValue();
208-
if(code.length > 1) {
208+
if (code.length > 1) {
209209
let xhr = new XMLHttpRequest();
210210
xhr.open('POST', '/api/execute', true);
211211
xhr.setRequestHeader('Content-Type', 'text/x-lua');
@@ -227,7 +227,6 @@ local index_page = [[
227227
]]
228228

229229
function t.OnLoad()
230-
package.loaded.svhttp = nil
231230
local server = require('svhttp'):newServer('*', 1337)
232231
local exec_env = setmetatable({
233232
_SELF = server,

examples/ScriptMenu.lua

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,58 @@
11
local t = {}
22

33
function t.OnLoad()
4-
menu.set{
5-
title = 'My menu',
6-
items = {
7-
{
8-
type = 1,
9-
title = 'My inactive button'
10-
},
11-
{
12-
type = 1,
13-
title = 'My button',
14-
onclick = function()
15-
print('Hello!')
16-
end
17-
},
18-
{
19-
type = 2,
20-
title = 'My switchable',
21-
onclick = function(state)
22-
return not state
23-
end
24-
},
25-
{
26-
type = 0,
27-
islist = true,
28-
title = 'My sublist',
29-
menu = {
30-
title = 'My submenu',
31-
items = {
32-
{
33-
type = 1,
34-
title = 'My subbutton',
35-
onclick = function() end
4+
lang.install {
5+
en = {
6+
['example.mystr'] = 'My localized button'
7+
},
8+
ru = {
9+
['example.mystr'] = 'Моя локализированная кнопка'
10+
}
11+
}
12+
end
13+
14+
function t.OnTick(buildMenu)
15+
-- Menu builder MUST be here
16+
if buildMenu then
17+
menu.set{
18+
title = 'My menu',
19+
items = {
20+
{
21+
type = 1,
22+
title = lang.get 'example.mystr'
23+
},
24+
{
25+
type = LUAMENU_ITEM_BUTTON,
26+
title = 'My button',
27+
onclick = function()
28+
print('Hello!')
29+
end
30+
},
31+
{
32+
type = LUAMENU_ITEM_SWITCHABLE,
33+
title = 'My switchable',
34+
onclick = function(state)
35+
return not state
36+
end
37+
},
38+
{
39+
type = LUAMENU_ITEM_MENU,
40+
islist = true,
41+
title = 'My sublist',
42+
menu = {
43+
title = 'My submenu',
44+
items = {
45+
{
46+
type = 1,
47+
title = 'My subbutton',
48+
onclick = function() end
49+
}
3650
}
3751
}
3852
}
3953
}
4054
}
41-
}
55+
end
4256
end
4357

4458
function t.OnStop()

misc/Langs/en.lng

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
English
2+
0
3+
4+
# Main menu
5+
core.main.scripts=Scripts
6+
core.main.refr=Refresh scripts list
7+
core.main.setts=Settings
8+
core.main.about=About RedLua
9+
10+
# Settings
11+
core.setts.autorun=Autorun feature enabled
12+
core.setts.updater=Check for updates at startup
13+
core.setts.chkupd=Check for updates
14+
core.setts.langs=Change language
15+
core.setts.rldndb=Reload NativeDB
16+
core.setts.pos=Change menu position
17+
core.setts.toggall=Toggle all scripts
18+
core.setts.relall=Reload all scripts
19+
core.setts.unlall=Unload all scripts
20+
21+
core.setts.nfy.srlsc=Script list has been successfully updated
22+
core.setts.nfy.srlfl=Failed to update script list
23+
core.setts.nfy.nrlsc=NativeDB reloaded successfully!
24+
core.setts.nfy.nrlfl=Failed to reload NativeDB, error code: %d
25+
core.setts.nfy.runall=All scripts have been resumed
26+
core.setts.nfy.stpall=All scripts have been suspended
27+
core.setts.nfy.unlall=All scripts have been unloaded
28+
29+
# Scripts list
30+
core.scripts.nf=Scripts not found
31+
32+
# Script manager
33+
core.script.state=Status: %s
34+
core.script.state1=running
35+
core.script.state2=error
36+
core.script.state3=disabled
37+
core.script.usage=Usage: %.3f KB
38+
core.script.rvlusage=[press to show RAM usage]
39+
core.script.ownmenu=Script menu
40+
core.script.tgl=Toggle
41+
core.script.rel=Reload
42+
core.script.unl=Unload
43+
44+
core.script.nfy.relsc=Script successfully reloaded
45+
core.script.nfy.relfl=Script failed to reload
46+
core.script.nfy.unlsc=Script successfully unloaded
47+
48+
# Updater
49+
core.chkupd.rl=Check for RedLua updates
50+
core.chkupd.ndb=Check for NativeDB updates
51+
core.chkupd.nfy.noup=No updates found
52+
core.chkupd.nfy.upfl=Updater failed, error code: %d
53+
core.updalert.nfn=New version %s found
54+
core.updalert.btn=Go to release page
55+
56+
# Выбор языка
57+
core.langs.ingame=Ingame language
58+
core.langs.nfy.chsc=Language changed successfully
59+
60+
# Position
61+
core.pos.left=Left
62+
core.pos.center=Center
63+
core.pos.right=Right
64+
65+
# Notifications
66+
core.nfy.redir=Link will be opened in your default browser in a few moments...

misc/Langs/ru.lng

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Русский
2+
7
3+
4+
# Главное меню
5+
core.main.scripts=Скрипты
6+
core.main.refr=Обновить список скриптов
7+
core.main.setts=Настройки
8+
core.main.about=О RedLua
9+
10+
# Настройки
11+
core.setts.autorun=Автозагрузка скриптов
12+
core.setts.updater=Автообновление библиотеки
13+
core.setts.chkupd=Проверить обновления
14+
core.setts.langs=Изменить язык
15+
core.setts.rldndb=Перезагрузить NativeDB
16+
core.setts.pos=Расположение меню
17+
core.setts.toggall=Вкл/выкл все скрипты
18+
core.setts.relall=Перезагрузить все скрипты
19+
core.setts.unlall=Выгрузить все скрипты
20+
21+
core.setts.nfy.srlsc=Список скриптов успешно обновлён
22+
core.setts.nfy.srlfl=Не удалось обновить список скриптов
23+
core.setts.nfy.nrlsc=NativeDB успешно перезагружена
24+
core.setts.nfy.nrlfl=Не удалось перезагрузить NativeDB: %d
25+
core.setts.nfy.runall=Выполнение всех скриптов возобновлено
26+
core.setts.nfy.stpall=Выполнение всех скриптов приостановлено
27+
core.setts.nfy.unlall=Все скрпиты выгружены
28+
29+
# Список скриптов
30+
core.scripts.nf=Скрипты не найдены
31+
32+
# Управление скриптом
33+
core.script.state=Состояние: %s
34+
core.script.state1=запущен
35+
core.script.state2=ошибка
36+
core.script.state3=остановлен
37+
core.script.usage=Исп. ОЗУ: %.3f КБ
38+
core.script.rvlusage=[Показать исп. ОЗУ]
39+
core.script.ownmenu=Меню скрипта
40+
core.script.tgl=Вкл/выкл
41+
core.script.rel=Перезагрузить
42+
core.script.unl=Выгрузить
43+
44+
core.script.nfy.relsc=Скрипт успешно перезагружен
45+
core.script.nfy.relfl=Не удалось перезапустить скрипт
46+
core.script.nfy.unlsc=Скрипт выгружен успешно
47+
48+
# Проверка обновлений
49+
core.chkupd.rl=Обновить RedLua
50+
core.chkupd.ndb=Обновить NativeDB
51+
core.chkupd.nfy.upfl=Поризошла ошибка при обновлении: %d
52+
core.updalert.nfn=Новая версия %s
53+
core.updalert.btn=Открыть страницу загрузки
54+
55+
# Выбор языка
56+
core.langs.ingame=Язык игры
57+
core.langs.nfy.chsc=Язык успешно изменён
58+
59+
# Расположение меню
60+
core.pos.left=Слева
61+
core.pos.center=По центру
62+
core.pos.right=Справа
63+
64+
# Уведомления
65+
core.nfy.redir=Выбранная ссылка скоро будет открыта в вашем браузере

misc/Pack.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ $CODES = @{
55

66
Foreach($item in @("RDR2", "V")) {
77
New-Item -Path ".\objs\output$($item)\" -Name "RedLua" -ItemType "Directory" -ErrorAction "SilentlyContinue"
8+
Copy-Item -Path ".\misc\Langs\" -Destination ".\objs\output$($item)\RedLua\" -Container -Recurse -Force
89
Copy-Item .\README.md .\objs\output$($item)\
910
Copy-Item .\LICENSE .\objs\output$($item)\
1011
CURL.EXE -o.\objs\output$($item)\RedLua\natives.json https://raw.githubusercontent.com/alloc8or/$($CODES[$item])-nativedb-data/master/natives.json

misc/ScriptHook.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
$ErrorActionPreference = "Stop";
22

33
$SCR_DIR = $(Split-Path $MyInvocation.MyCommand.Path -Parent)
4-
if($args[0] -eq "gtav") {
4+
if ($args[0] -eq "gtav") {
55
$VARIANT = "V"
66
$LINK = "/gtav/scripthookv/"
77
} else {
@@ -17,16 +17,16 @@ $FILES = @(
1717
"inc/types.h", "readme.txt", "lib/ScriptHook$($VARIANT).lib"
1818
)
1919

20-
if(Test-Path -PathType Container $SHOOK_DIR) {
20+
if (Test-Path -PathType Container $SHOOK_DIR) {
2121
$corrupted = $false
2222

2323
Foreach($item in $FILES) {
24-
if(!(Test-Path "$SHOOK_DIR/$item")) {
24+
if (!(Test-Path "$SHOOK_DIR/$item")) {
2525
$corrupted = $true;
2626
break
2727
}
2828
}
29-
if($corrupted -eq $false) {
29+
if ($corrupted -eq $false) {
3030
Exit 0
3131
}
3232

@@ -53,16 +53,16 @@ $HEADERS = @{
5353
}
5454

5555
Foreach($elem in (Invoke-WebRequest -URI ($DOMAIN + $LINK)).Links.Href) {
56-
if($elem.IndexOf("ScriptHook$($VARIANT)_SDK") -ige 0) {
56+
if ($elem.IndexOf("ScriptHook$($VARIANT)_SDK") -ige 0) {
5757
$outFile = "$SCR_DIR/temp.zip";
5858
Invoke-WebRequest -Uri ($DOMAIN + $elem) -OutFile $outFile -Headers $HEADERS
5959
Add-Type -Assembly System.IO.Compression.FileSystem
6060
$zip = [IO.Compression.ZipFile]::OpenRead($outFile)
6161
New-Item -ItemType Directory -Path $SHOOK_DIR
6262
Foreach($ent in $zip.Entries) {
6363
$fileName = $ent.FullName
64-
if($FILES.Contains($fileName)) {
65-
if($fileName.Substring($fileName.Length - 1) -eq '/') {
64+
if ($FILES.Contains($fileName)) {
65+
if ($fileName.Substring($fileName.Length - 1) -eq '/') {
6666
New-Item -ItemType Directory -Path "$SHOOK_DIR\$filename"
6767
Continue
6868
}

0 commit comments

Comments
 (0)