Skip to content

Commit 5916bee

Browse files
committed
Version 0.3.1
* Some improvements to http error displaying * Memory leak fixed
1 parent a528fa0 commit 5916bee

File tree

10 files changed

+52
-37
lines changed

10 files changed

+52
-37
lines changed

build.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ SET RL_SCRIPTHOOK_SDK_DIR=.\src\thirdparty\ScriptHook!RL_SCRIPTHOOK_VARIANT!
4747
IF "%RL_STANDALONE%"=="1" (
4848
SET RL_OUT_PATH=".\objs\output!RL_SCRIPTHOOK_VARIANT!"
4949
SET RL_CFLAGS=!RL_CFLAGS! /DREDLUA_STANDALONE /Zi /MTd
50-
SET RL_CFLAGS=!RL_CFLAGS! /Fd!RL_OUT_PATH!\ /DEBUG
50+
SET RL_CFLAGS=!RL_CFLAGS! /Fd!RL_OUT_PATH!\ /DEBUG
5151
SET RL_SOURCES=!RL_SOURCES! src\thirdparty\easyloggingpp.cpp
52-
SET RL_OUT_BIN=RedLua.dll
52+
SET RL_OUT_BIN=RedLua.dll
5353
) ELSE (
5454
SET RL_CFLAGS=!RL_CFLAGS! /MT
5555
SET RL_LIBS=!RL_LIBS! ScriptHook!RL_SCRIPTHOOK_VARIANT!.lib

src/base.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void RedLuaMain(void) {
4646
if(logger->enabled(el::Level::Global) && logger->toStandardOutput(el::Level::Global)) {
4747
bool alloced = false;
4848
if(AttachConsole(ATTACH_PARENT_PROCESS) || (alloced = AllocConsole()) == true) {
49-
if(alloced) SetConsoleTitle("RedLua debug console");
49+
if(alloced) SetConsoleTitle(REDLUA_NAME " debug console");
5050
freopen("CONOUT$", "w", stdout);
5151
freopen("CONOUT$", "w", stderr);
5252
HasConsole = true;
@@ -60,7 +60,7 @@ void RedLuaMain(void) {
6060
menuController->SetCurrentPosition(
6161
Settings.Read("menu_position", 0)
6262
);
63-
LOG(DEBUG) << "RedLua menu initialized";
63+
LOG(DEBUG) << REDLUA_NAME " menu initialized";
6464
#endif
6565
if(Settings.Read("auto_updates", false)) {
6666
LOG(DEBUG) << "Starting updates checker...";
@@ -72,7 +72,7 @@ void RedLuaMain(void) {
7272
CreateUpdateAlert(menuController, data);
7373
#endif
7474
else
75-
LOG(DEBUG) << "RedLua updater: " << data;
75+
LOG(DEBUG) << REDLUA_NAME " updater: " << data;
7676
if(UpdatesCtl.CheckNativeDB(data))
7777
LOG(INFO) << "NativeDB updated successfully";
7878
else

src/constants.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

33
#define REDLUA_NAME "RedLua"
4-
#define REDLUA_VERSION "v0.3.0"
5-
#define REDLUA_VERSION_NUM 030
4+
#define REDLUA_VERSION "v0.3.1"
5+
#define REDLUA_VERSION_NUM 031
66
#define REDLUA_FULLNAME REDLUA_NAME " " REDLUA_VERSION
77

88
#ifndef REDLUA_GTAV

src/dllmain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ BOOL DllMain(HMODULE hInstance, DWORD dwReason, LPVOID lpReserved) {
1717
|| !EnsureDirectory(REDLUA_CLIBS_DIR)) {
1818
switch(MessageBox(NULL, "Failed to create RedLua "
1919
"directory, please set write permissions "
20-
"to the root folder of the game.", "RedLua",
20+
"to the root folder of the game.", REDLUA_FULLNAME,
2121
MB_ICONERROR | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
2222
)) {
2323
case IDCANCEL:

src/menus/helpers.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class MenuItemLink : public MenuItemDefault {
1818

1919
class MenuTemporary : public MenuBase
2020
{
21-
virtual void OnPop(void)
21+
void OnPop(void)
2222
{
23+
GetController()->UnregisterMenu(this);
2324
delete this;
2425
}
2526

src/menus/scripts.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
#include "luascript.hpp"
33
#include "menus\scripts.hpp"
44

5-
class MenuScript : public MenuBase {
6-
virtual void OnPop() {
7-
delete this;
8-
}
9-
5+
class MenuScript : public MenuTemporary {
106
private:
117
LuaScript *m_script;
128

139
public:
1410
MenuScript(MenuItemTitle *title, LuaScript *script)
15-
: MenuBase(title), m_script(script) {}
11+
: MenuTemporary(title), m_script(script) {}
1612

1713
virtual LuaScript *GetScript(void) {
1814
return m_script;

src/native/call.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static int native_prepare_nobj(lua_State *L, NativeParam *param, bool vector_all
5050
nativePush(vec[i * 2]);
5151
return 3;
5252
}
53-
53+
5454
NativeTypeInfo &nti_obj = get_type_info(no->hdr.type),
5555
&nti_param = get_type_info(param->type);
5656

@@ -127,19 +127,19 @@ static int native_perform(lua_State *L, NativeMeth *meth) {
127127
case NTYPE_HASH:
128128
lua_pushinteger(L, *ret);
129129
break;
130-
130+
131131
case NTYPE_FLOAT:
132132
lua_pushnumber(L, *(float *)ret);
133133
break;
134-
134+
135135
case NTYPE_BOOL:
136136
lua_pushboolean(L, *(int *)ret);
137137
break;
138-
138+
139139
case NTYPE_CHAR:
140140
lua_pushlstring(L, (char *)ret, 1);
141141
break;
142-
142+
143143
default:
144144
push_cached_fullobject(L, meth->returns, (NativeData)*ret);
145145
break;

src/native/object.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static NativeObject *push_uncached_fullcopy
3333
memcpy(&no->content, ptr, nti.size * count);
3434
else
3535
memset(&no->content, 0, nti.size * count);
36-
36+
3737
return no;
3838
}
3939

@@ -47,7 +47,7 @@ static NativeObject *push_cached_lightobjectlink
4747
NativeCache *cache = get_native_cache(L, cache_ref);
4848
if(search_in_cache(L, cache, &cache_id, type, -1, &cached))
4949
return (NativeObject *)lua_touserdata(L, -1);
50-
50+
5151
auto no = (NativeObject *)lua_newuserdata(L, sizeof(NativeObject));
5252
NATIVEOBJECT_INITLIGHT(no, type, false, 1, *ptr);
5353
luaL_setmetatable(L, LUANATIVE_OBJECT);
@@ -106,7 +106,7 @@ static int vector_newindex(lua_State *L, NativeObject *no, char idx) {
106106
case 'X':
107107
nv->x = (float)luaL_checknumber(L, 3);
108108
break;
109-
109+
110110
case 'y':
111111
case 'Y':
112112
nv->y = (float)luaL_checknumber(L, 3);
@@ -130,7 +130,7 @@ static int vector_index(lua_State *L, NativeObject *no, char idx) {
130130
case 'X':
131131
lua_pushnumber(L, nv->x);
132132
return 1;
133-
133+
134134
case 'y':
135135
case 'Y':
136136
lua_pushnumber(L, nv->y);

src/thirdparty/scriptmenu.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ class MenuBase
198198
void AddItem(MenuItemBase *item) { item->SetMenu(this); m_items.push_back(item); }
199199
int GetActiveItemIndex() { return m_activeScreenIndex * MenuBase_linesPerScreen + m_activeLineIndex; }
200200
void OnDraw();
201-
void OnPop() {}
202201
int OnInput();
203202
void OnFrame()
204203
{
205204
for (size_t i = 0; i < m_items.size(); i++)
206205
m_items[i]->OnFrame();
207206
}
207+
virtual void OnPop() {}
208208
void SetController(MenuController *controller) { m_controller = controller; }
209209
MenuController *GetController() { return m_controller; }
210210
};
@@ -304,6 +304,16 @@ class MenuController
304304
m_menuList.push_back(menu);
305305
}
306306
}
307+
void UnregisterMenu(MenuBase *menu)
308+
{
309+
for (size_t i = 0; i < m_menuList.size(); i++) {
310+
if (m_menuList[i] == menu)
311+
{
312+
m_menuList.erase(m_menuList.begin() + i);
313+
break;
314+
}
315+
}
316+
}
307317
void Update()
308318
{
309319
OnDraw();

src/updatesctl.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ using json = nlohmann::json;
1616
static const std::string errors[] = {
1717
"Internal error: ",
1818
"Server responded with error: ",
19-
"HTTP request failed: ",
19+
"HTTP request error: ",
2020
"Malformed server response",
2121

2222
// Internal errors
23-
"failed to initialize WinInet",
24-
"InternetOpenUrl failed",
25-
"HttpQueryInfo failed"
23+
"failed to initialize WinInet ",
24+
"InternetOpenUrl failed ",
25+
"HttpQueryInfo failed ",
26+
"HttpReadFile faield "
2627
};
2728

2829
static HINTERNET hInternet = NULL;
@@ -39,12 +40,17 @@ void UpdatesController::Stop(void) {
3940

4041
static HINTERNET open_request(std::string url, std::string headers) {
4142
return InternetOpenUrl(hInternet, url.c_str(), headers.c_str(), headers.length(),
42-
INTERNET_FLAG_SECURE | INTERNET_FLAG_NO_UI | INTERNET_FLAG_NO_COOKIES, 0);
43+
INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_PRAGMA_NOCACHE, 0);
44+
}
45+
46+
static std::string build_error(int t1, int t2) {
47+
std::string str = errors[t1] + errors[t2];
48+
return str + std::to_string(GetLastError());
4349
}
4450

4551
bool UpdatesController::CheckRedLua(std::string &ret) {
4652
if(!Prepare()) {
47-
ret = errors[0] + errors[4];
53+
ret = build_error(0, 4);
4854
return false;
4955
}
5056

@@ -56,13 +62,15 @@ bool UpdatesController::CheckRedLua(std::string &ret) {
5662

5763
HINTERNET hRequest;
5864
do {
59-
hRequest = open_request(REDLUA_TAGS_URL, "Accept: application/json");
60-
if(hRequest == NULL) break;
65+
if((hRequest = open_request(REDLUA_TAGS_URL, "Accept: application/json")) == NULL) {
66+
ret = build_error(0, 5);
67+
break;
68+
}
6169

6270
while((success = InternetReadFile(hRequest, buf, BUFSIZE, &read)) && read > 0)
6371
temp.append((const char *)buf, read);
6472
if(!success) {
65-
ret = errors[2] + std::to_string(GetLastError());
73+
ret = build_error(2, 7);
6674
break;
6775
}
6876

@@ -119,13 +127,13 @@ bool UpdatesController::CheckNativeDB(std::string &ret, bool force_update) {
119127
if(!force_update)
120128
headers.append("\r\nIf-None-Match: " + Settings.Read("nativedb_etag", etag));
121129
if((hRequest = open_request(REDLUA_NATIVEDB_URL, headers)) == NULL) {
122-
ret = errors[0] + errors[5];
130+
ret = build_error(0, 5);
123131
break;
124132
}
125133

126134
DWORD code = 0; DWORD codelen = sizeof(DWORD);
127135
if(!HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &codelen, NULL)) {
128-
ret = errors[0] + errors[6];
136+
ret = build_error(0, 6);
129137
break;
130138
}
131139

@@ -144,7 +152,7 @@ bool UpdatesController::CheckNativeDB(std::string &ret, bool force_update) {
144152

145153
DWORD bufsize = BUFSIZE;
146154
if(!HttpQueryInfoA(hRequest, HTTP_QUERY_ETAG, buf, &bufsize, NULL)) {
147-
ret = errors[0] + errors[6];
155+
ret = build_error(0, 6);
148156
break;
149157
}
150158

0 commit comments

Comments
 (0)