From 3fb97952947e221d7c02808b8ca795df2f2a2b3c Mon Sep 17 00:00:00 2001
From: TehRealSalt <tehrealsalt@gmail.com>
Date: Sat, 12 Nov 2016 18:46:53 -0500
Subject: [PATCH] m_cond constants for Lua, reverting table offset

m_cond constants are fairly self-explanatory; useful constants for Lua
for the unlockable library. Also undid part of my last commit, since I
realized since then none of the other internal tables do that.
---
 src/dehacked.c    | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 src/lua_condlib.c | 20 ++++++++---------
 2 files changed, 65 insertions(+), 10 deletions(-)

diff --git a/src/dehacked.c b/src/dehacked.c
index ea3b92d51..026ec949f 100644
--- a/src/dehacked.c
+++ b/src/dehacked.c
@@ -7394,6 +7394,61 @@ struct {
 
 	{"V_CHARCOLORSHIFT",V_CHARCOLORSHIFT},
 	{"V_ALPHASHIFT",V_ALPHASHIFT},
+	
+	// conditions
+	{"UC_PLAYTIME",UC_PLAYTIME},
+	{"UC_GAMECLEAR",UC_GAMECLEAR},
+	{"UC_ALLEMERALDS",UC_ALLEMERALDS},
+	{"UC_ULTIMATECLEAR",UC_ULTIMATECLEAR},
+	{"UC_OVERALLSCORE",UC_OVERALLSCORE},
+	{"UC_OVERALLTIME",UC_OVERALLTIME},
+	{"UC_OVERALLRINGS",UC_OVERALLRINGS},
+	{"UC_MAPVISITED",UC_MAPVISITED},
+	{"UC_MAPBEATEN",UC_MAPBEATEN},
+	{"UC_MAPALLEMERALDS",UC_MAPALLEMERALDS},
+	{"UC_MAPULTIMATE",UC_MAPULTIMATE},
+	{"UC_MAPPERFECT",UC_MAPPERFECT},
+	{"UC_MAPSCORE",UC_MAPSCORE},
+	{"UC_MAPTIME",UC_MAPTIME},
+	{"UC_MAPRINGS",UC_MAPRINGS},
+	{"UC_NIGHTSSCORE",UC_NIGHTSSCORE},
+	{"UC_NIGHTSTIME",UC_NIGHTSTIME},
+	{"UC_NIGHTSGRADE",UC_NIGHTSGRADE},
+	{"UC_TRIGGER",UC_TRIGGER},
+	{"UC_TOTALEMBLEMS",UC_TOTALEMBLEMS},
+	{"UC_EMBLEM",UC_EMBLEM},
+	{"UC_EXTRAEMBLEM",UC_EXTRAEMBLEM},
+	{"UC_CONDITIONSET",UC_CONDITIONSET},
+	
+	{"MAXCONDITIONSETS",MAXCONDITIONSETS},
+	
+	// emblems
+	{"ET_GLOBAL",ET_GLOBAL},
+	{"ET_SKIN",ET_SKIN},
+	{"ET_SCORE",ET_SCORE},
+	{"ET_TIME",ET_TIME},
+	{"ET_RINGS",ET_RINGS},
+	{"ET_NGRADE",ET_NGRADE},
+	{"ET_NTIME",ET_NTIME},
+	{"ET_MAP",ET_MAP},
+	
+	{"MAXEMBLEMS",MAXEMBLEMS},
+	{"MAXEXTRAEMBLEMS",MAXEXTRAEMBLEMS},
+	
+	// secrets
+	{"SECRET_NONE",SECRET_NONE},
+	{"SECRET_ITEMFINDER",SECRET_ITEMFINDER},
+	{"SECRET_EMBLEMHINTS",SECRET_EMBLEMHINTS},
+	{"SECRET_PANDORA",SECRET_PANDORA},
+	{"SECRET_RECORDATTACK",SECRET_RECORDATTACK},
+	{"SECRET_NIGHTSMODE",SECRET_NIGHTSMODE},
+	{"SECRET_HEADER",SECRET_HEADER},
+	{"SECRET_LEVELSELECT",SECRET_LEVELSELECT},
+	{"SECRET_WARP",SECRET_WARP},
+	{"SECRET_SOUNDTEST",SECRET_SOUNDTEST},
+	{"SECRET_CREDITS",SECRET_CREDITS},
+	
+	{"MAXUNLOCKABLES",MAXUNLOCKABLES},
 #endif
 
 	{NULL,0}
diff --git a/src/lua_condlib.c b/src/lua_condlib.c
index e27ced1c2..5efca4d63 100644
--- a/src/lua_condlib.c
+++ b/src/lua_condlib.c
@@ -58,9 +58,9 @@ static int lib_getConditionsets(lua_State *L)
 	UINT16 i;
 	lua_remove(L, 1);
 
-	i = luaL_checkinteger(L, 1)-1;
+	i = luaL_checkinteger(L, 1);
 	if (i >= MAXCONDITIONSETS)
-		return luaL_error(L, "conditionSets[] index %d out of range (1 - %d)", i+1, MAXCONDITIONSETS);
+		return luaL_error(L, "conditionSets[] index %d out of range (0 - %d)", i, MAXCONDITIONSETS-1);
 	LUA_PushUserdata(L, &conditionSets[i], META_CONDITIONSET);
 	return 1;
 }
@@ -117,9 +117,9 @@ static int lib_getEmblemlocations(lua_State *L)
 	UINT16 i;
 	lua_remove(L, 1);
 
-	i = luaL_checkinteger(L, 1)-1;
+	i = luaL_checkinteger(L, 1);
 	if (i >= MAXEMBLEMS)
-		return luaL_error(L, "emblemlocations[] index %d out of range (1 - %d)", i+1, MAXEMBLEMS);
+		return luaL_error(L, "emblemlocations[] index %d out of range (0 - %d)", i, MAXEMBLEMS-1);
 	LUA_PushUserdata(L, &emblemlocations[i], META_EMBLEM);
 	return 1;
 }
@@ -168,9 +168,9 @@ static int lib_getExtraemblems(lua_State *L)
 	UINT16 i;
 	lua_remove(L, 1);
 
-	i = luaL_checkinteger(L, 1)-1;
-	if (1 >= MAXEXTRAEMBLEMS)
-		return luaL_error(L, "extraemblems[] index %d out of range (1 - %d)", i, MAXEXTRAEMBLEMS);
+	i = luaL_checkinteger(L, 1);
+	if (i >= MAXEXTRAEMBLEMS)
+		return luaL_error(L, "extraemblems[] index %d out of range (0 - %d)", i, MAXEXTRAEMBLEMS-1);
 	LUA_PushUserdata(L, &extraemblems[i], META_EXTRAEMBLEM);
 	return 1;
 }
@@ -225,9 +225,9 @@ static int lib_getUnlockables(lua_State *L)
 	UINT16 i;
 	lua_remove(L, 1);
 
-	i = luaL_checkinteger(L, 1)-1;
+	i = luaL_checkinteger(L, 1);
 	if (i >= MAXUNLOCKABLES)
-		return luaL_error(L, "unlockables[] index %d out of range (1 - %d)", i, MAXUNLOCKABLES);
+		return luaL_error(L, "unlockables[] index %d out of range (0 - %d)", i, MAXUNLOCKABLES-1);
 	LUA_PushUserdata(L, &unlockables[i], META_UNLOCKABLE);
 	return 1;
 }
@@ -280,7 +280,7 @@ int LUA_CondLib(lua_State *L)
 			lua_pushcfunction(L, lib_numconditionsets);
 			lua_setfield(L, -2, "__len");
 		lua_setmetatable(L, -2);
-	lua_setglobal(L, "conditionsets");
+	lua_setglobal(L, "conditionSets");
 	
 	lua_newuserdata(L, 0);
 		lua_createtable(L, 0, 2);
-- 
GitLab